1eace7efcSopenharmony_ci/* 2eace7efcSopenharmony_ci * Copyright (c) 2023 Huawei Device Co., Ltd. 3eace7efcSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4eace7efcSopenharmony_ci * you may not use this file except in compliance with the License. 5eace7efcSopenharmony_ci * You may obtain a copy of the License at 6eace7efcSopenharmony_ci * 7eace7efcSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8eace7efcSopenharmony_ci * 9eace7efcSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10eace7efcSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11eace7efcSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12eace7efcSopenharmony_ci * See the License for the specific language governing permissions and 13eace7efcSopenharmony_ci * limitations under the License. 14eace7efcSopenharmony_ci */ 15eace7efcSopenharmony_ci 16eace7efcSopenharmony_ci#include "start_ability_handler.h" 17eace7efcSopenharmony_ci 18eace7efcSopenharmony_ci#include "permission_verification.h" 19eace7efcSopenharmony_ci#ifdef WITH_DLP 20eace7efcSopenharmony_ci#include "dlp_utils.h" 21eace7efcSopenharmony_ci#endif // WITH_DLP 22eace7efcSopenharmony_ci 23eace7efcSopenharmony_cinamespace OHOS { 24eace7efcSopenharmony_cinamespace AAFwk { 25eace7efcSopenharmony_cibool StartAbilityParams::IsCallerSandboxApp() 26eace7efcSopenharmony_ci{ 27eace7efcSopenharmony_ci return GetCallerAppIndex() > 0; 28eace7efcSopenharmony_ci} 29eace7efcSopenharmony_ci 30eace7efcSopenharmony_ci#ifdef WITH_DLP 31eace7efcSopenharmony_cibool StartAbilityParams::OtherAppsAccessDlp() 32eace7efcSopenharmony_ci{ 33eace7efcSopenharmony_ci if (otherAppsAccessDlp.has_value()) { 34eace7efcSopenharmony_ci return otherAppsAccessDlp.value(); 35eace7efcSopenharmony_ci } 36eace7efcSopenharmony_ci otherAppsAccessDlp = DlpUtils::OtherAppsAccessDlpCheck(callerToken, want); 37eace7efcSopenharmony_ci return otherAppsAccessDlp.value(); 38eace7efcSopenharmony_ci} 39eace7efcSopenharmony_ci 40eace7efcSopenharmony_cibool StartAbilityParams::DlpAccessOtherApps() 41eace7efcSopenharmony_ci{ 42eace7efcSopenharmony_ci if (dlpAccessOtherApps.has_value()) { 43eace7efcSopenharmony_ci return dlpAccessOtherApps.value(); 44eace7efcSopenharmony_ci } 45eace7efcSopenharmony_ci dlpAccessOtherApps = DlpUtils::DlpAccessOtherAppsCheck(callerToken, want); 46eace7efcSopenharmony_ci return dlpAccessOtherApps.value(); 47eace7efcSopenharmony_ci} 48eace7efcSopenharmony_ci 49eace7efcSopenharmony_cibool StartAbilityParams::SandboxExternalAuth() 50eace7efcSopenharmony_ci{ 51eace7efcSopenharmony_ci if (sandboxExternalAuth.has_value()) { 52eace7efcSopenharmony_ci return sandboxExternalAuth.value(); 53eace7efcSopenharmony_ci } 54eace7efcSopenharmony_ci auto record = GetCallerRecord(); 55eace7efcSopenharmony_ci if (!record) { 56eace7efcSopenharmony_ci sandboxExternalAuth = false; 57eace7efcSopenharmony_ci return false; 58eace7efcSopenharmony_ci } 59eace7efcSopenharmony_ci sandboxExternalAuth = DlpUtils::SandboxAuthCheck(*record, want); 60eace7efcSopenharmony_ci return sandboxExternalAuth.value(); 61eace7efcSopenharmony_ci} 62eace7efcSopenharmony_ci#endif // WITH_DLP 63eace7efcSopenharmony_ci 64eace7efcSopenharmony_cibool StartAbilityParams::IsCallerSysApp() 65eace7efcSopenharmony_ci{ 66eace7efcSopenharmony_ci if (isCallerSysApp.has_value()) { 67eace7efcSopenharmony_ci return isCallerSysApp.value(); 68eace7efcSopenharmony_ci } 69eace7efcSopenharmony_ci isCallerSysApp = PermissionVerification::GetInstance()->IsSystemAppCall(); 70eace7efcSopenharmony_ci return isCallerSysApp.value(); 71eace7efcSopenharmony_ci} 72eace7efcSopenharmony_ci 73eace7efcSopenharmony_cistd::shared_ptr<AbilityRecord> StartAbilityParams::GetCallerRecord() 74eace7efcSopenharmony_ci{ 75eace7efcSopenharmony_ci if (callerRecord.has_value()) { 76eace7efcSopenharmony_ci return callerRecord.value(); 77eace7efcSopenharmony_ci } 78eace7efcSopenharmony_ci 79eace7efcSopenharmony_ci if (callerToken) { 80eace7efcSopenharmony_ci callerRecord = Token::GetAbilityRecordByToken(callerToken); 81eace7efcSopenharmony_ci } else { 82eace7efcSopenharmony_ci callerRecord = nullptr; 83eace7efcSopenharmony_ci } 84eace7efcSopenharmony_ci return callerRecord.value(); 85eace7efcSopenharmony_ci} 86eace7efcSopenharmony_ci 87eace7efcSopenharmony_ciint32_t StartAbilityParams::GetCallerAppIndex() 88eace7efcSopenharmony_ci{ 89eace7efcSopenharmony_ci if (callerAppIndex.has_value()) { 90eace7efcSopenharmony_ci return callerAppIndex.value(); 91eace7efcSopenharmony_ci } 92eace7efcSopenharmony_ci auto record = GetCallerRecord(); 93eace7efcSopenharmony_ci callerAppIndex = record ? record->GetAppIndex() : 0; 94eace7efcSopenharmony_ci return callerAppIndex.value(); 95eace7efcSopenharmony_ci} 96eace7efcSopenharmony_ci 97eace7efcSopenharmony_ciEventInfo StartAbilityParams::BuildEventInfo() 98eace7efcSopenharmony_ci{ 99eace7efcSopenharmony_ci EventInfo eventInfo; 100eace7efcSopenharmony_ci eventInfo.userId = userId; 101eace7efcSopenharmony_ci eventInfo.bundleName = want.GetElement().GetBundleName(); 102eace7efcSopenharmony_ci eventInfo.moduleName = want.GetElement().GetModuleName(); 103eace7efcSopenharmony_ci eventInfo.abilityName = want.GetElement().GetAbilityName(); 104eace7efcSopenharmony_ci return eventInfo; 105eace7efcSopenharmony_ci} 106eace7efcSopenharmony_ci} // namespace AAFwk 107eace7efcSopenharmony_ci} // namespace OHOS