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