• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-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 <memory>
17 #include "distributed_device_profile_proxy.h"
18 
19 namespace OHOS {
20 namespace DistributedDeviceProfile {
21 namespace {
22     const std::string TAG = "DistributedDeviceProfileProxy";
23 }
24 
PutAccessControlProfile(const AccessControlProfile & aclProfile)25 int32_t DistributedDeviceProfileProxy::PutAccessControlProfile(const AccessControlProfile& aclProfile)
26 {
27     sptr<IRemoteObject> remote = nullptr;
28     GET_REMOTE_OBJECT(remote);
29     MessageParcel data;
30     WRITE_INTERFACE_TOKEN(data);
31     if (!aclProfile.Marshalling(data)) {
32         HILOGE("dp ipc write parcel fail");
33         return DP_WRITE_PARCEL_FAIL;
34     }
35     MessageParcel reply;
36     SEND_REQUEST(remote, static_cast<uint32_t>(DPInterfaceCode::PUT_ACL_PROFILE), data, reply);
37     return DP_SUCCESS;
38 }
39 
UpdateAccessControlProfile(const AccessControlProfile & aclProfile)40 int32_t DistributedDeviceProfileProxy::UpdateAccessControlProfile(const AccessControlProfile& aclProfile)
41 {
42     sptr<IRemoteObject> remote = nullptr;
43     GET_REMOTE_OBJECT(remote);
44     MessageParcel data;
45     WRITE_INTERFACE_TOKEN(data);
46     if (!aclProfile.Marshalling(data)) {
47         HILOGE("dp ipc write parcel fail");
48         return DP_WRITE_PARCEL_FAIL;
49     }
50     MessageParcel reply;
51     SEND_REQUEST(remote, static_cast<uint32_t>(DPInterfaceCode::UPDATE_ACL_PROFILE), data, reply);
52     return DP_SUCCESS;
53 }
54 
PutProductInfoBatch(const std::vector<ProductInfo> & productInfos)55 int32_t DistributedDeviceProfileProxy::PutProductInfoBatch(const std::vector<ProductInfo>& productInfos)
56 {
57     sptr<IRemoteObject> remote = nullptr;
58     GET_REMOTE_OBJECT(remote);
59     MessageParcel data;
60     WRITE_INTERFACE_TOKEN(data);
61     if (!IpcUtils::Marshalling(data, productInfos)) {
62         HILOGE("dp ipc write parcel fail");
63         return DP_WRITE_PARCEL_FAIL;
64     }
65     MessageParcel reply;
66     SEND_REQUEST(remote, static_cast<uint32_t>(DPInterfaceCode::PUT_PRODUCT_INFO_BATCH), data, reply);
67     return DP_SUCCESS;
68 }
69 
PutDeviceIconInfoBatch(const std::vector<DeviceIconInfo> & deviceIconInfos)70 int32_t DistributedDeviceProfileProxy::PutDeviceIconInfoBatch(const std::vector<DeviceIconInfo>& deviceIconInfos)
71 {
72     sptr<IRemoteObject> remote = nullptr;
73     GET_REMOTE_OBJECT(remote);
74     MessageParcel data;
75     WRITE_INTERFACE_TOKEN(data);
76     if (!IpcUtils::Marshalling(data, deviceIconInfos)) {
77         HILOGE("dp ipc write parcel fail");
78         return DP_WRITE_PARCEL_FAIL;
79     }
80     MessageParcel reply;
81     SEND_REQUEST(remote, static_cast<uint32_t>(DPInterfaceCode::PUT_DEVICE_ICON_INFO_BATCH), data, reply);
82     return DP_SUCCESS;
83 }
84 
GetDeviceIconInfos(const DeviceIconInfoFilterOptions & filterOptions,std::vector<DeviceIconInfo> & deviceIconInfos)85 int32_t DistributedDeviceProfileProxy::GetDeviceIconInfos(const DeviceIconInfoFilterOptions& filterOptions,
86     std::vector<DeviceIconInfo>& deviceIconInfos)
87 {
88     sptr<IRemoteObject> remote = nullptr;
89     GET_REMOTE_OBJECT(remote);
90     MessageParcel data;
91     WRITE_INTERFACE_TOKEN(data);
92     if (!filterOptions.Marshalling(data)) {
93         HILOGE("dp ipc write parcel fail");
94         return DP_WRITE_PARCEL_FAIL;
95     }
96     MessageParcel reply;
97     SEND_REQUEST(remote, static_cast<uint32_t>(DPInterfaceCode::GET_DEVICE_ICON_INFOS), data, reply);
98     if (!IpcUtils::UnMarshalling(reply, deviceIconInfos)) {
99         HILOGE("dp ipc write parcel fail");
100         return DP_WRITE_PARCEL_FAIL;
101     }
102     return DP_SUCCESS;
103 }
104 
GetTrustDeviceProfile(const std::string & deviceId,TrustDeviceProfile & trustDeviceProfile)105 int32_t DistributedDeviceProfileProxy::GetTrustDeviceProfile(const std::string& deviceId,
106     TrustDeviceProfile& trustDeviceProfile)
107 {
108     sptr<IRemoteObject> remote = nullptr;
109     GET_REMOTE_OBJECT(remote);
110     MessageParcel data;
111     WRITE_INTERFACE_TOKEN(data);
112     WRITE_HELPER(data, String, deviceId);
113     MessageParcel reply;
114     SEND_REQUEST(remote, static_cast<uint32_t>(DPInterfaceCode::GET_TRUST_DEVICE_PROFILE), data, reply);
115     if (!trustDeviceProfile.UnMarshalling(reply)) {
116         HILOGE("dp ipc write parcel fail");
117         return DP_WRITE_PARCEL_FAIL;
118     }
119     return DP_SUCCESS;
120 }
121 
GetAllTrustDeviceProfile(std::vector<TrustDeviceProfile> & trustDeviceProfiles)122 int32_t DistributedDeviceProfileProxy::GetAllTrustDeviceProfile(std::vector<TrustDeviceProfile>& trustDeviceProfiles)
123 {
124     sptr<IRemoteObject> remote = nullptr;
125     GET_REMOTE_OBJECT(remote);
126     MessageParcel data;
127     WRITE_INTERFACE_TOKEN(data);
128     MessageParcel reply;
129     SEND_REQUEST(remote, static_cast<uint32_t>(DPInterfaceCode::GET_ALL_TRUST_DEVICE_PROFILE), data, reply);
130     if (!IpcUtils::UnMarshalling(reply, trustDeviceProfiles)) {
131         HILOGE("dp ipc read parcel fail");
132         return DP_READ_PARCEL_FAIL;
133     }
134     return DP_SUCCESS;
135 }
136 
GetAccessControlProfile(std::map<std::string,std::string> queryParams,std::vector<AccessControlProfile> & accessControlProfiles)137 int32_t DistributedDeviceProfileProxy::GetAccessControlProfile(std::map<std::string, std::string> queryParams,
138     std::vector<AccessControlProfile>& accessControlProfiles)
139 {
140     sptr<IRemoteObject> remote = nullptr;
141     GET_REMOTE_OBJECT(remote);
142     MessageParcel data;
143     WRITE_INTERFACE_TOKEN(data);
144     if (!IpcUtils::Marshalling(data, queryParams)) {
145         HILOGE("dp ipc write parcel fail");
146         return DP_WRITE_PARCEL_FAIL;
147     }
148     MessageParcel reply;
149     SEND_REQUEST(remote, static_cast<uint32_t>(DPInterfaceCode::GET_ACL_PROFILE), data, reply);
150     if (!IpcUtils::UnMarshalling(reply, accessControlProfiles)) {
151         HILOGE("dp ipc read parcel fail");
152         return DP_READ_PARCEL_FAIL;
153     }
154     return DP_SUCCESS;
155 }
156 
GetAllAccessControlProfile(std::vector<AccessControlProfile> & accessControlProfiles)157 int32_t DistributedDeviceProfileProxy::GetAllAccessControlProfile(
158     std::vector<AccessControlProfile>& accessControlProfiles)
159 {
160     sptr<IRemoteObject> remote = nullptr;
161     GET_REMOTE_OBJECT(remote);
162     MessageParcel data;
163     WRITE_INTERFACE_TOKEN(data);
164     MessageParcel reply;
165     SEND_REQUEST(remote, static_cast<uint32_t>(DPInterfaceCode::GET_ALL_ACL_PROFILE), data, reply);
166     if (!IpcUtils::UnMarshalling(reply, accessControlProfiles)) {
167         HILOGE("dp ipc read parcel fail");
168         return DP_READ_PARCEL_FAIL;
169     }
170     return DP_SUCCESS;
171 }
172 
GetAllAclIncludeLnnAcl(std::vector<AccessControlProfile> & accessControlProfiles)173 int32_t DistributedDeviceProfileProxy::GetAllAclIncludeLnnAcl(std::vector<AccessControlProfile>& accessControlProfiles)
174 {
175     sptr<IRemoteObject> remote = nullptr;
176     GET_REMOTE_OBJECT(remote);
177     MessageParcel data;
178     WRITE_INTERFACE_TOKEN(data);
179     MessageParcel reply;
180     SEND_REQUEST(remote, static_cast<uint32_t>(DPInterfaceCode::GET_ALL_ACL_INCLUDE_LNN_ACL), data, reply);
181     if (!IpcUtils::UnMarshalling(reply, accessControlProfiles)) {
182         HILOGE("dp ipc read parcel fail");
183         return DP_READ_PARCEL_FAIL;
184     }
185     return DP_SUCCESS;
186 }
187 
DeleteAccessControlProfile(int32_t accessControlId)188 int32_t DistributedDeviceProfileProxy::DeleteAccessControlProfile(int32_t accessControlId)
189 {
190     sptr<IRemoteObject> remote = nullptr;
191     GET_REMOTE_OBJECT(remote);
192     MessageParcel data;
193     WRITE_INTERFACE_TOKEN(data);
194     WRITE_HELPER(data, Int32, accessControlId);
195     MessageParcel reply;
196     SEND_REQUEST(remote, static_cast<uint32_t>(DPInterfaceCode::DELETE_ACL_PROFILE), data, reply);
197     return DP_SUCCESS;
198 }
199 
PutSessionKey(uint32_t userId,const std::vector<uint8_t> & sessionKey,int32_t & sessionKeyId)200 int32_t DistributedDeviceProfileProxy::PutSessionKey(
201     uint32_t userId, const std::vector<uint8_t>& sessionKey, int32_t& sessionKeyId)
202 {
203     sptr<IRemoteObject> remote = nullptr;
204     GET_REMOTE_OBJECT(remote);
205     MessageParcel data;
206     WRITE_INTERFACE_TOKEN(data);
207     WRITE_HELPER(data, Uint32, userId);
208     if (!IpcUtils::Marshalling(data, sessionKey)) {
209         HILOGE("dp ipc write parcel fail");
210         return DP_WRITE_PARCEL_FAIL;
211     }
212     MessageParcel reply;
213     SEND_REQUEST(remote, static_cast<uint32_t>(DPInterfaceCode::PUT_SESSION_KEY), data, reply);
214     READ_HELPER(reply, Int32, sessionKeyId);
215     return DP_SUCCESS;
216 }
217 
GetSessionKey(uint32_t userId,int32_t sessionKeyId,std::vector<uint8_t> & sessionKey)218 int32_t DistributedDeviceProfileProxy::GetSessionKey(
219     uint32_t userId, int32_t sessionKeyId, std::vector<uint8_t>& sessionKey)
220 {
221     sptr<IRemoteObject> remote = nullptr;
222     GET_REMOTE_OBJECT(remote);
223     MessageParcel data;
224     WRITE_INTERFACE_TOKEN(data);
225     WRITE_HELPER(data, Uint32, userId);
226     WRITE_HELPER(data, Int32, sessionKeyId);
227     MessageParcel reply;
228     SEND_REQUEST(remote, static_cast<uint32_t>(DPInterfaceCode::GET_SESSION_KEY), data, reply);
229     if (!IpcUtils::UnMarshalling(reply, sessionKey)) {
230         HILOGE("dp ipc read parcel fail");
231         return DP_WRITE_PARCEL_FAIL;
232     }
233     return DP_SUCCESS;
234 }
235 
UpdateSessionKey(uint32_t userId,int32_t sessionKeyId,const std::vector<uint8_t> & sessionKey)236 int32_t DistributedDeviceProfileProxy::UpdateSessionKey(
237     uint32_t userId, int32_t sessionKeyId, const std::vector<uint8_t>& sessionKey)
238 {
239     sptr<IRemoteObject> remote = nullptr;
240     GET_REMOTE_OBJECT(remote);
241     MessageParcel data;
242     WRITE_INTERFACE_TOKEN(data);
243     WRITE_HELPER(data, Uint32, userId);
244     WRITE_HELPER(data, Int32, sessionKeyId);
245     if (!IpcUtils::Marshalling(data, sessionKey)) {
246         HILOGE("dp ipc write parcel fail");
247         return DP_WRITE_PARCEL_FAIL;
248     }
249     MessageParcel reply;
250     SEND_REQUEST(remote, static_cast<uint32_t>(DPInterfaceCode::UPDATE_SESSION_KEY), data, reply);
251     return DP_SUCCESS;
252 }
253 
DeleteSessionKey(uint32_t userId,int32_t sessionKeyId)254 int32_t DistributedDeviceProfileProxy::DeleteSessionKey(uint32_t userId, int32_t sessionKeyId)
255 {
256     sptr<IRemoteObject> remote = nullptr;
257     GET_REMOTE_OBJECT(remote);
258     MessageParcel data;
259     WRITE_INTERFACE_TOKEN(data);
260     WRITE_HELPER(data, Uint32, userId);
261     WRITE_HELPER(data, Int32, sessionKeyId);
262     MessageParcel reply;
263     SEND_REQUEST(remote, static_cast<uint32_t>(DPInterfaceCode::DELETE_SESSION_KEY), data, reply);
264     return DP_SUCCESS;
265 }
266 
PutDeviceProfileBatch(std::vector<DeviceProfile> & deviceProfiles)267 int32_t DistributedDeviceProfileProxy::PutDeviceProfileBatch(std::vector<DeviceProfile>& deviceProfiles)
268 {
269     sptr<IRemoteObject> remote = nullptr;
270     GET_REMOTE_OBJECT(remote);
271     MessageParcel data;
272     WRITE_INTERFACE_TOKEN(data);
273     if (!IpcUtils::Marshalling(data, deviceProfiles)) {
274         HILOGE("dp ipc write parcel fail");
275         return DP_WRITE_PARCEL_FAIL;
276     }
277     MessageParcel reply;
278     SEND_REQUEST(remote, static_cast<uint32_t>(DPInterfaceCode::PUT_DEVICE_PROFILE_BATCH), data, reply);
279     return DP_SUCCESS;
280 }
281 
PutServiceProfile(const ServiceProfile & serviceProfile)282 int32_t DistributedDeviceProfileProxy::PutServiceProfile(const ServiceProfile& serviceProfile)
283 {
284     sptr<IRemoteObject> remote = nullptr;
285     GET_REMOTE_OBJECT(remote);
286     MessageParcel data;
287     WRITE_INTERFACE_TOKEN(data);
288     if (!serviceProfile.Marshalling(data)) {
289         HILOGE("dp ipc write parcel fail");
290         return DP_WRITE_PARCEL_FAIL;
291     }
292     MessageParcel reply;
293     SEND_REQUEST(remote, static_cast<uint32_t>(DPInterfaceCode::PUT_SERVICE_PROFILE), data, reply);
294     return DP_SUCCESS;
295 }
296 
PutServiceProfileBatch(const std::vector<ServiceProfile> & serviceProfiles)297 int32_t DistributedDeviceProfileProxy::PutServiceProfileBatch(const std::vector<ServiceProfile>& serviceProfiles)
298 {
299     sptr<IRemoteObject> remote = nullptr;
300     GET_REMOTE_OBJECT(remote);
301     MessageParcel data;
302     WRITE_INTERFACE_TOKEN(data);
303     if (!IpcUtils::Marshalling(data, serviceProfiles)) {
304         HILOGE("dp ipc write parcel fail");
305         return DP_WRITE_PARCEL_FAIL;
306     }
307     MessageParcel reply;
308     SEND_REQUEST(remote, static_cast<uint32_t>(DPInterfaceCode::PUT_SERVICE_PROFILE_BATCH), data, reply);
309     return DP_SUCCESS;
310 }
311 
PutCharacteristicProfile(const CharacteristicProfile & charProfile)312 int32_t DistributedDeviceProfileProxy::PutCharacteristicProfile(const CharacteristicProfile& charProfile)
313 {
314     sptr<IRemoteObject> remote = nullptr;
315     GET_REMOTE_OBJECT(remote);
316     MessageParcel data;
317     WRITE_INTERFACE_TOKEN(data);
318     if (!charProfile.Marshalling(data)) {
319         HILOGE("dp ipc write parcel fail");
320         return DP_WRITE_PARCEL_FAIL;
321     }
322     MessageParcel reply;
323     SEND_REQUEST(remote, static_cast<uint32_t>(DPInterfaceCode::PUT_CHAR_PROFILE), data, reply);
324     return DP_SUCCESS;
325 }
326 
PutCharacteristicProfileBatch(const std::vector<CharacteristicProfile> & charProfiles)327 int32_t DistributedDeviceProfileProxy::PutCharacteristicProfileBatch(
328     const std::vector<CharacteristicProfile>& charProfiles)
329 {
330     sptr<IRemoteObject> remote = nullptr;
331     GET_REMOTE_OBJECT(remote);
332     MessageParcel data;
333     WRITE_INTERFACE_TOKEN(data);
334     if (!IpcUtils::Marshalling(data, charProfiles)) {
335         HILOGE("dp ipc write parcel fail");
336         return DP_WRITE_PARCEL_FAIL;
337     }
338     MessageParcel reply;
339     SEND_REQUEST(remote, static_cast<uint32_t>(DPInterfaceCode::PUT_CHAR_PROFILE_BATCH), data, reply);
340     return DP_SUCCESS;
341 }
342 
GetDeviceProfile(const std::string & deviceId,DeviceProfile & deviceProfile)343 int32_t DistributedDeviceProfileProxy::GetDeviceProfile(const std::string& deviceId, DeviceProfile& deviceProfile)
344 {
345     sptr<IRemoteObject> remote = nullptr;
346     GET_REMOTE_OBJECT(remote);
347     MessageParcel data;
348     WRITE_INTERFACE_TOKEN(data);
349     WRITE_HELPER(data, String, deviceId);
350     WRITE_HELPER(data, Bool, deviceProfile.IsMultiUser());
351     WRITE_HELPER(data, Int32, deviceProfile.GetUserId());
352     MessageParcel reply;
353     SEND_REQUEST(remote, static_cast<uint32_t>(DPInterfaceCode::GET_DEVICE_PROFILE_NEW), data, reply);
354     if (!deviceProfile.UnMarshalling(reply)) {
355         HILOGE("dp ipc read parcel fail");
356         return DP_READ_PARCEL_FAIL;
357     }
358     return DP_SUCCESS;
359 }
360 
GetDeviceProfiles(DeviceProfileFilterOptions & options,std::vector<DeviceProfile> & deviceProfiles)361 int32_t DistributedDeviceProfileProxy::GetDeviceProfiles(DeviceProfileFilterOptions& options,
362     std::vector<DeviceProfile>& deviceProfiles)
363 {
364     sptr<IRemoteObject> remote = nullptr;
365     GET_REMOTE_OBJECT(remote);
366     MessageParcel data;
367     WRITE_INTERFACE_TOKEN(data);
368     if (!options.Marshalling(data)) {
369         HILOGE("dp ipc write parcel fail");
370         return DP_WRITE_PARCEL_FAIL;
371     }
372     MessageParcel reply;
373     SEND_REQUEST(remote, static_cast<uint32_t>(DPInterfaceCode::GET_DEVICE_PROFILES), data, reply);
374     if (!IpcUtils::UnMarshalling(reply, deviceProfiles)) {
375         HILOGE("dp ipc read parcel fail");
376         return DP_READ_PARCEL_FAIL;
377     }
378     return DP_SUCCESS;
379 }
380 
DeleteDeviceProfileBatch(std::vector<DeviceProfile> & deviceProfiles)381 int32_t DistributedDeviceProfileProxy::DeleteDeviceProfileBatch(std::vector<DeviceProfile>& deviceProfiles)
382 {
383     sptr<IRemoteObject> remote = nullptr;
384     GET_REMOTE_OBJECT(remote);
385     MessageParcel data;
386     WRITE_INTERFACE_TOKEN(data);
387     if (!IpcUtils::Marshalling(data, deviceProfiles)) {
388         HILOGE("dp ipc write parcel fail");
389         return DP_WRITE_PARCEL_FAIL;
390     }
391     MessageParcel reply;
392     SEND_REQUEST(remote, static_cast<uint32_t>(DPInterfaceCode::DELETE_DEVICE_PROFILE_BATCH), data, reply);
393     return DP_SUCCESS;
394 }
395 
GetServiceProfile(const std::string & deviceId,const std::string & serviceName,ServiceProfile & serviceProfile)396 int32_t DistributedDeviceProfileProxy::GetServiceProfile(const std::string& deviceId, const std::string& serviceName,
397     ServiceProfile& serviceProfile)
398 {
399     sptr<IRemoteObject> remote = nullptr;
400     GET_REMOTE_OBJECT(remote);
401     MessageParcel data;
402     WRITE_INTERFACE_TOKEN(data);
403     WRITE_HELPER(data, String, deviceId);
404     WRITE_HELPER(data, String, serviceName);
405     WRITE_HELPER(data, Bool, serviceProfile.IsMultiUser());
406     WRITE_HELPER(data, Int32, serviceProfile.GetUserId());
407     MessageParcel reply;
408     SEND_REQUEST(remote, static_cast<uint32_t>(DPInterfaceCode::GET_SERVICE_PROFILE), data, reply);
409     if (!serviceProfile.UnMarshalling(reply)) {
410         HILOGE("dp ipc read parcel fail");
411         return DP_READ_PARCEL_FAIL;
412     }
413     return DP_SUCCESS;
414 }
415 
PutServiceInfoProfile(const ServiceInfoProfile & serviceInfoProfile)416 int32_t DistributedDeviceProfileProxy::PutServiceInfoProfile(const ServiceInfoProfile& serviceInfoProfile)
417 {
418     sptr<IRemoteObject> remote = nullptr;
419     GET_REMOTE_OBJECT(remote);
420     MessageParcel data;
421     WRITE_INTERFACE_TOKEN(data);
422     if (!serviceInfoProfile.Marshalling(data)) {
423         HILOGE("dp ipc write parcel fail");
424         return DP_WRITE_PARCEL_FAIL;
425     }
426     MessageParcel reply;
427     SEND_REQUEST(remote, static_cast<uint32_t>(DPInterfaceCode::PUT_SERVICE_INFO_PROFILE), data, reply);
428     return DP_SUCCESS;
429 }
430 
DeleteServiceInfoProfile(const ServiceInfoUniqueKey & key)431 int32_t DistributedDeviceProfileProxy::DeleteServiceInfoProfile(const ServiceInfoUniqueKey& key)
432 {
433     sptr<IRemoteObject> remote = nullptr;
434     GET_REMOTE_OBJECT(remote);
435     MessageParcel data;
436     WRITE_INTERFACE_TOKEN(data);
437     if (!key.Marshalling(data)) {
438         HILOGE("dp ipc write parcel fail");
439         return DP_WRITE_PARCEL_FAIL;
440     }
441     MessageParcel reply;
442     SEND_REQUEST(remote, static_cast<uint32_t>(DPInterfaceCode::DELETE_SERVICE_INFO_PROFILE), data, reply);
443     return DP_SUCCESS;
444 }
445 
UpdateServiceInfoProfile(const ServiceInfoProfile & serviceInfoProfile)446 int32_t DistributedDeviceProfileProxy::UpdateServiceInfoProfile(const ServiceInfoProfile& serviceInfoProfile)
447 {
448     sptr<IRemoteObject> remote = nullptr;
449     GET_REMOTE_OBJECT(remote);
450     MessageParcel data;
451     WRITE_INTERFACE_TOKEN(data);
452     if (!serviceInfoProfile.Marshalling(data)) {
453         HILOGE("dp ipc write parcel fail");
454         return DP_WRITE_PARCEL_FAIL;
455     }
456     MessageParcel reply;
457     SEND_REQUEST(remote, static_cast<uint32_t>(DPInterfaceCode::UPDATE_SERVICE_INFO_PROFILE), data, reply);
458     return DP_SUCCESS;
459 }
460 
GetServiceInfoProfileByUniqueKey(const ServiceInfoUniqueKey & key,ServiceInfoProfile & serviceInfoProfile)461 int32_t DistributedDeviceProfileProxy::GetServiceInfoProfileByUniqueKey(const ServiceInfoUniqueKey& key,
462     ServiceInfoProfile& serviceInfoProfile)
463 {
464     sptr<IRemoteObject> remote = nullptr;
465     GET_REMOTE_OBJECT(remote);
466     MessageParcel data;
467     WRITE_INTERFACE_TOKEN(data);
468     if (!key.Marshalling(data)) {
469         HILOGE("dp ipc write parcel fail");
470         return DP_WRITE_PARCEL_FAIL;
471     }
472     MessageParcel reply;
473     SEND_REQUEST(remote, static_cast<uint32_t>(DPInterfaceCode::GET_SERVICE_INFO_PROFILE_BY_UNIQUE_KEY), data, reply);
474     if (!serviceInfoProfile.UnMarshalling(reply)) {
475         HILOGE("dp ipc read parcel fail");
476         return DP_READ_PARCEL_FAIL;
477     }
478     return DP_SUCCESS;
479 }
480 
GetServiceInfoProfileListByTokenId(const ServiceInfoUniqueKey & key,std::vector<ServiceInfoProfile> & serviceInfoProfiles)481 int32_t DistributedDeviceProfileProxy::GetServiceInfoProfileListByTokenId(const ServiceInfoUniqueKey& key,
482     std::vector<ServiceInfoProfile>& serviceInfoProfiles)
483 {
484     sptr<IRemoteObject> remote = nullptr;
485     GET_REMOTE_OBJECT(remote);
486     MessageParcel data;
487     WRITE_INTERFACE_TOKEN(data);
488     if (!key.Marshalling(data)) {
489         HILOGE("dp ipc write parcel fail");
490         return DP_WRITE_PARCEL_FAIL;
491     }
492     MessageParcel reply;
493     SEND_REQUEST(remote, static_cast<uint32_t>(DPInterfaceCode::GET_SERVICE_INFO_PROFILE_LIST_BY_TOKEN_ID),
494         data, reply);
495     if (!IpcUtils::UnMarshalling(reply, serviceInfoProfiles)) {
496         HILOGE("dp ipc read parcel fail");
497         return DP_READ_PARCEL_FAIL;
498     }
499     return DP_SUCCESS;
500 }
501 
GetAllServiceInfoProfileList(std::vector<ServiceInfoProfile> & serviceInfoProfiles)502 int32_t DistributedDeviceProfileProxy::GetAllServiceInfoProfileList(
503     std::vector<ServiceInfoProfile>& serviceInfoProfiles)
504 {
505     sptr<IRemoteObject> remote = nullptr;
506     GET_REMOTE_OBJECT(remote);
507     MessageParcel data;
508     WRITE_INTERFACE_TOKEN(data);
509     MessageParcel reply;
510     SEND_REQUEST(remote, static_cast<uint32_t>(DPInterfaceCode::GET_ALL_SERVICE_INFO_PROFILE_LIST),
511         data, reply);
512     if (!IpcUtils::UnMarshalling(reply, serviceInfoProfiles)) {
513         HILOGE("dp ipc read parcel fail");
514         return DP_READ_PARCEL_FAIL;
515     }
516     return DP_SUCCESS;
517 }
518 
GetServiceInfoProfileListByBundleName(const ServiceInfoUniqueKey & key,std::vector<ServiceInfoProfile> & serviceInfoProfiles)519 int32_t DistributedDeviceProfileProxy::GetServiceInfoProfileListByBundleName(const ServiceInfoUniqueKey& key,
520     std::vector<ServiceInfoProfile>& serviceInfoProfiles)
521 {
522     sptr<IRemoteObject> remote = nullptr;
523     GET_REMOTE_OBJECT(remote);
524     MessageParcel data;
525     WRITE_INTERFACE_TOKEN(data);
526     if (!key.Marshalling(data)) {
527         HILOGE("dp ipc write parcel fail");
528         return DP_WRITE_PARCEL_FAIL;
529     }
530     MessageParcel reply;
531     SEND_REQUEST(remote, static_cast<uint32_t>(DPInterfaceCode::GET_SERVICE_INFO_PROFILE_LIST_BY_BUNDLE_NAME),
532         data, reply);
533     if (!IpcUtils::UnMarshalling(reply, serviceInfoProfiles)) {
534         HILOGE("dp ipc read parcel fail");
535         return DP_READ_PARCEL_FAIL;
536     }
537     return DP_SUCCESS;
538 }
539 
GetCharacteristicProfile(const std::string & deviceId,const std::string & serviceName,const std::string & characteristicId,CharacteristicProfile & charProfile)540 int32_t DistributedDeviceProfileProxy::GetCharacteristicProfile(const std::string& deviceId,
541     const std::string& serviceName, const std::string& characteristicId, CharacteristicProfile& charProfile)
542 {
543     sptr<IRemoteObject> remote = nullptr;
544     GET_REMOTE_OBJECT(remote);
545     MessageParcel data;
546     WRITE_INTERFACE_TOKEN(data);
547     WRITE_HELPER(data, String, deviceId);
548     WRITE_HELPER(data, String, serviceName);
549     WRITE_HELPER(data, String, characteristicId);
550     WRITE_HELPER(data, Bool, charProfile.IsMultiUser());
551     WRITE_HELPER(data, Int32, charProfile.GetUserId());
552     MessageParcel reply;
553     SEND_REQUEST(remote, static_cast<uint32_t>(DPInterfaceCode::GET_CHAR_PROFILE), data, reply);
554     if (!charProfile.UnMarshalling(reply)) {
555         HILOGE("dp ipc read parcel fail");
556         return DP_READ_PARCEL_FAIL;
557     }
558     return DP_SUCCESS;
559 }
560 
DeleteServiceProfile(const std::string & deviceId,const std::string & serviceName,bool isMultiUser,int32_t userId)561 int32_t DistributedDeviceProfileProxy::DeleteServiceProfile(const std::string& deviceId,
562     const std::string& serviceName, bool isMultiUser, int32_t userId)
563 {
564     sptr<IRemoteObject> remote = nullptr;
565     GET_REMOTE_OBJECT(remote);
566     MessageParcel data;
567     WRITE_INTERFACE_TOKEN(data);
568     WRITE_HELPER(data, String, deviceId);
569     WRITE_HELPER(data, String, serviceName);
570     WRITE_HELPER(data, Bool, isMultiUser);
571     WRITE_HELPER(data, Int32, userId);
572     MessageParcel reply;
573     SEND_REQUEST(remote, static_cast<uint32_t>(DPInterfaceCode::DEL_SERVICE_PROFILE), data, reply);
574     return DP_SUCCESS;
575 }
576 
DeleteCharacteristicProfile(const std::string & deviceId,const std::string & serviceName,const std::string & characteristicId,bool isMultiUser,int32_t userId)577 int32_t DistributedDeviceProfileProxy::DeleteCharacteristicProfile(const std::string& deviceId,
578     const std::string& serviceName, const std::string& characteristicId, bool isMultiUser, int32_t userId)
579 {
580     sptr<IRemoteObject> remote = nullptr;
581     GET_REMOTE_OBJECT(remote);
582     MessageParcel data;
583     WRITE_INTERFACE_TOKEN(data);
584     WRITE_HELPER(data, String, deviceId);
585     WRITE_HELPER(data, String, serviceName);
586     WRITE_HELPER(data, String, characteristicId);
587     WRITE_HELPER(data, Bool, isMultiUser);
588     WRITE_HELPER(data, Int32, userId);
589     MessageParcel reply;
590     SEND_REQUEST(remote, static_cast<uint32_t>(DPInterfaceCode::DEL_CHAR_PROFILE), data, reply);
591     return DP_SUCCESS;
592 }
593 
SubscribeDeviceProfile(const SubscribeInfo & subscribeInfo)594 int32_t DistributedDeviceProfileProxy::SubscribeDeviceProfile(const SubscribeInfo& subscribeInfo)
595 {
596     sptr<IRemoteObject> remote = nullptr;
597     GET_REMOTE_OBJECT(remote);
598     MessageParcel data;
599     WRITE_INTERFACE_TOKEN(data);
600     if (!subscribeInfo.Marshalling(data)) {
601         HILOGE("dp ipc write parcel fail");
602         return DP_WRITE_PARCEL_FAIL;
603     }
604     MessageParcel reply;
605     SEND_REQUEST(remote, static_cast<uint32_t>(DPInterfaceCode::SUBSCRIBE_DEVICE_PROFILE), data, reply);
606     return DP_SUCCESS;
607 }
608 
UnSubscribeDeviceProfile(const SubscribeInfo & subscribeInfo)609 int32_t DistributedDeviceProfileProxy::UnSubscribeDeviceProfile(const SubscribeInfo& subscribeInfo)
610 {
611     sptr<IRemoteObject> remote = nullptr;
612     GET_REMOTE_OBJECT(remote);
613     MessageParcel data;
614     WRITE_INTERFACE_TOKEN(data);
615     if (!subscribeInfo.Marshalling(data)) {
616         HILOGE("dp ipc write parcel fail");
617         return DP_WRITE_PARCEL_FAIL;
618     }
619     MessageParcel reply;
620     SEND_REQUEST(remote, static_cast<uint32_t>(DPInterfaceCode::UNSUBSCRIBE_DEVICE_PROFILE), data, reply);
621     return DP_SUCCESS;
622 }
623 
SyncDeviceProfile(const DpSyncOptions & syncOptions,const sptr<IRemoteObject> syncCompletedCallback)624 int32_t DistributedDeviceProfileProxy::SyncDeviceProfile(const DpSyncOptions& syncOptions,
625     const sptr<IRemoteObject> syncCompletedCallback)
626 {
627     sptr<IRemoteObject> remote = nullptr;
628     GET_REMOTE_OBJECT(remote);
629     MessageParcel data;
630     WRITE_INTERFACE_TOKEN(data);
631     if (!syncOptions.Marshalling(data)) {
632         HILOGE("dp ipc write parcel fail");
633         return DP_WRITE_PARCEL_FAIL;
634     }
635     WRITE_HELPER(data, RemoteObject, syncCompletedCallback);
636     MessageParcel reply;
637     SEND_REQUEST(remote, static_cast<uint32_t>(DPInterfaceCode::SYNC_DEVICE_PROFILE_NEW), data, reply);
638     return DP_SUCCESS;
639 }
640 
SendSubscribeInfos(std::map<std::string,SubscribeInfo> listenerMap)641 int32_t DistributedDeviceProfileProxy::SendSubscribeInfos(std::map<std::string, SubscribeInfo> listenerMap)
642 {
643     sptr<IRemoteObject> remote = nullptr;
644     GET_REMOTE_OBJECT(remote);
645     MessageParcel data;
646     WRITE_INTERFACE_TOKEN(data);
647     if (!IpcUtils::Marshalling(data, listenerMap)) {
648         HILOGE("dp ipc write parcel fail");
649         return DP_WRITE_PARCEL_FAIL;
650     }
651     MessageParcel reply;
652     SEND_REQUEST(remote, static_cast<uint32_t>(DPInterfaceCode::SEND_SUBSCRIBE_INFOS), data, reply);
653     return DP_SUCCESS;
654 }
655 
SubscribeDeviceProfileInited(int32_t saId,sptr<IRemoteObject> dpInitedCallback)656 int32_t DistributedDeviceProfileProxy::SubscribeDeviceProfileInited(int32_t saId, sptr<IRemoteObject> dpInitedCallback)
657 {
658     sptr<IRemoteObject> remote = nullptr;
659     GET_REMOTE_OBJECT(remote);
660     MessageParcel data;
661     WRITE_INTERFACE_TOKEN(data);
662     WRITE_HELPER(data, Int32, saId);
663     WRITE_HELPER(data, RemoteObject, dpInitedCallback);
664     MessageParcel reply;
665     SEND_REQUEST(remote, static_cast<uint32_t>(DPInterfaceCode::SUBSCRIBE_DEVICE_PROFILE_INITED), data, reply);
666     return DP_SUCCESS;
667 }
668 
UnSubscribeDeviceProfileInited(int32_t saId)669 int32_t OHOS::DistributedDeviceProfile::DistributedDeviceProfileProxy::UnSubscribeDeviceProfileInited(int32_t saId)
670 {
671     sptr<IRemoteObject> remote = nullptr;
672     GET_REMOTE_OBJECT(remote);
673     MessageParcel data;
674     WRITE_INTERFACE_TOKEN(data);
675     WRITE_HELPER(data, Int32, saId);
676     MessageParcel reply;
677     SEND_REQUEST(remote, static_cast<uint32_t>(DPInterfaceCode::UNSUBSCRIBE_DEVICE_PROFILE_INITED), data, reply);
678     return DP_SUCCESS;
679 }
680 
SubscribePinCodeInvalid(const std::string & bundleName,int32_t pinExchangeType,sptr<IRemoteObject> pinCodeCallback)681 int32_t OHOS::DistributedDeviceProfile::DistributedDeviceProfileProxy::SubscribePinCodeInvalid(
682     const std::string& bundleName, int32_t pinExchangeType, sptr<IRemoteObject> pinCodeCallback)
683 {
684     sptr<IRemoteObject> remote = nullptr;
685     GET_REMOTE_OBJECT(remote);
686     MessageParcel data;
687     WRITE_INTERFACE_TOKEN(data);
688     WRITE_HELPER(data, String, bundleName);
689     WRITE_HELPER(data, Int32, pinExchangeType);
690     WRITE_HELPER(data, RemoteObject, pinCodeCallback);
691     MessageParcel reply;
692     SEND_REQUEST(remote, static_cast<uint32_t>(DPInterfaceCode::SUBSCRIBE_PINCODE_INVALID), data, reply);
693     return DP_SUCCESS;
694 }
695 
UnSubscribePinCodeInvalid(const std::string & bundleName,int32_t pinExchangeType)696 int32_t OHOS::DistributedDeviceProfile::DistributedDeviceProfileProxy::UnSubscribePinCodeInvalid(
697     const std::string& bundleName, int32_t pinExchangeType)
698 {
699     sptr<IRemoteObject> remote = nullptr;
700     GET_REMOTE_OBJECT(remote);
701     MessageParcel data;
702     WRITE_INTERFACE_TOKEN(data);
703     WRITE_HELPER(data, String, bundleName);
704     WRITE_HELPER(data, Int32, pinExchangeType);
705     MessageParcel reply;
706     SEND_REQUEST(remote, static_cast<uint32_t>(DPInterfaceCode::UNSUBSCRIBE_PINCODE_INVALID), data, reply);
707     return DP_SUCCESS;
708 }
709 
PutAllTrustedDevices(const std::vector<TrustedDeviceInfo> deviceInfos)710 int32_t OHOS::DistributedDeviceProfile::DistributedDeviceProfileProxy::PutAllTrustedDevices(
711     const std::vector<TrustedDeviceInfo> deviceInfos)
712 {
713     sptr<IRemoteObject> remote = nullptr;
714     GET_REMOTE_OBJECT(remote);
715     MessageParcel data;
716     WRITE_INTERFACE_TOKEN(data);
717     if (!IpcUtils::Marshalling(data, deviceInfos)) {
718         HILOGE("dp ipc write parcel fail");
719         return DP_WRITE_PARCEL_FAIL;
720     }
721     MessageParcel reply;
722     SEND_REQUEST(remote, static_cast<uint32_t>(DPInterfaceCode::PUT_ALL_TRUSTED_DEVICES), data, reply);
723     return DP_SUCCESS;
724 }
725 
PutLocalServiceInfo(const LocalServiceInfo & localServiceInfo)726 int32_t DistributedDeviceProfileProxy::PutLocalServiceInfo(const LocalServiceInfo& localServiceInfo)
727 {
728     sptr<IRemoteObject> remote = nullptr;
729     GET_REMOTE_OBJECT(remote);
730     MessageParcel data;
731     WRITE_INTERFACE_TOKEN(data);
732     if (!localServiceInfo.Marshalling(data)) {
733         HILOGE("dp ipc write parcel fail");
734         return DP_WRITE_PARCEL_FAIL;
735     }
736     MessageParcel reply;
737     SEND_REQUEST(remote, static_cast<uint32_t>(DPInterfaceCode::PUT_LOCAL_SERVICE_INFO), data, reply);
738     return DP_SUCCESS;
739 }
740 
UpdateLocalServiceInfo(const LocalServiceInfo & localServiceInfo)741 int32_t DistributedDeviceProfileProxy::UpdateLocalServiceInfo(const LocalServiceInfo& localServiceInfo)
742 {
743     sptr<IRemoteObject> remote = nullptr;
744     GET_REMOTE_OBJECT(remote);
745     MessageParcel data;
746     WRITE_INTERFACE_TOKEN(data);
747     if (!localServiceInfo.Marshalling(data)) {
748         HILOGE("dp ipc write parcel fail");
749         return DP_WRITE_PARCEL_FAIL;
750     }
751     MessageParcel reply;
752     SEND_REQUEST(remote, static_cast<uint32_t>(DPInterfaceCode::UPDATE_LOCAL_SERVICE_INFO), data, reply);
753     return DP_SUCCESS;
754 }
755 
GetLocalServiceInfoByBundleAndPinType(const std::string & bundleName,int32_t pinExchangeType,LocalServiceInfo & localServiceInfo)756 int32_t DistributedDeviceProfileProxy::GetLocalServiceInfoByBundleAndPinType(const std::string& bundleName,
757     int32_t pinExchangeType, LocalServiceInfo& localServiceInfo)
758 {
759     sptr<IRemoteObject> remote = nullptr;
760     GET_REMOTE_OBJECT(remote);
761     MessageParcel data;
762     WRITE_INTERFACE_TOKEN(data);
763     WRITE_HELPER(data, String, bundleName);
764     WRITE_HELPER(data, Int32, pinExchangeType);
765     MessageParcel reply;
766     SEND_REQUEST(remote,
767         static_cast<uint32_t>(DPInterfaceCode::GET_LOCAL_SERVICE_INFO_BY_BINDLE_AND_PINTYPE), data, reply);
768     if (!localServiceInfo.UnMarshalling(reply)) {
769         HILOGE("dp ipc read parcel fail");
770         return DP_READ_PARCEL_FAIL;
771     }
772     return DP_SUCCESS;
773 }
774 
DeleteLocalServiceInfo(const std::string & bundleName,int32_t pinExchangeType)775 int32_t DistributedDeviceProfileProxy::DeleteLocalServiceInfo(const std::string& bundleName, int32_t pinExchangeType)
776 {
777     sptr<IRemoteObject> remote = nullptr;
778     GET_REMOTE_OBJECT(remote);
779     MessageParcel data;
780     WRITE_INTERFACE_TOKEN(data);
781     WRITE_HELPER(data, String, bundleName);
782     WRITE_HELPER(data, Int32, pinExchangeType);
783     MessageParcel reply;
784     SEND_REQUEST(remote,
785         static_cast<uint32_t>(DPInterfaceCode::DELETE_LOCAL_SERVICE_INFO), data, reply);
786     return DP_SUCCESS;
787 }
788 
RegisterBusinessCallback(const std::string & saId,const std::string & businessKey,sptr<IRemoteObject> businessCallback)789 int32_t DistributedDeviceProfileProxy::RegisterBusinessCallback(const std::string& saId,
790     const std::string& businessKey, sptr<IRemoteObject> businessCallback)
791 {
792     sptr<IRemoteObject> remote = nullptr;
793     GET_REMOTE_OBJECT(remote);
794     MessageParcel data;
795     WRITE_INTERFACE_TOKEN(data);
796     WRITE_HELPER(data, String, saId);
797     WRITE_HELPER(data, String, businessKey);
798     WRITE_HELPER(data, RemoteObject, businessCallback);
799     MessageParcel reply;
800     SEND_REQUEST(remote, static_cast<uint32_t>(DPInterfaceCode::REGISTER_BUSINESS_CALLBACK), data, reply);
801     return DP_SUCCESS;
802 }
803 
UnRegisterBusinessCallback(const std::string & saId,const std::string & businessKey)804 int32_t DistributedDeviceProfileProxy::UnRegisterBusinessCallback(const std::string& saId,
805     const std::string& businessKey)
806 {
807     sptr<IRemoteObject> remote = nullptr;
808     GET_REMOTE_OBJECT(remote);
809     MessageParcel data;
810     WRITE_INTERFACE_TOKEN(data);
811     WRITE_HELPER(data, String, saId);
812     WRITE_HELPER(data, String, businessKey);
813     MessageParcel reply;
814     SEND_REQUEST(remote, static_cast<uint32_t>(DPInterfaceCode::UNREGISTER_BUSINESS_CALLBACK), data, reply);
815     return DP_SUCCESS;
816 }
817 
PutBusinessEvent(const BusinessEvent & event)818 int32_t DistributedDeviceProfileProxy::PutBusinessEvent(const BusinessEvent& event)
819 {
820     sptr<IRemoteObject> remote = nullptr;
821     GET_REMOTE_OBJECT(remote);
822     MessageParcel data;
823     WRITE_INTERFACE_TOKEN(data);
824     if (!event.Marshalling(data)) {
825         HILOGE("dp ipc write parcel fail");
826         return DP_WRITE_PARCEL_FAIL;
827     }
828     MessageParcel reply;
829     SEND_REQUEST(remote, static_cast<uint32_t>(DPInterfaceCode::PUT_BUSINESS_EVENT), data, reply);
830     return DP_SUCCESS;
831 }
832 
GetBusinessEvent(BusinessEvent & event)833 int32_t DistributedDeviceProfileProxy::GetBusinessEvent(BusinessEvent& event)
834 {
835     sptr<IRemoteObject> remote = nullptr;
836     GET_REMOTE_OBJECT(remote);
837     MessageParcel data;
838     WRITE_INTERFACE_TOKEN(data);
839     if (!event.Marshalling(data)) {
840         HILOGE("dp ipc write parcel fail");
841         return DP_WRITE_PARCEL_FAIL;
842     }
843     MessageParcel reply;
844     SEND_REQUEST(remote, static_cast<uint32_t>(DPInterfaceCode::GET_BUSINESS_EVENT), data, reply);
845     if (!event.UnMarshalling(reply)) {
846         HILOGE("dp ipc read parcel fail");
847         return DP_READ_PARCEL_FAIL;
848     }
849     return DP_SUCCESS;
850 }
851 } // namespace DeviceProfile
852 } // namespace OHOS
853