diff --git a/services/native/driver_extension/src/js_driver_extension.cpp b/services/native/driver_extension/src/js_driver_extension.cpp index 8a5b2971ae287da9fcc2ee16bbc982316b323ae6..3df23f2274b68f673477a1946aa2a1cf2f9e83de 100644 --- a/services/native/driver_extension/src/js_driver_extension.cpp +++ b/services/native/driver_extension/src/js_driver_extension.cpp @@ -364,10 +364,11 @@ napi_value JsDriverExtension::CallObjectMethod(napi_env env, const char* name, c 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"); + ExtDevReportSysEvent::ReportExternalDeviceEvent(extDevEvent, + ExtDevReportSysEvent::EventErrCode::LIFECYCLE_FUNCTION_FAILED); return nullptr; } - ExtDevReportSysEvent::ReportExternalDeviceEvent(extDevEvent, 0, "Success to call callback"); + ExtDevReportSysEvent::ReportExternalDeviceEvent(extDevEvent, ExtDevReportSysEvent::EventErrCode::SUCCESS); HILOG_INFO("JsDriverExtension::CallFunction(%{public}s), success", name); return result; } @@ -402,16 +403,6 @@ napi_value JsDriverExtension::CallOnConnect(const AAFwk::Want &want) napi_value napiWant = OHOS::AppExecFwk::WrapWant(env, want); napi_value argv[] = {napiWant}; napi_value result = CallObjectMethod(env, "onConnect", argv, ARGC_ONE); - 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 nullptr; - } - ExternalDeviceManager::ExtDevReportSysEvent::SetEventValue(interfaceName, - ExternalDeviceManager::DRIVER_PACKAGE_CYCLE_MANAGE, 0, eventPtr); return result; } @@ -422,16 +413,6 @@ napi_value JsDriverExtension::CallOnDisconnect(const AAFwk::Want &want, bool wit napi_value napiWant = OHOS::AppExecFwk::WrapWant(env, want); napi_value argv[] = { napiWant }; napi_value result = CallObjectMethod(env, "onDisconnect", argv, ARGC_ONE); - 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); - } else { - ExternalDeviceManager::ExtDevReportSysEvent::SetEventValue(interfaceName, - ExternalDeviceManager::DRIVER_PACKAGE_CYCLE_MANAGE, 0, eventPtr); - } if (withResult) { return handleEscape.Escape(result); } else { 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 5129deba85a64034954899ed114bbe11c5ceb413..ffb15d38fc2466e69f422b59f9e0302494c7e7e8 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 @@ -28,8 +28,6 @@ class DeviceInfo; class DriverInfo; struct PkgInfoTable; -constexpr int MAP_SIZE_MAX = 1024; - enum EXTDEV_EXP_EVENT { // 操作类型枚举 DRIVER_BIND = 1, // 绑定设备驱动 DRIVER_UNBIND, // 解绑设备驱动 @@ -67,18 +65,31 @@ typedef struct ExtDevEvent { class ExtDevReportSysEvent { public: - static void ReportDriverPackageCycleManageSysEvent(const PkgInfoTable &pkgInfoTable, std::string pids, - std::string vids, uint32_t versionCode, std::string driverEventName); - - static void ReportDelPkgsCycleManageSysEvent(const std::string &bundleName, const std::string &driverEventName); + enum class EventErrCode { + SUCCESS = 0, + BIND_JS_CALLBACK_FAILED = 10001, + CONNECT_DRIVER_EXTENSION_FAILED, + BIND_ACCESS_NOT_ALLOWED, + UNBIND_DRIVER_EMPTY = 20001, + UNBIND_RELATION_NOT_FOUND, + DISCONNECT_DRIVER_EXTENSION_FAILED, + QUERY_DRIVER_EXTENSION_FAILED = 30001, + UPDATE_DATABASE_FAILED, + LIFECYCLE_FUNCTION_FAILED = 40001, + OPEN_DEVICE_FAILED = 50001, + GET_DEVICE_DESCRIPTOR_FAILED, + DEVICE_DESCRIPTOR_LENGTH_INVALID, + GET_INTERFACE_DESCRIPTOR_FAILED, + STOP_DRIVER_EXTENSION_FAILED = 60001, + QUERY_DRIVER_INFO_FAILED = 70001, + NO_MATCHING_DRIVER_FOUND + }; + + static const std::map ErrMsgs; 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 void ReportExternalDeviceEvent(const std::shared_ptr &extDevEvent, const EventErrCode errCode); static void ParseToExtDevEvent(const std::shared_ptr &deviceInfo, const std::shared_ptr &eventObj); @@ -89,22 +100,7 @@ public: static void ParseToExtDevEvent(const std::shared_ptr &deviceInfo, const std::shared_ptr &driverInfo, const std::shared_ptr &eventObj); - 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 DriverMapErase(const std::string driverUid); - - static void DriverMapDelete(const std::string &bundleName); - static std::string ParseIdVector(std::vector ids); - -private: - static std::map> driverMap_; - static std::mutex hisyseventMutex_; }; } // namespace ExternalDeviceManager diff --git a/services/native/driver_extension_manager/include/drivers_pkg_manager/drv_bundle_state_callback.h b/services/native/driver_extension_manager/include/drivers_pkg_manager/drv_bundle_state_callback.h index 1b8b6476cf68930a59ee099a572797f9d4e79012..d89541f17b77cc5eadcccbbb19de708e8b279130 100644 --- a/services/native/driver_extension_manager/include/drivers_pkg_manager/drv_bundle_state_callback.h +++ b/services/native/driver_extension_manager/include/drivers_pkg_manager/drv_bundle_state_callback.h @@ -51,11 +51,6 @@ enum ON_BUNDLE_STATUS { typedef int32_t(*PCALLBACKFUN)(int, int, const string &, const string &); -typedef struct DriverObj { - PkgInfoTable pkgInfoTable; - DriverInfo driverInfo; -} DriverObj; - class DrvBundleStateCallback : public IBundleStatusCallback { public: DrvBundleStateCallback(); @@ -101,8 +96,6 @@ public: void ResetInitOnce(); void ResetMatchedBundles(const int32_t userId); - void ReportBundleSysEvent(const std::vector &driverInfos, - const std::string &bundleName, std::string driverEventName); private: std::mutex bundleMgrMutex_; @@ -118,25 +111,19 @@ private: bool QueryDriverInfos(const std::string &bundleName, const int userId, std::vector &driverInfos); - bool UpdateToRdb(const std::vector &driverInfos, const std::string &bundleName = ""); + bool UpdateToRdb(const std::vector &driverInfos, const std::string &bundleName = "", + const std::string &interfaceName = ""); void ClearDriverInfo(DriverInfo &tmpDrvInfo); bool GetBundleMgrProxy(); int32_t GetCurrentActiveUserId(); void ChangeValue(DriverInfo &tmpDrvInfo, const map &metadata); std::string GetBundleSize(const std::string &bundleName); - std::vector ParseToPkgInfoTables( + std::vector ParseToPkgInfoTables( const std::vector &driverInfos, std::vector &pkgInfoTables); PkgInfoTable CreatePkgInfoTable(const ExtensionAbilityInfo &driverInfo, string driverInfoStr); bool IsCurrentUserId(const int userId); - - void OnBundleDrvAdded(int bundleStatus); - void OnBundleDrvUpdated(int bundleStatus); - void OnBundleDrvRemoved(const std::string &bundleName); + void OnBundleDrvRemoved(const std::string &bundleName, const std::string &interfaceName); void ResetBundleMgr(); - std::string ParseIdVector(std::vector ids); - int ParseVersionCode(const std::vector &driverInfos, const std::string &bundleName); - shared_ptr GetDriverInfo(const std::vector &driverInfos, - const std::string &bundleName); }; class BundleMgrDeathRecipient : public IRemoteObject::DeathRecipient { diff --git a/services/native/driver_extension_manager/include/drivers_pkg_manager/pkg_db_helper.h b/services/native/driver_extension_manager/include/drivers_pkg_manager/pkg_db_helper.h index 1dcd5d0da883f79b1661a25e79125062eb245536..e880c1f1d550e6cb114c3f6e221d42887458b31b 100644 --- a/services/native/driver_extension_manager/include/drivers_pkg_manager/pkg_db_helper.h +++ b/services/native/driver_extension_manager/include/drivers_pkg_manager/pkg_db_helper.h @@ -38,6 +38,7 @@ public: int32_t QueryAllDriverInfos(std::vector &driverInfos); int32_t QueryPkgInfos(std::vector &pkgInfos, bool isByDriverUid = false, const std::string &driverUid = ""); + int32_t QueryPkgInfos(const std::string &bundleName, std::vector &pkgInfos); /* add or update (user, device, app) record */ int32_t AddOrUpdateRightRecord( const std::string &bundleName, const std::string &bundleAbility, const std::string &driverInfo); @@ -60,6 +61,9 @@ private: const std::vector &columns, const std::string &columnName, std::vector &columnValues); int32_t DeleteAndNoOtherOperation(const std::string &whereClause, const std::vector &whereArgs); + int32_t QueryPkgInfos(const std::string &whereKey, const std::string &whereValue, + std::vector &pkgInfos); + static std::shared_ptr instance_; std::mutex databaseMutex_; std::shared_ptr rightDatabase_; 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 2ef5de589b55ff983f21f578932a46af01c4eb89..2b8340b2df9dccea7c9623603d1fc93673e72929 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 @@ -148,7 +148,8 @@ 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::ReportExternalDeviceEvent(extDevEvent, EDM_ERR_IO, "OpenDevice failed"); + ExtDevReportSysEvent::ReportExternalDeviceEvent(extDevEvent, + ExtDevReportSysEvent::EventErrCode::OPEN_DEVICE_FAILED); return EDM_ERR_IO; } vector descData; @@ -156,14 +157,16 @@ 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::ReportExternalDeviceEvent(extDevEvent, EDM_ERR_IO, "GetDeviceDescriptor failed"); + ExtDevReportSysEvent::ReportExternalDeviceEvent(extDevEvent, + ExtDevReportSysEvent::EventErrCode::GET_DEVICE_DESCRIPTOR_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"); + ExtDevReportSysEvent::ReportExternalDeviceEvent(extDevEvent, + ExtDevReportSysEvent::EventErrCode::DEVICE_DESCRIPTOR_LENGTH_INVALID); return EDM_ERR_USB_ERR; } auto usbDevInfo = make_shared(ToBusDeivceId(usbDev), ToDeviceDesc(usbDev, deviceDescriptor)); @@ -173,10 +176,11 @@ int32_t UsbDevSubscriber::OnDeviceConnect(const UsbDev &usbDev) if (ret != EDM_OK) { EDM_LOGE(MODULE_BUS_USB, "GetInterfaceDescriptor fail, ret = %{public}d", ret); (void)this->iusb_->CloseDevice(usbDev); - ExtDevReportSysEvent::ReportExternalDeviceEvent(extDevEvent, EDM_ERR_IO, "GetInterfaceDescriptor failed"); + ExtDevReportSysEvent::ReportExternalDeviceEvent(extDevEvent, + ExtDevReportSysEvent::EventErrCode::GET_INTERFACE_DESCRIPTOR_FAILED); return ret; } - ExtDevReportSysEvent::ReportExternalDeviceEvent(extDevEvent, EDM_OK, "GetDescriptorInfo success"); + ExtDevReportSysEvent::ReportExternalDeviceEvent(extDevEvent, ExtDevReportSysEvent::EventErrCode::SUCCESS); (void)this->iusb_->CloseDevice(usbDev); if (this->callback_ != nullptr) { this->callback_->OnDeviceAdd(usbDevInfo); 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 f6f9e28aaff8625a59dd1ed0eb5955ba49b758de..19f1b55ef6438fa96385255875a5f358495553ef 100644 --- a/services/native/driver_extension_manager/src/device_manager/device.cpp +++ b/services/native/driver_extension_manager/src/device_manager/device.cpp @@ -102,19 +102,20 @@ 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"); - ExtDevReportSysEvent::ReportExternalDeviceEvent(extDevEvent, UsbErrCode::EDM_ERR_INVALID_OBJECT, - "failed to register callback object"); + ExtDevReportSysEvent::ReportExternalDeviceEvent(extDevEvent, + ExtDevReportSysEvent::EventErrCode::BIND_JS_CALLBACK_FAILED); return ret; } boundCallerInfos_[callingTokenId] = CallerInfo{true}; + ExtDevReportSysEvent::ReportExternalDeviceEvent(extDevEvent, ExtDevReportSysEvent::EventErrCode::SUCCESS); return ret; } int32_t ret = RegisterDrvExtMgrCallback(connectCallback); if (ret != UsbErrCode::EDM_OK) { EDM_LOGE(MODULE_DEV_MGR, "failed to register callback object"); - ExtDevReportSysEvent::ReportExternalDeviceEvent(extDevEvent, UsbErrCode::EDM_ERR_INVALID_OBJECT, - "failed to register callback object"); + ExtDevReportSysEvent::ReportExternalDeviceEvent(extDevEvent, + ExtDevReportSysEvent::EventErrCode::BIND_JS_CALLBACK_FAILED); return ret; } @@ -132,8 +133,9 @@ int32_t Device::Connect(const sptr &connectCallback, uint UnregisterDrvExtMgrCallback(connectCallback); boundCallerInfos_.erase(callingTokenId); } - ExtDevReportSysEvent::ReportExternalDeviceEvent(extDevEvent, ret, - ret != UsbErrCode::EDM_OK ? "failed to connect driver extension" : ""); + ExtDevReportSysEvent::ReportExternalDeviceEvent(extDevEvent, + ret != UsbErrCode::EDM_OK ? ExtDevReportSysEvent::EventErrCode::CONNECT_DRIVER_EXTENSION_FAILED : + ExtDevReportSysEvent::EventErrCode::SUCCESS); return ret; } @@ -146,8 +148,8 @@ int32_t Device::Disconnect(const bool isFromBind) 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"); + ExtDevReportSysEvent::ReportExternalDeviceEvent(extDevEvent, + ExtDevReportSysEvent::EventErrCode::SUCCESS); } return UsbErrCode::EDM_OK; } @@ -161,8 +163,9 @@ int32_t Device::Disconnect(const bool isFromBind) EDM_LOGE(MODULE_DEV_MGR, "failed to disconnect driver extension"); } if (isFromBind) { - ExtDevReportSysEvent::ReportExternalDeviceEvent(extDevEvent, ret, - ret != UsbErrCode::EDM_OK ? "failed to disconnect driver extension" : ""); + ExtDevReportSysEvent::ReportExternalDeviceEvent(extDevEvent, ret != UsbErrCode::EDM_OK ? + ExtDevReportSysEvent::EventErrCode::DISCONNECT_DRIVER_EXTENSION_FAILED : + ExtDevReportSysEvent::EventErrCode::SUCCESS); } return ret; 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 8c80bc8ad935913cda55609fcc5cf3da91903145..93df86f9d99250e2d98b166b2fd7004cfac71e35 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 @@ -292,12 +292,11 @@ void ExtDeviceManager::ClearMatchedDrivers(const int32_t userId) ExtDevReportSysEvent::ParseToExtDevEvent(device->GetDeviceInfo(), driverInfo, extDevEvent); auto ret = DriverExtensionController::GetInstance().StopDriverExtension(driverInfo->GetBundleName(), driverInfo->GetDriverName(), userId); + ExtDevReportSysEvent::ReportExternalDeviceEvent(extDevEvent, + ret != EDM_OK ? ExtDevReportSysEvent::EventErrCode::STOP_DRIVER_EXTENSION_FAILED : + ExtDevReportSysEvent::EventErrCode::SUCCESS); 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(); @@ -564,7 +563,8 @@ int32_t ExtDeviceManager::DisConnectDevice(uint64_t deviceId, uint32_t callingTo 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"); + ExtDevReportSysEvent::ReportExternalDeviceEvent(extDevEvent, + ExtDevReportSysEvent::EventErrCode::UNBIND_DRIVER_EMPTY); return EDM_NOK; } @@ -572,8 +572,7 @@ 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"); + ExtDevReportSysEvent::ReportExternalDeviceEvent(extDevEvent, ExtDevReportSysEvent::EventErrCode::SUCCESS); return EDM_OK; } return device->Disconnect(true); @@ -595,7 +594,9 @@ int32_t ExtDeviceManager::ConnectDriverWithDeviceId(uint64_t deviceId, uint32_t 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"); + ExtDevReportSysEvent::ReportExternalDeviceEvent(extDevEvent, + ret != EDM_OK ? ExtDevReportSysEvent::EventErrCode::BIND_ACCESS_NOT_ALLOWED : + ExtDevReportSysEvent::EventErrCode::SUCCESS); return ret; } return device->Connect(connectCallback, callingTokenId); @@ -615,15 +616,16 @@ int32_t ExtDeviceManager::DisConnectDriverWithDeviceId(uint64_t deviceId, uint32 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"); + ExtDevReportSysEvent::ReportExternalDeviceEvent(extDevEvent, + ExtDevReportSysEvent::EventErrCode::UNBIND_RELATION_NOT_FOUND); 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"); + ExtDevReportSysEvent::ReportExternalDeviceEvent(extDevEvent, + ExtDevReportSysEvent::EventErrCode::UNBIND_DRIVER_EMPTY); return EDM_NOK; } @@ -631,8 +633,7 @@ 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"); + ExtDevReportSysEvent::ReportExternalDeviceEvent(extDevEvent, ExtDevReportSysEvent::EventErrCode::SUCCESS); return EDM_OK; } return device->Disconnect(true); 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 3e292c6a7e21870ed16e57b3a6f5e6a314ee8ac9..6004cb402e89fc5914bf1d4883c34a812a2f9b65 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,43 +26,38 @@ using namespace OHOS::HiviewDFX; namespace OHOS { namespace ExternalDeviceManager { -std::map> ExtDevReportSysEvent::driverMap_; -std::mutex ExtDevReportSysEvent::hisyseventMutex_; -constexpr int LAST_FIVE = 5; - -void ExtDevReportSysEvent::ReportDriverPackageCycleManageSysEvent(const PkgInfoTable &pkgInfoTable, - std::string pids, std::string vids, uint32_t versionCode, std::string driverEventName) -{ - EDM_LOGI(MODULE_PKG_MGR, "report driver package cycle sys event"); - int32_t hiRet = HiSysEventWrite(HiSysEvent::Domain::EXTERNAL_DEVICE, "DRIVER_PACKAGE_CYCLE_MANAGER", - HiSysEvent::EventType::STATISTIC, "BUNDLE_NAME", pkgInfoTable.bundleName, "USER_ID", pkgInfoTable.userId, - "DRIVER_UID", pkgInfoTable.driverUid, "VERSION_CODE", versionCode, - "VENDOR_ID", vids, "PRODUCT_ID", pids, "DRIVER_EVENT_NAME", driverEventName); - if (hiRet != EDM_OK) { - EDM_LOGI(MODULE_PKG_MGR, "HiSysEventWrite ret: %{public}d", hiRet); - } -} - -void ExtDevReportSysEvent::ReportDelPkgsCycleManageSysEvent(const std::string &bundleName, - const std::string &driverEventName) -{ - EDM_LOGI(MODULE_PKG_MGR, "ReportDelPkgsCycleManageSysEvent enter"); - std::lock_guard lock(hisyseventMutex_); - for (const auto &[driverId, extDevEvent] : driverMap_) { - if (extDevEvent == nullptr) { - EDM_LOGI(MODULE_PKG_MGR, "extDevEvent of %{public}s is null", driverId.c_str()); - continue; - } - int32_t hiRet = HiSysEventWrite(HiSysEvent::Domain::EXTERNAL_DEVICE, "DRIVER_PACKAGE_CYCLE_MANAGER", - HiSysEvent::EventType::STATISTIC, "BUNDLE_NAME", extDevEvent->bundleName, "USER_ID", - extDevEvent->userId, "DRIVER_UID", extDevEvent->driverUid, "VERSION_CODE", - extDevEvent->versionCode, "VENDOR_ID", extDevEvent->vids, "PRODUCT_ID", extDevEvent->pids, - "DRIVER_EVENT_NAME", driverEventName); - if (hiRet != EDM_OK) { - EDM_LOGI(MODULE_PKG_MGR, "HiSysEventWrite ret: %{public}d", hiRet); - } - } -} +constexpr int32_t LAST_FIVE = 5; + +const std::map ExtDevReportSysEvent::ErrMsgs = { + {ExtDevReportSysEvent::EventErrCode::SUCCESS, "Success"}, + {ExtDevReportSysEvent::EventErrCode::BIND_JS_CALLBACK_FAILED, "Failed to register JS callback"}, + {ExtDevReportSysEvent::EventErrCode::CONNECT_DRIVER_EXTENSION_FAILED, + "Failed to connect DriverExtensionAbility"}, + {ExtDevReportSysEvent::EventErrCode::BIND_ACCESS_NOT_ALLOWED, "Bind access is not allowed"}, + {ExtDevReportSysEvent::EventErrCode::UNBIND_DRIVER_EMPTY, "No driver matched for the device"}, + {ExtDevReportSysEvent::EventErrCode::UNBIND_RELATION_NOT_FOUND, + "Binding relationship between client and driver not found"}, + {ExtDevReportSysEvent::EventErrCode::DISCONNECT_DRIVER_EXTENSION_FAILED, + "Failed to disconnect DriverExtensionAbility"}, + {ExtDevReportSysEvent::EventErrCode::QUERY_DRIVER_EXTENSION_FAILED, + "Failed to query DriverExtensionAbility"}, + {ExtDevReportSysEvent::EventErrCode::UPDATE_DATABASE_FAILED, "Failed to update database"}, + {ExtDevReportSysEvent::EventErrCode::LIFECYCLE_FUNCTION_FAILED, + "Lifecycle function execution failed"}, + {ExtDevReportSysEvent::EventErrCode::OPEN_DEVICE_FAILED, "Failed to open device"}, + {ExtDevReportSysEvent::EventErrCode::GET_DEVICE_DESCRIPTOR_FAILED, + "Failed to get device descriptor"}, + {ExtDevReportSysEvent::EventErrCode::DEVICE_DESCRIPTOR_LENGTH_INVALID, + "Device descriptor length is invalid"}, + {ExtDevReportSysEvent::EventErrCode::GET_INTERFACE_DESCRIPTOR_FAILED, + "Failed to get interface descriptor"}, + {ExtDevReportSysEvent::EventErrCode::STOP_DRIVER_EXTENSION_FAILED, + "Failed to stop DriverExtensionAbility"}, + {ExtDevReportSysEvent::EventErrCode::QUERY_DRIVER_INFO_FAILED, + "Failed to query driver information"}, + {ExtDevReportSysEvent::EventErrCode::NO_MATCHING_DRIVER_FOUND, + "No matching driver found for the device"} +}; void ExtDevReportSysEvent::ReportExternalDeviceEvent(const std::shared_ptr &extDevEvent) { @@ -91,29 +86,19 @@ void ExtDevReportSysEvent::ReportExternalDeviceEvent(const std::shared_ptr &extDevEvent, - const int32_t errCode, const std::string &message) + const ExtDevReportSysEvent::EventErrCode errCode) { 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) -{ - EDM_LOGI(MODULE_PKG_MGR, "report external device sa event"); - int32_t hiRet = HiSysEventWrite(HiSysEvent::Domain::EXTERNAL_DEVICE, "DRIVER_PACKAGE_CYCLE_MANAGER", - HiSysEvent::EventType::STATISTIC, "BUNDLE_NAME", pkgInfoTable.bundleName, "USER_ID", pkgInfoTable.userId, - "DRIVER_UID", pkgInfoTable.driverUid, "VERSION_CODE", versionCode, - "VENDOR_ID", vids, "PRODUCT_ID", pids, "DRIVER_EVENT_NAME", driverEventName); - if (hiRet != EDM_OK) { - EDM_LOGI(MODULE_PKG_MGR, "HiSysEventWrite ret: %{public}d", hiRet); + extDevEvent->errCode = static_cast(errCode); + auto it = ExtDevReportSysEvent::ErrMsgs.find(errCode); + if (it != ExtDevReportSysEvent::ErrMsgs.end()) { + extDevEvent->message = it->second; } + ReportExternalDeviceEvent(extDevEvent); } void ExtDevReportSysEvent::ParseToExtDevEvent(const std::shared_ptr &deviceInfo, @@ -175,59 +160,6 @@ void ExtDevReportSysEvent::ParseToExtDevEvent(const std::shared_ptr ExtDevReportSysEvent::ParseToExtDevEvent(driverInfo, eventObj); } -std::shared_ptr ExtDevReportSysEvent::DriverEventReport(const std::string driverUid) -{ - std::lock_guard lock(hisyseventMutex_); - std::shared_ptr matchPtr = std::make_shared(); - auto driver = driverMap_.find(driverUid); - if (driver != driverMap_.end()) { - matchPtr = driver->second; - return matchPtr; - } - return nullptr; -} - -void ExtDevReportSysEvent::SetEventValue(const std::string interfaceName, const int32_t operatType, - const int32_t errCode, std::shared_ptr eventPtr) -{ - if (eventPtr != nullptr) { - eventPtr->interfaceName = interfaceName; - eventPtr->operatType = operatType; - eventPtr->errCode = errCode; - ReportExternalDeviceEvent(eventPtr); - } -} - -void ExtDevReportSysEvent::DriverMapInsert(const std::string driverUid, std::shared_ptr eventPtr) -{ - if (eventPtr != nullptr) { - std::lock_guard lock(hisyseventMutex_); - driverMap_[driverUid] = eventPtr; - } -} - -void ExtDevReportSysEvent::DriverMapErase(const std::string driverUid) -{ - std::lock_guard lock(hisyseventMutex_); - driverMap_.erase(driverUid); -} - -void ExtDevReportSysEvent::DriverMapDelete(const std::string &bundleName) -{ - std::lock_guard lock(hisyseventMutex_); - if (bundleName.empty()) { - driverMap_.clear(); - return; - } - for (auto it = driverMap_.begin(); it != driverMap_.end();) { - if (it->second != nullptr && it->second->bundleName == bundleName) { - it = driverMap_.erase(it); - } else { - ++it; - } - } -} - std::string ExtDevReportSysEvent::ParseIdVector(std::vector ids) { if (ids.size() < 1) { 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 a9c98442ac3997c9e9c9ef279cca40b9c8a29886..0b5fca756eac8a778095eab7f93809bea52e86d4 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 @@ -130,11 +130,13 @@ shared_ptr DriverPkgManager::QueryMatchDriver(shared_ptr int32_t retRdb = helper->QueryPkgInfos(pkgInfos); if (retRdb < 0) { EDM_LOGE(MODULE_PKG_MGR, "QueryMatchDriver QueryPkgInfos failed"); - ExtDevReportSysEvent::ReportExternalDeviceEvent(extDevEvent, EDM_NOK, "QueryPkgInfos failed"); + ExtDevReportSysEvent::ReportExternalDeviceEvent(extDevEvent, + ExtDevReportSysEvent::EventErrCode::QUERY_DRIVER_INFO_FAILED); return nullptr; } else if (retRdb == 0) { EDM_LOGD(MODULE_PKG_MGR, "QueryMatchDriver no driver installed"); - ExtDevReportSysEvent::ReportExternalDeviceEvent(extDevEvent, EDM_NOK, "no driver installed"); + ExtDevReportSysEvent::ReportExternalDeviceEvent(extDevEvent, + ExtDevReportSysEvent::EventErrCode::NO_MATCHING_DRIVER_FOUND); return nullptr; } EDM_LOGI(MODULE_PKG_MGR, "Total driverInfos number: %{public}zu", pkgInfos.size()); @@ -144,14 +146,15 @@ shared_ptr DriverPkgManager::QueryMatchDriver(shared_ptr 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); + std::shared_ptr driverPtr = std::make_shared(driverInfo); ExtDevReportSysEvent::ParseToExtDevEvent(driverPtr, extDevEvent); - ExtDevReportSysEvent::ReportExternalDeviceEvent(extDevEvent, EDM_OK, "MatchDriver success"); + ExtDevReportSysEvent::ReportExternalDeviceEvent(extDevEvent, ExtDevReportSysEvent::EventErrCode::SUCCESS); return driverPtr; } } EDM_LOGI(MODULE_PKG_MGR, "QueryMatchDriver return null"); - ExtDevReportSysEvent::ReportExternalDeviceEvent(extDevEvent, EDM_NOK, "no driver match"); + ExtDevReportSysEvent::ReportExternalDeviceEvent(extDevEvent, + ExtDevReportSysEvent::EventErrCode::NO_MATCHING_DRIVER_FOUND); return nullptr; } diff --git a/services/native/driver_extension_manager/src/drivers_pkg_manager/drv_bundle_state_callback.cpp b/services/native/driver_extension_manager/src/drivers_pkg_manager/drv_bundle_state_callback.cpp index edaa9c1e8254f8eeeeeb427f9d06eb9b7acaccc7..c97018d84836086755f2e1cccc2ef2ff4330aeba 100644 --- a/services/native/driver_extension_manager/src/drivers_pkg_manager/drv_bundle_state_callback.cpp +++ b/services/native/driver_extension_manager/src/drivers_pkg_manager/drv_bundle_state_callback.cpp @@ -55,8 +55,6 @@ const string DRV_INFO_ALLOW_ACCESSED = "ohos.permission.ACCESS_DDK_ALLOWED"; static constexpr const char *BUNDLE_RESET_TASK_NAME = "DRIVER_INFO_RESET"; static constexpr const char *BUNDLE_UPDATE_TASK_NAME = "DRIVER_INFO_UPDATE"; static constexpr const char *GET_DRIVERINFO_TASK_NAME = "GET_DRIVERINFO_ASYNC"; -constexpr int RDB_ERR = -2; -constexpr int QUERY_ERR = -3; std::string DrvBundleStateCallback::GetBundleSize(const std::string &bundleName) { @@ -100,12 +98,12 @@ void DrvBundleStateCallback::ChangeValue(DriverInfo &tmpDrvInfo, const map DrvBundleStateCallback::ParseToPkgInfoTables( +std::vector DrvBundleStateCallback::ParseToPkgInfoTables( const std::vector &driverInfos, std::vector &pkgInfoTables) { std::unordered_map bundlesSize; shared_ptr extInstance = nullptr; - std::vector ret; + std::vector ret; for (const auto &driverInfo : driverInfos) { if (driverInfo.type != ExtensionAbilityType::DRIVER || driverInfo.metadata.empty()) { continue; @@ -141,8 +139,10 @@ std::vector DrvBundleStateCallback::ParseToPkgInfoTables( } PkgInfoTable pkgInfo = CreatePkgInfoTable(driverInfo, driverInfoStr); + tmpDrvInfo.driverUid_ = pkgInfo.driverUid; + tmpDrvInfo.userId_ = pkgInfo.userId; pkgInfoTables.emplace_back(pkgInfo); - ret.emplace_back(DriverObj{pkgInfo, tmpDrvInfo}); + ret.emplace_back(tmpDrvInfo); } return ret; } @@ -212,24 +212,25 @@ void DrvBundleStateCallback::OnBundleAdded(const std::string &bundleName, const { EDM_LOGI(MODULE_PKG_MGR, "OnBundleAdded"); StartTrace(LABEL, "OnBundleAdded"); - std::shared_ptr eventPtr = std::make_shared(); - std::string interfaceName = std::string(__func__); - eventPtr->userId = userId; - eventPtr->bundleName = bundleName; if (!IsCurrentUserId(userId)) { return; } std::vector driverInfos; - if (!QueryDriverInfos(bundleName, userId, driverInfos) || driverInfos.empty()) { - ExtDevReportSysEvent::SetEventValue(interfaceName, DRIVER_PACKAGE_DATA_REFRESH, -1, eventPtr); + if (!QueryDriverInfos(bundleName, userId, driverInfos)) { + auto extDevEvent = std::make_shared(__func__, DRIVER_PACKAGE_DATA_REFRESH); + if (extDevEvent == nullptr) { + return; + } + extDevEvent->bundleName = bundleName; + extDevEvent->userId = userId; + ExtDevReportSysEvent::ReportExternalDeviceEvent(extDevEvent, + ExtDevReportSysEvent::EventErrCode::QUERY_DRIVER_EXTENSION_FAILED); return; } - if (!UpdateToRdb(driverInfos, bundleName)) { + if (!UpdateToRdb(driverInfos, bundleName, __func__)) { EDM_LOGE(MODULE_PKG_MGR, "OnBundleAdded error"); - ExtDevReportSysEvent::SetEventValue(interfaceName, DRIVER_PACKAGE_DATA_REFRESH, RDB_ERR, eventPtr); } - ReportBundleSysEvent(driverInfos, bundleName, "BUNDLE_ADD"); FinishTrace(LABEL); } /** @@ -241,30 +242,30 @@ void DrvBundleStateCallback::OnBundleUpdated(const std::string &bundleName, cons { EDM_LOGI(MODULE_PKG_MGR, "OnBundleUpdated"); StartTrace(LABEL, "OnBundleUpdated"); - std::shared_ptr eventPtr = std::make_shared(); - std::string interfaceName = std::string(__func__); - eventPtr->userId = userId; - eventPtr->bundleName = bundleName; if (!IsCurrentUserId(userId)) { - ExtDevReportSysEvent::SetEventValue(interfaceName, DRIVER_PACKAGE_DATA_REFRESH, -1, eventPtr); return; } std::vector driverInfos; if (!QueryDriverInfos(bundleName, userId, driverInfos)) { - ExtDevReportSysEvent::SetEventValue(interfaceName, DRIVER_PACKAGE_DATA_REFRESH, RDB_ERR, eventPtr); + auto extDevEvent = std::make_shared(__func__, DRIVER_PACKAGE_DATA_REFRESH); + if (extDevEvent == nullptr) { + return; + } + extDevEvent->bundleName = bundleName; + extDevEvent->userId = userId; + ExtDevReportSysEvent::ReportExternalDeviceEvent(extDevEvent, + ExtDevReportSysEvent::EventErrCode::QUERY_DRIVER_EXTENSION_FAILED); return; } if (driverInfos.empty()) { - OnBundleDrvRemoved(bundleName); + OnBundleDrvRemoved(bundleName, __func__); return; } - if (!UpdateToRdb(driverInfos, bundleName)) { + if (!UpdateToRdb(driverInfos, bundleName, __func__)) { EDM_LOGE(MODULE_PKG_MGR, "OnBundleUpdated error"); - ExtDevReportSysEvent::SetEventValue(interfaceName, DRIVER_PACKAGE_DATA_REFRESH, QUERY_ERR, eventPtr); } - ReportBundleSysEvent(driverInfos, bundleName, "BUNDLE_UPDATE"); FinishTrace(LABEL); } @@ -280,20 +281,7 @@ void DrvBundleStateCallback::OnBundleRemoved(const std::string &bundleName, cons if (!IsCurrentUserId(userId)) { return; } - std::vector driverInfos; - (void)QueryDriverInfos(bundleName, userId, driverInfos); - std::shared_ptr driverInfo = GetDriverInfo(driverInfos, bundleName); - std::shared_ptr eventPtr = std::make_shared(); - eventPtr = ExtDevReportSysEvent::DriverEventReport(driverInfo->GetDriverUid()); - std::string interfaceName = std::string(__func__); - if (eventPtr != nullptr) { - eventPtr->userId = userId; - ExtDevReportSysEvent::DriverMapErase(driverInfo->GetDriverUid()); - ExtDevReportSysEvent::SetEventValue(interfaceName, DRIVER_PACKAGE_DATA_REFRESH, 0, eventPtr); - } - ExtDevReportSysEvent::ReportDelPkgsCycleManageSysEvent(bundleName, "BUNDLE_REMOVED"); - OnBundleDrvRemoved(bundleName); - ExtDevReportSysEvent::DriverMapDelete(bundleName); + OnBundleDrvRemoved(bundleName, __func__); FinishTrace(LABEL); } @@ -344,7 +332,7 @@ bool DrvBundleStateCallback::GetAllDriverInfos() } bundleMgr_->QueryExtensionAbilityInfos(ExtensionAbilityType::DRIVER, userId, driverInfos); bundleMgrMutex_.unlock(); - if (!UpdateToRdb(driverInfos, "")) { + if (!UpdateToRdb(driverInfos, "", __func__)) { EDM_LOGE(MODULE_PKG_MGR, "UpdateToRdb failed"); return false; } @@ -430,43 +418,49 @@ void DrvBundleStateCallback::ClearDriverInfo(DriverInfo &tmpDrvInfo) tmpDrvInfo.driverInfoExt_ = nullptr; } -static void ReportPkgsEvent(const std::vector &driverObjs, const std::string &bundleName) +static void ReportPkgsEvent(const std::vector &driverObjs, const std::string &interfaceName, + const ExtDevReportSysEvent::EventErrCode errCode) { - EDM_LOGI(MODULE_PKG_MGR, "ReportPkgsEvent enter, %{public}zu", driverObjs.size()); - ExtDevReportSysEvent::DriverMapDelete(bundleName); + EDM_LOGI(MODULE_PKG_MGR, "ReportPkgsEvent enter, interfaceName:%{public}s, %{public}zu", interfaceName.c_str(), + driverObjs.size()); + auto extDevEvent = std::make_shared(interfaceName, DRIVER_PACKAGE_DATA_REFRESH); for (const auto &driverObj : driverObjs) { - if (driverObj.driverInfo.GetBusType() != BusType::BUS_TYPE_USB) { + ExtDevReportSysEvent::ParseToExtDevEvent(std::make_shared(driverObj), extDevEvent); + ExtDevReportSysEvent::ReportExternalDeviceEvent(extDevEvent, errCode); + } +} + +static void ReportPkgsDelEvent(const std::vector &pkgInfos, + const std::string &interfaceName, const ExtDevReportSysEvent::EventErrCode errCode) +{ + EDM_LOGI(MODULE_PKG_MGR, "ReportPkgsDelEvent enter, interfaceName:%{public}s, %{public}zu", interfaceName.c_str(), + pkgInfos.size()); + auto extDevEvent = std::make_shared(interfaceName, DRIVER_PACKAGE_DATA_REFRESH); + for (const auto &pkgInfo : pkgInfos) { + std::shared_ptr driverInfo + = std::make_shared(pkgInfo.bundleName, pkgInfo.driverName, pkgInfo.driverUid, pkgInfo.userId); + if (driverInfo == nullptr) { + EDM_LOGE(MODULE_PKG_MGR, "ReportPkgsDelEvent driverInfo is null"); continue; } - auto eventObj = std::make_shared(); - std::shared_ptr usbDriverInfo = - std::static_pointer_cast(driverObj.driverInfo.GetInfoExt()); - std::vector productIds = usbDriverInfo->GetProductIds(); - std::vector vendorIds = usbDriverInfo->GetVendorIds(); - eventObj->vids = ExtDevReportSysEvent::ParseIdVector(vendorIds); - eventObj->pids = ExtDevReportSysEvent::ParseIdVector(productIds); - eventObj->driverUid = driverObj.pkgInfoTable.driverUid; - eventObj->driverName = driverObj.pkgInfoTable.driverName; - eventObj->versionCode = driverObj.driverInfo.GetVersion(); - eventObj->userId = driverObj.pkgInfoTable.userId; - eventObj->bundleName = driverObj.pkgInfoTable.bundleName; - ExtDevReportSysEvent::DriverMapInsert(eventObj->driverUid, eventObj); - ExtDevReportSysEvent::SetEventValue(std::string(__func__), DRIVER_PACKAGE_DATA_REFRESH, 0, eventObj); + driverInfo->UnSerialize(pkgInfo.driverInfo); + ExtDevReportSysEvent::ParseToExtDevEvent(driverInfo, extDevEvent); + ExtDevReportSysEvent::ReportExternalDeviceEvent(extDevEvent, errCode); } } bool DrvBundleStateCallback::UpdateToRdb(const std::vector &driverInfos, - const std::string &bundleName) + const std::string &bundleName, const std::string &interfaceName) { std::vector pkgInfoTables; auto driverObjs = ParseToPkgInfoTables(driverInfos, pkgInfoTables); std::shared_ptr helper = PkgDbHelper::GetInstance(); if (helper->AddOrUpdatePkgInfo(pkgInfoTables, bundleName) < PKG_OK) { EDM_LOGE(MODULE_PKG_MGR, "add or update failed,bundleName:%{public}s", bundleName.c_str()); + ReportPkgsEvent(driverObjs, interfaceName, ExtDevReportSysEvent::EventErrCode::UPDATE_DATABASE_FAILED); return false; } - - ReportPkgsEvent(driverObjs, bundleName); + ReportPkgsEvent(driverObjs, interfaceName, ExtDevReportSysEvent::EventErrCode::SUCCESS); if (bundleUpdateCallback_ != nullptr) { std::thread taskThread([bundleName, this]() { @@ -529,15 +523,18 @@ bool DrvBundleStateCallback::GetBundleMgrProxy() return true; } -void DrvBundleStateCallback::OnBundleDrvRemoved(const std::string &bundleName) +void DrvBundleStateCallback::OnBundleDrvRemoved(const std::string &bundleName, const std::string &interfaceName) { std::shared_ptr helper = PkgDbHelper::GetInstance(); - + std::vector pkgInfos; + (void)helper->QueryPkgInfos(bundleName, pkgInfos); int32_t ret = helper->DeleteRightRecord(bundleName); if (ret < 0) { EDM_LOGE(MODULE_PKG_MGR, "delete failed: %{public}s", bundleName.c_str()); + ReportPkgsDelEvent(pkgInfos, interfaceName, ExtDevReportSysEvent::EventErrCode::UPDATE_DATABASE_FAILED); return; } + ReportPkgsDelEvent(pkgInfos, interfaceName, ExtDevReportSysEvent::EventErrCode::SUCCESS); if (bundleUpdateCallback_ != nullptr) { std::thread taskThread([bundleName, this]() { if (bundleUpdateCallback_ == nullptr) { @@ -559,71 +556,5 @@ void DrvBundleStateCallback::ResetBundleMgr() } bundleMgr_ = nullptr; } - -void DrvBundleStateCallback::ReportBundleSysEvent(const std::vector &driverInfos, - const std::string &bundleName, std::string driverEventName) -{ - EDM_LOGI(MODULE_BUS_USB, "ReportBundleSysEvent begin"); - std::vector pkgInfoTables; - ParseToPkgInfoTables(driverInfos, pkgInfoTables); - for (const auto &pkgInfoTable : pkgInfoTables) { - if (pkgInfoTable.bundleName == bundleName) { - DriverInfo tmpDrvInfo; - if (tmpDrvInfo.UnSerialize(pkgInfoTable.driverInfo) != EDM_OK) { - EDM_LOGE(MODULE_PKG_MGR, "Unserialize driverInfo faild"); - return; - } - shared_ptr usbDriverInfo = make_shared(); - if (usbDriverInfo == nullptr) { - EDM_LOGE(MODULE_BUS_USB, "creat UsbDriverInfo obj fail\n"); - return; - } - usbDriverInfo = std::static_pointer_cast(tmpDrvInfo.driverInfoExt_); - if (usbDriverInfo == nullptr) { - EDM_LOGE(MODULE_BUS_USB, "static_pointer_cast UsbDriverInfo fail\n"); - return; - } - uint32_t versionCode = ParseVersionCode(driverInfos, bundleName); - std::vector productIds = usbDriverInfo->GetProductIds(); - std::vector vendorIds = usbDriverInfo->GetVendorIds(); - std::string pids = ExtDevReportSysEvent::ParseIdVector(productIds); - std::string vids = ExtDevReportSysEvent::ParseIdVector(vendorIds); - ExtDevReportSysEvent::ReportDriverPackageCycleManageSysEvent(pkgInfoTable, pids, vids, - versionCode, driverEventName); - } - } -} - -int DrvBundleStateCallback::ParseVersionCode(const std::vector &driverInfos, - const std::string &bundleName) -{ - uint32_t versionCode = 0; - for (const auto &driverInfo : driverInfos) { - if (driverInfo.bundleName == bundleName) { - versionCode = driverInfo.applicationInfo.versionCode; - break; - } - } - return versionCode; -} - -shared_ptr DrvBundleStateCallback::GetDriverInfo(const std::vector &driverInfos, - const std::string &bundleName) -{ - shared_ptr driverInfo = make_shared(); - std::vector pkgInfoTables; - ParseToPkgInfoTables(driverInfos, pkgInfoTables); - for (const auto &pkgInfoTable : pkgInfoTables) { - if (pkgInfoTable.bundleName == bundleName) { - int ret = driverInfo->UnSerialize(pkgInfoTable.driverInfo); - if (ret != EDM_OK) { - EDM_LOGE(MODULE_PKG_MGR, "Unserialize driverInfo faild"); - return nullptr; - } - break; - } - } - return driverInfo; -} } } \ No newline at end of file diff --git a/services/native/driver_extension_manager/src/drivers_pkg_manager/pkg_db_helper.cpp b/services/native/driver_extension_manager/src/drivers_pkg_manager/pkg_db_helper.cpp index b3cb34f545057b5fa201247e3f4a39ae6125191b..dd9d78a64467a89382ae8170b3e09d70a348faf5 100644 --- a/services/native/driver_extension_manager/src/drivers_pkg_manager/pkg_db_helper.cpp +++ b/services/native/driver_extension_manager/src/drivers_pkg_manager/pkg_db_helper.cpp @@ -261,14 +261,14 @@ static bool ParseToPkgInfos(const std::shared_ptr &resultSet, std::ve return true; } -int32_t PkgDbHelper::QueryPkgInfos(std::vector &pkgInfos, - bool isByDriverUid, const std::string &driverUid) +int32_t PkgDbHelper::QueryPkgInfos(const std::string &whereKey, const std::string &whereValue, + std::vector &pkgInfos) { std::lock_guard guard(databaseMutex_); std::vector columns = { "driverUid", "bundleName", "driverName", "driverInfo" }; RdbPredicates rdbPredicates(PKG_TABLE_NAME); - if (isByDriverUid) { - rdbPredicates.EqualTo("driverUid", driverUid); + if (!whereKey.empty()) { + rdbPredicates.EqualTo(whereKey, whereValue); } int32_t ret = rightDatabase_->BeginTransaction(); if (ret < PKG_OK) { @@ -295,6 +295,17 @@ int32_t PkgDbHelper::QueryPkgInfos(std::vector &pkgInfos, return static_cast(pkgInfos.size()); } +int32_t PkgDbHelper::QueryPkgInfos(std::vector &pkgInfos, + bool isByDriverUid, const std::string &driverUid) +{ + return QueryPkgInfos(isByDriverUid ? "driverUid" : "", driverUid, pkgInfos); +} + +int32_t PkgDbHelper::QueryPkgInfos(const std::string &bundleName, std::vector &pkgInfos) +{ + return QueryPkgInfos(bundleName.empty() ? "" : "bundleName", bundleName, pkgInfos); +} + int32_t PkgDbHelper::QueryAllSize(std::vector &allBundleAbility) { std::lock_guard guard(databaseMutex_);