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