1 /*
2 * Copyright (c) 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 #include <string>
16 #include <vector>
17 #include "i18n_hilog.h"
18 #include "parameter.h"
19 #include "upgrade_utils.h"
20
21 namespace OHOS {
22 namespace Global {
23 namespace I18n {
24 const std::string CFG_PATH =
25 "/data/service/el1/public/update/param_service/install/system/etc/TIMEZONE/generic/current/";
26 const std::string LOCAL_VERSION_PATH = "/system/etc/TIMEZONE/generic/current/version.txt";
27 const std::string VERSION_FILE = "version.txt";
28 const std::string PUBKEY_PATH = "/system/etc/i18n/upgrade/hota_i18n_upgrade_v1.pem";
29 const std::string SAFE_PATH = "/data/service/el1/public/i18n/timezone/";
30 const std::string MOUNT_DIR = "/system/etc/tzdata_distro/";
31 const std::string COTA_PARAM_TIMEZONE_KEY = "persist.global.tz_override";
32
UpdateTimeZone()33 void UpdateTimeZone()
34 {
35 if (SetParameter(COTA_PARAM_TIMEZONE_KEY.c_str(), "false") != 0) {
36 HILOG_ERROR_I18N("UpdateTimeZone: Set COTA_PARAM_TIMEZONE_KEY false failed.");
37 }
38 std::vector<std::string> filesList;
39 if (!UpgradeUtils::CheckIfUpdateNecessary(CFG_PATH + VERSION_FILE, LOCAL_VERSION_PATH)) {
40 HILOG_ERROR_I18N("UpdateTimeZone: CheckIfUpdateNecessary error, no need to update.");
41 return;
42 }
43
44 if (!UpgradeUtils::CheckFileIntegrity(CFG_PATH, PUBKEY_PATH, filesList)) {
45 HILOG_ERROR_I18N("UpdateTimeZone: CheckFileIntegrity error, no need to update.");
46 return;
47 }
48
49 if (!UpgradeUtils::CopyDataFile(CFG_PATH, SAFE_PATH, filesList)) {
50 HILOG_ERROR_I18N("UpdateTimeZone: Copy data file failed.");
51 return;
52 }
53
54 if (!UpgradeUtils::FileDirMount(SAFE_PATH, MOUNT_DIR)) {
55 HILOG_ERROR_I18N("UpdateTimeZone: Mount error.");
56 return;
57 }
58 if (SetParameter(COTA_PARAM_TIMEZONE_KEY.c_str(), "true") != 0) {
59 HILOG_ERROR_I18N("UpdateTimeZone: Set COTA_PARAM_TIMEZONE_KEY true failed.");
60 }
61 HILOG_INFO_I18N("UpdateTimeZone: Update success.");
62 }
63 }
64 }
65 }
66
main(int argc,char * argv[])67 int main(int argc, char *argv[])
68 {
69 HILOG_INFO_I18N("hmos_timezone_mount: UpdateTimeZone start.");
70 OHOS::Global::I18n::UpdateTimeZone();
71 return 0;
72 }