From a5d60f2ac75a55c75f29704cd347e34491340e81 Mon Sep 17 00:00:00 2001 From: shenkang Date: Mon, 14 Apr 2025 16:55:25 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E7=B3=BB=E7=BB=9F=E4=BA=8B=E4=BB=B6?= =?UTF-8?q?=E6=89=93=E7=82=B9=E6=96=B0=E5=A2=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: shenkang --- .../src/js_driver_extension.cpp | 55 +++--- .../include/device_manager/device.h | 2 +- .../driver_report_sys_event.h | 30 ++-- .../bus_extension/usb/usb_bus_extension.cpp | 15 -- .../bus_extension/usb/usb_dev_subscriber.cpp | 37 ++-- .../src/device_manager/device.cpp | 44 ++--- .../driver_extension_controller.cpp | 18 -- .../src/device_manager/etx_device_mgr.cpp | 78 +++++---- .../src/driver_ext_mgr.cpp | 18 -- .../driver_report_sys_event.cpp | 159 +++++++----------- .../driver_os_account_subscriber.cpp | 6 - .../driver_pkg_manager.cpp | 42 ++--- utils/include/ext_object.h | 9 +- 13 files changed, 224 insertions(+), 289 deletions(-) diff --git a/services/native/driver_extension/src/js_driver_extension.cpp b/services/native/driver_extension/src/js_driver_extension.cpp index 3ee3682..8a5b297 100644 --- a/services/native/driver_extension/src/js_driver_extension.cpp +++ b/services/native/driver_extension/src/js_driver_extension.cpp @@ -37,6 +37,27 @@ constexpr size_t ARGC_ONE = 1; } namespace { +using namespace OHOS::ExternalDeviceManager; + +static void ParseToExtDevEvent(const std::shared_ptr &abilityInfo, + const std::shared_ptr &extDevEvent) +{ + if (abilityInfo == nullptr || extDevEvent == nullptr) { + return; + } + extDevEvent->bundleName = abilityInfo->applicationInfo.bundleName; + extDevEvent->driverName = abilityInfo->name; + extDevEvent->driverUid = abilityInfo->name + "-" + std::to_string(abilityInfo->applicationInfo.accessTokenId); + extDevEvent->versionCode = abilityInfo->applicationInfo.versionName; + for (const auto &meta : abilityInfo->metadata) { + if (LowerStr(meta.name) == "vid") { + extDevEvent->vids = meta.value; + } else if (LowerStr(meta.name) == "pid") { + extDevEvent->pids = meta.value; + } + } +} + napi_value PromiseCallback(napi_env env, napi_callback_info info) { if (info == nullptr) { @@ -214,18 +235,8 @@ void JsDriverExtension::OnStart(const AAFwk::Want &want) napi_env env = jsRuntime_.GetNapiEnv(); napi_value napiWant = OHOS::AppExecFwk::WrapWant(env, want); napi_value argv[] = {napiWant}; - napi_value result = CallObjectMethod(env, "onInit", argv, ARGC_ONE); + CallObjectMethod(env, "onInit", argv, ARGC_ONE); HILOG_INFO("%{public}s end.", __func__); - std::shared_ptr eventPtr = - std::make_shared(); - std::string interfaceName = std::string(__func__); - if (result == nullptr) { - ExternalDeviceManager::ExtDevReportSysEvent::SetEventValue(interfaceName, - ExternalDeviceManager::DRIVER_PACKAGE_CYCLE_MANAGE, -1, eventPtr); - return; - } - ExternalDeviceManager::ExtDevReportSysEvent::SetEventValue(interfaceName, - ExternalDeviceManager::DRIVER_PACKAGE_CYCLE_MANAGE, 0, eventPtr); } void JsDriverExtension::OnStop() @@ -240,16 +251,6 @@ void JsDriverExtension::OnStop() HILOG_INFO("The driver extension connection is not disconnected."); } HILOG_INFO("%{public}s end.", __func__); - std::shared_ptr eventPtr = - std::make_shared(); - std::string interfaceName = std::string(__func__); - if (ret) { - ExternalDeviceManager::ExtDevReportSysEvent::SetEventValue(interfaceName, - ExternalDeviceManager::DRIVER_PACKAGE_CYCLE_MANAGE, -1, eventPtr); - return; - } - ExternalDeviceManager::ExtDevReportSysEvent::SetEventValue(interfaceName, - ExternalDeviceManager::DRIVER_PACKAGE_CYCLE_MANAGE, 0, eventPtr); } sptr JsDriverExtension::OnConnect(const AAFwk::Want &want) @@ -357,9 +358,17 @@ napi_value JsDriverExtension::CallObjectMethod(napi_env env, const char* name, c HILOG_ERROR("Failed to get '%{public}s' from DriverExtension object", name); return nullptr; } - HILOG_INFO("JsDriverExtension::CallFunction(%{public}s), success", name); + auto extDevEvent = std::make_shared(name, ExternalDeviceManager::DRIVER_PACKAGE_CYCLE_MANAGE); + ParseToExtDevEvent(Extension::abilityInfo_, extDevEvent); napi_value result = nullptr; - napi_call_function(env, obj, method, argc, argv, &result); + napi_status status = napi_call_function(env, obj, method, argc, argv, &result); + if (status != napi_ok) { + HILOG_ERROR("Failed to call '%{public}s' from DriverExtension object", name); + ExtDevReportSysEvent::ReportExternalDeviceEvent(extDevEvent, -1, "Failed to call callback"); + return nullptr; + } + ExtDevReportSysEvent::ReportExternalDeviceEvent(extDevEvent, 0, "Success to call callback"); + HILOG_INFO("JsDriverExtension::CallFunction(%{public}s), success", name); return result; } 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 d8fae4f..00f47c0 100644 --- a/services/native/driver_extension_manager/include/device_manager/device.h +++ b/services/native/driver_extension_manager/include/device_manager/device.h @@ -38,7 +38,7 @@ public: int32_t Connect(); int32_t Connect(const sptr &connectCallback, uint32_t callingTokenId); - int32_t Disconnect(); + int32_t Disconnect(const bool isFromBind); bool HasDriver() const { diff --git a/services/native/driver_extension_manager/include/drivers_hisysevent/driver_report_sys_event.h b/services/native/driver_extension_manager/include/drivers_hisysevent/driver_report_sys_event.h index c755c8c..5129deb 100644 --- a/services/native/driver_extension_manager/include/drivers_hisysevent/driver_report_sys_event.h +++ b/services/native/driver_extension_manager/include/drivers_hisysevent/driver_report_sys_event.h @@ -59,6 +59,10 @@ typedef struct ExtDevEvent { std::string interfaceName; // 接口名称 std::string message; // 信息 int32_t errCode; // 故障码 + + ExtDevEvent(std::string interfaceName = "", const int32_t operatType = 0, const uint64_t deviceId = 0) + : deviceClass(0), deviceSubClass(0), deviceProtocol(0), vendorId(0), productId(0), deviceId(deviceId), + userId(0), operatType(operatType), interfaceName(std::move(interfaceName)), errCode(0) {} } ExtDevEvent; class ExtDevReportSysEvent { @@ -69,42 +73,36 @@ public: static void ReportDelPkgsCycleManageSysEvent(const std::string &bundleName, const std::string &driverEventName); static void ReportExternalDeviceEvent(const std::shared_ptr &extDevEvent); + + static void ReportExternalDeviceEvent(const std::shared_ptr &extDevEvent, const int32_t errCode, + const std::string &message); static void ReportExternalDeviceSaEvent(const PkgInfoTable &pkgInfoTable, std::string pids, std::string vids, uint32_t versionCode, std::string driverEventName); - static std::shared_ptr ExtDevEventInit(const std::shared_ptr &deviceInfo, - const std::shared_ptr &driverInfo, std::shared_ptr eventObj); + static void ParseToExtDevEvent(const std::shared_ptr &deviceInfo, + const std::shared_ptr &eventObj); - static bool IsMatched(const std::shared_ptr &deviceInfo, - const std::shared_ptr &driverInfo, const std::string &type, const std::string &interfaceName); - - static std::shared_ptr DeviceEventReport(const uint64_t deviceId, const std::string &message = ""); + static void ParseToExtDevEvent(const std::shared_ptr &driverInfo, + const std::shared_ptr &eventObj); - static std::shared_ptr DriverEventReport(const std::string driverUid); + static void ParseToExtDevEvent(const std::shared_ptr &deviceInfo, + const std::shared_ptr &driverInfo, const std::shared_ptr &eventObj); - static std::shared_ptr MatchEventReport(const uint64_t deviceId); + static std::shared_ptr DriverEventReport(const std::string driverUid); static void SetEventValue(const std::string interfaceName, const int32_t operatType, const int32_t errCode, std::shared_ptr eventPtr); static void DriverMapInsert(const std::string driverUid, std::shared_ptr eventPtr); - static void DeviceMapInsert(const uint64_t deviceId, std::shared_ptr eventPtr); - static void DriverMapErase(const std::string driverUid); static void DriverMapDelete(const std::string &bundleName); - static void DeviceMapErase(const uint64_t deviceId); - - static void MatchMapErase(const uint64_t deviceId); - static std::string ParseIdVector(std::vector ids); private: - static std::map> matchMap_; - static std::map> deviceMap_; static std::map> driverMap_; static std::mutex hisyseventMutex_; }; diff --git a/services/native/driver_extension_manager/src/bus_extension/usb/usb_bus_extension.cpp b/services/native/driver_extension_manager/src/bus_extension/usb/usb_bus_extension.cpp index 4ec0a31..68e1490 100644 --- a/services/native/driver_extension_manager/src/bus_extension/usb/usb_bus_extension.cpp +++ b/services/native/driver_extension_manager/src/bus_extension/usb/usb_bus_extension.cpp @@ -26,7 +26,6 @@ #include "usb_device_info.h" #include "usb_driver_info.h" #include "usb_bus_extension.h" -#include "driver_report_sys_event.h" namespace OHOS { namespace ExternalDeviceManager { @@ -118,8 +117,6 @@ int32_t UsbBusExtension::SetDevChangeCallback(shared_ptr dev bool UsbBusExtension::MatchDriver(const DriverInfo &driver, const DeviceInfo &device, const std::string &type) { - auto eventPtr = ExtDevReportSysEvent::DeviceEventReport(device.GetDeviceId(), type); - std::string interfaceName = std::string(__func__); if (LowerStr(driver.GetBusName()) != "usb") { EDM_LOGW(MODULE_BUS_USB, "driver bus not support by this module [UsbBusExtension]"); return false; @@ -128,10 +125,6 @@ bool UsbBusExtension::MatchDriver(const DriverInfo &driver, const DeviceInfo &de if (device.GetBusType() != BusType::BUS_TYPE_USB) { EDM_LOGW(MODULE_BUS_USB, "deivce type not support %d != %d", (uint32_t)device.GetBusType(), (uint32_t)BusType::BUS_TYPE_USB); - if (eventPtr != nullptr) { - eventPtr->message += "device type not support"; - ExtDevReportSysEvent::SetEventValue(interfaceName, DRIVER_DEVICE_MATCH, EDM_NOK, eventPtr); - } return false; } const UsbDriverInfo *usbDriverInfo = static_cast(driver.GetInfoExt().get()); @@ -145,19 +138,11 @@ bool UsbBusExtension::MatchDriver(const DriverInfo &driver, const DeviceInfo &de auto vidFind = find(usbDriverInfo->vids_.begin(), usbDriverInfo->vids_.end(), usbDeviceInfo->idVendor_); if (vidFind == usbDriverInfo->vids_.end()) { EDM_LOGI(MODULE_BUS_USB, "vid not match\n"); - if (eventPtr != nullptr) { - eventPtr->message += "vid not match"; - ExtDevReportSysEvent::SetEventValue(interfaceName, DRIVER_DEVICE_MATCH, EDM_NOK, eventPtr); - } return false; } auto pidFind = find(usbDriverInfo->pids_.begin(), usbDriverInfo->pids_.end(), usbDeviceInfo->idProduct_); if (pidFind == usbDriverInfo->pids_.end()) { EDM_LOGI(MODULE_BUS_USB, "pid not match\n"); - if (eventPtr != nullptr) { - eventPtr->message += "pid not match"; - ExtDevReportSysEvent::SetEventValue(interfaceName, DRIVER_DEVICE_MATCH, EDM_NOK, eventPtr); - } return false; } EDM_LOGI(MODULE_BUS_USB, "Driver and Device match sucess\n"); diff --git a/services/native/driver_extension_manager/src/bus_extension/usb/usb_dev_subscriber.cpp b/services/native/driver_extension_manager/src/bus_extension/usb/usb_dev_subscriber.cpp index 91c4ff5..1a8a8d2 100644 --- a/services/native/driver_extension_manager/src/bus_extension/usb/usb_dev_subscriber.cpp +++ b/services/native/driver_extension_manager/src/bus_extension/usb/usb_dev_subscriber.cpp @@ -57,6 +57,21 @@ static uint64_t ToDdkDeviceId(const UsbDev& usbDev) return ((uint64_t)usbDev.busNum << SHIFT_32) + usbDev.devAddr; } +static uint64_t ToExtDevId(const UsbDev& usbDev) +{ + union DevInfo { + uint64_t deviceId; + struct { + BusType busType; + uint32_t busDeviceId; + } devBusInfo; + } devInfo; + + devInfo.devBusInfo.busType = BusType::BUS_TYPE_USB; + devInfo.devBusInfo.busDeviceId = ToBusDeivceId(usbDev); + + return devInfo.deviceId; +} void UsbDevSubscriber::Init(shared_ptr callback, sptr iusb, sptr iUsbDdk) @@ -114,8 +129,8 @@ int32_t UsbDevSubscriber::GetInterfaceDescriptor(const UsbDev &usbDev, int32_t UsbDevSubscriber::OnDeviceConnect(const UsbDev &usbDev) { - std::shared_ptr eventPtr = std::make_shared(); - std::string interfaceName = std::string(__func__); + std::shared_ptr extDevEvent = std::make_shared(__func__, GET_DEVICE_INFO, + ToExtDevId(usbDev)); int32_t ret = 0; if (this->iusb_ == nullptr) { return EDM_ERR_INVALID_OBJECT; @@ -123,7 +138,7 @@ int32_t UsbDevSubscriber::OnDeviceConnect(const UsbDev &usbDev) ret = this->iusb_->OpenDevice(usbDev); if (ret != EDM_OK) { EDM_LOGE(MODULE_BUS_USB, "OpenDevice failed, ret = %{public}d", ret); - ExtDevReportSysEvent::SetEventValue(interfaceName, GET_DEVICE_INFO, EDM_ERR_IO, eventPtr); + ExtDevReportSysEvent::ReportExternalDeviceEvent(extDevEvent, EDM_ERR_IO, "OpenDevice failed"); return EDM_ERR_IO; } vector descData; @@ -131,51 +146,45 @@ int32_t UsbDevSubscriber::OnDeviceConnect(const UsbDev &usbDev) if (ret != EDM_OK || descData.empty()) { EDM_LOGE(MODULE_BUS_USB, "GetDeviceDescriptor failed, ret = %{public}d", ret); (void)this->iusb_->CloseDevice(usbDev); - ExtDevReportSysEvent::SetEventValue(interfaceName, GET_DEVICE_INFO, EDM_ERR_IO, eventPtr); + ExtDevReportSysEvent::ReportExternalDeviceEvent(extDevEvent, EDM_ERR_IO, "GetDeviceDescriptor failed"); return EDM_ERR_IO; } UsbDevDescLite deviceDescriptor = *(reinterpret_cast(descData.data())); if (deviceDescriptor.bLength != USB_DEV_DESC_SIZE) { EDM_LOGE(MODULE_BUS_USB, "UsbdDeviceDescriptor size error"); (void)this->iusb_->CloseDevice(usbDev); + ExtDevReportSysEvent::ReportExternalDeviceEvent(extDevEvent, EDM_ERR_IO, "UsbdDeviceDescriptor size error"); return EDM_ERR_USB_ERR; } auto usbDevInfo = make_shared(ToBusDeivceId(usbDev), ToDeviceDesc(usbDev, deviceDescriptor)); SetUsbDevInfoValue(deviceDescriptor, usbDevInfo, GetDevStringVal(usbDev, deviceDescriptor.iSerialNumber)); + ExtDevReportSysEvent::ParseToExtDevEvent(usbDevInfo, extDevEvent); ret = GetInterfaceDescriptor(usbDev, usbDevInfo->interfaceDescList_); if (ret != EDM_OK) { EDM_LOGE(MODULE_BUS_USB, "GetInterfaceDescriptor fail, ret = %{public}d", ret); (void)this->iusb_->CloseDevice(usbDev); - eventPtr = ExtDevReportSysEvent::ExtDevEventInit(usbDevInfo, nullptr, eventPtr); - ExtDevReportSysEvent::SetEventValue(interfaceName, GET_DEVICE_INFO, ret, eventPtr); + ExtDevReportSysEvent::ReportExternalDeviceEvent(extDevEvent, EDM_ERR_IO, "GetInterfaceDescriptor failed"); return ret; } - eventPtr = ExtDevReportSysEvent::ExtDevEventInit(usbDevInfo, nullptr, eventPtr); - ExtDevReportSysEvent::DeviceMapInsert(usbDevInfo->GetDeviceId(), eventPtr); + ExtDevReportSysEvent::ReportExternalDeviceEvent(extDevEvent, EDM_OK, "GetDescriptorInfo success"); (void)this->iusb_->CloseDevice(usbDev); if (this->callback_ != nullptr) { this->callback_->OnDeviceAdd(usbDevInfo); } - ExtDevReportSysEvent::SetEventValue(interfaceName, GET_DEVICE_INFO, EDM_OK, eventPtr); return EDM_OK; }; int32_t UsbDevSubscriber::OnDeviceDisconnect(const UsbDev &usbDev) { EDM_LOGD(MODULE_BUS_USB, "OnDeviceDisconnect enter"); - std::shared_ptr eventPtr = std::make_shared(); std::string interfaceName = std::string(__func__); if (this->callback_ != nullptr) { uint32_t busDevId = ToBusDeivceId(usbDev); auto deviceInfo = make_shared(busDevId); if (deviceInfo != nullptr) { - eventPtr = ExtDevReportSysEvent::DeviceEventReport(deviceInfo->GetDeviceId()); this->callback_->OnDeviceRemove(deviceInfo); - ExtDevReportSysEvent::DeviceMapErase(deviceInfo->GetDeviceId()); - ExtDevReportSysEvent::SetEventValue(interfaceName, GET_DEVICE_INFO, EDM_OK, eventPtr); } else { EDM_LOGE(MODULE_BUS_USB, "deviceInfo is nullptr"); - ExtDevReportSysEvent::SetEventValue(interfaceName, GET_DEVICE_INFO, EDM_NOK, eventPtr); } } return 0; 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 0fcfb43..f6f9e28 100644 --- a/services/native/driver_extension_manager/src/device_manager/device.cpp +++ b/services/native/driver_extension_manager/src/device_manager/device.cpp @@ -62,8 +62,6 @@ int32_t Device::Connect() { EDM_LOGI(MODULE_DEV_MGR, "%{public}s enter", __func__); std::lock_guard lock(deviceMutex_); - std::shared_ptr eventPtr = std::make_shared(); - std::string interfaceName = std::string(__func__); uint32_t busDevId = GetDeviceInfo()->GetBusDevId(); std::string bundleInfo = GetBundleInfo(); std::string bundleName = Device::GetBundleName(bundleInfo); @@ -89,28 +87,23 @@ int32_t Device::Connect() } if (ret != UsbErrCode::EDM_OK) { EDM_LOGE(MODULE_DEV_MGR, "failed to connect driver extension"); - eventPtr = ExtDevReportSysEvent::ExtDevEventInit(GetDeviceInfo(), GetDriverInfo(), eventPtr); - ExtDevReportSysEvent::SetEventValue(interfaceName, DRIVER_PACKAGE_CYCLE_MANAGE, ret, eventPtr); - return ret; } - return UsbErrCode::EDM_OK; + return ret; } int32_t Device::Connect(const sptr &connectCallback, uint32_t callingTokenId) { EDM_LOGI(MODULE_DEV_MGR, "%{public}s enter", __func__); std::lock_guard lock(deviceMutex_); - std::shared_ptr eventPtr = std::make_shared(); - eventPtr = ExtDevReportSysEvent::DeviceEventReport(GetDeviceInfo()->GetDeviceId()); - std::string interfaceName = std::string(__func__); + auto extDevEvent = std::make_shared(__func__, DRIVER_BIND); + ExtDevReportSysEvent::ParseToExtDevEvent(GetDeviceInfo(), GetDriverInfo(), extDevEvent); if (drvExtRemote_ != nullptr) { connectCallback->OnConnect(GetDeviceInfo()->GetDeviceId(), drvExtRemote_, {UsbErrCode::EDM_OK, ""}); int32_t ret = RegisterDrvExtMgrCallback(connectCallback); if (ret != UsbErrCode::EDM_OK) { EDM_LOGE(MODULE_DEV_MGR, "failed to register callback object"); - if (eventPtr != nullptr) { - ExtDevReportSysEvent::SetEventValue(interfaceName, DRIVER_BIND, ret, eventPtr); - } + ExtDevReportSysEvent::ReportExternalDeviceEvent(extDevEvent, UsbErrCode::EDM_ERR_INVALID_OBJECT, + "failed to register callback object"); return ret; } boundCallerInfos_[callingTokenId] = CallerInfo{true}; @@ -120,9 +113,8 @@ int32_t Device::Connect(const sptr &connectCallback, uint int32_t ret = RegisterDrvExtMgrCallback(connectCallback); if (ret != UsbErrCode::EDM_OK) { EDM_LOGE(MODULE_DEV_MGR, "failed to register callback object"); - if (eventPtr != nullptr) { - ExtDevReportSysEvent::SetEventValue(interfaceName, DRIVER_BIND, ret, eventPtr); - } + ExtDevReportSysEvent::ReportExternalDeviceEvent(extDevEvent, UsbErrCode::EDM_ERR_INVALID_OBJECT, + "failed to register callback object"); return ret; } @@ -139,17 +131,24 @@ int32_t Device::Connect(const sptr &connectCallback, uint EDM_LOGE(MODULE_DEV_MGR, "failed to connect driver extension"); UnregisterDrvExtMgrCallback(connectCallback); boundCallerInfos_.erase(callingTokenId); - return ret; } - return UsbErrCode::EDM_OK; + ExtDevReportSysEvent::ReportExternalDeviceEvent(extDevEvent, ret, + ret != UsbErrCode::EDM_OK ? "failed to connect driver extension" : ""); + return ret; } -int32_t Device::Disconnect() +int32_t Device::Disconnect(const bool isFromBind) { - EDM_LOGI(MODULE_DEV_MGR, "%{public}s enter", __func__); + EDM_LOGI(MODULE_DEV_MGR, "%{public}s enter, isFromBind:%{public}d", __func__, isFromBind); std::lock_guard lock(deviceMutex_); + auto extDevEvent = std::make_shared(__func__, DRIVER_UNBIND); + ExtDevReportSysEvent::ParseToExtDevEvent(GetDeviceInfo(), GetDriverInfo(), extDevEvent); if (connectNofitier_ != nullptr && connectNofitier_->IsInvalidDrvExtConnectionInfo()) { EDM_LOGI(MODULE_DEV_MGR, "driver extension has been disconnected"); + if (isFromBind) { + ExtDevReportSysEvent::ReportExternalDeviceEvent(extDevEvent, UsbErrCode::EDM_OK, + "driver extension has been disconnected"); + } return UsbErrCode::EDM_OK; } uint32_t busDevId = GetDeviceInfo()->GetBusDevId(); @@ -160,10 +159,13 @@ int32_t Device::Disconnect() bundleName, abilityName, connectNofitier_, busDevId); if (ret != UsbErrCode::EDM_OK) { EDM_LOGE(MODULE_DEV_MGR, "failed to disconnect driver extension"); - return ret; + } + if (isFromBind) { + ExtDevReportSysEvent::ReportExternalDeviceEvent(extDevEvent, ret, + ret != UsbErrCode::EDM_OK ? "failed to disconnect driver extension" : ""); } - return UsbErrCode::EDM_OK; + return ret; } void Device::OnConnect(const sptr &remote, int resultCode) diff --git a/services/native/driver_extension_manager/src/device_manager/driver_extension_controller.cpp b/services/native/driver_extension_manager/src/device_manager/driver_extension_controller.cpp index 008e1c8..2560cb6 100644 --- a/services/native/driver_extension_manager/src/device_manager/driver_extension_controller.cpp +++ b/services/native/driver_extension_manager/src/device_manager/driver_extension_controller.cpp @@ -18,7 +18,6 @@ #include "ability_connect_callback_stub.h" #include "edm_errors.h" #include "driver_extension_controller.h" -#include "driver_report_sys_event.h" namespace OHOS { namespace ExternalDeviceManager { using namespace std; @@ -120,10 +119,6 @@ int32_t DriverExtensionController::ConnectDriverExtension( { EDM_LOGI(MODULE_EA_MGR, "Begin to Connect DriverExtension, bundle:%{public}s, ability:%{public}s", \ bundleName.c_str(), abilityName.c_str()); - - std::string interfaceName = std::string(__func__); - std::shared_ptr eventPtr = make_shared(); - eventPtr = ExtDevReportSysEvent::DeviceEventReport(deviceId); if (callback == nullptr) { EDM_LOGE(MODULE_EA_MGR, "param callback is nullptr"); return EDM_ERR_INVALID_PARAM; @@ -142,7 +137,6 @@ int32_t DriverExtensionController::ConnectDriverExtension( auto abmc = AAFwk::AbilityManagerClient::GetInstance(); if (abmc == nullptr) { EDM_LOGE(MODULE_EA_MGR, "Get AMC Instance failed"); - ExtDevReportSysEvent::SetEventValue(interfaceName, DRIVER_BIND, EDM_ERR_INVALID_OBJECT, eventPtr); return EDM_ERR_INVALID_OBJECT; } AAFwk::Want want; @@ -151,9 +145,6 @@ int32_t DriverExtensionController::ConnectDriverExtension( auto ret = abmc->ConnectAbility(want, callback->info_->connectInner_, -1); if (ret != 0) { EDM_LOGE(MODULE_EA_MGR, "ConnectExtensionAbility failed %{public}d", ret); - if (eventPtr != nullptr) { - ExtDevReportSysEvent::SetEventValue(interfaceName, DRIVER_BIND, ret, eventPtr); - } return ret; } @@ -169,10 +160,6 @@ int32_t DriverExtensionController::DisconnectDriverExtension( { EDM_LOGI(MODULE_EA_MGR, "Begin to Disconnect DriverExtension, bundle:%{public}s, ability:%{public}s", \ bundleName.c_str(), abilityName.c_str()); - - std::shared_ptr eventPtr = make_shared(); - std::string interfaceName = std::string(__func__); - eventPtr = ExtDevReportSysEvent::MatchEventReport(deviceId); if (callback == nullptr) { EDM_LOGE(MODULE_EA_MGR, "param callback is nullptr"); return EDM_ERR_INVALID_PARAM; @@ -190,16 +177,11 @@ int32_t DriverExtensionController::DisconnectDriverExtension( auto abmc = AAFwk::AbilityManagerClient::GetInstance(); if (abmc == nullptr) { EDM_LOGE(MODULE_EA_MGR, "Get AMC Instance failed"); - ExtDevReportSysEvent::SetEventValue(interfaceName, DRIVER_BIND, EDM_ERR_INVALID_OBJECT, eventPtr); return EDM_ERR_INVALID_OBJECT; } auto ret = abmc->DisconnectAbility(callback->info_->connectInner_); if (ret != 0) { EDM_LOGE(MODULE_EA_MGR, "DisconnectExtensionAbility failed %{public}d", ret); - - if (eventPtr != nullptr) { - ExtDevReportSysEvent::SetEventValue(interfaceName, DRIVER_BIND, ret, eventPtr); - } return ret; } EDM_LOGI(MODULE_EA_MGR, "DisconnectExtensionAbility success"); 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 9595ab7..8c80bc8 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 @@ -141,7 +141,7 @@ int32_t ExtDeviceManager::RemoveDevIdOfBundleInfoMap(shared_ptr device, bundleMatchMap_.erase(pos); // stop ability and destory sa - int32_t ret = device->Disconnect(); + int32_t ret = device->Disconnect(false); if (ret != EDM_OK) { EDM_LOGE(MODULE_DEV_MGR, "deviceId[%{public}016" PRIX64 "] disconnect driver extension ability[%{public}s] failed[%{public}d]", @@ -272,25 +272,41 @@ void ExtDeviceManager::MatchDriverInfos(std::unordered_set deviceIds) void ExtDeviceManager::ClearMatchedDrivers(const int32_t userId) { - EDM_LOGI(MODULE_DEV_MGR, "ClearMatchedDrivers start"); - lock_guard lock(bundleMatchMapMutex_); - for (auto iter : bundleMatchMap_) { - std::string bundleInfo = iter.first; - (void)DriverExtensionController::GetInstance().StopDriverExtension(Device::GetBundleName(bundleInfo), - Device::GetAbilityName(bundleInfo), userId); - } - bundleMatchMap_.clear(); - + EDM_LOGI(MODULE_DEV_MGR, "ClearMatchedDrivers start, userId: %{public}d", userId); lock_guard deviceMapLock(deviceMapMutex_); for (auto &m : deviceMap_) { for (auto &[_, device] : m.second) { - if (device != nullptr && !device->IsUnRegisted()) { - device->RemoveBundleInfo(); - device->ClearDrvExtRemote(); - RemoveDriverInfo(device); + if (device == nullptr || device->IsUnRegisted() || !device->HasDriver() || + device->GetDriverInfo() == nullptr || device->GetDriverInfo()->GetUserId() != userId) { + continue; } + auto bundleInfo = device->GetBundleInfo(); + lock_guard lock(bundleMatchMapMutex_); + if (bundleMatchMap_.find(bundleInfo) == bundleMatchMap_.end()) { + EDM_LOGD(MODULE_DEV_MGR, "bundleInfo[%{public}s] has removed", bundleInfo.c_str()); + continue; + } + + auto driverInfo = device->GetDriverInfo(); + auto extDevEvent = std::make_shared(__func__, CHANGE_FUNC); + ExtDevReportSysEvent::ParseToExtDevEvent(device->GetDeviceInfo(), driverInfo, extDevEvent); + auto ret = DriverExtensionController::GetInstance().StopDriverExtension(driverInfo->GetBundleName(), + driverInfo->GetDriverName(), userId); + if (ret != EDM_OK) { + ExtDevReportSysEvent::ReportExternalDeviceEvent(extDevEvent, ret, "StopDriverExtension failed"); + EDM_LOGE(MODULE_DEV_MGR, "StopDriverExtension failed, ret=%{public}d", ret); + } else { + ExtDevReportSysEvent::ReportExternalDeviceEvent(extDevEvent, EDM_OK, "StopDriverExtension success"); + EDM_LOGI(MODULE_DEV_MGR, "StopDriverExtension success"); + } + bundleMatchMap_.erase(bundleInfo); + device->RemoveBundleInfo(); + device->ClearDrvExtRemote(); + RemoveDriverInfo(device); } } + lock_guard lock(bundleMatchMapMutex_); + bundleMatchMap_.clear(); } int32_t ExtDeviceManager::RegisterDevice(shared_ptr devInfo) @@ -528,10 +544,6 @@ int32_t ExtDeviceManager::ConnectDevice(uint64_t deviceId, uint32_t callingToken std::shared_ptr device = QueryDeviceByDeviceID(deviceId); if (device == nullptr) { EDM_LOGI(MODULE_DEV_MGR, "failed to find device with %{public}016" PRIX64 " deviceId", deviceId); - std::shared_ptr eventPtr = std::make_shared(); - eventPtr->deviceId = deviceId; - std::string interfaceName = std::string(__func__); - ExtDevReportSysEvent::SetEventValue(interfaceName, DRIVER_BIND, EDM_NOK, eventPtr); return EDM_NOK; } @@ -540,26 +552,19 @@ int32_t ExtDeviceManager::ConnectDevice(uint64_t deviceId, uint32_t callingToken int32_t ExtDeviceManager::DisConnectDevice(uint64_t deviceId, uint32_t callingTokenId) { + auto extDevEvent = std::make_shared(__func__, DRIVER_UNBIND); lock_guard lock(deviceMapMutex_); std::shared_ptr device = QueryDeviceByDeviceID(deviceId); if (device == nullptr) { EDM_LOGI(MODULE_DEV_MGR, "failed to find device with %{public}016" PRIX64 " deviceId", deviceId); - std::shared_ptr eventPtr = std::make_shared(); - eventPtr->deviceId = deviceId; - std::string interfaceName = std::string(__func__); - ExtDevReportSysEvent::SetEventValue(interfaceName, DRIVER_UNBIND, EDM_NOK, eventPtr); return EDM_NOK; } + ExtDevReportSysEvent::ParseToExtDevEvent(device->GetDeviceInfo(), device->GetDriverInfo(), extDevEvent); std::shared_ptr driverInfo = device->GetDriverInfo(); if (driverInfo == nullptr) { EDM_LOGE(MODULE_DEV_MGR, "failed to find driverInfo for device with %{public}016" PRIX64 " deviceId", deviceId); - std::shared_ptr eventPtr = make_shared(); - eventPtr = ExtDevReportSysEvent::DeviceEventReport(deviceId); - if (eventPtr != nullptr) { - std::string interfaceName = std::string(__func__); - ExtDevReportSysEvent::SetEventValue(interfaceName, DRIVER_UNBIND, EDM_NOK, eventPtr); - } + ExtDevReportSysEvent::ReportExternalDeviceEvent(extDevEvent, EDM_NOK, "failed to find driverInfo"); return EDM_NOK; } @@ -567,9 +572,11 @@ int32_t ExtDeviceManager::DisConnectDevice(uint64_t deviceId, uint32_t callingTo device->RemoveCaller(callingTokenId); EDM_LOGI(MODULE_DEV_MGR, "driver not launching on bind or other client bound. Removing caller ID: %{public}u", callingTokenId); + ExtDevReportSysEvent::ReportExternalDeviceEvent(extDevEvent, EDM_OK, + "driver not launching on bind or other client bound"); return EDM_OK; } - return device->Disconnect(); + return device->Disconnect(true); } int32_t ExtDeviceManager::ConnectDriverWithDeviceId(uint64_t deviceId, uint32_t callingTokenId, @@ -586,6 +593,9 @@ int32_t ExtDeviceManager::ConnectDriverWithDeviceId(uint64_t deviceId, uint32_t int32_t ret = CheckAccessPermission(device->GetDriverInfo(), accessibleBundles); if (ret != EDM_OK) { EDM_LOGE(MODULE_DEV_MGR, "failed to bind device verification with %{public}016" PRIX64 " deviceId", deviceId); + auto extDevEvent = std::make_shared(__func__, DRIVER_BIND); + ExtDevReportSysEvent::ParseToExtDevEvent(device->GetDeviceInfo(), device->GetDriverInfo(), extDevEvent); + ExtDevReportSysEvent::ReportExternalDeviceEvent(extDevEvent, ret, "failed to bind device verification"); return ret; } return device->Connect(connectCallback, callingTokenId); @@ -593,6 +603,7 @@ int32_t ExtDeviceManager::ConnectDriverWithDeviceId(uint64_t deviceId, uint32_t int32_t ExtDeviceManager::DisConnectDriverWithDeviceId(uint64_t deviceId, uint32_t callingTokenId) { + auto extDevEvent = std::make_shared(__func__, DRIVER_UNBIND); lock_guard lock(deviceMapMutex_); std::shared_ptr device = QueryDeviceByDeviceID(deviceId); if (device == nullptr) { @@ -600,14 +611,19 @@ int32_t ExtDeviceManager::DisConnectDriverWithDeviceId(uint64_t deviceId, uint32 return EDM_NOK; } + ExtDevReportSysEvent::ParseToExtDevEvent(device->GetDeviceInfo(), device->GetDriverInfo(), extDevEvent); + if (!device->IsBindCaller(callingTokenId)) { EDM_LOGE(MODULE_DEV_MGR, "can not find binding relationship by %{public}u callerTokenId", callingTokenId); + ExtDevReportSysEvent::ReportExternalDeviceEvent(extDevEvent, EDM_ERR_SERVICE_NOT_BOUND, + "can not find binding relationship"); return EDM_ERR_SERVICE_NOT_BOUND; } std::shared_ptr driverInfo = device->GetDriverInfo(); if (driverInfo == nullptr) { EDM_LOGE(MODULE_DEV_MGR, "failed to find driverInfo for device with %{public}016" PRIX64 " deviceId", deviceId); + ExtDevReportSysEvent::ReportExternalDeviceEvent(extDevEvent, EDM_NOK, "failed to find driverInfo"); return EDM_NOK; } @@ -615,9 +631,11 @@ int32_t ExtDeviceManager::DisConnectDriverWithDeviceId(uint64_t deviceId, uint32 device->RemoveCaller(callingTokenId); EDM_LOGI(MODULE_DEV_MGR, "driver not launching on bind or other client bound. Removing caller ID: %{public}u", callingTokenId); + ExtDevReportSysEvent::ReportExternalDeviceEvent(extDevEvent, EDM_OK, + "driver not launching on bind or other client bound"); return EDM_OK; } - return device->Disconnect(); + return device->Disconnect(true); } void ExtDeviceManager::SetDriverChangeCallback(shared_ptr &driverChangeCallback) diff --git a/services/native/driver_extension_manager/src/driver_ext_mgr.cpp b/services/native/driver_extension_manager/src/driver_ext_mgr.cpp index a1c410a..334346a 100644 --- a/services/native/driver_extension_manager/src/driver_ext_mgr.cpp +++ b/services/native/driver_extension_manager/src/driver_ext_mgr.cpp @@ -28,7 +28,6 @@ #include "system_ability_definition.h" #include "usb_device_info.h" #include "usb_driver_info.h" -#include "driver_report_sys_event.h" namespace OHOS { namespace ExternalDeviceManager { @@ -169,12 +168,6 @@ ErrCode DriverExtMgr::BindDevice(int32_t &errorCode, uint64_t deviceId, UsbErrCode ret = static_cast(ExtDeviceManager::GetInstance().ConnectDevice(deviceId, callingTokenId, connectCallback)); if (ret == UsbErrCode::EDM_OK) { - std::shared_ptr eventPtr = std::make_shared(); - eventPtr = ExtDevReportSysEvent::MatchEventReport(deviceId); - std::string interfaceName = std::string(__func__); - if (eventPtr != nullptr) { - ExtDevReportSysEvent::SetEventValue(interfaceName, DRIVER_BIND, ret, eventPtr); - } errorCode = static_cast(ret); return static_cast(UsbErrCode::EDM_OK); } @@ -193,17 +186,6 @@ ErrCode DriverExtMgr::UnBindDevice(int32_t &errorCode, uint64_t deviceId) uint32_t callingTokenId = ExtPermissionManager::GetCallingTokenID(); auto ret = static_cast(ExtDeviceManager::GetInstance().DisConnectDevice(deviceId, callingTokenId)); - if (ret == UsbErrCode::EDM_OK) { - std::shared_ptr eventPtr = std::make_shared(); - eventPtr = ExtDevReportSysEvent::MatchEventReport(deviceId); - std::string interfaceName = std::string(__func__); - if (eventPtr != nullptr) { - ExtDevReportSysEvent::SetEventValue(interfaceName, DRIVER_UNBIND, ret, eventPtr); - } - ExtDevReportSysEvent::MatchMapErase(deviceId); - errorCode = static_cast(ret); - return static_cast(UsbErrCode::EDM_OK); - } errorCode = static_cast(ret); return static_cast(UsbErrCode::EDM_OK); } diff --git a/services/native/driver_extension_manager/src/drivers_hisysevent/driver_report_sys_event.cpp b/services/native/driver_extension_manager/src/drivers_hisysevent/driver_report_sys_event.cpp index 9b98468..3e292c6 100644 --- a/services/native/driver_extension_manager/src/drivers_hisysevent/driver_report_sys_event.cpp +++ b/services/native/driver_extension_manager/src/drivers_hisysevent/driver_report_sys_event.cpp @@ -26,8 +26,6 @@ using namespace OHOS::HiviewDFX; namespace OHOS { namespace ExternalDeviceManager { -std::map> ExtDevReportSysEvent::matchMap_; -std::map> ExtDevReportSysEvent::deviceMap_; std::map> ExtDevReportSysEvent::driverMap_; std::mutex ExtDevReportSysEvent::hisyseventMutex_; constexpr int LAST_FIVE = 5; @@ -66,11 +64,11 @@ void ExtDevReportSysEvent::ReportDelPkgsCycleManageSysEvent(const std::string &b } } -void ExtDevReportSysEvent::ReportExternalDeviceEvent(const std::shared_ptr& extDevEvent) +void ExtDevReportSysEvent::ReportExternalDeviceEvent(const std::shared_ptr &extDevEvent) { EDM_LOGI(MODULE_PKG_MGR, "report external device event"); if (extDevEvent == nullptr) { - EDM_LOGI(MODULE_PKG_MGR, "extDevEvent is null"); + EDM_LOGI(MODULE_PKG_MGR, "%{public}s, extDevEvent is null", __func__); return; } std::string snNum = ""; @@ -92,6 +90,19 @@ void ExtDevReportSysEvent::ReportExternalDeviceEvent(const std::shared_ptr &extDevEvent, + const int32_t errCode, const std::string &message) +{ + EDM_LOGI(MODULE_PKG_MGR, "report external device event with error code"); + if (extDevEvent == nullptr) { + EDM_LOGI(MODULE_PKG_MGR, "%{public}s, extDevEvent is null", __func__); + return; + } + extDevEvent->errCode = errCode; + extDevEvent->message = message; + ReportExternalDeviceEvent(extDevEvent); +} + void ExtDevReportSysEvent::ReportExternalDeviceSaEvent(const PkgInfoTable &pkgInfoTable, std::string pids, std::string vids, uint32_t versionCode, std::string driverEventName) { @@ -105,83 +116,63 @@ void ExtDevReportSysEvent::ReportExternalDeviceSaEvent(const PkgInfoTable &pkgIn } } - -std::shared_ptr ExtDevReportSysEvent::ExtDevEventInit(const std::shared_ptr &deviceInfo, - const std::shared_ptr &driverInfo, std::shared_ptr eventObj) +void ExtDevReportSysEvent::ParseToExtDevEvent(const std::shared_ptr &deviceInfo, + const std::shared_ptr &eventObj) { - if (deviceInfo != nullptr) { - auto busType = deviceInfo->GetBusType(); - switch (busType) { - case BusType::BUS_TYPE_USB:{ - std::shared_ptr usbDeviceInfo = std::static_pointer_cast(deviceInfo); - eventObj->deviceId = usbDeviceInfo->GetDeviceId(); - eventObj->deviceClass = usbDeviceInfo->GetDeviceClass(); - eventObj->deviceSubClass = usbDeviceInfo->GetDeviceSubClass(); - eventObj->deviceProtocol = usbDeviceInfo->GetDeviceProtocol(); - eventObj->snNum = usbDeviceInfo->GetSnNum(); - eventObj->vendorId = usbDeviceInfo->GetVendorId(); - eventObj->productId = usbDeviceInfo->GetProductId(); - break; - } - default: - break; - } + if (deviceInfo == nullptr || eventObj == nullptr) { + return; } - - if (driverInfo != nullptr) { - auto busType = driverInfo->GetBusType(); - switch (busType) { - case BusType::BUS_TYPE_USB:{ - std::shared_ptr usbDriverInfo = - std::static_pointer_cast(driverInfo->GetInfoExt()); - std::vector productIds = usbDriverInfo->GetProductIds(); - std::vector vendorIds = usbDriverInfo->GetVendorIds(); - eventObj->vids = ParseIdVector(vendorIds); - eventObj->pids = ParseIdVector(productIds); - eventObj->driverUid = driverInfo->GetDriverUid(); - eventObj->driverName = driverInfo->GetDriverName(); - eventObj->versionCode = driverInfo->GetVersion(); - eventObj->bundleName = driverInfo->GetBundleName(); - break; - } - default: - break; + switch (deviceInfo->GetBusType()) { + case BusType::BUS_TYPE_USB:{ + std::shared_ptr usbDeviceInfo = std::static_pointer_cast(deviceInfo); + eventObj->deviceId = usbDeviceInfo->GetDeviceId(); + eventObj->deviceClass = usbDeviceInfo->GetDeviceClass(); + eventObj->deviceSubClass = usbDeviceInfo->GetDeviceSubClass(); + eventObj->deviceProtocol = usbDeviceInfo->GetDeviceProtocol(); + eventObj->snNum = usbDeviceInfo->GetSnNum(); + eventObj->vendorId = usbDeviceInfo->GetVendorId(); + eventObj->productId = usbDeviceInfo->GetProductId(); + break; } + default: + break; } - return eventObj; } -bool ExtDevReportSysEvent::IsMatched(const std::shared_ptr &deviceInfo, - const std::shared_ptr &driverInfo, const std::string &type, const std::string &interfaceName) +void ExtDevReportSysEvent::ParseToExtDevEvent(const std::shared_ptr &driverInfo, + const std::shared_ptr &eventObj) { - if (deviceInfo != nullptr && driverInfo != nullptr) { - std::lock_guard lock(hisyseventMutex_); - std::shared_ptr matchPtr = std::make_shared(); - auto device = deviceMap_.find(deviceInfo->GetDeviceId()); - auto driver = driverMap_.find(driverInfo->GetDriverUid()); - if (device != deviceMap_.end() && driver != driverMap_.end()) { - matchPtr = ExtDevReportSysEvent::ExtDevEventInit(deviceInfo, driverInfo, matchPtr); - matchPtr->message = type; - ExtDevReportSysEvent::SetEventValue(interfaceName, DRIVER_DEVICE_MATCH, EDM_OK, matchPtr); - matchMap_[deviceInfo->GetDeviceId()] = matchPtr; - return true; + if (driverInfo == nullptr || eventObj == nullptr) { + return; + } + switch (driverInfo->GetBusType()) { + case BusType::BUS_TYPE_USB:{ + std::shared_ptr usbDriverInfo = + std::static_pointer_cast(driverInfo->GetInfoExt()); + std::vector productIds = usbDriverInfo->GetProductIds(); + std::vector vendorIds = usbDriverInfo->GetVendorIds(); + eventObj->vids = ParseIdVector(vendorIds); + eventObj->pids = ParseIdVector(productIds); + eventObj->driverUid = driverInfo->GetDriverUid(); + eventObj->userId = driverInfo->GetUserId(); + eventObj->driverName = driverInfo->GetDriverName(); + eventObj->versionCode = driverInfo->GetVersion(); + eventObj->bundleName = driverInfo->GetBundleName(); + break; } + default: + break; } - return false; } -std::shared_ptr ExtDevReportSysEvent::DeviceEventReport(const uint64_t deviceId, - const std::string &message) +void ExtDevReportSysEvent::ParseToExtDevEvent(const std::shared_ptr &deviceInfo, + const std::shared_ptr &driverInfo, const std::shared_ptr &eventObj) { - std::lock_guard lock(hisyseventMutex_); - if (auto it = deviceMap_.find(deviceId); it != deviceMap_.end()) { - auto &deviceEvent = it->second; - if (deviceEvent != nullptr) { - deviceEvent->message = message; - } - return deviceEvent; + if (deviceInfo == nullptr || driverInfo == nullptr || eventObj == nullptr) { + return; } - return nullptr; + ExtDevReportSysEvent::ParseToExtDevEvent(deviceInfo, eventObj); + ExtDevReportSysEvent::ParseToExtDevEvent(driverInfo, eventObj); } std::shared_ptr ExtDevReportSysEvent::DriverEventReport(const std::string driverUid) @@ -196,18 +187,6 @@ std::shared_ptr ExtDevReportSysEvent::DriverEventReport(const std:: return nullptr; } -std::shared_ptr ExtDevReportSysEvent::MatchEventReport(const uint64_t deviceId) -{ - std::lock_guard lock(hisyseventMutex_); - std::shared_ptr matchPtr = std::make_shared(); - auto match = matchMap_.find(deviceId); - if (match != matchMap_.end()) { - matchPtr = match->second; - return matchPtr; - } - return nullptr; -} - void ExtDevReportSysEvent::SetEventValue(const std::string interfaceName, const int32_t operatType, const int32_t errCode, std::shared_ptr eventPtr) { @@ -227,14 +206,6 @@ void ExtDevReportSysEvent::DriverMapInsert(const std::string driverUid, std::sha } } -void ExtDevReportSysEvent::DeviceMapInsert(const uint64_t deviceId, std::shared_ptr eventPtr) -{ - if (eventPtr != nullptr) { - std::lock_guard lock(hisyseventMutex_); - deviceMap_[deviceId] = eventPtr; - } -} - void ExtDevReportSysEvent::DriverMapErase(const std::string driverUid) { std::lock_guard lock(hisyseventMutex_); @@ -257,18 +228,6 @@ void ExtDevReportSysEvent::DriverMapDelete(const std::string &bundleName) } } -void ExtDevReportSysEvent::DeviceMapErase(const uint64_t deviceId) -{ - std::lock_guard lock(hisyseventMutex_); - deviceMap_.erase(deviceId); -} - -void ExtDevReportSysEvent::MatchMapErase(const uint64_t deviceId) -{ - std::lock_guard lock(hisyseventMutex_); - matchMap_.erase(deviceId); -} - std::string ExtDevReportSysEvent::ParseIdVector(std::vector ids) { if (ids.size() < 1) { diff --git a/services/native/driver_extension_manager/src/drivers_pkg_manager/driver_os_account_subscriber.cpp b/services/native/driver_extension_manager/src/drivers_pkg_manager/driver_os_account_subscriber.cpp index 4b563b7..d5b40a5 100644 --- a/services/native/driver_extension_manager/src/drivers_pkg_manager/driver_os_account_subscriber.cpp +++ b/services/native/driver_extension_manager/src/drivers_pkg_manager/driver_os_account_subscriber.cpp @@ -34,12 +34,6 @@ void DriverOsAccountSwitched::OnAccountsChanged(const int &id) void DriverOsAccountSwitched::OnAccountsSwitch(const int &newId, const int &oldId) { EDM_LOGI(MODULE_PKG_MGR, "OnAccountsSwitched, newId=%{public}d, oldId=%{public}d", newId, oldId); - std::shared_ptr eventPtr = std::make_shared(); - std::string lastId = std::to_string(oldId); - std::string nextId = std::to_string(newId); - eventPtr->message = "oldId:" + lastId + "newId:" + nextId; - std::string interfaceName = std::string(__func__); - ExtDevReportSysEvent::SetEventValue(interfaceName, CHANGE_FUNC, 0, eventPtr); if (bundleStateCallback_ == nullptr) { EDM_LOGE(MODULE_PKG_MGR, "OnAccountsSwitched bundleStateCallback_ is null"); return; diff --git a/services/native/driver_extension_manager/src/drivers_pkg_manager/driver_pkg_manager.cpp b/services/native/driver_extension_manager/src/drivers_pkg_manager/driver_pkg_manager.cpp index ca27aef..a9c9844 100644 --- a/services/native/driver_extension_manager/src/drivers_pkg_manager/driver_pkg_manager.cpp +++ b/services/native/driver_extension_manager/src/drivers_pkg_manager/driver_pkg_manager.cpp @@ -113,14 +113,7 @@ bool DriverPkgManager::SubscribeOsAccountSwitch() shared_ptr DriverPkgManager::QueryMatchDriver(shared_ptr devInfo, const std::string &type) { - EDM_LOGI(MODULE_PKG_MGR, "Enter QueryMatchDriver"); - std::shared_ptr eventPtr = std::make_shared(); - eventPtr = ExtDevReportSysEvent::DeviceEventReport(devInfo->GetDeviceId()); - if (eventPtr != nullptr) { - eventPtr->message = type; - } - std::string interfaceName = std::string(__func__); - shared_ptr extInstance = nullptr; + EDM_LOGI(MODULE_PKG_MGR, "Enter QueryMatchDriver %{public}s", type.c_str()); if (bundleStateCallback_ == nullptr) { EDM_LOGE(MODULE_PKG_MGR, "QueryMatchDriver bundleStateCallback_ null"); return nullptr; @@ -128,38 +121,37 @@ shared_ptr DriverPkgManager::QueryMatchDriver(shared_ptr if (!bundleStateCallback_->GetAllDriverInfos()) { EDM_LOGE(MODULE_PKG_MGR, "QueryMatchDriver GetAllDriverInfos Err"); - if (eventPtr != nullptr) { - eventPtr->message += "QueryMatchDriver GetAllDriverInfos Err"; - ExtDevReportSysEvent::SetEventValue(interfaceName, DRIVER_DEVICE_MATCH, EDM_NOK, eventPtr); - } return nullptr; } - + auto extDevEvent = std::make_shared(__func__, DRIVER_DEVICE_MATCH); + ExtDevReportSysEvent::ParseToExtDevEvent(devInfo, extDevEvent); std::vector pkgInfos; std::shared_ptr helper = PkgDbHelper::GetInstance(); int32_t retRdb = helper->QueryPkgInfos(pkgInfos); - if (retRdb <= 0) { - /* error or empty record */ - if (eventPtr != nullptr) { - eventPtr->message += (retRdb < 0 ? "QueryPkgInfos err" : "pkgTable is empty"); - ExtDevReportSysEvent::SetEventValue(interfaceName, DRIVER_DEVICE_MATCH, EDM_NOK, eventPtr); - } + if (retRdb < 0) { + EDM_LOGE(MODULE_PKG_MGR, "QueryMatchDriver QueryPkgInfos failed"); + ExtDevReportSysEvent::ReportExternalDeviceEvent(extDevEvent, EDM_NOK, "QueryPkgInfos failed"); + return nullptr; + } else if (retRdb == 0) { + EDM_LOGD(MODULE_PKG_MGR, "QueryMatchDriver no driver installed"); + ExtDevReportSysEvent::ReportExternalDeviceEvent(extDevEvent, EDM_NOK, "no driver installed"); return nullptr; } EDM_LOGI(MODULE_PKG_MGR, "Total driverInfos number: %{public}zu", pkgInfos.size()); + shared_ptr extInstance = nullptr; for (const auto &pkgInfo : pkgInfos) { - DriverInfo driverInfo(pkgInfo.bundleName, pkgInfo.driverName, pkgInfo.driverUid); + DriverInfo driverInfo(pkgInfo.bundleName, pkgInfo.driverName, pkgInfo.driverUid, pkgInfo.userId); driverInfo.UnSerialize(pkgInfo.driverInfo); extInstance = BusExtensionCore::GetInstance().GetBusExtensionByName(driverInfo.GetBusName()); if (extInstance != nullptr && extInstance->MatchDriver(driverInfo, *devInfo, type)) { std::shared_ptr driverPtr= std::make_shared(driverInfo); - if (!ExtDevReportSysEvent::IsMatched(devInfo, driverPtr, type, interfaceName)) { - EDM_LOGI(MODULE_PKG_MGR, "IsMatched failed"); - } - return std::make_shared(driverInfo); + ExtDevReportSysEvent::ParseToExtDevEvent(driverPtr, extDevEvent); + ExtDevReportSysEvent::ReportExternalDeviceEvent(extDevEvent, EDM_OK, "MatchDriver success"); + return driverPtr; } } EDM_LOGI(MODULE_PKG_MGR, "QueryMatchDriver return null"); + ExtDevReportSysEvent::ReportExternalDeviceEvent(extDevEvent, EDM_NOK, "no driver match"); return nullptr; } @@ -186,7 +178,7 @@ int32_t DriverPkgManager::QueryDriverInfo(vector> &driver } for (const auto &pkgInfo : pkgInfos) { std::shared_ptr driverInfo - = std::make_shared(pkgInfo.bundleName, pkgInfo.driverName, pkgInfo.driverUid); + = std::make_shared(pkgInfo.bundleName, pkgInfo.driverName, pkgInfo.driverUid, pkgInfo.userId); if (driverInfo->UnSerialize(pkgInfo.driverInfo) != EDM_OK) { return EDM_NOK; } diff --git a/utils/include/ext_object.h b/utils/include/ext_object.h index 4de810a..aab1370 100644 --- a/utils/include/ext_object.h +++ b/utils/include/ext_object.h @@ -38,8 +38,8 @@ public: class DriverInfo : public DriverInfoExt { public: DriverInfo() = default; - DriverInfo(const std::string &bundleName, const std::string &driverName, const std::string &driverUid = "") - : bundleName_(bundleName), driverName_(driverName) + DriverInfo(const std::string &bundleName, const std::string &driverName, const std::string &driverUid = "", + const int32_t userId = -1) : userId_(userId), bundleName_(bundleName), driverName_(driverName) { if (driverUid.empty()) { driverUid_ = bundleName + "-" + driverName; @@ -61,6 +61,10 @@ public: { return driverUid_; } + int32_t GetUserId() const + { + return userId_; + } std::string GetBundleName() const { return bundleName_; @@ -98,6 +102,7 @@ private: std::string bus_; BusType busType_{0}; std::string driverUid_; + int32_t userId_ = -1; std::string bundleName_; std::string driverName_; std::string vendor_; -- Gitee