From 6082912ffb4504f7bc449854a530d9f3a3f7d279 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cyour?= Date: Thu, 24 Feb 2022 18:25:30 -0800 Subject: [PATCH] device_ready_status bug Signed-off-by: pang-wenbin2 pangwenbin2@huawei.com --- ext/profile/include/device_profile_adapter.h | 3 ++- ext/profile/src/device_profile_adapter.cpp | 5 +++-- .../src/devicestate/dm_device_state_manager.cpp | 4 +++- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/ext/profile/include/device_profile_adapter.h b/ext/profile/include/device_profile_adapter.h index 3703a619a..e976907aa 100644 --- a/ext/profile/include/device_profile_adapter.h +++ b/ext/profile/include/device_profile_adapter.h @@ -24,7 +24,8 @@ namespace OHOS { namespace DistributedHardware { -class DeviceProfileAdapter : public IProfileAdapter, public IProfileConnectorCallback { +class DeviceProfileAdapter : public IProfileAdapter, public IProfileConnectorCallback,// { + public std::enable_shared_from_this { public: DeviceProfileAdapter(); ~DeviceProfileAdapter(); diff --git a/ext/profile/src/device_profile_adapter.cpp b/ext/profile/src/device_profile_adapter.cpp index 5d6165a01..08c2ea386 100644 --- a/ext/profile/src/device_profile_adapter.cpp +++ b/ext/profile/src/device_profile_adapter.cpp @@ -36,13 +36,14 @@ int32_t DeviceProfileAdapter::RegisterProfileListener(const std::string &pkgName { LOGI("DeviceProfileAdapter::RegisterProfileListener"); deviceProfileAdapterCallback_ = callback; - profileConnector_->RegisterProfileCallback(pkgName, deviceId, std::shared_ptr(this)); + // profileConnector_->RegisterProfileCallback(pkgName, deviceId, std::shared_ptr(this)); + profileConnector_->RegisterProfileCallback(pkgName, deviceId, shared_from_this()); return DM_OK; } int32_t DeviceProfileAdapter::UnRegisterProfileListener(const std::string &pkgName) { - LOGI("DeviceProfileAdapter::RegisterProfileListener"); + LOGI("DeviceProfileAdapter::UnRegisterProfileListener"); deviceProfileAdapterCallback_ = nullptr; profileConnector_->UnRegisterProfileCallback(pkgName); return DM_OK; diff --git a/services/devicemanagerservice/src/devicestate/dm_device_state_manager.cpp b/services/devicemanagerservice/src/devicestate/dm_device_state_manager.cpp index 98ba3c7f2..09a0f12d2 100644 --- a/services/devicemanagerservice/src/devicestate/dm_device_state_manager.cpp +++ b/services/devicemanagerservice/src/devicestate/dm_device_state_manager.cpp @@ -70,7 +70,8 @@ void DmDeviceStateManager::OnDeviceOnline(const std::string &pkgName, const DmDe remoteDeviceInfos_[uuid] = saveInfo; LOGI("RegisterProfileListener in, deviceId = %s, deviceUdid = %s, uuid = %s", info.deviceId, deviceUdid.c_str(), uuid.c_str()); - LOGI("RegisterProfileListener out"); + profileAdapter->RegisterProfileListener(pkgName, deviceUdid, shared_from_this()); + LOGI("RegisterProfileListener out"); } } DmDeviceState state = DEVICE_STATE_ONLINE; @@ -87,6 +88,7 @@ void DmDeviceStateManager::OnDeviceOffline(const std::string &pkgName, const DmD if (profileAdapter == nullptr) { LOGE("OnDeviceOffline profile adapter is null"); } else { + profileAdapter->UnRegisterProfileListener(pkgName); std::string uuid; SoftbusConnector::GetUuidByNetworkId(info.deviceId, uuid); auto iter = remoteDeviceInfos_.find(std::string(info.deviceId)); -- Gitee