• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_START_ABILITY_UTILS_H
17 #define OHOS_ABILITY_RUNTIME_START_ABILITY_UTILS_H
18 
19 #include <memory>
20 #include <string>
21 
22 #include "ability_info.h"
23 #include "extension_ability_info.h"
24 #include "want.h"
25 
26 namespace OHOS {
27 namespace AAFwk {
28 
29 struct StartAbilityInfo {
30     static std::shared_ptr<StartAbilityInfo> CreateStartAbilityInfo(const Want &want, int32_t userId,
31         int32_t appIndex);
32     static std::shared_ptr<StartAbilityInfo> CreateCallerAbilityInfo(const sptr<IRemoteObject> &callerToken);
33 
34     static std::shared_ptr<StartAbilityInfo> CreateStartExtensionInfo(const Want &want, int32_t userId,
35         int32_t appIndex);
36 
37     static void FindExtensionInfo(const Want &want, int32_t flags, int32_t userId,
38         int32_t appIndex, std::shared_ptr<StartAbilityInfo> abilityInfo);
39 
GetAppBundleNameStartAbilityInfo40     std::string GetAppBundleName() const
41     {
42         return abilityInfo.applicationInfo.bundleName;
43     }
44 
45     int32_t status = ERR_OK;
46     AppExecFwk::AbilityInfo abilityInfo;
47     AppExecFwk::ExtensionProcessMode extensionProcessMode = AppExecFwk::ExtensionProcessMode::UNDEFINED;
48     std::string customProcess;
49 };
50 
51 struct StartAbilityUtils {
52     static bool GetAppIndex(const Want &want, sptr<IRemoteObject> callerToken, int32_t &appIndex);
53     static bool GetApplicationInfo(const std::string &bundleName, int32_t userId,
54         AppExecFwk::ApplicationInfo &appInfo);
55     static bool GetCallerAbilityInfo(const sptr<IRemoteObject> &callerToken,
56         AppExecFwk::AbilityInfo &abilityInfo);
57     static int32_t CheckAppProvisionMode(const Want& want, int32_t userId);
58     static int32_t CheckAppProvisionMode(const std::string& bundleName, int32_t userId);
59     static std::vector<int32_t> GetCloneAppIndexes(const std::string &bundleName, int32_t userId);
60 
61     static bool IsCallFromAncoShellOrBroker(const sptr<IRemoteObject> &callerToken);
62 
63     static thread_local std::shared_ptr<StartAbilityInfo> startAbilityInfo;
64     static thread_local std::shared_ptr<StartAbilityInfo> callerAbilityInfo;
65     static thread_local bool skipCrowTest;
66     static thread_local bool skipStartOther;
67     static thread_local bool skipErms;
68     static thread_local int32_t ermsResultCode;
69     static thread_local bool isWantWithAppCloneIndex;
70     static thread_local bool ermsSupportBackToCallerFlag;
71 };
72 
73 struct StartAbilityInfoWrap {
74     StartAbilityInfoWrap(const Want &want, int32_t validUserId, int32_t appIndex,
75         const sptr<IRemoteObject> &callerToken, bool isExtension = false);
76     StartAbilityInfoWrap();
77     ~StartAbilityInfoWrap();
78     void SetStartAbilityInfo(const AppExecFwk::AbilityInfo& abilityInfo);
79 };
80 }
81 }
82 #endif // OHOS_ABILITY_RUNTIME_START_ABILITY_UTILS_H