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_sys_installer_callback.h"
17
18 #include "firmware_log.h"
19
20 namespace OHOS {
21 namespace UpdateEngine {
SysInstallerCallback(SysInstallerExecutorCallback & installCallback)22 SysInstallerCallback::SysInstallerCallback(SysInstallerExecutorCallback &installCallback)
23 {
24 sysInstallCallback_ = installCallback;
25 }
26
OnUpgradeProgress(SysInstaller::UpdateStatus updateStatus,int percent,const std::string & resultMsg)27 void SysInstallerCallback::OnUpgradeProgress(SysInstaller::UpdateStatus updateStatus, int percent, const std::string &resultMsg)
28 {
29 FIRMWARE_LOGI("sysInstallerCallback OnUpgradeProgress status %{public}d percent %{public}d", updateStatus, percent);
30 InstallProgress installProgress = {};
31 switch (updateStatus) {
32 case SysInstaller::UpdateStatus::UPDATE_STATE_INIT:
33 case SysInstaller::UpdateStatus::UPDATE_STATE_ONGOING:
34 installProgress.progress.status = UpgradeStatus::INSTALLING;
35 break;
36 case SysInstaller::UpdateStatus::UPDATE_STATE_SUCCESSFUL:
37 installProgress.progress.status = UpgradeStatus::INSTALL_SUCCESS;
38 break;
39 default:
40 installProgress.progress.status = UpgradeStatus::INSTALL_FAIL;
41 installProgress.errMsg.errorMsg = resultMsg;
42 break;
43 }
44
45 installProgress.progress.percent = static_cast<uint32_t>(percent);
46 installProgress.errMsg.errorCode = CAST_INT(updateStatus);
47 sysInstallCallback_.onSysInstallerCallback(installProgress);
48 }
49 } // namespace UpdateEngine
50 } // namespace OHOS
51