• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 #ifndef UPDATER_UPDATER_H
17 #define UPDATER_UPDATER_H
18 #include <string>
19 #include "package/packages_info.h"
20 #include "package/pkg_manager.h"
21 
22 namespace Updater {
23 enum UpdaterStatus {
24     UPDATE_ERROR = -1,
25     UPDATE_SUCCESS,
26     UPDATE_CORRUPT, /* package or verify failed, something is broken. */
27     UPDATE_SKIP, /* skip update because of condition is not satisfied, e.g, battery is low */
28     UPDATE_RETRY,
29     UPDATE_SPACE_NOTENOUGH,
30     UPDATE_UNKNOWN
31 };
32 
33 using PostMessageFunction = std::function<void(const char *cmd, const char *content)>;
34 
35 enum PackageUpdateMode {
36     HOTA_UPDATE = 0,
37     SDCARD_UPDATE,
38     UNKNOWN_UPDATE,
39 };
40 
41 struct UpdaterParams {
42     bool factoryWipeData {};
43     bool userWipeData {};
44     int retryCount {};
45     float initialProgress {};
46     float currentPercentage {};
47     unsigned int pkgLocation {};
48     std::vector<std::string> updatePackage {};
49 };
50 
51 int GetTmpProgressValue();
52 
53 void ProgressSmoothHandler(int beginProgress, int endProgress);
54 
55 UpdaterStatus DoInstallUpdaterPackage(Hpackage::PkgManager::PkgManagerPtr pkgManager,
56     UpdaterParams &upParams, PackageUpdateMode updateMode);
57 
58 UpdaterStatus StartUpdaterProc(Hpackage::PkgManager::PkgManagerPtr pkgManager,
59     UpdaterParams &upParams, int &maxTemperature);
60 
61 int GetUpdatePackageInfo(Hpackage::PkgManager::PkgManagerPtr pkgManager, const std::string& path);
62 
63 #ifdef UPDATER_USE_PTABLE
64 bool PtableProcess(Hpackage::PkgManager::PkgManagerPtr pkgManager, PackageUpdateMode updateMode);
65 #endif
66 
67 int ExecUpdate(Hpackage::PkgManager::PkgManagerPtr pkgManager, int retry, PostMessageFunction postMessage);
68 
69 UpdaterStatus IsSpaceCapacitySufficient(const std::vector<std::string> &packagePath);
70 
71 bool IsSDCardExist(const std::string &sdcard_path);
72 
73 void PostUpdater(bool clearMisc);
74 
75 bool DeleteUpdaterPath(const std::string &path);
76 
77 std::vector<std::string> ParseParams(int argc, char **argv);
78 
79 bool ClearMisc();
80 
81 int GetBootMode(int &mode);
82 
83 std::string GetWorkPath();
84 } // Updater
85 #endif /* UPDATER_UPDATER_H */
86