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 deviceType; 46 std::string typeName; 47 std::vector<std::string> infoNames; 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); 63 64 void ResetCallingIdentityAsCaller(int32_t tokenId); 65 66 int NotifyCreateModalDialog(AbilityRequest &abilityRequest, const Want &want, int32_t userId, 67 std::vector<DialogAppInfo> &dialogAppInfos); 68 69 private: 70 int GenerateAbilityRequestByAction(int32_t userId, AbilityRequest &request, 71 std::vector<DialogAppInfo> &dialogAppInfos, std::string &deviceType, bool isMoreHapList); 72 std::string MatchTypeAndUri(const AAFwk::Want &want); 73 std::shared_ptr<AppExecFwk::BundleMgrHelper> GetBundleManagerHelper(); 74 std::vector<std::string> SplitStr(const std::string& str, char delimiter); 75 int QueryBmsAppInfos(AbilityRequest &request, int32_t userId, std::vector<DialogAppInfo> &dialogAppInfos); 76 77 using StartAbilityClosure = std::function<int32_t()>; 78 int CallStartAbilityInner(int32_t userId, const Want &want, const StartAbilityClosure &callBack, 79 const AbilityCallType &callType); 80 81 int32_t ImplicitStartAbilityInner(const Want &targetWant, const AbilityRequest &request, int32_t userId); 82 83 bool CheckImplicitStartExtensionIsValid(const AbilityRequest &request, 84 const AppExecFwk::ExtensionAbilityInfo &extensionInfo); 85 86 bool FilterAbilityList(const Want &want, std::vector<AppExecFwk::AbilityInfo> &abilityInfos, 87 std::vector<AppExecFwk::ExtensionAbilityInfo> extensionInfos, int32_t userId); 88 sptr<AppExecFwk::IDefaultApp> GetDefaultAppProxy(); 89 90 void GetEcologicalCallerInfo(const Want &want, ErmsCallerInfo &callerInfo, int32_t userId); 91 92 void AddIdentity(int32_t tokenId, std::string identity); 93 94 void AddAbilityInfoToDialogInfos(const AddInfoParam ¶m, std::vector<DialogAppInfo> &dialogAppInfos); 95 96 bool IsExistDefaultApp(int32_t userId, const std::string &typeName); 97 98 bool IsCallFromAncoShellOrBroker(const sptr<IRemoteObject> &token); 99 100 private: 101 const static std::vector<std::string> blackList; 102 const static std::unordered_set<AppExecFwk::ExtensionAbilityType> extensionWhiteList; 103 std::shared_ptr<AppExecFwk::BundleMgrHelper> iBundleManagerHelper_; 104 ffrt::mutex identityListLock_; 105 std::list<IdentityNode> identityList_; 106 }; 107 } // namespace AAFwk 108 } // namespace OHOS 109 #endif // OHOS_ABILITY_RUNTIME_IMPLICIT_START_PROCESSOR_H