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 "update_service_local_updater.h"
17 
18 #include "package/package.h"
19 #include "updaterkits/updaterkits.h"
20 
21 #include "update_log.h"
22 #include "update_service_util.h"
23 #include "update_system_event.h"
24 
25 namespace OHOS {
26 namespace UpdateEngine {
ApplyNewVersion(const UpgradeInfo & info,const std::string & miscFile,const std::vector<std::string> & packageNames,BusinessError & businessError)27 int32_t UpdateServiceLocalUpdater::ApplyNewVersion(const UpgradeInfo &info, const std::string &miscFile,
28     const std::vector<std::string> &packageNames, BusinessError &businessError)
29 {
30 #ifndef UPDATER_UT
31     SYS_EVENT_SYSTEM_UPGRADE(0, UpdateSystemEvent::UPGRADE_START);
32     businessError.errorNum = CallResult::SUCCESS;
33     int32_t ret = RebootAndInstallSdcardPackage(miscFile, packageNames) ? INT_CALL_SUCCESS : INT_CALL_FAIL;
34     ENGINE_LOGI("ApplyNewVersion result : %{public}d", ret);
35     SYS_EVENT_SYSTEM_UPGRADE(
36         0, ret == INT_CALL_SUCCESS ? UpdateSystemEvent::EVENT_SUCCESS_RESULT : UpdateSystemEvent::EVENT_FAILED_RESULT);
37     return ret;
38 #else
39     return INT_CALL_SUCCESS;
40 #endif
41 }
42 
VerifyUpgradePackage(const std::string & packagePath,const std::string & keyPath,BusinessError & businessError)43 int32_t UpdateServiceLocalUpdater::VerifyUpgradePackage(const std::string &packagePath, const std::string &keyPath,
44     BusinessError &businessError)
45 {
46     businessError.errorNum = CallResult::SUCCESS;
47     int32_t ret = ::VerifyPackageWithCallback(packagePath.c_str(), keyPath.c_str(),
48         [](int32_t result, uint32_t percent) {});
49     ENGINE_LOGI("VerifyUpgradePackage %s, %s, %{public}d", packagePath.c_str(), keyPath.c_str(), ret);
50     return (ret == 0) ? INT_CALL_SUCCESS : INT_CALL_FAIL;
51 }
52 } // namespace UpdateEngine
53 } // namespace OHOS
54