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