From e29621a6dd4200f8d528174fc269f86361ce8ad8 Mon Sep 17 00:00:00 2001 From: tuyuanyang Date: Sat, 7 Oct 2023 14:58:15 +0800 Subject: [PATCH] =?UTF-8?q?@ohos.distributedDeviceMnager=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E6=9B=BF=E6=8D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: tuyuanyang --- .../model/NotificationDistributionManager.ts | 34 ++++++++++++------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/features/noticeitem/src/main/ets/com/ohos/noticeItem/model/NotificationDistributionManager.ts b/features/noticeitem/src/main/ets/com/ohos/noticeItem/model/NotificationDistributionManager.ts index d17a06f7..6ef7a536 100644 --- a/features/noticeitem/src/main/ets/com/ohos/noticeItem/model/NotificationDistributionManager.ts +++ b/features/noticeitem/src/main/ets/com/ohos/noticeItem/model/NotificationDistributionManager.ts @@ -14,7 +14,7 @@ */ import Log from '../../../../../../../../../common/src/main/ets/default/Log'; -import DeviceManager from '@ohos.distributedHardware.deviceManager'; +import deviceManager from '@ohos.distributedDeviceManager'; import DeviceInfo from '@ohos.deviceInfo'; const TAG = 'NotificationDistributionManager'; @@ -41,12 +41,16 @@ export default class NotificationDistributionManager { initDeviceManager(): void { Log.showInfo(TAG, 'initDeviceManager'); - DeviceManager.createDeviceManager('com.ohos.systemui', (err, data) => { - Log.showInfo(TAG, `initDeviceManager createDeviceManager err:${JSON.stringify(err)} data:${JSON.stringify(data)}`); - if (data) { - this.deviceManager = data; + try { + let dmInstance = deviceManager.createDeviceManager("com.ohos.systemui"); + if (dmInstance) { + this.deviceManager = dmInstance; + } else { + Log.showDebug(TAG, 'initDeviceManager dmInstance else'); } - }); + } catch (err) { + Log.showError(TAG, `initDeviceManager trycatch-error ${JSON.stringify(err)}`); + } } getTrustedDeviceDeviceName(deviceId: string): string { @@ -67,16 +71,20 @@ export default class NotificationDistributionManager { getTrustedDeviceListSync(): any[] { Log.showInfo(TAG, 'getTrustedDeviceListSync'); - return this.deviceManager.getTrustedDeviceListSync(); - } - - getLocalDeviceInfoSync(): any { - Log.showInfo(TAG, 'getLocalDeviceInfoSync'); - return this.deviceManager.getLocalDeviceInfoSync(); + return this.deviceManager.getAvailableDeviceListSync(); } release(): void { - this.deviceManager.release(); + try { + let dmInstance = deviceManager.createDeviceManager("com.ohos.systemui"); + if (dmInstance) { + deviceManager.releaseDeviceManager(dmInstance); + } else { + Log.showDebug(TAG, 'initDeviceManager dmInstance else'); + } + } catch (err) { + Log.showDebug(TAG, 'deviceManager release err'); + } } } -- Gitee