1 /*
2 * Copyright (c) 2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "reset_factory_plugin.h"
17 #include "edm_ipc_interface_code.h"
18 #include "update_service_kits.h"
19 #include "plugin_manager.h"
20
21 namespace OHOS {
22 namespace EDM {
23 const bool REGISTER_RESULT = PluginManager::GetInstance()->AddPlugin(ResetFactoryPlugin::GetPlugin());
24
InitPlugin(std::shared_ptr<IPluginTemplate<ResetFactoryPlugin,std::string>> ptr)25 void ResetFactoryPlugin::InitPlugin(std::shared_ptr<IPluginTemplate<ResetFactoryPlugin, std::string>> ptr)
26 {
27 EDMLOGI("ResetFactoryPlugin InitPlugin...");
28 ptr->InitAttribute(EdmInterfaceCode::RESET_FACTORY, "reset_factory", "ohos.permission.ENTERPRISE_RESET_DEVICE",
29 IPlugin::PermissionType::SUPER_DEVICE_ADMIN, false);
30 ptr->SetSerializer(StringSerializer::GetInstance());
31 ptr->SetOnHandlePolicyListener(&ResetFactoryPlugin::OnSetPolicy, FuncOperateType::SET);
32 }
33
OnSetPolicy()34 ErrCode ResetFactoryPlugin::OnSetPolicy()
35 {
36 UpdateEngine::BusinessError businessError;
37 int32_t ret = UpdateEngine::UpdateServiceKits::GetInstance().FactoryReset(businessError);
38 if (FAILED(ret)) {
39 EDMLOGE("ResetFactoryPlugin:OnSetPolicy send request fail. %{public}d", ret);
40 return EdmReturnErrCode::SYSTEM_ABNORMALLY;
41 }
42 return ERR_OK;
43 }
44 } // namespace EDM
45 } // namespace OHOS