diff --git a/etc/init/edm.cfg b/etc/init/edm.cfg index 3ef8a63cc39d95852a821a978b07289349f1a3f8..3aaf6e531f16cc8e6c7b94e647bbcd637643f9ef 100644 --- a/etc/init/edm.cfg +++ b/etc/init/edm.cfg @@ -65,6 +65,7 @@ "ohos.permission.INSTALL_SELF_BUNDLE", "ohos.permission.MANAGE_APN_SETTING", "ohos.permission.MANAGE_APP_BOOT_INTERNAL", + "ohos.permission.MANAGE_APP_INSTALL_INFO", "ohos.permission.MANAGE_APP_KEEP_ALIVE_INTERNAL", "ohos.permission.MANAGE_BLUETOOTH", "ohos.permission.MANAGE_EDM_POLICY", @@ -75,6 +76,7 @@ "ohos.permission.MANAGE_USB_CONFIG", "ohos.permission.MANAGE_VPN", "ohos.permission.MANAGE_WIFI_CONNECTION", + "ohos.permission.RECEIVE_APP_INSTALL_INFO_CHANGE", "ohos.permission.MICROPHONE_CONTROL", "ohos.permission.MOUNT_UNMOUNT_MANAGER", "ohos.permission.NETSYS_INTERNAL", diff --git a/interfaces/inner_api/BUILD.gn b/interfaces/inner_api/BUILD.gn index 68e375ed97269e6a40baed3d14d1c63e07a4e2ce..82312dcdb86e8cb548dabb884d9223b70b6d2656 100644 --- a/interfaces/inner_api/BUILD.gn +++ b/interfaces/inner_api/BUILD.gn @@ -52,6 +52,7 @@ ohos_shared_library("edmservice_kits") { "./bundle_manager/src/bundle_manager_proxy.cpp", "./bundle_manager/src/edm_application_info.cpp", "./bundle_manager/src/edm_bundle_info.cpp", + "./bundle_manager/src/install_market_apps_serializer.cpp", "./bundle_manager/src/install_param_serializer.cpp", "./common/src/domain_account_policy.cpp", "./common/src/edm_load_callback.cpp", diff --git a/interfaces/inner_api/bundle_manager/include/bundle_manager_proxy.h b/interfaces/inner_api/bundle_manager/include/bundle_manager_proxy.h index b5b9df71447dcc054fc1759ecbbf309f850c6a9c..002962d0ae8ade3aeea22ed50f125a1cb42683ef 100644 --- a/interfaces/inner_api/bundle_manager/include/bundle_manager_proxy.h +++ b/interfaces/inner_api/bundle_manager/include/bundle_manager_proxy.h @@ -43,6 +43,7 @@ public: int32_t AddOrRemoveInstallationAllowedAppDistributionTypes(MessageParcel &data, FuncOperateType operateType); int32_t GetInstallationAllowedAppDistributionTypes(MessageParcel &data, std::vector &installationAllowedAppDistributionTypes); + int32_t InstallMarketApps(MessageParcel &data, std::vector &apps); private: void AddPolicyTypeMap(); static std::shared_ptr instance_; diff --git a/interfaces/inner_api/bundle_manager/include/install_market_apps_serializer.h b/interfaces/inner_api/bundle_manager/include/install_market_apps_serializer.h new file mode 100644 index 0000000000000000000000000000000000000000..6bf7f9272974c21a094c375f8824cf6bd707e223 --- /dev/null +++ b/interfaces/inner_api/bundle_manager/include/install_market_apps_serializer.h @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef INTERFACES_INNER_API_BUNDLE_MANAGER_INCLUDE_INSTALL_MARKET_APPS_SERIALIZER_H +#define INTERFACES_INNER_API_BUNDLE_MANAGER_INCLUDE_INSTALL_MARKET_APPS_SERIALIZER_H + +#include +#include "ipolicy_serializer.h" +#include "singleton.h" + +namespace OHOS { +namespace EDM { +struct InstallMarketAppsInfo { + std::vector bundleNames; + int32_t installFlag = 0; + int32_t eventCode = 0; + std::string singleBundleName; +}; + +/* + * Policy data serializer of type int. + */ +class InstallMarketAppsSerializer : public IPolicySerializer, + public DelayedSingleton { +public: + bool Deserialize(const std::string &jsonString, InstallMarketAppsInfo &dataObj) override; + + bool Serialize(const InstallMarketAppsInfo &dataObj, std::string &jsonString) override; + + bool GetPolicy(MessageParcel &data, InstallMarketAppsInfo &result) override; + + bool WritePolicy(MessageParcel &reply, InstallMarketAppsInfo &result) override; + + bool MergePolicy(std::vector &data, InstallMarketAppsInfo &result) override; +}; +} // namespace EDM +} // namespace OHOS + +#endif // INTERFACES_INNER_API_BUNDLE_MANAGER_INCLUDE_INSTALL_MARKET_APPS_SERIALIZER_H diff --git a/interfaces/inner_api/bundle_manager/src/bundle_manager_proxy.cpp b/interfaces/inner_api/bundle_manager/src/bundle_manager_proxy.cpp index 68c7832a82ee07aeb23421a9b2b4298e06463f07..7af82038b77b28a39cdb0d150250726841595b5b 100644 --- a/interfaces/inner_api/bundle_manager/src/bundle_manager_proxy.cpp +++ b/interfaces/inner_api/bundle_manager/src/bundle_manager_proxy.cpp @@ -34,6 +34,7 @@ std::once_flag BundleManagerProxy::flag_; const std::u16string DESCRIPTOR = u"ohos.edm.IEnterpriseDeviceMgr"; const std::string HAP_DIRECTORY = "/data/service/el1/public/edm/stream_install"; const std::string SEPARATOR = "/"; +const int32_t SET_MARKET_APPS = 0; bool BundleManagerProxy::GetData(void *&buffer, size_t size, const void *data) { @@ -182,6 +183,16 @@ int32_t BundleManagerProxy::GetBundlesByPolicyType(AppExecFwk::ElementName &admi return ERR_OK; } +int32_t BundleManagerProxy::InstallMarketApps(MessageParcel &data, std::vector &apps) +{ + EDMLOGD("BundleManagerProxy::InstallMarketApps"); + data.WriteInt32(SET_MARKET_APPS); + MessageParcel reply; + std::uint32_t funcCode = POLICY_FUNC_CODE((std::uint32_t)FuncOperateType::SET, + EdmInterfaceCode::INSTALL_MARKET_APPS); + return EnterpriseDeviceMgrProxy::GetInstance()->HandleDevicePolicy(funcCode, data); +} + int32_t BundleManagerProxy::Install(AppExecFwk::ElementName &admin, std::vector &hapFilePaths, AppExecFwk::InstallParam &installParam, std::string &errMessage) { diff --git a/interfaces/inner_api/bundle_manager/src/install_market_apps_serializer.cpp b/interfaces/inner_api/bundle_manager/src/install_market_apps_serializer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..5096f8df802ccdf988c60aff7a9632548f98c0cf --- /dev/null +++ b/interfaces/inner_api/bundle_manager/src/install_market_apps_serializer.cpp @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "install_market_apps_serializer.h" + +namespace OHOS { +namespace EDM { +bool InstallMarketAppsSerializer::Deserialize(const std::string &jsonString, InstallMarketAppsInfo &config) +{ + return true; +} + +bool InstallMarketAppsSerializer::Serialize(const InstallMarketAppsInfo &config, std::string &jsonString) +{ + return true; +} + +bool InstallMarketAppsSerializer::GetPolicy(MessageParcel &data, InstallMarketAppsInfo &result) +{ + data.ReadStringVector(&result.bundleNames); + result.installFlag = data.ReadInt32(); + result.eventCode = data.ReadInt32(); + result.singleBundleName = data.ReadString(); + return true; +} + +bool InstallMarketAppsSerializer::WritePolicy(MessageParcel &reply, InstallMarketAppsInfo &result) +{ + return true; +} + +bool InstallMarketAppsSerializer::MergePolicy(std::vector &data, InstallMarketAppsInfo &result) +{ + return true; +} +} // namespace EDM +} // namespace OHOS \ No newline at end of file diff --git a/interfaces/inner_api/common/include/edm_ipc_interface_code.h b/interfaces/inner_api/common/include/edm_ipc_interface_code.h index 51542b84363196171e31517324c0d5ffa86f5223..ed20c8f073c6070a3c4134cc442ae18a47dfb436 100644 --- a/interfaces/inner_api/common/include/edm_ipc_interface_code.h +++ b/interfaces/inner_api/common/include/edm_ipc_interface_code.h @@ -158,6 +158,10 @@ enum EdmInterfaceCode : uint32_t { DISABLED_PRINT = 1113, PERMISSION_MANAGED_STATE = 1114, SET_WALL_PAPER = 1115, + DISABLED_APP_CLONE = 1116, + DISALLOWED_RANDOM_MAC_ADDRESS = 1117, + DISALLOWED_EXTERNAL_STORAGE_CARD = 1118, + INSTALL_MARKET_APPS = 1119, POLICY_CODE_END = 3000, }; } // namespace EDM diff --git a/interfaces/inner_api/libedmservice_kits.map b/interfaces/inner_api/libedmservice_kits.map index 18ef4b39c4d5467ef285be4e8978ee9c40279c3d..86edd91b7720a2f99b166271eb55f4b5fc936199 100644 --- a/interfaces/inner_api/libedmservice_kits.map +++ b/interfaces/inner_api/libedmservice_kits.map @@ -93,6 +93,8 @@ VTT?for?OHOS::EDM::ManageAutoStartAppInfo; vtable?for?OHOS::EDM::ManageAutoStartAppInfo; vtable?for?OHOS::EDM::WallPaperParamSerializer; + OHOS::EDM::InstallMarketAppsSerializer::*; + vtable?for?OHOS::EDM::InstallMarketAppsSerializer; }; local: *; diff --git a/interfaces/inner_api/plugin_kits/include/iplugin.h b/interfaces/inner_api/plugin_kits/include/iplugin.h index 2bf9d18bb1cfa3e211a24600097970b51373b938..6a8bfaae2833ec4a2598a9a7da8a8f2354861eda 100644 --- a/interfaces/inner_api/plugin_kits/include/iplugin.h +++ b/interfaces/inner_api/plugin_kits/include/iplugin.h @@ -121,6 +121,15 @@ public: std::shared_ptr GetExecuteStrategy(); void SetPluginType(IPlugin::PluginType type); IPlugin::PluginType GetPluginType(); + bool GetPluginUnloadFlag() + { + return this->pluginUnloadFlag_; + } + + void SetPluginUnloadFlag(bool flag) + { + this->pluginUnloadFlag_ = flag; + } virtual ~IPlugin(); protected: @@ -134,6 +143,7 @@ protected: bool needSave_ = true; bool isGlobal_ = true; IPlugin::PluginType type_ = PluginType::BASIC; + bool pluginUnloadFlag_ = true; private: std::string CheckAndGetPermissionFromConfig(PermissionType permissionType, const std::string &permissionTag, diff --git a/interfaces/kits/bundle_manager/include/bundle_manager_addon.h b/interfaces/kits/bundle_manager/include/bundle_manager_addon.h index 91ba2aab7f568a1b2a9088cb619f1d3b51fa26b0..903161d1375b4331d1c3edf18dc18e7be88e1311 100644 --- a/interfaces/kits/bundle_manager/include/bundle_manager_addon.h +++ b/interfaces/kits/bundle_manager/include/bundle_manager_addon.h @@ -90,6 +90,7 @@ public: static napi_value AddOrRemoveInstallationAllowedAppDistributionTypes(napi_env env, napi_callback_info info, FuncOperateType operateType); static napi_value GetInstallationAllowedAppDistributionTypes(napi_env env, napi_callback_info info); + static napi_value InstallMarketApps(napi_env env, napi_callback_info info); private: static napi_value AddOrRemoveInstallBundles(napi_env env, napi_callback_info info, const std::string &workName, diff --git a/interfaces/kits/bundle_manager/src/bundle_manager_addon.cpp b/interfaces/kits/bundle_manager/src/bundle_manager_addon.cpp index 34e98135dbe80d4882db789958beb784bd6d7fab..300e204b5f1b038e1463372687db455da2cd8d65 100644 --- a/interfaces/kits/bundle_manager/src/bundle_manager_addon.cpp +++ b/interfaces/kits/bundle_manager/src/bundle_manager_addon.cpp @@ -116,6 +116,7 @@ napi_value BundleManagerAddon::Init(napi_env env, napi_value exports) RemoveInstallationAllowedAppDistributionTypes), DECLARE_NAPI_FUNCTION("getInstallationAllowedAppDistributionTypes", GetInstallationAllowedAppDistributionTypes), + DECLARE_NAPI_FUNCTION("installMarketApps", InstallMarketApps), DECLARE_NAPI_PROPERTY("AppDistributionType", nAppDistributionType), }; NAPI_CALL(env, napi_define_properties(env, exports, sizeof(property) / sizeof(property[0]), property)); @@ -829,6 +830,30 @@ napi_value BundleManagerAddon::GetInstallationAllowedAppDistributionTypes(napi_e return result; } +napi_value BundleManagerAddon::InstallMarketApps(napi_env env, napi_callback_info info) +{ + AddonMethodSign addonMethodSign; + addonMethodSign.name = "InstallMarketApps"; + addonMethodSign.argsType = {EdmAddonCommonType::ELEMENT, EdmAddonCommonType::ARRAY_STRING}; + addonMethodSign.methodAttribute = MethodAttribute::HANDLE; + AdapterAddonData adapterAddonData{}; + if (JsObjectToData(env, info, addonMethodSign, &adapterAddonData) == nullptr) { + return nullptr; + } + auto bundleManagerProxy = BundleManagerProxy::GetBundleManagerProxy(); + if (bundleManagerProxy == nullptr) { + EDMLOGE("can not get BundleManagerProxy"); + return nullptr; + } + std::vector installMarketApps; + int32_t retCode = bundleManagerProxy->InstallMarketApps(adapterAddonData.data, + installMarketApps); + if (FAILED(retCode)) { + napi_throw(env, CreateError(env, retCode)); + } + return nullptr; +} + napi_value BundleManagerAddon::GetAllowedInstallBundlesSync(napi_env env, napi_callback_info info) { EDMLOGI("NAPI_GetAllowedInstallBundles called"); diff --git a/services/edm/include/enterprise_device_mgr_ability.h b/services/edm/include/enterprise_device_mgr_ability.h index 3153f207fcfdfacc5539a4425e72531f3d522501..658064ce94fbb17dc3719ca60a296ab38ecfa658 100644 --- a/services/edm/include/enterprise_device_mgr_ability.h +++ b/services/edm/include/enterprise_device_mgr_ability.h @@ -72,6 +72,7 @@ public: const std::vector &policies, int32_t userId) override; ErrCode SetBundleInstallPolicies(const std::vector &bundles, int32_t userId, int32_t policyType) override; + ErrCode UnloadInstallMarketAppsPlugin() override; ErrCode HandleDevicePolicy(uint32_t code, AppExecFwk::ElementName &admin, MessageParcel &data, MessageParcel &reply, int32_t userId) override; @@ -135,6 +136,8 @@ private: ErrCode DelDisallowUninstallApp(const std::string &bundleName); void AfterEnableAdmin(const AppExecFwk::ElementName &admin, AdminType type, int32_t userId); void ReportFuncEvent(uint32_t code); + void UpdateMarketAppsState(const EventFwk::CommonEventData &data, const int32_t event); + void InitAgTask(); #ifdef COMMON_EVENT_SERVICE_EDM_ENABLE std::shared_ptr CreateEnterpriseDeviceEventSubscriber( EnterpriseDeviceMgrAbility &listener); diff --git a/services/edm/include/plugin_manager.h b/services/edm/include/plugin_manager.h index b70f9b4a01bb602814c9623429dc4884b0462c37..16068e9c1b6151f7cf879a69b27630ba94946b9b 100644 --- a/services/edm/include/plugin_manager.h +++ b/services/edm/include/plugin_manager.h @@ -92,6 +92,8 @@ private: void DumpPluginInner(std::map> pluginsCode, std::map> pluginsName); void DumpPluginConfig(IPlugin::PolicyPermissionConfig config); + bool ExtraHasPersistPlugin(std::vector targetVec); + bool HasPersistPlugin(std::vector targetVec); std::shared_ptr CreateExecuteStrategy(ExecuteStrategy strategy); std::shared_ptr enhanceStrategy_ = std::make_shared(); std::shared_ptr singleStrategy_ = std::make_shared(); diff --git a/services/edm/src/enterprise_device_mgr_ability.cpp b/services/edm/src/enterprise_device_mgr_ability.cpp index b86712426ac3b8912866e44c4f7e4b9b1fa3638d..bcc4b47119cef0c165d892c6a7c38a98ade7e324 100644 --- a/services/edm/src/enterprise_device_mgr_ability.cpp +++ b/services/edm/src/enterprise_device_mgr_ability.cpp @@ -85,6 +85,14 @@ const char* const KEY_EDM_DISPLAY = "com.enterprise.enterprise_device_manager_di const std::string POLICY_ALLOW_ALL = "allow_all"; const int32_t INVALID_SYSTEM_ABILITY_ID = -1; const int32_t MAX_POLICY_TYPE = 3; +const int32_t UPDATE_APPS_STATE_ON_AG_CHANGE = 1; +const int32_t UPDATE_APPS_STATE_ON_BMS_CHANGE = 2; +const int32_t INIT_AG_TASK = 3; +const int32_t INSTALL_MARKET_APPS_PLUGIN_CODE = 3028; +const std::string AG_EVENT_DOWNLOAD_STATUS_CHANGE = + "com.huawei.hmsapp.appgallery.commonevent.EVENT_DOWNLOAD_STATUS_CHANGE"; +const std::string AG_EVENT_INSTALL_STATUS_CHANGE = + "com.huawei.hmsapp.appgallery.commonevent.EVENT_INSTALL_STATUS_CHANGE"; std::shared_mutex EnterpriseDeviceMgrAbility::adminLock_; @@ -114,6 +122,7 @@ void EnterpriseDeviceMgrAbility::AddCommonEventFuncMap() commonEventFuncMap_[EventFwk::CommonEventSupport::COMMON_EVENT_PACKAGE_ADDED] = [](EnterpriseDeviceMgrAbility* that, const EventFwk::CommonEventData &data) { that->OnCommonEventPackageAdded(data); + that->UpdateMarketAppsState(data, UPDATE_APPS_STATE_ON_BMS_CHANGE); }; commonEventFuncMap_[EventFwk::CommonEventSupport::COMMON_EVENT_PACKAGE_REMOVED] = [](EnterpriseDeviceMgrAbility* that, const EventFwk::CommonEventData &data) { @@ -139,6 +148,60 @@ void EnterpriseDeviceMgrAbility::AddCommonEventFuncMap() [](EnterpriseDeviceMgrAbility* that, const EventFwk::CommonEventData &data) { that->OnCommonEventKioskMode(data, false); }; + commonEventFuncMap_[AG_EVENT_DOWNLOAD_STATUS_CHANGE] = + [](EnterpriseDeviceMgrAbility* that, const EventFwk::CommonEventData &data) { + that->UpdateMarketAppsState(data, UPDATE_APPS_STATE_ON_AG_CHANGE); + }; + commonEventFuncMap_[AG_EVENT_INSTALL_STATUS_CHANGE] = + [](EnterpriseDeviceMgrAbility* that, const EventFwk::CommonEventData &data) { + that->UpdateMarketAppsState(data, UPDATE_APPS_STATE_ON_AG_CHANGE); + }; +} + +void EnterpriseDeviceMgrAbility::InitAgTask() +{ + auto superAdmin = AdminManager::GetInstance()->GetSuperAdmin(); + if (superAdmin == nullptr) { + EDMLOGE("current super admin is nullptr"); + return; + } + std::uint32_t funcCode = + POLICY_FUNC_CODE((std::uint32_t)FuncOperateType::SET, EdmInterfaceCode::INSTALL_MARKET_APPS); + MessageParcel reply; + MessageParcel messageData; + messageData.WriteString(WITHOUT_PERMISSION_TAG); + std::vector bundleNames = {}; + messageData.WriteStringVector(bundleNames); + messageData.WriteInt32(INIT_AG_TASK); + + OHOS::AppExecFwk::ElementName elementName; + elementName.SetBundleName(superAdmin->adminInfo_.packageName_); + elementName.SetAbilityName(superAdmin->adminInfo_.className_); + HandleDevicePolicy(funcCode, elementName, messageData, reply, EdmConstants::DEFAULT_USER_ID); +} + +void EnterpriseDeviceMgrAbility::UpdateMarketAppsState(const EventFwk::CommonEventData &data, const int32_t event) +{ + auto superAdmin = AdminManager::GetInstance()->GetSuperAdmin(); + if (superAdmin == nullptr) { + EDMLOGE("current super admin is nullptr"); + return; + } + std::uint32_t funcCode = + POLICY_FUNC_CODE((std::uint32_t)FuncOperateType::SET, EdmInterfaceCode::INSTALL_MARKET_APPS); + MessageParcel reply; + MessageParcel messageData; + messageData.WriteString(WITHOUT_PERMISSION_TAG); + std::vector bundleNames = {}; + messageData.WriteStringVector(bundleNames); + messageData.WriteInt32(event); + messageData.WriteInt32(data.GetCode()); + messageData.WriteString(data.GetWant().GetStringParam(WANT_BUNDLE_NAME)); + + OHOS::AppExecFwk::ElementName elementName; + elementName.SetBundleName(superAdmin->adminInfo_.packageName_); + elementName.SetAbilityName(superAdmin->adminInfo_.className_); + HandleDevicePolicy(funcCode, elementName, messageData, reply, EdmConstants::DEFAULT_USER_ID); } void EnterpriseDeviceMgrAbility::OnCommonEventSystemUpdate(const EventFwk::CommonEventData &data) @@ -622,22 +685,25 @@ int32_t EnterpriseDeviceMgrAbility::Dump(int32_t fd, const std::vector autoLock(adminLock_); - EDMLOGD("EnterpriseDeviceMgrAbility::OnStart() Publish"); - InitAllAdmins(); - InitAllPolices(); - RemoveAllDebugAdmin(); - if (!registerToService_) { - if (!Publish(this)) { - EDMLOGE("EnterpriseDeviceMgrAbility: res == false"); - return; + { + std::unique_lock autoLock(adminLock_); + EDMLOGD("EnterpriseDeviceMgrAbility::OnStart() Publish"); + InitAllAdmins(); + InitAllPolices(); + RemoveAllDebugAdmin(); + if (!registerToService_) { + if (!Publish(this)) { + EDMLOGE("EnterpriseDeviceMgrAbility: res == false"); + return; + } + registerToService_ = true; } - registerToService_ = true; + WatermarkObserverManager::GetInstance(); + AddOnAddSystemAbilityFuncMap(); + AddSystemAbilityListeners(); + CheckAndUpdateByodSettingsData(); } - WatermarkObserverManager::GetInstance(); - AddOnAddSystemAbilityFuncMap(); - AddSystemAbilityListeners(); - CheckAndUpdateByodSettingsData(); + InitAgTask(); } void EnterpriseDeviceMgrAbility::CheckAndUpdateByodSettingsData() @@ -2059,6 +2125,23 @@ ErrCode EnterpriseDeviceMgrAbility::CheckDelegatedPolicies(std::shared_ptrVerifyCallingPermission(tokenId, + EdmPermission::PERMISSION_ENTERPRISE_INSTALL_BUNDLE) && IPCSkeleton::GetCallingUid() == EDM_UID) { + EDMLOGW("EnterpriseDeviceMgrAbility::UnloadInstallMarketAppsPlugin check permission failed"); + return EdmReturnErrCode::PERMISSION_DENIED; + } + auto plugin = PluginManager::GetInstance()->GetPluginByCode(INSTALL_MARKET_APPS_PLUGIN_CODE); + if (plugin == nullptr) { + EDMLOGE("get Plugin fail %{public}d", INSTALL_MARKET_APPS_PLUGIN_CODE); + return; + } + plugin->SetPluginUnloadFlag(true); + return ERR_OK; +} + ErrCode EnterpriseDeviceMgrAbility::GetAdmins(std::vector> &wants) { std::vector> admins; diff --git a/services/edm/src/plugin_manager.cpp b/services/edm/src/plugin_manager.cpp index 45e3613f36c35a8bac78fc7bf70179a9d117412f..eb2ddf734db778b326da34a554f8233d626048f2 100644 --- a/services/edm/src/plugin_manager.cpp +++ b/services/edm/src/plugin_manager.cpp @@ -105,7 +105,8 @@ std::vector PluginManager::needExtraSoCodes_ = { EdmInterfaceCode::GET_DEVICE_SERIAL, EdmInterfaceCode::GET_DEVICE_NAME, EdmInterfaceCode::GET_DEVICE_INFO, EdmInterfaceCode::OPERATE_DEVICE, EdmInterfaceCode::SET_OTA_UPDATE_POLICY, EdmInterfaceCode::NOTIFY_UPGRADE_PACKAGES, - EdmInterfaceCode::GET_ADMINPROVISION_INFO, EdmInterfaceCode::SET_WALL_PAPER + EdmInterfaceCode::GET_ADMINPROVISION_INFO, EdmInterfaceCode::SET_WALL_PAPER, + EdmInterfaceCode::INSTALL_MARKET_APPS }; PluginManager::PluginManager() @@ -410,9 +411,16 @@ void PluginManager::UnloadPlugin(const std::string &soName) } else { targetVec = &extraPluginCodeList; GetExtraPluginCodeList(targetVec); + if (ExtraHasPersistPlugin(*targetVec)) { + return; + } extensionPluginMap_.clear(); executeStrategyMap_.clear(); } + if (HasPersistPlugin(*targetVec)) { + return; + } + for (const auto& code : *targetVec) { RemovePlugin(GetPluginByCode(code)); } @@ -434,6 +442,41 @@ void PluginManager::UnloadPlugin(const std::string &soName) soLoadStateMap_.erase(soName); } +bool PluginManager::ExtraHasPersistPlugin(std::vector targetVec) +{ + for (const auto& code : targetVec) { + auto plugin = GetPluginByCode(code); + if (plugin != nullptr && !plugin->GetPluginUnloadFlag()) { + EDMLOGW("PluginManager::UnloadPlugin this plugin:%{public}d need persist", code.c_str()); + return true; + } + } + return false; +} + +bool PluginManager::HasPersistPlugin(std::vector targetVec) +{ + for (const auto& code : targetVec) { + std::uint32_t extensionCode; + auto it = extensionPluginMap_.find(code); + if (it != extensionPluginMap_.end()) { + extensionCode = it->second; + auto extensionPlugin = GetPluginByCode(extensionCode); + if (extensionPlugin != nullptr && !extensionPlugin->GetPluginUnloadFlag()) { + EDMLOGW("PluginManager::UnloadPlugin this extension plugin:%{public}d need persist", extensionCode.c_str()); + return true; + } + } + + auto plugin = GetPluginByCode(code); + if (plugin != nullptr && !plugin->GetPluginUnloadFlag()) { + EDMLOGW("PluginManager::UnloadPlugin this plugin:%{public}d need persist", code.c_str()); + return true; + } + } + return false; +} + void PluginManager::GetExtraPluginCodeList(std::vector* targetVec) { for (const auto& it : pluginsCode_) { diff --git a/services/edm_plugin/BUILD.gn b/services/edm_plugin/BUILD.gn index 9ff96a305ddb8cee49ea04a8edeff9e1305ab1c5..9df2b3ea307f76630efc3702e326384c5d1d856e 100644 --- a/services/edm_plugin/BUILD.gn +++ b/services/edm_plugin/BUILD.gn @@ -583,6 +583,7 @@ ohos_shared_library("need_extra_plugin") { sources += [ "./src/get_adminprovision_info_plugin.cpp", "./src/get_device_info_plugin.cpp", + "./src/install_market_apps_plugin.cpp", "./src/notify_update_packages_plugin.cpp", "./src/set_update_policy_plugin.cpp", "./src/set_wall_paper_plugin.cpp", diff --git a/services/edm_plugin/include/install_market_apps_plugin.h b/services/edm_plugin/include/install_market_apps_plugin.h new file mode 100644 index 0000000000000000000000000000000000000000..511c5d3ecb15033382e515fc5943f7f27ee6dbcc --- /dev/null +++ b/services/edm_plugin/include/install_market_apps_plugin.h @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef SERVICES_EDM_PLUGIN_INCLUDE_INSTALL_PLUGIN_H +#define SERVICES_EDM_PLUGIN_INCLUDE_INSTALL_PLUGIN_H + +#include "install_market_apps_serializer.h" +#include "plugin_singleton.h" + +namespace OHOS { +namespace EDM { +class InstallMarketAppsPlugin : public PluginSingleton { +public: + void InitPlugin(std::shared_ptr> ptr) override; + ErrCode OnSetPolicy(InstallMarketAppsInfo &info); +}; +} // namespace EDM +} // namespace OHOS + +#endif // SERVICES_EDM_PLUGIN_INCLUDE_INSTALL_PLUGIN_H diff --git a/services/edm_plugin/src/install_market_apps_plugin.cpp b/services/edm_plugin/src/install_market_apps_plugin.cpp new file mode 100644 index 0000000000000000000000000000000000000000..8ed6766e2254fe5f80e1a9554515c111b886957d --- /dev/null +++ b/services/edm_plugin/src/install_market_apps_plugin.cpp @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "install_market_apps_plugin.h" +#include "install_market_apps_serializer.h" +#include "edm_ipc_interface_code.h" +#include "edm_log.h" +#include "iplugin_manager.h" + +namespace OHOS { +namespace EDM { +const bool REGISTER_RESULT = IPluginManager::GetInstance()->AddPlugin(InstallMarketAppsPlugin::GetPlugin()); + +void InstallMarketAppsPlugin::InitPlugin(std::shared_ptr> ptr) +{ + EDMLOGI("InstallMarketAppsPlugin InitPlugin..."); + ptr->InitAttribute(EdmInterfaceCode::INSTALL_MARKET_APPS, "INSTALL_MARKET_APPS", + EdmPermission::PERMISSION_ENTERPRISE_INSTALL_BUNDLE, IPlugin::PermissionType::SUPER_DEVICE_ADMIN, false); + ptr->SetSerializer(InstallMarketAppsSerializer::GetInstance()); + ptr->SetOnHandlePolicyListener(&InstallMarketAppsPlugin::OnSetPolicy, FuncOperateType::SET); +} + +ErrCode InstallMarketAppsPlugin::OnSetPolicy(InstallMarketAppsInfo &info) +{ + return EdmReturnErrCode::INTERFACE_UNSUPPORTED; +} +} // namespace EDM +} // namespace OHOS diff --git a/services/idl/IEnterpriseDeviceMgrIdl.idl b/services/idl/IEnterpriseDeviceMgrIdl.idl index 51f795be70394206d3ededb42a655fb23a552d84..76b098211d9a96b67f7768b77cde3ae630d64f39 100644 --- a/services/idl/IEnterpriseDeviceMgrIdl.idl +++ b/services/idl/IEnterpriseDeviceMgrIdl.idl @@ -41,4 +41,5 @@ interface OHOS.EDM.IEnterpriseDeviceMgrIdl { [ipccode 20] void SetDelegatedPolicies([in] String bundleName, [in] String[] policies, [in] int userId); [ipccode 21] void SetBundleInstallPolicies([in] String[] bundles, [in] int userId, [in] int policyType); [ipccode 22] void IsByodAdmin([in] ElementName admin, [out] boolean isByod); + [ipccode 23] void UnloadInstallMarketAppsPlugin(); } diff --git a/test/unittest/interface/inner_api/proxy/bundle_manager_proxy_test.cpp b/test/unittest/interface/inner_api/proxy/bundle_manager_proxy_test.cpp index db2774bc7cd84b73bd81f00dc4dfa4c29c0990e7..20ab46aa9b81d44235045097a265fbf6d41a1b75 100644 --- a/test/unittest/interface/inner_api/proxy/bundle_manager_proxy_test.cpp +++ b/test/unittest/interface/inner_api/proxy/bundle_manager_proxy_test.cpp @@ -587,6 +587,42 @@ HWTEST_F(BundleManagerProxyTest, TestGetInstallationAllowedAppDistributionTypesF ASSERT_TRUE(ret == EdmReturnErrCode::ADMIN_INACTIVE); ASSERT_TRUE(allowedAppDistributionTypes.empty()); } + +/** + * @tc.name: TestInstallMarketAppsSuc + * @tc.desc: Test install market apps func. + * @tc.type: FUNC + */ +HWTEST_F(BundleManagerProxyTest, TestInstallMarketAppsSuc, TestSize.Level1) +{ + MessageParcel data; + OHOS::AppExecFwk::ElementName admin; + admin.SetBundleName(ADMIN_PACKAGENAME); + data.WriteParcelable(&admin); + EXPECT_CALL(*object_, SendRequest(_, _, _, _)) + .Times(1) + .WillOnce(Invoke(object_.GetRefPtr(), &EnterpriseDeviceMgrStubMock::InvokeSendRequestSetPolicy)); + std::vector allowedAppDistributionTypes; + int32_t ret = bundleManagerProxy->InstallMarketApps(data, allowedAppDistributionTypes); + ASSERT_TRUE(ret == ERR_OK); +} + +/** + * @tc.name: TestInstallMarketAppsFail + * @tc.desc: Test install market apps func. + * @tc.type: FUNC + */ +HWTEST_F(BundleManagerProxyTest, TestInstallMarketAppsFail, TestSize.Level1) +{ + Utils::SetEdmServiceDisable(); + MessageParcel data; + OHOS::AppExecFwk::ElementName admin; + admin.SetBundleName(ADMIN_PACKAGENAME); + data.WriteParcelable(&admin); + std::vector allowedAppDistributionTypes; + int32_t ret = bundleManagerProxy->InstallMarketApps(data, allowedAppDistributionTypes); + ASSERT_TRUE(ret == EdmReturnErrCode::ADMIN_INACTIVE); +} } // namespace TEST } // namespace EDM } // namespace OHOS diff --git a/test/unittest/services/edm_plugin/BUILD.gn b/test/unittest/services/edm_plugin/BUILD.gn index 1f5c67346f40c0c3b2d9bac326f79335bf10d80d..7d6d1c3245d03ecb7eb06f707e202f42da957569 100644 --- a/test/unittest/services/edm_plugin/BUILD.gn +++ b/test/unittest/services/edm_plugin/BUILD.gn @@ -424,6 +424,7 @@ ohos_static_library("edm_all_plugin_static") { "../../../../services/edm_plugin/src/get_device_info_plugin.cpp", "../../../../services/edm_plugin/src/inactive_user_freeze_plugin.cpp", "../../../../services/edm_plugin/src/install_plugin.cpp", + "../../../../services/edm_plugin/src/install_market_apps_plugin.cpp", "../../../../services/edm_plugin/src/installed_bundle_info_list_plugin.cpp", "../../../../services/edm_plugin/src/kiosk_feature_plugin.cpp", "../../../../services/edm_plugin/src/managed_browser_policy_plugin.cpp",