• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <gmock/gmock.h>
20 
21 #include "ipc_skeleton.h"
22 #include "singleton.h"
23 #include "want.h"
24 #include "mock_my_flag.h"
25 
26 namespace OHOS {
27 namespace AAFwk {
28 
29 class PermissionVerification : public DelayedSingleton<PermissionVerification> {
30 public:
31 struct VerificationInfo {
32     bool visible = false;
33     bool isBackgroundCall = true;
34     bool associatedWakeUp = false;
35     uint32_t accessTokenId = 0;
36     int32_t apiTargetVersion = 0;
37 };
38 
39     PermissionVerification() = default;
40     ~PermissionVerification() = default;
41 
42     bool VerifyCallingPermission(const std::string &permissionName) const;
43 
44     bool IsSACall() const;
45 
46     bool IsShellCall() const;
47 
48     bool IsGatewayCall() const;
49 
50     bool CheckSpecificSystemAbilityAccessPermission() const;
51 
52     bool VerifyRunningInfoPerm() const;
53 
54     bool VerifyControllerPerm() const;
55 
56     bool VerifyDlpPermission(Want &want) const;
57 
58     int VerifyAccountPermission() const;
59 
60     bool VerifyMissionPermission() const;
61 
62     int VerifyAppStateObserverPermission() const;
63 
64     int32_t VerifyUpdateConfigurationPerm() const;
65 
66     bool VerifyInstallBundlePermission() const;
67 
68     bool VerifyGetBundleInfoPrivilegedPermission() const;
69 
70     int CheckCallDataAbilityPermission(const VerificationInfo &verificationInfo) const;
71 
72     int CheckCallServiceAbilityPermission(const VerificationInfo &verificationInfo) const;
73 
74     int CheckCallAbilityPermission(const VerificationInfo &verificationInfo) const;
75 
76     int CheckCallServiceExtensionPermission(const VerificationInfo &verificationInfo) const;
77 
78     int CheckStartByCallPermission(const VerificationInfo &verificationInfo) const;
79 
80     unsigned int GetCallingTokenID() const;
81 
82     bool JudgeStartInvisibleAbility(const uint32_t accessTokenId, const bool visible) const;
83 
84     bool JudgeStartAbilityFromBackground(const bool isBackgroundCall) const;
85 
86     bool JudgeAssociatedWakeUp(const uint32_t accessTokenId, const bool associatedWakeUp) const;
87 
88     int JudgeInvisibleAndBackground(const VerificationInfo &verificationInfo) const;
89 
IsCallFromSameAccessToken(const uint32_t accessTokenId)90     inline bool IsCallFromSameAccessToken(const uint32_t accessTokenId) const
91     {
92         return IPCSkeleton::GetCallingTokenID() == accessTokenId;
93     }
94 };
95 }  // namespace AAFwk
96 }  // namespace OHOS
97 #endif // OHOS_ABILITY_RUNTIME_PERMISSION_VERIFICATION_H