1 /*
2  * Copyright (c) 2024-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 "brightness_config_parser.h"
17 
18 #include <unistd.h>
19 #include <json/json.h>
20 
21 #include "config_parser_base.h"
22 #include "display_log.h"
23 
24 namespace OHOS {
25 namespace DisplayPowerMgr {
26 namespace {
27 const std::string CONFIG_NAME = "brightness_config";
28 } // namespace
29 
30 using namespace OHOS::DisplayPowerMgr;
31 
ParseConfig(BrightnessConfig::Data & data)32 bool BrightnessConfigParser::ParseConfig(BrightnessConfig::Data& data)
33 {
34     DISPLAY_HILOGI(FEAT_BRIGHTNESS, "parse BrightnessConfigParser start!");
35     const Json::Value root = ConfigParserBase::Get().LoadConfigRoot(0, CONFIG_NAME);
36     if (root.isNull()) {
37         return false;
38     }
39     ConfigParserBase::Get().ParseScreenData(root, "displayModeData", data.displayModeMap, "displayMode");
40     ConfigParserBase::Get().ParseScreenData(root, "foldStatus", data.foldStatusModeMap, "foldStatus");
41     DISPLAY_HILOGI(FEAT_BRIGHTNESS, "parse BrightnessConfigParser over!");
42     return true;
43 }
44 
PrintConfig(const BrightnessConfig::Data & data)45 void BrightnessConfigParser::PrintConfig(const BrightnessConfig::Data& data)
46 {
47     std::string text = "";
48     text.append("screenData: ");
49     text.append(ConfigParserBase::Get().ScreenDataToString("displayModeData", data.displayModeMap, "displayMode"));
50     text.append(ConfigParserBase::Get().ScreenDataToString("foldStatus", data.foldStatusModeMap, "foldStatus"));
51     DISPLAY_HILOGI(FEAT_BRIGHTNESS, "%{public}s", text.c_str());
52 }
53 } // namespace DisplayPowerMgr
54 } // namespace OHOS
55