1 /*
2 * Copyright (c) 2023 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 "firmware_check_executor.h"
17
18 #include <thread>
19
20 #include "config_parse.h"
21 #include "firmware_common.h"
22 #include "firmware_constant.h"
23 #include "firmware_file_utils.h"
24 #include "firmware_icheck.h"
25 #include "firmware_log.h"
26 #include "firmware_status_cache.h"
27 #include "firmware_update_helper.h"
28 #include "update_helper.h"
29
30 namespace OHOS {
31 namespace UpdateEngine {
Execute()32 void FirmwareCheckExecutor::Execute()
33 {
34 FIRMWARE_LOGI("FirmwareCheckExecutor::Execute");
35 DelayedSingleton<FirmwareStatusCache>::GetInstance()->SetIsChecking(true);
36 std::thread checkThread(&FirmwareCheckExecutor::DoCheck, this);
37 checkThread.detach();
38 }
39
Complete()40 void FirmwareCheckExecutor::Complete()
41 {
42 FIRMWARE_LOGI("FirmwareCheckExecutor::complete");
43 DelayedSingleton<FirmwareStatusCache>::GetInstance()->SetIsChecking(false);
44 checkComponentCallback_.firmwareComponentCallback(status_, duration_, componentList_, checkAndAuthInfo_);
45 }
46
DoCheck()47 void FirmwareCheckExecutor::DoCheck()
48 {
49 FIRMWARE_LOGI("FirmwareCheckExecutor::DoCheck");
50 FirmwareCheckCallback cb{
51 [=](CheckStatus status, const Duration &duration, const std::vector<FirmwareComponent> &firmwareCheckResultList,
52 const CheckAndAuthInfo &checkAndAuthInfo) {
53 status_ = status;
54 duration_ = duration;
55 componentList_ = firmwareCheckResultList;
56 checkAndAuthInfo_ = checkAndAuthInfo;
57 FIRMWARE_LOGI("CheckComplete status: %{public}d size: %{public}d", status_, CAST_INT(componentList_.size()));
58 if (status_ == CheckStatus::CHECK_FAIL || componentList_.size() == 0) {
59 Complete();
60 return;
61 }
62 SetComponentCheckStatus();
63 Complete();
64 }};
65
66 std::shared_ptr<FirmwareICheck> check = nullptr;
67 check = std::make_shared<FirmwareICheck>(RequestType::CHECK);
68 if (check == nullptr) {
69 FIRMWARE_LOGE("check is nullptr");
70 return;
71 }
72 check->DoAction(cb);
73 }
74
SetComponentCheckStatus()75 void FirmwareCheckExecutor::SetComponentCheckStatus()
76 {
77 FIRMWARE_LOGI("FirmwareCheckExecutor::SetComponentCheckStatus");
78 for (auto &component : componentList_) {
79 component.status = UpgradeStatus::CHECK_VERSION_SUCCESS;
80 }
81 }
82 } // namespace UpdateEngine
83 } // namespace OHOS
84