• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 #include "restorer.h"
16 #include "napi_util.h"
17 #include "update_service_kits.h"
18 
19 namespace OHOS {
20 namespace UpdateEngine {
FactoryReset(napi_env env,napi_callback_info info)21 napi_value Restorer::Napi::FactoryReset(napi_env env, napi_callback_info info)
22 {
23     CLIENT_LOGI("Restorer::Napi::FactoryReset");
24     Restorer* restorer = UnwrapJsObject<Restorer>(env, info);
25     PARAM_CHECK_NAPI_CALL(env, restorer != nullptr, return nullptr, "Error get restorer");
26     return restorer->FactoryReset(env, info);
27 }
28 
Restorer(napi_env env,napi_value thisVar)29 Restorer::Restorer(napi_env env, napi_value thisVar)
30 {
31     napi_ref thisReference = nullptr;
32     napi_create_reference(env, thisVar, 1, &thisReference);
33     sessionsMgr_ = std::make_shared<SessionManager>(env, thisReference);
34     CLIENT_LOGI("Restorer::Restorer");
35 }
36 
FactoryReset(napi_env env,napi_callback_info info)37 napi_value Restorer::FactoryReset(napi_env env, napi_callback_info info)
38 {
39     SessionParams sessionParams(SessionType::SESSION_FACTORY_RESET, CALLBACK_POSITION_ONE, true);
40     napi_value retValue = StartSession(env, info, sessionParams,
41         [](SessionType type, void *context) -> int {
42             BusinessError *businessError = reinterpret_cast<BusinessError *>(context);
43             return UpdateServiceKits::GetInstance().FactoryReset(*businessError);
44         });
45     PARAM_CHECK(retValue != nullptr, return nullptr, "Failed to FactoryReset.");
46     return retValue;
47 }
48 } // namespace UpdateEngine
49 } // namespace OHOS
50