From b04d0d263a2f8a8174bcfa379c1c1a6e1b482f0e Mon Sep 17 00:00:00 2001 From: liwuli Date: Thu, 2 Feb 2023 09:46:07 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=81=A2=E5=A4=8D=E5=87=BA?= =?UTF-8?q?=E5=8E=82=E8=AE=BE=E7=BD=AE=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: liwuli --- bundle.json | 6 +- common/native/BUILD.gn | 55 +++++++ .../native}/include/edm_permission.h | 0 common/native/src/edm_data_ability_utils.cpp | 3 +- .../native}/src/edm_permission.cpp | 0 edm.gni | 1 + etc/init/edm.cfg | 2 +- framework/extension/BUILD.gn | 7 +- interfaces/inner_api/BUILD.gn | 2 + .../include/enterprise_device_mgr_proxy.h | 4 +- .../inner_api/common/include/policy_info.h | 1 + .../src/enterprise_device_mgr_proxy.cpp | 8 +- .../include/device_control_proxy.h | 37 +++++ .../src/device_control_proxy.cpp | 58 +++++++ interfaces/inner_api/plugin_kits/BUILD.gn | 55 +++++++ .../inner_api/plugin_kits}/include/iplugin.h | 3 +- .../plugin_kits/include/iplugin_manager.h | 41 +++++ .../plugin_kits}/include/iplugin_template.h | 13 +- .../plugin_kits/include/ipolicy_manager.h | 43 +++++ .../plugin_kits}/include/ipolicy_serializer.h | 0 .../include/utils/array_map_serializer.h | 0 .../include/utils/array_string_serializer.h | 0 .../include/utils/bool_serializer.h | 0 .../include/utils/func_code_utils.h | 0 .../include/utils/json_serializer.h | 0 .../include/utils/long_serializer.h | 0 .../include/utils/map_string_serializer.h | 0 .../include/utils/string_serializer.h | 0 .../inner_api/plugin_kits}/src/iplugin.cpp | 8 +- .../plugin_kits/src/iplugin_manager.cpp | 30 ++++ .../plugin_kits/src/ipolicy_manager.cpp | 30 ++++ .../src/utils/array_map_serializer.cpp | 0 .../src/utils/array_string_serializer.cpp | 0 .../src/utils/bool_serializer.cpp | 0 .../src/utils/func_code_utils.cpp | 0 .../src/utils/json_serializer.cpp | 0 .../src/utils/long_serializer.cpp | 0 .../src/utils/map_string_serializer.cpp | 0 .../src/utils/string_serializer.cpp | 0 interfaces/kits/admin_manager/BUILD.gn | 3 +- interfaces/kits/datetime_manager/BUILD.gn | 4 +- interfaces/kits/device_control/BUILD.gn | 46 ++++++ .../include/device_control_addon.h | 49 ++++++ .../src/device_control_addon.cpp | 94 +++++++++++ services/edm/BUILD.gn | 23 +-- .../edm/include/enterprise_device_mgr_stub.h | 4 +- services/edm/include/permission_manager.h | 3 +- services/edm/include/plugin_manager.h | 5 +- services/edm/include/policy_manager.h | 5 +- .../edm/src/enterprise_device_mgr_ability.cpp | 3 +- .../edm/src/enterprise_device_mgr_stub.cpp | 6 +- services/edm/src/plugin_manager.cpp | 5 +- services/edm/src/policy_manager.cpp | 4 +- services/edm_plugin/BUILD.gn | 25 ++- .../include/get_device_name_plugin.h | 3 +- .../include/get_device_serial_plugin.h | 3 +- .../include/get_display_version_plugin.h | 3 +- .../edm_plugin/include/reset_factory_plugin.h | 51 ++++++ .../edm_plugin/include/set_datetime_plugin.h | 3 +- services/edm_plugin/plugin.gni | 9 +- .../edm_plugin/src/get_device_name_plugin.cpp | 5 +- .../src/get_device_serial_plugin.cpp | 7 +- .../src/get_display_version_plugin.cpp | 5 +- .../edm_plugin/src/reset_factory_plugin.cpp | 151 ++++++++++++++++++ .../edm_plugin/src/set_datetime_plugin.cpp | 5 +- test/unittest/BUILD.gn | 7 +- test/unittest/device_control_proxy/BUILD.gn | 72 +++++++++ .../device_control_proxy_test.cpp | 64 ++++++++ test/unittest/edm_plugin/BUILD.gn | 22 ++- .../edm_plugin/reset_factory_plugin_test.cpp | 49 ++++++ .../edm_plugin/reset_factory_plugin_test.h | 39 +++++ .../enterprise_device_mgr_proxy/BUILD.gn | 4 +- .../enterprise_device_mgr_proxy_test.cpp | 6 +- test/unittest/include/iplugin_template_test.h | 9 +- .../src/enterprise_device_mgr_proxy_test.cpp | 2 +- test/unittest/src/iplugin_template_test.cpp | 14 +- 76 files changed, 1110 insertions(+), 109 deletions(-) create mode 100644 common/native/BUILD.gn rename {services/edm => common/native}/include/edm_permission.h (100%) rename {services/edm => common/native}/src/edm_permission.cpp (100%) create mode 100644 interfaces/inner_api/device_control/include/device_control_proxy.h create mode 100644 interfaces/inner_api/device_control/src/device_control_proxy.cpp create mode 100644 interfaces/inner_api/plugin_kits/BUILD.gn rename {services/edm => interfaces/inner_api/plugin_kits}/include/iplugin.h (97%) create mode 100644 interfaces/inner_api/plugin_kits/include/iplugin_manager.h rename {services/edm => interfaces/inner_api/plugin_kits}/include/iplugin_template.h (98%) create mode 100644 interfaces/inner_api/plugin_kits/include/ipolicy_manager.h rename {services/edm => interfaces/inner_api/plugin_kits}/include/ipolicy_serializer.h (100%) rename {services/edm => interfaces/inner_api/plugin_kits}/include/utils/array_map_serializer.h (100%) rename {services/edm => interfaces/inner_api/plugin_kits}/include/utils/array_string_serializer.h (100%) rename {services/edm => interfaces/inner_api/plugin_kits}/include/utils/bool_serializer.h (100%) rename {services/edm => interfaces/inner_api/plugin_kits}/include/utils/func_code_utils.h (100%) rename {services/edm => interfaces/inner_api/plugin_kits}/include/utils/json_serializer.h (100%) rename {services/edm => interfaces/inner_api/plugin_kits}/include/utils/long_serializer.h (100%) rename {services/edm => interfaces/inner_api/plugin_kits}/include/utils/map_string_serializer.h (100%) rename {services/edm => interfaces/inner_api/plugin_kits}/include/utils/string_serializer.h (100%) rename {services/edm => interfaces/inner_api/plugin_kits}/src/iplugin.cpp (83%) create mode 100644 interfaces/inner_api/plugin_kits/src/iplugin_manager.cpp create mode 100644 interfaces/inner_api/plugin_kits/src/ipolicy_manager.cpp rename {services/edm => interfaces/inner_api/plugin_kits}/src/utils/array_map_serializer.cpp (100%) rename {services/edm => interfaces/inner_api/plugin_kits}/src/utils/array_string_serializer.cpp (100%) rename {services/edm => interfaces/inner_api/plugin_kits}/src/utils/bool_serializer.cpp (100%) rename {services/edm => interfaces/inner_api/plugin_kits}/src/utils/func_code_utils.cpp (100%) rename {services/edm => interfaces/inner_api/plugin_kits}/src/utils/json_serializer.cpp (100%) rename {services/edm => interfaces/inner_api/plugin_kits}/src/utils/long_serializer.cpp (100%) rename {services/edm => interfaces/inner_api/plugin_kits}/src/utils/map_string_serializer.cpp (100%) rename {services/edm => interfaces/inner_api/plugin_kits}/src/utils/string_serializer.cpp (100%) create mode 100644 interfaces/kits/device_control/BUILD.gn create mode 100644 interfaces/kits/device_control/include/device_control_addon.h create mode 100644 interfaces/kits/device_control/src/device_control_addon.cpp create mode 100644 services/edm_plugin/include/reset_factory_plugin.h create mode 100644 services/edm_plugin/src/reset_factory_plugin.cpp create mode 100644 test/unittest/device_control_proxy/BUILD.gn create mode 100644 test/unittest/device_control_proxy/device_control_proxy_test.cpp create mode 100644 test/unittest/edm_plugin/reset_factory_plugin_test.cpp create mode 100644 test/unittest/edm_plugin/reset_factory_plugin_test.h diff --git a/bundle.json b/bundle.json index 7b11858eb..f3a549eae 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 000000000..6ce7f438e --- /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 ef22bffa3..0b4704af0 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 bd0b5b40c..800b68150 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 bdd59ed6a..2bc8912dc 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 2265cfd91..958aedad2 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 00e723071..8da7ddc53 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 f9bfe9289..f61e7fb1e 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 573c4725b..16c619c1b 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 9b4b7ec1f..6e3b63b8b 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 000000000..5e22a31f9 --- /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 000000000..339bd05cb --- /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 0180dd203..91f54127b 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 000000000..23092b1e5 --- /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 dc86f4ec3..1cdb9b13a 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 000000000..615b78f11 --- /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 fea3c5c51..e2f2efb4e 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 000000000..9b3412af2 --- /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 000000000..7e1af909b --- /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 a841a0693..069d79de9 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 a4085b24a..a47419a66 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 000000000..6d74f4782 --- /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 000000000..6d7babd99 --- /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 000000000..81f11e170 --- /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 d87085a80..554a223fc 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 69d594c29..0f5675b82 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 28869a25a..0f4427f14 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 6e0098bc4..53d09d8c1 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 c44f5275e..9d7aa32e6 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 997dce260..635a1611f 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 195963281..4e8ae0fbf 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 27c72916a..b6b3c0b24 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 d215cd5e2..b412821d3 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 984507268..9b1178b57 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 4f760a204..e2a7d0de6 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 38d6447fa..cf5520719 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 860b7e6b4..b51b5d474 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 000000000..df5b0434f --- /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 75d9fa564..9928204ff 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 6eed010ef..d61d79c0b 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 61043a8c7..c0cdf3a00 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 4160122ac..a8b55e143 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 106f417da..7df469b6b 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 000000000..1b5a14884 --- /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 2c68b853a..aba80d2d2 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 c742eb307..8e2d2f676 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 000000000..b27e88efe --- /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 000000000..0f1ff4b5c --- /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 b5ab218a0..e20cf39df 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 000000000..569763258 --- /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 000000000..7e6384361 --- /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 5e77ed87d..50463f72d 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 f8d6991a6..25cd844da 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 14c75eac9..66d539b63 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 1d61db0da..811b509ce 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 7d0918bdf..d76f57bd3 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 -- Gitee