1 /* 2 * Copyright (c) 2021 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 "ams_configuration_parameter.h" 17 #include "hilog_wrapper.h" 18 19 namespace OHOS { 20 namespace AAFwk { 21 using json = nlohmann::json; 22 Parse()23void AmsConfigurationParameter::Parse() 24 { 25 auto ref = LoadAmsConfiguration(AmsConfig::AMS_CONFIG_FILE_PATH); 26 HILOG_INFO("load config ref : %{public}d", ref); 27 } 28 GetStartLauncherState() const29bool AmsConfigurationParameter::GetStartLauncherState() const 30 { 31 return canStartLauncher; 32 } 33 GetStatusBarState() const34bool AmsConfigurationParameter::GetStatusBarState() const 35 { 36 return canStartUiStatusBar; 37 } 38 GetNavigationBarState() const39bool AmsConfigurationParameter::GetNavigationBarState() const 40 { 41 return canStartUiNavigationBar; 42 } 43 NonConfigFile() const44bool AmsConfigurationParameter::NonConfigFile() const 45 { 46 return nonConfigFile; 47 } 48 LoadAmsConfiguration(const std::string & filePath)49int AmsConfigurationParameter::LoadAmsConfiguration(const std::string &filePath) 50 { 51 HILOG_DEBUG("%{public}s", __func__); 52 53 std::ifstream inFile; 54 inFile.open(filePath, std::ios::in); 55 if (!inFile.is_open()) { 56 HILOG_INFO("read ams config error ..."); 57 nonConfigFile = true; 58 return READ_FAIL; 59 } 60 61 json amsJson; 62 inFile >> amsJson; 63 if (amsJson.is_discarded()) { 64 HILOG_INFO("json discarded error ..."); 65 nonConfigFile = true; 66 inFile.close(); 67 return READ_JSON_FAIL; 68 } 69 70 if (amsJson.contains(AmsConfig::SERVICE_ITEM_AMS)) { 71 canStartLauncher = amsJson.at(AmsConfig::SERVICE_ITEM_AMS).at(AmsConfig::STARTUP_LAUNCHER).get<bool>(); 72 canStartUiStatusBar = amsJson.at(AmsConfig::SERVICE_ITEM_AMS).at(AmsConfig::STARTUP_STATUS_BAR).get<bool>(); 73 canStartUiNavigationBar = 74 amsJson.at(AmsConfig::SERVICE_ITEM_AMS).at(AmsConfig::STARTUP_NAVIGATION_BAR).get<bool>(); 75 HILOG_INFO("get ams service config succes!"); 76 } else { 77 HILOG_INFO("json no have service item ..."); 78 nonConfigFile = true; 79 amsJson.clear(); 80 inFile.close(); 81 return READ_JSON_FAIL; 82 } 83 84 amsJson.clear(); 85 inFile.close(); 86 HILOG_INFO("read ams config succes!"); 87 return READ_OK; 88 } 89 90 } // namespace AAFwk 91 } // namespace OHOS