1 /* 2 * Copyright (c) 2022-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 #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 AppExecFwk::AbilityInfo info; 41 int32_t userId = 0; 42 bool isExtension = false; 43 bool isMoreHapList = false; 44 bool withDefault = false; 45 std::string typeName; 46 std::vector<std::string> infoNames; 47 bool isExistDefaultApp = false; 48 }; 49 using namespace OHOS::EcologicalRuleMgrService; 50 using ErmsCallerInfo = OHOS::EcologicalRuleMgrService::AbilityCallerInfo; 51 /** 52 * @class ImplicitStartProcessor 53 * ImplicitStartProcessor. 54 */ 55 class ImplicitStartProcessor : public std::enable_shared_from_this<ImplicitStartProcessor> { 56 public: 57 explicit ImplicitStartProcessor() = default; 58 virtual ~ImplicitStartProcessor() = default; 59 60 static bool IsImplicitStartAction(const Want &want); 61 62 int ImplicitStartAbility(AbilityRequest &request, int32_t userId, int32_t windowMode = 0, 63 const std::string &replaceWantString = "", bool isAppCloneSelector = false); 64 65 void ResetCallingIdentityAsCaller(int32_t tokenId, bool flag); 66 67 void RemoveIdentity(int32_t tokenId); 68 69 private: 70 int GenerateAbilityRequestByAction(int32_t userId, AbilityRequest &request, 71 std::vector<DialogAppInfo> &dialogAppInfos, bool isMoreHapList); 72 73 int GenerateAbilityRequestByAppIndexes(int32_t userId, AbilityRequest &request, 74 std::vector<DialogAppInfo> &dialogAppInfos); 75 76 int FindExtensionInfo(const Want &want, int32_t flags, int32_t userId, int32_t appIndex, 77 AppExecFwk::AbilityInfo &abilityInfo); 78 79 std::string MatchTypeAndUri(const AAFwk::Want &want); 80 std::shared_ptr<AppExecFwk::BundleMgrHelper> GetBundleManagerHelper(); 81 std::vector<std::string> SplitStr(const std::string& str, char delimiter); 82 int QueryBmsAppInfos(AbilityRequest &request, int32_t userId, std::vector<DialogAppInfo> &dialogAppInfos); 83 84 using StartAbilityClosure = std::function<int32_t()>; 85 int CallStartAbilityInner(int32_t userId, const Want &want, const StartAbilityClosure &callBack, 86 const AbilityCallType &callType); 87 88 int32_t ImplicitStartAbilityInner(const Want &targetWant, const AbilityRequest &request, int32_t userId); 89 90 bool CheckImplicitStartExtensionIsValid(const AbilityRequest &request, 91 const AppExecFwk::ExtensionAbilityInfo &extensionInfo); 92 93 bool FilterAbilityList(const Want &want, std::vector<AppExecFwk::AbilityInfo> &abilityInfos, 94 std::vector<AppExecFwk::ExtensionAbilityInfo> extensionInfos, int32_t userId); 95 sptr<AppExecFwk::IDefaultApp> GetDefaultAppProxy(); 96 97 void GetEcologicalCallerInfo(const Want &want, ErmsCallerInfo &callerInfo, int32_t userId); 98 99 void AddIdentity(int32_t tokenId, std::string identity); 100 101 void AddAbilityInfoToDialogInfos(const AddInfoParam ¶m, std::vector<DialogAppInfo> &dialogAppInfos); 102 103 bool IsExistDefaultApp(int32_t userId, const std::string &typeName); 104 105 void SetTargetLinkInfo(const std::vector<AppExecFwk::SkillUriForAbilityAndExtension> &skillUri, Want &want); 106 107 void OnlyKeepReserveApp(std::vector<AppExecFwk::AbilityInfo> &abilityInfos, 108 std::vector<AppExecFwk::ExtensionAbilityInfo> &extensionInfos, const AbilityRequest &request); 109 110 int CheckImplicitCallPermission(const AbilityRequest& abilityRequest); 111 112 private: 113 sptr<AppExecFwk::IBundleMgr> iBundleManager_; 114 bool IsExtensionInWhiteList(AppExecFwk::ExtensionAbilityType type); 115 ffrt::mutex identityListLock_; 116 std::list<IdentityNode> identityList_; 117 std::shared_ptr<AppExecFwk::BundleMgrHelper> iBundleManagerHelper_; 118 }; 119 } // namespace AAFwk 120 } // namespace OHOS 121 #endif // OHOS_ABILITY_RUNTIME_IMPLICIT_START_PROCESSOR_H