From ab005fd890bd9d6bf71545f5915abb96aad4765b Mon Sep 17 00:00:00 2001 From: Anduin1109 Date: Thu, 11 Sep 2025 15:33:19 +0800 Subject: [PATCH 1/2] add init for enterprise device Signed-off-by: Anduin1109 --- services/native/include/usb_host_manager.h | 1 + services/native/src/usb_host_manager.cpp | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/services/native/include/usb_host_manager.h b/services/native/include/usb_host_manager.h index 5e965b25..fc99ebdb 100644 --- a/services/native/include/usb_host_manager.h +++ b/services/native/include/usb_host_manager.h @@ -131,6 +131,7 @@ private: int32_t FillDevStrings(UsbDevice &dev); std::string GetDevStringValFromIdx(uint8_t busNum, uint8_t devAddr, uint8_t idx); bool IsEdmEnabled(); + void SetMdmDefaultAuthorize(bool authorized); int32_t ExecuteManageDevicePolicy(std::vector &whiteList); int32_t ExecuteManageInterfaceType(const std::vector &disableType, bool disable); int32_t GetEdmPolicy(bool &IsGlobalDisabled, std::vector &disableType, diff --git a/services/native/src/usb_host_manager.cpp b/services/native/src/usb_host_manager.cpp index 7ff3d4f3..126aff2d 100644 --- a/services/native/src/usb_host_manager.cpp +++ b/services/native/src/usb_host_manager.cpp @@ -118,6 +118,7 @@ UsbHostManager::UsbHostManager(SystemAbility *systemAbility) { systemAbility_ = systemAbility; usbRightManager_ = std::make_shared(); + SetMdmDefaultAuthorize(true); #ifndef USB_MANAGER_PASS_THROUGH usbd_ = OHOS::HDI::Usb::V1_2::IUsbInterface::Get(); USB_HILOGI(MODULE_USB_SERVICE, "%{public}s:%{public}d usbd_ == nullptr: %{public}d", @@ -1435,6 +1436,16 @@ bool UsbHostManager::IsEdmEnabled() return edmParaValue == "true"; } +void UsbHostManager::SetMdmDefaultAuthorize(bool authorized) +{ + if (OHOS::system::GetParameter("const.edm.is_enterprise", "false") == "true") { + auto ret = UsbDeviceAuthorize(0, 0, authorized, "GlobalType"); + if (ret != UEC_OK) { + USB_HILOGE(MODULE_USB_SERVICE, "failed to set usb default authorize for enterprise device"); + } + } +} + int32_t UsbHostManager::UsbDeviceAuthorize( uint8_t busNum, uint8_t devAddr, bool authorized, const std::string &operationType) { @@ -1444,6 +1455,11 @@ int32_t UsbHostManager::UsbDeviceAuthorize( USB_HILOGE(MODULE_USB_SERVICE, "usbDeviceInterface_ is nullptr"); return UEC_SERVICE_INVALID_VALUE; } + if (busNum == 0 && devAddr == 0) { + USB_HILOGI(MODULE_USB_SERVICE, "set default authorize value"); + return usbDeviceInterface_->UsbDeviceAuthorize(busNum, devAddr, authorized); + } + std::string name = std::to_string(busNum) + "-" + std::to_string(devAddr); auto iterDev = devices_.find(name); if (iterDev == devices_.end()) { -- Gitee From 0d618dca63e26af475d606315b39fd5bf48a6cd4 Mon Sep 17 00:00:00 2001 From: Anduin1109 Date: Thu, 11 Sep 2025 16:29:43 +0800 Subject: [PATCH 2/2] add init for enterprise device Signed-off-by: Anduin1109 --- services/native/src/usb_host_manager.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/services/native/src/usb_host_manager.cpp b/services/native/src/usb_host_manager.cpp index 126aff2d..74d6b2c4 100644 --- a/services/native/src/usb_host_manager.cpp +++ b/services/native/src/usb_host_manager.cpp @@ -118,7 +118,6 @@ UsbHostManager::UsbHostManager(SystemAbility *systemAbility) { systemAbility_ = systemAbility; usbRightManager_ = std::make_shared(); - SetMdmDefaultAuthorize(true); #ifndef USB_MANAGER_PASS_THROUGH usbd_ = OHOS::HDI::Usb::V1_2::IUsbInterface::Get(); USB_HILOGI(MODULE_USB_SERVICE, "%{public}s:%{public}d usbd_ == nullptr: %{public}d", @@ -153,6 +152,7 @@ bool UsbHostManager::InitUsbHostInterface() USB_HILOGE(MODULE_USB_SERVICE, "usbManagerSubscriber_ is nullptr"); return false; } + SetMdmDefaultAuthorize(true); ErrCode ret = usbHostInterface_->BindUsbdHostSubscriber(usbManagerSubscriber_); USB_HILOGI(MODULE_USB_SERVICE, "entry InitUsbHostInterface ret: %{public}d", ret); return SUCCEEDED(ret); @@ -1438,7 +1438,10 @@ bool UsbHostManager::IsEdmEnabled() void UsbHostManager::SetMdmDefaultAuthorize(bool authorized) { - if (OHOS::system::GetParameter("const.edm.is_enterprise", "false") == "true") { + std::string isEnterpriseDevice = OHOS::system::GetParameter("const.edm.is_enterprise", "false"); + USB_HILOGI(MODULE_USB_SERVICE, "set mdm device enter, param=%{public}s", isEnterpriseDevice.c_str()); + if (isEnterpriseDevice == "true") { + // set default authorize status with param {0, 0}, and will enable all devices auto ret = UsbDeviceAuthorize(0, 0, authorized, "GlobalType"); if (ret != UEC_OK) { USB_HILOGE(MODULE_USB_SERVICE, "failed to set usb default authorize for enterprise device"); -- Gitee