1 /*
2 * Copyright (c) 2021-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 #include "disc_server_proxy_standard.h"
17
18 #include "ipc_skeleton.h"
19
20 #include "discovery_service.h"
21 #include "message_parcel.h"
22 #include "softbus_errcode.h"
23 #include "softbus_ipc_def.h"
24 #include "softbus_log.h"
25
26 namespace OHOS {
27 static uint32_t g_getSystemAbilityId = 2;
28 const std::u16string SAMANAGER_INTERFACE_TOKEN = u"ohos.samgr.accessToken";
GetSystemAbility()29 static sptr<IRemoteObject> GetSystemAbility()
30 {
31 MessageParcel data;
32
33 if (!data.WriteInterfaceToken(SAMANAGER_INTERFACE_TOKEN)) {
34 return nullptr;
35 }
36
37 data.WriteInt32(SOFTBUS_SERVER_SA_ID_INNER);
38 MessageParcel reply;
39 MessageOption option;
40 sptr<IRemoteObject> samgr = IPCSkeleton::GetContextObject();
41 int32_t err = samgr->SendRequest(g_getSystemAbilityId, data, reply, option);
42 if (err != 0) {
43 LOG_ERR("Get GetSystemAbility failed!\n");
44 return nullptr;
45 }
46 return reply.ReadRemoteObject();
47 }
48
StartDiscovery(const char * pkgName,const SubscribeInfo * subInfo)49 int32_t DiscServerProxy::StartDiscovery(const char *pkgName, const SubscribeInfo *subInfo)
50 {
51 sptr<IRemoteObject> remote = GetSystemAbility();
52 if (remote == nullptr) {
53 SoftBusLog(SOFTBUS_LOG_DISC, SOFTBUS_LOG_ERROR, "remote is nullptr!");
54 return SOFTBUS_ERR;
55 }
56
57 MessageParcel data;
58 if (!data.WriteInterfaceToken(GetDescriptor())) {
59 SoftBusLog(SOFTBUS_LOG_DISC, SOFTBUS_LOG_ERROR, "StartDiscovery write InterfaceToken failed!");
60 return SOFTBUS_ERR;
61 }
62 data.WriteCString(pkgName);
63 data.WriteInt32(subInfo->subscribeId);
64 data.WriteInt32(subInfo->mode);
65 data.WriteInt32(subInfo->medium);
66 data.WriteInt32(subInfo->freq);
67 data.WriteBool(subInfo->isSameAccount);
68 data.WriteBool(subInfo->isWakeRemote);
69 data.WriteCString(subInfo->capability);
70 data.WriteUint32(subInfo->dataLen);
71 if (subInfo->dataLen != 0) {
72 data.WriteCString((char *)subInfo->capabilityData);
73 }
74 MessageParcel reply;
75 MessageOption option;
76 int32_t err = remote->SendRequest(SERVER_START_DISCOVERY, data, reply, option);
77 if (err != 0) {
78 SoftBusLog(SOFTBUS_LOG_DISC, SOFTBUS_LOG_ERROR, "StartDiscovery send request failed!");
79 return SOFTBUS_ERR;
80 }
81 int32_t serverRet = 0;
82 int32_t ret = reply.ReadInt32(serverRet);
83 if (!ret) {
84 SoftBusLog(SOFTBUS_LOG_DISC, SOFTBUS_LOG_ERROR, "StartDiscovery read serverRet failed!");
85 return SOFTBUS_ERR;
86 }
87 return serverRet;
88 }
89
StopDiscovery(const char * pkgName,int subscribeId)90 int32_t DiscServerProxy::StopDiscovery(const char *pkgName, int subscribeId)
91 {
92 sptr<IRemoteObject> remote = GetSystemAbility();
93 if (remote == nullptr) {
94 SoftBusLog(SOFTBUS_LOG_DISC, SOFTBUS_LOG_ERROR, "remote is nullptr!");
95 return SOFTBUS_ERR;
96 }
97
98 MessageParcel data;
99 if (!data.WriteInterfaceToken(GetDescriptor())) {
100 SoftBusLog(SOFTBUS_LOG_DISC, SOFTBUS_LOG_ERROR, "StopDiscovery write InterfaceToken failed!");
101 return SOFTBUS_ERR;
102 }
103 data.WriteCString(pkgName);
104 data.WriteInt32(subscribeId);
105
106 MessageParcel reply;
107 MessageOption option;
108 int32_t err = remote->SendRequest(SERVER_STOP_DISCOVERY, data, reply, option);
109 SoftBusLog(SOFTBUS_LOG_DISC, SOFTBUS_LOG_INFO, "StopDiscovery send request ret = %d!", err);
110 if (err != 0) {
111 SoftBusLog(SOFTBUS_LOG_DISC, SOFTBUS_LOG_ERROR, "StopDiscovery send request failed!");
112 return SOFTBUS_ERR;
113 }
114 int32_t serverRet = 0;
115 int32_t ret = reply.ReadInt32(serverRet);
116 if (!ret) {
117 SoftBusLog(SOFTBUS_LOG_DISC, SOFTBUS_LOG_ERROR, "StopDiscovery read serverRet failed!");
118 return SOFTBUS_ERR;
119 }
120 return serverRet;
121 }
122
PublishService(const char * pkgName,const PublishInfo * pubInfo)123 int32_t DiscServerProxy::PublishService(const char *pkgName, const PublishInfo *pubInfo)
124 {
125 sptr<IRemoteObject> remote = GetSystemAbility();
126 if (remote == nullptr) {
127 SoftBusLog(SOFTBUS_LOG_DISC, SOFTBUS_LOG_ERROR, "remote is nullptr!");
128 return SOFTBUS_ERR;
129 }
130
131 MessageParcel data;
132 if (!data.WriteInterfaceToken(GetDescriptor())) {
133 SoftBusLog(SOFTBUS_LOG_DISC, SOFTBUS_LOG_ERROR, "PublishService write InterfaceToken failed!");
134 return SOFTBUS_ERR;
135 }
136 data.WriteCString(pkgName);
137 data.WriteInt32(pubInfo->publishId);
138 data.WriteInt32(pubInfo->mode);
139 data.WriteInt32(pubInfo->medium);
140 data.WriteInt32(pubInfo->freq);
141 data.WriteCString(pubInfo->capability);
142 data.WriteUint32(pubInfo->dataLen);
143 if (pubInfo->dataLen != 0) {
144 data.WriteCString((char *)pubInfo->capabilityData);
145 }
146 MessageParcel reply;
147 MessageOption option;
148 int32_t err = remote->SendRequest(SERVER_PUBLISH_SERVICE, data, reply, option);
149 SoftBusLog(SOFTBUS_LOG_DISC, SOFTBUS_LOG_INFO, "PublishService send request ret = %d!", err);
150 if (err != 0) {
151 SoftBusLog(SOFTBUS_LOG_DISC, SOFTBUS_LOG_ERROR, "PublishService send request failed!");
152 return SOFTBUS_ERR;
153 }
154 int32_t serverRet = 0;
155 int32_t ret = reply.ReadInt32(serverRet);
156 if (!ret) {
157 SoftBusLog(SOFTBUS_LOG_DISC, SOFTBUS_LOG_ERROR, "PublishService read serverRet failed!");
158 return SOFTBUS_ERR;
159 }
160 return serverRet;
161 }
162
UnPublishService(const char * pkgName,int publishId)163 int32_t DiscServerProxy::UnPublishService(const char *pkgName, int publishId)
164 {
165 sptr<IRemoteObject> remote = GetSystemAbility();
166 if (remote == nullptr) {
167 SoftBusLog(SOFTBUS_LOG_DISC, SOFTBUS_LOG_ERROR, "remote is nullptr!");
168 return SOFTBUS_ERR;
169 }
170
171 MessageParcel data;
172 if (!data.WriteInterfaceToken(GetDescriptor())) {
173 SoftBusLog(SOFTBUS_LOG_DISC, SOFTBUS_LOG_ERROR, "UnPublishService write InterfaceToken failed!");
174 return SOFTBUS_ERR;
175 }
176 data.WriteCString(pkgName);
177 data.WriteInt32(publishId);
178
179 MessageParcel reply;
180 MessageOption option;
181 int32_t err = remote->SendRequest(SERVER_UNPUBLISH_SERVICE, data, reply, option);
182 SoftBusLog(SOFTBUS_LOG_DISC, SOFTBUS_LOG_INFO, "UnPublishService send request ret = %d!", err);
183 if (err != 0) {
184 SoftBusLog(SOFTBUS_LOG_DISC, SOFTBUS_LOG_ERROR, "UnPublishService send request failed!");
185 return SOFTBUS_ERR;
186 }
187 int32_t serverRet = 0;
188 int32_t ret = reply.ReadInt32(serverRet);
189 if (!ret) {
190 SoftBusLog(SOFTBUS_LOG_DISC, SOFTBUS_LOG_ERROR, "UnPublishService read serverRet failed!");
191 return SOFTBUS_ERR;
192 }
193 return serverRet;
194 }
195
SoftbusRegisterService(const char * clientPkgName,const sptr<IRemoteObject> & object)196 int32_t DiscServerProxy::SoftbusRegisterService(const char *clientPkgName, const sptr<IRemoteObject>& object)
197 {
198 (void)clientPkgName;
199 (void)object;
200 return SOFTBUS_OK;
201 }
202
CreateSessionServer(const char * pkgName,const char * sessionName)203 int32_t DiscServerProxy::CreateSessionServer(const char *pkgName, const char *sessionName)
204 {
205 (void)pkgName;
206 (void)sessionName;
207 return SOFTBUS_OK;
208 }
209
RemoveSessionServer(const char * pkgName,const char * sessionName)210 int32_t DiscServerProxy::RemoveSessionServer(const char *pkgName, const char *sessionName)
211 {
212 (void)pkgName;
213 (void)sessionName;
214 return SOFTBUS_OK;
215 }
216
OpenSession(const SessionParam * param,TransInfo * info)217 int32_t DiscServerProxy::OpenSession(const SessionParam *param, TransInfo *info)
218 {
219 (void)param;
220 (void)info;
221 return SOFTBUS_OK;
222 }
223
OpenAuthSession(const char * sessionName,const ConnectionAddr * addrInfo)224 int32_t DiscServerProxy::OpenAuthSession(const char *sessionName, const ConnectionAddr *addrInfo)
225 {
226 (void)sessionName;
227 (void)addrInfo;
228 return SOFTBUS_OK;
229 }
230
NotifyAuthSuccess(int32_t channelId,int32_t channelType)231 int32_t DiscServerProxy::NotifyAuthSuccess(int32_t channelId, int32_t channelType)
232 {
233 (void)channelId;
234 (void)channelType;
235 return SOFTBUS_OK;
236 }
237
CloseChannel(int32_t channelId,int32_t channelType)238 int32_t DiscServerProxy::CloseChannel(int32_t channelId, int32_t channelType)
239 {
240 (void)channelId;
241 (void)channelType;
242 return SOFTBUS_OK;
243 }
244
SendMessage(int32_t channelId,int32_t channelType,const void * data,uint32_t len,int32_t msgType)245 int32_t DiscServerProxy::SendMessage(int32_t channelId, int32_t channelType, const void *data,
246 uint32_t len, int32_t msgType)
247 {
248 (void)channelId;
249 (void)channelType;
250 (void)data;
251 (void)len;
252 (void)msgType;
253 return SOFTBUS_OK;
254 }
255
JoinLNN(const char * pkgName,void * addr,uint32_t addrTypeLen)256 int32_t DiscServerProxy::JoinLNN(const char *pkgName, void *addr, uint32_t addrTypeLen)
257 {
258 (void)pkgName;
259 (void)addr;
260 (void)addrTypeLen;
261 return SOFTBUS_OK;
262 }
263
JoinMetaNode(const char * pkgName,void * addr,CustomData * customData,uint32_t addrTypeLen)264 int32_t DiscServerProxy::JoinMetaNode(const char *pkgName, void *addr, CustomData *customData, uint32_t addrTypeLen)
265 {
266 (void)pkgName;
267 (void)addr;
268 (void)customData;
269 (void)addrTypeLen;
270 return SOFTBUS_OK;
271 }
272
LeaveLNN(const char * pkgName,const char * networkId)273 int32_t DiscServerProxy::LeaveLNN(const char *pkgName, const char *networkId)
274 {
275 (void)pkgName;
276 (void)networkId;
277 return SOFTBUS_OK;
278 }
279
LeaveMetaNode(const char * pkgName,const char * networkId)280 int32_t DiscServerProxy::LeaveMetaNode(const char *pkgName, const char *networkId)
281 {
282 (void)pkgName;
283 (void)networkId;
284 return SOFTBUS_OK;
285 }
286
GetAllOnlineNodeInfo(const char * pkgName,void ** info,uint32_t infoTypeLen,int * infoNum)287 int32_t DiscServerProxy::GetAllOnlineNodeInfo(const char *pkgName, void **info, uint32_t infoTypeLen, int *infoNum)
288 {
289 (void)pkgName;
290 (void)info;
291 (void)infoTypeLen;
292 (void)infoNum;
293 return SOFTBUS_OK;
294 }
295
GetLocalDeviceInfo(const char * pkgName,void * info,uint32_t infoTypeLen)296 int32_t DiscServerProxy::GetLocalDeviceInfo(const char *pkgName, void *info, uint32_t infoTypeLen)
297 {
298 (void)pkgName;
299 (void)info;
300 (void)infoTypeLen;
301 return SOFTBUS_OK;
302 }
303
GetNodeKeyInfo(const char * pkgName,const char * networkId,int key,unsigned char * buf,uint32_t len)304 int32_t DiscServerProxy::GetNodeKeyInfo(const char *pkgName, const char *networkId, int key, unsigned char *buf,
305 uint32_t len)
306 {
307 (void)pkgName;
308 (void)networkId;
309 (void)key;
310 (void)buf;
311 (void)len;
312 return SOFTBUS_OK;
313 }
314
SetNodeDataChangeFlag(const char * pkgName,const char * networkId,uint16_t dataChangeFlag)315 int32_t DiscServerProxy::SetNodeDataChangeFlag(const char *pkgName, const char *networkId, uint16_t dataChangeFlag)
316 {
317 (void)pkgName;
318 (void)networkId;
319 (void)dataChangeFlag;
320 return SOFTBUS_OK;
321 }
322
StartTimeSync(const char * pkgName,const char * targetNetworkId,int32_t accuracy,int32_t period)323 int32_t DiscServerProxy::StartTimeSync(const char *pkgName, const char *targetNetworkId, int32_t accuracy,
324 int32_t period)
325 {
326 (void)pkgName;
327 (void)targetNetworkId;
328 (void)accuracy;
329 (void)period;
330 return SOFTBUS_OK;
331 }
332
StopTimeSync(const char * pkgName,const char * targetNetworkId)333 int32_t DiscServerProxy::StopTimeSync(const char *pkgName, const char *targetNetworkId)
334 {
335 (void)pkgName;
336 (void)targetNetworkId;
337 return SOFTBUS_OK;
338 }
339
QosReport(int32_t channelId,int32_t chanType,int32_t appType,int32_t quality)340 int32_t DiscServerProxy::QosReport(int32_t channelId, int32_t chanType, int32_t appType, int32_t quality)
341 {
342 (void)channelId;
343 (void)chanType;
344 (void)appType;
345 (void)quality;
346 return SOFTBUS_OK;
347 }
348
StreamStats(int32_t channelId,int32_t channelType,const StreamSendStats * data)349 int32_t DiscServerProxy::StreamStats(int32_t channelId, int32_t channelType, const StreamSendStats *data)
350 {
351 (void)channelId;
352 (void)channelType;
353 (void)data;
354 return SOFTBUS_OK;
355 }
356
RippleStats(int32_t channelId,int32_t channelType,const TrafficStats * data)357 int32_t DiscServerProxy::RippleStats(int32_t channelId, int32_t channelType, const TrafficStats *data)
358 {
359 (void)channelId;
360 (void)channelType;
361 (void)data;
362 return SOFTBUS_OK;
363 }
364 } // namespace OHOS
365