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 #ifndef OHOS_ABILITY_RUNTIME_CONFIGURATION_UTILS_H
17 #define OHOS_ABILITY_RUNTIME_CONFIGURATION_UTILS_H
18 
19 #include "configuration.h"
20 #include "resource_config_helper.h"
21 #ifdef SUPPORT_GRAPHICS
22 #include "display_manager.h"
23 #endif
24 #include "resource_manager.h"
25 
26 namespace OHOS {
27 namespace AbilityRuntime {
28 class ConfigurationUtils {
29 public:
30     ConfigurationUtils() = default;
31     ~ConfigurationUtils() = default;
32     using Configuration = AppExecFwk::Configuration;
33     using ResourceManager = Global::Resource::ResourceManager;
34 
35     /**
36      * @brief Update global configuration to resource manager.
37      *
38      * @param configuration configuration
39      * @param resourceManager resource manager
40      */
41     void UpdateGlobalConfig(const Configuration &configuration, std::shared_ptr<ResourceManager> resourceManager);
42 
43 private:
44     void GetGlobalConfig(const Configuration &configuration,
45         OHOS::AbilityRuntime::ResourceConfigHelper &resourceConfig);
46 
47 #ifdef SUPPORT_GRAPHICS
48 public:
49     /**
50      * @brief Init display configuration to context configuration and resource manager.
51      *
52      * @param displayId Display ID
53      * @param configuration Context configuration need to add display config
54      * @param resourceManager Resource manager instance need to add display config
55      */
56     void InitDisplayConfig(Rosen::DisplayId displayId, std::shared_ptr<Configuration> configuration,
57         std::shared_ptr<ResourceManager> resourceManager);
58 
59     /**
60      * @brief Update display configuration to context configuration and resource manager.
61      *
62      * @param displayId Display ID
63      * @param configuration Context configuration need to add display config
64      * @param resourceManager Resource manager instance need to add display config
65      * @param configChanged If configuration has changed, set to true
66      */
67     void UpdateDisplayConfig(Rosen::DisplayId displayId, std::shared_ptr<Configuration> configuration,
68         std::shared_ptr<ResourceManager> resourceManager, bool &configChanged);
69 
70 private:
71     bool GetDisplayConfig(Rosen::DisplayId displayId, float &density, std::string &directionStr);
72     void UpdateDisplayResConfig(std::shared_ptr<ResourceManager> resourceManager, float &density,
73         std::string &direction);
74 #endif
75 };
76 } // namespace AbilityRuntime
77 } // namespace OHOS
78 #endif  // OHOS_ABILITY_RUNTIME_CONFIGURATION_UTILS_H
79