After a digital car key is enabled, the car owner app can remotely unlock the car and perform other operations through car control commands.

The typical service process is as follows:
The car owner app calls the queryICCEConnectionState API to check the Bluetooth connection status of the car control system. If the Bluetooth connection is not set up, the car owner app calls startICCEConnection to set up the connection.
The car owner app calls registerICCEListener to register a listener for messages sent from HUAWEI Wallet.
The car owner app calls the sendICCERKEMessage API to send car control commands.
When the user exits the digital key car control page, the car owner app calls the unregisterICCEListener API to unregister the listener.
Make the car owner app call the queryICCEConnectionState API to check the Bluetooth connection status of the car key based on the service ID registered when applying for Wallet Kit and the unique pass ID defined when applying for the key card.
import { common } from '@kit.AbilityKit';
import { walletPass } from '@kit.WalletKit';
import { BusinessError } from '@kit.BasicServicesKit';
@Entry
@Component
struct Index {
private walletPassClient: walletPass.WalletPassClient = new walletPass.WalletPassClient(this.getUIContext().getHostContext() as common.UIAbilityContext);
// Service ID registered when applying for Wallet Kit.
private passType: string = '';
// Unique pass ID defined when applying for the key card.
private serialNumber: string = '';
async queryICCEConnectionState() {
let passStr = JSON.stringify({
passType: this.passType,
serialNumber: this.serialNumber
});
this.walletPassClient.queryICCEConnectionState(passStr).then((result: string) => {
console.info(`Succeeded in querying ICCEConnectionState, result: ${result}`);
}).catch((err: BusinessError) => {
console.error(`Failed to query ICCEConnectionState, code:${err.code}, message:${err.message}`);
})
}
build() {
// your application UI
}
} If the value of connectionState returned by the queryICCEConnectionState API is 0 (not paired), call startICCEConnection to set up a Bluetooth connection.
import { common } from '@kit.AbilityKit';
import { walletPass } from '@kit.WalletKit';
import { BusinessError } from '@kit.BasicServicesKit';
@Entry
@Component
struct Index {
private walletPassClient: walletPass.WalletPassClient = new walletPass.WalletPassClient(this.getUIContext().getHostContext() as common.UIAbilityContext);
// Service ID registered when applying for Wallet Kit.
private passType: string = '';
// Unique pass ID defined when applying for the key card.
private serialNumber: string = '';
async startICCEConnection() {
let passStr = JSON.stringify({
passType: this.passType,
serialNumber: this.serialNumber
});
this.walletPassClient.startICCEConnection(passStr).then((result: string) => {
console.info(`Succeeded in starting ICCEConnection, result: ${result}`);
}).catch((err: BusinessError) => {
console.error(`Failed to start ICCEConnection, code:${err.code}, message:${err.message}`);
})
}
build() {
// your application UI
}
} The car owner app calls registerICCEListener to register a listener for messages sent from HUAWEI Wallet.
import { common } from '@kit.AbilityKit';
import { walletPass } from '@kit.WalletKit';
import { BusinessError } from '@kit.BasicServicesKit';
import { rpc } from '@kit.IPCKit';
class ICCECallBack extends rpc.RemoteObject {
constructor() {
super('ICCECallBack');
}
async onRemoteMessageRequest(code: number, data: rpc.MessageSequence, reply: rpc.MessageSequence, option: rpc.MessageOption): Promise<boolean> {
// processing after receiving communication data
let codeInt = data.readInt();
return true;
}
}
@Entry
@Component
struct Index {
private walletPassClient: walletPass.WalletPassClient = new walletPass.WalletPassClient(this.getUIContext().getHostContext() as common.UIAbilityContext);
private callback: rpc.RemoteObject | null = null;
// Service ID registered when applying for Wallet Kit.
private passType: string = '';
// Name of the app for which the listener needs to be registered, which is usually the app package name.
private registerName: string = '';
async registerICCEListener() {
let passStr = JSON.stringify({
passType: this.passType,
registerName: this.registerName
});
this.callback = new ICCECallBack();
this.walletPassClient.registerICCEListener(passStr, this.callback).then((result: string) => {
console.info(`Succeeded in registering ICCEListener, result: ${result}`);
}).catch((err: BusinessError) => {
console.error(`Failed to register ICCEListener, code:${err.code}, message:${err.message}`);
})
}
build() {
// your application UI
}
} The car owner app calls the sendICCERKEMessage API to send car control commands.
import { common } from '@kit.AbilityKit';
import { walletPass } from '@kit.WalletKit';
import { BusinessError } from '@kit.BasicServicesKit';
@Entry
@Component
struct Index {
private walletPassClient: walletPass.WalletPassClient = new walletPass.WalletPassClient(this.getUIContext().getHostContext() as common.UIAbilityContext);
// Service ID registered when applying for Wallet Kit.
private passType: string = '';
// Unique pass ID defined when applying for the key card.
private serialNumber: string = '';
// Car control command.
private rkeCommand: string = '';
async sendICCERKEMessage() {
let passStr = JSON.stringify({
passType: this.passType,
serialNumber: this.serialNumber,
rkeCommand: this.rkeCommand,
encryptFlag: '0',
directionFlag: '1'
});
this.walletPassClient.sendICCERKEMessage(passStr).then((result: string) => {
console.info(`Succeeded in sending ICCERKEMessage, result: ${result}`);
}).catch((err: BusinessError) => {
console.error(`Failed to send ICCERKEMessage, code:${err.code}, message:${err.message}`);
})
}
build() {
// your application UI
}
} When the user exits the digital key car control page, the car owner app calls the unregisterICCEListener API to unregister the listener.
import { common } from '@kit.AbilityKit';
import { walletPass } from '@kit.WalletKit';
import { BusinessError } from '@kit.BasicServicesKit';
import { rpc } from '@kit.IPCKit';
@Entry
@Component
struct Index {
private walletPassClient: walletPass.WalletPassClient = new walletPass.WalletPassClient(this.getUIContext().getHostContext() as common.UIAbilityContext);
private callback: rpc.RemoteObject | null = null;
// Service ID registered when applying for Wallet Kit.
private passType: string = '';
// Name of the app for which the listener needs to be registered, which is usually the app package name.
private registerName: string = '';
async unregisterICCEListener() {
let passStr = JSON.stringify({
passType: this.passType,
registerName: this.registerName
});
this.walletPassClient.unregisterICCEListener(passStr).then((result: string) => {
console.info(`Succeeded in unregistering ICCEListener, result: ${result}`);
this.callback = null;
}).catch((err: BusinessError) => {
console.error(`Failed to unregister ICCEListener, code:${err.code}, message:${err.message}`);
})
}
build() {
// your application UI
}
}