diff --git a/services/native/driver_extension_manager/include/device_manager/device.h b/services/native/driver_extension_manager/include/device_manager/device.h index e49027510cb2a1e83e621f18953456dbd8857d77..4ec40554299a7266a4b476a15ebb8c7cfe1e1ea2 100644 --- a/services/native/driver_extension_manager/include/device_manager/device.h +++ b/services/native/driver_extension_manager/include/device_manager/device.h @@ -141,6 +141,14 @@ public: explicit DrvExtConnNotify(std::weak_ptr device) : device_(device) {} int32_t OnConnectDone(const sptr &remote, int resultCode) override; int32_t OnDisconnectDone(int resultCode) override; + bool IsInvalidDrvExtConnectionInfo() + { + return info_ == nullptr; + } + void ClearDrvExtConnectionInfo() + { + info_ = nullptr; + } private: std::weak_ptr device_; diff --git a/services/native/driver_extension_manager/include/driver_controller/driver_extension_controller.h b/services/native/driver_extension_manager/include/driver_controller/driver_extension_controller.h index bf42d63101c1c65f19f9aef86f54cb031bf5ee2e..d4ee97862ce3710a18165bfc280d31a5b50c0aeb 100644 --- a/services/native/driver_extension_manager/include/driver_controller/driver_extension_controller.h +++ b/services/native/driver_extension_manager/include/driver_controller/driver_extension_controller.h @@ -62,7 +62,7 @@ public: virtual int32_t OnDisconnectDone(int resultCode) = 0; bool IsConnectDone(); sptr GetRemoteObj(); -private: +protected: friend class DriverExtensionController; std::shared_ptr info_ = nullptr; }; diff --git a/services/native/driver_extension_manager/src/device_manager/device.cpp b/services/native/driver_extension_manager/src/device_manager/device.cpp index 0c2300388eda8000576bb5e12017a598f89d5318..780ff61b746e34edc1bf0752aa3f98e2b62524de 100644 --- a/services/native/driver_extension_manager/src/device_manager/device.cpp +++ b/services/native/driver_extension_manager/src/device_manager/device.cpp @@ -98,6 +98,10 @@ int32_t Device::Disconnect() { EDM_LOGI(MODULE_DEV_MGR, "%{public}s enter", __func__); std::lock_guard lock(deviceMutex_); + if (connectNofitier_ != nullptr && connectNofitier_->IsInvalidDrvExtConnectionInfo()) { + EDM_LOGI(MODULE_DEV_MGR, "driver extension has been disconnected"); + return UsbErrCode::EDM_OK; + } uint32_t busDevId = GetDeviceInfo()->GetBusDevId(); std::string bundleInfo = GetBundleInfo(); std::string bundleName = Device::GetBundleName(bundleInfo); @@ -105,7 +109,7 @@ int32_t Device::Disconnect() int32_t ret = DriverExtensionController::GetInstance().DisconnectDriverExtension( bundleName, abilityName, connectNofitier_, busDevId); if (ret != UsbErrCode::EDM_OK) { - EDM_LOGE(MODULE_DEV_MGR, "failed to connect driver extension"); + EDM_LOGE(MODULE_DEV_MGR, "failed to disconnect driver extension"); return ret; } @@ -137,6 +141,7 @@ void Device::OnDisconnect(int resultCode) std::lock_guard lock(deviceMutex_); drvExtRemote_ = nullptr; + connectNofitier_->ClearDrvExtConnectionInfo(); for (auto &callback : callbacks_) { callback->OnUnBind(GetDeviceInfo()->GetDeviceId(), {static_cast(resultCode), ""}); } diff --git a/services/native/driver_extension_manager/src/device_manager/etx_device_mgr.cpp b/services/native/driver_extension_manager/src/device_manager/etx_device_mgr.cpp index d404ae06bfaa210793ee11063a166320f60adb15..2ffb99d7c93074ef6fd88e0ace5163c36b0d375a 100644 --- a/services/native/driver_extension_manager/src/device_manager/etx_device_mgr.cpp +++ b/services/native/driver_extension_manager/src/device_manager/etx_device_mgr.cpp @@ -163,6 +163,7 @@ int32_t ExtDeviceManager::RemoveAllDevIdOfBundleInfoMap(shared_ptr devic int32_t ExtDeviceManager::AddBundleInfo(enum BusType busType, const string &bundleName, const string &abilityName) { + EDM_LOGI(MODULE_DEV_MGR, "%{public}s enter", __func__); if (busType <= BUS_TYPE_INVALID || busType > BUS_TYPE_TEST) { EDM_LOGE(MODULE_DEV_MGR, "busType para invalid"); return EDM_ERR_INVALID_PARAM; @@ -213,6 +214,7 @@ int32_t ExtDeviceManager::AddBundleInfo(enum BusType busType, const string &bund int32_t ExtDeviceManager::RemoveBundleInfo(enum BusType busType, const string &bundleName, const string &abilityName) { + EDM_LOGI(MODULE_DEV_MGR, "%{public}s enter", __func__); if (busType <= BUS_TYPE_INVALID || busType >= BUS_TYPE_TEST) { EDM_LOGE(MODULE_DEV_MGR, "busType para invalid"); return EDM_ERR_INVALID_PARAM; @@ -238,8 +240,8 @@ int32_t ExtDeviceManager::RemoveBundleInfo(enum BusType busType, const string &b // iterate over device by bustype if (bundleInfo.compare(device->GetBundleInfo()) == 0) { - device->RemoveBundleInfo(); // update device int32_t ret = RemoveAllDevIdOfBundleInfoMap(device, bundleInfo); + device->RemoveBundleInfo(); // update device if (ret != EDM_OK) { EDM_LOGE(MODULE_DEV_MGR, "deviceId[%{public}016" PRIX64 "] stop driver extension ability[%{public}s] fail[%{public}d]", @@ -252,6 +254,7 @@ int32_t ExtDeviceManager::RemoveBundleInfo(enum BusType busType, const string &b int32_t ExtDeviceManager::UpdateBundleInfo(enum BusType busType, const string &bundleName, const string &abilityName) { + EDM_LOGI(MODULE_DEV_MGR, "%{public}s enter", __func__); // stop ability of device and reset bundleInfo of device int32_t ret = RemoveBundleInfo(busType, bundleName, abilityName); if (ret != EDM_OK) { @@ -299,7 +302,7 @@ int32_t ExtDeviceManager::UpdateBundleStatusCallback( // remove bundle ret = ExtDeviceManager::GetInstance().RemoveBundleInfo((enum BusType)busType, bundleName, abilityName); if (ret != EDM_OK) { - EDM_LOGE(MODULE_DEV_MGR, "callback update bundle info fail"); + EDM_LOGE(MODULE_DEV_MGR, "callback remove bundle info fail"); } return ret; @@ -382,7 +385,7 @@ int32_t ExtDeviceManager::UnRegisterDevice(const shared_ptr devInfo) } if (bundleInfo.empty()) { - EDM_LOGD(MODULE_DEV_MGR, "deviceId %{public}016" PRIX64 " bundleInfo is empty", deviceId); + EDM_LOGI(MODULE_DEV_MGR, "deviceId %{public}016" PRIX64 " bundleInfo is empty", deviceId); return EDM_OK; }