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
18 #include "edm_ipc_interface_code.h"
19 #include "string_serializer.h"
20 #include "update_service_kits.h"
21
22 namespace OHOS {
23 namespace EDM {
24 const bool REGISTER_RESULT = IPluginManager::GetInstance()->AddPlugin(ResetFactoryPlugin::GetPlugin());
25
InitPlugin(std::shared_ptr<IPluginTemplate<ResetFactoryPlugin,std::string>> ptr)26 void ResetFactoryPlugin::InitPlugin(std::shared_ptr<IPluginTemplate<ResetFactoryPlugin, std::string>> ptr)
27 {
28 EDMLOGD("ResetFactoryPlugin InitPlugin...");
29 ptr->InitAttribute(EdmInterfaceCode::RESET_FACTORY, "reset_factory", "ohos.permission.ENTERPRISE_RESET_DEVICE",
30 IPlugin::PermissionType::SUPER_DEVICE_ADMIN, false);
31 ptr->SetSerializer(StringSerializer::GetInstance());
32 ptr->SetOnHandlePolicyListener(&ResetFactoryPlugin::OnSetPolicy, FuncOperateType::SET);
33 }
34
OnSetPolicy()35 ErrCode ResetFactoryPlugin::OnSetPolicy()
36 {
37 EDMLOGD("ResetFactoryPlugin OnSetPolicy");
38 UpdateEngine::BusinessError businessError;
39 int32_t ret = ERR_OK;
40 ret = UpdateEngine::UpdateServiceKits::GetInstance().FactoryReset(businessError);
41 if (FAILED(ret)) {
42 EDMLOGE("ResetFactoryPlugin:OnSetPolicy send request fail. %{public}d", ret);
43 return EdmReturnErrCode::SYSTEM_ABNORMALLY;
44 }
45 return ERR_OK;
46 }
47 } // namespace EDM
48 } // namespace OHOS
49