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 
16 #include "form_resource_param.h"
17 
18 #include "fms_log_wrapper.h"
19 #include "parameter.h"
20 
21 namespace OHOS {
22 namespace AppExecFwk {
23 namespace {
24 const int32_t MAX_LEN = 128;
25 const std::string SYSTEM_LANGUAGE = "persist.global.locale";
26 const std::string SYSTEM_COLOR_MODE = "persist.ace.darkmode";
27 const std::string DEFAULT_LANGUAGE = "zh-Hans";
28 const std::string DEFAULT_COLOR_MODE_LIGHT = "light";
29 }
30 
GetSystemLanguage()31 std::string FormResourceParam::GetSystemLanguage()
32 {
33     std::string language = GetSystemParam(SYSTEM_LANGUAGE);
34     return language.empty() ? DEFAULT_LANGUAGE : language;
35 }
36 
GetSystemColorMode()37 std::string FormResourceParam::GetSystemColorMode()
38 {
39     std::string mode = GetSystemParam(SYSTEM_COLOR_MODE);
40     return mode.empty() ? DEFAULT_COLOR_MODE_LIGHT : mode;
41 }
42 
GetSystemParam(const std::string & key)43 std::string FormResourceParam::GetSystemParam(const std::string &key)
44 {
45     char value[MAX_LEN] = {0};
46     int32_t ret = GetParameter(key.c_str(), "", value, MAX_LEN);
47     if (ret <= 0) {
48         HILOG_ERROR("GetParameter:%{public}s failed", key.c_str());
49         return "";
50     }
51     return std::string(value);
52 }
53 } // AppExecFwk
54 } // OHOS
55