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 <string>
17 #include <vector>
18 #include "application_configuration_manager.h"
19 #include "configuration_utils.h"
20 
21 namespace OHOS {
22 namespace AbilityRuntime {
23 
operator <(SetLevel lhs,SetLevel rhs)24 bool operator<(SetLevel lhs, SetLevel rhs)
25 {
26     return static_cast<uint8_t>(lhs) < static_cast<uint8_t>(rhs);
27 };
28 
operator >(SetLevel lhs,SetLevel rhs)29 bool operator>(SetLevel lhs, SetLevel rhs)
30 {
31     return static_cast<uint8_t>(lhs) > static_cast<uint8_t>(rhs);
32 };
33 
GetInstance()34 ApplicationConfigurationManager& ApplicationConfigurationManager::GetInstance()
35 {
36     static ApplicationConfigurationManager instance;
37     return instance;
38 }
39 
SetLanguageSetLevel(SetLevel languageSetLevel)40 void ApplicationConfigurationManager::SetLanguageSetLevel(SetLevel languageSetLevel)
41 {
42     languageSetLevel_ = languageSetLevel;
43 }
44 
GetLanguageSetLevel() const45 SetLevel ApplicationConfigurationManager::GetLanguageSetLevel() const
46 {
47     return languageSetLevel_;
48 }
49 
SetfontSetLevel(SetLevel fontSetLevel)50 void ApplicationConfigurationManager::SetfontSetLevel(SetLevel fontSetLevel)
51 {
52     fontSetLevel_ = fontSetLevel;
53 }
54 
GetFontSetLevel() const55 SetLevel ApplicationConfigurationManager::GetFontSetLevel() const
56 {
57     return fontSetLevel_;
58 }
59 
SetColorModeSetLevel(SetLevel colorModeSetLevel,const std::string & value)60 std::string ApplicationConfigurationManager::SetColorModeSetLevel(SetLevel colorModeSetLevel, const std::string &value)
61 {
62     colorModeVal_[static_cast<uint8_t>(colorModeSetLevel)] = value;
63     for (int i = static_cast<uint8_t>(SetLevel::SetLevelCount) - 1; i >= 0; i--) {
64         if (!colorModeVal_[i].empty() &&
65             colorModeVal_[i].compare(AppExecFwk::ConfigurationInner::COLOR_MODE_AUTO) != 0) {
66             colorModeSetLevel_ = static_cast<SetLevel>(i);
67             break;
68         }
69     }
70 
71     return colorModeVal_[static_cast<uint8_t>(colorModeSetLevel_)];
72 }
73 
GetColorModeSetLevel() const74 SetLevel ApplicationConfigurationManager::GetColorModeSetLevel() const
75 {
76     return colorModeSetLevel_;
77 }
78 
ColorModeHasSetByApplication() const79 bool ApplicationConfigurationManager::ColorModeHasSetByApplication() const
80 {
81     return !colorModeVal_[static_cast<uint8_t>(SetLevel::Application)].empty();
82 }
83 } // namespace AbilityRuntime
84 } // namespace OHOS