1 /* 2 * Copyright (c) 2021-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 #ifndef UPDATER_MAIN_H 16 #define UPDATER_MAIN_H 17 18 #include <iostream> 19 #include <string> 20 #include "package/pkg_manager.h" 21 #include "pkg_manager.h" 22 #include "updater/updater.h" 23 #include "updater_init.h" 24 25 namespace Updater { 26 enum FactoryResetMode { 27 USER_WIPE_DATA = 0, 28 FACTORY_WIPE_DATA, 29 MENU_WIPE_DATA, 30 CLEAR_SPACE, 31 INVALID_MODE, 32 }; 33 34 int UpdaterMain(int argc, char **argv); 35 36 int FactoryReset(FactoryResetMode mode, const std::string &path); 37 38 void RebootAfterUpdateSuccess(const UpdaterParams &upParams, const std::vector<std::string> &args); 39 40 UpdaterStatus InstallUpdaterPackage(UpdaterParams &upParams, Hpackage::PkgManager::PkgManagerPtr manager); 41 42 UpdaterStatus DoUpdatePackages(UpdaterParams &upParams); 43 44 UpdaterStatus StartUpdaterEntry(UpdaterParams &upParams); 45 46 UpdaterStatus DoUpdaterEntry(UpdaterParams &upParams); 47 48 UpdaterStatus DoFactoryRstEntry(UpdaterParams &upParams); 49 50 UpdaterStatus UpdaterFromSdcard(UpdaterParams &upParams); 51 52 bool IsBatteryCapacitySufficient(); 53 54 void DeleteInstallTimeFile(); 55 56 void WriteInstallTime(UpdaterParams &upParams); 57 58 void ReadInstallTime(UpdaterParams &upParams); 59 60 bool IsDouble(const std::string& str); 61 62 UpdaterStatus InstallUpdaterPackages(UpdaterParams &upParams); 63 64 int OtaUpdatePreCheck(Hpackage::PkgManager::PkgManagerPtr pkgManager, const std::string &packagePath); 65 66 void SetPrgrsSmoothHandlerFunc(std::function<void(float, float, UpdaterParams, bool)> func); 67 68 void SetTotalProgressRatio(float ratio); 69 70 float GetTotalProgressRatio(); 71 72 void ProcessPrgrsSmooth(float beginProgress, float endProgress, UpdaterParams upParams, bool isFinish); 73 74 #ifdef __cplusplus 75 #if __cplusplus 76 extern "C" { 77 #endif 78 #endif /* __cplusplus */ 79 bool IsSupportOption([[maybe_unused]] const std::string &option); 80 UpdaterStatus ProcessOtherOption([[maybe_unused]] const std::string &option, 81 [[maybe_unused]] UpdaterParams &upParams, PackageUpdateMode &mode); 82 bool PreStartBinaryEntry([[maybe_unused]] const std::string &path); 83 int32_t VerifySpecialPkgs([[maybe_unused]]UpdaterParams &upParams); 84 UpdaterStatus CheckAndSetSlot([[maybe_unused]]UpdaterParams &upParams); 85 bool PostUpdateSyncProcess([[maybe_unused]] bool isOtaUpdate, [[maybe_unused]] const UpdaterParams &upParams, 86 [[maybe_unused]] UpdaterStatus &status); 87 void UpdaterVerifyFailEntry(bool verifyret); 88 bool IsSpareBoardBoot(void); 89 bool IsNeedWipe(); 90 void NotifyAutoReboot(PackageUpdateMode &mode); 91 bool NotifySdUpdateReboot(const UpdaterParams &upParams); 92 void NotifyReboot(const std::string& rebootTarget, const std::string &rebootReason, const std::string &extData = ""); 93 UpdaterStatus NotifyActionResult(UpdaterParams &upParams, 94 UpdaterStatus &status, const std::vector<NotifyAction> ¬ifyActionVec); 95 UpdaterStatus UpdateSubPkg(UpdaterParams &upParams); 96 void NotifyPreCheck(UpdaterStatus &status, UpdaterParams &upParams); 97 #ifdef __cplusplus 98 #if __cplusplus 99 } 100 #endif 101 #endif /* __cplusplus */ 102 } // namespace Updater 103 #endif // UPDATER_MAIN_H 104