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 "status_manager.h" 17 18 #include "log/log.h" 19 #include "utils.h" 20 21 namespace OHOS { 22 namespace SysInstaller { 23 using namespace Updater; 24 Init()25void StatusManager::Init() 26 { 27 updateStatus_ = UPDATE_STATE_INIT; 28 percent_ = 0; 29 } 30 SetUpdateCallback(const sptr<ISysInstallerCallback> & updateCallback)31int StatusManager::SetUpdateCallback(const sptr<ISysInstallerCallback> &updateCallback) 32 { 33 if (updateCallback == nullptr) { 34 LOG(ERROR) << "para error"; 35 return -1; 36 } 37 updateCallback_ = updateCallback; 38 return 0; 39 } 40 GetUpdateStatus()41int StatusManager::GetUpdateStatus() 42 { 43 return updateStatus_; 44 } 45 UpdateCallback(UpdateStatus updateStatus,int percent)46void StatusManager::UpdateCallback(UpdateStatus updateStatus, int percent) 47 { 48 if (updateCallback_ == nullptr) { 49 return; 50 } 51 52 if (updateStatus > UPDATE_STATE_SUCCESSFUL) { 53 LOG(INFO) << "status error:" << updateStatus; 54 return; 55 } 56 if (percent >=0 && percent <= 100 && percent >= percent_) { // 100 : max percent 57 percent_ = percent; 58 } 59 60 updateStatus_ = updateStatus; 61 LOG(INFO) << "status:" << updateStatus_ << " percent:" << percent_; 62 updateCallback_->OnUpgradeProgress(updateStatus_, percent_); 63 } 64 } // namespace SysInstaller 65 } // namespace OHOS 66