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