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