• 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_ab_callback.h"
17 
18 namespace OHOS {
19 namespace UpdateEngine {
UpdateServiceAbCallback(const UpgradeInfo & info)20 UpdateServiceAbCallback::UpdateServiceAbCallback(const UpgradeInfo &info)
21 {
22     InitEventInfo();
23     info_ = info;
24 }
25 
OnUpgradeProgress(int updateStatus,int percent)26 void UpdateServiceAbCallback::OnUpgradeProgress(int updateStatus, int percent)
27 {
28     ENGINE_LOGI("UpdateServiceAbCallback OnUpgradeProgress progress %d percent %d", updateStatus, percent);
29     switch (updateStatus) {
30         case OHOS::SysInstaller::UPDATE_STATE_INIT:
31         case OHOS::SysInstaller::UPDATE_STATE_ONGOING:
32             eventInfo_.taskBody.status = UPDATE_STATE_UPDATE_ON;
33             eventInfo_.eventId = EventId::EVENT_UPGRADE_UPDATE;
34             break;
35         case OHOS::SysInstaller::UPDATE_STATE_SUCCESSFUL:
36             eventInfo_.taskBody.status = UPDATE_STATE_UPDATE_SUCCESS;
37             eventInfo_.eventId = EventId::EVENT_UPGRADE_UPDATE;
38             break;
39         case OHOS::SysInstaller::UPDATE_STATE_FAILED:
40             eventInfo_.taskBody.status = UPDATE_STATE_UPDATE_FAIL;
41             eventInfo_.eventId = EventId::EVENT_UPGRADE_FAIL;
42             break;
43         default:
44             ENGINE_LOGE("updateStatus invalid, is %d", updateStatus);
45             return;
46     }
47     eventInfo_.taskBody.progress = percent;
48     sptr<UpdateService> service = UpdateService::GetInstance();
49     if (service == nullptr) {
50         ENGINE_LOGE("UpdateServiceAbCallback OnUpgradeProgress UpdateService no instance");
51         return;
52     }
53     sptr<IUpdateCallback> upgradeCallback = service->GetUpgradeCallback(info_);
54     if (upgradeCallback == nullptr) {
55         ENGINE_LOGE("UpdateServiceAbCallback OnUpgradeProgress upgradeCallback_ is null");
56         return;
57     }
58     upgradeCallback->OnEvent(eventInfo_);
59 }
60 
InitEventInfo()61 void UpdateServiceAbCallback::InitEventInfo()
62 {
63     eventInfo_.taskBody.installMode = INSTALLMODE_NORMAL;
64     eventInfo_.taskBody.subStatus = 0;
65     eventInfo_.taskBody.versionDigestInfo.versionDigest = "versionDigest";
66 }
67 } // namespace UpdateEngine
68 } // namespace OHOS
69