mirror of
https://gitee.com/openharmony/global_i18n
synced 2024-11-23 23:21:42 +00:00
commit
66ec57972c
@ -64,7 +64,7 @@ private:
|
||||
static const char *CITY_DISPLAYNAME_PATH;
|
||||
static const char *BASE_DEVICE_CITY_DISPLAYNAME_PATH;
|
||||
static const char *DISTRO_DEVICE_CITY_DISPLAYNAME_PATH;
|
||||
static const char *DEVICE_CITY_DISPLAYNAME_PATH;
|
||||
static const char *DISTRO_ROOT_DISPLAYNAME_PATH;
|
||||
static const char *SUPPORTED_LOCALES_PATH;
|
||||
static const char *TIMEZONE_ROOT_TAG;
|
||||
static const char *TIMEZONE_SECOND_ROOT_TAG;
|
||||
|
@ -59,7 +59,7 @@ const char *I18nTimeZone::DEFAULT_LOCALE = "root";
|
||||
const char *I18nTimeZone::CITY_DISPLAYNAME_PATH = "/system/usr/ohos_timezone/ohos_city_dispname/";
|
||||
const char *I18nTimeZone::BASE_DEVICE_CITY_DISPLAYNAME_PATH = "/system/usr/ohos_timezone/device_city_dispname/";
|
||||
const char *I18nTimeZone::DISTRO_DEVICE_CITY_DISPLAYNAME_PATH = "/system/etc/tzdata_distro/device_city_dispname/";
|
||||
const char *I18nTimeZone::DEVICE_CITY_DISPLAYNAME_PATH = GetDeviceCityDisplayNamePath();
|
||||
const char *I18nTimeZone::DISTRO_ROOT_DISPLAYNAME_PATH = "/system/etc/tzdata_distro/device_city_dispname/root.xml";
|
||||
|
||||
const char *I18nTimeZone::TIMEZONE_ROOT_TAG = "timezones";
|
||||
const char *I18nTimeZone::TIMEZONE_SECOND_ROOT_TAG = "timezone";
|
||||
@ -914,8 +914,9 @@ std::string I18nTimeZone::FindCityDisplayNameFromXml(std::string &cityID, std::s
|
||||
|
||||
std::string I18nTimeZone::GetCityDisplayNameXmlPath(const std::string &locale)
|
||||
{
|
||||
if (DEVICE_CITY_DISPLAYNAME_PATH != nullptr) {
|
||||
return DEVICE_CITY_DISPLAYNAME_PATH + locale + ".xml";
|
||||
const char *deviceCityDisplayNamePath = GetDeviceCityDisplayNamePath();
|
||||
if (deviceCityDisplayNamePath != nullptr) {
|
||||
return deviceCityDisplayNamePath + locale + ".xml";
|
||||
} else {
|
||||
return CITY_DISPLAYNAME_PATH + locale + ".xml";
|
||||
}
|
||||
@ -925,12 +926,7 @@ std::map<std::string, std::string> I18nTimeZone::FindCityDisplayNameMap(std::str
|
||||
{
|
||||
xmlKeepBlanksDefault(0);
|
||||
std::map<std::string, std::string> resultMap;
|
||||
std::string xmlPath;
|
||||
if (DEVICE_CITY_DISPLAYNAME_PATH != nullptr) {
|
||||
xmlPath = DEVICE_CITY_DISPLAYNAME_PATH + locale + ".xml";
|
||||
} else {
|
||||
xmlPath = CITY_DISPLAYNAME_PATH + locale + ".xml";
|
||||
}
|
||||
std::string xmlPath = GetCityDisplayNameXmlPath(locale);
|
||||
xmlDocPtr doc = xmlParseFile(xmlPath.c_str());
|
||||
if (!doc) {
|
||||
HILOG_ERROR_I18N("FindCityDisplayNameMap: can't parse city displayname file %{public}s", xmlPath.c_str());
|
||||
@ -977,10 +973,8 @@ bool I18nTimeZone::GetSupportedLocales()
|
||||
using std::filesystem::directory_iterator;
|
||||
|
||||
struct stat s;
|
||||
std::string displayNamePath;
|
||||
if (DEVICE_CITY_DISPLAYNAME_PATH != nullptr) {
|
||||
displayNamePath = DEVICE_CITY_DISPLAYNAME_PATH;
|
||||
} else {
|
||||
std::string displayNamePath = GetDeviceCityDisplayNamePath();
|
||||
if (displayNamePath.length() == 0) {
|
||||
displayNamePath = CITY_DISPLAYNAME_PATH;
|
||||
}
|
||||
for (const auto &dirEntry : directory_iterator{displayNamePath}) {
|
||||
@ -1364,7 +1358,7 @@ bool I18nTimeZone::ParamExceedScope(const int x, const int y, int fixedX, int fi
|
||||
const char *I18nTimeZone::GetDeviceCityDisplayNamePath()
|
||||
{
|
||||
struct stat s;
|
||||
if (stat(DISTRO_DEVICE_CITY_DISPLAYNAME_PATH, &s) == 0) {
|
||||
if (stat(DISTRO_ROOT_DISPLAYNAME_PATH, &s) == 0) {
|
||||
return DISTRO_DEVICE_CITY_DISPLAYNAME_PATH;
|
||||
} else if (stat(BASE_DEVICE_CITY_DISPLAYNAME_PATH, &s) == 0) {
|
||||
return BASE_DEVICE_CITY_DISPLAYNAME_PATH;
|
||||
|
@ -28,7 +28,7 @@ using namespace icu;
|
||||
using namespace std;
|
||||
|
||||
const char *ZoneUtil::COUNTRY_ZONE_DATA_PATH = "/system/usr/ohos_timezone/tzlookup.xml";
|
||||
const char *ZoneUtil::DISTRO_COUNTRY_ZONE_DATA_PATH = "/system/etc/tzdata_distro/tzlookup.xml";
|
||||
const char *ZoneUtil::DISTRO_COUNTRY_ZONE_DATA_PATH = "/system/etc/tzdata_distro/hos/tzlookup.xml";
|
||||
const char *ZoneUtil::DEFAULT_TIMEZONE = "GMT";
|
||||
const char *ZoneUtil::TIMEZONES_TAG = "timezones";
|
||||
const char *ZoneUtil::ID_TAG = "id";
|
||||
|
@ -4,7 +4,8 @@
|
||||
"name": "boot",
|
||||
"cmds": [
|
||||
"mkdir /data/service/el1/public/i18n/ 0744 i18n_service i18n_service",
|
||||
"mkdir /data/service/el1/public/i18n/libphonenumber/ 0744 i18n_service i18n_service",
|
||||
"mkdir /data/service/el1/public/i18n/libphonenumber/ 0755 i18n_service i18n_service",
|
||||
"mkdir /data/service/el1/public/i18n/timezone/ 0755 i18n_service i18n_service",
|
||||
"exec /system/bin/hmos_cust_timezone_mount",
|
||||
"exec /system/bin/hmos_cust_libphonenumber_mount"
|
||||
]
|
||||
|
@ -12,6 +12,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include <filesystem>
|
||||
#include <string>
|
||||
#include <sys/mount.h>
|
||||
#include "i18n_hilog.h"
|
||||
@ -32,24 +33,26 @@ const std::string SUB_TYPE = "generic";
|
||||
const std::string CFG_PATH =
|
||||
"/data/service/el1/public/update/param_service/install/system/etc/TIMEZONE/generic/current/";
|
||||
const std::string LOCALE_PATH = "/system/etc/TIMEZONE/generic/current/";
|
||||
const std::string SAFE_PATH = "/data/service/el1/public/i18n/timezone/";
|
||||
const std::string PUBKEY_PATH = "/system/etc/LIBPHONENUMBER/generic/";
|
||||
const std::string PUBKEY_NAME = "hota_i18n_upgrade_v1.pem";
|
||||
const std::vector<std::string> DATA_FILES = {"tzdata", "device_timezones.xml", "version.txt",
|
||||
"distro_version", "tzlookup.xml", "device_city_dispname/bo_CN.xml", "device_city_dispname/root.xml",
|
||||
"device_city_dispname/ug.xml", "device_city_dispname/zh_Hans.xml", "device_city_dispname/zh_HK.xml",
|
||||
"device_city_dispname/zh_TW.xml", "device_city_dispname/zz_ZX.xml", "icu/icu_tzdata.dat",
|
||||
"telephonylookup.xml"};
|
||||
"telephonylookup.xml", "icu/metaZones.res", "icu/timezoneTypes.res", "icu/windowsZones.res",
|
||||
"icu/zoneinfo64.res", "hos/tzlookup.xml"};
|
||||
|
||||
bool Mount()
|
||||
{
|
||||
if (!IsDirExist(CUST_GLOBAL_CARRIER_DIR.c_str()) ||
|
||||
!IsDirExist(CFG_PATH.c_str())) {
|
||||
!IsDirExist(SAFE_PATH.c_str())) {
|
||||
HILOG_ERROR_I18N("Mount: CUST_GLOBAL_CARRIER_DIR or CFG_PATH not exist");
|
||||
return false;
|
||||
}
|
||||
|
||||
int ret = 0;
|
||||
std::string cotaOpkeyVersionDir = CFG_PATH;
|
||||
std::string cotaOpkeyVersionDir = SAFE_PATH;
|
||||
std::string custOpkeyVersionDir = CUST_GLOBAL_CARRIER_DIR;
|
||||
|
||||
if (mount(cotaOpkeyVersionDir.c_str(), custOpkeyVersionDir.c_str(), nullptr, MS_BIND, nullptr) != 0) {
|
||||
@ -62,6 +65,78 @@ bool Mount()
|
||||
return true;
|
||||
}
|
||||
|
||||
void ensureDirectoryExists(const std::filesystem::path& dir_path)
|
||||
{
|
||||
std::error_code ec;
|
||||
if (!std::filesystem::exists(dir_path)) {
|
||||
HILOG_ERROR_I18N("Directory does not exist: %{public}s", dir_path.c_str());
|
||||
std::filesystem::create_directories(dir_path, ec);
|
||||
if (ec) {
|
||||
HILOG_ERROR_I18N("Failed to create directory: %{public}s, Error: %{public}s", dir_path.c_str(),
|
||||
ec.message().c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void clearPath(const std::filesystem::path& dir_path)
|
||||
{
|
||||
std::error_code ec;
|
||||
for (const auto& entry : std::filesystem::directory_iterator(dir_path)) {
|
||||
std::filesystem::remove_all(entry.path(), ec);
|
||||
if (ec) {
|
||||
HILOG_ERROR_I18N("clearPath: Error removing file: %{public}s, Error: %{public}s", entry.path().c_str(),
|
||||
ec.message().c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool copySingleFile(const std::filesystem::path& src_path, const std::filesystem::path& dst_path)
|
||||
{
|
||||
if (!FileExist(src_path.string())) {
|
||||
HILOG_ERROR_I18N("copySingleFile: Source file does not exist: %{public}s", src_path.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
ensureDirectoryExists(dst_path.parent_path());
|
||||
HILOG_INFO_I18N("copySingleFile: copy file: %{public}s, %{public}s", src_path.c_str(), dst_path.c_str());
|
||||
if (!FileCopy(src_path.string(), dst_path.string())) {
|
||||
HILOG_ERROR_I18N("copySingleFile: Failed to copy file: %{public}s", src_path.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CopyDataFile()
|
||||
{
|
||||
HILOG_INFO_I18N("TimeZone CopyDataFile start");
|
||||
if (!IsDirExist(SAFE_PATH.c_str())) {
|
||||
HILOG_ERROR_I18N("TimeZone CopyDataFile: SAFE_PATH does not exist");
|
||||
return false;
|
||||
}
|
||||
|
||||
std::filesystem::path safe_dir(SAFE_PATH);
|
||||
clearPath(safe_dir);
|
||||
|
||||
bool copySuccess = true;
|
||||
for (const auto& file : DATA_FILES) {
|
||||
std::filesystem::path src_path = std::filesystem::path(CFG_PATH) / file;
|
||||
std::filesystem::path dst_path = std::filesystem::path(SAFE_PATH) / file;
|
||||
if (!copySingleFile(src_path, dst_path)) {
|
||||
HILOG_ERROR_I18N("CopyDataFile: Copy failed for %{public}s", file.c_str());
|
||||
copySuccess = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!copySuccess) {
|
||||
HILOG_ERROR_I18N("CopyDataFile error, clearing the safe directory...");
|
||||
clearPath(safe_dir);
|
||||
}
|
||||
|
||||
return copySuccess;
|
||||
}
|
||||
|
||||
bool CheckIfUpdateNecessary()
|
||||
{
|
||||
std::string versionUpdate = SignatureVerifier::LoadFileVersion(CFG_PATH + VERSION_FILE);
|
||||
@ -107,6 +182,10 @@ bool CheckFileIntegrity()
|
||||
|
||||
void UpdateTimeZone()
|
||||
{
|
||||
if (!Mount()) {
|
||||
HILOG_INFO_I18N("UpdateTimeZone: mount error");
|
||||
return;
|
||||
}
|
||||
if (!CheckIfUpdateNecessary()) {
|
||||
HILOG_INFO_I18N("UpdateTimeZone: CheckIfUpdateNecessary error, no need to update");
|
||||
return;
|
||||
@ -115,8 +194,8 @@ void UpdateTimeZone()
|
||||
HILOG_INFO_I18N("UpdateTimeZone: CheckFileIntegrity error, no need to update");
|
||||
return;
|
||||
}
|
||||
if (!Mount()) {
|
||||
HILOG_INFO_I18N("UpdateTimeZone: mount error");
|
||||
if (!CopyDataFile()) {
|
||||
HILOG_INFO_I18N("UpdateTimeZone: CopyDataFile error");
|
||||
return;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user