• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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 IMF_TEST_IDENTITY_CHECKER_MOCK_H
17 #define IMF_TEST_IDENTITY_CHECKER_MOCK_H
18 
19 #include "identity_checker.h"
20 
21 namespace OHOS {
22 namespace MiscServices {
23 class IdentityCheckerMock : public IdentityChecker {
24 public:
25     IdentityCheckerMock() = default;
26     virtual ~IdentityCheckerMock() = default;
27     bool IsFocused(int64_t callingPid, uint32_t callingTokenId, int64_t focusedPid = INVALID_PID,
28         bool isAttach = false, sptr<IRemoteObject> abilityToken = nullptr) override
29     {
30         return isFocused_;
31     }
IsSystemApp(uint64_t fullTokenId)32     bool IsSystemApp(uint64_t fullTokenId) override
33     {
34         return isSystemApp_;
35     }
IsBundleNameValid(uint32_t tokenId,const std::string & validBundleName)36     bool IsBundleNameValid(uint32_t tokenId, const std::string &validBundleName) override
37     {
38         return isBundleNameValid_;
39     }
HasPermission(uint32_t tokenId,const std::string & permission)40     bool HasPermission(uint32_t tokenId, const std::string &permission) override
41     {
42         return hasPermission_;
43     }
IsBroker(Security::AccessToken::AccessTokenID tokenId)44     bool IsBroker(Security::AccessToken::AccessTokenID tokenId) override
45     {
46         return isBroker_;
47     }
IsNativeSa(Security::AccessToken::AccessTokenID tokenId)48     bool IsNativeSa(Security::AccessToken::AccessTokenID tokenId) override
49     {
50         return isNativeSa_;
51     }
IsFormShell(Security::AccessToken::AccessTokenID tokenId)52     bool IsFormShell(Security::AccessToken::AccessTokenID tokenId) override
53     {
54         return isFormShell_;
55     }
GetBundleNameByToken(uint32_t tokenId)56     std::string GetBundleNameByToken(uint32_t tokenId) override
57         {
58             return bundleName_;
59     }
GetDisplayIdByWindowId(int32_t callingWindowId)60     uint64_t GetDisplayIdByWindowId(int32_t callingWindowId) override
61     {
62         return 0;
63     }
IsSpecialSaUid()64     bool IsSpecialSaUid() override
65     {
66         return isSpecialSaUid_;
67     }
ResetParam()68     static void ResetParam()
69     {
70         isFocused_ = false;
71         isSystemApp_ = false;
72         isBundleNameValid_ = false;
73         hasPermission_ = false;
74         isBroker_ = false;
75         isFormShell_ = false;
76         isNativeSa_ = false;
77         isSpecialSaUid_ = false;
78         bundleName_ = "";
79     }
SetFocused(bool isFocused)80     static void SetFocused(bool isFocused)
81     {
82         isFocused_ = isFocused;
83     }
SetSystemApp(bool isSystemApp)84     static void SetSystemApp(bool isSystemApp)
85     {
86         isSystemApp_ = isSystemApp;
87     }
SetBundleNameValid(bool isBundleNameValid)88     static void SetBundleNameValid(bool isBundleNameValid)
89     {
90         isBundleNameValid_ = isBundleNameValid;
91     }
SetBroker(bool isBroker)92     static void SetBroker(bool isBroker)
93     {
94         isBroker_ = isBroker;
95     }
SetNativeSa(bool isNativeSa)96     static void SetNativeSa(bool isNativeSa)
97     {
98         isNativeSa_ = isNativeSa;
99     }
SetPermission(bool hasPermission)100     static void SetPermission(bool hasPermission)
101     {
102         hasPermission_ = hasPermission;
103     }
104 
SetBundleName(const std::string & bundleName)105     static void SetBundleName(const std::string &bundleName)
106     {
107         bundleName_ = bundleName;
108     }
SetSpecialSaUid(bool isSpecialSaUid)109     static void SetSpecialSaUid(bool isSpecialSaUid)
110     {
111         isSpecialSaUid_ = isSpecialSaUid;
112     }
113 
114 private:
115     static bool isFocused_;
116     static bool isSystemApp_;
117     static bool isBundleNameValid_;
118     static bool hasPermission_;
119     static bool isBroker_;
120     static bool isNativeSa_;
121     static bool isFormShell_;
122     static bool isSpecialSaUid_;
123     static std::string bundleName_;
124 };
125 bool IdentityCheckerMock::isFocused_ { false };
126 bool IdentityCheckerMock::isSystemApp_ { false };
127 bool IdentityCheckerMock::isBundleNameValid_ { false };
128 bool IdentityCheckerMock::hasPermission_ { false };
129 bool IdentityCheckerMock::isBroker_ { false };
130 bool IdentityCheckerMock::isNativeSa_ { false };
131 bool IdentityCheckerMock::isFormShell_ { false };
132 bool IdentityCheckerMock::isSpecialSaUid_ { false };
133 std::string IdentityCheckerMock::bundleName_;
134 } // namespace MiscServices
135 } // namespace OHOS
136 #endif // IMF_TEST_IDENTITY_CHECKER_MOCK_H
137