• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 "stream_status_manager.h"
17 
18 #include "sys_installer_common.h"
19 #include "log/log.h"
20 #include "utils.h"
21 
22 namespace OHOS {
23 namespace SysInstaller {
24 using namespace Updater;
25 
Init()26 void StreamStatusManager::Init()
27 {
28     updateStatus_ = UpdateStatus::UPDATE_STATE_INIT;
29 }
30 
SetUpdateCallback(const sptr<ISysInstallerCallback> & updateCallback)31 int StreamStatusManager::SetUpdateCallback(const sptr<ISysInstallerCallback> &updateCallback)
32 {
33     std::lock_guard<std::mutex> lock(updateCbMutex_);
34     if (updateCallback == nullptr) {
35         LOG(ERROR) << "para error";
36         return -1;
37     }
38 
39     updateCallback_ = updateCallback;
40     return 0;
41 }
42 
GetUpdateStatus()43 int StreamStatusManager::GetUpdateStatus()
44 {
45     return static_cast<int>(updateStatus_);
46 }
47 
UpdateCallback(UpdateStatus updateStatus,int dealLen,const std::string & resultMsg)48 void StreamStatusManager::UpdateCallback(UpdateStatus updateStatus, int dealLen, const std::string &resultMsg)
49 {
50     std::lock_guard<std::mutex> lock(updateCbMutex_);
51     if (updateCallback_ == nullptr) {
52         LOG(ERROR) << "updateCallback_ null";
53         return;
54     }
55 
56     if (updateStatus > UpdateStatus::UPDATE_STATE_MAX) {
57         LOG(INFO) << "status error:" << static_cast<int>(updateStatus);
58         return;
59     }
60 
61     updateStatus_ = updateStatus;
62     LOG(INFO) << "status:" << static_cast<int>(updateStatus_) << " dealLen:"  << dealLen << " msg:" << resultMsg;
63     updateCallback_->OnUpgradeDealLen(updateStatus_, dealLen, resultMsg);
64 }
65 
66 } // namespace SysInstaller
67 } // namespace OHOS
68