1 /*
2 * Copyright (c) 2023-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 "mmi_log.h"
17 #include "parameters.h"
18 #include "input_scene_board_judgement.h"
19
20 #undef MMI_LOG_TAG
21 #define MMI_LOG_TAG "MMISceneBoardJudgement"
22
23 namespace OHOS {
24 namespace MMI {
IsSceneBoardEnabled()25 bool MMISceneBoardJudgement::IsSceneBoardEnabled()
26 {
27 static bool isSceneBoardEnabled = false;
28 static bool initialized = false;
29 if (!initialized) {
30 InitWithConfigFile("/etc/sceneboard.config", isSceneBoardEnabled);
31 initialized = true;
32 }
33 return isSceneBoardEnabled;
34 }
35
IsResampleEnabled()36 bool MMISceneBoardJudgement::IsResampleEnabled()
37 {
38 static bool isResampleEnabled = false;
39 static bool resampleInited = false;
40 if (!resampleInited) {
41 MMI_HILOGD("Resample algorithm switch is not inited");
42 isResampleEnabled =
43 (std::atoi((OHOS::system::GetParameter("persist.sys.input.resampleEnabled", "0")).c_str()) != 0);
44 MMI_HILOGD("isResampleEnabled is set to %{public}d", isResampleEnabled);
45 resampleInited = true;
46 }
47 return isResampleEnabled;
48 }
SafeGetLine(std::ifstream & configFile,std::string & line)49 std::ifstream& MMISceneBoardJudgement::SafeGetLine(std::ifstream& configFile, std::string& line)
50 {
51 std::getline(configFile, line);
52 if (!line.empty() && (line.back() == '\r')) {
53 line.pop_back();
54 }
55 return configFile;
56 }
57
InitWithConfigFile(const char * filePath,bool & enabled)58 void MMISceneBoardJudgement::InitWithConfigFile(const char* filePath, bool& enabled)
59 {
60 char checkPath[PATH_MAX] = { 0 };
61 if (realpath(filePath, checkPath) == nullptr) {
62 MMI_HILOGE("canonicalize failed. path:%{private}s", filePath);
63 return;
64 }
65 std::ifstream configFile(checkPath);
66 std::string line;
67 if (!(configFile.is_open() && SafeGetLine(configFile, line) && line == "DISABLED")) {
68 enabled = true;
69 }
70 configFile.close();
71 }
72 } // namespace MMI
73 } // namespace OHOS
74