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 #include "mmi_log.h"
17 #include "parameters.h"
18 #include "input_scene_board_judgement.h"
19
20 namespace OHOS {
21 namespace MMI {
22 namespace {
23 constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, MMI_LOG_DOMAIN, "MMISceneBoardJudgement" };
24 } // namespace
25
IsSceneBoardEnabled()26 bool MMISceneBoardJudgement::IsSceneBoardEnabled()
27 {
28 static bool isSceneBoardEnabled = false;
29 static bool initialized = false;
30 if (!initialized) {
31 InitWithConfigFile("/etc/sceneboard.config", isSceneBoardEnabled);
32 initialized = true;
33 }
34 return isSceneBoardEnabled;
35 }
36
IsResampleEnabled()37 bool MMISceneBoardJudgement::IsResampleEnabled()
38 {
39 static bool isResampleEnabled = false;
40 static bool resampleInited = false;
41 if (!resampleInited) {
42 MMI_HILOGD("resample algorithm switch is not inited!");
43 isResampleEnabled =
44 (std::atoi((OHOS::system::GetParameter("persist.sys.input.resampleEnabled", "0")).c_str()) != 0);
45 MMI_HILOGD("isResampleEnabled is set to %{public}d", isResampleEnabled);
46 resampleInited = true;
47 }
48 return isResampleEnabled;
49 }
SafeGetLine(std::ifstream & configFile,std::string & line)50 std::ifstream& MMISceneBoardJudgement::SafeGetLine(std::ifstream& configFile, std::string& line)
51 {
52 std::getline(configFile, line);
53 if (line.size() && line[line.size() - 1] == '\r') {
54 line = line.substr(0, line.size() - 1);
55 }
56 return configFile;
57 }
58
InitWithConfigFile(const char * filePath,bool & enabled)59 void MMISceneBoardJudgement::InitWithConfigFile(const char* filePath, bool& enabled)
60 {
61 std::ifstream configFile(filePath);
62 std::string line;
63 if (configFile.is_open() && SafeGetLine(configFile, line) && line == "ENABLED") {
64 enabled = true;
65 }
66 configFile.close();
67 }
68 } // namespace MMI
69 } // namespace OHOS
70