1# Device Manager ChangeLog 2 3## cl.device_manager.1 Error Information Return Method Change of APIs 4 5The 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: 6 7Asynchronous API: An error message is returned via **AsyncCallback** or the **error** object of **Promise**. 8 9Synchronous API: An error message is returned via an exception. 10 11**Change Impact** 12 13The application developed based on earlier versions needs to adapt the method for returning API error information. Otherwise, the original service logic will be affected. 14 15**Key API/Component Changes** 16 17Error code processing is added for the following APIs: 18 - createDeviceManager(bundleName: string, callback: AsyncCallback<DeviceManager>): void; 19 - release(): void; 20 - getTrustedDeviceListSync(): Array<DeviceInfo> 21 - getTrustedDeviceList(callback:AsyncCallback<Array<DeviceInfo>>): void; 22 - getTrustedDeviceList(): Promise<Array<DeviceInfo>> 23 - getLocalDeviceInfoSync(): DeviceInfo; 24 - getLocalDeviceInfo(callback:AsyncCallback<DeviceInfo>): void; 25 - getLocalDeviceInfo(): Promise<DeviceInfo> 26 - startDeviceDiscovery(subscribeInfo: SubscribeInfo): void; 27 - startDeviceDiscovery(subscribeInfo: SubscribeInfo, filterOptions?: string): void; 28 - stopDeviceDiscovery(subscribeId: number): void; 29 - publishDeviceDiscovery(publishInfo: PublishInfo): void; 30 - unPublishDeviceDiscovery(publishId: number): void; 31 - authenticateDevice(deviceInfo: DeviceInfo, authParam: AuthParam, callback: AsyncCallback<{deviceId: string, pinToken ?: number}>): void; 32 - unAuthenticateDevice(deviceInfo: DeviceInfo): void; 33 - verifyAuthInfo(authInfo: AuthInfo, callback: AsyncCallback<{deviceId: string, level: number}>): void; 34 - setUserOperation(operateAction: number, params: string): void; 35 - on(type: 'uiStateChange', callback: Callback<{ param: string}>): void; 36 - off(type: 'uiStateChange', callback?: Callback<{ param: string}>): void; 37 - on(type: 'deviceStateChange', callback: Callback<{ action: DeviceStateChangeAction, device: DeviceInfo }>): void; 38 - off(type: 'deviceStateChange', callback?: Callback<{ action: DeviceStateChangeAction, device: DeviceInfo }>): void; 39 - on(type: 'deviceFound', callback: Callback<{ subscribeId: number, device: DeviceInfo }>): void; 40 - off(type: 'deviceFound', callback?: Callback<{ subscribeId: number, device: DeviceInfo }>): void; 41 - on(type: 'discoverFail', callback: Callback<{ subscribeId: number, reason: number }>): void; 42 - off(type: 'discoverFail', callback?: Callback<{ subscribeId: number, reason: number }>): void; 43 - on(type: 'publishSuccess', callback: Callback<{ publishId: number }>): void; 44 - off(type: 'publishSuccess', callback?: Callback<{ publishId: number }>): void; 45 - on(type: 'publishFail', callback: Callback<{ publishId: number, reason: number }>): void; 46 - off(type: 'publishFail', callback?: Callback<{ publishId: number, reason: number }>): void; 47 - on(type: 'serviceDie', callback: () => void): void; 48 - off(type: 'serviceDie', callback?: () => void): void; 49 50**Adaptation Guide** 51 52The following uses **getTrustedDeviceList** as an example for asynchronous APIs: 53 54```ts 55import account_osAccount from "@ohos.distributedHardware.deviceManager" 56dmInstance.getTrustedDeviceList((err, data) => { 57 console.log("getTrustedDeviceList err: " + JSON.stringify(err)); 58 console.log('get trusted device info: ' + JSON.stringify(data)); 59}); 60 61try { 62 dmInstance.getTrustedDeviceList((err, data) => { 63 if (err) { 64 console.error("getTrustedDeviceList errCode:" + err.code + ",errMessage:" + err.message); 65 return; 66 } 67 console.log('get trusted device info: ' + JSON.stringify(data)); 68 }); 69} catch (err) { 70 console.error("getTrustedDeviceList errCode:" + err.code + ",errMessage:" + err.message); 71} 72``` 73 74The following uses **startDeviceDiscovery** as an example for synchronous APIs: 75 76```ts 77// Automatically generate a unique subscription ID. 78var subscribeId = Math.floor(Math.random() * 10000 + 1000); 79var subscribeInfo = { 80 "subscribeId": subscribeId, 81 "mode": 0xAA, // Active discovery 82 "medium": 0, // Automatic. Multiple media can be used for device discovery. 83 "freq": 2, // High frequency 84 "isSameAccount": false, 85 "isWakeRemote": false, 86 "capability": 1 87}; 88dmInstance.startDeviceDiscovery(subscribeInfo); // The deviceFound callback is called to notify the application when a device is discovered. 89 90// Automatically generate a unique subscription ID. 91var subscribeId = Math.floor(Math.random() * 10000 + 1000); 92var subscribeInfo = { 93 "subscribeId": subscribeId, 94 "mode": 0xAA, // Active discovery 95 "medium": 0, // Automatic. Multiple media can be used for device discovery. 96 "freq": 2, // High frequency 97 "isSameAccount": false, 98 "isWakeRemote": false, 99 "capability": 1 100}; 101try { 102 dmInstance.startDeviceDiscovery(subscribeInfo); // The deviceFound callback is called to notify the application when a device is discovered. 103} catch (err) { 104 console.error("startDeviceDiscovery errCode:" + err.code + ",errMessage:" + err.message); 105} 106``` 107