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 #include "app_utils.h"
17
18 #include "hilog_tag_wrapper.h"
19 #include "hilog_wrapper.h"
20 #include "parameters.h"
21 #include "scene_board_judgement.h"
22
23 namespace OHOS {
24 namespace AAFwk {
25 namespace {
26 const std::string BUNDLE_NAME_LAUNCHER = "com.ohos.launcher";
27 const std::string BUNDLE_NAME_SCENEBOARD = "com.ohos.sceneboard";
28 const std::string LAUNCHER_ABILITY_NAME = "com.ohos.launcher.MainAbility";
29 const std::string SCENEBOARD_ABILITY_NAME = "com.ohos.sceneboard.MainAbility";
30 const std::string INHERIT_WINDOW_SPLIT_SCREEN_MODE = "persist.sys.abilityms.inherit_window_split_screen_mode";
31 const std::string SUPPORT_ANCO_APP = "persist.sys.abilityms.support_anco_app";
32 const std::string TIMEOUT_UNIT_TIME_RATIO = "persist.sys.abilityms.timeout_unit_time_ratio";
33 const std::string SELECTOR_DIALOG_POSSION = "persist.sys.abilityms.selector_dialog_possion";
34 const std::string START_SPECIFIED_PROCESS = "persist.sys.abilityms.start_specified_process";
35 const std::string USE_MULTI_RENDER_PROCESS = "persist.sys.abilityms.use_multi_render_process";
36 const std::string LIMIT_MAXIMUM_OF_RENDER_PROCESS = "persist.sys.abilityms.limit_maximum_of_render_process";
37 const std::string GRANT_PERSIST_URI_PERMISSION = "persist.sys.abilityms.grant_persist_uri_permission";
38 const std::string START_OPTIONS_WITH_ANIMATION = "persist.sys.abilityms.start_options_with_animation";
39 const std::string MULTI_PROCESS_MODEL = "persist.sys.abilityms.multi_process_model";
40 const std::string START_OPTIONS_WITH_PROCESS_OPTION = "persist.sys.abilityms.start_options_with_process_option";
41 const std::string MOVE_UI_ABILITY_TO_BACKGROUND_API_ENABLE =
42 "persist.sys.abilityms.move_ui_ability_to_background_api_enable";
43 const std::string LAUNCH_EMBEDED_UI_ABILITY = "const.abilityms.launch_embeded_ui_ability";
44 }
~AppUtils()45 AppUtils::~AppUtils() {}
46
AppUtils()47 AppUtils::AppUtils()
48 {
49 if (Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) {
50 isSceneBoard_ = true;
51 }
52 }
53
GetInstance()54 AppUtils &AppUtils::GetInstance()
55 {
56 static AppUtils utils;
57 return utils;
58 }
59
IsLauncher(const std::string & bundleName) const60 bool AppUtils::IsLauncher(const std::string &bundleName) const
61 {
62 if (isSceneBoard_) {
63 return bundleName == BUNDLE_NAME_SCENEBOARD;
64 }
65
66 return bundleName == BUNDLE_NAME_LAUNCHER;
67 }
68
IsLauncherAbility(const std::string & abilityName) const69 bool AppUtils::IsLauncherAbility(const std::string &abilityName) const
70 {
71 if (isSceneBoard_) {
72 return abilityName == SCENEBOARD_ABILITY_NAME;
73 }
74
75 return abilityName == LAUNCHER_ABILITY_NAME;
76 }
77
IsInheritWindowSplitScreenMode()78 bool AppUtils::IsInheritWindowSplitScreenMode()
79 {
80 if (!isInheritWindowSplitScreenMode_.isLoaded) {
81 isInheritWindowSplitScreenMode_.value = system::GetBoolParameter(INHERIT_WINDOW_SPLIT_SCREEN_MODE, true);
82 isInheritWindowSplitScreenMode_.isLoaded = true;
83 }
84 TAG_LOGI(AAFwkTag::DEFAULT, "isInheritWindowSplitScreenMode is %{public}d", isInheritWindowSplitScreenMode_.value);
85 return isInheritWindowSplitScreenMode_.value;
86 }
87
IsSupportAncoApp()88 bool AppUtils::IsSupportAncoApp()
89 {
90 if (!isSupportAncoApp_.isLoaded) {
91 isSupportAncoApp_.value = system::GetBoolParameter(SUPPORT_ANCO_APP, false);
92 isSupportAncoApp_.isLoaded = true;
93 }
94 TAG_LOGI(AAFwkTag::DEFAULT, "isSupportAncoApp is %{public}d", isSupportAncoApp_.value);
95 return isSupportAncoApp_.value;
96 }
97
GetTimeoutUnitTimeRatio()98 int32_t AppUtils::GetTimeoutUnitTimeRatio()
99 {
100 if (!timeoutUnitTimeRatio_.isLoaded) {
101 timeoutUnitTimeRatio_.value = system::GetIntParameter<int32_t>(TIMEOUT_UNIT_TIME_RATIO, 1);
102 timeoutUnitTimeRatio_.isLoaded = true;
103 }
104 TAG_LOGI(AAFwkTag::DEFAULT, "timeoutUnitTimeRatio is %{public}d", timeoutUnitTimeRatio_.value);
105 return timeoutUnitTimeRatio_.value;
106 }
107
IsSelectorDialogDefaultPossion()108 bool AppUtils::IsSelectorDialogDefaultPossion()
109 {
110 if (!isSelectorDialogDefaultPossion_.isLoaded) {
111 isSelectorDialogDefaultPossion_.value = system::GetBoolParameter(SELECTOR_DIALOG_POSSION, true);
112 isSelectorDialogDefaultPossion_.isLoaded = true;
113 }
114 TAG_LOGI(AAFwkTag::DEFAULT, "isSelectorDialogDefaultPossion is %{public}d", isSelectorDialogDefaultPossion_.value);
115 return isSelectorDialogDefaultPossion_.value;
116 }
117
IsStartSpecifiedProcess()118 bool AppUtils::IsStartSpecifiedProcess()
119 {
120 if (!isStartSpecifiedProcess_.isLoaded) {
121 isStartSpecifiedProcess_.value = system::GetBoolParameter(START_SPECIFIED_PROCESS, false);
122 isStartSpecifiedProcess_.isLoaded = true;
123 }
124 TAG_LOGI(AAFwkTag::DEFAULT, "isStartSpecifiedProcess is %{public}d", isStartSpecifiedProcess_.value);
125 return isStartSpecifiedProcess_.value;
126 }
127
IsUseMultiRenderProcess()128 bool AppUtils::IsUseMultiRenderProcess()
129 {
130 if (!isUseMultiRenderProcess_.isLoaded) {
131 isUseMultiRenderProcess_.value = system::GetBoolParameter(USE_MULTI_RENDER_PROCESS, true);
132 isUseMultiRenderProcess_.isLoaded = true;
133 }
134 TAG_LOGI(AAFwkTag::DEFAULT, "isUseMultiRenderProcess is %{public}d", isUseMultiRenderProcess_.value);
135 return isUseMultiRenderProcess_.value;
136 }
137
IsLimitMaximumOfRenderProcess()138 bool AppUtils::IsLimitMaximumOfRenderProcess()
139 {
140 if (!isLimitMaximumOfRenderProcess_.isLoaded) {
141 isLimitMaximumOfRenderProcess_.value = system::GetBoolParameter(LIMIT_MAXIMUM_OF_RENDER_PROCESS, true);
142 isLimitMaximumOfRenderProcess_.isLoaded = true;
143 }
144 TAG_LOGI(AAFwkTag::DEFAULT, "isLimitMaximumOfRenderProcess_ is %{public}d", isLimitMaximumOfRenderProcess_.value);
145 return isLimitMaximumOfRenderProcess_.value;
146 }
147
IsGrantPersistUriPermission()148 bool AppUtils::IsGrantPersistUriPermission()
149 {
150 if (!isGrantPersistUriPermission_.isLoaded) {
151 isGrantPersistUriPermission_.value = system::GetBoolParameter(GRANT_PERSIST_URI_PERMISSION, false);
152 isGrantPersistUriPermission_.isLoaded = true;
153 }
154 TAG_LOGI(AAFwkTag::DEFAULT, "isGrantPersistUriPermission_ is %{public}d", isGrantPersistUriPermission_.value);
155 return isGrantPersistUriPermission_.value;
156 }
157
IsStartOptionsWithAnimation()158 bool AppUtils::IsStartOptionsWithAnimation()
159 {
160 if (!isStartOptionsWithAnimation_.isLoaded) {
161 isStartOptionsWithAnimation_.value = system::GetBoolParameter(START_OPTIONS_WITH_ANIMATION, false);
162 isStartOptionsWithAnimation_.isLoaded = true;
163 }
164 TAG_LOGI(AAFwkTag::DEFAULT, "isStartOptionsWithAnimation_ is %{public}d", isStartOptionsWithAnimation_.value);
165 return isStartOptionsWithAnimation_.value;
166 }
167
IsMultiProcessModel()168 bool AppUtils::IsMultiProcessModel()
169 {
170 if (!isMultiProcessModel_.isLoaded) {
171 isMultiProcessModel_.value = system::GetBoolParameter(MULTI_PROCESS_MODEL, false);
172 isMultiProcessModel_.isLoaded = true;
173 }
174 TAG_LOGI(AAFwkTag::DEFAULT, "isMultiProcessModel_ is %{public}d", isMultiProcessModel_.value);
175 return isMultiProcessModel_.value;
176 }
177
IsStartOptionsWithProcessOptions()178 bool AppUtils::IsStartOptionsWithProcessOptions()
179 {
180 if (!isStartOptionsWithProcessOptions_.isLoaded) {
181 isStartOptionsWithProcessOptions_.value = system::GetBoolParameter(START_OPTIONS_WITH_PROCESS_OPTION, false);
182 isStartOptionsWithProcessOptions_.isLoaded = true;
183 }
184 TAG_LOGI(AAFwkTag::DEFAULT,
185 "isStartOptionsWithProcessOptions_ is %{public}d", isStartOptionsWithProcessOptions_.value);
186 return isStartOptionsWithProcessOptions_.value;
187 }
188
EnableMoveUIAbilityToBackgroundApi()189 bool AppUtils::EnableMoveUIAbilityToBackgroundApi()
190 {
191 if (!enableMoveUIAbilityToBackgroundApi_.isLoaded) {
192 enableMoveUIAbilityToBackgroundApi_.value =
193 system::GetBoolParameter(MOVE_UI_ABILITY_TO_BACKGROUND_API_ENABLE, true);
194 enableMoveUIAbilityToBackgroundApi_.isLoaded = true;
195 }
196 TAG_LOGI(AAFwkTag::DEFAULT,
197 "enableMoveUIAbilityToBackgroundApi_ is %{public}d", enableMoveUIAbilityToBackgroundApi_.value);
198 return enableMoveUIAbilityToBackgroundApi_.value;
199 }
200
IsLaunchEmbededUIAbility()201 bool AppUtils::IsLaunchEmbededUIAbility()
202 {
203 if (!isLaunchEmbededUIAbility_.isLoaded) {
204 isLaunchEmbededUIAbility_.value = system::GetBoolParameter(LAUNCH_EMBEDED_UI_ABILITY, false);
205 isLaunchEmbededUIAbility_.isLoaded = true;
206 }
207 TAG_LOGI(AAFwkTag::DEFAULT, "isLaunchEmbededUIAbility_ is %{public}d", isLaunchEmbededUIAbility_.value);
208 return isLaunchEmbededUIAbility_.value;
209 }
210 } // namespace AAFwk
211 } // namespace OHOS
212