• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 "softbus_permission_acl_mock.h"
17 
18 namespace OHOS::AccountSA {
19 
QueryActiveOsAccountIds(std::vector<int32_t> & ids)20     OHOS::ErrCode OsAccountManager::QueryActiveOsAccountIds(std::vector<int32_t> &ids)
21     {
22         return ERR_OK;
23     }
24 
IsOsAccountVerified(const int32_t id,bool & isVerified)25     OHOS::ErrCode OsAccountManager::IsOsAccountVerified(const int32_t id, bool &isVerified)
26     {
27         return ERR_OK;
28     }
29 }
30 
31 namespace OHOS {
SoftbusPermissionACLInterfaceMock()32 SoftbusPermissionACLInterfaceMock::SoftbusPermissionACLInterfaceMock()
33 {
34     mock.store(this);
35 }
36 
~SoftbusPermissionACLInterfaceMock()37 SoftbusPermissionACLInterfaceMock::~SoftbusPermissionACLInterfaceMock()
38 {
39     mock.store(nullptr);
40 }
41 
IPCSkeletonMock()42 IPCSkeletonMock::IPCSkeletonMock()
43 {
44     mock.store(this);
45 }
46 
~IPCSkeletonMock()47 IPCSkeletonMock::~IPCSkeletonMock()
48 {
49     mock.store(nullptr);
50 }
51 
GetCallingUid()52 pid_t IPCSkeleton::GetCallingUid()
53 {
54     auto mock = IPCSkeletonMock::GetMock();
55     if (mock == nullptr) {
56         return -1;
57     }
58     return mock->GetCallingUid();
59 }
60 
GetFirstFullTokenID()61 uint64_t IPCSkeleton::GetFirstFullTokenID()
62 {
63     auto mock = IPCSkeletonMock::GetMock();
64     if (mock == nullptr) {
65         return -1;
66     }
67     return mock->GetFirstFullTokenID();
68 }
69 
GetCallingFullTokenID()70 uint64_t IPCSkeleton::GetCallingFullTokenID()
71 {
72     auto mock = IPCSkeletonMock::GetMock();
73     if (mock == nullptr) {
74         return -1;
75     }
76     return mock->GetCallingFullTokenID();
77 }
78 
79 extern "C"{
LnnGetLocalStrInfo(InfoKey key,char * info,uint32_t len)80 int32_t LnnGetLocalStrInfo(InfoKey key, char *info, uint32_t len)
81 {
82     return SoftbusPermissionACLInterfaceMock::GetMock()->LnnGetLocalStrInfo(key, info, len);
83 }
84 
SoftBusGetAccessTokenType(uint64_t tokenId)85 int32_t SoftBusGetAccessTokenType(uint64_t tokenId)
86 {
87     return SoftbusPermissionACLInterfaceMock::GetMock()->SoftBusGetAccessTokenType(tokenId);
88 }
89 
LnnGetRemoteStrInfo(const char * networkId,InfoKey key,char * info,uint32_t len)90 int32_t LnnGetRemoteStrInfo(const char *networkId, InfoKey key, char *info, uint32_t len)
91 {
92     return SoftbusPermissionACLInterfaceMock::GetMock()->LnnGetRemoteStrInfo(networkId, key, info, len);
93 }
94 
TransGetTokenIdBySessionName(const char * sessionName,uint64_t * tokenId)95 int32_t TransGetTokenIdBySessionName(const char *sessionName, uint64_t *tokenId)
96 {
97     return SoftbusPermissionACLInterfaceMock::GetMock()->TransGetTokenIdBySessionName(sessionName, tokenId);
98 }
99 
GetOsAccountLocalIdFromUidAdapter(const int32_t uid)100 int32_t GetOsAccountLocalIdFromUidAdapter(const int32_t uid)
101 {
102     return SoftbusPermissionACLInterfaceMock::GetMock()->GetOsAccountLocalIdFromUidAdapter(uid);
103 }
104 
TransProxyGetUidAndPidBySessionName(const char * sessionName,int32_t * uid,int32_t * pid)105 int32_t TransProxyGetUidAndPidBySessionName(const char *sessionName, int32_t *uid, int32_t *pid)
106 {
107     return SoftbusPermissionACLInterfaceMock::GetMock()->TransProxyGetUidAndPidBySessionName(sessionName, uid, pid);
108 }
109 
LnnGetNetworkIdByUuid(const char * uuid,char * buf,uint32_t len)110 int32_t LnnGetNetworkIdByUuid(const char *uuid, char *buf, uint32_t len)
111 {
112     return SoftbusPermissionACLInterfaceMock::GetMock()->LnnGetNetworkIdByUuid(uuid, buf, len);
113 }
114 
IsOsAccountForegroundAdapter(const int32_t appUserId,bool & isForegroundUser)115 int32_t IsOsAccountForegroundAdapter(const int32_t appUserId, bool &isForegroundUser)
116 {
117     return SoftbusPermissionACLInterfaceMock::GetMock()->IsOsAccountForegroundAdapter(appUserId, isForegroundUser);
118 }
119 
GetOsAccountUidByUserId(char * id,uint32_t idLen,uint32_t * len,int32_t userId)120 int32_t GetOsAccountUidByUserId(char *id, uint32_t idLen, uint32_t *len, int32_t userId)
121 {
122     return SoftbusPermissionACLInterfaceMock::GetMock()->GetOsAccountUidByUserId(id, idLen, len, userId);
123 }
124 
StrStartWith(const char * string,const char * target)125 bool StrStartWith(const char *string, const char *target)
126 {
127     return SoftbusPermissionACLInterfaceMock::GetMock()->StrStartWith(string, target);
128 }
129 
CheckDBinder(const char * sessionName)130 bool CheckDBinder(const char *sessionName)
131 {
132     return SoftbusPermissionACLInterfaceMock::GetMock()->CheckDBinder(sessionName);
133 }
134 }
135 } // namespace OHOS
136 
137 namespace OHOS::DistributedDeviceProfile {
GetAccessControlProfile(std::map<std::string,std::string> parms,std::vector<AccessControlProfile> & profile)138 int32_t DistributedDeviceProfileClient::GetAccessControlProfile(std::map<std::string, std::string> parms,
139     std::vector<AccessControlProfile>& profile)
140 {
141     int32_t times = 3;
142     if (profile.empty()) {
143         int32_t bindLevelTest = 1;
144         int32_t bindTypeTest = 4;
145         for (int i = 0; i < times; ++i) {
146             AccessControlProfile item;
147             item.SetBindLevel(bindLevelTest++);
148             item.SetBindType(bindTypeTest++);
149             profile.push_back(item);
150         }
151     }
152     return 0;
153 }
154 }
155