Device Manager ChangeLog
cl.device_manager.1 Error Information Return Method Change of APIs
The device manager API uses service logic return values to indicate the error information, which does not comply with the API error code specifications of OpenHarmony. The following changes are made in API version 9 and later:
Asynchronous API: An error message is returned via AsyncCallback or the error object of Promise.
Synchronous API: An error message is returned via an exception.
Change Impact
The application developed based on earlier versions needs to adapt the method for returning API error information. Otherwise, the original service logic will be affected.
Key API/Component Changes
Error code processing is added for the following APIs:
- createDeviceManager(bundleName: string, callback: AsyncCallback<DeviceManager>): void;
- release(): void;
- getTrustedDeviceListSync(): Array<DeviceInfo>
- getTrustedDeviceList(callback:AsyncCallback<Array<DeviceInfo>>): void;
- getTrustedDeviceList(): Promise<Array<DeviceInfo>>
- getLocalDeviceInfoSync(): DeviceInfo;
- getLocalDeviceInfo(callback:AsyncCallback<DeviceInfo>): void;
- getLocalDeviceInfo(): Promise<DeviceInfo>
- startDeviceDiscovery(subscribeInfo: SubscribeInfo): void;
- startDeviceDiscovery(subscribeInfo: SubscribeInfo, filterOptions?: string): void;
- stopDeviceDiscovery(subscribeId: number): void;
- publishDeviceDiscovery(publishInfo: PublishInfo): void;
- unPublishDeviceDiscovery(publishId: number): void;
- authenticateDevice(deviceInfo: DeviceInfo, authParam: AuthParam, callback: AsyncCallback<{deviceId: string, pinToken ?: number}>): void;
- unAuthenticateDevice(deviceInfo: DeviceInfo): void;
- verifyAuthInfo(authInfo: AuthInfo, callback: AsyncCallback<{deviceId: string, level: number}>): void;
- setUserOperation(operateAction: number, params: string): void;
- on(type: 'uiStateChange', callback: Callback<{ param: string}>): void;
- off(type: 'uiStateChange', callback?: Callback<{ param: string}>): void;
- on(type: 'deviceStateChange', callback: Callback<{ action: DeviceStateChangeAction, device: DeviceInfo }>): void;
- off(type: 'deviceStateChange', callback?: Callback<{ action: DeviceStateChangeAction, device: DeviceInfo }>): void;
- on(type: 'deviceFound', callback: Callback<{ subscribeId: number, device: DeviceInfo }>): void;
- off(type: 'deviceFound', callback?: Callback<{ subscribeId: number, device: DeviceInfo }>): void;
- on(type: 'discoverFail', callback: Callback<{ subscribeId: number, reason: number }>): void;
- off(type: 'discoverFail', callback?: Callback<{ subscribeId: number, reason: number }>): void;
- on(type: 'publishSuccess', callback: Callback<{ publishId: number }>): void;
- off(type: 'publishSuccess', callback?: Callback<{ publishId: number }>): void;
- on(type: 'publishFail', callback: Callback<{ publishId: number, reason: number }>): void;
- off(type: 'publishFail', callback?: Callback<{ publishId: number, reason: number }>): void;
- on(type: 'serviceDie', callback: () => void): void;
- off(type: 'serviceDie', callback?: () => void): void;
Adaptation Guide
The following uses getTrustedDeviceList as an example for asynchronous APIs:
import account_osAccount from "@ohos.distributedHardware.deviceManager"
dmInstance.getTrustedDeviceList((err, data) => {
console.log("getTrustedDeviceList err: " + JSON.stringify(err));
console.log('get trusted device info: ' + JSON.stringify(data));
});
try {
dmInstance.getTrustedDeviceList((err, data) => {
if (err) {
console.error("getTrustedDeviceList errCode:" + err.code + ",errMessage:" + err.message);
return;
}
console.log('get trusted device info: ' + JSON.stringify(data));
});
} catch (err) {
console.error("getTrustedDeviceList errCode:" + err.code + ",errMessage:" + err.message);
}
The following uses startDeviceDiscovery as an example for synchronous APIs:
// Automatically generate a unique subscription ID.
var subscribeId = Math.floor(Math.random() * 10000 + 1000);
var subscribeInfo = {
"subscribeId": subscribeId,
"mode": 0xAA, // Active discovery
"medium": 0, // Automatic. Multiple media can be used for device discovery.
"freq": 2, // High frequency
"isSameAccount": false,
"isWakeRemote": false,
"capability": 1
};
dmInstance.startDeviceDiscovery(subscribeInfo); // The deviceFound callback is called to notify the application when a device is discovered.
// Automatically generate a unique subscription ID.
var subscribeId = Math.floor(Math.random() * 10000 + 1000);
var subscribeInfo = {
"subscribeId": subscribeId,
"mode": 0xAA, // Active discovery
"medium": 0, // Automatic. Multiple media can be used for device discovery.
"freq": 2, // High frequency
"isSameAccount": false,
"isWakeRemote": false,
"capability": 1
};
try {
dmInstance.startDeviceDiscovery(subscribeInfo); // The deviceFound callback is called to notify the application when a device is discovered.
} catch (err) {
console.error("startDeviceDiscovery errCode:" + err.code + ",errMessage:" + err.message);
}