• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2024 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 OHOS_FILEMGMT_BACKUP_B_CONSTANTS_H
17 #define OHOS_FILEMGMT_BACKUP_B_CONSTANTS_H
18 
19 #include <array>
20 #include <cstdint>
21 #include <string>
22 #include <string_view>
23 #include <unistd.h>
24 
25 namespace OHOS::FileManagement::Backup::BConstants {
26 
27 static inline const char *EXTENSION_ACTION_PARA = "extensionAction";
28 static inline const char *EXTENSION_RESTORE_TYPE_PARA = "restoreType";
29 static inline const char *EXTENSION_VERSION_CODE_PARA = "versionCode";
30 static inline const char *EXTENSION_VERSION_NAME_PARA = "versionName";
31 static inline const char *EXTENSION_RESTORE_EXT_INFO_PARA = "restoreExtInfo";
32 static inline const char *EXTENSION_BACKUP_EXT_INFO_PARA = "backupExtInfo";
33 static inline const char *EXTENSION_APP_CLONE_INDEX_PARA = "ohos.extra.param.key.appCloneIndex";
34 static inline const char *EXTENSION_OLD_BACKUP_VERSION_PARA = "oldBackupVersion";
35 
36 enum class ExtensionAction {
37     INVALID = 0,
38     BACKUP = 1,
39     RESTORE = 2,
40 };
41 
42 enum ServiceSchedAction {
43     WAIT = 0,
44     START = 1,
45     RUNNING = 2,
46     FINISH = 3,
47     CLEAN = 4,
48     UNKNOWN = 5,
49 };
50 
51 enum ExtensionScenario {
52     INVALID = 0,
53     BACKUP = 1,
54     RESTORE = 2,
55 };
56 
57 constexpr int SPAN_USERID_UID = 200000;
58 constexpr int SYSTEM_UID = 0;
59 constexpr int XTS_UID = 1;
60 constexpr int DEFAULT_USER_ID = 100;
61 constexpr int BACKUP_UID = 1089;
62 constexpr int EXTENSION_THREAD_POOL_COUNT = 1;
63 constexpr int BACKUP_LOADSA_TIMEOUT_MS = 5000;
64 
65 constexpr int DECIMAL_BASE = 10; // 十进制基数
66 
67 constexpr off_t BIG_FILE_BOUNDARY = 2 * 1024 * 1024; // 大文件边界
68 constexpr unsigned long BIG_FILE_NAME_SIZE = 16;     // 大文件名长度(hash处理)
69 
70 constexpr int PATHES_TO_BACKUP_SIZE = 13;     // 应用默认备份的目录个数
71 constexpr uint32_t BACKUP_PARA_VALUE_MAX = 5; // 读取backup.para字段值的最大长度
72 constexpr int SA_THREAD_POOL_COUNT = 1;       // SA THREAD_POOL 最大线程数
73 constexpr int EXT_CONNECT_MAX_COUNT = 3;      // extension 最大启动数
74 constexpr int EXT_CONNECT_MAX_TIME = 15000;   // SA 启动 extension 等待连接最大时间
75 
76 constexpr int IPC_MAX_WAIT_TIME = 3000; // IPC通讯最大等待时间(s)
77 constexpr int MAX_PARCELABLE_VECTOR_NUM = 10000;
78 constexpr char FILE_SEPARATOR_CHAR = '/';
79 
80 // 分片打包常量
81 const uint64_t DEFAULT_SLICE_SIZE = 100 * 1024 * 1024; // 分片文件大小为100M
82 const uint32_t MAX_FILE_COUNT = 6000; // 单个tar包最多包含6000个文件
83 const int FILE_AND_MANIFEST_FD_COUNT = 2; // 每组文件和简报数量统计
84 
85 constexpr int DEFAULT_VFS_CACHE_PRESSURE = 100; // 默认内存回收参数
86 constexpr int BACKUP_VFS_CACHE_PRESSURE = 10000; // 备份过程修改参数
87 
88 constexpr int32_t INVALID_FD_NUM = -1;
89 
90 constexpr int MAX_FD_SEND_RATE = 800; // 允许应用申请的最大FD数量
91 constexpr int MIN_FD_SEND_RATE = 0; // 允许应用申请的最小FD数量
92 constexpr int DEFAULT_FD_SEND_RATE = 60; // 框架默认的FD数量
93 constexpr int32_t PARAM_STARING_MAX_MEMORY = 2 * 1024 * 1024;
94 constexpr uint32_t H2MS = 60 * 60 * 1000;
95 constexpr uint32_t MAX_UPDATE_TIMER = 4 * H2MS;
96 constexpr uint32_t DEFAULT_TIMEOUT = 15 * 60 * 1000;
97 constexpr uint32_t TIMEOUT_INVALID = UINT32_MAX;
98 constexpr int LONG_FILE_NAME_BOUNDARY_VAL = 255;
99 
100 constexpr int CALL_APP_ON_PROCESS_TIME_INTERVAL = 5; // 框架每隔5s去调用应用的onProcess
101 constexpr int APP_ON_PROCESS_MAX_TIMEOUT = 1000; // 应用的onProcess接口最大超时时间为1秒
102 constexpr int FIRST_CALL_APP_ON_PROCESS_MAX_TIMEOUT = 15000; // 首次调用应用的onProcess接口最大超时时间为15秒
103 constexpr int APP_ON_PROCESS_TIMEOUT_MAX_COUNT = 3; // 应用的onProcess接口超时的上限次数
104 
105 constexpr int APP_ON_RELEASE_MAX_TIMEOUT = 5000; // 应用的onRelease接口最大超时时间为5秒
106 // 应用的getBackupCompatibilityInfo/getRestoreCompatibilityInfo接口最大超时时间为1秒
107 constexpr int APP_GETCOMINFO_MAX_TIMEOUT = 1000;
108 
109 // backup.para内配置项的名称,该配置项值为true时可在不更新hap包的情况下,可以读取包管理元数据配置文件的内容
110 static inline std::string BACKUP_DEBUG_OVERRIDE_EXTENSION_CONFIG_KEY = "backup.debug.overrideExtensionConfig";
111 static const bool BACKUP_DEBUG_OVERRIDE_EXTENSION_CONFIG_DEFAULT_VALUE = false;
112 
113 // backup.para内配置项的名称,该配置项AccountConfig为true时存在时,可以按照配置的AccountNumber备份恢复
114 static inline std::string BACKUP_DEBUG_OVERRIDE_ACCOUNT_CONFIG_KEY = "backup.debug.overrideAccountConfig";
115 static inline std::string BACKUP_DEBUG_OVERRIDE_ACCOUNT_NUMBER_KEY = "backup.debug.overrideAccountNumber";
116 
117 // 增量备份相关处理目录
118 static const std::string BACKUP_PATH_PREFIX = "/data/service/el2/";
119 static const std::string BACKUP_PATH_SURFFIX = "/backup/backup_sa/";
120 static const std::string BACKUP_INCEXC_SYMBOL = "incExc_";
121 static const std::string BACKUP_STAT_SYMBOL = "stat_";
122 static const std::string BACKUP_INCLUDE = "INCLUDES";
123 static const std::string BACKUP_EXCLUDE = "EXCLUDES";
124 
125 // backup.para内配置项的名称,该配置项为true时备份恢复支持Release接口调用
126 static inline std::string BACKUP_OVERRIDE_BACKUP_SA_RELEASE_KEY = "backup.overrideBackupSARelease";
127 static const bool BACKUP_DEBUG_OVERRIDE_BACKUP_SA_RELEASE_DEFAULT_VALUE = true;
128 
129 // backup.para内配置项的名称,该配置项为true时备份恢复支持增量恢复
130 static inline std::string BACKUP_OVERRIDE_INCREMENTAL_KEY = "backup.overrideIncrementalRestore";
131 static const bool BACKUP_DEBUG_OVERRIDE_INCREMENTAL_DEFAULT_VALUE = true;
132 
133 // 应用备份数据暂存路径
134 static inline std::string_view SA_BUNDLE_BACKUP_BACKUP = "/backup/";
135 static inline std::string_view SA_BUNDLE_BACKUP_RESTORE = "/restore/";
136 static inline std::string_view SA_BUNDLE_BACKUP_TMP_DIR = "/tmp/";
137 static inline std::string_view BACKUP_TOOL_RECEIVE_DIR = "/data/backup/received/";
138 static inline std::string_view PATH_BUNDLE_BACKUP_HOME_EL1 = "/data/storage/el1/base/.backup";
139 static inline std::string_view PATH_BUNDLE_BACKUP_HOME = "/data/storage/el2/base/.backup";
140 static inline std::string_view PATH_FILEMANAGE_BACKUP_HOME = "/storage/Users/currentUser/.backup";
141 static inline std::string_view PATH_MEDIALDATA_BACKUP_HOME = "/storage/media/local/files/.backup";
142 static inline std::string_view BACKUP_TOOL_LINK_DIR = "/data/backup";
143 static inline std::string_view BACKUP_TOOL_INCREMENTAL_RECEIVE_DIR = "/data/backup/incrementalreceived/";
144 static inline std::string_view BACKUP_TOOL_MANIFEST = "/manifest";
145 static inline std::string_view BACKUP_TOOL_INCREMENTAL = "/incremental";
146 static inline std::string BACKUP_DIR_PRE = "/data/storage/";
147 static inline std::string CONTEXT_ELS[] = {"el1", "el2"};
148 static inline std::string BACKUP_DIR_END = "/base/.backup/";
149 static inline std::string BUNDLE_BASE_DIR = "/data/storage/el2/base";
150 static inline std::string PATH_PUBLIC_HOME = "/storage/Users/currentUser/";
151 static inline std::string PATH_APP_DATA = "appdata";
152 
153 // 文管bundleName
154 static inline std::string BUNDLE_FILE_MANAGER = ".filemanager";
155 // 文管bundleNameSize
156 constexpr size_t FM_LEN = 27;
157 // 媒体库数据bundleName
158 static inline std::string BUNDLE_MEDIAL_DATA = "com.ohos.medialibrary.medialibrarydata";
159 // SA Ext
160 constexpr int BACKUP_DEFAULT_SA_ID = -1;
161 constexpr int BACKUP_SA_RELOAD_MAX = 2;
162 static inline std::string EXTENSION_BACKUP = "backup";
163 static inline std::string EXTENSION_RESTORE = "restore";
164 // 路径校验
165 static inline std::string PATH_ABSOLUTE = "../";
166 
167 // 多用户场景应用备份数据路径
GetSaBundleBackupDir(int32_t userId)168 static inline std::string GetSaBundleBackupDir(int32_t userId)
169 {
170     std::string str;
171     str.append("/data/app/el2/");
172     str.append(std::to_string(userId));
173     str.append("/base/.backup/");
174     return str;
175 }
176 
GetSaBundleBackupRootDir(int32_t userId)177 static inline std::string GetSaBundleBackupRootDir(int32_t userId)
178 {
179     std::string str;
180     str.append("/data/service/el2/");
181     str.append(std::to_string(userId));
182     str.append("/backup/backup_sa/");
183     return str;
184 }
185 
GetSaBundleBackupToolDir(int32_t userId)186 static inline std::string GetSaBundleBackupToolDir(int32_t userId)
187 {
188     std::string str;
189     str.append("/data/service/el2/");
190     str.append(std::to_string(userId));
191     str.append("/backup/backup_tool/");
192     return str;
193 }
194 
195 constexpr uint32_t APP_BASE_PATH_DEPTH = 4;
196 
197 // 备份恢复配置文件暂存路径
198 static inline std::string_view BACKUP_CONFIG_EXTENSION_PATH = "/data/storage/el2/base/cache/";
199 
200 // 应用备份恢复所需的索引文件
201 static inline std::string_view EXT_BACKUP_MANAGE = "manage.json";
202 
203 // 包管理元数据配置文件
204 static inline std::string_view BACKUP_CONFIG_JSON = "backup_config.json";
205 
206 // 简报文件名后缀
207 static inline std::string_view REPORT_FILE_EXT = "rp";
208 
209 // 空简报
210 static inline std::string BLANK_REPORT_NAME = "blankReport.rp";
211 
212 // 特殊版本信息
213 constexpr int DEFAULT_VERSION_CODE = 0;
214 constexpr char VERSION_NAME_SEPARATOR_CHAR = '-';
215 static inline std::string_view DEFAULT_VERSION_NAME = "0.0.0.0";
216 static inline std::string_view DEFAULT_VERSION_NAME_CLONE = "99.99.99.999";
217 static inline std::string_view DEFAULT_VERSION_NAME_CLONE_2 = "99.99.99.998";
218 static inline std::string_view DEFAULT_VERSION_NAME_CLONE_3 = "99.99.99.997";
219 static inline std::string_view DEFAULT_VERSION_NAME_PC = "99.99.99.996";
220 static inline std::string_view DEFAULT_VERSION_NAME_CLOUD = "99.99.99.995";
221 static inline std::vector<std::string_view> DEFAULT_VERSION_NAMES_VEC = {
222     DEFAULT_VERSION_NAME,         DEFAULT_VERSION_NAME_CLONE, DEFAULT_VERSION_NAME_CLONE_2,
223     DEFAULT_VERSION_NAME_CLONE_3, DEFAULT_VERSION_NAME_PC,    DEFAULT_VERSION_NAME_CLOUD,
224 };
225 static inline std::string BACKUP_VERSION = R"({"backupVersion" : "20.0"})";
226 
227 // 应用默认备份的目录,其均为相对根路径的路径。为避免模糊匹配,务必以斜线为结尾。
228 static inline std::array<std::string_view, PATHES_TO_BACKUP_SIZE> PATHES_TO_BACKUP = {
229     "data/storage/el1/database/",          "data/storage/el1/base/files/",
230     "data/storage/el1/base/preferences/",  "data/storage/el1/base/haps/*/database/",
231     "data/storage/el1/base/haps/*/files/", "data/storage/el1/base/haps/*/preferences/",
232     "data/storage/el2/database/",          "data/storage/el2/base/files/",
233     "data/storage/el2/base/preferences/",  "data/storage/el2/base/haps/*/database/",
234     "data/storage/el2/base/haps/*/files/", "data/storage/el2/base/haps/*/preferences/",
235     "data/storage/el2/distributedfiles/",
236 };
237 
238 // napi 层代码引用到的常量,对应js接口声明(@ohos.file.backup.d.ts)中的属性字段
239 static inline std::string BUNDLE_NAME = "bundleName";
240 static inline std::string URI = "uri";
241 static inline std::string FD = "fd";
242 static inline std::string MANIFEST_FD = "manifestFd";
243 static inline std::string LAST_INCREMENTAL_TIME = "lastIncrementalTime";
244 static inline std::string PARAMETERS = "parameters";
245 static inline std::string PRIORITY = "priority";
246 
247 // unicast
248 const std::string UNICAST_TYPE = "unicast";
249 
250 // 雷达打点引用到的常量
251 constexpr int32_t MS_1000 = 1000;
252 constexpr int32_t MAX_TIME_COST = 900000;
253 constexpr int32_t MAX_INEXCLUDE_SIZE = 25;
254 constexpr uint8_t INDEX = 3;
255 constexpr int INVALID_TIMEOUT_VALUE = -1;
256 static inline std::string FILE_BACKUP_RESTORE_EVENTS = "FILE_BACKUP_RESTORE_EVENTS";
257 static inline std::string FILE_BACKUP_RESTORE_STATISTIC = "FILE_BACKUP_RESTORE_STATISTIC";
258 } // namespace OHOS::FileManagement::Backup::BConstants
259 
260 #endif // OHOS_FILEMGMT_BACKUP_B_CONSTANTS_H
261