• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-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 
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     INSTALLING = 1,
41     START,
42     RUNNING,
43     FINISH,
44 };
45 
46 enum EntryKey {
47     SUPER_LONG_PATH = 0,
48     SUPER_LONG_LINK_PATH,
49     SUPER_LONG_SIZE,
50 };
51 
52 constexpr int SPAN_USERID_UID = 20000000;
53 constexpr int SYSTEM_UID = 0;
54 constexpr int XTS_UID = 1;
55 constexpr int DEFAULT_USER_ID = 100;
56 constexpr int BACKUP_UID = 1089;
57 constexpr int EXTENSION_THREAD_POOL_COUNT = 1;
58 constexpr int BACKUP_LOADSA_TIMEOUT_MS = 4000;
59 
60 constexpr int DECIMAL_BASE = 10; // 十进制基数
61 
62 constexpr int HEADER_SIZE = 512;         // 打包文件头部Header结构体大小
63 constexpr int BLOCK_SIZE = 512;          // 打包文件数据段尾部补充的全零字节块上限大小
64 constexpr int BLOCK_PADDING_SIZE = 1024; // 打包文件尾部追加的全零字节块大小
65 constexpr off_t BIG_FILE_BOUNDARY = 1024 * 1024 * 1024; // 大文件边界
66 constexpr unsigned long BIG_FILE_NAME_SIZE = 16;        // 大文件名长度(hash处理)
67 
68 // 打包文件头部Header结构体各字段数组/字符串大小。
69 constexpr int PATHNAME_MAX_SIZE = 100;
70 constexpr int MODE_MAX_SIZE = 8;
71 constexpr int UGID_MAX_SIZE = 8;
72 constexpr int FILESIZE_MAX_SIZE = 12;
73 constexpr int TIME_MAX_SIZE = 12;
74 constexpr int CHKSUM_MAX_SIZE = 8;
75 constexpr int LINKNAME_MAX_SIZE = 100;
76 constexpr int MAGIC_SIZE = 6;
77 constexpr int VERSION_SIZE = 2;
78 constexpr int UGNAME_MAX_SIZE = 32;
79 constexpr int DEV_MAX_SIZE = 8;
80 constexpr int PREFIX_SIZE = 155;
81 constexpr int PADDING_SIZE = 12;
82 
83 // 读取backup.para字段值的最大长度
84 constexpr uint32_t BACKUP_PARA_VALUE_MAX = 5;
85 
86 // SA THREAD_POOL 最大线程数
87 constexpr int SA_THREAD_POOL_COUNT = 1;
88 // extension 最大启动数
89 constexpr int EXT_CONNECT_MAX_COUNT = 3;
90 // SA 启动 extension 等待连接最大时间
91 constexpr int EXT_CONNECT_MAX_TIME = 15000;
92 
93 // 打包文件头部Header结构体fileSize字段最大值。
94 constexpr off_t FILESIZE_MAX = 077777777777;
95 
96 // 打包文件头部Header结构体typeFlag字段值。
97 constexpr char TYPEFLAG_REGULAR_FILE = '0';
98 constexpr char TYPEFLAG_SYMBOLIC_LINK = '2';
99 constexpr char TYPEFLAG_DIRECTORY = '5';
100 constexpr char TYPEFLAG_EXTENDED = 'x';
101 
102 // 打包文件扩展数据段字段值。
103 static inline std::string ENTRY_NAME_LINKPATH = "linkpath";
104 static inline std::string ENTRY_NAME_PATH = "path";
105 static inline std::string ENTRY_NAME_SIZE = "size";
106 
107 // backup.para内配置项的名称,改配置项值为true时可在不更新hap包的情况下,可以读取包管理元数据配置文件的内容
108 static inline std::string BACKUP_DEBUG_OVERRIDE_EXTENSION_CONFIG_KEY = "backup.debug.overrideExtensionConfig";
109 
110 // 应用备份数据暂存路径
111 static inline std::string_view SA_BUNDLE_BACKUP_BACKUP = "/backup/";
112 static inline std::string_view SA_BUNDLE_BACKUP_RESTORE = "/restore/";
113 static inline std::string_view SA_BUNDLE_BACKUP_TMP_DIR = "/tmp/";
114 static inline std::string_view BACKUP_TOOL_RECEIVE_DIR = "/data/backup/received/";
115 static inline std::string_view PATH_BUNDLE_BACKUP_HOME = "/data/storage/el2/backup";
116 static inline std::string_view BACKUP_TOOL_LINK_DIR = "/data/backup";
117 static inline std::string_view BACKUP_TOOL_INSTALL_DIR = "/data/backup/install/";
118 
119 // 多用户场景应用备份数据路径
GetSaBundleBackupDir(int32_t userId)120 static inline std::string GetSaBundleBackupDir(int32_t userId)
121 {
122     std::string str;
123     str.append("/data/service/el2/");
124     str.append(std::to_string(userId));
125     str.append("/backup/bundles/");
126     return str;
127 }
128 
GetSaBundleBackupRootDir(int32_t userId)129 static inline std::string GetSaBundleBackupRootDir(int32_t userId)
130 {
131     std::string str;
132     str.append("/data/service/el2/");
133     str.append(std::to_string(userId));
134     str.append("/backup/backup_sa/");
135     return str;
136 }
137 
GetSaBundleBackupToolDir(int32_t userId)138 static inline std::string GetSaBundleBackupToolDir(int32_t userId)
139 {
140     std::string str;
141     str.append("/data/service/el2/");
142     str.append(std::to_string(userId));
143     str.append("/backup/backup_tool/");
144     return str;
145 }
146 
147 // 备份恢复配置文件暂存路径
148 static inline std::string_view BACKUP_CONFIG_EXTENSION_PATH = "/data/storage/el2/base/temp/";
149 
150 // 应用备份恢复所需的索引文件
151 static inline std::string_view EXT_BACKUP_MANAGE = "manage.json";
152 
153 // 包管理元数据配置文件
154 static inline std::string_view BACKUP_CONFIG_JSON = "backup_config.json";
155 
156 // 恢复应用安装包URL判断
157 static inline std::string_view RESTORE_INSTALL_PATH = "/data/storage/el2/restore/bundle.hap";
158 
159 // 双生单场景默认的版本信息
160 constexpr int DEFAULT_VERSION_CODE = 0;
161 static inline std::string_view DEFAULT_VERSION_NAME = "0.0.0.0";
162 
163 // 应用默认备份的目录,其均为相对根路径的路径。为避免模糊匹配,务必以斜线为结尾。
164 static inline std::array<std::string_view, 6> PATHES_TO_BACKUP = {
165     "data/storage/el2/database/",
166     "data/storage/el2/base/files/",
167     "data/storage/el2/base/preferences/",
168     "data/storage/el2/base/haps/*/database/",
169     "data/storage/el2/base/haps/*/files/",
170     "data/storage/el2/base/haps/*/preferences/",
171 };
172 } // namespace OHOS::FileManagement::Backup::BConstants
173 
174 #endif // OHOS_FILEMGMT_BACKUP_B_CONSTANTS_H
175