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_installer_manager.h" 17 18 #include "log/log.h" 19 #include "package/pkg_manager.h" 20 #include "utils.h" 21 #include "updater_main.h" 22 23 namespace OHOS { 24 namespace SysInstaller { 25 using namespace Updater; 26 RegisterDump(std::unique_ptr<StreamInstallerManagerHelper> ptr)27void StreamInstallerManager::RegisterDump(std::unique_ptr<StreamInstallerManagerHelper> ptr) 28 { 29 helper_ = std::move(ptr); 30 } 31 GetInstance()32StreamInstallerManager &StreamInstallerManager::GetInstance() 33 { 34 static StreamInstallerManager instance; 35 return instance; 36 } 37 SysInstallerInit()38int32_t StreamInstallerManager::SysInstallerInit() 39 { 40 if (helper_ == nullptr) { 41 if (helper_ == nullptr) { 42 RegisterDump(std::make_unique<StreamInstallerManagerHelper>()); 43 } 44 } 45 return helper_->SysInstallerInit(); 46 } 47 StartStreamUpdate()48int32_t StreamInstallerManager::StartStreamUpdate() 49 { 50 if (helper_ == nullptr) { 51 LOG(ERROR) << "helper_ null"; 52 return -1; 53 } 54 return helper_->StartStreamUpdate(); 55 } 56 StopStreamUpdate()57int32_t StreamInstallerManager::StopStreamUpdate() 58 { 59 if (helper_ == nullptr) { 60 LOG(ERROR) << "helper_ null"; 61 return -1; 62 } 63 return helper_->StopStreamUpdate(); 64 } 65 ProcessStreamData(const uint8_t * buffer,uint32_t size)66int32_t StreamInstallerManager::ProcessStreamData(const uint8_t *buffer, uint32_t size) 67 { 68 if (helper_ == nullptr) { 69 LOG(ERROR) << "helper_ null"; 70 return -1; 71 } 72 return helper_->ProcessStreamData(buffer, size); 73 } 74 SetUpdateCallback(const sptr<ISysInstallerCallback> & updateCallback)75int32_t StreamInstallerManager::SetUpdateCallback(const sptr<ISysInstallerCallback> &updateCallback) 76 { 77 if (helper_ == nullptr) { 78 LOG(ERROR) << "helper_ null"; 79 return -1; 80 } 81 return helper_->SetUpdateCallback(updateCallback); 82 } 83 GetUpdateStatus()84int32_t StreamInstallerManager::GetUpdateStatus() 85 { 86 if (helper_ == nullptr) { 87 LOG(ERROR) << "helper_ null"; 88 return -1; 89 } 90 return helper_->GetUpdateStatus(); 91 } 92 93 } // namespace SysInstaller 94 } // namespace OHOS 95