1 /*
2 * Copyright (c) 2022-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 "xcollie/xcollie.h"
17 #include "xcollie/xcollie_define.h"
18
19 #include "device_manager_ipc_interface_code.h"
20 #include "device_manager_service.h"
21 #include "device_manager_service_notify.h"
22 #include "dm_anonymous.h"
23 #include "dm_constants.h"
24 #include "ipc_acl_profile_req.h"
25 #include "ipc_cmd_register.h"
26 #include "ipc_def.h"
27 #include "ipc_create_pin_holder_req.h"
28 #include "ipc_credential_auth_status_req.h"
29 #include "ipc_destroy_pin_holder_req.h"
30 #include "ipc_model_codec.h"
31 #include "ipc_notify_devicetrustchange_req.h"
32 #include "ipc_notify_auth_result_req.h"
33 #include "ipc_notify_bind_result_req.h"
34 #include "ipc_notify_credential_req.h"
35 #include "ipc_notify_device_found_req.h"
36 #include "ipc_notify_device_discovery_req.h"
37 #include "ipc_notify_device_state_req.h"
38 #include "ipc_notify_discover_result_req.h"
39 #include "ipc_notify_get_device_icon_info_req.h"
40 #include "ipc_notify_get_device_profile_info_list_req.h"
41 #include "ipc_notify_publish_result_req.h"
42 #include "ipc_notify_pin_holder_event_req.h"
43 #include "ipc_notify_set_local_device_name_req.h"
44 #include "ipc_notify_set_remote_device_name_req.h"
45 #include "ipc_server_client_proxy.h"
46 #include "ipc_server_stub.h"
47 #include "multiple_user_connector.h"
48 #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE))
49 #include "multiple_user_connector.h"
50 #endif
51 namespace OHOS {
52 namespace DistributedHardware {
53 const unsigned int XCOLLIE_TIMEOUT_S = 5;
EncodeDmDeviceInfo(const DmDeviceInfo & devInfo,MessageParcel & parcel)54 bool EncodeDmDeviceInfo(const DmDeviceInfo &devInfo, MessageParcel &parcel)
55 {
56 bool bRet = true;
57 std::string deviceIdStr(devInfo.deviceId);
58 bRet = (bRet && parcel.WriteString(deviceIdStr));
59 std::string deviceNameStr(devInfo.deviceName);
60 bRet = (bRet && parcel.WriteString(deviceNameStr));
61 bRet = (bRet && parcel.WriteUint16(devInfo.deviceTypeId));
62 std::string networkIdStr(devInfo.networkId);
63 bRet = (bRet && parcel.WriteString(networkIdStr));
64 bRet = (bRet && parcel.WriteInt32(devInfo.range));
65 bRet = (bRet && parcel.WriteInt32(devInfo.networkType));
66 bRet = (bRet && parcel.WriteInt32(devInfo.authForm));
67 bRet = (bRet && parcel.WriteString(devInfo.extraData));
68 return bRet;
69 }
70
EncodeDmDeviceBasicInfo(const DmDeviceBasicInfo & devInfo,MessageParcel & parcel)71 bool EncodeDmDeviceBasicInfo(const DmDeviceBasicInfo &devInfo, MessageParcel &parcel)
72 {
73 bool bRet = true;
74 std::string deviceIdStr(devInfo.deviceId);
75 bRet = (bRet && parcel.WriteString(deviceIdStr));
76 std::string deviceNameStr(devInfo.deviceName);
77 bRet = (bRet && parcel.WriteString(deviceNameStr));
78 bRet = (bRet && parcel.WriteUint16(devInfo.deviceTypeId));
79 std::string networkIdStr(devInfo.networkId);
80 bRet = (bRet && parcel.WriteString(networkIdStr));
81 bRet = (bRet && parcel.WriteString(devInfo.extraData));
82 return bRet;
83 }
84
EncodePeerTargetId(const PeerTargetId & targetId,MessageParcel & parcel)85 bool EncodePeerTargetId(const PeerTargetId &targetId, MessageParcel &parcel)
86 {
87 bool bRet = true;
88 bRet = (bRet && parcel.WriteString(targetId.deviceId));
89 bRet = (bRet && parcel.WriteString(targetId.brMac));
90 bRet = (bRet && parcel.WriteString(targetId.bleMac));
91 bRet = (bRet && parcel.WriteString(targetId.wifiIp));
92 bRet = (bRet && parcel.WriteUint16(targetId.wifiPort));
93 return bRet;
94 }
95
DecodePeerTargetId(MessageParcel & parcel,PeerTargetId & targetId)96 void DecodePeerTargetId(MessageParcel &parcel, PeerTargetId &targetId)
97 {
98 targetId.deviceId = parcel.ReadString();
99 targetId.brMac = parcel.ReadString();
100 targetId.bleMac = parcel.ReadString();
101 targetId.wifiIp = parcel.ReadString();
102 targetId.wifiPort = parcel.ReadUint16();
103 }
104
DecodeDmAccessCaller(MessageParcel & parcel,DmAccessCaller & caller)105 void DecodeDmAccessCaller(MessageParcel &parcel, DmAccessCaller &caller)
106 {
107 caller.accountId = parcel.ReadString();
108 caller.pkgName = parcel.ReadString();
109 caller.networkId = parcel.ReadString();
110 caller.userId = parcel.ReadInt32();
111 caller.tokenId = parcel.ReadUint64();
112 caller.extra = parcel.ReadString();
113 }
114
DecodeDmAccessCallee(MessageParcel & parcel,DmAccessCallee & callee)115 void DecodeDmAccessCallee(MessageParcel &parcel, DmAccessCallee &callee)
116 {
117 callee.accountId = parcel.ReadString();
118 callee.networkId = parcel.ReadString();
119 callee.peerId = parcel.ReadString();
120 callee.userId = parcel.ReadInt32();
121 callee.extra = parcel.ReadString();
122 }
123
ON_IPC_SET_REQUEST(SERVER_DEVICE_STATE_NOTIFY,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)124 ON_IPC_SET_REQUEST(SERVER_DEVICE_STATE_NOTIFY, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
125 {
126 CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED);
127 std::shared_ptr<IpcNotifyDeviceStateReq> pReq = std::static_pointer_cast<IpcNotifyDeviceStateReq>(pBaseReq);
128 std::string pkgName = pReq->GetPkgName();
129 int32_t deviceState = pReq->GetDeviceState();
130 DmDeviceInfo deviceInfo = pReq->GetDeviceInfo();
131 DmDeviceBasicInfo deviceBasicInfo = pReq->GetDeviceBasicInfo();
132 if (!data.WriteString(pkgName)) {
133 LOGE("write pkgName failed");
134 return ERR_DM_IPC_WRITE_FAILED;
135 }
136 if (!data.WriteInt32(deviceState)) {
137 LOGE("write state failed");
138 return ERR_DM_IPC_WRITE_FAILED;
139 }
140 if (!EncodeDmDeviceInfo(deviceInfo, data)) {
141 LOGE("write dm device info failed");
142 return ERR_DM_IPC_WRITE_FAILED;
143 }
144 if (!EncodeDmDeviceBasicInfo(deviceBasicInfo, data)) {
145 LOGE("write dm device basic info failed");
146 return ERR_DM_IPC_WRITE_FAILED;
147 }
148 return DM_OK;
149 }
150
ON_IPC_READ_RESPONSE(SERVER_DEVICE_STATE_NOTIFY,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)151 ON_IPC_READ_RESPONSE(SERVER_DEVICE_STATE_NOTIFY, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
152 {
153 CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED);
154 pBaseRsp->SetErrCode(reply.ReadInt32());
155 return DM_OK;
156 }
157
ON_IPC_SET_REQUEST(SERVER_DEVICE_FOUND,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)158 ON_IPC_SET_REQUEST(SERVER_DEVICE_FOUND, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
159 {
160 CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED);
161 std::shared_ptr<IpcNotifyDeviceFoundReq> pReq = std::static_pointer_cast<IpcNotifyDeviceFoundReq>(pBaseReq);
162 std::string pkgName = pReq->GetPkgName();
163 uint16_t subscribeId = pReq->GetSubscribeId();
164 DmDeviceInfo deviceInfo = pReq->GetDeviceInfo();
165 DmDeviceBasicInfo devBasicInfo = pReq->GetDeviceBasicInfo();
166 if (!data.WriteString(pkgName)) {
167 LOGE("write pkgName failed");
168 return ERR_DM_IPC_WRITE_FAILED;
169 }
170 if (!data.WriteInt16((int16_t)subscribeId)) {
171 LOGE("write subscribeId failed");
172 return ERR_DM_IPC_WRITE_FAILED;
173 }
174 if (!EncodeDmDeviceInfo(deviceInfo, data)) {
175 LOGE("write dm device info failed");
176 return ERR_DM_IPC_WRITE_FAILED;
177 }
178 if (!EncodeDmDeviceBasicInfo(devBasicInfo, data)) {
179 LOGE("write dm device basic info failed");
180 return ERR_DM_IPC_WRITE_FAILED;
181 }
182 return DM_OK;
183 }
184
ON_IPC_READ_RESPONSE(SERVER_DEVICE_FOUND,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)185 ON_IPC_READ_RESPONSE(SERVER_DEVICE_FOUND, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
186 {
187 CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED);
188 pBaseRsp->SetErrCode(reply.ReadInt32());
189 return DM_OK;
190 }
191
ON_IPC_SET_REQUEST(SERVER_DEVICE_DISCOVERY,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)192 ON_IPC_SET_REQUEST(SERVER_DEVICE_DISCOVERY, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
193 {
194 CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED);
195 std::shared_ptr<IpcNotifyDeviceDiscoveryReq> pReq = std::static_pointer_cast<IpcNotifyDeviceDiscoveryReq>(pBaseReq);
196 std::string pkgName = pReq->GetPkgName();
197 uint16_t subscribeId = pReq->GetSubscribeId();
198 DmDeviceBasicInfo deviceBasicInfo = pReq->GetDeviceBasicInfo();
199 if (!data.WriteString(pkgName)) {
200 LOGE("write pkgName failed");
201 return ERR_DM_IPC_WRITE_FAILED;
202 }
203 if (!data.WriteInt16((int16_t)subscribeId)) {
204 LOGE("write subscribeId failed");
205 return ERR_DM_IPC_WRITE_FAILED;
206 }
207 if (!EncodeDmDeviceBasicInfo(deviceBasicInfo, data)) {
208 LOGE("write dm device basic info failed");
209 return ERR_DM_IPC_WRITE_FAILED;
210 }
211 return DM_OK;
212 }
213
ON_IPC_READ_RESPONSE(SERVER_DEVICE_DISCOVERY,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)214 ON_IPC_READ_RESPONSE(SERVER_DEVICE_DISCOVERY, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
215 {
216 CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED);
217 pBaseRsp->SetErrCode(reply.ReadInt32());
218 return DM_OK;
219 }
220
ON_IPC_SET_REQUEST(SERVER_DISCOVER_FINISH,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)221 ON_IPC_SET_REQUEST(SERVER_DISCOVER_FINISH, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
222 {
223 CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED);
224 std::shared_ptr<IpcNotifyDiscoverResultReq> pReq = std::static_pointer_cast<IpcNotifyDiscoverResultReq>(pBaseReq);
225 std::string pkgName = pReq->GetPkgName();
226 uint16_t subscribeId = pReq->GetSubscribeId();
227 int32_t result = pReq->GetResult();
228 if (!data.WriteString(pkgName)) {
229 LOGE("write pkgName failed");
230 return ERR_DM_IPC_WRITE_FAILED;
231 }
232 if (!data.WriteInt16((int16_t)subscribeId)) {
233 LOGE("write subscribeId failed");
234 return ERR_DM_IPC_WRITE_FAILED;
235 }
236 if (!data.WriteInt32(result)) {
237 LOGE("write result failed");
238 return ERR_DM_IPC_WRITE_FAILED;
239 }
240 return DM_OK;
241 }
242
ON_IPC_READ_RESPONSE(SERVER_DISCOVER_FINISH,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)243 ON_IPC_READ_RESPONSE(SERVER_DISCOVER_FINISH, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
244 {
245 CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED);
246 pBaseRsp->SetErrCode(reply.ReadInt32());
247 return DM_OK;
248 }
249
ON_IPC_SET_REQUEST(SERVER_PUBLISH_FINISH,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)250 ON_IPC_SET_REQUEST(SERVER_PUBLISH_FINISH, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
251 {
252 CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED);
253 std::shared_ptr<IpcNotifyPublishResultReq> pReq = std::static_pointer_cast<IpcNotifyPublishResultReq>(pBaseReq);
254 std::string pkgName = pReq->GetPkgName();
255 int32_t publishId = pReq->GetPublishId();
256 int32_t result = pReq->GetResult();
257 if (!data.WriteString(pkgName)) {
258 LOGE("write pkgName failed");
259 return ERR_DM_IPC_WRITE_FAILED;
260 }
261 if (!data.WriteInt32(publishId)) {
262 LOGE("write publishId failed");
263 return ERR_DM_IPC_WRITE_FAILED;
264 }
265 if (!data.WriteInt32(result)) {
266 LOGE("write result failed");
267 return ERR_DM_IPC_WRITE_FAILED;
268 }
269 return DM_OK;
270 }
271
ON_IPC_READ_RESPONSE(SERVER_PUBLISH_FINISH,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)272 ON_IPC_READ_RESPONSE(SERVER_PUBLISH_FINISH, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
273 {
274 CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED);
275 pBaseRsp->SetErrCode(reply.ReadInt32());
276 return DM_OK;
277 }
278
ON_IPC_SET_REQUEST(SERVER_AUTH_RESULT,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)279 ON_IPC_SET_REQUEST(SERVER_AUTH_RESULT, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
280 {
281 CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED);
282 std::shared_ptr<IpcNotifyAuthResultReq> pReq = std::static_pointer_cast<IpcNotifyAuthResultReq>(pBaseReq);
283
284 std::string pkgName = pReq->GetPkgName();
285 std::string deviceId = pReq->GetDeviceId();
286 std::string token = pReq->GetPinToken();
287 int32_t status = pReq->GetStatus();
288 int32_t reason = pReq->GetReason();
289 if (!data.WriteString(pkgName)) {
290 LOGE("write pkgName failed");
291 return ERR_DM_IPC_WRITE_FAILED;
292 }
293 if (!data.WriteString(deviceId)) {
294 LOGE("write deviceId failed");
295 return ERR_DM_IPC_WRITE_FAILED;
296 }
297 if (!data.WriteString(token)) {
298 LOGE("write token failed");
299 return ERR_DM_IPC_WRITE_FAILED;
300 }
301 if (!data.WriteInt32(status)) {
302 LOGE("write status failed");
303 return ERR_DM_IPC_WRITE_FAILED;
304 }
305 if (!data.WriteInt32(reason)) {
306 LOGE("write reason failed");
307 return ERR_DM_IPC_WRITE_FAILED;
308 }
309 return DM_OK;
310 }
311
ON_IPC_READ_RESPONSE(SERVER_AUTH_RESULT,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)312 ON_IPC_READ_RESPONSE(SERVER_AUTH_RESULT, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
313 {
314 CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED);
315 pBaseRsp->SetErrCode(reply.ReadInt32());
316 return DM_OK;
317 }
318
ON_IPC_SET_REQUEST(SERVER_DEVICE_FA_NOTIFY,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)319 ON_IPC_SET_REQUEST(SERVER_DEVICE_FA_NOTIFY, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
320 {
321 CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED);
322 std::shared_ptr<IpcNotifyDMFAResultReq> pReq = std::static_pointer_cast<IpcNotifyDMFAResultReq>(pBaseReq);
323
324 std::string packagname = pReq->GetPkgName();
325 std::string paramJson = pReq->GetJsonParam();
326 if (!data.WriteString(packagname)) {
327 LOGE("write pkgName failed");
328 return ERR_DM_IPC_WRITE_FAILED;
329 }
330 if (!data.WriteString(paramJson)) {
331 LOGE("write paramJson failed");
332 return ERR_DM_IPC_WRITE_FAILED;
333 }
334 return DM_OK;
335 }
336
ON_IPC_READ_RESPONSE(SERVER_DEVICE_FA_NOTIFY,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)337 ON_IPC_READ_RESPONSE(SERVER_DEVICE_FA_NOTIFY, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
338 {
339 CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED);
340 pBaseRsp->SetErrCode(reply.ReadInt32());
341 return DM_OK;
342 }
343
ON_IPC_CMD(GET_TRUST_DEVICE_LIST,MessageParcel & data,MessageParcel & reply)344 ON_IPC_CMD(GET_TRUST_DEVICE_LIST, MessageParcel &data, MessageParcel &reply)
345 {
346 std::string pkgName = data.ReadString();
347 std::string extra = data.ReadString();
348 bool isRefresh = data.ReadBool();
349 if (isRefresh) {
350 DeviceManagerService::GetInstance().ShiftLNNGear(pkgName, pkgName, isRefresh, false);
351 }
352 std::vector<DmDeviceInfo> deviceList;
353 int32_t result = DeviceManagerService::GetInstance().GetTrustedDeviceList(pkgName, extra, deviceList);
354 if (!reply.WriteInt32((int32_t)deviceList.size())) {
355 LOGE("write device list size failed");
356 return ERR_DM_IPC_WRITE_FAILED;
357 }
358 for (const auto &devInfo : deviceList) {
359 if (!EncodeDmDeviceInfo(devInfo, reply)) {
360 LOGE("write dm device info failed");
361 return ERR_DM_IPC_WRITE_FAILED;
362 }
363 }
364 if (!reply.WriteInt32(result)) {
365 LOGE("write result failed");
366 return ERR_DM_IPC_WRITE_FAILED;
367 }
368 return DM_OK;
369 }
370
ON_IPC_CMD(GET_ALL_TRUST_DEVICE_LIST,MessageParcel & data,MessageParcel & reply)371 ON_IPC_CMD(GET_ALL_TRUST_DEVICE_LIST, MessageParcel &data, MessageParcel &reply)
372 {
373 std::string pkgName = data.ReadString();
374 std::string extra = data.ReadString();
375 std::vector<DmDeviceInfo> deviceList;
376 int32_t result = DeviceManagerService::GetInstance().GetAllTrustedDeviceList(pkgName, extra, deviceList);
377 if (!reply.WriteInt32((int32_t)deviceList.size())) {
378 LOGE("write device list size failed");
379 return ERR_DM_IPC_WRITE_FAILED;
380 }
381 for (const auto &devInfo : deviceList) {
382 if (!EncodeDmDeviceInfo(devInfo, reply)) {
383 LOGE("write dm device info failed");
384 return ERR_DM_IPC_WRITE_FAILED;
385 }
386 }
387 if (!reply.WriteInt32(result)) {
388 LOGE("write result failed");
389 return ERR_DM_IPC_WRITE_FAILED;
390 }
391 return DM_OK;
392 }
393
ON_IPC_CMD(REGISTER_DEVICE_MANAGER_LISTENER,MessageParcel & data,MessageParcel & reply)394 ON_IPC_CMD(REGISTER_DEVICE_MANAGER_LISTENER, MessageParcel &data, MessageParcel &reply)
395 {
396 int32_t id = OHOS::HiviewDFX::XCollie::GetInstance().SetTimer("RegisterDeviceManagerListener", XCOLLIE_TIMEOUT_S,
397 nullptr, nullptr, OHOS::HiviewDFX::XCOLLIE_FLAG_LOG | OHOS::HiviewDFX::XCOLLIE_FLAG_RECOVERY);
398 std::string pkgName = data.ReadString();
399 sptr<IRemoteObject> listener = data.ReadRemoteObject();
400 if (listener == nullptr) {
401 LOGE("read remote object failed.");
402 OHOS::HiviewDFX::XCollie::GetInstance().CancelTimer(id);
403 return ERR_DM_POINT_NULL;
404 }
405 sptr<IpcServerClientProxy> callback(new IpcServerClientProxy(listener));
406 if (callback == nullptr) {
407 LOGE("create ipc server client proxy failed.");
408 OHOS::HiviewDFX::XCollie::GetInstance().CancelTimer(id);
409 return ERR_DM_POINT_NULL;
410 }
411 ProcessInfo processInfo;
412 processInfo.pkgName = pkgName;
413 MultipleUserConnector::GetCallerUserId(processInfo.userId);
414 DeviceManagerService::GetInstance().RegisterCallerAppId(pkgName);
415 int32_t result = IpcServerStub::GetInstance().RegisterDeviceManagerListener(processInfo, callback);
416 if (!reply.WriteInt32(result)) {
417 LOGE("write result failed");
418 OHOS::HiviewDFX::XCollie::GetInstance().CancelTimer(id);
419 return ERR_DM_IPC_WRITE_FAILED;
420 }
421 OHOS::HiviewDFX::XCollie::GetInstance().CancelTimer(id);
422 return DM_OK;
423 }
424
ON_IPC_CMD(UNREGISTER_DEVICE_MANAGER_LISTENER,MessageParcel & data,MessageParcel & reply)425 ON_IPC_CMD(UNREGISTER_DEVICE_MANAGER_LISTENER, MessageParcel &data, MessageParcel &reply)
426 {
427 std::string pkgName = data.ReadString();
428 ProcessInfo processInfo;
429 processInfo.pkgName = pkgName;
430 MultipleUserConnector::GetCallerUserId(processInfo.userId);
431 DeviceManagerService::GetInstance().UnRegisterCallerAppId(pkgName);
432 int32_t result = IpcServerStub::GetInstance().UnRegisterDeviceManagerListener(processInfo);
433 if (!reply.WriteInt32(result)) {
434 LOGE("write result failed");
435 return ERR_DM_IPC_WRITE_FAILED;
436 }
437 return DM_OK;
438 }
439
440
ON_IPC_CMD(PUBLISH_DEVICE_DISCOVER,MessageParcel & data,MessageParcel & reply)441 ON_IPC_CMD(PUBLISH_DEVICE_DISCOVER, MessageParcel &data, MessageParcel &reply)
442 {
443 std::string pkgName = data.ReadString();
444 DmPublishInfo *publishInfo =
445 static_cast<DmPublishInfo *>(const_cast<void *>(data.ReadRawData(sizeof(DmPublishInfo))));
446 int32_t result = ERR_DM_POINT_NULL;
447
448 if (publishInfo != nullptr) {
449 result = DeviceManagerService::GetInstance().PublishDeviceDiscovery(pkgName, *publishInfo);
450 }
451 if (!reply.WriteInt32(result)) {
452 LOGE("write result failed");
453 return ERR_DM_IPC_WRITE_FAILED;
454 }
455 return DM_OK;
456 }
457
ON_IPC_CMD(UNPUBLISH_DEVICE_DISCOVER,MessageParcel & data,MessageParcel & reply)458 ON_IPC_CMD(UNPUBLISH_DEVICE_DISCOVER, MessageParcel &data, MessageParcel &reply)
459 {
460 std::string pkgName = data.ReadString();
461 int32_t publishId = data.ReadInt32();
462 int32_t result = DeviceManagerService::GetInstance().UnPublishDeviceDiscovery(pkgName, publishId);
463 if (!reply.WriteInt32(result)) {
464 LOGE("write result failed");
465 return ERR_DM_IPC_WRITE_FAILED;
466 }
467 return DM_OK;
468 }
469
ON_IPC_CMD(AUTHENTICATE_DEVICE,MessageParcel & data,MessageParcel & reply)470 ON_IPC_CMD(AUTHENTICATE_DEVICE, MessageParcel &data, MessageParcel &reply)
471 {
472 std::string pkgName = data.ReadString();
473 std::string extra = data.ReadString();
474 std::string deviceId = data.ReadString();
475 int32_t authType = data.ReadInt32();
476
477 int32_t result = DM_OK;
478 result = DeviceManagerService::GetInstance().AuthenticateDevice(pkgName, authType, deviceId, extra);
479 if (!reply.WriteInt32(result)) {
480 LOGE("write result failed");
481 return ERR_DM_IPC_WRITE_FAILED;
482 }
483 return DM_OK;
484 }
485
ON_IPC_CMD(UNAUTHENTICATE_DEVICE,MessageParcel & data,MessageParcel & reply)486 ON_IPC_CMD(UNAUTHENTICATE_DEVICE, MessageParcel &data, MessageParcel &reply)
487 {
488 std::string pkgName = data.ReadString();
489 std::string deviceId = data.ReadString();
490 int32_t result = DeviceManagerService::GetInstance().UnAuthenticateDevice(pkgName, deviceId);
491 if (!reply.WriteInt32(result)) {
492 LOGE("write result failed");
493 return ERR_DM_IPC_WRITE_FAILED;
494 }
495 return DM_OK;
496 }
497
ON_IPC_CMD(GET_DEVICE_INFO,MessageParcel & data,MessageParcel & reply)498 ON_IPC_CMD(GET_DEVICE_INFO, MessageParcel &data, MessageParcel &reply)
499 {
500 std::string networkId = data.ReadString();
501 DmDeviceInfo deviceInfo;
502 int32_t result = DeviceManagerService::GetInstance().GetDeviceInfo(networkId, deviceInfo);
503 if (!EncodeDmDeviceInfo(deviceInfo, reply)) {
504 LOGE("write dm device info failed");
505 return ERR_DM_IPC_WRITE_FAILED;
506 }
507 if (!reply.WriteInt32(result)) {
508 LOGE("write result failed");
509 return ERR_DM_IPC_WRITE_FAILED;
510 }
511 return DM_OK;
512 }
513
ON_IPC_CMD(GET_LOCAL_DEVICE_INFO,MessageParcel & data,MessageParcel & reply)514 ON_IPC_CMD(GET_LOCAL_DEVICE_INFO, MessageParcel &data, MessageParcel &reply)
515 {
516 (void)data;
517 DmDeviceInfo localDeviceInfo;
518 int32_t result = DeviceManagerService::GetInstance().GetLocalDeviceInfo(localDeviceInfo);
519 if (!EncodeDmDeviceInfo(localDeviceInfo, reply)) {
520 LOGE("write dm device info failed");
521 return ERR_DM_IPC_WRITE_FAILED;
522 }
523 if (!reply.WriteInt32(result)) {
524 LOGE("write result failed");
525 return ERR_DM_IPC_WRITE_FAILED;
526 }
527 return DM_OK;
528 }
529
ON_IPC_CMD(GET_UDID_BY_NETWORK,MessageParcel & data,MessageParcel & reply)530 ON_IPC_CMD(GET_UDID_BY_NETWORK, MessageParcel &data, MessageParcel &reply)
531 {
532 std::string pkgName = data.ReadString();
533 std::string netWorkId = data.ReadString();
534 std::string udid;
535 int32_t result = DeviceManagerService::GetInstance().GetUdidByNetworkId(pkgName, netWorkId, udid);
536
537 if (!reply.WriteInt32(result)) {
538 LOGE("write result failed");
539 return ERR_DM_IPC_WRITE_FAILED;
540 }
541 if (!reply.WriteString(udid)) {
542 LOGE("write result failed");
543 return ERR_DM_IPC_WRITE_FAILED;
544 }
545 return DM_OK;
546 }
547
ON_IPC_CMD(GET_UUID_BY_NETWORK,MessageParcel & data,MessageParcel & reply)548 ON_IPC_CMD(GET_UUID_BY_NETWORK, MessageParcel &data, MessageParcel &reply)
549 {
550 std::string pkgName = data.ReadString();
551 std::string netWorkId = data.ReadString();
552 std::string uuid;
553 int32_t result = DeviceManagerService::GetInstance().GetUuidByNetworkId(pkgName, netWorkId, uuid);
554
555 if (!reply.WriteInt32(result)) {
556 LOGE("write result failed");
557 return ERR_DM_IPC_WRITE_FAILED;
558 }
559 if (!reply.WriteString(uuid)) {
560 LOGE("write result failed");
561 return ERR_DM_IPC_WRITE_FAILED;
562 }
563 return DM_OK;
564 }
565
ON_IPC_CMD(SERVER_USER_AUTH_OPERATION,MessageParcel & data,MessageParcel & reply)566 ON_IPC_CMD(SERVER_USER_AUTH_OPERATION, MessageParcel &data, MessageParcel &reply)
567 {
568 std::string packageName = data.ReadString();
569 int32_t action = data.ReadInt32();
570 std::string params = data.ReadString();
571 int result = DeviceManagerService::GetInstance().SetUserOperation(packageName, action, params);
572 if (!reply.WriteInt32(result)) {
573 return ERR_DM_IPC_WRITE_FAILED;
574 }
575 return result;
576 }
577
ON_IPC_CMD(REQUEST_CREDENTIAL,MessageParcel & data,MessageParcel & reply)578 ON_IPC_CMD(REQUEST_CREDENTIAL, MessageParcel &data, MessageParcel &reply)
579 {
580 std::string packageName = data.ReadString();
581 std::string reqParaStr = data.ReadString();
582 std::map<std::string, std::string> requestParam;
583 ParseMapFromJsonString(reqParaStr, requestParam);
584 std::string returnJsonStr;
585 int32_t ret = ERR_DM_FAILED;
586 if (requestParam[DM_CREDENTIAL_TYPE] == DM_TYPE_OH) {
587 ret = DeviceManagerService::GetInstance().RequestCredential(requestParam[DM_CREDENTIAL_REQJSONSTR],
588 returnJsonStr);
589 }
590 if (requestParam[DM_CREDENTIAL_TYPE] == DM_TYPE_MINE) {
591 ret = DeviceManagerService::GetInstance().MineRequestCredential(packageName, returnJsonStr);
592 }
593 if (!reply.WriteInt32(ret)) {
594 LOGE("write ret failed");
595 return ERR_DM_IPC_WRITE_FAILED;
596 }
597 if (ret == DM_OK && !returnJsonStr.empty()) {
598 if (!reply.WriteString(returnJsonStr)) {
599 LOGE("write returnJsonStr failed");
600 return ERR_DM_IPC_WRITE_FAILED;
601 }
602 }
603 return DM_OK;
604 }
605
ON_IPC_CMD(IMPORT_CREDENTIAL,MessageParcel & data,MessageParcel & reply)606 ON_IPC_CMD(IMPORT_CREDENTIAL, MessageParcel &data, MessageParcel &reply)
607 {
608 std::string packageName = data.ReadString();
609 std::string reqParaStr = data.ReadString();
610 std::map<std::string, std::string> requestParam;
611 ParseMapFromJsonString(reqParaStr, requestParam);
612 std::string returnJsonStr;
613 std::map<std::string, std::string> outputResult;
614 int32_t ret = ERR_DM_FAILED;
615 if (requestParam[DM_CREDENTIAL_TYPE] == DM_TYPE_OH) {
616 ret = DeviceManagerService::GetInstance().ImportCredential(packageName, requestParam[DM_CREDENTIAL_REQJSONSTR]);
617 outputResult.emplace(DM_CREDENTIAL_TYPE, DM_TYPE_OH);
618 }
619 if (requestParam[DM_CREDENTIAL_TYPE] == DM_TYPE_MINE) {
620 ret = DeviceManagerService::GetInstance().ImportCredential(packageName, requestParam[DM_CREDENTIAL_REQJSONSTR],
621 returnJsonStr);
622 outputResult.emplace(DM_CREDENTIAL_TYPE, DM_TYPE_MINE);
623 outputResult.emplace(DM_CREDENTIAL_RETURNJSONSTR, returnJsonStr);
624 }
625 if (!reply.WriteInt32(ret)) {
626 LOGE("write ret failed");
627 return ERR_DM_IPC_WRITE_FAILED;
628 }
629 if (ret == DM_OK && !returnJsonStr.empty()) {
630 std::string outParaStr = ConvertMapToJsonString(outputResult);
631 if (!reply.WriteString(outParaStr)) {
632 LOGE("write returnJsonStr failed");
633 return ERR_DM_IPC_WRITE_FAILED;
634 }
635 }
636 return DM_OK;
637 }
638
ON_IPC_CMD(DELETE_CREDENTIAL,MessageParcel & data,MessageParcel & reply)639 ON_IPC_CMD(DELETE_CREDENTIAL, MessageParcel &data, MessageParcel &reply)
640 {
641 std::string packageName = data.ReadString();
642 std::string reqParaStr = data.ReadString();
643 std::map<std::string, std::string> requestParam;
644 ParseMapFromJsonString(reqParaStr, requestParam);
645 std::map<std::string, std::string> outputResult;
646 std::string returnJsonStr;
647 int32_t ret = ERR_DM_FAILED;
648 if (requestParam[DM_CREDENTIAL_TYPE] == DM_TYPE_OH) {
649 ret = DeviceManagerService::GetInstance().DeleteCredential(packageName, requestParam[DM_CREDENTIAL_REQJSONSTR]);
650 outputResult.emplace(DM_CREDENTIAL_TYPE, DM_TYPE_OH);
651 }
652 if (requestParam[DM_CREDENTIAL_TYPE] == DM_TYPE_MINE) {
653 ret = DeviceManagerService::GetInstance().DeleteCredential(packageName, requestParam[DM_CREDENTIAL_REQJSONSTR],
654 returnJsonStr);
655 outputResult.emplace(DM_CREDENTIAL_TYPE, DM_TYPE_MINE);
656 outputResult.emplace(DM_CREDENTIAL_RETURNJSONSTR, returnJsonStr);
657 }
658 if (!reply.WriteInt32(ret)) {
659 LOGE("write ret failed");
660 return ERR_DM_IPC_WRITE_FAILED;
661 }
662 if (ret == DM_OK && !returnJsonStr.empty()) {
663 std::string outParaStr = ConvertMapToJsonString(outputResult);
664 if (!reply.WriteString(outParaStr)) {
665 LOGE("write returnJsonStr failed");
666 return ERR_DM_IPC_WRITE_FAILED;
667 }
668 }
669 return DM_OK;
670 }
671
ON_IPC_CMD(SERVER_GET_DMFA_INFO,MessageParcel & data,MessageParcel & reply)672 ON_IPC_CMD(SERVER_GET_DMFA_INFO, MessageParcel &data, MessageParcel &reply)
673 {
674 std::string packageName = data.ReadString();
675 std::string reqJsonStr = data.ReadString();
676 std::string returnJsonStr;
677 int32_t ret = DeviceManagerService::GetInstance().CheckCredential(packageName, reqJsonStr, returnJsonStr);
678 if (!reply.WriteInt32(ret)) {
679 LOGE("write ret failed");
680 return ERR_DM_IPC_WRITE_FAILED;
681 }
682 if (ret == DM_OK && !returnJsonStr.empty()) {
683 if (!reply.WriteString(returnJsonStr)) {
684 LOGE("write returnJsonStr failed");
685 return ERR_DM_IPC_WRITE_FAILED;
686 }
687 }
688 return DM_OK;
689 }
690
ON_IPC_CMD(REGISTER_CREDENTIAL_CALLBACK,MessageParcel & data,MessageParcel & reply)691 ON_IPC_CMD(REGISTER_CREDENTIAL_CALLBACK, MessageParcel &data, MessageParcel &reply)
692 {
693 std::string packageName = data.ReadString();
694 int result = DeviceManagerService::GetInstance().RegisterCredentialCallback(packageName);
695 if (!reply.WriteInt32(result)) {
696 LOGE("write result failed");
697 return ERR_DM_IPC_WRITE_FAILED;
698 }
699 return result;
700 }
701
ON_IPC_CMD(UNREGISTER_CREDENTIAL_CALLBACK,MessageParcel & data,MessageParcel & reply)702 ON_IPC_CMD(UNREGISTER_CREDENTIAL_CALLBACK, MessageParcel &data, MessageParcel &reply)
703 {
704 std::string packageName = data.ReadString();
705 int result = DeviceManagerService::GetInstance().UnRegisterCredentialCallback(packageName);
706 if (!reply.WriteInt32(result)) {
707 LOGE("write result failed");
708 return ERR_DM_IPC_WRITE_FAILED;
709 }
710 return result;
711 }
712
ON_IPC_CMD(NOTIFY_EVENT,MessageParcel & data,MessageParcel & reply)713 ON_IPC_CMD(NOTIFY_EVENT, MessageParcel &data, MessageParcel &reply)
714 {
715 std::string pkgName = data.ReadString();
716 int32_t eventId = data.ReadInt32();
717 std::string event = data.ReadString();
718 int32_t result = DeviceManagerService::GetInstance().NotifyEvent(pkgName, eventId, event);
719 if (!reply.WriteInt32(result)) {
720 LOGE("write result failed");
721 return ERR_DM_IPC_WRITE_FAILED;
722 }
723 return DM_OK;
724 }
725
ON_IPC_SET_REQUEST(SERVER_CREDENTIAL_RESULT,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)726 ON_IPC_SET_REQUEST(SERVER_CREDENTIAL_RESULT, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
727 {
728 CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED);
729 std::shared_ptr<IpcNotifyCredentialReq> pReq = std::static_pointer_cast<IpcNotifyCredentialReq>(pBaseReq);
730 std::string pkgName = pReq->GetPkgName();
731 int32_t action = pReq->GetCredentialAction();
732 std::string credentialResult = pReq->GetCredentialResult();
733 if (!data.WriteString(pkgName)) {
734 LOGE("write pkgName failed");
735 return ERR_DM_IPC_WRITE_FAILED;
736 }
737 if (!data.WriteInt32(action)) {
738 LOGE("write action failed");
739 return ERR_DM_IPC_WRITE_FAILED;
740 }
741 if (!data.WriteString(credentialResult)) {
742 LOGE("write credentialResult failed");
743 return ERR_DM_IPC_WRITE_FAILED;
744 }
745
746 return DM_OK;
747 }
748
ON_IPC_READ_RESPONSE(SERVER_CREDENTIAL_RESULT,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)749 ON_IPC_READ_RESPONSE(SERVER_CREDENTIAL_RESULT, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
750 {
751 CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED);
752 pBaseRsp->SetErrCode(reply.ReadInt32());
753 return DM_OK;
754 }
755
ON_IPC_CMD(GET_ENCRYPTED_UUID_BY_NETWOEKID,MessageParcel & data,MessageParcel & reply)756 ON_IPC_CMD(GET_ENCRYPTED_UUID_BY_NETWOEKID, MessageParcel &data, MessageParcel &reply)
757 {
758 std::string pkgName = data.ReadString();
759 std::string networkId = data.ReadString();
760 std::string uuid;
761
762 int32_t result = DeviceManagerService::GetInstance().GetEncryptedUuidByNetworkId(pkgName, networkId, uuid);
763 if (!reply.WriteInt32(result)) {
764 LOGE("write result failed");
765 return ERR_DM_IPC_WRITE_FAILED;
766 }
767 if (!reply.WriteString(uuid)) {
768 LOGE("write uuid failed");
769 return ERR_DM_IPC_WRITE_FAILED;
770 }
771 return DM_OK;
772 }
773
ON_IPC_CMD(GENERATE_ENCRYPTED_UUID,MessageParcel & data,MessageParcel & reply)774 ON_IPC_CMD(GENERATE_ENCRYPTED_UUID, MessageParcel &data, MessageParcel &reply)
775 {
776 std::string pkgName = data.ReadString();
777 std::string uuid = data.ReadString();
778 std::string appId = data.ReadString();
779 std::string encryptedUuid;
780
781 int32_t result = DeviceManagerService::GetInstance().GenerateEncryptedUuid(pkgName, uuid, appId, encryptedUuid);
782 if (!reply.WriteInt32(result)) {
783 LOGE("write result failed");
784 return ERR_DM_IPC_WRITE_FAILED;
785 }
786 if (!reply.WriteString(encryptedUuid)) {
787 LOGE("write encryptedUuid failed");
788 return ERR_DM_IPC_WRITE_FAILED;
789 }
790 return DM_OK;
791 }
792
ON_IPC_CMD(BIND_DEVICE,MessageParcel & data,MessageParcel & reply)793 ON_IPC_CMD(BIND_DEVICE, MessageParcel &data, MessageParcel &reply)
794 {
795 std::string pkgName = data.ReadString();
796 std::string bindParam = data.ReadString();
797 std::string deviceId = data.ReadString();
798 int32_t bindType = data.ReadInt32();
799 int32_t result = DM_OK;
800 result = DeviceManagerService::GetInstance().BindDevice(pkgName, bindType, deviceId, bindParam);
801 if (!reply.WriteInt32(result)) {
802 LOGE("write result failed");
803 return ERR_DM_IPC_WRITE_FAILED;
804 }
805 return DM_OK;
806 }
807
ON_IPC_CMD(UNBIND_DEVICE,MessageParcel & data,MessageParcel & reply)808 ON_IPC_CMD(UNBIND_DEVICE, MessageParcel &data, MessageParcel &reply)
809 {
810 std::string pkgName = data.ReadString();
811 std::string deviceId = data.ReadString();
812 std::string extra = data.ReadString();
813 int32_t result = 0;
814 if (extra == "") {
815 result = DeviceManagerService::GetInstance().UnBindDevice(pkgName, deviceId);
816 } else {
817 result = DeviceManagerService::GetInstance().UnBindDevice(pkgName, deviceId, extra);
818 }
819 if (!reply.WriteInt32(result)) {
820 LOGE("write result failed");
821 return ERR_DM_IPC_WRITE_FAILED;
822 }
823 return DM_OK;
824 }
825
ON_IPC_CMD(GET_NETWORKTYPE_BY_NETWORK,MessageParcel & data,MessageParcel & reply)826 ON_IPC_CMD(GET_NETWORKTYPE_BY_NETWORK, MessageParcel &data, MessageParcel &reply)
827 {
828 std::string pkgName = data.ReadString();
829 std::string netWorkId = data.ReadString();
830 int32_t networkType = -1;
831 int32_t result = DeviceManagerService::GetInstance().GetNetworkTypeByNetworkId(pkgName, netWorkId, networkType);
832 if (!reply.WriteInt32(result)) {
833 LOGE("write result failed");
834 return ERR_DM_IPC_WRITE_FAILED;
835 }
836 if (!reply.WriteInt32(networkType)) {
837 LOGE("write result failed");
838 return ERR_DM_IPC_WRITE_FAILED;
839 }
840 return DM_OK;
841 }
842
ON_IPC_CMD(REGISTER_UI_STATE_CALLBACK,MessageParcel & data,MessageParcel & reply)843 ON_IPC_CMD(REGISTER_UI_STATE_CALLBACK, MessageParcel &data, MessageParcel &reply)
844 {
845 std::string pkgName = data.ReadString();
846 int32_t result = DeviceManagerService::GetInstance().RegisterUiStateCallback(pkgName);
847 if (!reply.WriteInt32(result)) {
848 LOGE("write result failed");
849 return ERR_DM_IPC_WRITE_FAILED;
850 }
851 return DM_OK;
852 }
853
ON_IPC_CMD(UNREGISTER_UI_STATE_CALLBACK,MessageParcel & data,MessageParcel & reply)854 ON_IPC_CMD(UNREGISTER_UI_STATE_CALLBACK, MessageParcel &data, MessageParcel &reply)
855 {
856 std::string pkgName = data.ReadString();
857 int32_t result = DeviceManagerService::GetInstance().UnRegisterUiStateCallback(pkgName);
858 if (!reply.WriteInt32(result)) {
859 LOGE("write result failed");
860 return ERR_DM_IPC_WRITE_FAILED;
861 }
862 return DM_OK;
863 }
864
ON_IPC_CMD(IMPORT_AUTH_CODE,MessageParcel & data,MessageParcel & reply)865 ON_IPC_CMD(IMPORT_AUTH_CODE, MessageParcel &data, MessageParcel &reply)
866 {
867 std::string pkgName = data.ReadString();
868 std::string authCode = data.ReadString();
869 int32_t result = DeviceManagerService::GetInstance().ImportAuthCode(pkgName, authCode);
870 if (!reply.WriteInt32(result)) {
871 LOGE("write result failed");
872 return ERR_DM_IPC_WRITE_FAILED;
873 }
874 return DM_OK;
875 }
876
ON_IPC_CMD(EXPORT_AUTH_CODE,MessageParcel & data,MessageParcel & reply)877 ON_IPC_CMD(EXPORT_AUTH_CODE, MessageParcel &data, MessageParcel &reply)
878 {
879 std::string authCode = "";
880 int32_t result = DeviceManagerService::GetInstance().ExportAuthCode(authCode);
881 if (!reply.WriteString(authCode)) {
882 LOGE("write result failed");
883 return ERR_DM_IPC_WRITE_FAILED;
884 }
885 if (!reply.WriteInt32(result)) {
886 LOGE("write result failed");
887 return ERR_DM_IPC_WRITE_FAILED;
888 }
889 return DM_OK;
890 }
891
ON_IPC_CMD(REGISTER_DISCOVERY_CALLBACK,MessageParcel & data,MessageParcel & reply)892 ON_IPC_CMD(REGISTER_DISCOVERY_CALLBACK, MessageParcel &data, MessageParcel &reply)
893 {
894 std::string pkgName = data.ReadString();
895 std::string discParaStr = data.ReadString();
896 std::string filterOpStr = data.ReadString();
897 std::map<std::string, std::string> discoverParam;
898 ParseMapFromJsonString(discParaStr, discoverParam);
899 std::map<std::string, std::string> filterOptions;
900 ParseMapFromJsonString(filterOpStr, filterOptions);
901 int32_t result = DeviceManagerService::GetInstance().EnableDiscoveryListener(pkgName, discoverParam, filterOptions);
902 if (!reply.WriteInt32(result)) {
903 LOGE("write result failed");
904 return ERR_DM_IPC_WRITE_FAILED;
905 }
906 return DM_OK;
907 }
908
ON_IPC_CMD(UNREGISTER_DISCOVERY_CALLBACK,MessageParcel & data,MessageParcel & reply)909 ON_IPC_CMD(UNREGISTER_DISCOVERY_CALLBACK, MessageParcel &data, MessageParcel &reply)
910 {
911 std::string pkgName = data.ReadString();
912 std::string extraParaStr = data.ReadString();
913 std::map<std::string, std::string> extraParam;
914 ParseMapFromJsonString(extraParaStr, extraParam);
915 int32_t result = DeviceManagerService::GetInstance().DisableDiscoveryListener(pkgName, extraParam);
916 if (!reply.WriteInt32(result)) {
917 LOGE("write result failed");
918 return ERR_DM_IPC_WRITE_FAILED;
919 }
920 return DM_OK;
921 }
922
ON_IPC_CMD(START_DISCOVERING,MessageParcel & data,MessageParcel & reply)923 ON_IPC_CMD(START_DISCOVERING, MessageParcel &data, MessageParcel &reply)
924 {
925 std::string pkgName = data.ReadString();
926 std::string discParaStr = data.ReadString();
927 std::string filterOpStr = data.ReadString();
928 std::map<std::string, std::string> discoverParam;
929 ParseMapFromJsonString(discParaStr, discoverParam);
930 std::map<std::string, std::string> filterOptions;
931 ParseMapFromJsonString(filterOpStr, filterOptions);
932 int32_t result = DeviceManagerService::GetInstance().StartDiscovering(pkgName, discoverParam, filterOptions);
933 if (!reply.WriteInt32(result)) {
934 LOGE("write result failed");
935 return ERR_DM_IPC_WRITE_FAILED;
936 }
937 return DM_OK;
938 }
939
ON_IPC_CMD(STOP_DISCOVERING,MessageParcel & data,MessageParcel & reply)940 ON_IPC_CMD(STOP_DISCOVERING, MessageParcel &data, MessageParcel &reply)
941 {
942 std::string pkgName = data.ReadString();
943 std::string discParaStr = data.ReadString();
944 std::map<std::string, std::string> discoverParam;
945 ParseMapFromJsonString(discParaStr, discoverParam);
946 int32_t result = DeviceManagerService::GetInstance().StopDiscovering(pkgName, discoverParam);
947 if (!reply.WriteInt32(result)) {
948 LOGE("write result failed");
949 return ERR_DM_IPC_WRITE_FAILED;
950 }
951 return DM_OK;
952 }
953
ON_IPC_CMD(START_ADVERTISING,MessageParcel & data,MessageParcel & reply)954 ON_IPC_CMD(START_ADVERTISING, MessageParcel &data, MessageParcel &reply)
955 {
956 std::string pkgName = data.ReadString();
957 std::string adverParaStr = data.ReadString();
958 std::map<std::string, std::string> advertiseParam;
959 ParseMapFromJsonString(adverParaStr, advertiseParam);
960 int32_t result = DeviceManagerService::GetInstance().StartAdvertising(pkgName, advertiseParam);
961 if (!reply.WriteInt32(result)) {
962 LOGE("write result failed");
963 return ERR_DM_IPC_WRITE_FAILED;
964 }
965 return DM_OK;
966 }
967
ON_IPC_CMD(STOP_ADVERTISING,MessageParcel & data,MessageParcel & reply)968 ON_IPC_CMD(STOP_ADVERTISING, MessageParcel &data, MessageParcel &reply)
969 {
970 std::string pkgName = data.ReadString();
971 std::string adverParaStr = data.ReadString();
972 std::map<std::string, std::string> advertiseParam;
973 ParseMapFromJsonString(adverParaStr, advertiseParam);
974 int32_t result = DeviceManagerService::GetInstance().StopAdvertising(pkgName, advertiseParam);
975 if (!reply.WriteInt32(result)) {
976 LOGE("write result failed");
977 return ERR_DM_IPC_WRITE_FAILED;
978 }
979 return DM_OK;
980 }
981
ON_IPC_CMD(BIND_TARGET,MessageParcel & data,MessageParcel & reply)982 ON_IPC_CMD(BIND_TARGET, MessageParcel &data, MessageParcel &reply)
983 {
984 std::string pkgName = data.ReadString();
985 PeerTargetId targetId;
986 DecodePeerTargetId(data, targetId);
987 std::string bindParamStr = data.ReadString();
988 std::map<std::string, std::string> bindParam;
989 ParseMapFromJsonString(bindParamStr, bindParam);
990 int32_t result = DeviceManagerService::GetInstance().BindTarget(pkgName, targetId, bindParam);
991 if (!reply.WriteInt32(result)) {
992 LOGE("write result failed");
993 return ERR_DM_IPC_WRITE_FAILED;
994 }
995 return DM_OK;
996 }
997
ON_IPC_CMD(UNBIND_TARGET,MessageParcel & data,MessageParcel & reply)998 ON_IPC_CMD(UNBIND_TARGET, MessageParcel &data, MessageParcel &reply)
999 {
1000 std::string pkgName = data.ReadString();
1001 PeerTargetId targetId;
1002 DecodePeerTargetId(data, targetId);
1003 std::string unbindParamStr = data.ReadString();
1004 std::map<std::string, std::string> unbindParam;
1005 ParseMapFromJsonString(unbindParamStr, unbindParam);
1006 int32_t result = DeviceManagerService::GetInstance().UnbindTarget(pkgName, targetId, unbindParam);
1007 if (!reply.WriteInt32(result)) {
1008 LOGE("write result failed");
1009 return ERR_DM_IPC_WRITE_FAILED;
1010 }
1011 return DM_OK;
1012 }
1013
ON_IPC_SET_REQUEST(BIND_TARGET_RESULT,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)1014 ON_IPC_SET_REQUEST(BIND_TARGET_RESULT, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
1015 {
1016 CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED);
1017 std::shared_ptr<IpcNotifyBindResultReq> pReq = std::static_pointer_cast<IpcNotifyBindResultReq>(pBaseReq);
1018 std::string pkgName = pReq->GetPkgName();
1019 PeerTargetId targetId = pReq->GetPeerTargetId();
1020 int32_t result = pReq->GetResult();
1021 int32_t status = pReq->GetStatus();
1022 std::string content = pReq->GetContent();
1023
1024 if (!data.WriteString(pkgName)) {
1025 LOGE("write bind pkgName failed");
1026 return ERR_DM_IPC_WRITE_FAILED;
1027 }
1028 if (!EncodePeerTargetId(targetId, data)) {
1029 LOGE("write bind peer target id failed");
1030 return ERR_DM_IPC_WRITE_FAILED;
1031 }
1032 if (!data.WriteInt32(result)) {
1033 LOGE("write bind result code failed");
1034 return ERR_DM_IPC_WRITE_FAILED;
1035 }
1036 if (!data.WriteInt32(status)) {
1037 LOGE("write bind result status failed");
1038 return ERR_DM_IPC_WRITE_FAILED;
1039 }
1040 if (!data.WriteString(content)) {
1041 LOGE("write bind result content failed");
1042 return ERR_DM_IPC_WRITE_FAILED;
1043 }
1044 return DM_OK;
1045 }
1046
ON_IPC_READ_RESPONSE(BIND_TARGET_RESULT,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)1047 ON_IPC_READ_RESPONSE(BIND_TARGET_RESULT, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
1048 {
1049 CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED);
1050 pBaseRsp->SetErrCode(reply.ReadInt32());
1051 return DM_OK;
1052 }
1053
ON_IPC_SET_REQUEST(SINK_BIND_TARGET_RESULT,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)1054 ON_IPC_SET_REQUEST(SINK_BIND_TARGET_RESULT, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
1055 {
1056 CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED);
1057 std::shared_ptr<IpcNotifyBindResultReq> pReq = std::static_pointer_cast<IpcNotifyBindResultReq>(pBaseReq);
1058 std::string pkgName = pReq->GetPkgName();
1059 PeerTargetId targetId = pReq->GetPeerTargetId();
1060 int32_t result = pReq->GetResult();
1061 int32_t status = pReq->GetStatus();
1062 std::string content = pReq->GetContent();
1063
1064 if (!data.WriteString(pkgName)) {
1065 LOGE("write bind pkgName failed");
1066 return ERR_DM_IPC_WRITE_FAILED;
1067 }
1068 if (!EncodePeerTargetId(targetId, data)) {
1069 LOGE("write bind peer target id failed");
1070 return ERR_DM_IPC_WRITE_FAILED;
1071 }
1072 if (!data.WriteInt32(result)) {
1073 LOGE("write bind result code failed");
1074 return ERR_DM_IPC_WRITE_FAILED;
1075 }
1076 if (!data.WriteInt32(status)) {
1077 LOGE("write bind result status failed");
1078 return ERR_DM_IPC_WRITE_FAILED;
1079 }
1080 if (!data.WriteString(content)) {
1081 LOGE("write bind result content failed");
1082 return ERR_DM_IPC_WRITE_FAILED;
1083 }
1084 return DM_OK;
1085 }
1086
ON_IPC_READ_RESPONSE(SINK_BIND_TARGET_RESULT,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)1087 ON_IPC_READ_RESPONSE(SINK_BIND_TARGET_RESULT, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
1088 {
1089 CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED);
1090 pBaseRsp->SetErrCode(reply.ReadInt32());
1091 return DM_OK;
1092 }
1093
ON_IPC_SET_REQUEST(UNBIND_TARGET_RESULT,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)1094 ON_IPC_SET_REQUEST(UNBIND_TARGET_RESULT, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
1095 {
1096 CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED);
1097 std::shared_ptr<IpcNotifyBindResultReq> pReq = std::static_pointer_cast<IpcNotifyBindResultReq>(pBaseReq);
1098 std::string pkgName = pReq->GetPkgName();
1099 PeerTargetId targetId = pReq->GetPeerTargetId();
1100 int32_t result = pReq->GetResult();
1101 std::string content = pReq->GetContent();
1102
1103 if (!data.WriteString(pkgName)) {
1104 LOGE("write unbind pkgName failed");
1105 return ERR_DM_IPC_WRITE_FAILED;
1106 }
1107 if (!EncodePeerTargetId(targetId, data)) {
1108 LOGE("write unbind peer target id failed");
1109 return ERR_DM_IPC_WRITE_FAILED;
1110 }
1111 if (!data.WriteInt32(result)) {
1112 LOGE("write unbind result code failed");
1113 return ERR_DM_IPC_WRITE_FAILED;
1114 }
1115 if (!data.WriteString(content)) {
1116 LOGE("write unbind result content failed");
1117 return ERR_DM_IPC_WRITE_FAILED;
1118 }
1119 return DM_OK;
1120 }
1121
ON_IPC_READ_RESPONSE(UNBIND_TARGET_RESULT,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)1122 ON_IPC_READ_RESPONSE(UNBIND_TARGET_RESULT, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
1123 {
1124 CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED);
1125 pBaseRsp->SetErrCode(reply.ReadInt32());
1126 return DM_OK;
1127 }
1128
ON_IPC_CMD(REGISTER_PIN_HOLDER_CALLBACK,MessageParcel & data,MessageParcel & reply)1129 ON_IPC_CMD(REGISTER_PIN_HOLDER_CALLBACK, MessageParcel &data, MessageParcel &reply)
1130 {
1131 std::string pkgName = data.ReadString();
1132 int32_t result = DeviceManagerService::GetInstance().RegisterPinHolderCallback(pkgName);
1133 if (!reply.WriteInt32(result)) {
1134 LOGE("write result failed");
1135 return ERR_DM_IPC_WRITE_FAILED;
1136 }
1137 return DM_OK;
1138 }
1139
ON_IPC_CMD(CREATE_PIN_HOLDER,MessageParcel & data,MessageParcel & reply)1140 ON_IPC_CMD(CREATE_PIN_HOLDER, MessageParcel &data, MessageParcel &reply)
1141 {
1142 std::string pkgName = data.ReadString();
1143 PeerTargetId targetId;
1144 DecodePeerTargetId(data, targetId);
1145 std::string payload = data.ReadString();
1146 DmPinType pinType = static_cast<DmPinType>(data.ReadInt32());
1147 int32_t result = DeviceManagerService::GetInstance().CreatePinHolder(pkgName, targetId, pinType, payload);
1148 if (!reply.WriteInt32(result)) {
1149 LOGE("write result failed");
1150 return ERR_DM_IPC_WRITE_FAILED;
1151 }
1152 return DM_OK;
1153 }
1154
ON_IPC_CMD(DESTROY_PIN_HOLDER,MessageParcel & data,MessageParcel & reply)1155 ON_IPC_CMD(DESTROY_PIN_HOLDER, MessageParcel &data, MessageParcel &reply)
1156 {
1157 std::string pkgName = data.ReadString();
1158 PeerTargetId targetId;
1159 DecodePeerTargetId(data, targetId);
1160 DmPinType pinType = static_cast<DmPinType>(data.ReadInt32());
1161 std::string payload = data.ReadString();
1162 int32_t result = DeviceManagerService::GetInstance().DestroyPinHolder(pkgName, targetId, pinType, payload);
1163 if (!reply.WriteInt32(result)) {
1164 LOGE("write result failed");
1165 return ERR_DM_IPC_WRITE_FAILED;
1166 }
1167 return DM_OK;
1168 }
1169
ON_IPC_SET_REQUEST(SERVER_CREATE_PIN_HOLDER,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)1170 ON_IPC_SET_REQUEST(SERVER_CREATE_PIN_HOLDER, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
1171 {
1172 CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED);
1173 std::shared_ptr<IpcCreatePinHolderReq> pReq = std::static_pointer_cast<IpcCreatePinHolderReq>(pBaseReq);
1174 std::string pkgName = pReq->GetPkgName();
1175 std::string deviceId = pReq->GetDeviceId();
1176 int32_t pinType = pReq->GetPinType();
1177 std::string payload = pReq->GetPayload();
1178
1179 if (!data.WriteString(pkgName)) {
1180 LOGE("write pkgName failed");
1181 return ERR_DM_IPC_WRITE_FAILED;
1182 }
1183 if (!data.WriteString(deviceId)) {
1184 LOGE("write deviceId failed");
1185 return ERR_DM_IPC_WRITE_FAILED;
1186 }
1187 if (!data.WriteInt32(pinType)) {
1188 LOGE("write pinType failed");
1189 return ERR_DM_IPC_WRITE_FAILED;
1190 }
1191 if (!data.WriteString(payload)) {
1192 LOGE("write payload failed");
1193 return ERR_DM_IPC_WRITE_FAILED;
1194 }
1195 return DM_OK;
1196 }
1197
ON_IPC_READ_RESPONSE(SERVER_CREATE_PIN_HOLDER,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)1198 ON_IPC_READ_RESPONSE(SERVER_CREATE_PIN_HOLDER, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
1199 {
1200 CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED);
1201 pBaseRsp->SetErrCode(reply.ReadInt32());
1202 return DM_OK;
1203 }
1204
ON_IPC_SET_REQUEST(SERVER_DESTROY_PIN_HOLDER,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)1205 ON_IPC_SET_REQUEST(SERVER_DESTROY_PIN_HOLDER, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
1206 {
1207 CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED);
1208 std::shared_ptr<IpcDestroyPinHolderReq> pReq = std::static_pointer_cast<IpcDestroyPinHolderReq>(pBaseReq);
1209 std::string pkgName = pReq->GetPkgName();
1210 int32_t pinType = pReq->GetPinType();
1211 std::string payload = pReq->GetPayload();
1212
1213 if (!data.WriteString(pkgName)) {
1214 LOGE("write pkgName failed");
1215 return ERR_DM_IPC_WRITE_FAILED;
1216 }
1217 if (!data.WriteInt32(pinType)) {
1218 LOGE("write pinType failed");
1219 return ERR_DM_IPC_WRITE_FAILED;
1220 }
1221 if (!data.WriteString(payload)) {
1222 LOGE("write payload failed");
1223 return ERR_DM_IPC_WRITE_FAILED;
1224 }
1225 return DM_OK;
1226 }
1227
ON_IPC_READ_RESPONSE(SERVER_DESTROY_PIN_HOLDER,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)1228 ON_IPC_READ_RESPONSE(SERVER_DESTROY_PIN_HOLDER, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
1229 {
1230 CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED);
1231 pBaseRsp->SetErrCode(reply.ReadInt32());
1232 return DM_OK;
1233 }
1234
ON_IPC_SET_REQUEST(SERVER_CREATE_PIN_HOLDER_RESULT,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)1235 ON_IPC_SET_REQUEST(SERVER_CREATE_PIN_HOLDER_RESULT, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
1236 {
1237 CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED);
1238 std::shared_ptr<IpcNotifyPublishResultReq> pReq = std::static_pointer_cast<IpcNotifyPublishResultReq>(pBaseReq);
1239 std::string pkgName = pReq->GetPkgName();
1240 int32_t result = pReq->GetResult();
1241
1242 if (!data.WriteString(pkgName)) {
1243 LOGE("write pkgName failed");
1244 return ERR_DM_IPC_WRITE_FAILED;
1245 }
1246 if (!data.WriteInt32(result)) {
1247 LOGE("write result failed");
1248 return ERR_DM_IPC_WRITE_FAILED;
1249 }
1250 return DM_OK;
1251 }
1252
ON_IPC_READ_RESPONSE(SERVER_CREATE_PIN_HOLDER_RESULT,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)1253 ON_IPC_READ_RESPONSE(SERVER_CREATE_PIN_HOLDER_RESULT, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
1254 {
1255 CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED);
1256 pBaseRsp->SetErrCode(reply.ReadInt32());
1257 return DM_OK;
1258 }
1259
ON_IPC_SET_REQUEST(SERVER_DESTROY_PIN_HOLDER_RESULT,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)1260 ON_IPC_SET_REQUEST(SERVER_DESTROY_PIN_HOLDER_RESULT, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
1261 {
1262 CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED);
1263 std::shared_ptr<IpcNotifyPublishResultReq> pReq = std::static_pointer_cast<IpcNotifyPublishResultReq>(pBaseReq);
1264 std::string pkgName = pReq->GetPkgName();
1265 int32_t result = pReq->GetResult();
1266
1267 if (!data.WriteString(pkgName)) {
1268 LOGE("write pkgName failed");
1269 return ERR_DM_IPC_WRITE_FAILED;
1270 }
1271 if (!data.WriteInt32(result)) {
1272 LOGE("write result failed");
1273 return ERR_DM_IPC_WRITE_FAILED;
1274 }
1275 return DM_OK;
1276 }
1277
ON_IPC_READ_RESPONSE(SERVER_DESTROY_PIN_HOLDER_RESULT,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)1278 ON_IPC_READ_RESPONSE(SERVER_DESTROY_PIN_HOLDER_RESULT, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
1279 {
1280 CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED);
1281 pBaseRsp->SetErrCode(reply.ReadInt32());
1282 return DM_OK;
1283 }
1284
ON_IPC_CMD(DP_ACL_ADD,MessageParcel & data,MessageParcel & reply)1285 ON_IPC_CMD(DP_ACL_ADD, MessageParcel &data, MessageParcel &reply)
1286 {
1287 std::string udid = data.ReadString();
1288 int32_t result = DeviceManagerService::GetInstance().DpAclAdd(udid);
1289 if (!reply.WriteInt32(result)) {
1290 LOGE("write result failed");
1291 return ERR_DM_IPC_WRITE_FAILED;
1292 }
1293 return DM_OK;
1294 }
1295
ON_IPC_CMD(GET_SECURITY_LEVEL,MessageParcel & data,MessageParcel & reply)1296 ON_IPC_CMD(GET_SECURITY_LEVEL, MessageParcel &data, MessageParcel &reply)
1297 {
1298 std::string pkgName = data.ReadString();
1299 std::string networkId = data.ReadString();
1300 int32_t securityLevel = -1;
1301 int32_t result = DeviceManagerService::GetInstance().GetDeviceSecurityLevel(pkgName, networkId, securityLevel);
1302 if (!reply.WriteInt32(result)) {
1303 return ERR_DM_IPC_WRITE_FAILED;
1304 }
1305 if (!reply.WriteInt32(securityLevel)) {
1306 return ERR_DM_IPC_WRITE_FAILED;
1307 }
1308 return DM_OK;
1309 }
1310
ON_IPC_SET_REQUEST(SERVER_ON_PIN_HOLDER_EVENT,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)1311 ON_IPC_SET_REQUEST(SERVER_ON_PIN_HOLDER_EVENT, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
1312 {
1313 CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED);
1314 std::shared_ptr<IpcNotifyPinHolderEventReq> pReq = std::static_pointer_cast<IpcNotifyPinHolderEventReq>(pBaseReq);
1315 std::string pkgName = pReq->GetPkgName();
1316 int32_t pinHolderEvent = pReq->GetPinHolderEvent();
1317 int32_t result = pReq->GetResult();
1318 std::string content = pReq->GetContent();
1319
1320 if (!data.WriteString(pkgName)) {
1321 LOGE("write pkgName failed");
1322 return ERR_DM_IPC_WRITE_FAILED;
1323 }
1324 if (!data.WriteInt32(result)) {
1325 LOGE("write result failed");
1326 return ERR_DM_IPC_WRITE_FAILED;
1327 }
1328 if (!data.WriteInt32(pinHolderEvent)) {
1329 LOGE("write pinHolderEvent failed");
1330 return ERR_DM_IPC_WRITE_FAILED;
1331 }
1332 if (!data.WriteString(content)) {
1333 LOGE("write content failed");
1334 return ERR_DM_IPC_WRITE_FAILED;
1335 }
1336 return DM_OK;
1337 }
1338
ON_IPC_READ_RESPONSE(SERVER_ON_PIN_HOLDER_EVENT,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)1339 ON_IPC_READ_RESPONSE(SERVER_ON_PIN_HOLDER_EVENT, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
1340 {
1341 CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED);
1342 pBaseRsp->SetErrCode(reply.ReadInt32());
1343 return DM_OK;
1344 }
1345
ON_IPC_CMD(IS_SAME_ACCOUNT,MessageParcel & data,MessageParcel & reply)1346 ON_IPC_CMD(IS_SAME_ACCOUNT, MessageParcel &data, MessageParcel &reply)
1347 {
1348 std::string netWorkId = data.ReadString();
1349 int32_t result = DeviceManagerService::GetInstance().IsSameAccount(netWorkId);
1350 if (!reply.WriteInt32(result)) {
1351 LOGE("write result failed.");
1352 return ERR_DM_IPC_WRITE_FAILED;
1353 }
1354 return DM_OK;
1355 }
1356
ON_IPC_CMD(CHECK_API_PERMISSION,MessageParcel & data,MessageParcel & reply)1357 ON_IPC_CMD(CHECK_API_PERMISSION, MessageParcel &data, MessageParcel &reply)
1358 {
1359 int32_t permissionLevel = data.ReadInt32();
1360 int32_t result = DeviceManagerService::GetInstance().CheckApiPermission(permissionLevel);
1361 if (!reply.WriteInt32(result)) {
1362 LOGE("write result failed");
1363 return ERR_DM_IPC_WRITE_FAILED;
1364 }
1365 return DM_OK;
1366 }
1367
ON_IPC_CMD(CHECK_ACCESS_CONTROL,MessageParcel & data,MessageParcel & reply)1368 ON_IPC_CMD(CHECK_ACCESS_CONTROL, MessageParcel &data, MessageParcel &reply)
1369 {
1370 DmAccessCaller caller;
1371 DmAccessCallee callee;
1372 DecodeDmAccessCaller(data, caller);
1373 DecodeDmAccessCallee(data, callee);
1374 int32_t result = DeviceManagerService::GetInstance().CheckAccessControl(caller, callee);
1375 if (!reply.WriteInt32(result)) {
1376 LOGE("write result failed.");
1377 return ERR_DM_IPC_WRITE_FAILED;
1378 }
1379 return DM_OK;
1380 }
1381
ON_IPC_CMD(CHECK_SAME_ACCOUNT,MessageParcel & data,MessageParcel & reply)1382 ON_IPC_CMD(CHECK_SAME_ACCOUNT, MessageParcel &data, MessageParcel &reply)
1383 {
1384 DmAccessCaller caller;
1385 DmAccessCallee callee;
1386 DecodeDmAccessCaller(data, caller);
1387 DecodeDmAccessCallee(data, callee);
1388 int32_t result = DeviceManagerService::GetInstance().CheckIsSameAccount(caller, callee);
1389 if (!reply.WriteInt32(result)) {
1390 LOGE("write result failed.");
1391 return ERR_DM_IPC_WRITE_FAILED;
1392 }
1393 return DM_OK;
1394 }
1395
1396
ON_IPC_CMD(SHIFT_LNN_GEAR,MessageParcel & data,MessageParcel & reply)1397 ON_IPC_CMD(SHIFT_LNN_GEAR, MessageParcel &data, MessageParcel &reply)
1398 {
1399 std::string pkgName = data.ReadString();
1400 int32_t result = DeviceManagerService::GetInstance().ShiftLNNGear(pkgName, pkgName, true, true);
1401 if (!reply.WriteInt32(result)) {
1402 LOGE("write result failed");
1403 return ERR_DM_IPC_WRITE_FAILED;
1404 }
1405 return DM_OK;
1406 }
1407
ON_IPC_CMD(SET_DN_POLICY,MessageParcel & data,MessageParcel & reply)1408 ON_IPC_CMD(SET_DN_POLICY, MessageParcel &data, MessageParcel &reply)
1409 {
1410 std::string pkgName = data.ReadString();
1411 std::string policyStr = data.ReadString();
1412 std::map<std::string, std::string> policy;
1413 ParseMapFromJsonString(policyStr, policy);
1414 int32_t result = DeviceManagerService::GetInstance().SetDnPolicy(pkgName, policy);
1415 if (!reply.WriteInt32(result)) {
1416 LOGE("write result failed");
1417 return ERR_DM_IPC_WRITE_FAILED;
1418 }
1419 return DM_OK;
1420 }
1421
ON_IPC_CMD(STOP_AUTHENTICATE_DEVICE,MessageParcel & data,MessageParcel & reply)1422 ON_IPC_CMD(STOP_AUTHENTICATE_DEVICE, MessageParcel &data, MessageParcel &reply)
1423 {
1424 std::string pkgName = data.ReadString();
1425 int32_t result = DeviceManagerService::GetInstance().StopAuthenticateDevice(pkgName);
1426 if (!reply.WriteInt32(result)) {
1427 LOGE("write result failed");
1428 return ERR_DM_IPC_WRITE_FAILED;
1429 }
1430 return DM_OK;
1431 }
1432
ON_IPC_SET_REQUEST(REMOTE_DEVICE_TRUST_CHANGE,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)1433 ON_IPC_SET_REQUEST(REMOTE_DEVICE_TRUST_CHANGE, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
1434 {
1435 CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED);
1436 std::shared_ptr<IpcNotifyDevTrustChangeReq> pReq = std::static_pointer_cast<IpcNotifyDevTrustChangeReq>(pBaseReq);
1437 std::string pkgName = pReq->GetPkgName();
1438 std::string udid = pReq->GetUdid();
1439 int32_t authForm = pReq->GetAuthForm();
1440 std::string uuid = pReq->GetUuid();
1441 if (!data.WriteString(pkgName)) {
1442 LOGE("write pkgName failed");
1443 return ERR_DM_IPC_WRITE_FAILED;
1444 }
1445 if (!data.WriteString(udid)) {
1446 LOGE("write udid failed");
1447 return ERR_DM_IPC_WRITE_FAILED;
1448 }
1449 if (!data.WriteInt32(authForm)) {
1450 LOGE("write authForm code failed");
1451 return ERR_DM_IPC_WRITE_FAILED;
1452 }
1453 if (!data.WriteString(uuid)) {
1454 LOGE("write uuid code failed");
1455 return ERR_DM_IPC_WRITE_FAILED;
1456 }
1457 return DM_OK;
1458 }
1459
ON_IPC_READ_RESPONSE(REMOTE_DEVICE_TRUST_CHANGE,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)1460 ON_IPC_READ_RESPONSE(REMOTE_DEVICE_TRUST_CHANGE, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
1461 {
1462 CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED);
1463 pBaseRsp->SetErrCode(reply.ReadInt32());
1464 return DM_OK;
1465 }
1466
ON_IPC_SET_REQUEST(SERVER_DEVICE_SCREEN_STATE_NOTIFY,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)1467 ON_IPC_SET_REQUEST(SERVER_DEVICE_SCREEN_STATE_NOTIFY, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
1468 {
1469 CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED);
1470 std::shared_ptr<IpcNotifyDeviceStateReq> pReq = std::static_pointer_cast<IpcNotifyDeviceStateReq>(pBaseReq);
1471 std::string pkgName = pReq->GetPkgName();
1472 DmDeviceInfo deviceInfo = pReq->GetDeviceInfo();
1473
1474 if (!data.WriteString(pkgName)) {
1475 LOGE("write pkgName failed");
1476 return ERR_DM_IPC_WRITE_FAILED;
1477 }
1478 if (!EncodeDmDeviceInfo(deviceInfo, data)) {
1479 LOGE("write dm device info failed");
1480 return ERR_DM_IPC_WRITE_FAILED;
1481 }
1482 return DM_OK;
1483 }
1484
ON_IPC_READ_RESPONSE(SERVER_DEVICE_SCREEN_STATE_NOTIFY,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)1485 ON_IPC_READ_RESPONSE(SERVER_DEVICE_SCREEN_STATE_NOTIFY, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
1486 {
1487 CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED);
1488 pBaseRsp->SetErrCode(reply.ReadInt32());
1489 return DM_OK;
1490 }
1491
ON_IPC_CMD(GET_DEVICE_SCREEN_STATUS,MessageParcel & data,MessageParcel & reply)1492 ON_IPC_CMD(GET_DEVICE_SCREEN_STATUS, MessageParcel &data, MessageParcel &reply)
1493 {
1494 std::string pkgName = data.ReadString();
1495 std::string networkId = data.ReadString();
1496 int32_t screenStatus = -1;
1497 int32_t result = DeviceManagerService::GetInstance().GetDeviceScreenStatus(pkgName, networkId, screenStatus);
1498 if (!reply.WriteInt32(result)) {
1499 return ERR_DM_IPC_WRITE_FAILED;
1500 }
1501 if (!reply.WriteInt32(screenStatus)) {
1502 return ERR_DM_IPC_WRITE_FAILED;
1503 }
1504 return DM_OK;
1505 }
1506
ON_IPC_CMD(GET_NETWORKID_BY_UDID,MessageParcel & data,MessageParcel & reply)1507 ON_IPC_CMD(GET_NETWORKID_BY_UDID, MessageParcel &data, MessageParcel &reply)
1508 {
1509 std::string pkgName = data.ReadString();
1510 std::string udid = data.ReadString();
1511 std::string netWorkId;
1512 int32_t result = DeviceManagerService::GetInstance().GetNetworkIdByUdid(pkgName, udid, netWorkId);
1513
1514 if (!reply.WriteInt32(result)) {
1515 LOGE("write result failed");
1516 return ERR_DM_IPC_WRITE_FAILED;
1517 }
1518 if (!reply.WriteString(netWorkId)) {
1519 LOGE("write result failed");
1520 return ERR_DM_IPC_WRITE_FAILED;
1521 }
1522 return DM_OK;
1523 }
1524
ON_IPC_CMD(GET_ANONY_LOCAL_UDID,MessageParcel & data,MessageParcel & reply)1525 ON_IPC_CMD(GET_ANONY_LOCAL_UDID, MessageParcel &data, MessageParcel &reply)
1526 {
1527 std::string pkgName = data.ReadString();
1528 std::string anonyUdid;
1529 int32_t result = DeviceManagerService::GetInstance().GetAnonyLocalUdid(pkgName, anonyUdid);
1530 if (!reply.WriteInt32(result)) {
1531 return ERR_DM_IPC_WRITE_FAILED;
1532 }
1533 if (!reply.WriteString(anonyUdid)) {
1534 return ERR_DM_IPC_WRITE_FAILED;
1535 }
1536 return DM_OK;
1537 }
1538
ON_IPC_SET_REQUEST(SERVICE_CREDENTIAL_AUTH_STATUS_NOTIFY,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)1539 ON_IPC_SET_REQUEST(SERVICE_CREDENTIAL_AUTH_STATUS_NOTIFY, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
1540 {
1541 CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED);
1542 std::shared_ptr<IpcNotifyCredentialAuthStatusReq> pReq =
1543 std::static_pointer_cast<IpcNotifyCredentialAuthStatusReq>(pBaseReq);
1544 std::string pkgName = pReq->GetPkgName();
1545 std::string deviceList = pReq->GetDeviceList();
1546 uint16_t deviceTypeId = pReq->GetDeviceTypeId();
1547 int32_t errCode = pReq->GetErrCode();
1548
1549 if (!data.WriteString(pkgName)) {
1550 LOGE("write pkgName failed");
1551 return ERR_DM_IPC_WRITE_FAILED;
1552 }
1553 if (!data.WriteString(deviceList)) {
1554 LOGE("write deviceList failed");
1555 return ERR_DM_IPC_WRITE_FAILED;
1556 }
1557 if (!data.WriteUint16(deviceTypeId)) {
1558 LOGE("write deviceTypeId failed");
1559 return ERR_DM_IPC_WRITE_FAILED;
1560 }
1561 if (!data.WriteInt32(errCode)) {
1562 LOGE("write errCode failed");
1563 return ERR_DM_IPC_WRITE_FAILED;
1564 }
1565 return DM_OK;
1566 }
1567
ON_IPC_READ_RESPONSE(SERVICE_CREDENTIAL_AUTH_STATUS_NOTIFY,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)1568 ON_IPC_READ_RESPONSE(SERVICE_CREDENTIAL_AUTH_STATUS_NOTIFY, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
1569 {
1570 CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED);
1571 pBaseRsp->SetErrCode(reply.ReadInt32());
1572 return DM_OK;
1573 }
1574
ON_IPC_CMD(SYNC_CALLBACK,MessageParcel & data,MessageParcel & reply)1575 ON_IPC_CMD(SYNC_CALLBACK, MessageParcel &data, MessageParcel &reply)
1576 {
1577 std::string pkgName = data.ReadString();
1578 int32_t dmCommonNotifyEvent = data.ReadInt32();
1579 ProcessInfo processInfo;
1580 processInfo.pkgName = pkgName;
1581 MultipleUserConnector::GetCallerUserId(processInfo.userId);
1582 int32_t result = DeviceManagerServiceNotify::GetInstance().RegisterCallBack(dmCommonNotifyEvent, processInfo);
1583 if (dmCommonNotifyEvent == static_cast<int32_t>(DmCommonNotifyEvent::REG_DEVICE_STATE)) {
1584 DeviceManagerService::GetInstance().RegDevStateCallbackToService(pkgName);
1585 }
1586 if (!reply.WriteInt32(result)) {
1587 LOGE("write result failed");
1588 return ERR_DM_IPC_WRITE_FAILED;
1589 }
1590 return DM_OK;
1591 }
1592
ON_IPC_CMD(REG_AUTHENTICATION_TYPE,MessageParcel & data,MessageParcel & reply)1593 ON_IPC_CMD(REG_AUTHENTICATION_TYPE, MessageParcel &data, MessageParcel &reply)
1594 {
1595 std::string pkgName = data.ReadString();
1596 std::string authTypeStr = data.ReadString();
1597 std::map<std::string, std::string> authParam;
1598 ParseMapFromJsonString(authTypeStr, authParam);
1599 int32_t result = DeviceManagerService::GetInstance().RegisterAuthenticationType(pkgName, authParam);
1600 if (!reply.WriteInt32(result)) {
1601 LOGE("write result failed");
1602 return ERR_DM_IPC_WRITE_FAILED;
1603 }
1604 return DM_OK;
1605 }
1606
ON_IPC_CMD(GET_DEVICE_PROFILE_INFO_LIST,MessageParcel & data,MessageParcel & reply)1607 ON_IPC_CMD(GET_DEVICE_PROFILE_INFO_LIST, MessageParcel &data, MessageParcel &reply)
1608 {
1609 std::string pkgName = data.ReadString();
1610 DmDeviceProfileInfoFilterOptions filterOptions;
1611 int32_t ret = IpcModelCodec::DecodeDmDeviceProfileInfoFilterOptions(data, filterOptions);
1612 if (ret != DM_OK) {
1613 LOGE("DecodeDmDeviceProfileInfoFilterOptions fail ret:%{public}d,", ret);
1614 return ret;
1615 }
1616 int32_t result = DeviceManagerService::GetInstance().GetDeviceProfileInfoList(pkgName, filterOptions);
1617 if (!reply.WriteInt32(result)) {
1618 LOGE("write result failed");
1619 return ERR_DM_IPC_WRITE_FAILED;
1620 }
1621 return DM_OK;
1622 }
1623
ON_IPC_SET_REQUEST(GET_DEVICE_PROFILE_INFO_LIST_RESULT,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)1624 ON_IPC_SET_REQUEST(GET_DEVICE_PROFILE_INFO_LIST_RESULT, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
1625 {
1626 CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED);
1627 std::shared_ptr<IpcNotifyGetDeviceProfileInfoListReq> pReq =
1628 std::static_pointer_cast<IpcNotifyGetDeviceProfileInfoListReq>(pBaseReq);
1629 std::string pkgName = pReq->GetPkgName();
1630 if (!data.WriteString(pkgName)) {
1631 LOGE("write pkgName failed");
1632 return ERR_DM_IPC_WRITE_FAILED;
1633 }
1634 int32_t result = pReq->GetResult();
1635 if (!data.WriteInt32(result)) {
1636 LOGE("write result code failed");
1637 return ERR_DM_IPC_WRITE_FAILED;
1638 }
1639 std::vector<DmDeviceProfileInfo> deviceProfileInfos = pReq->GetDeviceProfileInfoList();
1640 if (!data.WriteInt32((int32_t)deviceProfileInfos.size())) {
1641 LOGE("write device list size failed");
1642 return ERR_DM_IPC_WRITE_FAILED;
1643 }
1644 for (const auto &devInfo : deviceProfileInfos) {
1645 if (!IpcModelCodec::EncodeDmDeviceProfileInfo(devInfo, data)) {
1646 LOGE("write dm device profile info failed");
1647 return ERR_DM_IPC_WRITE_FAILED;
1648 }
1649 }
1650 return DM_OK;
1651 }
1652
ON_IPC_READ_RESPONSE(GET_DEVICE_PROFILE_INFO_LIST_RESULT,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)1653 ON_IPC_READ_RESPONSE(GET_DEVICE_PROFILE_INFO_LIST_RESULT, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
1654 {
1655 CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED);
1656 pBaseRsp->SetErrCode(reply.ReadInt32());
1657 return DM_OK;
1658 }
1659
ON_IPC_CMD(PUT_DEVICE_PROFILE_INFO_LIST,MessageParcel & data,MessageParcel & reply)1660 ON_IPC_CMD(PUT_DEVICE_PROFILE_INFO_LIST, MessageParcel &data, MessageParcel &reply)
1661 {
1662 std::string pkgName = data.ReadString();
1663 int32_t deviceNum = data.ReadInt32();
1664 std::vector<DmDeviceProfileInfo> deviceProfileInfoList;
1665 if (deviceNum > 0 && deviceNum <= MAX_DEVICE_PROFILE_SIZE) {
1666 for (int32_t i = 0; i < deviceNum; ++i) {
1667 DmDeviceProfileInfo deviceInfo;
1668 IpcModelCodec::DecodeDmDeviceProfileInfo(data, deviceInfo);
1669 deviceProfileInfoList.emplace_back(deviceInfo);
1670 }
1671 }
1672 int32_t result = DeviceManagerService::GetInstance().PutDeviceProfileInfoList(pkgName, deviceProfileInfoList);
1673 if (!reply.WriteInt32(result)) {
1674 LOGE("write result failed");
1675 return ERR_DM_IPC_WRITE_FAILED;
1676 }
1677 return DM_OK;
1678 }
1679
ON_IPC_CMD(GET_DEVICE_ICON_INFO,MessageParcel & data,MessageParcel & reply)1680 ON_IPC_CMD(GET_DEVICE_ICON_INFO, MessageParcel &data, MessageParcel &reply)
1681 {
1682 std::string pkgName = data.ReadString();
1683 DmDeviceIconInfoFilterOptions filterOptions;
1684 IpcModelCodec::DecodeDmDeviceIconInfoFilterOptions(data, filterOptions);
1685 int32_t result = DeviceManagerService::GetInstance().GetDeviceIconInfo(pkgName, filterOptions);
1686 if (!reply.WriteInt32(result)) {
1687 LOGE("write result failed");
1688 return ERR_DM_IPC_WRITE_FAILED;
1689 }
1690 return DM_OK;
1691 }
1692
ON_IPC_SET_REQUEST(GET_DEVICE_ICON_INFO_RESULT,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)1693 ON_IPC_SET_REQUEST(GET_DEVICE_ICON_INFO_RESULT, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
1694 {
1695 CHECK_NULL_RETURN(pBaseReq, ERR_DM_FAILED);
1696 std::shared_ptr<IpcNotifyGetDeviceIconInfoReq> pReq =
1697 std::static_pointer_cast<IpcNotifyGetDeviceIconInfoReq>(pBaseReq);
1698 std::string pkgName = pReq->GetPkgName();
1699 if (!data.WriteString(pkgName)) {
1700 LOGE("write pkgName failed");
1701 return ERR_DM_IPC_WRITE_FAILED;
1702 }
1703 int32_t result = pReq->GetResult();
1704 if (!data.WriteInt32(result)) {
1705 LOGE("write result code failed");
1706 return ERR_DM_IPC_WRITE_FAILED;
1707 }
1708 if (!IpcModelCodec::EncodeDmDeviceIconInfo(pReq->GetDmDeviceIconInfo(), data)) {
1709 LOGE("write dm device icon info failed");
1710 return ERR_DM_IPC_WRITE_FAILED;
1711 }
1712 return DM_OK;
1713 }
1714
ON_IPC_READ_RESPONSE(GET_DEVICE_ICON_INFO_RESULT,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)1715 ON_IPC_READ_RESPONSE(GET_DEVICE_ICON_INFO_RESULT, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
1716 {
1717 CHECK_NULL_RETURN(pBaseRsp, ERR_DM_FAILED);
1718 pBaseRsp->SetErrCode(reply.ReadInt32());
1719 return DM_OK;
1720 }
1721
ON_IPC_CMD(GET_LOCAL_DISPLAY_DEVICE_NAME,MessageParcel & data,MessageParcel & reply)1722 ON_IPC_CMD(GET_LOCAL_DISPLAY_DEVICE_NAME, MessageParcel &data, MessageParcel &reply)
1723 {
1724 std::string pkgName = data.ReadString();
1725 int32_t maxNameLength = data.ReadInt32();
1726 std::string displayName = "";
1727 int32_t result = DeviceManagerService::GetInstance().GetLocalDisplayDeviceName(pkgName, maxNameLength, displayName);
1728 if (!reply.WriteInt32(result)) {
1729 LOGE("write result failed");
1730 return ERR_DM_IPC_WRITE_FAILED;
1731 }
1732 if (!reply.WriteString(displayName)) {
1733 LOGE("write displayName failed");
1734 return ERR_DM_IPC_WRITE_FAILED;
1735 }
1736 return DM_OK;
1737 }
1738
ON_IPC_CMD(REG_LOCALSERVICE_INFO,MessageParcel & data,MessageParcel & reply)1739 ON_IPC_CMD(REG_LOCALSERVICE_INFO, MessageParcel &data, MessageParcel &reply)
1740 {
1741 DMLocalServiceInfo serviceInfo;
1742 IpcModelCodec::DecodeLocalServiceInfo(data, serviceInfo);
1743 int32_t result = DeviceManagerService::GetInstance().RegisterLocalServiceInfo(serviceInfo);
1744 if (!reply.WriteInt32(result)) {
1745 LOGE("write result failed");
1746 return ERR_DM_IPC_WRITE_FAILED;
1747 }
1748 return DM_OK;
1749 }
1750
ON_IPC_CMD(UNREG_LOCALSERVICE_INFO,MessageParcel & data,MessageParcel & reply)1751 ON_IPC_CMD(UNREG_LOCALSERVICE_INFO, MessageParcel &data, MessageParcel &reply)
1752 {
1753 std::string bundleName = data.ReadString();
1754 int32_t pinExchangeType = data.ReadInt32();
1755 int32_t result = DeviceManagerService::GetInstance().UnRegisterLocalServiceInfo(bundleName, pinExchangeType);
1756 if (!reply.WriteInt32(result)) {
1757 LOGE("write result failed");
1758 return ERR_DM_IPC_WRITE_FAILED;
1759 }
1760 return DM_OK;
1761 }
1762
ON_IPC_CMD(UPDATE_LOCALSERVICE_INFO,MessageParcel & data,MessageParcel & reply)1763 ON_IPC_CMD(UPDATE_LOCALSERVICE_INFO, MessageParcel &data, MessageParcel &reply)
1764 {
1765 DMLocalServiceInfo serviceInfo;
1766 IpcModelCodec::DecodeLocalServiceInfo(data, serviceInfo);
1767 int32_t result = DeviceManagerService::GetInstance().UpdateLocalServiceInfo(serviceInfo);
1768 if (!reply.WriteInt32(result)) {
1769 LOGE("write result failed");
1770 return ERR_DM_IPC_WRITE_FAILED;
1771 }
1772 return DM_OK;
1773 }
1774
ON_IPC_CMD(GET_SERVICEINFO_BYBUNDLENAME_PINEXCHANGETYPE,MessageParcel & data,MessageParcel & reply)1775 ON_IPC_CMD(GET_SERVICEINFO_BYBUNDLENAME_PINEXCHANGETYPE, MessageParcel &data, MessageParcel &reply)
1776 {
1777 std::string bundleName = data.ReadString();
1778 int64_t pinExchangeType = data.ReadInt32();
1779 DMLocalServiceInfo serviceInfo;
1780 int32_t result = DeviceManagerService::GetInstance().GetLocalServiceInfoByBundleNameAndPinExchangeType(
1781 bundleName, pinExchangeType, serviceInfo);
1782 if (!reply.WriteInt32(result)) {
1783 LOGE("write result failed");
1784 return ERR_DM_IPC_WRITE_FAILED;
1785 }
1786 if (result == DM_OK && !IpcModelCodec::EncodeLocalServiceInfo(serviceInfo, reply)) {
1787 LOGE("write result failed");
1788 return ERR_DM_IPC_WRITE_FAILED;
1789 }
1790 return DM_OK;
1791 }
1792
ON_IPC_CMD(SET_LOCAL_DEVICE_NAME,MessageParcel & data,MessageParcel & reply)1793 ON_IPC_CMD(SET_LOCAL_DEVICE_NAME, MessageParcel &data, MessageParcel &reply)
1794 {
1795 std::string pkgName = data.ReadString();
1796 std::string deviceName = data.ReadString();
1797 int32_t result = DeviceManagerService::GetInstance().SetLocalDeviceName(pkgName, deviceName);
1798 if (!reply.WriteInt32(result)) {
1799 LOGE("write result failed");
1800 return ERR_DM_IPC_WRITE_FAILED;
1801 }
1802 return DM_OK;
1803 }
1804
ON_IPC_SET_REQUEST(SET_LOCAL_DEVICE_NAME_RESULT,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)1805 ON_IPC_SET_REQUEST(SET_LOCAL_DEVICE_NAME_RESULT, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
1806 {
1807 if (pBaseReq == nullptr) {
1808 return ERR_DM_FAILED;
1809 }
1810 std::shared_ptr<IpcNotifySetLocalDeviceNameReq> pReq =
1811 std::static_pointer_cast<IpcNotifySetLocalDeviceNameReq>(pBaseReq);
1812 std::string pkgName = pReq->GetPkgName();
1813 if (!data.WriteString(pkgName)) {
1814 LOGE("write pkgName failed");
1815 return ERR_DM_IPC_WRITE_FAILED;
1816 }
1817 int32_t result = pReq->GetResult();
1818 if (!data.WriteInt32(result)) {
1819 LOGE("write result code failed");
1820 return ERR_DM_IPC_WRITE_FAILED;
1821 }
1822 return DM_OK;
1823 }
1824
ON_IPC_READ_RESPONSE(SET_LOCAL_DEVICE_NAME_RESULT,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)1825 ON_IPC_READ_RESPONSE(SET_LOCAL_DEVICE_NAME_RESULT, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
1826 {
1827 if (pBaseRsp == nullptr) {
1828 LOGE("pBaseRsp is null");
1829 return ERR_DM_FAILED;
1830 }
1831 pBaseRsp->SetErrCode(reply.ReadInt32());
1832 return DM_OK;
1833 }
1834
ON_IPC_CMD(SET_REMOTE_DEVICE_NAME,MessageParcel & data,MessageParcel & reply)1835 ON_IPC_CMD(SET_REMOTE_DEVICE_NAME, MessageParcel &data, MessageParcel &reply)
1836 {
1837 std::string pkgName = data.ReadString();
1838 std::string deviceId = data.ReadString();
1839 std::string deviceName = data.ReadString();
1840 int32_t result = DeviceManagerService::GetInstance().SetRemoteDeviceName(pkgName, deviceId, deviceName);
1841 if (!reply.WriteInt32(result)) {
1842 LOGE("write result failed");
1843 return ERR_DM_IPC_WRITE_FAILED;
1844 }
1845 return DM_OK;
1846 }
1847
ON_IPC_SET_REQUEST(SET_REMOTE_DEVICE_NAME_RESULT,std::shared_ptr<IpcReq> pBaseReq,MessageParcel & data)1848 ON_IPC_SET_REQUEST(SET_REMOTE_DEVICE_NAME_RESULT, std::shared_ptr<IpcReq> pBaseReq, MessageParcel &data)
1849 {
1850 if (pBaseReq == nullptr) {
1851 return ERR_DM_FAILED;
1852 }
1853 std::shared_ptr<IpcNotifySetRemoteDeviceNameReq> pReq =
1854 std::static_pointer_cast<IpcNotifySetRemoteDeviceNameReq>(pBaseReq);
1855 std::string pkgName = pReq->GetPkgName();
1856 if (!data.WriteString(pkgName)) {
1857 LOGE("write pkgName failed");
1858 return ERR_DM_IPC_WRITE_FAILED;
1859 }
1860 std::string deviceId = pReq->GetDeviceId();
1861 if (!data.WriteString(deviceId)) {
1862 LOGE("write deviceId failed");
1863 return ERR_DM_IPC_WRITE_FAILED;
1864 }
1865 int32_t result = pReq->GetResult();
1866 if (!data.WriteInt32(result)) {
1867 LOGE("write result code failed");
1868 return ERR_DM_IPC_WRITE_FAILED;
1869 }
1870 return DM_OK;
1871 }
1872
ON_IPC_READ_RESPONSE(SET_REMOTE_DEVICE_NAME_RESULT,MessageParcel & reply,std::shared_ptr<IpcRsp> pBaseRsp)1873 ON_IPC_READ_RESPONSE(SET_REMOTE_DEVICE_NAME_RESULT, MessageParcel &reply, std::shared_ptr<IpcRsp> pBaseRsp)
1874 {
1875 if (pBaseRsp == nullptr) {
1876 LOGE("pBaseRsp is null");
1877 return ERR_DM_FAILED;
1878 }
1879 pBaseRsp->SetErrCode(reply.ReadInt32());
1880 return DM_OK;
1881 }
1882
ON_IPC_CMD(RESTORE_LOCAL_DEVICE_NAME,MessageParcel & data,MessageParcel & reply)1883 ON_IPC_CMD(RESTORE_LOCAL_DEVICE_NAME, MessageParcel &data, MessageParcel &reply)
1884 {
1885 std::string pkgName = data.ReadString();
1886 int32_t result = DeviceManagerService::GetInstance().RestoreLocalDeviceName(pkgName);
1887 if (!reply.WriteInt32(result)) {
1888 LOGE("write result failed");
1889 return ERR_DM_IPC_WRITE_FAILED;
1890 }
1891 return DM_OK;
1892 }
1893
ON_IPC_CMD(GET_DEVICE_NETWORK_ID_LIST,MessageParcel & data,MessageParcel & reply)1894 ON_IPC_CMD(GET_DEVICE_NETWORK_ID_LIST, MessageParcel &data, MessageParcel &reply)
1895 {
1896 std::string pkgName = data.ReadString();
1897 NetworkIdQueryFilter queryFilter;
1898 IpcModelCodec::DecodeNetworkIdQueryFilter(data, queryFilter);
1899 std::vector<std::string> networkIds;
1900 int32_t result = DeviceManagerService::GetInstance().GetDeviceNetworkIdList(pkgName, queryFilter, networkIds);
1901 if (!reply.WriteInt32(result)) {
1902 LOGE("write result failed");
1903 return ERR_DM_IPC_WRITE_FAILED;
1904 }
1905 if (result == DM_OK && !IpcModelCodec::EncodeStringVector(networkIds, reply)) {
1906 LOGE("write result failed");
1907 return ERR_DM_IPC_WRITE_FAILED;
1908 }
1909 return DM_OK;
1910 }
1911 } // namespace DistributedHardware
1912 } // namespace OHOS
1913