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_util.h"
17 
18 #include "firmware_combine_version_utils.h"
19 #include "firmware_constant.h"
20 #include "device_adapter.h"
21 #include "firmware_update_helper.h"
22 #include "preferences_utils.h"
23 #include "update_define.h"
24 #include "update_log.h"
25 #include "update_service.h"
26 #include "update_service_cache.h"
27 #include "update_system_event.h"
28 
29 namespace OHOS {
30 namespace UpdateEngine {
BuildTaskBody(const Progress & progress,TaskBody & taskBody)31 void UpdateServiceUtil::BuildTaskBody(const Progress &progress, TaskBody &taskBody)
32 {
33     taskBody.status = progress.status;
34     taskBody.progress = static_cast<int32_t>(progress.percent);
35     int errorCode = atoi(progress.endReason.c_str());
36     if (errorCode != 0) {
37         ErrorMessage errorMsg;
38         errorMsg.errorCode = errorCode;
39         errorMsg.errorMessage = progress.endReason;
40         taskBody.errorMessages.push_back(errorMsg);
41     }
42 }
43 
GetUpgradeCallback(const UpgradeInfo & upgradeInfo)44 sptr<IUpdateCallback> UpdateServiceUtil::GetUpgradeCallback(const UpgradeInfo &upgradeInfo)
45 {
46     sptr<UpdateService> service = UpdateService::GetInstance();
47     if (service == nullptr) {
48         ENGINE_LOGI("GetUpgradeCallback no instance");
49         return nullptr;
50     }
51     return service->GetUpgradeCallback(upgradeInfo);
52 }
53 } // namespace UpdateEngine
54 } // namespace OHOS