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
32 enum class ExtensionAction {
33 INVALID = 0,
34 BACKUP = 1,
35 RESTORE = 2,
36 };
37
38 enum ServiceSchedAction {
39 WAIT = 0,
40 START = 1,
41 RUNNING = 2,
42 FINISH = 3,
43 };
44
45 constexpr int SPAN_USERID_UID = 20000000;
46 constexpr int SYSTEM_UID = 0;
47 constexpr int XTS_UID = 1;
48 constexpr int DEFAULT_USER_ID = 100;
49 constexpr int BACKUP_UID = 1089;
50 constexpr int EXTENSION_THREAD_POOL_COUNT = 1;
51 constexpr int BACKUP_LOADSA_TIMEOUT_MS = 4000;
52
53 constexpr int DECIMAL_BASE = 10; // 十进制基数
54
55 constexpr off_t BIG_FILE_BOUNDARY = 2 * 1024 * 1024; // 大文件边界
56 constexpr unsigned long BIG_FILE_NAME_SIZE = 16; // 大文件名长度(hash处理)
57
58 constexpr int PATHES_TO_BACKUP_SIZE = 13; // 应用默认备份的目录个数
59 constexpr uint32_t BACKUP_PARA_VALUE_MAX = 5; // 读取backup.para字段值的最大长度
60 constexpr int SA_THREAD_POOL_COUNT = 1; // SA THREAD_POOL 最大线程数
61 constexpr int EXT_CONNECT_MAX_COUNT = 3; // extension 最大启动数
62 constexpr int EXT_CONNECT_MAX_TIME = 15000; // SA 启动 extension 等待连接最大时间
63
64 constexpr int IPC_MAX_WAIT_TIME = 3000; // IPC通讯最大等待时间(s)
65 constexpr char FILE_SEPARATOR_CHAR = '/';
66 constexpr int MAX_PARCELABLE_VECTOR_NUM = 10000;
67
68 constexpr int DEFAULT_VFS_CACHE_PRESSURE = 100; // 默认内存回收参数
69 constexpr int BACKUP_VFS_CACHE_PRESSURE = 10000; // 备份过程修改参数
70
71 // backup.para内配置项的名称,该配置项值为true时可在不更新hap包的情况下,可以读取包管理元数据配置文件的内容
72 static inline std::string BACKUP_DEBUG_OVERRIDE_EXTENSION_CONFIG_KEY = "backup.debug.overrideExtensionConfig";
73
74 // backup.para内配置项的名称,该配置项AccountConfig为true时存在时,可以按照配置的AccountNumber备份恢复
75 static inline std::string BACKUP_DEBUG_OVERRIDE_ACCOUNT_CONFIG_KEY = "backup.debug.overrideAccountConfig";
76 static inline std::string BACKUP_DEBUG_OVERRIDE_ACCOUNT_NUMBER_KEY = "backup.debug.overrideAccountNumber";
77
78 // 增量备份相关处理目录
79 static const std::string BACKUP_PATH_PREFIX = "/data/service/el2/";
80 static const std::string BACKUP_PATH_SURFFIX = "/backup/backup_sa/";
81 static const std::string BACKUP_INCEXC_SYMBOL = "incExc_";
82 static const std::string BACKUP_STAT_SYMBOL = "stat_";
83 static const std::string BACKUP_INCLUDE = "INCLUDES";
84 static const std::string BACKUP_EXCLUDE = "EXCLUDES";
85
86 // backup.para内配置项的名称,该配置项为true时备份恢复支持Release接口调用
87 static inline std::string BACKUP_OVERRIDE_BACKUP_SA_RELEASE_KEY = "backup.overrideBackupSARelease";
88
89 // backup.para内配置项的名称,该配置项为true时备份恢复支持增量恢复
90 static inline std::string BACKUP_OVERRIDE_INCREMENTAL_KEY = "backup.overrideIncrementalRestore";
91
92 // 应用备份数据暂存路径
93 static inline std::string_view SA_BUNDLE_BACKUP_BACKUP = "/backup/";
94 static inline std::string_view SA_BUNDLE_BACKUP_RESTORE = "/restore/";
95 static inline std::string_view SA_BUNDLE_BACKUP_TMP_DIR = "/tmp/";
96 static inline std::string_view BACKUP_TOOL_RECEIVE_DIR = "/data/backup/received/";
97 static inline std::string_view PATH_BUNDLE_BACKUP_HOME_EL1 = "/data/storage/el1/backup";
98 static inline std::string_view PATH_BUNDLE_BACKUP_HOME = "/data/storage/el2/backup";
99 static inline std::string_view BACKUP_TOOL_LINK_DIR = "/data/backup";
100 static inline std::string_view BACKUP_TOOL_INCREMENTAL_RECEIVE_DIR = "/data/backup/incrementalreceived/";
101 static inline std::string_view BACKUP_TOOL_MANIFEST = "/manifest";
102 static inline std::string_view BACKUP_TOOL_INCREMENTAL = "/incremental";
103
104 // 多用户场景应用备份数据路径
GetSaBundleBackupDir(int32_t userId)105 static inline std::string GetSaBundleBackupDir(int32_t userId)
106 {
107 std::string str;
108 str.append("/data/service/el2/");
109 str.append(std::to_string(userId));
110 str.append("/backup/bundles/");
111 return str;
112 }
113
GetSaBundleBackupRootDir(int32_t userId)114 static inline std::string GetSaBundleBackupRootDir(int32_t userId)
115 {
116 std::string str;
117 str.append("/data/service/el2/");
118 str.append(std::to_string(userId));
119 str.append("/backup/backup_sa/");
120 return str;
121 }
122
GetSaBundleBackupToolDir(int32_t userId)123 static inline std::string GetSaBundleBackupToolDir(int32_t userId)
124 {
125 std::string str;
126 str.append("/data/service/el2/");
127 str.append(std::to_string(userId));
128 str.append("/backup/backup_tool/");
129 return str;
130 }
131
132 // 备份恢复配置文件暂存路径
133 static inline std::string_view BACKUP_CONFIG_EXTENSION_PATH = "/data/storage/el2/base/cache/";
134
135 // 应用备份恢复所需的索引文件
136 static inline std::string_view EXT_BACKUP_MANAGE = "manage.json";
137
138 // 包管理元数据配置文件
139 static inline std::string_view BACKUP_CONFIG_JSON = "backup_config.json";
140
141 // 简报文件名后缀
142 static inline std::string_view REPORT_FILE_EXT = "rp";
143
144 // 特殊版本信息
145 constexpr int DEFAULT_VERSION_CODE = 0;
146 static inline std::string_view DEFAULT_VERSION_NAME = "0.0.0.0";
147 static inline std::string_view DEFAULT_VERSION_NAME_CLONE = "99.99.99.999";
148 static inline std::string_view DEFAULT_VERSION_NAME_CLONE_2 = "99.99.99.998";
149 static inline std::string_view DEFAULT_VERSION_NAME_CLONE_3 = "99.99.99.997";
150 static inline std::string_view DEFAULT_VERSION_NAME_PC = "99.99.99.996";
151 static inline std::string_view DEFAULT_VERSION_NAME_CLOUD = "99.99.99.995";
152 static inline std::vector<std::string_view> DEFAULT_VERSION_NAMES_VEC = {
153 DEFAULT_VERSION_NAME, DEFAULT_VERSION_NAME_CLONE, DEFAULT_VERSION_NAME_CLONE_2,
154 DEFAULT_VERSION_NAME_CLONE_3, DEFAULT_VERSION_NAME_PC, DEFAULT_VERSION_NAME_CLOUD,
155 };
156
157 // 应用默认备份的目录,其均为相对根路径的路径。为避免模糊匹配,务必以斜线为结尾。
158 static inline std::array<std::string_view, PATHES_TO_BACKUP_SIZE> PATHES_TO_BACKUP = {
159 "data/storage/el1/database/", "data/storage/el1/base/files/",
160 "data/storage/el1/base/preferences/", "data/storage/el1/base/haps/*/database/",
161 "data/storage/el1/base/haps/*/files/", "data/storage/el1/base/haps/*/preferences/",
162 "data/storage/el2/database/", "data/storage/el2/base/files/",
163 "data/storage/el2/base/preferences/", "data/storage/el2/base/haps/*/database/",
164 "data/storage/el2/base/haps/*/files/", "data/storage/el2/base/haps/*/preferences/",
165 "data/storage/el2/distributedfiles/",
166 };
167 } // namespace OHOS::FileManagement::Backup::BConstants
168
169 #endif // OHOS_FILEMGMT_BACKUP_B_CONSTANTS_H
170