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 AppExecFwk::AbilityInfo abilityInfo; 46 AppExecFwk::ExtensionProcessMode extensionProcessMode = AppExecFwk::ExtensionProcessMode::UNDEFINED; 47 int32_t status = ERR_OK; 48 }; 49 50 struct StartAbilityUtils { 51 static bool GetAppIndex(const Want &want, sptr<IRemoteObject> callerToken, int32_t &appIndex); 52 static bool GetApplicationInfo(const std::string &bundleName, int32_t userId, 53 AppExecFwk::ApplicationInfo &appInfo); 54 static bool GetCallerAbilityInfo(const sptr<IRemoteObject> &callerToken, 55 AppExecFwk::AbilityInfo &abilityInfo); 56 static int32_t CheckAppProvisionMode(const Want& want, int32_t userId); 57 static int32_t CheckAppProvisionMode(const std::string& bundleName, int32_t userId); 58 static std::vector<int32_t> GetCloneAppIndexes(const std::string &bundleName, int32_t userId); 59 60 static bool IsCallFromAncoShellOrBroker(const sptr<IRemoteObject> &callerToken); 61 62 static thread_local std::shared_ptr<StartAbilityInfo> startAbilityInfo; 63 static thread_local std::shared_ptr<StartAbilityInfo> callerAbilityInfo; 64 static thread_local bool skipCrowTest; 65 static thread_local bool skipStartOther; 66 static thread_local bool skipErms; 67 static thread_local int32_t ermsResultCode; 68 static thread_local bool isWantWithAppCloneIndex; 69 static thread_local bool ermsSupportBackToCallerFlag; 70 }; 71 72 struct StartAbilityInfoWrap { 73 StartAbilityInfoWrap(const Want &want, int32_t validUserId, int32_t appIndex, 74 const sptr<IRemoteObject> &callerToken, bool isExtension = false); 75 StartAbilityInfoWrap(); 76 ~StartAbilityInfoWrap(); 77 void SetStartAbilityInfo(const AppExecFwk::AbilityInfo& abilityInfo); 78 }; 79 } 80 } 81 #endif // OHOS_ABILITY_RUNTIME_START_ABILITY_UTILS_H