From a5d24f2876f3a7092f557977066460798c13dbbc Mon Sep 17 00:00:00 2001 From: Anduin1109 Date: Thu, 11 Sep 2025 20:22:51 +0800 Subject: [PATCH] add init for enterprise device Signed-off-by: Anduin1109 --- services/native/include/usb_host_manager.h | 1 + services/native/src/usb_host_manager.cpp | 19 +++++++++++++++++++ 2 files changed, 20 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 454d092d..d0cecc8f 100644 --- a/services/native/src/usb_host_manager.cpp +++ b/services/native/src/usb_host_manager.cpp @@ -152,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); @@ -1440,6 +1441,19 @@ bool UsbHostManager::IsEdmEnabled() return edmParaValue == "true"; } +void UsbHostManager::SetMdmDefaultAuthorize(bool authorized) +{ + 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"); + } + } +} + int32_t UsbHostManager::UsbDeviceAuthorize( uint8_t busNum, uint8_t devAddr, bool authorized, const std::string &operationType) { @@ -1449,6 +1463,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