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