1 /*
2 * Copyright (c) 2024-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 "device_manager_agent_mock.h"
17
18 namespace OHOS {
19 namespace Storage {
20 namespace DistributedFile {
21 using namespace std;
22 const int32_t FIRST = 1;
23 const int32_t SECOND = 2;
24 const int32_t THIRD = 3;
25 const int32_t FOURTH = 4;
DeviceManagerAgent()26 DeviceManagerAgent::DeviceManagerAgent() : DfsuActor<DeviceManagerAgent>(this,
27 std::numeric_limits<uint32_t>::max()) {}
28
~DeviceManagerAgent()29 DeviceManagerAgent::~DeviceManagerAgent() {}
30
StartInstance()31 void DeviceManagerAgent::StartInstance()
32 {
33 return;
34 }
35
StopInstance()36 void DeviceManagerAgent::StopInstance()
37 {
38 return;
39 }
40
Start()41 void DeviceManagerAgent::Start()
42 {
43 return;
44 }
45
Stop()46 void DeviceManagerAgent::Stop()
47 {
48 return;
49 }
50
JoinGroup(weak_ptr<MountPoint> mp)51 void DeviceManagerAgent::JoinGroup(weak_ptr<MountPoint> mp)
52 {
53 return;
54 }
55
QuitGroup(shared_ptr<MountPoint> mp)56 void DeviceManagerAgent::QuitGroup(shared_ptr<MountPoint> mp)
57 {
58 return;
59 }
60
OfflineAllDevice()61 void DeviceManagerAgent::OfflineAllDevice()
62 {
63 return;
64 }
65
ReconnectOnlineDevices()66 void DeviceManagerAgent::ReconnectOnlineDevices()
67 {
68 return;
69 }
70
FindNetworkBaseTrustRelation(bool isAccountless)71 std::shared_ptr<NetworkAgentTemplate> DeviceManagerAgent::FindNetworkBaseTrustRelation(bool isAccountless)
72 {
73 return nullptr;
74 }
75
GetNetworkType(const string & cid)76 int32_t DeviceManagerAgent::GetNetworkType(const string &cid)
77 {
78 return 0;
79 }
80
IsWifiNetworkType(int32_t networkType)81 bool DeviceManagerAgent::IsWifiNetworkType(int32_t networkType)
82 {
83 return true;
84 }
85
OnDeviceReady(const DistributedHardware::DmDeviceInfo & deviceInfo)86 void DeviceManagerAgent::OnDeviceReady(const DistributedHardware::DmDeviceInfo &deviceInfo)
87 {
88 return;
89 }
90
OnDeviceOffline(const DistributedHardware::DmDeviceInfo & deviceInfo)91 void DeviceManagerAgent::OnDeviceOffline(const DistributedHardware::DmDeviceInfo &deviceInfo)
92 {
93 return;
94 }
95
ClearCount(const DistributedHardware::DmDeviceInfo & deviceInfo)96 void DeviceManagerAgent::ClearCount(const DistributedHardware::DmDeviceInfo &deviceInfo)
97 {
98 return;
99 }
100
OnDeviceP2POnline(const DistributedHardware::DmDeviceInfo & deviceInfo)101 int32_t DeviceManagerAgent::OnDeviceP2POnline(const DistributedHardware::DmDeviceInfo &deviceInfo)
102 {
103 if (IDeviceManagerAgentMock::iDeviceManagerAgentMock_ == nullptr) {
104 return -1;
105 }
106 return IDeviceManagerAgentMock::iDeviceManagerAgentMock_->OnDeviceP2POnline(deviceInfo);
107 }
108
OnDeviceP2POffline(const DistributedHardware::DmDeviceInfo & deviceInfo)109 int32_t DeviceManagerAgent::OnDeviceP2POffline(const DistributedHardware::DmDeviceInfo &deviceInfo)
110 {
111 if (IDeviceManagerAgentMock::iDeviceManagerAgentMock_ == nullptr) {
112 return -1;
113 }
114 return IDeviceManagerAgentMock::iDeviceManagerAgentMock_->OnDeviceP2POffline(deviceInfo);
115 }
116
MountDfsCountOnly(const std::string & deviceId)117 bool DeviceManagerAgent::MountDfsCountOnly(const std::string &deviceId)
118 {
119 return true;
120 }
121
UMountDfsCountOnly(const std::string & deviceId,bool needClear)122 bool DeviceManagerAgent::UMountDfsCountOnly(const std::string &deviceId, bool needClear)
123 {
124 return true;
125 }
126
GetCurrentUserId()127 int32_t DeviceManagerAgent::GetCurrentUserId()
128 {
129 return 0;
130 }
131
GetStorageManager()132 void DeviceManagerAgent::GetStorageManager()
133 {
134 return;
135 }
136
AddNetworkId(uint32_t tokenId,const std::string & networkId)137 void DeviceManagerAgent::AddNetworkId(uint32_t tokenId, const std::string &networkId)
138 {
139 return;
140 }
141
RemoveNetworkId(uint32_t tokenId)142 void DeviceManagerAgent::RemoveNetworkId(uint32_t tokenId)
143 {
144 return;
145 }
146
RemoveNetworkIdByOne(uint32_t tokenId,const std::string & networkId)147 void DeviceManagerAgent::RemoveNetworkIdByOne(uint32_t tokenId, const std::string &networkId)
148 {
149 return;
150 }
151
RemoveNetworkIdForAllToken(const std::string & networkId)152 void DeviceManagerAgent::RemoveNetworkIdForAllToken(const std::string &networkId)
153 {
154 return;
155 }
156
ClearNetworkId()157 void DeviceManagerAgent::ClearNetworkId()
158 {
159 return;
160 }
161
GetNetworkIds(uint32_t tokenId)162 std::unordered_set<std::string> DeviceManagerAgent::GetNetworkIds(uint32_t tokenId)
163 {
164 if (IDeviceManagerAgentMock::iDeviceManagerAgentMock_ == nullptr) {
165 return {};
166 }
167 return IDeviceManagerAgentMock::iDeviceManagerAgentMock_->GetNetworkIds(tokenId);
168 }
169
MountDfsDocs(const std::string & networkId,const std::string & deviceId)170 int32_t DeviceManagerAgent::MountDfsDocs(const std::string &networkId, const std::string &deviceId)
171 {
172 if (IDeviceManagerAgentMock::iDeviceManagerAgentMock_ == nullptr) {
173 return -1;
174 }
175 return IDeviceManagerAgentMock::iDeviceManagerAgentMock_->MountDfsDocs(networkId, deviceId);
176 }
177
UMountDfsDocs(const std::string & networkId,const std::string & deviceId,bool needClear)178 int32_t DeviceManagerAgent::UMountDfsDocs(const std::string &networkId, const std::string &deviceId, bool needClear)
179 {
180 if (IDeviceManagerAgentMock::iDeviceManagerAgentMock_ == nullptr) {
181 return -1;
182 }
183 return IDeviceManagerAgentMock::iDeviceManagerAgentMock_->UMountDfsDocs(networkId, deviceId, needClear);
184 }
185
IncreaseMountDfsCount(const std::string & deviceId)186 void DeviceManagerAgent::IncreaseMountDfsCount(const std::string &deviceId)
187 {
188 return;
189 }
190
RemoveMountDfsCount(const std::string & deviceId)191 void DeviceManagerAgent::RemoveMountDfsCount(const std::string &deviceId)
192 {
193 return;
194 }
195
NotifyRemoteReverseObj(const std::string & networkId,int32_t status)196 void DeviceManagerAgent::NotifyRemoteReverseObj(const std::string &networkId, int32_t status)
197 {
198 return;
199 }
200
AddRemoteReverseObj(uint32_t callingTokenId,sptr<IFileDfsListener> remoteReverseObj)201 int32_t DeviceManagerAgent::AddRemoteReverseObj(uint32_t callingTokenId, sptr<IFileDfsListener> remoteReverseObj)
202 {
203 if (IDeviceManagerAgentMock::iDeviceManagerAgentMock_ == nullptr) {
204 return -1;
205 }
206 return IDeviceManagerAgentMock::iDeviceManagerAgentMock_->AddRemoteReverseObj(callingTokenId, remoteReverseObj);
207 }
208
RemoveRemoteReverseObj(bool clear,uint32_t callingTokenId)209 int32_t DeviceManagerAgent::RemoveRemoteReverseObj(bool clear, uint32_t callingTokenId)
210 {
211 if (IDeviceManagerAgentMock::iDeviceManagerAgentMock_ == nullptr) {
212 return -1;
213 }
214 return IDeviceManagerAgentMock::iDeviceManagerAgentMock_->RemoveRemoteReverseObj(clear, callingTokenId);
215 }
216
FindListenerByObject(const wptr<IRemoteObject> & remote,uint32_t & tokenId,sptr<IFileDfsListener> & listener)217 int32_t DeviceManagerAgent::FindListenerByObject(const wptr<IRemoteObject> &remote,
218 uint32_t &tokenId, sptr<IFileDfsListener> &listener)
219 {
220 if (IDeviceManagerAgentMock::iDeviceManagerAgentMock_ == nullptr) {
221 return -1;
222 }
223 auto ret = IDeviceManagerAgentMock::iDeviceManagerAgentMock_->FindListenerByObject(remote, tokenId, listener);
224 switch (ret) {
225 case FIRST:
226 tokenId = 0;
227 listener = nullptr;
228 break;
229 case SECOND:
230 tokenId = 1;
231 listener = nullptr;
232 break;
233 case THIRD:
234 tokenId = 0;
235 listener = IDeviceManagerAgentMock::iDeviceManagerAgentMock_->GetDfsListener();
236 break;
237 case FOURTH:
238 tokenId = 1;
239 listener = IDeviceManagerAgentMock::iDeviceManagerAgentMock_->GetDfsListener();
240 break;
241 default:
242 break;
243 }
244 return 0;
245 }
246
GetDeviceIdByNetworkId(const std::string & networkId)247 std::string DeviceManagerAgent::GetDeviceIdByNetworkId(const std::string &networkId)
248 {
249 if (IDeviceManagerAgentMock::iDeviceManagerAgentMock_ == nullptr) {
250 return "";
251 }
252 return IDeviceManagerAgentMock::iDeviceManagerAgentMock_->GetDeviceIdByNetworkId(networkId);
253 }
254
from_json(const nlohmann::json & jsonObject,GroupInfo & groupInfo)255 void from_json(const nlohmann::json &jsonObject, GroupInfo &groupInfo)
256 {
257 return;
258 }
259
QueryRelatedGroups(const std::string & udid,const std::string & networkId)260 void DeviceManagerAgent::QueryRelatedGroups(const std::string &udid, const std::string &networkId)
261 {
262 return;
263 }
264
CheckIsAccountless(const GroupInfo & group)265 bool DeviceManagerAgent::CheckIsAccountless(const GroupInfo &group)
266 {
267 return true;
268 }
269
OnDeviceChanged(const DistributedHardware::DmDeviceInfo & deviceInfo)270 void DeviceManagerAgent::OnDeviceChanged(const DistributedHardware::DmDeviceInfo &deviceInfo)
271 {
272 return;
273 }
274
InitDeviceInfos()275 void DeviceManagerAgent::InitDeviceInfos()
276 {
277 return;
278 }
279
IsSupportedDevice(const DistributedHardware::DmDeviceInfo & deviceInfo)280 int32_t DeviceManagerAgent::IsSupportedDevice(const DistributedHardware::DmDeviceInfo &deviceInfo)
281 {
282 if (IDeviceManagerAgentMock::iDeviceManagerAgentMock_ == nullptr) {
283 return -1;
284 }
285 return IDeviceManagerAgentMock::iDeviceManagerAgentMock_->IsSupportedDevice(deviceInfo);
286 }
287
InitLocalNodeInfo()288 void DeviceManagerAgent::InitLocalNodeInfo()
289 {
290 return;
291 }
292
OnRemoteDied()293 void DeviceManagerAgent::OnRemoteDied()
294 {
295 return;
296 }
297
GetLocalDeviceInfo()298 DeviceInfo &DeviceManagerAgent::GetLocalDeviceInfo()
299 {
300 DeviceInfo deviceInfo;
301 if (IDeviceManagerAgentMock::iDeviceManagerAgentMock_ == nullptr) {
302 return deviceInfo;
303 }
304 return IDeviceManagerAgentMock::iDeviceManagerAgentMock_->GetLocalDeviceInfo();
305 }
306
GetRemoteDevicesInfo()307 vector<DeviceInfo> DeviceManagerAgent::GetRemoteDevicesInfo()
308 {
309 if (IDeviceManagerAgentMock::iDeviceManagerAgentMock_ == nullptr) {
310 return {};
311 }
312 return IDeviceManagerAgentMock::iDeviceManagerAgentMock_->GetRemoteDevicesInfo();
313 }
314
RegisterToExternalDm()315 void DeviceManagerAgent::RegisterToExternalDm()
316 {
317 return;
318 }
319
UnregisterFromExternalDm()320 void DeviceManagerAgent::UnregisterFromExternalDm()
321 {
322 return;
323 }
324 } // namespace DistributedFile
325 } // namespace Storage
326 } // namespace OHOS