diff --git a/bundle.json b/bundle.json index 7b11858eb1356844382cf89e8e1947bc12e6a760..f3a549eaed7c715b29d1d7edcaf6ff86efa5515b 100644 --- a/bundle.json +++ b/bundle.json @@ -82,17 +82,21 @@ "fwk_group":[ "//base/customization/enterprise_device_management/interfaces/kits/admin_manager:adminmanager", "//base/customization/enterprise_device_management/interfaces/kits/datetime_manager:datetimemanager", + "//base/customization/enterprise_device_management/interfaces/kits/device_control:devicecontrol", "//base/customization/enterprise_device_management/interfaces/kits/device_info:deviceinfo", "//base/customization/enterprise_device_management/framework/extension:enterprise_admin_extension", "//base/customization/enterprise_device_management/interfaces/kits/enterprise_admin_extension:enterpriseadminextensionability_napi", "//base/customization/enterprise_device_management/interfaces/kits/enterprise_admin_extension_context:enterpriseadminextensioncontext_napi", "//base/customization/enterprise_device_management/framework/extension:enterprise_admin_extension_module", - "//base/customization/enterprise_device_management/interfaces/inner_api:edmservice_kits" + "//base/customization/enterprise_device_management/interfaces/inner_api:edmservice_kits", + "//base/customization/enterprise_device_management/common/native:edm_commom", + "//base/customization/enterprise_device_management/interfaces/inner_api/plugin_kits:plugin_kits" ], "service_group":[ "//base/customization/enterprise_device_management/services/edm:edmservice", "//base/customization/enterprise_device_management/services/edm_plugin:datetime_manager_plugin", "//base/customization/enterprise_device_management/services/edm_plugin:device_info_plugin", + "//base/customization/enterprise_device_management/services/edm_plugin:reset_factory_plugin", "//base/customization/enterprise_device_management/sa_profile:edm_sa_profile", "//base/customization/enterprise_device_management/etc/init:edm.cfg" ] diff --git a/common/native/BUILD.gn b/common/native/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..6ce7f438e397dde9872df65553dc089d615b98cd --- /dev/null +++ b/common/native/BUILD.gn @@ -0,0 +1,55 @@ +# Copyright (c) 2023 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. + +import("//base/customization/enterprise_device_management/edm.gni") +import("//build/ohos.gni") + +config("edm_commom_all_dependent_configs") { + include_dirs = [ + "$EDM_INNERKITS_PATH/plugin_kits/include", + "$SUBSYSTEM_DIR/common/native/include", + ] +} + +ohos_shared_library("edm_commom") { + include_dirs = [ + "$SUBSYSTEM_DIR/common/native/include", + "include", + "$EDM_INNERKITS_PATH/plugin_kits/include", + "include/connection", + JSONCPP_INCLUDE_DIR, + "$SUBSYSTEM_DIR/framework/extension/include", + ] + + sources = [ + "$SUBSYSTEM_DIR/common/native/src/edm_data_ability_utils.cpp", + "$SUBSYSTEM_DIR/common/native/src/edm_permission.cpp", + "$SUBSYSTEM_DIR/common/native/src/edm_sys_manager.cpp", + ] + + configs = [ "$SUBSYSTEM_DIR/common/config:coverage_flags" ] + + all_dependent_configs = [ ":edm_commom_all_dependent_configs" ] + deps = [] + + external_deps = [ + "ability_base:zuri", + "ability_runtime:ability_manager", + "c_utils:utils", + "data_share:datashare_consumer", + "samgr:samgr_proxy", + ] + + subsystem_name = "customization" + part_name = "enterprise_device_management" +} diff --git a/services/edm/include/edm_permission.h b/common/native/include/edm_permission.h similarity index 100% rename from services/edm/include/edm_permission.h rename to common/native/include/edm_permission.h diff --git a/common/native/src/edm_data_ability_utils.cpp b/common/native/src/edm_data_ability_utils.cpp index ef22bffa33ab8dd73b63f26952737bd18983039c..0b4704af02a3b2bea7017c7476d2fd844468bcac 100644 --- a/common/native/src/edm_data_ability_utils.cpp +++ b/common/native/src/edm_data_ability_utils.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2023 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 @@ -13,7 +13,6 @@ * limitations under the License. */ -#include "abs_shared_result_set.h" #include "datashare_helper.h" #include "datashare_predicates.h" #include "edm_data_ability_utils.h" diff --git a/services/edm/src/edm_permission.cpp b/common/native/src/edm_permission.cpp similarity index 100% rename from services/edm/src/edm_permission.cpp rename to common/native/src/edm_permission.cpp diff --git a/edm.gni b/edm.gni index bd0b5b40c2e8472c6eb177fba974888011c169f6..800b681507742bbe53dc2ae1865d953308966713 100644 --- a/edm.gni +++ b/edm.gni @@ -16,3 +16,4 @@ EDM_SA_ROOT = "$SUBSYSTEM_DIR/services/edm" EDM_SRC_PATH = "$EDM_SA_ROOT/src" JSONCPP_INCLUDE_DIR = "//third_party/jsoncpp/include" EDM_INNERKITS_PATH = "${SUBSYSTEM_DIR}/interfaces/inner_api/" +UPDATER_SA_DIR = "//base/update/updater" \ No newline at end of file diff --git a/etc/init/edm.cfg b/etc/init/edm.cfg index bdd59ed6a2ea1a059b45794fc3e30d5e13e9a681..2bc8912dca193254452a47cab1d3434ae52fc806 100644 --- a/etc/init/edm.cfg +++ b/etc/init/edm.cfg @@ -15,7 +15,7 @@ "uid" : "edm", "gid" : ["edm", "shell"], "apl" : "system_core", - "permission" : ["ohos.permission.SET_TIME"], + "permission" : ["ohos.permission.SET_TIME", "ohos.permission.FACTORY_RESET"], "secon" : "u:r:edm_sa:s0" } ] diff --git a/framework/extension/BUILD.gn b/framework/extension/BUILD.gn index 2265cfd9123c4c6a0c077d80ca6910c723390bf8..958aedad27c406e93e653ae05971a7a9d4ca5de4 100644 --- a/framework/extension/BUILD.gn +++ b/framework/extension/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2022 Huawei Device Co., Ltd. +# Copyright (c) 2022-2023 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 @@ -64,10 +64,7 @@ ohos_shared_library("enterprise_admin_extension_module") { configs = [ "//base/customization/enterprise_device_management/common/config:coverage_flags" ] deps = [ ":enterprise_admin_extension" ] - external_deps = [ - "ability_runtime:abilitykit_native", - "ability_runtime:runtime", - ] + external_deps = [ "ability_runtime:abilitykit_native" ] relative_install_dir = "extensionability/" subsystem_name = "customization" diff --git a/interfaces/inner_api/BUILD.gn b/interfaces/inner_api/BUILD.gn index 00e7230719bdd76581ab860eb4fea1f8d134ae89..8da7ddc53d72810d5df1676bb631c892a472869f 100644 --- a/interfaces/inner_api/BUILD.gn +++ b/interfaces/inner_api/BUILD.gn @@ -19,6 +19,7 @@ SRC_PATH = "$EDM_INNERKITS_PATH/" config("edmservice_kits_config") { include_dirs = [ "common/include", + "device_control/include", "device_info/include", "datetime_manager/include", "$SUBSYSTEM_DIR/common/native/include", @@ -32,6 +33,7 @@ ohos_shared_library("edmservice_kits") { "$SRC_PATH/common/src/ent_info.cpp", "$SRC_PATH/common/src/enterprise_device_mgr_proxy.cpp", "$SRC_PATH/datetime_manager/src/datetime_manager_proxy.cpp", + "$SRC_PATH/device_control/src/device_control_proxy.cpp", "$SRC_PATH/device_info/src/device_info_proxy.cpp", "$SUBSYSTEM_DIR/common/native/src/edm_sys_manager.cpp", ] diff --git a/interfaces/inner_api/common/include/enterprise_device_mgr_proxy.h b/interfaces/inner_api/common/include/enterprise_device_mgr_proxy.h index f9bfe928944e870d8baa3c86a0d48cbbb10065ba..f61e7fb1e6b35790ce860e4ae97def3522bacab2 100644 --- a/interfaces/inner_api/common/include/enterprise_device_mgr_proxy.h +++ b/interfaces/inner_api/common/include/enterprise_device_mgr_proxy.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2023 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 @@ -35,7 +35,7 @@ public: ErrCode EnableAdmin(AppExecFwk::ElementName &admin, EntInfo &entInfo, AdminType type, int32_t userId); ErrCode DisableAdmin(AppExecFwk::ElementName &admin, int32_t userId); ErrCode DisableSuperAdmin(std::string bundleName); - ErrCode GetEnabledAdmin(AdminType type, std::vector &enabledAdminList); + ErrCode GetEnabledAdmin(AdminType type, std::vector &enabledAdminList); ErrCode GetEnterpriseInfo(AppExecFwk::ElementName &admin, EntInfo &entInfo); ErrCode SetEnterpriseInfo(AppExecFwk::ElementName &admin, EntInfo &entInfo); ErrCode HandleManagedEvent(const AppExecFwk::ElementName &admin, diff --git a/interfaces/inner_api/common/include/policy_info.h b/interfaces/inner_api/common/include/policy_info.h index 573c4725bb34256f125e6d37ad7e9a5fda4b3ed3..16c619c1b79ec14c433d109832be4f78c307b62b 100644 --- a/interfaces/inner_api/common/include/policy_info.h +++ b/interfaces/inner_api/common/include/policy_info.h @@ -26,6 +26,7 @@ enum { GET_DEVICE_SERIAL = 1002, GET_DISPLAY_VERSION = 1003, GET_DEVICE_NAME = 1004, + RESET_FACTORY = 1005, }; #define POLICY_CODE_TO_NAME(ENUM_CODE, POLICY_NAME) do { \ diff --git a/interfaces/inner_api/common/src/enterprise_device_mgr_proxy.cpp b/interfaces/inner_api/common/src/enterprise_device_mgr_proxy.cpp index 9b4b7ec1f736ed47ee9a4f6787c1acfb761e7a3e..6e3b63b8bab7f2e508ea02cc5e73211270caf870 100644 --- a/interfaces/inner_api/common/src/enterprise_device_mgr_proxy.cpp +++ b/interfaces/inner_api/common/src/enterprise_device_mgr_proxy.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2023 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 @@ -136,7 +136,7 @@ ErrCode EnterpriseDeviceMgrProxy::DisableSuperAdmin(std::string bundleName) return ERR_OK; } -ErrCode EnterpriseDeviceMgrProxy::GetEnabledAdmin(AdminType type, std::vector &enabledAdminList) +ErrCode EnterpriseDeviceMgrProxy::GetEnabledAdmin(AdminType type, std::vector &enabledAdminList) { EDMLOGD("EnterpriseDeviceMgrProxy::GetEnabledAdmin"); sptr remote = GetRemoteObject(); @@ -158,7 +158,7 @@ ErrCode EnterpriseDeviceMgrProxy::GetEnabledAdmin(AdminType type, std::vector GetDeviceControlProxy(); + int32_t ResetFactory(AppExecFwk::ElementName &admin); +private: + static std::shared_ptr proxy_; + static std::shared_ptr instance_; + static std::mutex mutexLock_; +}; +} // namespace EDM +} // namespace OHOS + +#endif // INTERFACES_INNER_API_DEVICE_INFO_INCLUDE_DEVICE_INFO_PROXY_H diff --git a/interfaces/inner_api/device_control/src/device_control_proxy.cpp b/interfaces/inner_api/device_control/src/device_control_proxy.cpp new file mode 100644 index 0000000000000000000000000000000000000000..5e22a31f90af45acb086bec19f1252b8336cb553 --- /dev/null +++ b/interfaces/inner_api/device_control/src/device_control_proxy.cpp @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2022 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 "device_control_proxy.h" +#include "edm_log.h" +#include "func_code.h" +#include "policy_info.h" + +namespace OHOS { +namespace EDM { +std::shared_ptr DeviceControlProxy::instance_ = nullptr; +std::mutex DeviceControlProxy::mutexLock_; +const std::u16string DESCRIPTOR = u"ohos.edm.IEnterpriseDeviceMgr"; + +DeviceControlProxy::DeviceControlProxy() {} + +DeviceControlProxy::~DeviceControlProxy() {} + +std::shared_ptr DeviceControlProxy::GetDeviceControlProxy() +{ + if (instance_ == nullptr) { + std::lock_guard lock(mutexLock_); + if (instance_ == nullptr) { + std::shared_ptr temp = std::make_shared(); + instance_ = temp; + } + } + return instance_; +} + +int32_t DeviceControlProxy::ResetFactory(AppExecFwk::ElementName &admin) +{ + EDMLOGD("DeviceInfoProxy::ResetFactory"); + auto proxy = EnterpriseDeviceMgrProxy::GetInstance(); + if (proxy == nullptr) { + EDMLOGE("can not get EnterpriseDeviceMgrProxy"); + return EdmReturnErrCode::SYSTEM_ABNORMALLY; + } + MessageParcel data; + std::uint32_t funcCode = POLICY_FUNC_CODE((std::uint32_t)FuncOperateType::SET, RESET_FACTORY); + data.WriteInterfaceToken(DESCRIPTOR); + data.WriteParcelable(&admin); + return proxy->HandleDevicePolicy(funcCode, data); +} +} // namespace EDM +} // namespace OHOS \ No newline at end of file diff --git a/interfaces/inner_api/plugin_kits/BUILD.gn b/interfaces/inner_api/plugin_kits/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..339bd05cb04d00b7caa311d86e447daa7505e41a --- /dev/null +++ b/interfaces/inner_api/plugin_kits/BUILD.gn @@ -0,0 +1,55 @@ +# Copyright (c) 2023 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. + +import("//base/customization/enterprise_device_management/edm.gni") +import("//build/ohos.gni") + +ohos_shared_library("plugin_kits") { + include_dirs = [ + "$SUBSYSTEM_DIR/interfaces/inner_api/plugin_kits/include", + "$SUBSYSTEM_DIR/interfaces/inner_api/plugin_kits/include/utils", + "$SUBSYSTEM_DIR/common/native/include", + JSONCPP_INCLUDE_DIR, + ] + + sources = [ + "$SUBSYSTEM_DIR/interfaces/inner_api/plugin_kits/src/iplugin.cpp", + "$SUBSYSTEM_DIR/interfaces/inner_api/plugin_kits/src/iplugin_manager.cpp", + "$SUBSYSTEM_DIR/interfaces/inner_api/plugin_kits/src/ipolicy_manager.cpp", + "$SUBSYSTEM_DIR/interfaces/inner_api/plugin_kits/src/utils/array_map_serializer.cpp", + "$SUBSYSTEM_DIR/interfaces/inner_api/plugin_kits/src/utils/array_string_serializer.cpp", + "$SUBSYSTEM_DIR/interfaces/inner_api/plugin_kits/src/utils/bool_serializer.cpp", + "$SUBSYSTEM_DIR/interfaces/inner_api/plugin_kits/src/utils/func_code_utils.cpp", + "$SUBSYSTEM_DIR/interfaces/inner_api/plugin_kits/src/utils/json_serializer.cpp", + "$SUBSYSTEM_DIR/interfaces/inner_api/plugin_kits/src/utils/long_serializer.cpp", + "$SUBSYSTEM_DIR/interfaces/inner_api/plugin_kits/src/utils/map_string_serializer.cpp", + "$SUBSYSTEM_DIR/interfaces/inner_api/plugin_kits/src/utils/string_serializer.cpp", + ] + + configs = [ "$SUBSYSTEM_DIR/common/config:coverage_flags" ] + + deps = [ "//third_party/jsoncpp:jsoncpp" ] + + external_deps = [ + "c_utils:utils", + "ipc:ipc_core", + ] + + if (is_standard_system) { + external_deps += [ "hiviewdfx_hilog_native:libhilog" ] + } else { + external_deps += [ "hilog:libhilog" ] + } + subsystem_name = "customization" + part_name = "enterprise_device_management" +} diff --git a/services/edm/include/iplugin.h b/interfaces/inner_api/plugin_kits/include/iplugin.h similarity index 97% rename from services/edm/include/iplugin.h rename to interfaces/inner_api/plugin_kits/include/iplugin.h index 0180dd203673b98aeecefccbd3a4ba2cb4ec41ef..91f54127b43fbdbaaf11504b5c915d68e2a32dce 100644 --- a/services/edm/include/iplugin.h +++ b/interfaces/inner_api/plugin_kits/include/iplugin.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2023 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 @@ -20,7 +20,6 @@ #include #include #include "edm_errors.h" -#include "func_code_utils.h" #include "message_parcel.h" namespace OHOS { diff --git a/interfaces/inner_api/plugin_kits/include/iplugin_manager.h b/interfaces/inner_api/plugin_kits/include/iplugin_manager.h new file mode 100644 index 0000000000000000000000000000000000000000..23092b1e57ed178b27890d847a7d3d0f201d8935 --- /dev/null +++ b/interfaces/inner_api/plugin_kits/include/iplugin_manager.h @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2023 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_INCLUDE_EDM_IPLUGIN_MANAGER_H +#define SERVICES_EDM_INCLUDE_EDM_IPLUGIN_MANAGER_H + +#include +#include +#include +#include "iplugin.h" + +namespace OHOS { +namespace EDM { +class IPluginManager { +public: + static IPluginManager* GetInstance(); + virtual bool AddPlugin(std::shared_ptr plugin) + { + return true; + } + virtual ~IPluginManager() {} + +protected: + static IPluginManager* pluginManagerInstance_; +}; +} // namespace EDM +} // namespace OHOS + +#endif // SERVICES_EDM_INCLUDE_EDM_PLUGIN_MANAGER_H diff --git a/services/edm/include/iplugin_template.h b/interfaces/inner_api/plugin_kits/include/iplugin_template.h similarity index 98% rename from services/edm/include/iplugin_template.h rename to interfaces/inner_api/plugin_kits/include/iplugin_template.h index dc86f4ec3a69a7f7828bdadc45856156c0f2e648..1cdb9b13a136da211ba2ce3f03f4d93b461c3736 100644 --- a/services/edm/include/iplugin_template.h +++ b/interfaces/inner_api/plugin_kits/include/iplugin_template.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2023 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 @@ -17,10 +17,13 @@ #define SERVICES_EDM_INCLUDE_EDM_IPLUGIN_TEMPLATE_H #include +#include +#include #include "edm_log.h" +#include "func_code_utils.h" #include "iplugin.h" +#include "ipolicy_manager.h" #include "ipolicy_serializer.h" -#include "policy_manager.h" namespace OHOS { namespace EDM { @@ -469,12 +472,12 @@ void IPluginTemplate::SetOnHandlePolicyListener(BiFunction &&listener, F }; handlePolicyFuncMap_.insert(std::make_pair(type, HandlePolicyFunc(handle, listener))); } - +using AdminValueItemsMap = std::unordered_map; template ErrCode IPluginTemplate::MergePolicyData(const std::string &adminName, std::string &policyData) { AdminValueItemsMap adminValues; - PolicyManager::GetInstance()->GetAdminByPolicyName(GetPolicyName(), adminValues); + IPolicyManager::GetInstance()->GetAdminByPolicyName(GetPolicyName(), adminValues); EDMLOGD("IPluginTemplate::MergePolicyData %{public}s value size %{public}d.", GetPolicyName().c_str(), (uint32_t)adminValues.size()); if (adminValues.empty()) { @@ -680,7 +683,7 @@ template bool IPluginTemplate::GetMergePolicyData(DT &policyData) { AdminValueItemsMap adminValues; - PolicyManager::GetInstance()->GetAdminByPolicyName(GetPolicyName(), adminValues); + IPolicyManager::GetInstance()->GetAdminByPolicyName(GetPolicyName(), adminValues); if (adminValues.empty()) { return true; } diff --git a/interfaces/inner_api/plugin_kits/include/ipolicy_manager.h b/interfaces/inner_api/plugin_kits/include/ipolicy_manager.h new file mode 100644 index 0000000000000000000000000000000000000000..615b78f1137944ed9410a53b8c62beea8eff96da --- /dev/null +++ b/interfaces/inner_api/plugin_kits/include/ipolicy_manager.h @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2023 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_INCLUDE_EDM_IPOLICY_MANAGER_H +#define SERVICES_EDM_INCLUDE_EDM_IPOLICY_MANAGER_H + +#include +#include +#include "edm_errors.h" + +namespace OHOS { +namespace EDM { +using AdminValueItemsMap = std::unordered_map; + +class IPolicyManager { +public: + static IPolicyManager *GetInstance(); + virtual ErrCode GetAdminByPolicyName(const std::string &policyName, AdminValueItemsMap &adminValueItems) + { + return ERR_OK; + } + virtual ~IPolicyManager() {} + +protected: + static IPolicyManager* policyManagerInstance_; +}; + +} // namespace EDM +} // namespace OHOS + +#endif // SERVICES_EDM_INCLUDE_EDM_IPOLICY_MANAGER_H diff --git a/services/edm/include/ipolicy_serializer.h b/interfaces/inner_api/plugin_kits/include/ipolicy_serializer.h similarity index 100% rename from services/edm/include/ipolicy_serializer.h rename to interfaces/inner_api/plugin_kits/include/ipolicy_serializer.h diff --git a/services/edm/include/utils/array_map_serializer.h b/interfaces/inner_api/plugin_kits/include/utils/array_map_serializer.h similarity index 100% rename from services/edm/include/utils/array_map_serializer.h rename to interfaces/inner_api/plugin_kits/include/utils/array_map_serializer.h diff --git a/services/edm/include/utils/array_string_serializer.h b/interfaces/inner_api/plugin_kits/include/utils/array_string_serializer.h similarity index 100% rename from services/edm/include/utils/array_string_serializer.h rename to interfaces/inner_api/plugin_kits/include/utils/array_string_serializer.h diff --git a/services/edm/include/utils/bool_serializer.h b/interfaces/inner_api/plugin_kits/include/utils/bool_serializer.h similarity index 100% rename from services/edm/include/utils/bool_serializer.h rename to interfaces/inner_api/plugin_kits/include/utils/bool_serializer.h diff --git a/services/edm/include/utils/func_code_utils.h b/interfaces/inner_api/plugin_kits/include/utils/func_code_utils.h similarity index 100% rename from services/edm/include/utils/func_code_utils.h rename to interfaces/inner_api/plugin_kits/include/utils/func_code_utils.h diff --git a/services/edm/include/utils/json_serializer.h b/interfaces/inner_api/plugin_kits/include/utils/json_serializer.h similarity index 100% rename from services/edm/include/utils/json_serializer.h rename to interfaces/inner_api/plugin_kits/include/utils/json_serializer.h diff --git a/services/edm/include/utils/long_serializer.h b/interfaces/inner_api/plugin_kits/include/utils/long_serializer.h similarity index 100% rename from services/edm/include/utils/long_serializer.h rename to interfaces/inner_api/plugin_kits/include/utils/long_serializer.h diff --git a/services/edm/include/utils/map_string_serializer.h b/interfaces/inner_api/plugin_kits/include/utils/map_string_serializer.h similarity index 100% rename from services/edm/include/utils/map_string_serializer.h rename to interfaces/inner_api/plugin_kits/include/utils/map_string_serializer.h diff --git a/services/edm/include/utils/string_serializer.h b/interfaces/inner_api/plugin_kits/include/utils/string_serializer.h similarity index 100% rename from services/edm/include/utils/string_serializer.h rename to interfaces/inner_api/plugin_kits/include/utils/string_serializer.h diff --git a/services/edm/src/iplugin.cpp b/interfaces/inner_api/plugin_kits/src/iplugin.cpp similarity index 83% rename from services/edm/src/iplugin.cpp rename to interfaces/inner_api/plugin_kits/src/iplugin.cpp index fea3c5c510e39fa9ac8ed0633fc29cf9d3d2e28b..e2f2efb4e9f35a83225ecb3a3e4192d6a8632d37 100644 --- a/services/edm/src/iplugin.cpp +++ b/interfaces/inner_api/plugin_kits/src/iplugin.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2023 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 @@ -15,7 +15,6 @@ #include "iplugin.h" #include -#include "policy_manager.h" namespace OHOS { namespace EDM { @@ -46,11 +45,6 @@ std::uint32_t IPlugin::GetCode() ErrCode IPlugin::MergePolicyData(const std::string &adminName, std::string &mergeJsonData) { - std::shared_ptr ptr = PolicyManager::GetInstance(); - AdminValueItemsMap map; - if (ptr != nullptr) { - ptr->GetAdminByPolicyName(policyName_, map); - } return ERR_OK; } diff --git a/interfaces/inner_api/plugin_kits/src/iplugin_manager.cpp b/interfaces/inner_api/plugin_kits/src/iplugin_manager.cpp new file mode 100644 index 0000000000000000000000000000000000000000..9b3412af222e0234e0f67317ca6789519950bb44 --- /dev/null +++ b/interfaces/inner_api/plugin_kits/src/iplugin_manager.cpp @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2023 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 "iplugin_manager.h" + +namespace OHOS { +namespace EDM { +IPluginManager* IPluginManager::pluginManagerInstance_ = nullptr; + +IPluginManager* IPluginManager::GetInstance() +{ + if (pluginManagerInstance_ == nullptr) { + pluginManagerInstance_ = new (std::nothrow) IPluginManager(); + } + return pluginManagerInstance_; +} +} // namespace EDM +} // namespace OHOS diff --git a/interfaces/inner_api/plugin_kits/src/ipolicy_manager.cpp b/interfaces/inner_api/plugin_kits/src/ipolicy_manager.cpp new file mode 100644 index 0000000000000000000000000000000000000000..7e1af909b78fbf06e7362f68c462d41c527e28a2 --- /dev/null +++ b/interfaces/inner_api/plugin_kits/src/ipolicy_manager.cpp @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2023 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 "ipolicy_manager.h" + +namespace OHOS { +namespace EDM { +IPolicyManager* IPolicyManager::policyManagerInstance_ = nullptr; + +IPolicyManager *IPolicyManager::GetInstance() +{ + if (policyManagerInstance_ == nullptr) { + policyManagerInstance_ = new (std::nothrow) IPolicyManager(); + } + return policyManagerInstance_; +} +} // namespace EDM +} // namespace OHOS diff --git a/services/edm/src/utils/array_map_serializer.cpp b/interfaces/inner_api/plugin_kits/src/utils/array_map_serializer.cpp similarity index 100% rename from services/edm/src/utils/array_map_serializer.cpp rename to interfaces/inner_api/plugin_kits/src/utils/array_map_serializer.cpp diff --git a/services/edm/src/utils/array_string_serializer.cpp b/interfaces/inner_api/plugin_kits/src/utils/array_string_serializer.cpp similarity index 100% rename from services/edm/src/utils/array_string_serializer.cpp rename to interfaces/inner_api/plugin_kits/src/utils/array_string_serializer.cpp diff --git a/services/edm/src/utils/bool_serializer.cpp b/interfaces/inner_api/plugin_kits/src/utils/bool_serializer.cpp similarity index 100% rename from services/edm/src/utils/bool_serializer.cpp rename to interfaces/inner_api/plugin_kits/src/utils/bool_serializer.cpp diff --git a/services/edm/src/utils/func_code_utils.cpp b/interfaces/inner_api/plugin_kits/src/utils/func_code_utils.cpp similarity index 100% rename from services/edm/src/utils/func_code_utils.cpp rename to interfaces/inner_api/plugin_kits/src/utils/func_code_utils.cpp diff --git a/services/edm/src/utils/json_serializer.cpp b/interfaces/inner_api/plugin_kits/src/utils/json_serializer.cpp similarity index 100% rename from services/edm/src/utils/json_serializer.cpp rename to interfaces/inner_api/plugin_kits/src/utils/json_serializer.cpp diff --git a/services/edm/src/utils/long_serializer.cpp b/interfaces/inner_api/plugin_kits/src/utils/long_serializer.cpp similarity index 100% rename from services/edm/src/utils/long_serializer.cpp rename to interfaces/inner_api/plugin_kits/src/utils/long_serializer.cpp diff --git a/services/edm/src/utils/map_string_serializer.cpp b/interfaces/inner_api/plugin_kits/src/utils/map_string_serializer.cpp similarity index 100% rename from services/edm/src/utils/map_string_serializer.cpp rename to interfaces/inner_api/plugin_kits/src/utils/map_string_serializer.cpp diff --git a/services/edm/src/utils/string_serializer.cpp b/interfaces/inner_api/plugin_kits/src/utils/string_serializer.cpp similarity index 100% rename from services/edm/src/utils/string_serializer.cpp rename to interfaces/inner_api/plugin_kits/src/utils/string_serializer.cpp diff --git a/interfaces/kits/admin_manager/BUILD.gn b/interfaces/kits/admin_manager/BUILD.gn index a841a0693e3076c17cfcde0316d7e59e892b833a..069d79de9c21eda8b583d9078f423f5f3ace3401 100644 --- a/interfaces/kits/admin_manager/BUILD.gn +++ b/interfaces/kits/admin_manager/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2022 Huawei Device Co., Ltd. +# Copyright (c) 2022-2023 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 @@ -38,7 +38,6 @@ ohos_shared_library("adminmanager") { "ability_base:want", "hisysevent_native:libhisysevent", "hiviewdfx_hilog_native:libhilog", - "ipc:ipc_core", "napi:ace_napi", "os_account:os_account_innerkits", ] diff --git a/interfaces/kits/datetime_manager/BUILD.gn b/interfaces/kits/datetime_manager/BUILD.gn index a4085b24a10b987e6712b6a508f65f32cb1fd017..a47419a669fbba50521844b06be941ea7325c173 100644 --- a/interfaces/kits/datetime_manager/BUILD.gn +++ b/interfaces/kits/datetime_manager/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2022 Huawei Device Co., Ltd. +# Copyright (c) 2022-2023 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 @@ -35,9 +35,7 @@ ohos_shared_library("datetimemanager") { external_deps = [ "ability_base:want", - "hisysevent_native:libhisysevent", "hiviewdfx_hilog_native:libhilog", - "ipc:ipc_core", "napi:ace_napi", ] diff --git a/interfaces/kits/device_control/BUILD.gn b/interfaces/kits/device_control/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..6d74f4782f87257d5566cc52a6ed691accb0a17c --- /dev/null +++ b/interfaces/kits/device_control/BUILD.gn @@ -0,0 +1,46 @@ +# Copyright (c) 2022 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. + +import("//base/customization/enterprise_device_management/edm.gni") +import("//build/ohos.gni") + +ohos_shared_library("devicecontrol") { + include_dirs = [ + "//third_party/node/src", + "$SUBSYSTEM_DIR/common/native/include", + "$SUBSYSTEM_DIR/interfaces/kits/device_control/include", + "$SUBSYSTEM_DIR/interfaces/kits/common/include", + "$SUBSYSTEM_DIR/interfaces/inner_api/include", + ] + + sources = [ + "$SUBSYSTEM_DIR/interfaces/kits/common/src/napi_edm_common.cpp", + "$SUBSYSTEM_DIR/interfaces/kits/common/src/napi_edm_error.cpp", + "src/device_control_addon.cpp", + ] + + configs = [ "//base/customization/enterprise_device_management/common/config:coverage_flags" ] + + deps = [ "$EDM_INNERKITS_PATH:edmservice_kits" ] + + external_deps = [ + "ability_base:want", + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_core", + "napi:ace_napi", + ] + + relative_install_dir = "module/enterprise" + subsystem_name = "customization" + part_name = "enterprise_device_management" +} diff --git a/interfaces/kits/device_control/include/device_control_addon.h b/interfaces/kits/device_control/include/device_control_addon.h new file mode 100644 index 0000000000000000000000000000000000000000..6d7babd99cb7a0c58072f9996f3f03d267019c43 --- /dev/null +++ b/interfaces/kits/device_control/include/device_control_addon.h @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2022 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_KITS_DEVICE_CONTROL_INCLUDE_DEVICE_CONTROL_ADDON_H +#define INTERFACES_KITS_DEVICE_CONTROL_INCLUDE_DEVICE_CONTROL_ADDON_H + +#include "device_control_proxy.h" +#include "enterprise_device_mgr_proxy.h" +#include "ienterprise_device_mgr.h" +#include "napi_edm_error.h" +#include "napi_edm_common.h" +#include "napi/native_common.h" +#include "napi/native_node_api.h" +#include "napi/native_api.h" +#include "want.h" + +namespace OHOS { +namespace EDM { +struct AsyncDeviceControlCallbackInfo : AsyncCallbackInfo { + OHOS::AppExecFwk::ElementName elementName; +}; + +class DeviceControlAddon { +public: + DeviceControlAddon(); + ~DeviceControlAddon() = default; + + static napi_value Init(napi_env env, napi_value exports); +private: + static napi_value ResetFactory(napi_env env, napi_callback_info info); + static void NativeResetFactory(napi_env env, void *data); + static std::shared_ptr deviceControlProxy_; +}; +} // namespace EDM +} // namespace OHOS + +#endif // INTERFACES_KITS_DATETIME_MANAGER_INCLUDE_DEVICE_INFO_ADDON_H \ No newline at end of file diff --git a/interfaces/kits/device_control/src/device_control_addon.cpp b/interfaces/kits/device_control/src/device_control_addon.cpp new file mode 100644 index 0000000000000000000000000000000000000000..81f11e170e2ae24d1c0f0b97fd12d6cc3c65e382 --- /dev/null +++ b/interfaces/kits/device_control/src/device_control_addon.cpp @@ -0,0 +1,94 @@ +/* + * Copyright (c) 2022 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 "device_control_addon.h" +#include "edm_log.h" + +using namespace OHOS::EDM; + +napi_value DeviceControlAddon::Init(napi_env env, napi_value exports) +{ + napi_property_descriptor property[] = { + DECLARE_NAPI_FUNCTION("resetFactory", ResetFactory), + }; + NAPI_CALL(env, napi_define_properties(env, exports, sizeof(property) / sizeof(property[0]), property)); + return exports; +} + +napi_value DeviceControlAddon::ResetFactory(napi_env env, napi_callback_info info) +{ + EDMLOGI("NAPI_resetFactory called"); + size_t argc = ARGS_SIZE_TWO; + napi_value argv[ARGS_SIZE_TWO] = {nullptr}; + napi_value thisArg = nullptr; + void *data = nullptr; + NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisArg, &data)); + ASSERT_AND_THROW_PARAM_ERROR(env, argc >= ARGS_SIZE_ONE, "parameter count error"); + bool matchFlag = MatchValueType(env, argv[ARR_INDEX_ZERO], napi_object); + if (argc > ARGS_SIZE_ONE) { + matchFlag = matchFlag && MatchValueType(env, argv[ARR_INDEX_ONE], napi_function); + } + ASSERT_AND_THROW_PARAM_ERROR(env, matchFlag, "parameter type error"); + auto asyncCallbackInfo = new (std::nothrow) AsyncDeviceControlCallbackInfo(); + if (asyncCallbackInfo == nullptr) { + return nullptr; + } + std::unique_ptr callbackPtr {asyncCallbackInfo}; + bool ret = ParseElementName(env, asyncCallbackInfo->elementName, argv[ARR_INDEX_ZERO]); + ASSERT_AND_THROW_PARAM_ERROR(env, ret, "element name param error"); + EDMLOGD("resetFactory: asyncCallbackInfo->elementName.bundlename %{public}s, " + "asyncCallbackInfo->abilityname:%{public}s", + asyncCallbackInfo->elementName.GetBundleName().c_str(), + asyncCallbackInfo->elementName.GetAbilityName().c_str()); + if (argc > ARGS_SIZE_ONE) { + EDMLOGD("NAPI_resetFactory argc == ARGS_SIZE_TWO"); + napi_create_reference(env, argv[ARR_INDEX_ONE], NAPI_RETURN_ONE, &asyncCallbackInfo->callback); + } + napi_value asyncWorkReturn = HandleAsyncWork(env, asyncCallbackInfo, "ResetFactory", + NativeResetFactory, NativeVoidCallbackComplete); + callbackPtr.release(); + return asyncWorkReturn; +} + +void DeviceControlAddon::NativeResetFactory(napi_env env, void *data) +{ + EDMLOGI("NAPI_NativeResetFactory called"); + if (data == nullptr) { + EDMLOGE("data is nullptr"); + return; + } + AsyncDeviceControlCallbackInfo *asyncCallbackInfo = static_cast(data); + auto deviceControlProxy_ = DeviceControlProxy::GetDeviceControlProxy(); + if (deviceControlProxy_ == nullptr) { + EDMLOGE("can not get GetDeviceControlProxy"); + return; + } + asyncCallbackInfo->ret = deviceControlProxy_->ResetFactory(asyncCallbackInfo->elementName); +} + +static napi_module g_deviceControlModule = { + .nm_version = 1, + .nm_flags = 0, + .nm_filename = nullptr, + .nm_register_func = DeviceControlAddon::Init, + .nm_modname = "enterprise.deviceControl", + .nm_priv = ((void *)0), + .reserved = { 0 }, +}; + +extern "C" __attribute__((constructor)) void DateTimeManagerRegister() +{ + napi_module_register(&g_deviceControlModule); +} \ No newline at end of file diff --git a/services/edm/BUILD.gn b/services/edm/BUILD.gn index d87085a80fe72103493158954d6bf6fe54747028..554a223fc08f5d786766ebd2c49f214595ccc6f9 100644 --- a/services/edm/BUILD.gn +++ b/services/edm/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2022 Huawei Device Co., Ltd. +# Copyright (c) 2022-2023 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 @@ -18,7 +18,8 @@ config("edm_config") { cflags = [ "-Wno-error=implicit-fallthrough" ] include_dirs = [ "include", - "include/utils", + "$EDM_INNERKITS_PATH/plugin_kits/include", + "$EDM_INNERKITS_PATH/plugin_kits/include/utils", "include/connection", JSONCPP_INCLUDE_DIR, "$SUBSYSTEM_DIR/common/native/include", @@ -35,28 +36,16 @@ ohos_shared_library("edmservice") { "$EDM_SRC_PATH/connection/enterprise_admin_proxy.cpp", "$EDM_SRC_PATH/connection/enterprise_bundle_connection.cpp", "$EDM_SRC_PATH/connection/enterprise_conn_manager.cpp", - "$EDM_SRC_PATH/edm_permission.cpp", "$EDM_SRC_PATH/enterprise_device_mgr_ability.cpp", "$EDM_SRC_PATH/enterprise_device_mgr_stub.cpp", - "$EDM_SRC_PATH/iplugin.cpp", "$EDM_SRC_PATH/permission_manager.cpp", "$EDM_SRC_PATH/plugin_manager.cpp", "$EDM_SRC_PATH/policy_manager.cpp", "$EDM_SRC_PATH/super_admin.cpp", - "$EDM_SRC_PATH/utils/array_map_serializer.cpp", - "$EDM_SRC_PATH/utils/array_string_serializer.cpp", - "$EDM_SRC_PATH/utils/bool_serializer.cpp", - "$EDM_SRC_PATH/utils/func_code_utils.cpp", - "$EDM_SRC_PATH/utils/json_serializer.cpp", - "$EDM_SRC_PATH/utils/long_serializer.cpp", - "$EDM_SRC_PATH/utils/map_string_serializer.cpp", - "$EDM_SRC_PATH/utils/string_serializer.cpp", - "$SUBSYSTEM_DIR/common/native/src/edm_data_ability_utils.cpp", - "$SUBSYSTEM_DIR/common/native/src/edm_sys_manager.cpp", ] public_configs = [ ":edm_config", - "//base/customization/enterprise_device_management/common/config:coverage_flags", + "$SUBSYSTEM_DIR/common/config:coverage_flags", ] defines = [] @@ -68,7 +57,6 @@ ohos_shared_library("edmservice") { external_deps = [ "ability_base:want", - "ability_base:zuri", "ability_runtime:ability_manager", "access_token:libaccesstoken_sdk", "access_token:libtokenid_sdk", @@ -76,7 +64,6 @@ ohos_shared_library("edmservice") { "bundle_framework:appexecfwk_core", "c_utils:utils", "common_event_service:cesfwk_innerkits", - "data_share:datashare_consumer", "ipc:ipc_core", "os_account:os_account_innerkits", "safwk:system_ability_fwk", @@ -91,6 +78,8 @@ ohos_shared_library("edmservice") { deps = [ "$EDM_INNERKITS_PATH:edmservice_kits", + "$EDM_INNERKITS_PATH/plugin_kits:plugin_kits", + "$SUBSYSTEM_DIR/common/native:edm_commom", "//third_party/jsoncpp:jsoncpp", ] diff --git a/services/edm/include/enterprise_device_mgr_stub.h b/services/edm/include/enterprise_device_mgr_stub.h index 69d594c29ef194b4e40063044017e13b1489ed05..0f5675b82d840a730643879a8b8e3a64efd3fd7d 100644 --- a/services/edm/include/enterprise_device_mgr_stub.h +++ b/services/edm/include/enterprise_device_mgr_stub.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2023 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 @@ -16,8 +16,8 @@ #ifndef SERVICES_EDM_INCLUDE_EDM_ENTERPRISE_DEVICE_MGR_STUB_ABILITY_H #define SERVICES_EDM_INCLUDE_EDM_ENTERPRISE_DEVICE_MGR_STUB_ABILITY_H #include -#include "func_code_utils.h" #include "edm_log.h" +#include "func_code.h" #include "ienterprise_device_mgr.h" #include "iremote_stub.h" diff --git a/services/edm/include/permission_manager.h b/services/edm/include/permission_manager.h index 28869a25a34da4f1087ca9d5b332a89ba87a257c..0f4427f14fc547cfb0033e7e7dc6b5bd2d78b3e6 100644 --- a/services/edm/include/permission_manager.h +++ b/services/edm/include/permission_manager.h @@ -35,7 +35,8 @@ static const AdminPermission ADMIN_PERMISSIONS[] = { { "ohos.permission.EDM_TEST_PERMISSION", AdminType::NORMAL }, { "ohos.permission.EDM_TEST_ENT_PERMISSION", AdminType::ENT }, { "ohos.permission.ENTERPRISE_SET_DATETIME", AdminType::ENT }, - { "ohos.permission.ENTERPRISE_GET_DEVICE_INFO", AdminType::ENT } + { "ohos.permission.ENTERPRISE_GET_DEVICE_INFO", AdminType::ENT }, + { "ohos.permission.ENTERPRISE_RESET_DEVICE", AdminType::ENT }, }; class PermissionManager : public DelayedSingleton { diff --git a/services/edm/include/plugin_manager.h b/services/edm/include/plugin_manager.h index 6e0098bc482b0fd9441d667c5f2d754e059c4135..53d09d8c103073356b570d5f50a02078ac27bd51 100644 --- a/services/edm/include/plugin_manager.h +++ b/services/edm/include/plugin_manager.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2023 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 @@ -19,10 +19,11 @@ #include #include #include "iplugin.h" +#include "iplugin_manager.h" namespace OHOS { namespace EDM { -class PluginManager : public std::enable_shared_from_this { +class PluginManager : public std::enable_shared_from_this, IPluginManager { public: static std::shared_ptr GetInstance(); std::shared_ptr GetPluginByFuncCode(std::uint32_t funcCode); diff --git a/services/edm/include/policy_manager.h b/services/edm/include/policy_manager.h index c44f5275e9e3c35539c7ae4cf44d6e552c2a51a6..9d7aa32e68b7f339f85a341018495040c86bdc5d 100644 --- a/services/edm/include/policy_manager.h +++ b/services/edm/include/policy_manager.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2023 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 @@ -22,6 +22,7 @@ #include #include "edm_errors.h" #include "json/json.h" +#include "ipolicy_manager.h" namespace OHOS { namespace EDM { @@ -33,7 +34,7 @@ using AdminValueItemsMap = std::unordered_map; /* Admi * provide the Get and Set api to operate on json file, the read and write json * file depend on jsoncpp library */ -class PolicyManager : public std::enable_shared_from_this { +class PolicyManager : public std::enable_shared_from_this, IPolicyManager { public: /* * The static function used to get singleton instance of PolicyManager. diff --git a/services/edm/src/enterprise_device_mgr_ability.cpp b/services/edm/src/enterprise_device_mgr_ability.cpp index 997dce2601563696c9a061c326f6ce6a91bc71d7..635a1611fb762877320334a79f0c0f5e34a59843 100644 --- a/services/edm/src/enterprise_device_mgr_ability.cpp +++ b/services/edm/src/enterprise_device_mgr_ability.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2023 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 @@ -34,7 +34,6 @@ #include "enterprise_conn_manager.h" #include "matching_skills.h" #include "os_account_manager.h" -#include "plugin_manager.h" namespace OHOS { namespace EDM { diff --git a/services/edm/src/enterprise_device_mgr_stub.cpp b/services/edm/src/enterprise_device_mgr_stub.cpp index 19596328104aae5dd77f4ec05838bbe1e1cb87b0..4e8ae0fbfedf53d344092777d1df4701bbfabc8f 100644 --- a/services/edm/src/enterprise_device_mgr_stub.cpp +++ b/services/edm/src/enterprise_device_mgr_stub.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2023 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 @@ -180,9 +180,7 @@ ErrCode EnterpriseDeviceMgrStub::GetEnabledAdminInner(MessageParcel &data, Messa return res; } reply.WriteInt32(ERR_OK); - std::vector writeArray; - ArrayPolicyUtils::StringToU16String(enabledAdminList, writeArray); - reply.WriteString16Vector(writeArray); + reply.WriteStringVector(enabledAdminList); return ERR_OK; } diff --git a/services/edm/src/plugin_manager.cpp b/services/edm/src/plugin_manager.cpp index 27c72916a3fe971daa5312a6e088d1833be80376..b6b3c0b24bd1ca9de3f6cb35b0569bf14e044829 100644 --- a/services/edm/src/plugin_manager.cpp +++ b/services/edm/src/plugin_manager.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2023 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 @@ -23,6 +23,7 @@ #include #include #include "edm_log.h" +#include "func_code_utils.h" #include "permission_manager.h" namespace OHOS { @@ -57,6 +58,8 @@ std::shared_ptr PluginManager::GetInstance() instance_.reset(new (std::nothrow) PluginManager()); } } + + IPluginManager::pluginManagerInstance_ = instance_.get(); return instance_; } diff --git a/services/edm/src/policy_manager.cpp b/services/edm/src/policy_manager.cpp index d215cd5e24299a1c500ccc05e6b5160a90713f88..b412821d3aee1edb162b41b1051b27d39cf9add8 100644 --- a/services/edm/src/policy_manager.cpp +++ b/services/edm/src/policy_manager.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2023 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 @@ -570,6 +570,8 @@ std::shared_ptr PolicyManager::GetInstance() instance_.reset(new (std::nothrow) PolicyManager()); } } + + IPolicyManager::policyManagerInstance_ = instance_.get(); return instance_; } } // namespace EDM diff --git a/services/edm_plugin/BUILD.gn b/services/edm_plugin/BUILD.gn index 984507268232f83f3276af0d873d8c60a367cf66..9b1178b57fd0ea6afa335d2a1c4238e7fcaecaa4 100644 --- a/services/edm_plugin/BUILD.gn +++ b/services/edm_plugin/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2022 Huawei Device Co., Ltd. +# Copyright (c) 2022-2023 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 @@ -23,11 +23,13 @@ edm_plugin_shared_library("datetime_manager_plugin") { configs = [ "//base/customization/enterprise_device_management/common/config:coverage_flags" ] - include_dirs = [ "//third_party/node/src" ] + include_dirs = [ + "//third_party/node/src", + "$SUBSYSTEM_DIR/common/native/include", + ] external_deps = [ "ability_runtime:wantagent_innerkits", "c_utils:utils", - "ipc:ipc_core", "time_service:time_client", ] } @@ -41,10 +43,25 @@ edm_plugin_shared_library("device_info_plugin") { configs = [ "//base/customization/enterprise_device_management/common/config:coverage_flags" ] - include_dirs = [ "//base/startup/init/interfaces/innerkits/syspara" ] + include_dirs = [ "$SUBSYSTEM_DIR/common/native/include" ] + deps = [ "$SUBSYSTEM_DIR/common/native:edm_commom" ] external_deps = [ "c_utils:utils", "init:libbegetutil", ] } + +edm_plugin_shared_library("reset_factory_plugin") { + sources = [ "$PLUGIN_SRC_PATH/reset_factory_plugin.cpp" ] + + configs = [ "//base/customization/enterprise_device_management/common/config:coverage_flags" ] + + include_dirs = [ "$SUBSYSTEM_DIR/common/native/include" ] + + external_deps = [ + "c_utils:utils", + "ipc:ipc_core", + "samgr:samgr_proxy", + ] +} \ No newline at end of file diff --git a/services/edm_plugin/include/get_device_name_plugin.h b/services/edm_plugin/include/get_device_name_plugin.h index 4f760a204adb2591da78cdab58f75e900fb1e5ca..e2a7d0de63869cacc57942d2543b820d895c5322 100644 --- a/services/edm_plugin/include/get_device_name_plugin.h +++ b/services/edm_plugin/include/get_device_name_plugin.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2023 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 @@ -18,6 +18,7 @@ #include "iplugin_template.h" #include "string_serializer.h" +#include "iplugin_manager.h" namespace OHOS { namespace EDM { diff --git a/services/edm_plugin/include/get_device_serial_plugin.h b/services/edm_plugin/include/get_device_serial_plugin.h index 38d6447faaa60bb514e25738a44c3b3cd7353464..cf55207198618d3e1a1a5532310db5434f04e29d 100644 --- a/services/edm_plugin/include/get_device_serial_plugin.h +++ b/services/edm_plugin/include/get_device_serial_plugin.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2023 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 @@ -18,6 +18,7 @@ #include "string_serializer.h" #include "iplugin_template.h" +#include "iplugin_manager.h" namespace OHOS { namespace EDM { diff --git a/services/edm_plugin/include/get_display_version_plugin.h b/services/edm_plugin/include/get_display_version_plugin.h index 860b7e6b47238c01d928f1874d0b7441be53bd29..b51b5d474d76b002b0f6ef0475f4934ff9337263 100644 --- a/services/edm_plugin/include/get_display_version_plugin.h +++ b/services/edm_plugin/include/get_display_version_plugin.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2023 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 @@ -18,6 +18,7 @@ #include "iplugin_template.h" #include "string_serializer.h" +#include "iplugin_manager.h" namespace OHOS { namespace EDM { diff --git a/services/edm_plugin/include/reset_factory_plugin.h b/services/edm_plugin/include/reset_factory_plugin.h new file mode 100644 index 0000000000000000000000000000000000000000..df5b0434f4385ca62b5c4c8b2326136adde88b50 --- /dev/null +++ b/services/edm_plugin/include/reset_factory_plugin.h @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2022 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_RESET_FACTORY_PLUGIN_H +#define SERVICES_EDM_PLUGIN_INCLUDE_RESET_FACTORY_PLUGIN_H + +#include "iplugin_template.h" +#include "iplugin_manager.h" +#include "string_serializer.h" +#include "system_ability_load_callback_stub.h" + +namespace OHOS { +namespace EDM { +enum class LoadUpdaterSaStatus +{ + WAIT_RESULT = 0, + SUCCESS, + FAIL, +}; +class ResetFactoryPlugin : public PluginSingleton, + public SystemAbilityLoadCallbackStub { +public: + void InitPlugin(std::shared_ptr> ptr) override; + void OnLoadSystemAbilitySuccess(int32_t systemAbilityId, const sptr &remoteObject) override; + void OnLoadSystemAbilityFail(int32_t systemAbilityId) override; + ErrCode OnSetPolicy(); + bool TryLoadUpdaterSa(); +private: + void InitStatus(); + void WaitUpdaterSaInit(); + bool CheckUpdaterSaLoaded(); + bool LoadUpdaterSa(); + + LoadUpdaterSaStatus loadUpdaterSaStatus_ = LoadUpdaterSaStatus::WAIT_RESULT; +}; +} // namespace EDM +} // namespace OHOS + +#endif // SERVICES_EDM_PLUGIN_INCLUDE_RESET_FACTORY_PLUGIN_H \ No newline at end of file diff --git a/services/edm_plugin/include/set_datetime_plugin.h b/services/edm_plugin/include/set_datetime_plugin.h index 75d9fa564532760178e18ec897c329d555549787..9928204ff891b31616939e17d7840366a6261376 100644 --- a/services/edm_plugin/include/set_datetime_plugin.h +++ b/services/edm_plugin/include/set_datetime_plugin.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2023 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 @@ -18,6 +18,7 @@ #include "long_serializer.h" #include "iplugin_template.h" +#include "iplugin_manager.h" namespace OHOS { namespace EDM { diff --git a/services/edm_plugin/plugin.gni b/services/edm_plugin/plugin.gni index 6eed010ef70ce1c0b2fddc6ee342559d6aac1314..d61d79c0b34f8129c09d0206aca818b25c252a89 100644 --- a/services/edm_plugin/plugin.gni +++ b/services/edm_plugin/plugin.gni @@ -1,4 +1,4 @@ -# Copyright (c) 2022 Huawei Device Co., Ltd. +# Copyright (c) 2022-2023 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 @@ -18,9 +18,9 @@ template("edm_plugin_shared_library") { forward_variables_from(invoker, "*") include_dirs += [ - "//base/customization/enterprise_device_management/services/edm/include", "//base/customization/enterprise_device_management/interfaces/inner_api/common/include", - "//base/customization/enterprise_device_management/services/edm/include/utils", + "//base/customization/enterprise_device_management/interfaces/inner_api/plugin_kits/include", + "//base/customization/enterprise_device_management/interfaces/inner_api/plugin_kits/include/utils", "//base/customization/enterprise_device_management/services/edm_plugin/include", "//third_party/jsoncpp/include", ] @@ -35,7 +35,8 @@ template("edm_plugin_shared_library") { if (!defined(deps)) { deps = [] } - deps += [ "//base/customization/enterprise_device_management/services/edm:edmservice" ] + + deps += [ "//base/customization/enterprise_device_management/interfaces/inner_api/plugin_kits:plugin_kits" ] if (defined(invoker.deps)) { deps += invoker.deps diff --git a/services/edm_plugin/src/get_device_name_plugin.cpp b/services/edm_plugin/src/get_device_name_plugin.cpp index 61043a8c7c503f7178b3577a074fcb99cfc477a0..c0cdf3a00bc741079d0cf1055c62770cdd0393a8 100644 --- a/services/edm_plugin/src/get_device_name_plugin.cpp +++ b/services/edm_plugin/src/get_device_name_plugin.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2023 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 @@ -16,7 +16,6 @@ #include "edm_data_ability_utils.h" #include "get_device_name_plugin.h" #include "parameter.h" -#include "plugin_manager.h" #include "policy_info.h" #include "string_serializer.h" @@ -26,7 +25,7 @@ const std::string SETTINGS_DATA_BASE_URI = "datashare:///com.ohos.settingsdata/entry/settingsdata/SETTINGSDATA?Proxy=true"; const std::string PREDICATES_STRING = "settings.general.device_name"; -const bool REGISTER_RESULT = PluginManager::GetInstance()->AddPlugin(GetDeviceNamePlugin::GetPlugin()); +const bool REGISTER_RESULT = IPluginManager::GetInstance()->AddPlugin(GetDeviceNamePlugin::GetPlugin()); void GetDeviceNamePlugin::InitPlugin(std::shared_ptr> ptr) { diff --git a/services/edm_plugin/src/get_device_serial_plugin.cpp b/services/edm_plugin/src/get_device_serial_plugin.cpp index 4160122acbfe6db0373bcb6a8a1007e57e579852..a8b55e14383de72dbf7278b6953f5edb8ecefa2e 100644 --- a/services/edm_plugin/src/get_device_serial_plugin.cpp +++ b/services/edm_plugin/src/get_device_serial_plugin.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2023 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 @@ -15,13 +15,12 @@ #include "get_device_serial_plugin.h" #include "string_serializer.h" -#include "plugin_manager.h" -#include "policy_info.h" #include "parameter.h" +#include "policy_info.h" namespace OHOS { namespace EDM { -const bool REGISTER_RESULT = PluginManager::GetInstance()->AddPlugin(GetDeviceSerialPlugin::GetPlugin()); +const bool REGISTER_RESULT = IPluginManager::GetInstance()->AddPlugin(GetDeviceSerialPlugin::GetPlugin()); void GetDeviceSerialPlugin::InitPlugin(std::shared_ptr> ptr) { diff --git a/services/edm_plugin/src/get_display_version_plugin.cpp b/services/edm_plugin/src/get_display_version_plugin.cpp index 106f417da3955d0e2c9546b6bd1f5fcab1de891a..7df469b6b816862b1326a83c257b16f37e5f1873 100644 --- a/services/edm_plugin/src/get_display_version_plugin.cpp +++ b/services/edm_plugin/src/get_display_version_plugin.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2023 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 @@ -15,13 +15,12 @@ #include "get_display_version_plugin.h" #include "parameter.h" -#include "plugin_manager.h" #include "policy_info.h" #include "string_serializer.h" namespace OHOS { namespace EDM { -const bool REGISTER_RESULT = PluginManager::GetInstance()->AddPlugin(GetDisplayVersionPlugin::GetPlugin()); +const bool REGISTER_RESULT = IPluginManager::GetInstance()->AddPlugin(GetDisplayVersionPlugin::GetPlugin()); void GetDisplayVersionPlugin::InitPlugin(std::shared_ptr> ptr) { diff --git a/services/edm_plugin/src/reset_factory_plugin.cpp b/services/edm_plugin/src/reset_factory_plugin.cpp new file mode 100644 index 0000000000000000000000000000000000000000..1b5a148846b47f6dcf474370a98aa2b9c9d59890 --- /dev/null +++ b/services/edm_plugin/src/reset_factory_plugin.cpp @@ -0,0 +1,151 @@ +/* + * Copyright (c) 2022 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 "reset_factory_plugin.h" +#include +#include +#include +#include "iremote_broker.h" +#include "iremote_object.h" +#include "iremote_proxy.h" +#include "iremote_stub.h" +#include "iservice_registry.h" +#include "policy_info.h" +#include "string_serializer.h" + +namespace OHOS { +namespace EDM { +static constexpr int64_t UPDATER_SA_INIT_TIME = 1000 * 1000; +static constexpr int64_t SLEEP_TIME = 500 * 1000; +static constexpr int32_t RETRY_TIMES = 10; +static constexpr int32_t RESET_FACTORY_CODE = 18; + +const bool REGISTER_RESULT = IPluginManager::GetInstance()->AddPlugin(ResetFactoryPlugin::GetPlugin()); + +void ResetFactoryPlugin::InitPlugin(std::shared_ptr> ptr) +{ + EDMLOGD("ResetFactoryPlugin InitPlugin..."); + std::string policyName; + POLICY_CODE_TO_NAME(RESET_FACTORY, policyName); + ptr->InitAttribute(RESET_FACTORY, policyName, "ohos.permission.ENTERPRISE_RESET_DEVICE", false); + ptr->SetSerializer(StringSerializer::GetInstance()); + ptr->SetOnHandlePolicyListener(&ResetFactoryPlugin::OnSetPolicy, FuncOperateType::SET); +} + +ErrCode ResetFactoryPlugin::OnSetPolicy() +{ + EDMLOGD("ResetFactoryPlugin OnSetPolicy"); + auto samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + auto remoteObject = samgr->GetSystemAbility(UPDATE_DISTRIBUTED_SERVICE_ID); + if (remoteObject == nullptr) { + if (TryLoadUpdaterSa()) { + EDMLOGE("TryLoadUpdaterSa failed"); + return EdmReturnErrCode::SYSTEM_ABNORMALLY; + } + remoteObject = samgr->GetSystemAbility(UPDATE_DISTRIBUTED_SERVICE_ID); + if (remoteObject == nullptr) { + EDMLOGE("remoteObject == nullptr after load update sa"); + return EdmReturnErrCode::SYSTEM_ABNORMALLY; + } + } + MessageParcel parcel; + parcel.WriteInterfaceToken(u"OHOS.Updater.IUpdateService"); + MessageParcel reply; + MessageOption option; + int32_t ret = ERR_OK; + ret = remoteObject->SendRequest(RESET_FACTORY_CODE, parcel, reply, option); + if (FAILED(ret)) { + EDMLOGE("ResetFactoryPlugin:OnSetPolicy send request fail. %{public}d", ret); + return EdmReturnErrCode::SYSTEM_ABNORMALLY; + } + return ERR_OK; +} + +void ResetFactoryPlugin::InitStatus() +{ + if (loadUpdaterSaStatus_ != LoadUpdaterSaStatus::WAIT_RESULT) { + loadUpdaterSaStatus_ = LoadUpdaterSaStatus::WAIT_RESULT; + } +} + +bool ResetFactoryPlugin::TryLoadUpdaterSa() +{ + InitStatus(); + return LoadUpdaterSa(); +} + +void ResetFactoryPlugin::OnLoadSystemAbilitySuccess(int32_t systemAbilityId, const sptr& remoteObject) +{ + EDMLOGI("OnLoadSystemAbilitySuccess systemAbilityId: %{public}d, IRemoteObject result: %{public}s", + systemAbilityId, (remoteObject != nullptr) ? "succeed" : "failed"); + loadUpdaterSaStatus_ = (remoteObject != nullptr) ? LoadUpdaterSaStatus::SUCCESS : LoadUpdaterSaStatus::FAIL; +} + +void ResetFactoryPlugin::OnLoadSystemAbilityFail(int32_t systemAbilityId) +{ + EDMLOGE("OnLoadSystemAbilityFail systemAbilityId: %{public}d", systemAbilityId); + loadUpdaterSaStatus_ = LoadUpdaterSaStatus::FAIL; +} + +bool ResetFactoryPlugin::CheckUpdaterSaLoaded() +{ + int32_t retry = RETRY_TIMES; + EDMLOGI("Waiting for CheckUpdaterSaLoaded"); + while (retry--) + { + usleep(SLEEP_TIME); + LoadUpdaterSaStatus loadUpdaterSaStatus = loadUpdaterSaStatus_; + if (loadUpdaterSaStatus != LoadUpdaterSaStatus::WAIT_RESULT) + { + bool isUpdaterSaLoaded = loadUpdaterSaStatus == LoadUpdaterSaStatus::SUCCESS; + EDMLOGI("found OnLoad result: %{public}s", isUpdaterSaLoaded ? "succeed" : "failed"); + return isUpdaterSaLoaded; + } + } + EDMLOGE("CheckUpdaterSaLoaded didn't get OnLoad result"); + return false; +} + +void ResetFactoryPlugin::WaitUpdaterSaInit() +{ + usleep(UPDATER_SA_INIT_TIME); +} + +bool ResetFactoryPlugin::LoadUpdaterSa() +{ + auto samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + if (samgr == nullptr) + { + EDMLOGE("GetSystemAbilityManager samgr object null!"); + return false; + } + int32_t result = samgr->LoadSystemAbility(UPDATE_DISTRIBUTED_SERVICE_ID, this); + if (result != ERR_OK) + { + EDMLOGE("systemAbilityId: %{public}d, load failed, result code: %{public}d", UPDATE_DISTRIBUTED_SERVICE_ID, + result); + return false; + } + if (!CheckUpdaterSaLoaded()) + { + EDMLOGE("systemAbilityId: %{public}d, CheckUpdaterSaLoaded failed", UPDATE_DISTRIBUTED_SERVICE_ID); + return false; + } + WaitUpdaterSaInit(); + EDMLOGI("systemAbilityId: %{public}d, load succeed", UPDATE_DISTRIBUTED_SERVICE_ID); + return true; +} +} // namespace EDM +} // namespace OHOS diff --git a/services/edm_plugin/src/set_datetime_plugin.cpp b/services/edm_plugin/src/set_datetime_plugin.cpp index 2c68b853abb0d15abaa4c9641bd440dc515f93b9..aba80d2d2e15b09e0bfef8d866b2f19a539a5be7 100644 --- a/services/edm_plugin/src/set_datetime_plugin.cpp +++ b/services/edm_plugin/src/set_datetime_plugin.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2023 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 @@ -15,13 +15,12 @@ #include "set_datetime_plugin.h" #include "long_serializer.h" -#include "plugin_manager.h" #include "policy_info.h" #include "time_service_client.h" namespace OHOS { namespace EDM { -const bool REGISTER_RESULT = PluginManager::GetInstance()->AddPlugin(SetDateTimePlugin::GetPlugin()); +const bool REGISTER_RESULT = IPluginManager::GetInstance()->AddPlugin(SetDateTimePlugin::GetPlugin()); void SetDateTimePlugin::InitPlugin(std::shared_ptr> ptr) { diff --git a/test/unittest/BUILD.gn b/test/unittest/BUILD.gn index c742eb307925b5e99155c5ffd86c9daf263d443e..8e2d2f67655eb31065ea7f40a2e608859bd550ba 100644 --- a/test/unittest/BUILD.gn +++ b/test/unittest/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2022 Huawei Device Co., Ltd. +# Copyright (c) 2022-2023 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 @@ -35,6 +35,8 @@ ohos_unittest("EdmServicesUnitTest") { "$SUBSYSTEM_DIR/interfaces/inner_api/include", "$SUBSYSTEM_DIR/common/native/include", "$SUBSYSTEM_DIR/services/edm_plugin/include", + "$SUBSYSTEM_DIR/interfaces/inner_api/plugin_kits/include", + "$SUBSYSTEM_DIR/interfaces/inner_api/plugin_kits/include/utils", ] sources = [ @@ -67,6 +69,8 @@ ohos_unittest("EdmServicesUnitTest") { deps = [ "$EDM_INNERKITS_PATH:edmservice_kits", "$EDM_SA_ROOT:edmservice", + "$SUBSYSTEM_DIR/common/native:edm_commom", + "$SUBSYSTEM_DIR/interfaces/inner_api/plugin_kits:plugin_kits", "//third_party/googletest:gmock_main", "//third_party/googletest:gtest_main", "//third_party/jsoncpp:jsoncpp", @@ -104,6 +108,7 @@ group("unittest") { deps += [ # deps file ":EdmServicesUnitTest", + "device_control_proxy:unittest", "device_info_proxy:unittest", "edm_plugin:unittest", "enterprise_device_mgr_ability:unittest", diff --git a/test/unittest/device_control_proxy/BUILD.gn b/test/unittest/device_control_proxy/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..b27e88efe8035530d86e8a10fc8471f6ad4c9e7a --- /dev/null +++ b/test/unittest/device_control_proxy/BUILD.gn @@ -0,0 +1,72 @@ +# Copyright (c) 2022 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. + +import("//base/customization/enterprise_device_management/edm.gni") +import("//build/test.gni") + +module_output_path = "enterprise_device_management/services" + +config("module_private_config") { + visibility = [ ":*" ] +} + +ohos_unittest("EdmDeviceControlProxyUnitTest") { + module_out_path = module_output_path + + include_dirs = [ + "$EDM_SA_ROOT/include", + "$SUBSYSTEM_DIR/test/unittest/include", + "$SUBSYSTEM_DIR/interfaces/inner_api/include", + ] + + sources = [ + "./device_control_proxy_test.cpp", + ] + + configs = [ "//base/customization/enterprise_device_management/common/config:coverage_flags" ] + + deps = [ + "$EDM_INNERKITS_PATH:edmservice_kits", + "$EDM_SA_ROOT:edmservice", + ] + + external_deps = [ + "ability_base:want", + "ability_runtime:ability_manager", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", + "c_utils:utils", + "common_event_service:cesfwk_innerkits", + "ipc:ipc_core", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + ] + + if (is_standard_system) { + external_deps += [ "hiviewdfx_hilog_native:libhilog" ] + } else { + external_deps += [ "hilog:libhilog" ] + } + + subsystem_name = "customization" + part_name = "enterprise_device_management" +} + +group("unittest") { + testonly = true + + deps = [ + # deps file + ":EdmDeviceControlProxyUnitTest", + ] +} diff --git a/test/unittest/device_control_proxy/device_control_proxy_test.cpp b/test/unittest/device_control_proxy/device_control_proxy_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..0f1ff4b5c7414a1ea8cb8a20b5c9bb0149cf27d4 --- /dev/null +++ b/test/unittest/device_control_proxy/device_control_proxy_test.cpp @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2022 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 +#include +#include +#include + +#include "device_control_proxy.h" +#include "policy_info.h" + +using namespace testing::ext; +using namespace testing; + +namespace OHOS { +namespace EDM { +namespace TEST { +const std::string ADMIN_PACKAGENAME = "com.edm.test.demo"; +class DeviceControlProxyTest : public testing::Test { +protected: + void SetUp() override; + + void TearDown() override; + + std::shared_ptr deviceControlProxy = nullptr; +}; + +void DeviceControlProxyTest::SetUp() +{ + deviceControlProxy = DeviceControlProxy::GetDeviceControlProxy(); +} + +void DeviceControlProxyTest::TearDown() +{ + deviceControlProxy.reset(); +} + +/** + * @tc.name: TestResetFactoryFail + * @tc.desc: Test ResetFactory func. + * @tc.type: FUNC + */ +HWTEST_F(DeviceControlProxyTest, TestGetDeviceInfoFail, TestSize.Level1) +{ + OHOS::AppExecFwk::ElementName admin; + admin.SetBundleName(ADMIN_PACKAGENAME); + int32_t ret = deviceControlProxy->ResetFactory(admin); + ASSERT_TRUE(ret != ERR_OK); +} +} // namespace TEST +} // namespace EDM +} // namespace OHOS diff --git a/test/unittest/edm_plugin/BUILD.gn b/test/unittest/edm_plugin/BUILD.gn index b5ab218a0c05c5a49160dba970cade917d3f8585..e20cf39df3536a3be364151c39c9dd0f9c638ae8 100644 --- a/test/unittest/edm_plugin/BUILD.gn +++ b/test/unittest/edm_plugin/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2022 Huawei Device Co., Ltd. +# Copyright (c) 2022-2023 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 @@ -28,6 +28,8 @@ ohos_unittest("EdmGetDeviceNamePluginTest") { "$SUBSYSTEM_DIR/services/edm_plugin/include", "$EDM_INNERKITS_PATH/", "$SUBSYSTEM_DIR/common/native/include", + "$SUBSYSTEM_DIR/interfaces/inner_api/plugin_kits/include", + "$SUBSYSTEM_DIR/interfaces/inner_api/plugin_kits/include/utils", "./get_device_name_plugin_test.h", ] @@ -35,6 +37,7 @@ ohos_unittest("EdmGetDeviceNamePluginTest") { "./device_info_plugin_test.cpp", "./edm_data_ability_utils_mock.cpp", "./get_device_name_plugin_test.cpp", + "./reset_factory_plugin_test.cpp", ] configs = [ @@ -46,6 +49,8 @@ ohos_unittest("EdmGetDeviceNamePluginTest") { ":edm_all_plugin_static", "$EDM_INNERKITS_PATH:edmservice_kits", "$EDM_SA_ROOT:edmservice", + "$SUBSYSTEM_DIR/common/native:edm_commom", + "$SUBSYSTEM_DIR/interfaces/inner_api/plugin_kits:plugin_kits", "//third_party/googletest:gmock_main", "//third_party/googletest:gtest_main", ] @@ -72,23 +77,34 @@ ohos_static_library("edm_all_plugin_static") { "$SUBSYSTEM_DIR/services/edm_plugin/src/get_device_name_plugin.cpp", "$SUBSYSTEM_DIR/services/edm_plugin/src/get_device_serial_plugin.cpp", "$SUBSYSTEM_DIR/services/edm_plugin/src/get_display_version_plugin.cpp", + "$SUBSYSTEM_DIR/services/edm_plugin/src/reset_factory_plugin.cpp", ] configs = [ "//base/customization/enterprise_device_management/common/config:coverage_flags" ] include_dirs = [ - "//base/startup/init/interfaces/innerkits/syspara", "$EDM_SA_ROOT/include", "$EDM_SA_ROOT/include/utils", JSONCPP_INCLUDE_DIR, + "$SUBSYSTEM_DIR/common/native/include", "$SUBSYSTEM_DIR/interfaces/inner_api/common/include", + "$SUBSYSTEM_DIR/interfaces/inner_api/plugin_kits/include", + "$SUBSYSTEM_DIR/interfaces/inner_api/plugin_kits/include/utils", "$SUBSYSTEM_DIR/services/edm_plugin/include", + "$UPDATER_SA_DIR/interfaces/kits/include", + "$UPDATER_SA_DIR/services/package/pkg_manager", + "$UPDATER_SA_DIR/services/include", ] - deps = [ "$EDM_SA_ROOT:edmservice" ] + deps = [ + "$SUBSYSTEM_DIR/common/native:edm_commom", + "$SUBSYSTEM_DIR/interfaces/inner_api/plugin_kits:plugin_kits", + ] external_deps = [ "c_utils:utils", "init:libbegetutil", + "updater:libpackageExt", + "updater:libupdaterkits", ] if (is_standard_system) { diff --git a/test/unittest/edm_plugin/reset_factory_plugin_test.cpp b/test/unittest/edm_plugin/reset_factory_plugin_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..569763258963590934390870b5eae3a3b6f2b73e --- /dev/null +++ b/test/unittest/edm_plugin/reset_factory_plugin_test.cpp @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2022 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 "iplugin_template.h" +#include "policy_info.h" +#include "reset_factory_plugin_test.h" + +using namespace testing::ext; + +namespace OHOS { +namespace EDM { +namespace TEST { +void DeviceControlPluginTest::SetUp() {} + +void DeviceControlPluginTest::TearDown() +{ + plugin_.reset(); +} + +/** + * @tc.name: TestRestFactory + * @tc.desc: Test RestFactoryPlugin::OnSetPolicy function. + * @tc.type: FUNC + */ +HWTEST_F(DeviceControlPluginTest, TestRestFactory, TestSize.Level1) +{ + plugin_ = ResetFactoryPlugin::GetPlugin(); + bool isChanged = false; + uint32_t code = POLICY_FUNC_CODE((std::uint32_t)FuncOperateType::SET, RESET_FACTORY); + std::string policyData{""}; + MessageParcel data; + ErrCode ret = plugin_->OnHandlePolicy(code, data, policyData, isChanged); + ASSERT_TRUE(ret != ERR_OK); +} +} // namespace TEST +} // namespace EDM +} // namespace OHOS \ No newline at end of file diff --git a/test/unittest/edm_plugin/reset_factory_plugin_test.h b/test/unittest/edm_plugin/reset_factory_plugin_test.h new file mode 100644 index 0000000000000000000000000000000000000000..7e6384361c8e522116c52fa01ccb213d409cadcc --- /dev/null +++ b/test/unittest/edm_plugin/reset_factory_plugin_test.h @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2022 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 EDM_UNIT_TEST_DEVICE_CONTROL_PLUGIN_TEST_H +#define EDM_UNIT_TEST_DEVICE_CONTROL_PLUGIN_TEST_H + +#include +#include "iplugin_manager.h" +#include "reset_factory_plugin.h" + +namespace OHOS { +namespace EDM { +namespace TEST { +class DeviceControlPluginTest : public testing::Test { +protected: + // Sets up the test fixture. + void SetUp() override; + + // Tears down the test fixture. + void TearDown() override; + + std::shared_ptr plugin_; +}; +} // namespace TEST +} // namespace EDM +} // namespace OHOS +#endif // EDM_UNIT_TEST_DEVICE_CONTROL_PLUGIN_TEST_H \ No newline at end of file diff --git a/test/unittest/enterprise_device_mgr_proxy/BUILD.gn b/test/unittest/enterprise_device_mgr_proxy/BUILD.gn index 5e77ed87d234f049bcf8809a55f638cc39855ac6..50463f72d31c4fd4128f0c5e9169f483b2861653 100644 --- a/test/unittest/enterprise_device_mgr_proxy/BUILD.gn +++ b/test/unittest/enterprise_device_mgr_proxy/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2022 Huawei Device Co., Ltd. +# Copyright (c) 2022-2023 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 @@ -31,7 +31,7 @@ ohos_unittest("EdmDeviceMgrProxyUnitTest") { "//commonlibrary/c_utils/base:utils_config", JSONCPP_INCLUDE_DIR, "$SUBSYSTEM_DIR/test/unittest/include", - "$SUBSYSTEM_DIR/interfaces/inner_api/include", + "$SUBSYSTEM_DIR/interfaces/inner_api/common/include", "$SUBSYSTEM_DIR/test/unittest/mock/include", ] diff --git a/test/unittest/enterprise_device_mgr_proxy/enterprise_device_mgr_proxy_test/enterprise_device_mgr_proxy_test.cpp b/test/unittest/enterprise_device_mgr_proxy/enterprise_device_mgr_proxy_test/enterprise_device_mgr_proxy_test.cpp index f8d6991a67cd3ed174ed188cf4ae8be9df1b0d00..25cd844dae850d5ea6c62f946a584595a451f6c1 100644 --- a/test/unittest/enterprise_device_mgr_proxy/enterprise_device_mgr_proxy_test/enterprise_device_mgr_proxy_test.cpp +++ b/test/unittest/enterprise_device_mgr_proxy/enterprise_device_mgr_proxy_test/enterprise_device_mgr_proxy_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2023 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 @@ -200,7 +200,7 @@ HWTEST_F(EnterpriseDeviceMgrProxyTest, TestGetEnabledAdminReplyFail, TestSize.Le EXPECT_CALL(*object_, SendRequest(_, _, _, _)) .Times(1) .WillOnce(Invoke(object_.GetRefPtr(), &EnterpriseDeviceMgrStubMock::InvokeSendRequestReplyFail)); - std::vector enabledAdminList1; + std::vector enabledAdminList1; ErrCode errVal = enterpriseDeviceMgrProxyTest->GetEnabledAdmin(AdminType::NORMAL, enabledAdminList1); EXPECT_TRUE(errVal != ERR_OK); } @@ -212,7 +212,7 @@ HWTEST_F(EnterpriseDeviceMgrProxyTest, TestGetEnabledAdminReplyFail, TestSize.Le */ HWTEST_F(EnterpriseDeviceMgrProxyTest, TestGetEnabledAdminFail, TestSize.Level1) { - std::vector enabledAdminList1; + std::vector enabledAdminList1; EXPECT_CALL(*object_, SendRequest(_, _, _, _)) .Times(1) .WillOnce(Invoke(object_.GetRefPtr(), &EnterpriseDeviceMgrStubMock::InvokeSendRequestFail)); diff --git a/test/unittest/include/iplugin_template_test.h b/test/unittest/include/iplugin_template_test.h index 14c75eac99b96d138ae7f4a6bd4ba50acc40f43e..66d539b63b06c4c732726fe2b18a2451f3f3f0d2 100644 --- a/test/unittest/include/iplugin_template_test.h +++ b/test/unittest/include/iplugin_template_test.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2023 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 @@ -380,11 +380,8 @@ public: class PluginTemplateTest : public testing::Test { protected: - // Tears down the test fixture. - virtual void TearDown() - { - PluginManager::GetInstance().reset(); - } + void SetUp() override; + void TearDown() override; }; } // namespace TEST } // namespace EDM diff --git a/test/unittest/src/enterprise_device_mgr_proxy_test.cpp b/test/unittest/src/enterprise_device_mgr_proxy_test.cpp index 1d61db0dad460af195e202e7ddc774c5e7d08e6c..811b509ceb0f6086b94a050c781b8ccb232aa0c5 100644 --- a/test/unittest/src/enterprise_device_mgr_proxy_test.cpp +++ b/test/unittest/src/enterprise_device_mgr_proxy_test.cpp @@ -79,7 +79,7 @@ HWTEST_F(EnterpriseDeviceMgrProxyTest, TestDisableAdmin, TestSize.Level1) enterpriseDeviceMgrProxyTest->GetEnabledAdmins(enabledAdminList); EXPECT_TRUE(enabledAdminList.empty()); - std::vector enabledAdminList1; + std::vector enabledAdminList1; enterpriseDeviceMgrProxyTest->GetEnabledAdmin(AdminType::NORMAL, enabledAdminList1); EXPECT_TRUE(enabledAdminList1.empty()); diff --git a/test/unittest/src/iplugin_template_test.cpp b/test/unittest/src/iplugin_template_test.cpp index 7d0918bdf39a8e9f6f5850dee8ce48acc8b100d9..d76f57bd3ba09a596fcb144be06c88f704344d38 100644 --- a/test/unittest/src/iplugin_template_test.cpp +++ b/test/unittest/src/iplugin_template_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2023 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 @@ -14,7 +14,7 @@ */ #include "iplugin_template_test.h" - +#include "policy_manager.h" using namespace testing::ext; namespace OHOS { @@ -316,6 +316,16 @@ HWTEST_F(PluginTemplateTest, TestOnGetPolicy, TestSize.Level1) ErrCode ret = plugin->OnGetPolicy(policyData, reply); ASSERT_TRUE(ret == ERR_OK); } + +void PluginTemplateTest::SetUp() +{ + PolicyManager::GetInstance(); +} + +void PluginTemplateTest::TearDown() +{ + PluginManager::GetInstance().reset(); +} } // namespace TEST } // namespace EDM } // namespace OHOS \ No newline at end of file