• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2025 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 #ifndef OHOS_ABILITY_RUNTIME_IMPLICIT_START_PROCESSOR_H
16 #define OHOS_ABILITY_RUNTIME_IMPLICIT_START_PROCESSOR_H
17 
18 #include <list>
19 #include <vector>
20 #include <string>
21 #include <unordered_set>
22 
23 #include "ability_record.h"
24 #include "bundle_mgr_helper.h"
25 #include "system_dialog_scheduler.h"
26 
27 namespace OHOS {
28 namespace EcologicalRuleMgrService {
29 struct AbilityCallerInfo;
30 }
31 namespace AAFwk {
32 struct IdentityNode {
33     int32_t tokenId;
34     std::string identity;
IdentityNodeIdentityNode35     IdentityNode(int tokenId, std::string identity) : tokenId(tokenId), identity(identity)
36     {}
37 };
38 
39 struct AddInfoParam {
40     bool isExtension = false;
41     bool isMoreHapList = false;
42     bool withDefault = false;
43     bool isExistDefaultApp = false;
44     int32_t userId = 0;
45     std::string typeName;
46     std::vector<std::string> infoNames;
47     AppExecFwk::AbilityInfo info;
48 };
49 
50 struct GenerateRequestParam {
51     bool isMoreHapList = false;
52     bool findDefaultApp = false;
53     bool isAppCloneSelector = false;
54     bool fromImplicitStartAG = false;
55 };
56 
57 using namespace OHOS::EcologicalRuleMgrService;
58 using ErmsCallerInfo = OHOS::EcologicalRuleMgrService::AbilityCallerInfo;
59 /**
60  * @class ImplicitStartProcessor
61  * ImplicitStartProcessor.
62  */
63 class ImplicitStartProcessor : public std::enable_shared_from_this<ImplicitStartProcessor> {
64 public:
65     explicit ImplicitStartProcessor() = default;
66     virtual ~ImplicitStartProcessor() = default;
67 
68     static bool IsImplicitStartAction(const Want &want);
69 
70     int ImplicitStartAbility(AbilityRequest &request, int32_t userId, int32_t windowMode = 0,
71         const std::string &replaceWantString = "", bool isAppCloneSelector = false);
72 
73     void ResetCallingIdentityAsCaller(int32_t tokenId, bool flag);
74 
75     void RemoveIdentity(int32_t tokenId);
76 
77 private:
78 #ifdef APP_DOMAIN_VERIFY_ENABLED
79     bool NeedQueryFromAG(const AbilityRequest &request, bool applinkExist);
80     int ImplicitStartAG(int32_t userId, AbilityRequest &request, std::vector<DialogAppInfo> &dialogAppInfos,
81         GenerateRequestParam &genReqParam, bool &queryAGSuccess);
82 #endif // APP_DOMAIN_VERIFY_ENABLED
83 
84     int GenerateAbilityRequestByAction(int32_t userId, AbilityRequest &request,
85         std::vector<DialogAppInfo> &dialogAppInfos, GenerateRequestParam &genReqParam);
86 
87     int GenerateAbilityRequestByAppIndexes(int32_t userId, AbilityRequest &request,
88         std::vector<DialogAppInfo> &dialogAppInfos);
89 
90     int FindExtensionInfo(const Want &want, int32_t flags, int32_t userId, int32_t appIndex,
91         AppExecFwk::AbilityInfo &abilityInfo);
92 
93     std::string MatchTypeAndUri(const AAFwk::Want &want);
94     std::shared_ptr<AppExecFwk::BundleMgrHelper> GetBundleManagerHelper();
95     std::vector<std::string> SplitStr(const std::string& str, char delimiter);
96     int QueryBmsAppInfos(AbilityRequest &request, int32_t userId, std::vector<DialogAppInfo> &dialogAppInfos);
97 
98     using StartAbilityClosure = std::function<int32_t()>;
99     int CallStartAbilityInner(int32_t userId, const Want &want, const StartAbilityClosure &callBack,
100         const AbilityCallType &callType);
101 
102     int32_t ImplicitStartAbilityInner(const Want &targetWant, const AbilityRequest &request, int32_t userId);
103 
104     bool CheckImplicitStartExtensionIsValid(const AbilityRequest &request,
105         const AppExecFwk::ExtensionAbilityInfo &extensionInfo);
106 
107     bool FilterAbilityList(const Want &want, std::vector<AppExecFwk::AbilityInfo> &abilityInfos,
108         std::vector<AppExecFwk::ExtensionAbilityInfo> extensionInfos, int32_t userId);
109     sptr<AppExecFwk::IDefaultApp> GetDefaultAppProxy();
110 
111     void GetEcologicalCallerInfo(const Want &want, ErmsCallerInfo &callerInfo, int32_t userId);
112 
113     void AddIdentity(int32_t tokenId, std::string identity);
114 
115     void AddAbilityInfoToDialogInfos(const AddInfoParam &param, std::vector<DialogAppInfo> &dialogAppInfos);
116 
117     bool IsExistDefaultApp(int32_t userId, const std::string &typeName);
118 
119     void SetTargetLinkInfo(const std::vector<AppExecFwk::SkillUriForAbilityAndExtension> &skillUri, Want &want);
120 
121     void OnlyKeepReserveApp(std::vector<AppExecFwk::AbilityInfo> &abilityInfos,
122         std::vector<AppExecFwk::ExtensionAbilityInfo> &extensionInfos, const AbilityRequest &request);
123 
124     bool IsActionImplicitStart(const Want &want, bool findDeafultApp);
125 
126     int CheckImplicitCallPermission(const AbilityRequest& abilityRequest);
127 
128     void TrustlistIntersectionProcess(const AbilityRequest &request,
129         std::vector<DialogAppInfo> &dialogAppInfos, int32_t userId);
130 
131     int32_t FindAppClone(std::vector<AppExecFwk::AbilityInfo> &abilityInfos,
132         std::vector<AppExecFwk::ExtensionAbilityInfo> extensionInfos, bool &isAppCloneSelector);
133 
134     bool FindAbilityAppClone(std::vector<AppExecFwk::AbilityInfo> &abilityInfos);
135     bool FindExtensionAppClone(std::vector<AppExecFwk::ExtensionAbilityInfo> &extensionInfos);
136 
137 private:
138     bool IsExtensionInWhiteList(AppExecFwk::ExtensionAbilityType type);
139     ffrt::mutex identityListLock_;
140     std::list<IdentityNode> identityList_;
141     std::shared_ptr<AppExecFwk::BundleMgrHelper> iBundleManagerHelper_;
142 };
143 }  // namespace AAFwk
144 }  // namespace OHOS
145 #endif  // OHOS_ABILITY_RUNTIME_IMPLICIT_START_PROCESSOR_H