• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021-2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "bluetooth_map_mce_proxy.h"
17 #include "bluetooth_log.h"
18 #include "bluetooth_errorcode.h"
19 
20 namespace OHOS {
21 namespace Bluetooth {
RegisterObserver(const sptr<IBluetoothMapMceObserver> & observer)22 void BluetoothMapMceProxy::RegisterObserver(const sptr<IBluetoothMapMceObserver> &observer)
23 {
24     HILOGI("BluetoothMapMceProxy::RegisterObserver Triggered!");
25     MessageParcel data;
26     if (!data.WriteInterfaceToken(BluetoothMapMceProxy::GetDescriptor())) {
27         HILOGE("BluetoothMapMceProxy::RegisterObserver WriteInterfaceToken error");
28         return;
29     }
30     if (!data.WriteRemoteObject(observer->AsObject())) {
31         HILOGE("BluetoothPbapPceProxy::RegisterObserver error");
32         return;
33     }
34     MessageParcel reply;
35     MessageOption option {
36         MessageOption::TF_ASYNC
37     };
38     int error = Remote()->SendRequest(
39         BluetoothMapMceInterfaceCode::MCE_REGISTER_OBSERVER, data, reply, option);
40     if (error != NO_ERROR) {
41         HILOGE("BluetoothMapMceProxy::RegisterObserver done fail, error: %{public}d", error);
42         return;
43     }
44 }
45 
DeregisterObserver(const sptr<IBluetoothMapMceObserver> & observer)46 void BluetoothMapMceProxy::DeregisterObserver(const sptr<IBluetoothMapMceObserver> &observer)
47 {
48     HILOGI("BluetoothMapMceProxy::DeregisterObserver Triggered!");
49     MessageParcel data;
50     if (!data.WriteInterfaceToken(BluetoothMapMceProxy::GetDescriptor())) {
51         HILOGE("BluetoothMapMceProxy::DeregisterObserver WriteInterfaceToken error");
52         return;
53     }
54     if (!data.WriteRemoteObject(observer->AsObject())) {
55         HILOGE("BluetoothPbapPceProxy::DeregisterObserver error");
56         return;
57     }
58     MessageParcel reply;
59     MessageOption option {
60         MessageOption::TF_ASYNC
61     };
62     int error = Remote()->SendRequest(
63         BluetoothMapMceInterfaceCode::MCE_DE_REGISTER_OBSERVER, data, reply, option);
64     if (error != NO_ERROR) {
65         HILOGE("BluetoothMapMceProxy::DeregisterObserver done fail, error: %{public}d", error);
66         return;
67     }
68 }
69 
Connect(const BluetoothRawAddress & device)70 int BluetoothMapMceProxy::Connect(const BluetoothRawAddress &device)
71 {
72     HILOGI("BluetoothMapMceProxy::Connect Triggered!");
73     MessageParcel data;
74     if (!data.WriteInterfaceToken(BluetoothMapMceProxy::GetDescriptor())) {
75         HILOGE("BluetoothMapMceProxy::Connect WriteInterfaceToken error");
76         return ERROR;
77     }
78     if (!data.WriteParcelable(&device)) {
79         HILOGE("BluetoothMapMceProxy::Connect error");
80         return ERROR;
81     }
82     MessageParcel reply;
83     MessageOption option {
84         MessageOption::TF_ASYNC
85     };
86     int error = Remote()->SendRequest(
87         BluetoothMapMceInterfaceCode::MCE_CONNECT, data, reply, option);
88     if (error != NO_ERROR) {
89         HILOGE("BluetoothMapMceProxy::Connect done fail, error: %{public}d", error);
90         return ERROR;
91     }
92     return reply.ReadInt32();
93 }
94 
Disconnect(const BluetoothRawAddress & device)95 int BluetoothMapMceProxy::Disconnect(const BluetoothRawAddress &device)
96 {
97     HILOGI("BluetoothMapMceProxy::Disconnect Triggered!");
98     MessageParcel data;
99     if (!data.WriteInterfaceToken(BluetoothMapMceProxy::GetDescriptor())) {
100         HILOGE("BluetoothMapMceProxy::Disconnect WriteInterfaceToken error");
101         return ERROR;
102     }
103     if (!data.WriteParcelable(&device)) {
104         HILOGE("BluetoothMapMceProxy::Disconnect error");
105         return ERROR;
106     }
107     MessageParcel reply;
108     MessageOption option {
109         MessageOption::TF_ASYNC
110     };
111     int error = Remote()->SendRequest(
112         BluetoothMapMceInterfaceCode::MCE_DISCONNECT, data, reply, option);
113     if (error != NO_ERROR) {
114         HILOGE("BluetoothMapMceProxy::Disconnect done fail, error: %{public}d", error);
115         return ERROR;
116     }
117     return reply.ReadInt32();
118 }
119 
IsConnected(const BluetoothRawAddress & device)120 int BluetoothMapMceProxy::IsConnected(const BluetoothRawAddress &device)
121 {
122     HILOGI("BluetoothMapMceProxy::IsConnected Triggered!");
123     MessageParcel data;
124     if (!data.WriteInterfaceToken(BluetoothMapMceProxy::GetDescriptor())) {
125         HILOGE("BluetoothMapMceProxy::IsConnected WriteInterfaceToken error");
126         return ERROR;
127     }
128     if (!data.WriteParcelable(&device)) {
129         HILOGE("BluetoothMapMceProxy::IsConnected error");
130         return ERROR;
131     }
132     MessageParcel reply;
133     MessageOption option {
134         MessageOption::TF_ASYNC
135     };
136     int error = Remote()->SendRequest(
137         BluetoothMapMceInterfaceCode::MCE_ISCONNECTED, data, reply, option);
138     if (error != NO_ERROR) {
139         HILOGE("BluetoothMapMceProxy::IsConnected done fail, error: %{public}d", error);
140         return ERROR;
141     }
142     return reply.ReadInt32();
143 }
144 
GetConnectDevices(std::vector<BluetoothRawAddress> & devices)145 void BluetoothMapMceProxy::GetConnectDevices(std::vector<BluetoothRawAddress> &devices)
146 {
147     HILOGI("BluetoothMapMceProxy::GetConnectDevices Triggered!");
148     MessageParcel data;
149     if (!data.WriteInterfaceToken(BluetoothMapMceProxy::GetDescriptor())) {
150         HILOGE("BluetoothMapMceProxy::GetConnectDevices WriteInterfaceToken error");
151         return;
152     }
153     MessageParcel reply;
154     MessageOption option {
155         MessageOption::TF_ASYNC
156     };
157     int error = Remote()->SendRequest(
158         BluetoothMapMceInterfaceCode::MCE_GET_CONNECT_DEVICES, data, reply, option);
159     if (error != NO_ERROR) {
160         HILOGE("BluetoothMapMceProxy::GetConnectDevices done fail, error: %{public}d", error);
161         return;
162     }
163     int devNum = reply.ReadInt32();
164     for (int i = devNum; i > 0; i--) {
165         std::shared_ptr<BluetoothRawAddress> dev(reply.ReadParcelable<BluetoothRawAddress>());
166         if (!dev) {
167             return;
168         }
169         devices.push_back(*dev);
170     }
171 }
172 
GetDevicesByStates(const std::vector<int> & statusList,std::vector<BluetoothRawAddress> & devices)173 void BluetoothMapMceProxy::GetDevicesByStates(
174     const std::vector<int> &statusList, std::vector<BluetoothRawAddress> &devices)
175 {
176     HILOGI("BluetoothMapMceProxy::GetDevicesByStates Triggered!");
177     MessageParcel data;
178     if (!data.WriteInterfaceToken(BluetoothMapMceProxy::GetDescriptor())) {
179         HILOGE("BluetoothMapMceProxy::GetDevicesByStates WriteInterfaceToken error");
180         return;
181     }
182     if (!data.WriteInt32Vector(statusList)) {
183         HILOGE("BluetoothPbapPceProxy::GetDevicesByStates transport error");
184         return;
185     }
186     MessageParcel reply;
187     MessageOption option {
188         MessageOption::TF_ASYNC
189     };
190     int error = Remote()->SendRequest(
191         BluetoothMapMceInterfaceCode::MCE_GET_DEVICES_BY_STATES, data, reply, option);
192     if (error != NO_ERROR) {
193         HILOGE("BluetoothMapMceProxy::GetDevicesByStates done fail, error: %{public}d", error);
194         return;
195     }
196     int devNum = reply.ReadInt32();
197     for (int i = devNum; i > 0; i--) {
198         std::shared_ptr<BluetoothRawAddress> dev(reply.ReadParcelable<BluetoothRawAddress>());
199         if (!dev) {
200             return;
201         }
202         devices.push_back(*dev);
203     }
204 }
205 
GetConnectionState(const BluetoothRawAddress & device)206 int BluetoothMapMceProxy::GetConnectionState(const BluetoothRawAddress &device)
207 {
208     HILOGI("BluetoothMapMceProxy::GetConnectionState Triggered!");
209     MessageParcel data;
210     if (!data.WriteInterfaceToken(BluetoothMapMceProxy::GetDescriptor())) {
211         HILOGE("BluetoothMapMceProxy::GetConnectionState WriteInterfaceToken error");
212         return ERROR;
213     }
214     if (!data.WriteParcelable(&device)) {
215         HILOGE("BluetoothMapMceProxy::IsConnected error");
216         return ERROR;
217     }
218     MessageParcel reply;
219     MessageOption option {
220         MessageOption::TF_ASYNC
221     };
222     int error = Remote()->SendRequest(
223         BluetoothMapMceInterfaceCode::MCE_GET_CONNECTION_STATE, data, reply, option);
224     if (error != NO_ERROR) {
225         HILOGE("BluetoothMapMceProxy::GetConnectionState done fail, error: %{public}d", error);
226         return ERROR;
227     }
228     return reply.ReadInt32();
229 }
230 
SetConnectionStrategy(const BluetoothRawAddress & device,int strategy)231 int BluetoothMapMceProxy::SetConnectionStrategy(const BluetoothRawAddress &device, int strategy)
232 {
233     HILOGI("BluetoothMapMceProxy::SetConnectionStrategy Triggered!");
234     MessageParcel data;
235     if (!data.WriteInterfaceToken(BluetoothMapMceProxy::GetDescriptor())) {
236         HILOGE("BluetoothMapMceProxy::SetConnectionStrategy WriteInterfaceToken error");
237         return ERROR;
238     }
239     if (!data.WriteParcelable(&device)) {
240         HILOGE("BluetoothMapMceProxy::SetConnectionStrategy error");
241         return ERROR;
242     }
243     if (!data.WriteInt32(strategy)) {
244         HILOGE("BluetoothPbapPceProxy::SetConnectionStrategy transport error");
245         return ERROR;
246     }
247     MessageParcel reply;
248     MessageOption option {
249         MessageOption::TF_ASYNC
250     };
251     int error = Remote()->SendRequest(
252         BluetoothMapMceInterfaceCode::MCE_SET_CONNECTION_STRATEGY, data, reply, option);
253     if (error != NO_ERROR) {
254         HILOGE("BluetoothMapMceProxy::GetDevicesByStates done fail, error: %{public}d", error);
255         return ERROR;
256     }
257     return reply.ReadInt32();
258 }
259 
GetConnectionStrategy(const BluetoothRawAddress & device)260 int BluetoothMapMceProxy::GetConnectionStrategy(const BluetoothRawAddress &device)
261 {
262     HILOGI("BluetoothMapMceProxy::GetConnectionStrategy Triggered!");
263     MessageParcel data;
264     if (!data.WriteInterfaceToken(BluetoothMapMceProxy::GetDescriptor())) {
265         HILOGE("BluetoothMapMceProxy::GetConnectionStrategy WriteInterfaceToken error");
266         return ERROR;
267     }
268     if (!data.WriteParcelable(&device)) {
269         HILOGE("BluetoothMapMceProxy::GetConnectionStrategy error");
270         return ERROR;
271     }
272     MessageParcel reply;
273     MessageOption option {
274         MessageOption::TF_ASYNC
275     };
276     int error = Remote()->SendRequest(
277         BluetoothMapMceInterfaceCode::MCE_GET_CONNECTION_STRATEGY, data, reply, option);
278     if (error != NO_ERROR) {
279         HILOGE("BluetoothMapMceProxy::GetConnectionStrategy done fail, error: %{public}d", error);
280         return ERROR;
281     }
282     return reply.ReadInt32();
283 }
284 
GetUnreadMessages(const BluetoothRawAddress & device,int32_t msgType,int32_t max)285 int BluetoothMapMceProxy::GetUnreadMessages(const BluetoothRawAddress &device, int32_t msgType, int32_t max)
286 {
287     HILOGI("BluetoothMapMceProxy::GetUnreadMessages Triggered!");
288     MessageParcel data;
289     if (!data.WriteInterfaceToken(BluetoothMapMceProxy::GetDescriptor())) {
290         HILOGE("BluetoothMapMceProxy::GetUnreadMessages WriteInterfaceToken error");
291         return ERROR;
292     }
293     if (!data.WriteParcelable(&device)) {
294         HILOGE("BluetoothMapMceProxy::GetUnreadMessages error");
295         return ERROR;
296     }
297     if (!data.WriteInt32(msgType)) {
298         HILOGE("BluetoothPbapPceProxy::GetUnreadMessages transport error");
299         return ERROR;
300     }
301     if (!data.WriteInt32(max)) {
302         HILOGE("BluetoothPbapPceProxy::GetUnreadMessages transport error");
303         return ERROR;
304     }
305     MessageParcel reply;
306     MessageOption option {
307         MessageOption::TF_ASYNC
308     };
309     int error = Remote()->SendRequest(
310         BluetoothMapMceInterfaceCode::MCE_GET_UNREAD_MESSAGES, data, reply, option);
311     if (error != NO_ERROR) {
312         HILOGE("BluetoothMapMceProxy::GetUnreadMessages done fail, error: %{public}d", error);
313         return ERROR;
314     }
315     return reply.ReadInt32();
316 }
317 
GetSupportedFeatures(const BluetoothRawAddress & device)318 int BluetoothMapMceProxy::GetSupportedFeatures(const BluetoothRawAddress &device)
319 {
320     HILOGI("BluetoothMapMceProxy::GetSupportedFeatures Triggered!");
321     MessageParcel data;
322     if (!data.WriteInterfaceToken(BluetoothMapMceProxy::GetDescriptor())) {
323         HILOGE("BluetoothMapMceProxy::GetSupportedFeatures WriteInterfaceToken error");
324         return ERROR;
325     }
326     if (!data.WriteParcelable(&device)) {
327         HILOGE("BluetoothMapMceProxy::GetSupportedFeatures error");
328         return ERROR;
329     }
330     MessageParcel reply;
331     MessageOption option {
332         MessageOption::TF_ASYNC
333     };
334     int error = Remote()->SendRequest(
335         BluetoothMapMceInterfaceCode::MCE_GET_SUPPORTED_FEATURES, data, reply, option);
336     if (error != NO_ERROR) {
337         HILOGE("BluetoothMapMceProxy::GetSupportedFeatures done fail, error: %{public}d", error);
338         return ERROR;
339     }
340     return reply.ReadInt32();
341 }
342 
SendMessage(const BluetoothRawAddress & device,const BluetoothIProfileSendMessageParameters & msg)343 int BluetoothMapMceProxy::SendMessage(
344     const BluetoothRawAddress &device, const BluetoothIProfileSendMessageParameters &msg)
345 {
346     HILOGI("BluetoothMapMceProxy::SendMessage Triggered!");
347     MessageParcel data;
348     if (!data.WriteInterfaceToken(BluetoothMapMceProxy::GetDescriptor())) {
349         HILOGE("BluetoothMapMceProxy::SendMessage WriteInterfaceToken error");
350         return ERROR;
351     }
352     if (!data.WriteParcelable(&device)) {
353         HILOGE("BluetoothMapMceProxy::SendMessage error");
354         return ERROR;
355     }
356     if (!data.WriteParcelable(&msg)) {
357         HILOGE("BluetoothMapMceProxy::SendMessage error");
358         return ERROR;
359     }
360     MessageParcel reply;
361     MessageOption option {
362         MessageOption::TF_ASYNC
363     };
364     int error = Remote()->SendRequest(
365         BluetoothMapMceInterfaceCode::MCE_SEND_MESSAGE, data, reply, option);
366     if (error != NO_ERROR) {
367         HILOGE("BluetoothMapMceProxy::SendMessage done fail, error: %{public}d", error);
368         return ERROR;
369     }
370     return reply.ReadInt32();
371 }
372 
SetNotificationFilter(const BluetoothRawAddress & device,int32_t mask)373 int BluetoothMapMceProxy::SetNotificationFilter(const BluetoothRawAddress &device, int32_t mask)
374 {
375     HILOGI("BluetoothMapMceProxy::SetNotificationFilter Triggered!");
376     MessageParcel data;
377     if (!data.WriteInterfaceToken(BluetoothMapMceProxy::GetDescriptor())) {
378         HILOGE("BluetoothMapMceProxy::SetNotificationFilter WriteInterfaceToken error");
379         return ERROR;
380     }
381     if (!data.WriteParcelable(&device)) {
382         HILOGE("BluetoothMapMceProxy::SetNotificationFilter error");
383         return ERROR;
384     }
385     if (!data.WriteInt32(mask)) {
386         HILOGE("BluetoothMapMceProxy::SetNotificationFilter error");
387         return ERROR;
388     }
389     MessageParcel reply;
390     MessageOption option {
391         MessageOption::TF_ASYNC
392     };
393     int error = Remote()->SendRequest(
394         BluetoothMapMceInterfaceCode::MCE_SET_NOTIFICATION_FILTER, data, reply, option);
395     if (error != NO_ERROR) {
396         HILOGE("BluetoothMapMceProxy::SetNotificationFilter done fail, error: %{public}d", error);
397         return ERROR;
398     }
399     return reply.ReadInt32();
400 }
401 
GetMessagesListing(const BluetoothRawAddress & device,const BluetoothIProfileGetMessagesListingParameters & para)402 int BluetoothMapMceProxy::GetMessagesListing(
403     const BluetoothRawAddress &device, const BluetoothIProfileGetMessagesListingParameters &para)
404 {
405     HILOGI("BluetoothMapMceProxy::GetMessagesListing Triggered!");
406     MessageParcel data;
407     if (!data.WriteInterfaceToken(BluetoothMapMceProxy::GetDescriptor())) {
408         HILOGE("BluetoothMapMceProxy::GetMessagesListing WriteInterfaceToken error");
409         return ERROR;
410     }
411     if (!data.WriteParcelable(&device)) {
412         HILOGE("BluetoothMapMceProxy::GetMessagesListing error");
413         return ERROR;
414     }
415     if (!data.WriteParcelable(&para)) {
416         HILOGE("BluetoothMapMceProxy::GetMessagesListing error");
417         return ERROR;
418     }
419     MessageParcel reply;
420     MessageOption option {
421         MessageOption::TF_ASYNC
422     };
423     int error = Remote()->SendRequest(
424         BluetoothMapMceInterfaceCode::MCE_GET_MESSAGES_LISTING, data, reply, option);
425     if (error != NO_ERROR) {
426         HILOGE("BluetoothMapMceProxy::GetMessagesListing done fail, error: %{public}d", error);
427         return ERROR;
428     }
429     return reply.ReadInt32();
430 }
431 
GetMessage(const BluetoothRawAddress & device,int32_t msgType,const std::u16string & msgHandle,const BluetoothIProfileGetMessageParameters & para)432 int BluetoothMapMceProxy::GetMessage(const BluetoothRawAddress &device,
433     int32_t msgType, const std::u16string &msgHandle, const BluetoothIProfileGetMessageParameters &para)
434 {
435     HILOGI("BluetoothMapMceProxy::GetMessage Triggered!");
436     MessageParcel data;
437     if (!data.WriteInterfaceToken(BluetoothMapMceProxy::GetDescriptor())) {
438         HILOGE("BluetoothMapMceProxy::GetMessage WriteInterfaceToken error");
439         return ERROR;
440     }
441     if (!data.WriteParcelable(&device)) {
442         HILOGE("BluetoothMapMceProxy::GetMessage error");
443         return ERROR;
444     }
445     if (!data.WriteInt32(msgType)) {
446         HILOGE("BluetoothMapMceProxy::GetMessage error");
447         return ERROR;
448     }
449     if (!data.WriteString16(msgHandle)) {
450         HILOGE("BluetoothMapMceProxy::GetMessage error");
451         return ERROR;
452     }
453     if (!data.WriteParcelable(&para)) {
454         HILOGE("BluetoothMapMceProxy::GetMessage error");
455         return ERROR;
456     }
457     MessageParcel reply;
458     MessageOption option {
459         MessageOption::TF_ASYNC
460     };
461     int error = Remote()->SendRequest(
462         BluetoothMapMceInterfaceCode::MCE_GET_MESSAGE, data, reply, option);
463     if (error != NO_ERROR) {
464         HILOGE("BluetoothMapMceProxy::GetMessage done fail, error: %{public}d", error);
465         return ERROR;
466     }
467     return reply.ReadInt32();
468 }
469 
UpdateInbox(const BluetoothRawAddress & device,int32_t msgType)470 int BluetoothMapMceProxy::UpdateInbox(const BluetoothRawAddress &device, int32_t msgType)
471 {
472     HILOGI("BluetoothMapMceProxy::UpdateInbox Triggered!");
473     MessageParcel data;
474     if (!data.WriteInterfaceToken(BluetoothMapMceProxy::GetDescriptor())) {
475         HILOGE("BluetoothMapMceProxy::UpdateInbox WriteInterfaceToken error");
476         return ERROR;
477     }
478     if (!data.WriteParcelable(&device)) {
479         HILOGE("BluetoothMapMceProxy::UpdateInbox error");
480         return ERROR;
481     }
482     if (!data.WriteInt32(msgType)) {
483         HILOGE("BluetoothMapMceProxy::UpdateInbox error");
484         return ERROR;
485     }
486     MessageParcel reply;
487     MessageOption option {
488         MessageOption::TF_ASYNC
489     };
490     int error = Remote()->SendRequest(
491         BluetoothMapMceInterfaceCode::MCE_UPDATE_INBOX, data, reply, option);
492     if (error != NO_ERROR) {
493         HILOGE("BluetoothMapMceProxy::UpdateInbox done fail, error: %{public}d", error);
494         return ERROR;
495     }
496     return reply.ReadInt32();
497 }
498 
GetConversationListing(const BluetoothRawAddress & device,const BluetoothIProfileGetConversationListingParameters & para)499 int BluetoothMapMceProxy::GetConversationListing(
500     const BluetoothRawAddress &device, const BluetoothIProfileGetConversationListingParameters &para)
501 {
502     HILOGI("BluetoothMapMceProxy::GetConversationListing Triggered!");
503     MessageParcel data;
504     if (!data.WriteInterfaceToken(BluetoothMapMceProxy::GetDescriptor())) {
505         HILOGE("BluetoothMapMceProxy::GetConversationListing WriteInterfaceToken error");
506         return ERROR;
507     }
508     if (!data.WriteParcelable(&device)) {
509         HILOGE("BluetoothMapMceProxy::GetConversationListing error");
510         return ERROR;
511     }
512     if (!data.WriteParcelable(&para)) {
513         HILOGE("BluetoothMapMceProxy::GetConversationListing error");
514         return ERROR;
515     }
516     MessageParcel reply;
517     MessageOption option {
518         MessageOption::TF_ASYNC
519     };
520     int error = Remote()->SendRequest(
521         BluetoothMapMceInterfaceCode::MCE_GET_CONVERSATION_LISTING, data, reply, option);
522     if (error != NO_ERROR) {
523         HILOGE("BluetoothMapMceProxy::GetConversationListing done fail, error: %{public}d", error);
524         return ERROR;
525     }
526     return reply.ReadInt32();
527 }
528 
SetMessageStatus(const BluetoothRawAddress & device,int32_t msgType,const std::u16string & msgHandle,int32_t statusIndicator,int32_t statusValue,const std::string & extendedData)529 int BluetoothMapMceProxy::SetMessageStatus(const BluetoothRawAddress &device, int32_t msgType,
530     const std::u16string &msgHandle, int32_t statusIndicator, int32_t statusValue, const std::string &extendedData)
531 {
532     HILOGI("BluetoothMapMceProxy::SetMessageStatus Triggered!");
533     MessageParcel data;
534     if (!data.WriteInterfaceToken(BluetoothMapMceProxy::GetDescriptor())) {
535         HILOGE("BluetoothMapMceProxy::SetMessageStatus WriteInterfaceToken error");
536         return ERROR;
537     }
538     if (!data.WriteParcelable(&device)) {
539         HILOGE("BluetoothMapMceProxy::SetMessageStatus error");
540         return ERROR;
541     }
542     if (!data.WriteInt32(msgType)) {
543         HILOGE("BluetoothMapMceProxy::SetMessageStatus error");
544         return ERROR;
545     }
546     if (!data.WriteString16(msgHandle)) {
547         HILOGE("BluetoothMapMceProxy::SetMessageStatus error");
548         return ERROR;
549     }
550     if (!data.WriteInt32(statusIndicator)) {
551         HILOGE("BluetoothMapMceProxy::SetMessageStatus error");
552         return ERROR;
553     }
554     if (!data.WriteInt32(statusValue)) {
555         HILOGE("BluetoothMapMceProxy::SetMessageStatus error");
556         return ERROR;
557     }
558     if (!data.WriteString(extendedData)) {
559         HILOGE("BluetoothMapMceProxy::SetMessageStatus error");
560         return ERROR;
561     }
562     MessageParcel reply;
563     MessageOption option {
564         MessageOption::TF_ASYNC
565     };
566     int error = Remote()->SendRequest(
567         BluetoothMapMceInterfaceCode::MCE_SET_MESSAGE_STATUS, data, reply, option);
568     if (error != NO_ERROR) {
569         HILOGE("BluetoothMapMceProxy::SetMessageStatus done fail, error: %{public}d", error);
570         return ERROR;
571     }
572     return reply.ReadInt32();
573 }
574 
SetOwnerStatus(const BluetoothRawAddress & device,const BluetoothIProfileSetOwnerStatusParameters & para)575 int BluetoothMapMceProxy::SetOwnerStatus(
576     const BluetoothRawAddress &device, const BluetoothIProfileSetOwnerStatusParameters &para)
577 {
578     HILOGI("BluetoothMapMceProxy::SetOwnerStatus Triggered!");
579     MessageParcel data;
580     if (!data.WriteInterfaceToken(BluetoothMapMceProxy::GetDescriptor())) {
581         HILOGE("BluetoothMapMceProxy::SetOwnerStatus WriteInterfaceToken error");
582         return ERROR;
583     }
584     if (!data.WriteParcelable(&device)) {
585         HILOGE("BluetoothMapMceProxy::SetOwnerStatus error");
586         return ERROR;
587     }
588     if (!data.WriteParcelable(&para)) {
589         HILOGE("BluetoothMapMceProxy::SetOwnerStatus error");
590         return ERROR;
591     }
592     MessageParcel reply;
593     MessageOption option {
594         MessageOption::TF_ASYNC
595     };
596     int error = Remote()->SendRequest(
597         BluetoothMapMceInterfaceCode::MCE_SET_OWNER_STATUS, data, reply, option);
598     if (error != NO_ERROR) {
599         HILOGE("BluetoothMapMceProxy::SetOwnerStatus done fail, error: %{public}d", error);
600         return ERROR;
601     }
602     return reply.ReadInt32();
603 }
604 
GetOwnerStatus(const BluetoothRawAddress & device,const std::string & conversationId)605 int BluetoothMapMceProxy::GetOwnerStatus(const BluetoothRawAddress &device, const std::string &conversationId)
606 {
607     HILOGI("BluetoothMapMceProxy::GetOwnerStatus Triggered!");
608     MessageParcel data;
609     if (!data.WriteInterfaceToken(BluetoothMapMceProxy::GetDescriptor())) {
610         HILOGE("BluetoothMapMceProxy::GetOwnerStatus WriteInterfaceToken error");
611         return ERROR;
612     }
613     if (!data.WriteParcelable(&device)) {
614         HILOGE("BluetoothMapMceProxy::GetOwnerStatus error");
615         return ERROR;
616     }
617     if (!data.WriteString(conversationId)) {
618         HILOGE("BluetoothMapMceProxy::GetOwnerStatus error");
619         return ERROR;
620     }
621     MessageParcel reply;
622     MessageOption option {
623         MessageOption::TF_ASYNC
624     };
625     int error = Remote()->SendRequest(
626         BluetoothMapMceInterfaceCode::MCE_GET_OWNER_STATUS, data, reply, option);
627     if (error != NO_ERROR) {
628         HILOGE("BluetoothMapMceProxy::GetOwnerStatus done fail, error: %{public}d", error);
629         return ERROR;
630     }
631     return reply.ReadInt32();
632 }
633 
GetMasInstanceInfo(const BluetoothRawAddress & device)634 BluetoothIProfileMasInstanceInfoList BluetoothMapMceProxy::GetMasInstanceInfo(const BluetoothRawAddress &device)
635 {
636     HILOGI("BluetoothMapMceProxy::GetMasInstanceInfo Triggered!");
637     BluetoothIProfileMasInstanceInfoList list;
638     list.isValid = false;
639     MessageParcel data;
640     if (!data.WriteInterfaceToken(BluetoothMapMceProxy::GetDescriptor())) {
641         HILOGE("BluetoothMapMceProxy::GetMasInstanceInfo WriteInterfaceToken error");
642         return list;
643     }
644     if (!data.WriteParcelable(&device)) {
645         HILOGE("BluetoothMapMceProxy::GetMasInstanceInfo error");
646         return list;
647     }
648     MessageParcel reply;
649     MessageOption option {
650         MessageOption::TF_SYNC
651     };
652     int error = Remote()->SendRequest(
653         BluetoothMapMceInterfaceCode::MCE_GET_MAS_INSTANCE_INFO, data, reply, option);
654     if (error != NO_ERROR) {
655         HILOGE("BluetoothMapMceProxy::GetMasInstanceInfo done fail, error: %{public}d", error);
656         return list;
657     }
658     std::shared_ptr<BluetoothIProfileMasInstanceInfoList> listPtr(
659         reply.ReadParcelable<BluetoothIProfileMasInstanceInfoList>());
660     if (!listPtr) {
661         return list;
662     }
663     return *listPtr;
664 }
665 }  // namespace Bluetooth
666 }  // namespace OHOS
667