1 /*
2  * Copyright (c) 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 CONSTANT_H
17 #define CONSTANT_H
18 
19 #include <stdint.h>
20 #include <string>
21 #include <vector>
22 
23 #include "file_utils.h"
24 
25 namespace OHOS {
26 namespace UpdateEngine {
27 namespace Constant {
28 constexpr int32_t ONE_DAY_HOUR = 24;
29 constexpr int32_t ONE_HOUR_MINUTES = 60;
30 constexpr int32_t ONE_MINUTE_SECONDS = 60;
31 constexpr int32_t FIVE_MINUTES_SECONDS = 5 * Constant::ONE_MINUTE_SECONDS;
32 constexpr int32_t MILLESECONDS = 1000;
33 
34 static const std::string DUPDATE_ENGINE_CONFIG_PATH = "/system/etc/update/dupdate_config.json";
35 
36 // 存放升级引擎数据库、缓存等文件的加密路径
37 static const std::string UPDATE_ENCRYPTED_ROOT_PATH = "/data/service/el1/public/update";
38 static const std::string DUPDATE_ENGINE_ENCRYPTED_ROOT_PATH = UPDATE_ENCRYPTED_ROOT_PATH + "/dupdate_engine";
39 static const std::string DATABASES_ROOT_PATH = UPDATE_ENCRYPTED_ROOT_PATH + "/update_service" + "/databases";
40 static const std::string PREFERENCES_ROOT_PATH = DUPDATE_ENGINE_ENCRYPTED_ROOT_PATH + "/preferences";
41 static const std::string FILES_ROOT_PATH = DUPDATE_ENGINE_ENCRYPTED_ROOT_PATH + "/files";
42 
43 // 存放ota升级包的非加密路径
44 static const std::string UPDATE_PACKAGE_ROOT_PATH = "/data/update";
45 static const std::string DUPDATE_ENGINE_PACKAGE_ROOT_PATH = UPDATE_PACKAGE_ROOT_PATH + "/ota_package";
46 
47 static const std::string DUE_INIT_FLAG = "due_init_flag"; // DUE初始启动标记
48 static const std::string PROCESS_RESTART_REASON = "process_restart_reason"; // 进程重启原因
49 } // namespace Constant
50 
51 enum class CommonEventType {
52     AUTO_UPGRADE = 0,
53     NET_CHANGED,
54     TIME_CHANGED,
55     TIME_ZONE_CHANGED,
56     BOOT_COMPLETE,
57     PROCESS_INIT,
58     NIGHT_UPGRADE,
59     SCREEN_OFF,
60     UPGRADE_REMIND,
61 };
62 
63 static const std::vector<DirInfo> BASE_DIR_INFOS {
64     {Constant::UPDATE_ENCRYPTED_ROOT_PATH, 0751, false},
65     {Constant::DUPDATE_ENGINE_ENCRYPTED_ROOT_PATH, 0700, false},
66     {Constant::DATABASES_ROOT_PATH, 0700, false},
67     {Constant::PREFERENCES_ROOT_PATH, 0700, false},
68     {Constant::FILES_ROOT_PATH, 0700, true},
69     {Constant::UPDATE_PACKAGE_ROOT_PATH, 0770, false},
70     {Constant::DUPDATE_ENGINE_PACKAGE_ROOT_PATH, 0770, true}
71 };
72 } // namespace UpdateEngine
73 } // namespace OHOS
74 #endif // CONSTANT_H