1 /* 2 * Copyright (c) 2023-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 #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 /** 44 * @brief Update global configuration to context configuration and resource manager. 45 * 46 * @param configuration global configuration 47 * @param contextConfig context configuration 48 * @param resourceManager resource manager 49 */ 50 void UpdateGlobalConfig(const Configuration &configuration, std::shared_ptr<Configuration> contextConfig, 51 std::shared_ptr<ResourceManager> resourceManager); 52 53 /** 54 * @brief Update global configuration to context configuration and resource manager. 55 * 56 * @param configuration global configuration 57 * @param contextConfig context configuration 58 * @param contextConfig ability configuration 59 * @param resourceManager resource manager 60 */ 61 Configuration UpdateGlobalConfig(const Configuration &configuration, std::shared_ptr<Configuration> contextConfig, 62 std::shared_ptr<Configuration> abilityConfig, std::shared_ptr<ResourceManager> resourceManager); 63 64 /** 65 * @brief Update ability configuration to context configuration and resource manager. 66 * 67 * @param configuration ability configuration 68 * @param resourceManager resource manager 69 */ 70 void UpdateAbilityConfig(const Configuration &configuration, std::shared_ptr<ResourceManager> resourceManager); 71 72 private: 73 void GetGlobalConfig(const Configuration &configuration, 74 OHOS::AbilityRuntime::ResourceConfigHelper &resourceConfig); 75 76 #ifdef SUPPORT_GRAPHICS 77 public: 78 /** 79 * @brief Init display configuration to context configuration and resource manager. 80 * 81 * @param displayId Display ID 82 * @param configuration Context configuration need to add display config 83 * @param resourceManager Resource manager instance need to add display config 84 */ 85 void InitDisplayConfig(Rosen::DisplayId displayId, std::shared_ptr<Configuration> configuration, 86 std::shared_ptr<ResourceManager> resourceManager); 87 88 /** 89 * @brief Update display configuration to context configuration and resource manager. 90 * 91 * @param displayId Display ID 92 * @param configuration Context configuration need to add display config 93 * @param resourceManager Resource manager instance need to add display config 94 * @param configChanged If configuration has changed, set to true 95 */ 96 void UpdateDisplayConfig(Rosen::DisplayId displayId, std::shared_ptr<Configuration> configuration, 97 std::shared_ptr<ResourceManager> resourceManager, bool &configChanged); 98 99 /** 100 * @brief Init display configuration to resource manager. 101 * 102 * @param configuration Context configuration need to update display config 103 * @param resourceManager Resource manager instance need to update display config 104 * @param displayId display Id 105 * @param density display density 106 * @param orientation display orientation 107 */ 108 void InitDisplayConfig(std::shared_ptr<Configuration> configuration, 109 std::shared_ptr<ResourceManager> resourceManager, Rosen::DisplayId displayId, float density, 110 int32_t orientation); 111 112 /** 113 * @brief Update display configuration to context configuration and resource manager. 114 * 115 * @param configuration Context configuration need to update display config 116 * @param resourceManager Resource manager instance need to update display config 117 * @param displayId display Id 118 * @param density display density 119 * @param orientation display orientation 120 * @return Returns true on update success, false on update failure. 121 */ 122 bool UpdateDisplayConfig(std::shared_ptr<Configuration> configuration, 123 std::shared_ptr<ResourceManager> resourceManager, Rosen::DisplayId displayId, float density, 124 Rosen::DisplayOrientation orientation); 125 126 private: 127 bool GetDisplayConfig(Rosen::DisplayId displayId, float &density, std::string &directionStr); 128 void UpdateDisplayResConfig(std::shared_ptr<ResourceManager> resourceManager, float &density, 129 std::string &direction); 130 #endif 131 }; 132 } // namespace AbilityRuntime 133 } // namespace OHOS 134 #endif // OHOS_ABILITY_RUNTIME_CONFIGURATION_UTILS_H 135