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