1 /* 2 * Copyright (c) 2022 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_PERMISSION_VERIFICATION_H 17 #define OHOS_ABILITY_RUNTIME_PERMISSION_VERIFICATION_H 18 19 #include "ipc_skeleton.h" 20 #include "singleton.h" 21 #include "want.h" 22 23 namespace OHOS { 24 namespace AAFwk { 25 class PermissionVerification : public DelayedSingleton<PermissionVerification> { 26 public: 27 struct VerificationInfo { 28 bool visible = false; 29 bool isBackgroundCall = true; 30 bool associatedWakeUp = false; 31 uint32_t accessTokenId = 0; 32 int32_t apiTargetVersion = 0; 33 bool withContinuousTask = false; 34 }; 35 36 PermissionVerification() = default; 37 ~PermissionVerification() = default; 38 39 bool VerifyPermissionByTokenId(const int &tokenId, const std::string &permissionName) const; 40 41 bool VerifyCallingPermission(const std::string &permissionName) const; 42 43 bool IsSACall() const; 44 45 bool IsShellCall() const; 46 47 bool IsGatewayCall() const; 48 49 bool CheckSpecificSystemAbilityAccessPermission() const; 50 51 bool VerifyRunningInfoPerm() const; 52 53 bool VerifyControllerPerm() const; 54 55 bool VerifyDlpPermission(Want &want) const; 56 57 int VerifyAccountPermission() const; 58 59 bool VerifyMissionPermission() const; 60 61 int VerifyAppStateObserverPermission() const; 62 63 int32_t VerifyUpdateConfigurationPerm() const; 64 65 bool VerifyInstallBundlePermission() const; 66 67 bool VerifyGetBundleInfoPrivilegedPermission() const; 68 69 int CheckCallDataAbilityPermission(const VerificationInfo &verificationInfo, bool isShell) const; 70 71 int CheckCallServiceAbilityPermission(const VerificationInfo &verificationInfo) const; 72 73 int CheckCallAbilityPermission(const VerificationInfo &verificationInfo) const; 74 75 /** 76 * Check if Caller is allowed to start ServiceExtension(Stage) or DataShareExtension(Stage) 77 * 78 * @param verificationInfo, verificationInfo. 79 * @return Returns ERR_OK on check success, others on check failure. 80 */ 81 int CheckCallServiceExtensionPermission(const VerificationInfo &verificationInfo) const; 82 83 int CheckStartByCallPermission(const VerificationInfo &verificationInfo) const; 84 85 bool JudgeCallerIsAllowedToUseSystemAPI() const; 86 87 bool IsSystemAppCall() const; 88 89 bool VerifyPrepareTerminatePermission() const; 90 91 bool VerifyPrepareTerminatePermission(const int &tokenId) const; 92 93 private: 94 DISALLOW_COPY_AND_MOVE(PermissionVerification); 95 96 constexpr static int32_t API8 = 8; 97 98 unsigned int GetCallingTokenID() const; 99 100 bool JudgeStartInvisibleAbility(const uint32_t accessTokenId, const bool visible) const; 101 102 bool JudgeStartAbilityFromBackground(const bool isBackgroundCall, bool withContinuousTask = false) const; 103 104 bool JudgeAssociatedWakeUp(const uint32_t accessTokenId, const bool associatedWakeUp) const; 105 106 int JudgeInvisibleAndBackground(const VerificationInfo &verificationInfo) const; 107 IsCallFromSameAccessToken(const uint32_t accessTokenId)108 inline bool IsCallFromSameAccessToken(const uint32_t accessTokenId) const 109 { 110 return IPCSkeleton::GetCallingTokenID() == accessTokenId; 111 } 112 }; 113 } // namespace AAFwk 114 } // namespace OHOS 115 #endif // OHOS_ABILITY_RUNTIME_PERMISSION_VERIFICATION_H 116