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 #ifndef OHOS_ABILITY_RUNTIME_APPSPAWN_UTIL_H
17 #define OHOS_ABILITY_RUNTIME_APPSPAWN_UTIL_H
18 
19 #include "ability_info.h"
20 #include "app_spawn_client.h"
21 #include "global_constant.h"
22 #include "want.h"
23 
24 namespace OHOS {
25 namespace AppExecFwk {
26 namespace AppspawnUtil {
27 constexpr const char* DLP_PARAMS_INDEX = "ohos.dlp.params.index";
28 
BuildStartFlags(const AAFwk::Want & want,const ApplicationInfo & applicationInfo)29 static uint32_t BuildStartFlags(const AAFwk::Want &want, const ApplicationInfo &applicationInfo)
30 {
31     uint32_t startFlags = 0x0;
32     if (want.GetBoolParam("coldStart", false)) {
33         startFlags = startFlags | (START_FLAG_BASE << StartFlags::COLD_START);
34     }
35 
36 #ifdef WITH_DLP
37     if (want.GetIntParam(DLP_PARAMS_INDEX, 0) != 0) {
38         startFlags = startFlags | (START_FLAG_BASE << StartFlags::DLP_MANAGER);
39     }
40 #endif // WITH_DLP
41 
42     if (applicationInfo.debug) {
43         startFlags = startFlags | (START_FLAG_BASE << StartFlags::DEBUGGABLE);
44     }
45     if (applicationInfo.asanEnabled) {
46         startFlags = startFlags | (START_FLAG_BASE << StartFlags::ASANENABLED);
47     }
48     if (want.GetBoolParam("nativeDebug", false)) {
49         startFlags = startFlags | (START_FLAG_BASE << StartFlags::NATIVEDEBUG);
50     }
51     if (applicationInfo.gwpAsanEnabled) {
52         startFlags = startFlags | (START_FLAG_BASE << StartFlags::GWP_ENABLED_FORCE);
53     }
54     if (applicationInfo.isSystemApp) {
55         startFlags = startFlags | (START_FLAG_BASE << StartFlags::GWP_ENABLED_NORMAL);
56     }
57     if (applicationInfo.tsanEnabled) {
58         startFlags = startFlags | (START_FLAG_BASE << StartFlags::TSANENABLED);
59     }
60     if (want.GetBoolParam("ohos.ability.params.extensionControl", false)) {
61         startFlags = startFlags | (START_FLAG_BASE << StartFlags::EXTENSION_CONTROLLED);
62     }
63     if (applicationInfo.multiAppMode.multiAppModeType == MultiAppModeType::APP_CLONE && applicationInfo.appIndex > 0 &&
64         applicationInfo.appIndex <= AbilityRuntime::GlobalConstant::MAX_APP_CLONE_INDEX) {
65         startFlags = startFlags | (START_FLAG_BASE << APP_FLAGS_CLONE_ENABLE);
66     }
67     if (applicationInfo.hwasanEnabled) {
68         startFlags = startFlags | (START_FLAG_BASE << StartFlags::HWASANENABLED);
69     }
70 
71     return startFlags;
72 }
73 
BuildStartFlags(const AAFwk::Want & want,const AbilityInfo & abilityInfo)74 static uint32_t BuildStartFlags(const AAFwk::Want &want, const AbilityInfo &abilityInfo)
75 {
76     uint32_t startFlags = BuildStartFlags(want, abilityInfo.applicationInfo);
77 
78     if (abilityInfo.extensionAbilityType == ExtensionAbilityType::BACKUP) {
79         startFlags = startFlags | (START_FLAG_BASE << StartFlags::BACKUP_EXTENSION);
80     }
81 
82     return startFlags;
83 }
84 }  // namespace AppspawnUtil
85 }  // namespace AppExecFwk
86 }  // namespace OHOS
87 
88 #endif  // OHOS_ABILITY_RUNTIME_APPSPAWN_UTIL_H
89