• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_APP_UTILS_H
17 #define OHOS_ABILITY_RUNTIME_APP_UTILS_H
18 
19 #include <mutex>
20 #include <string>
21 
22 #include "nocopyable.h"
23 
24 namespace OHOS {
25 namespace AAFwk {
26 constexpr const int32_t DEFAULT_MAX_EXT_PER_PROC = 10;
27 constexpr const int32_t DEFAULT_MAX_EXT_PER_DEV = 100;
28 constexpr const int32_t DEFAULT_INVALID_VALUE = -1;
29 constexpr const int32_t DEFAULT_MAX_CHILD_PROCESS = 0;
30 template<typename T>
31 class DeviceConfiguration {
32 public:
33     bool isLoaded = false;
34     T value;
35 };
36 
37 /**
38  * @class AppUtils
39  * provides app utils.
40  */
41 class AppUtils {
42 public:
43     /**
44      * GetInstance, get an instance of AppUtils.
45      *
46      * @return An instance of AppUtils.
47      */
48     static AppUtils &GetInstance();
49 
50     /**
51      * AppUtils, destructor.
52      *
53      */
54     ~AppUtils();
55 
56     /**
57      * IsLauncher, check if it is a launcher.
58      *
59      * @param bundleName The bundle name.
60      * @return Whether it is a launcher.
61      */
62     bool IsLauncher(const std::string &bundleName) const;
63 
64     /**
65      * IsLauncherAbility, check if it is a launcher ability.
66      *
67      * @param abilityName The ability name.
68      * @return Whether it is a launcher ability.
69      */
70     bool IsLauncherAbility(const std::string &abilityName) const;
71 
72     /**
73      * IsInheritWindowSplitScreenMode, check if it is inherit window split screen mode.
74      *
75      * @return Whether it is inherit window split screen mode.
76      */
77     bool IsInheritWindowSplitScreenMode();
78 
79     /**
80      * IsSupportAncoApp, check if it supports anco app.
81      *
82      * @return Whether it supports anco app.
83      */
84     bool IsSupportAncoApp();
85 
86     /**
87      * GetTimeoutUnitTimeRatio, get timeout unit time ratio.
88      *
89      * @return Timeout unit time ratio.
90      */
91     int32_t GetTimeoutUnitTimeRatio();
92 
93     /**
94      * IsSelectorDialogDefaultPossion, check if selector dialog is on the default position.
95      *
96      * @return Whether selector dialog is on the default position.
97      */
98     bool IsSelectorDialogDefaultPossion();
99 
100     /**
101      * IsStartSpecifiedProcess, check whether or not to start specified process.
102      *
103      * @return Whether or not to start specified process.
104      */
105     bool IsStartSpecifiedProcess();
106 
107     /**
108      * IsUseMultiRenderProcess, check whether uses multi-render process.
109      *
110      * @return Whether uses multi-render process.
111      */
112     bool IsUseMultiRenderProcess();
113 
114     /**
115      * IsLimitMaximumOfRenderProcess, check limit maximum of render process.
116      *
117      * @return Whether limit maximum of render process.
118      */
119     bool IsLimitMaximumOfRenderProcess();
120 
121     /**
122      * IsGrantPersistUriPermission, check whether to grant persist uri permission.
123      *
124      * @return Whether to grant persist uri permission.
125      */
126     bool IsGrantPersistUriPermission();
127 
128     /**
129      * IsStartOptionsWithAnimation, check whether the start options have animation.
130      *
131      * @return Whether the start options have animation.
132      */
133     bool IsStartOptionsWithAnimation();
134 
135     /**
136      * IsStartOptionsWithAnimation, check whether it is a multi-process model.
137      *
138      * @return Whether it is a multi-process model.
139      */
140     bool IsMultiProcessModel();
141 
142     /**
143      * IsStartOptionsWithProcessOptions, check whether the start options have process options.
144      *
145      * @return Whether the start options have process options.
146      */
147     bool IsStartOptionsWithProcessOptions();
148 
149     /**
150      * EnableMoveUIAbilityToBackgroundApi, enable move ui-ability to background api.
151      *
152      * @return Whether the enable move ui-ability to background api is successful.
153      */
154     bool EnableMoveUIAbilityToBackgroundApi();
155 
156     /**
157      * IsLaunchEmbededUIAbility, check if it is to launch embedded ui-ability.
158      *
159      * @return Whether it is to launch embedded ui-ability.
160      */
161     bool IsLaunchEmbededUIAbility();
162 
163     /**
164      * IsSupportNativeChildProcess, check if it supports native child process.
165      *
166      * @return Whether it supports native child process.
167      */
168     bool IsSupportNativeChildProcess();
169 
170     /**
171      * IsSupportMultiInstance, check if it supports multi-instance.
172      *
173      * @return Whether it supports multi-instance.
174      */
175     bool IsSupportMultiInstance();
176 
177     /**
178      * IsAllowResidentInExtremeMemory, check if it allows resident in extrem low memory.
179      *
180      * @param bundleName The bundle name.
181      * @param abilityName The ability name.
182      * @return Whether it allows resident in extrem low memory.
183      */
184     bool IsAllowResidentInExtremeMemory(const std::string& bundleName, const std::string& abilityName = "");
185 
186     /**
187      * IsAllowNativeChildProcess, check if it allows native child process.
188      *
189      * @param appIdentifier The app identifier.
190      * @return Whether it allows native child process.
191      */
192     bool IsAllowNativeChildProcess(const std::string &appIdentifier);
193 
194     /**
195      * GetLimitMaximumExtensionsPerProc, get limit max extensions per proc.
196      *
197      * @return Limit max extensions per proc.
198      */
199     int32_t GetLimitMaximumExtensionsPerProc();
200 
201     /**
202      * GetLimitMaximumExtensionsPerDevice, get limit max extensions per device.
203      *
204      * @return Limit max extensions per device.
205      */
206     int32_t GetLimitMaximumExtensionsPerDevice();
207 
208     /**
209      * GetCacheExtensionTypeList, get cache extension type list.
210      *
211      * @return Cache extension type list.
212      */
213     std::string GetCacheExtensionTypeList();
214 
215     /**
216      * IsAllowStartAbilityWithoutCallerToken, check if it allows start ability without caller token.
217      *
218      * @param bundleName The bundle name.
219      * @param abilityName The ability name.
220      * @return Whether it allows start ability without caller token.
221      */
222     bool IsAllowStartAbilityWithoutCallerToken(const std::string& bundleName, const std::string& abilityName);
223 
224     /**
225      * GetBrokerDelegateBundleName, get broker delegate bundle name.
226      *
227      * @return Broker delegate bundle name.
228      */
229     std::string GetBrokerDelegateBundleName();
230 
231     /**
232      * GetCollaboratorBrokerUID, get collaborator broker id.
233      *
234      * @return Collaborator broker id.
235      */
236     int32_t GetCollaboratorBrokerUID();
237 
238     /**
239      * GetCollaboratorBrokerReserveUID, get collaborator broker reserve uid.
240      *
241      * @return Collaborator broker reserve uid.
242      */
243     int32_t GetCollaboratorBrokerReserveUID();
244 
245     /**
246      * MaxChildProcess, get max child process.
247      *
248      * @return Max child process.
249      */
250     int32_t MaxChildProcess();
251 
252     /**
253      * GetMigrateClientBundleName, get migrate client bundle name.
254      *
255      * @return Migrate client bundle name.
256      */
257     std::string GetMigrateClientBundleName();
258 
259     /**
260      * IsConnectSupportCrossUser, check if it support cross-user.
261      *
262      * @return Whether it supports cross-user.
263      */
264     bool IsConnectSupportCrossUser();
265 
266     /**
267      * IsPrepareTerminateEnabled, check if it supports prepare terminate.
268      *
269      * @return Whether it supports prepare terminate.
270      */
271     bool IsPrepareTerminateEnabled();
272 
273     /**
274      * IsCacheExtensionAbilityByList, check if it allows cache extension ability by list.
275      *
276      * @param bundleName The bundle name.
277      * @param abilityName The ability name.
278      * @return Whether it allows cache extensionability.
279      */
280     bool IsCacheExtensionAbilityByList(const std::string& bundleName, const std::string& abilityName);
281 
282 private:
283     /**
284      * LoadResidentProcessInExtremeMemory, load resident process in extreme low memory.
285      *
286      */
287     void LoadResidentProcessInExtremeMemory();
288 
289     /**
290      * LoadAllowNativeChildProcessApps, load allow native child process apps.
291      *
292      */
293     void LoadAllowNativeChildProcessApps();
294 
295     /**
296      * LoadStartAbilityWithoutCallerToken, load start ability without caller token.
297      *
298      */
299     void LoadStartAbilityWithoutCallerToken();
300 
301     /**
302      * IsCacheAbilityEnabled, check cache ability parameter switch.
303      *
304      */
305     bool IsCacheAbilityEnabled();
306 
307      /**
308      * LoadCacheAbilityList, load cache ability list from file.
309      *
310      */
311     void LoadCacheAbilityList();
312 
313     /**
314      * AppUtils, private constructor.
315      *
316      */
317     AppUtils();
318 
319     volatile bool isSceneBoard_ = false;
320     volatile DeviceConfiguration<bool> isInheritWindowSplitScreenMode_ = {false, true};
321     volatile DeviceConfiguration<bool> isSupportAncoApp_ = {false, false};
322     volatile DeviceConfiguration<int32_t> timeoutUnitTimeRatio_ = {false, 1};
323     volatile DeviceConfiguration<bool> isSelectorDialogDefaultPossion_ = {false, true};
324     volatile DeviceConfiguration<bool> isStartSpecifiedProcess_ = {false, false};
325     volatile DeviceConfiguration<bool> isUseMultiRenderProcess_ = {false, true};
326     volatile DeviceConfiguration<bool> isLimitMaximumOfRenderProcess_ = {false, true};
327     volatile DeviceConfiguration<bool> isGrantPersistUriPermission_ = {false, false};
328     volatile DeviceConfiguration<bool> isStartOptionsWithAnimation_ = {false, false};
329     volatile DeviceConfiguration<bool> isMultiProcessModel_ = {false, false};
330     volatile DeviceConfiguration<bool> isStartOptionsWithProcessOptions_ = {false, false};
331     volatile DeviceConfiguration<bool> enableMoveUIAbilityToBackgroundApi_ = {false, true};
332     volatile DeviceConfiguration<bool> isLaunchEmbededUIAbility_ = {false, false};
333     volatile DeviceConfiguration<bool> isSupportNativeChildProcess_ = {false, false};
334     volatile DeviceConfiguration<bool> isSupportMultiInstance_ = {false, false};
335     std::mutex isConnectSupportCrossUserMutex_;
336     volatile DeviceConfiguration<bool> isConnectSupportCrossUser_ = {false, false};
337     DeviceConfiguration<std::vector<std::pair<std::string, std::string>>>
338         residentProcessInExtremeMemory_ = {false, {}};
339     std::mutex residentProcessInExtremeMemoryMutex_;
340     DeviceConfiguration<std::vector<std::string>>
341         allowStartNativeProcessApps_ = {false, {}};
342     volatile DeviceConfiguration<int32_t> limitMaximumExtensionsPerProc_ = {false, DEFAULT_MAX_EXT_PER_PROC};
343     volatile DeviceConfiguration<int32_t> limitMaximumExtensionsPerDevice_ = {false, DEFAULT_MAX_EXT_PER_DEV};
344     DeviceConfiguration<std::vector<std::pair<std::string, std::string>>>
345         startAbilityWithoutCallerToken_ = {false, {}};
346     std::mutex startAbilityWithoutCallerTokenMutex_;
347     DeviceConfiguration<std::string> brokerDelegateBundleName_ = {false, ""};
348     volatile DeviceConfiguration<int32_t> collaboratorBrokerUid_ = {false, DEFAULT_INVALID_VALUE};
349     volatile DeviceConfiguration<int32_t> collaboratorBrokerReserveUid_ = {false, DEFAULT_INVALID_VALUE};
350     volatile DeviceConfiguration<int32_t> maxChildProcess_ = {false, DEFAULT_MAX_CHILD_PROCESS};
351     DeviceConfiguration<std::string> migrateClientBundleName_ = {true, "com.huwei.hmos.migratecilent"};
352     DeviceConfiguration<std::vector<std::pair<std::string, std::string>>>
353         cacheAbilityList_ = {false, {}};
354     DISALLOW_COPY_AND_MOVE(AppUtils);
355 };
356 }  // namespace AAFwk
357 }  // namespace OHOS
358 #endif  // OHOS_ABILITY_RUNTIME_APP_UTILS_H
359