1 /* 2 * Copyright (c) 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 16 #include "start_ability_handler.h" 17 18 #include "permission_verification.h" 19 #ifdef WITH_DLP 20 #include "dlp_utils.h" 21 #endif // WITH_DLP 22 23 namespace OHOS { 24 namespace AAFwk { IsCallerSandboxApp()25bool StartAbilityParams::IsCallerSandboxApp() 26 { 27 return GetCallerAppIndex() > 0; 28 } 29 30 #ifdef WITH_DLP OtherAppsAccessDlp()31bool StartAbilityParams::OtherAppsAccessDlp() 32 { 33 if (otherAppsAccessDlp.has_value()) { 34 return otherAppsAccessDlp.value(); 35 } 36 otherAppsAccessDlp = DlpUtils::OtherAppsAccessDlpCheck(callerToken, want); 37 return otherAppsAccessDlp.value(); 38 } 39 DlpAccessOtherApps()40bool StartAbilityParams::DlpAccessOtherApps() 41 { 42 if (dlpAccessOtherApps.has_value()) { 43 return dlpAccessOtherApps.value(); 44 } 45 dlpAccessOtherApps = DlpUtils::DlpAccessOtherAppsCheck(callerToken, want); 46 return dlpAccessOtherApps.value(); 47 } 48 SandboxExternalAuth()49bool StartAbilityParams::SandboxExternalAuth() 50 { 51 if (sandboxExternalAuth.has_value()) { 52 return sandboxExternalAuth.value(); 53 } 54 auto record = GetCallerRecord(); 55 if (!record) { 56 sandboxExternalAuth = false; 57 return false; 58 } 59 sandboxExternalAuth = DlpUtils::SandboxAuthCheck(*record, want); 60 return sandboxExternalAuth.value(); 61 } 62 #endif // WITH_DLP 63 IsCallerSysApp()64bool StartAbilityParams::IsCallerSysApp() 65 { 66 if (isCallerSysApp.has_value()) { 67 return isCallerSysApp.value(); 68 } 69 isCallerSysApp = PermissionVerification::GetInstance()->IsSystemAppCall(); 70 return isCallerSysApp.value(); 71 } 72 GetCallerRecord()73std::shared_ptr<AbilityRecord> StartAbilityParams::GetCallerRecord() 74 { 75 if (callerRecord.has_value()) { 76 return callerRecord.value(); 77 } 78 79 if (callerToken) { 80 callerRecord = Token::GetAbilityRecordByToken(callerToken); 81 } else { 82 callerRecord = nullptr; 83 } 84 return callerRecord.value(); 85 } 86 GetCallerAppIndex()87int32_t StartAbilityParams::GetCallerAppIndex() 88 { 89 if (callerAppIndex.has_value()) { 90 return callerAppIndex.value(); 91 } 92 auto record = GetCallerRecord(); 93 callerAppIndex = record ? record->GetAppIndex() : 0; 94 return callerAppIndex.value(); 95 } 96 BuildEventInfo()97EventInfo StartAbilityParams::BuildEventInfo() 98 { 99 EventInfo eventInfo; 100 eventInfo.userId = userId; 101 eventInfo.bundleName = want.GetElement().GetBundleName(); 102 eventInfo.moduleName = want.GetElement().GetModuleName(); 103 eventInfo.abilityName = want.GetElement().GetAbilityName(); 104 return eventInfo; 105 } 106 } // namespace AAFwk 107 } // namespace OHOS