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