1190978c3Sopenharmony_ci/*
2190978c3Sopenharmony_ci * Copyright (c) 2022 Huawei Device Co., Ltd.
3190978c3Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4190978c3Sopenharmony_ci * you may not use this file except in compliance with the License.
5190978c3Sopenharmony_ci * You may obtain a copy of the License at
6190978c3Sopenharmony_ci *
7190978c3Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8190978c3Sopenharmony_ci *
9190978c3Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10190978c3Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11190978c3Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12190978c3Sopenharmony_ci * See the License for the specific language governing permissions and
13190978c3Sopenharmony_ci * limitations under the License.
14190978c3Sopenharmony_ci */
15190978c3Sopenharmony_ci
16190978c3Sopenharmony_ci#include "update_service_local_updater.h"
17190978c3Sopenharmony_ci
18190978c3Sopenharmony_ci#include "package/package.h"
19190978c3Sopenharmony_ci#include "updaterkits/updaterkits.h"
20190978c3Sopenharmony_ci
21190978c3Sopenharmony_ci#include "update_log.h"
22190978c3Sopenharmony_ci#include "update_service_util.h"
23190978c3Sopenharmony_ci#include "update_system_event.h"
24190978c3Sopenharmony_ci
25190978c3Sopenharmony_cinamespace OHOS {
26190978c3Sopenharmony_cinamespace UpdateEngine {
27190978c3Sopenharmony_ciint32_t UpdateServiceLocalUpdater::ApplyNewVersion(const UpgradeInfo &info, const std::string &miscFile,
28190978c3Sopenharmony_ci    const std::vector<std::string> &packageNames, BusinessError &businessError)
29190978c3Sopenharmony_ci{
30190978c3Sopenharmony_ci#ifndef UPDATER_UT
31190978c3Sopenharmony_ci    SYS_EVENT_SYSTEM_UPGRADE(0, UpdateSystemEvent::UPGRADE_START);
32190978c3Sopenharmony_ci    businessError.errorNum = CallResult::SUCCESS;
33190978c3Sopenharmony_ci    int32_t ret = RebootAndInstallSdcardPackage(miscFile, packageNames) ? INT_CALL_SUCCESS : INT_CALL_FAIL;
34190978c3Sopenharmony_ci    ENGINE_LOGI("ApplyNewVersion result : %{public}d", ret);
35190978c3Sopenharmony_ci    SYS_EVENT_SYSTEM_UPGRADE(
36190978c3Sopenharmony_ci        0, ret == INT_CALL_SUCCESS ? UpdateSystemEvent::EVENT_SUCCESS_RESULT : UpdateSystemEvent::EVENT_FAILED_RESULT);
37190978c3Sopenharmony_ci    return ret;
38190978c3Sopenharmony_ci#else
39190978c3Sopenharmony_ci    return INT_CALL_SUCCESS;
40190978c3Sopenharmony_ci#endif
41190978c3Sopenharmony_ci}
42190978c3Sopenharmony_ci
43190978c3Sopenharmony_ciint32_t UpdateServiceLocalUpdater::VerifyUpgradePackage(const std::string &packagePath, const std::string &keyPath,
44190978c3Sopenharmony_ci    BusinessError &businessError)
45190978c3Sopenharmony_ci{
46190978c3Sopenharmony_ci    businessError.errorNum = CallResult::SUCCESS;
47190978c3Sopenharmony_ci    int32_t ret = ::VerifyPackageWithCallback(packagePath.c_str(), keyPath.c_str(),
48190978c3Sopenharmony_ci        [](int32_t result, uint32_t percent) {});
49190978c3Sopenharmony_ci    ENGINE_LOGI("VerifyUpgradePackage %s, %s, %{public}d", packagePath.c_str(), keyPath.c_str(), ret);
50190978c3Sopenharmony_ci    return (ret == 0) ? INT_CALL_SUCCESS : INT_CALL_FAIL;
51190978c3Sopenharmony_ci}
52190978c3Sopenharmony_ci} // namespace UpdateEngine
53190978c3Sopenharmony_ci} // namespace OHOS
54