1 /*
2  * Copyright (C) 2021 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_avrcp_ct_observer_proxy.h"
17 #include "bluetooth_log.h"
18 
19 namespace OHOS {
20 namespace Bluetooth {
OnConnectionStateChanged(const RawAddress & rawAddr,int state,int cause)21 void BluetoothAvrcpCtObserverProxy::OnConnectionStateChanged(const RawAddress &rawAddr, int state, int cause)
22 {
23     MessageParcel data;
24     if (!data.WriteInterfaceToken(BluetoothAvrcpCtObserverProxy::GetDescriptor())) {
25         HILOGE("[OnConnectionStateChanged] fail: write interface token failed.");
26         return;
27     }
28 
29     if (!data.WriteString(rawAddr.GetAddress())) {
30         HILOGE("[OnConnectionStateChanged] fail: write addr failed");
31         return;
32     }
33 
34     if (!data.WriteInt32(state)) {
35         HILOGE("[OnConnectionStateChanged] fail: write state failed");
36         return;
37     }
38 
39     if (!data.WriteInt32(cause)) {
40         HILOGE("[OnConnectionStateChanged] fail: write cause failed");
41         return;
42     }
43     MessageParcel reply;
44     MessageOption option = {MessageOption::TF_ASYNC};
45     int error = InnerTransact(
46         BluetoothAvrcpCtObserverInterfaceCode::AVRCP_CT_CONNECTION_STATE_CHANGED, option, data, reply);
47     if (error != NO_ERROR) {
48         HILOGE("BluetoothAvrcpCtObserverProxy::OnConnectionStateChanged done fail, error: %{public}d", error);
49         return;
50     }
51 }
52 
OnPressButton(const RawAddress & rawAddr,uint8_t button,int result)53 void BluetoothAvrcpCtObserverProxy::OnPressButton(const RawAddress &rawAddr, uint8_t button, int result)
54 {
55     MessageParcel data;
56     if (!data.WriteInterfaceToken(BluetoothAvrcpCtObserverProxy::GetDescriptor())) {
57         HILOGE("[OnPressButton] fail: write interface token failed.");
58         return;
59     }
60 
61     if (!data.WriteString(rawAddr.GetAddress())) {
62         HILOGE("[OnPressButton] fail: write result failed");
63         return;
64     }
65 
66     if (!data.WriteInt32(button)) {
67         HILOGE("[OnPressButton] fail: write result failed");
68         return;
69     }
70 
71     if (!data.WriteInt32(result)) {
72         HILOGE("[OnPressButton] fail: write result failed");
73         return;
74     }
75 
76     MessageParcel reply;
77     MessageOption option = {MessageOption::TF_ASYNC};
78     int error = InnerTransact(
79         BluetoothAvrcpCtObserverInterfaceCode::AVRCP_CT_PRESS_BUTTON, option, data, reply);
80     if (error != NO_ERROR) {
81         HILOGE("BluetoothAvrcpCtObserverProxy::OnPressButton done fail, error: %{public}d", error);
82         return;
83     }
84 }
85 
OnReleaseButton(const RawAddress & rawAddr,uint8_t button,int result)86 void BluetoothAvrcpCtObserverProxy::OnReleaseButton(const RawAddress &rawAddr, uint8_t button,  int result)
87 {
88     MessageParcel data;
89     if (!data.WriteInterfaceToken(BluetoothAvrcpCtObserverProxy::GetDescriptor())) {
90         HILOGE("[OnReleaseButton] fail: write interface token failed.");
91         return;
92     }
93 
94     if (!data.WriteString(rawAddr.GetAddress())) {
95         HILOGE("[OnReleaseButton] fail: write result failed");
96         return;
97     }
98 
99     if (!data.WriteInt32(button)) {
100         HILOGE("[OnReleaseButton] fail: write result failed");
101         return;
102     }
103 
104     if (!data.WriteInt32(result)) {
105         HILOGE("[OnReleaseButton] fail: write result failed");
106         return;
107     }
108 
109     MessageParcel reply;
110     MessageOption option = {MessageOption::TF_ASYNC};
111     int error = InnerTransact(
112         BluetoothAvrcpCtObserverInterfaceCode::AVRCP_CT_RELEASE_BUTTON, option, data, reply);
113     if (error != NO_ERROR) {
114         HILOGE("BluetoothAvrcpCtObserverProxy::OnReleaseButton done fail, error: %{public}d", error);
115         return;
116     }
117 }
OnSetBrowsedPlayer(const RawAddress & rawAddr,uint16_t uidCounter,uint32_t numberOfItems,const std::vector<std::string> & folderNames,int result,int detail)118 void BluetoothAvrcpCtObserverProxy::OnSetBrowsedPlayer(const RawAddress &rawAddr, uint16_t uidCounter,
119     uint32_t numberOfItems, const std::vector<std::string> &folderNames, int result, int detail)
120 {
121     MessageParcel data;
122     if (!data.WriteInterfaceToken(BluetoothAvrcpCtObserverProxy::GetDescriptor())) {
123         HILOGE("[OnSetBrowsedPlayer] fail: write interface token failed.");
124         return;
125     }
126 
127     if (!data.WriteString(rawAddr.GetAddress())) {
128         HILOGE("[OnSetBrowsedPlayer] fail: write result failed");
129         return;
130     }
131 
132     if (!data.WriteInt32(uidCounter)) {
133         HILOGE("[OnSetBrowsedPlayer] fail: write result failed");
134         return;
135     }
136 
137     if (!data.WriteUint32(numberOfItems)) {
138         HILOGE("[OnSetBrowsedPlayer] fail: write result failed");
139         return;
140     }
141 
142     if (!WriteParcelableStringVector(folderNames, data)) {
143         HILOGE("[OnSetBrowsedPlayer] fail: write result failed");
144         return;
145     }
146 
147     if (!data.WriteInt32(result)) {
148         HILOGE("[OnSetBrowsedPlayer] fail: write result failed");
149         return;
150     }
151 
152     if (!data.WriteInt32(detail)) {
153         HILOGE("[OnSetBrowsedPlayer] fail: write result failed");
154         return;
155     }
156 
157     MessageParcel reply;
158     MessageOption option = {MessageOption::TF_ASYNC};
159     int error = InnerTransact(
160         BluetoothAvrcpCtObserverInterfaceCode::AVRCP_CT_SET_BROWSED_PLAYER, option, data, reply);
161     if (error != NO_ERROR) {
162         HILOGE("BluetoothAvrcpCtObserverProxy::OnSetBrowsedPlayer done fail, error: %{public}d", error);
163         return;
164     }
165 }
OnGetCapabilities(const RawAddress & rawAddr,const std::vector<uint32_t> & companies,const std::vector<uint8_t> & events,int result)166 void BluetoothAvrcpCtObserverProxy::OnGetCapabilities(const RawAddress &rawAddr, const std::vector<uint32_t> &companies,
167     const std::vector<uint8_t> &events, int result)
168 {
169     MessageParcel data;
170     if (!data.WriteInterfaceToken(BluetoothAvrcpCtObserverProxy::GetDescriptor())) {
171         HILOGE("[OnGetCapabilities] fail: write interface token failed.");
172         return;
173     }
174 
175     if (!data.WriteString(rawAddr.GetAddress())) {
176         HILOGE("[OnGetCapabilities] fail: write result failed");
177         return;
178     }
179 
180     if (!WriteParcelableUint32Vector(companies, data)) {
181         HILOGE("[OnGetCapabilities] fail: write result failed");
182         return;
183     }
184 
185     std::vector<int32_t> eventsTmp = {};
186     for (auto event : events) {
187         eventsTmp.push_back(event);
188     }
189 
190     if (!WriteParcelableInt32Vector(eventsTmp, data)) {
191         HILOGE("[OnGetCapabilities] fail: write result failed");
192         return;
193     }
194 
195     if (!data.WriteInt32(result)) {
196         HILOGE("[OnGetCapabilities] fail: write result failed");
197         return;
198     }
199 
200     MessageParcel reply;
201     MessageOption option = {MessageOption::TF_ASYNC};
202     int error = InnerTransact(
203         BluetoothAvrcpCtObserverInterfaceCode::AVRCP_CT_GET_CAPABILITIES, option, data, reply);
204     if (error != NO_ERROR) {
205         HILOGE("BluetoothAvrcpCtObserverProxy::OnGetCapabilities done fail, error: %{public}d", error);
206         return;
207     }
208 }
OnGetPlayerAppSettingAttributes(const RawAddress & rawAddr,std::vector<uint8_t> attributes,int result)209 void BluetoothAvrcpCtObserverProxy::OnGetPlayerAppSettingAttributes(
210     const RawAddress &rawAddr, std::vector<uint8_t> attributes, int result)
211 {
212     MessageParcel data;
213     if (!data.WriteInterfaceToken(BluetoothAvrcpCtObserverProxy::GetDescriptor())) {
214         HILOGE("[OnGetPlayerAppSettingAttributes] fail: write interface token failed.");
215         return;
216     }
217 
218     if (!data.WriteString(rawAddr.GetAddress())) {
219         HILOGE("[OnGetPlayerAppSettingAttributes] fail: write result failed");
220         return;
221     }
222 
223     std::vector<int32_t> attributesTmp = {};
224     for (auto event : attributes) {
225         attributesTmp.push_back(event);
226     }
227     if (!WriteParcelableInt32Vector(attributesTmp, data)) {
228         HILOGE("[OnGetPlayerAppSettingAttributes] fail: write result failed");
229         return;
230     }
231 
232     if (!data.WriteInt32(result)) {
233         HILOGE("[OnGetPlayerAppSettingAttributes] fail: write result failed");
234         return;
235     }
236 
237     MessageParcel reply;
238     MessageOption option = {MessageOption::TF_ASYNC};
239     int error = InnerTransact(
240         BluetoothAvrcpCtObserverInterfaceCode::AVRCP_CT_GET_PLAYER_APP_SETTING_ATTRIBUTES, option, data, reply);
241     if (error != NO_ERROR) {
242         HILOGE("BluetoothAvrcpCtObserverProxy::OnGetPlayerAppSettingAttributes done fail, error: %{public}d", error);
243         return;
244     }
245 }
OnGetPlayerAppSettingValues(const RawAddress & rawAddr,int attribute,const std::vector<uint8_t> & values,int result)246 void BluetoothAvrcpCtObserverProxy::OnGetPlayerAppSettingValues(const RawAddress &rawAddr,
247     int attribute, const std::vector<uint8_t> &values, int result)
248 {
249     MessageParcel data;
250     if (!data.WriteInterfaceToken(BluetoothAvrcpCtObserverProxy::GetDescriptor())) {
251         HILOGE("[OnGetPlayerAppSettingValues] fail: write interface token failed.");
252         return;
253     }
254 
255     if (!data.WriteString(rawAddr.GetAddress())) {
256         HILOGE("[OnGetPlayerAppSettingValues] fail: write result failed");
257         return;
258     }
259 
260     if (!data.WriteInt32(attribute)) {
261         HILOGE("[OnGetPlayerAppSettingValues] fail: write result failed");
262         return;
263     }
264 
265     std::vector<int32_t> valuesTmp {};
266     for (auto event : values) {
267         valuesTmp.push_back(event);
268     }
269     if (!WriteParcelableInt32Vector(valuesTmp, data)) {
270         HILOGE("[OnGetPlayerAppSettingValues] fail: write result failed");
271         return;
272     }
273 
274     if (!data.WriteInt32(result)) {
275         HILOGE("[OnGetPlayerAppSettingValues] fail: write result failed");
276         return;
277     }
278 
279     MessageParcel reply;
280     MessageOption option = {MessageOption::TF_ASYNC};
281     int error = InnerTransact(
282         BluetoothAvrcpCtObserverInterfaceCode::AVRCP_CT_GET_PLAYER_APP_SETTING_VALUES, option, data, reply);
283     if (error != NO_ERROR) {
284         HILOGE("BluetoothAvrcpCtObserverProxy::OnGetPlayerAppSettingValues done fail, error: %{public}d", error);
285         return;
286     }
287 }
OnGetPlayerAppSettingCurrentValue(const RawAddress & rawAddr,const std::vector<uint8_t> attributes,const std::vector<uint8_t> & values,int result)288 void BluetoothAvrcpCtObserverProxy::OnGetPlayerAppSettingCurrentValue(
289     const RawAddress &rawAddr, const std::vector<uint8_t> attributes, const std::vector<uint8_t> &values, int result)
290 {
291     MessageParcel data;
292     if (!data.WriteInterfaceToken(BluetoothAvrcpCtObserverProxy::GetDescriptor())) {
293         HILOGE("[OnGetPlayerAppSettingCurrentValue] fail: write interface token failed.");
294         return;
295     }
296 
297     if (!data.WriteString(rawAddr.GetAddress())) {
298         HILOGE("[OnGetPlayerAppSettingCurrentValue] fail: write result failed");
299         return;
300     }
301 
302     std::vector<int32_t> attributesTmp {};
303     for (auto event : attributes) {
304         attributesTmp.push_back(event);
305     }
306     if (!WriteParcelableInt32Vector(attributesTmp, data)) {
307         HILOGE("[OnGetPlayerAppSettingCurrentValue] fail: write result failed");
308         return;
309     }
310 
311     std::vector<int32_t> valuesTmp {};
312     for (auto event : values) {
313         valuesTmp.push_back(event);
314     }
315     if (!WriteParcelableInt32Vector(valuesTmp, data)) {
316         HILOGE("[OnGetPlayerAppSettingCurrentValue] fail: write result failed");
317         return;
318     }
319 
320     if (!data.WriteInt32(result)) {
321         HILOGE("[OnGetPlayerAppSettingCurrentValue] fail: write result failed");
322         return;
323     }
324 
325     MessageParcel reply;
326     MessageOption option = {MessageOption::TF_ASYNC};
327     int error = InnerTransact(
328         BluetoothAvrcpCtObserverInterfaceCode::AVRCP_CT_GET_PLAYER_APP_SETTING_CURRENT_VALUE,
329         option, data, reply);
330     if (error != NO_ERROR) {
331         HILOGE("BluetoothAvrcpCtObserverProxy::OnGetPlayerAppSettingCurrentValue done fail, error: %{public}d", error);
332         return;
333     }
334 }
335 
OnSetPlayerAppSettingCurrentValue(const RawAddress & rawAddr,int result)336 void BluetoothAvrcpCtObserverProxy::OnSetPlayerAppSettingCurrentValue(const RawAddress &rawAddr, int result)
337 {
338     MessageParcel data;
339     if (!data.WriteInterfaceToken(BluetoothAvrcpCtObserverProxy::GetDescriptor())) {
340         HILOGE("[OnSetPlayerAppSettingCurrentValue] fail: write interface token failed.");
341         return;
342     }
343 
344     if (!data.WriteString(rawAddr.GetAddress())) {
345         HILOGE("[OnSetPlayerAppSettingCurrentValue] fail: write result failed");
346         return;
347     }
348 
349     if (!data.WriteInt32(result)) {
350         HILOGE("[OnSetPlayerAppSettingCurrentValue] fail: write result failed");
351         return;
352     }
353 
354     MessageParcel reply;
355     MessageOption option = {MessageOption::TF_ASYNC};
356     int error = InnerTransact(
357         BluetoothAvrcpCtObserverInterfaceCode::AVRCP_CT_SET_PLAYER_APP_SETTING_CURRENT_VALUE, option, data, reply);
358     if (error != NO_ERROR) {
359         HILOGE("BluetoothAvrcpCtObserverProxy::OnSetPlayerAppSettingCurrentValue done fail, error: %{public}d", error);
360         return;
361     }
362 }
363 
OnGetPlayerAppSettingAttributeText(const RawAddress & rawAddr,const std::vector<uint8_t> attribtues,const std::vector<std::string> & attributeName,int result)364 void BluetoothAvrcpCtObserverProxy::OnGetPlayerAppSettingAttributeText(const RawAddress &rawAddr,
365     const std::vector<uint8_t> attribtues, const std::vector<std::string> &attributeName, int result)
366 {
367     MessageParcel data;
368     if (!data.WriteInterfaceToken(BluetoothAvrcpCtObserverProxy::GetDescriptor())) {
369         HILOGE("[OnGetPlayerAppSettingCurrentValue] fail: write interface token failed.");
370         return;
371     }
372 
373     if (!data.WriteString(rawAddr.GetAddress())) {
374         HILOGE("[OnGetPlayerAppSettingCurrentValue] fail: write result failed");
375         return;
376     }
377 
378     std::vector<int32_t> attributesTmp {};
379     for (auto event : attribtues) {
380         attributesTmp.push_back(event);
381     }
382     if (!WriteParcelableInt32Vector(attributesTmp, data)) {
383         HILOGE("[OnGetPlayerAppSettingCurrentValue] fail: write result failed");
384         return;
385     }
386 
387     if (!WriteParcelableStringVector(attributeName, data)) {
388         HILOGE("[OnGetPlayerAppSettingCurrentValue] fail: write result failed");
389         return;
390     }
391 
392     if (!data.WriteInt32(result)) {
393         HILOGE("[OnGetPlayerAppSettingCurrentValue] fail: write result failed");
394         return;
395     }
396 
397     MessageParcel reply;
398     MessageOption option = {MessageOption::TF_ASYNC};
399     int error = InnerTransact(
400         BluetoothAvrcpCtObserverInterfaceCode::AVRCP_CT_GET_PLAYER_APP_SETTING_ATTRIBUTE_TEXT, option, data, reply);
401     if (error != NO_ERROR) {
402         HILOGE("BluetoothAvrcpCtObserverProxy::OnGetPlayerAppSettingCurrentValue done fail, error: %{public}d", error);
403         return;
404     }
405 }
406 
OnGetPlayerAppSettingValueText(const RawAddress & rawAddr,const std::vector<uint8_t> & values,const std::vector<std::string> & valueName,int result)407 void BluetoothAvrcpCtObserverProxy::OnGetPlayerAppSettingValueText(const RawAddress &rawAddr,
408     const std::vector<uint8_t> &values, const std::vector<std::string> &valueName, int result)
409 {
410     MessageParcel data;
411     if (!data.WriteInterfaceToken(BluetoothAvrcpCtObserverProxy::GetDescriptor())) {
412         HILOGE("[OnGetPlayerAppSettingValueText] fail: write interface token failed.");
413         return;
414     }
415 
416     if (!data.WriteString(rawAddr.GetAddress())) {
417         HILOGE("[OnGetPlayerAppSettingValueText] fail: write result failed");
418         return;
419     }
420 
421     std::vector<int32_t> valuesTmp{};
422     for (auto event : values) {
423         valuesTmp.push_back(event);
424     }
425     if (!WriteParcelableInt32Vector(valuesTmp, data)) {
426         HILOGE("[OnGetPlayerAppSettingValueText] fail: write result failed");
427         return;
428     }
429 
430     if (!WriteParcelableStringVector(valueName, data)) {
431         HILOGE("[OnGetPlayerAppSettingValueText] fail: write result failed");
432         return;
433     }
434 
435     if (!data.WriteInt32(result)) {
436         HILOGE("[OnGetPlayerAppSettingValueText] fail: write result failed");
437         return;
438     }
439 
440     MessageParcel reply;
441     MessageOption option = {MessageOption::TF_ASYNC};
442     int error = InnerTransact(
443         BluetoothAvrcpCtObserverInterfaceCode::AVRCP_CT_GET_PLAYER_APP_SETTING_VALUE_TEXT, option, data, reply);
444     if (error != NO_ERROR) {
445         HILOGE("BluetoothAvrcpCtObserverProxy::OnGetPlayerAppSettingValueText done fail, error: %{public}d", error);
446         return;
447     }
448 }
449 
OnGetElementAttributes(const RawAddress & rawAddr,const std::vector<uint32_t> & attribtues,const std::vector<std::string> & valueName,int result)450 void BluetoothAvrcpCtObserverProxy::OnGetElementAttributes(const RawAddress &rawAddr,
451     const std::vector<uint32_t> &attribtues, const std::vector<std::string> &valueName, int result)
452 {
453     MessageParcel data;
454     if (!data.WriteInterfaceToken(BluetoothAvrcpCtObserverProxy::GetDescriptor())) {
455         HILOGE("[OnGetElementAttributes] fail: write interface token failed.");
456         return;
457     }
458 
459     if (!data.WriteString(rawAddr.GetAddress())) {
460         HILOGE("[OnGetElementAttributes] fail: write result failed");
461         return;
462     }
463 
464     if (!WriteParcelableUint32Vector(attribtues, data)) {
465         HILOGE("[OnGetElementAttributes] fail: write result failed");
466         return;
467     }
468 
469     if (!WriteParcelableStringVector(valueName, data)) {
470         HILOGE("[OnGetElementAttributes] fail: write result failed");
471         return;
472     }
473 
474     if (!data.WriteInt32(result)) {
475         HILOGE("[OnGetElementAttributes] fail: write result failed");
476         return;
477     }
478 
479     MessageParcel reply;
480     MessageOption option = {MessageOption::TF_ASYNC};
481     int error = InnerTransact(
482         BluetoothAvrcpCtObserverInterfaceCode::AVRCP_CT_ELEMENT_ATTRIBUTRES, option, data, reply);
483     if (error != NO_ERROR) {
484         HILOGE("BluetoothAvrcpCtObserverProxy::OnGetElementAttributes done fail, error: %{public}d", error);
485         return;
486     }
487 }
488 
OnGetPlayStatus(const RawAddress & rawAddr,uint32_t songLength,uint32_t songPosition,uint8_t playStatus,int result)489 void BluetoothAvrcpCtObserverProxy::OnGetPlayStatus(const RawAddress &rawAddr,
490     uint32_t songLength, uint32_t songPosition, uint8_t playStatus, int result)
491 {
492     MessageParcel data;
493     if (!data.WriteInterfaceToken(BluetoothAvrcpCtObserverProxy::GetDescriptor())) {
494         HILOGE("[OnGetPlayStatus] fail: write interface token failed.");
495         return;
496     }
497 
498     if (!data.WriteString(rawAddr.GetAddress())) {
499         HILOGE("[OnGetPlayStatus] fail: write result failed");
500         return;
501     }
502 
503     if (!data.WriteUint32(songLength)) {
504         HILOGE("[OnGetPlayStatus] fail: write result failed");
505         return;
506     }
507 
508     if (!data.WriteUint32(songPosition)) {
509         HILOGE("[OnGetPlayStatus] fail: write result failed");
510         return;
511     }
512 
513     if (!data.WriteInt32(playStatus)) {
514         HILOGE("[OnGetPlayStatus] fail: write result failed");
515         return;
516     }
517 
518 
519     if (!data.WriteInt32(result)) {
520         HILOGE("[OnGetPlayStatus] fail: write result failed");
521         return;
522     }
523 
524     MessageParcel reply;
525     MessageOption option = {MessageOption::TF_ASYNC};
526     int error = InnerTransact(
527         BluetoothAvrcpCtObserverInterfaceCode::AVRCP_CT_GET_PLAY_STATUS, option, data, reply);
528     if (error != NO_ERROR) {
529         HILOGE("BluetoothAvrcpCtObserverProxy::OnGetPlayStatus done fail, error: %{public}d", error);
530         return;
531     }
532 }
533 
OnPlayItem(const RawAddress & rawAddr,int status,int result)534 void BluetoothAvrcpCtObserverProxy::OnPlayItem(const RawAddress &rawAddr, int status, int result)
535 {
536     MessageParcel data;
537     if (!data.WriteInterfaceToken(BluetoothAvrcpCtObserverProxy::GetDescriptor())) {
538         HILOGE("[OnPlayItem] fail: write interface token failed.");
539         return;
540     }
541 
542     if (!data.WriteString(rawAddr.GetAddress())) {
543         HILOGE("[OnPlayItem] fail: write result failed");
544         return;
545     }
546 
547     if (!data.WriteInt32(status)) {
548         HILOGE("[OnPlayItem] fail: write result failed");
549         return;
550     }
551 
552     if (!data.WriteInt32(result)) {
553         HILOGE("[OnPlayItem] fail: write result failed");
554         return;
555     }
556 
557     MessageParcel reply;
558     MessageOption option = {MessageOption::TF_ASYNC};
559     int error = InnerTransact(
560         BluetoothAvrcpCtObserverInterfaceCode::AVRCP_CT_PLAY_ITEM, option, data, reply);
561     if (error != NO_ERROR) {
562         HILOGE("BluetoothAvrcpCtObserverProxy::OnPlayItem done fail, error: %{public}d", error);
563         return;
564     }
565 }
566 
OnGetTotalNumberOfItems(const RawAddress & rawAddr,uint16_t uidCounter,uint32_t numOfItems,int result,int detail)567 void BluetoothAvrcpCtObserverProxy::OnGetTotalNumberOfItems(const RawAddress &rawAddr,
568     uint16_t uidCounter, uint32_t numOfItems, int result, int detail)
569 {
570     MessageParcel data;
571     if (!data.WriteInterfaceToken(BluetoothAvrcpCtObserverProxy::GetDescriptor())) {
572         HILOGE("[OnGetTotalNumberOfItems] fail: write interface token failed.");
573         return;
574     }
575 
576     if (!data.WriteString(rawAddr.GetAddress())) {
577         HILOGE("[OnGetTotalNumberOfItems] fail: write result failed");
578         return;
579     }
580 
581     if (!data.WriteInt32(uidCounter)) {
582         HILOGE("[OnGetTotalNumberOfItems] fail: write result failed");
583         return;
584     }
585 
586     if (!data.WriteUint32(numOfItems)) {
587         HILOGE("[OnGetTotalNumberOfItems] fail: write result failed");
588         return;
589     }
590 
591     if (!data.WriteInt32(uidCounter)) {
592         HILOGE("[OnGetTotalNumberOfItems] fail: write result failed");
593         return;
594     }
595 
596     if (!data.WriteInt32(detail)) {
597         HILOGE("[OnGetTotalNumberOfItems] fail: write result failed");
598         return;
599     }
600 
601     MessageParcel reply;
602     MessageOption option = {MessageOption::TF_ASYNC};
603     int error = InnerTransact(
604         BluetoothAvrcpCtObserverInterfaceCode::AVRCP_CT_GET_TOTAL_NUMBER_OF_ITEMS, option, data, reply);
605     if (error != NO_ERROR) {
606         HILOGE("BluetoothAvrcpCtObserverProxy::OnGetTotalNumberOfItems done fail, error: %{public}d", error);
607         return;
608     }
609 }
610 
OnGetItemAttributes(const RawAddress & rawAddr,const std::vector<uint32_t> & attribtues,const std::vector<std::string> & values,int result,int detail)611 void BluetoothAvrcpCtObserverProxy::OnGetItemAttributes(const RawAddress &rawAddr,
612     const std::vector<uint32_t> &attribtues, const std::vector<std::string> &values, int result, int detail)
613 {
614     MessageParcel data;
615     if (!data.WriteInterfaceToken(BluetoothAvrcpCtObserverProxy::GetDescriptor())) {
616         HILOGE("[OnGetItemAttributes] fail: write interface token failed.");
617         return;
618     }
619 
620     if (!data.WriteString(rawAddr.GetAddress())) {
621         HILOGE("[OnGetItemAttributes] fail: write result failed");
622         return;
623     }
624 
625     if (!WriteParcelableUint32Vector(attribtues, data)) {
626         HILOGE("[OnGetItemAttributes] fail: write result failed");
627         return;
628     }
629 
630     if (!WriteParcelableStringVector(values, data)) {
631         HILOGE("[OnGetItemAttributes] fail: write result failed");
632         return;
633     }
634 
635     if (!data.WriteInt32(result)) {
636         HILOGE("[OnGetItemAttributes] fail: write result failed");
637         return;
638     }
639 
640     if (!data.WriteInt32(detail)) {
641         HILOGE("[OnGetItemAttributes] fail: write result failed");
642         return;
643     }
644 
645     MessageParcel reply;
646     MessageOption option = {MessageOption::TF_ASYNC};
647     int error = InnerTransact(
648         BluetoothAvrcpCtObserverInterfaceCode::AVRCP_CT_GET_ITEM_ATTRIBUTES, option, data, reply);
649     if (error != NO_ERROR) {
650         HILOGE("BluetoothAvrcpCtObserverProxy::OnGetItemAttributes done fail, error: %{public}d", error);
651         return;
652     }
653 }
654 
OnSetAbsoluteVolume(const RawAddress & rawAddr,uint8_t volume,int result)655 void BluetoothAvrcpCtObserverProxy::OnSetAbsoluteVolume(const RawAddress &rawAddr, uint8_t volume, int result)
656 {
657     MessageParcel data;
658     if (!data.WriteInterfaceToken(BluetoothAvrcpCtObserverProxy::GetDescriptor())) {
659         HILOGE("[OnSetAbsoluteVolume] fail: write interface token failed.");
660         return;
661     }
662 
663     if (!data.WriteString(rawAddr.GetAddress())) {
664         HILOGE("[OnSetAbsoluteVolume] fail: write result failed");
665         return;
666     }
667 
668     if (!data.WriteInt32(volume)) {
669         HILOGE("[OnSetAbsoluteVolume] fail: write result failed");
670         return;
671     }
672 
673     if (!data.WriteInt32(result)) {
674         HILOGE("[OnSetAbsoluteVolume] fail: write result failed");
675         return;
676     }
677 
678     MessageParcel reply;
679     MessageOption option = {MessageOption::TF_ASYNC};
680     int error = InnerTransact(
681         BluetoothAvrcpCtObserverInterfaceCode::AVRCP_CT_SET_ABSOLUTE_VOLUME, option, data, reply);
682     if (error != NO_ERROR) {
683         HILOGE("BluetoothAvrcpCtObserverProxy::OnSetAbsoluteVolume done fail, error: %{public}d", error);
684         return;
685     }
686 }
687 
OnPlaybackStatusChanged(const RawAddress & rawAddr,uint8_t playStatus,int result)688 void BluetoothAvrcpCtObserverProxy::OnPlaybackStatusChanged(const RawAddress &rawAddr, uint8_t playStatus, int result)
689 {
690     MessageParcel data;
691     if (!data.WriteInterfaceToken(BluetoothAvrcpCtObserverProxy::GetDescriptor())) {
692         HILOGE("[OnPlaybackStatusChanged] fail: write interface token failed.");
693         return;
694     }
695 
696     if (!data.WriteString(rawAddr.GetAddress())) {
697         HILOGE("[OnPlaybackStatusChanged] fail: write result failed");
698         return;
699     }
700 
701     if (!data.WriteInt32(playStatus)) {
702         HILOGE("[OnPlaybackStatusChanged] fail: write result failed");
703         return;
704     }
705 
706     if (!data.WriteInt32(result)) {
707         HILOGE("[OnPlaybackStatusChanged] fail: write result failed");
708         return;
709     }
710 
711     MessageParcel reply;
712     MessageOption option = {MessageOption::TF_ASYNC};
713     int error = InnerTransact(
714         BluetoothAvrcpCtObserverInterfaceCode::AVRCP_CT_PLAYBACK_STATUS_CHANGED, option, data, reply);
715     if (error != NO_ERROR) {
716         HILOGE("BluetoothAvrcpCtObserverProxy::OnPlaybackStatusChanged done fail, error: %{public}d", error);
717         return;
718     }
719 }
720 
OnTrackChanged(const RawAddress & rawAddr,uint64_t uid,int result)721 void BluetoothAvrcpCtObserverProxy::OnTrackChanged(const RawAddress &rawAddr, uint64_t uid, int result)
722 {
723     MessageParcel data;
724     if (!data.WriteInterfaceToken(BluetoothAvrcpCtObserverProxy::GetDescriptor())) {
725         HILOGE("[OnTrackChanged] fail: write interface token failed.");
726         return;
727     }
728 
729     if (!data.WriteString(rawAddr.GetAddress())) {
730         HILOGE("[OnTrackChanged] fail: write result failed");
731         return;
732     }
733 
734     if (!data.WriteInt64(uid)) {
735         HILOGE("[OnTrackChanged] fail: write result failed");
736         return;
737     }
738 
739     if (!data.WriteInt32(result)) {
740         HILOGE("[OnTrackChanged] fail: write result failed");
741         return;
742     }
743 
744     MessageParcel reply;
745     MessageOption option = {MessageOption::TF_ASYNC};
746     int error = InnerTransact(
747         BluetoothAvrcpCtObserverInterfaceCode::AVRCP_CT_TRACK_CHANGED, option, data, reply);
748     if (error != NO_ERROR) {
749         HILOGE("BluetoothAvrcpCtObserverProxy::OnTrackChanged done fail, error: %{public}d", error);
750         return;
751     }
752 }
753 
OnTrackReachedEnd(const RawAddress & rawAddr,int result)754 void BluetoothAvrcpCtObserverProxy::OnTrackReachedEnd(const RawAddress &rawAddr, int result)
755 {
756     MessageParcel data;
757     if (!data.WriteInterfaceToken(BluetoothAvrcpCtObserverProxy::GetDescriptor())) {
758         HILOGE("[OnTrackReachedEnd] fail: write interface token failed.");
759         return;
760     }
761 
762     if (!data.WriteString(rawAddr.GetAddress())) {
763         HILOGE("[OnTrackReachedEnd] fail: write result failed");
764         return;
765     }
766 
767     if (!data.WriteInt32(result)) {
768         HILOGE("[OnTrackReachedEnd] fail: write result failed");
769         return;
770     }
771 
772     MessageParcel reply;
773     MessageOption option = {MessageOption::TF_ASYNC};
774     int error = InnerTransact(
775         BluetoothAvrcpCtObserverInterfaceCode::AVRCP_CT_TRACK_REACHED_END, option, data, reply);
776     if (error != NO_ERROR) {
777         HILOGE("BluetoothAvrcpCtObserverProxy::OnTrackReachedEnd done fail, error: %{public}d", error);
778         return;
779     }
780 }
781 
OnTrackReachedStart(const RawAddress & rawAddr,int result)782 void BluetoothAvrcpCtObserverProxy::OnTrackReachedStart(const RawAddress &rawAddr, int result)
783 {
784     MessageParcel data;
785     if (!data.WriteInterfaceToken(BluetoothAvrcpCtObserverProxy::GetDescriptor())) {
786         HILOGE("[OnTrackReachedStart] fail: write interface token failed.");
787         return;
788     }
789 
790     if (!data.WriteString(rawAddr.GetAddress())) {
791         HILOGE("[OnTrackReachedStart] fail: write result failed");
792         return;
793     }
794 
795     if (!data.WriteInt32(result)) {
796         HILOGE("[OnTrackReachedStart] fail: write result failed");
797         return;
798     }
799 
800     MessageParcel reply;
801     MessageOption option = {MessageOption::TF_ASYNC};
802     int error = InnerTransact(
803         BluetoothAvrcpCtObserverInterfaceCode::AVRCP_CT_TRACK_REACHED_START, option, data, reply);
804     if (error != NO_ERROR) {
805         HILOGE("BluetoothAvrcpCtObserverProxy::OnTrackReachedStart done fail, error: %{public}d", error);
806         return;
807     }
808 }
809 
OnPlaybackPosChanged(const RawAddress & rawAddr,uint32_t playbackPos,int result)810 void BluetoothAvrcpCtObserverProxy::OnPlaybackPosChanged(const RawAddress &rawAddr, uint32_t playbackPos, int result)
811 {
812     MessageParcel data;
813     if (!data.WriteInterfaceToken(BluetoothAvrcpCtObserverProxy::GetDescriptor())) {
814         HILOGE("[OnPlaybackPosChanged] fail: write interface token failed.");
815         return;
816     }
817 
818     if (!data.WriteString(rawAddr.GetAddress())) {
819         HILOGE("[OnPlaybackPosChanged] fail: write result failed");
820         return;
821     }
822 
823     if (!data.WriteUint32(playbackPos)) {
824         HILOGE("[OnPlaybackPosChanged] fail: write result failed");
825         return;
826     }
827 
828     if (!data.WriteInt32(result)) {
829         HILOGE("[OnPlaybackPosChanged] fail: write result failed");
830         return;
831     }
832 
833     MessageParcel reply;
834     MessageOption option = {MessageOption::TF_ASYNC};
835     int error = InnerTransact(
836         BluetoothAvrcpCtObserverInterfaceCode::AVRCP_CT_PLAYBACK_POS_CHANGED, option, data, reply);
837     if (error != NO_ERROR) {
838         HILOGE("BluetoothAvrcpCtObserverProxy::OnPlaybackPosChanged done fail, error: %{public}d", error);
839         return;
840     }
841 }
842 
OnPlayerAppSettingChanged(const RawAddress & rawAddr,const std::vector<uint8_t> & attributes,const std::vector<uint8_t> & values,int result)843 void BluetoothAvrcpCtObserverProxy::OnPlayerAppSettingChanged(const RawAddress &rawAddr,
844     const std::vector<uint8_t> &attributes, const std::vector<uint8_t> &values, int result)
845 {
846     MessageParcel data;
847     if (!data.WriteInterfaceToken(BluetoothAvrcpCtObserverProxy::GetDescriptor())) {
848         HILOGE("[OnPlayerAppSettingChanged] fail: write interface token failed.");
849         return;
850     }
851 
852     if (!data.WriteString(rawAddr.GetAddress())) {
853         HILOGE("[OnPlayerAppSettingChanged] fail: write result failed");
854         return;
855     }
856 
857     std::vector<int32_t> attributesTmp {};
858     for (auto event : attributes) {
859         attributesTmp.push_back(event);
860     }
861     if (!WriteParcelableInt32Vector(attributesTmp, data)) {
862         HILOGE("[OnPlayerAppSettingChanged] fail: write result failed");
863         return;
864     }
865 
866     std::vector<int32_t> valuesTmp {};
867     for (auto event : values) {
868         valuesTmp.push_back(event);
869     }
870     if (!WriteParcelableInt32Vector(valuesTmp, data)) {
871         HILOGE("[OnPlayerAppSettingChanged] fail: write result failed");
872         return;
873     }
874 
875     if (!data.WriteInt32(result)) {
876         HILOGE("[OnPlayerAppSettingChanged] fail: write result failed");
877         return;
878     }
879 
880     MessageParcel reply;
881     MessageOption option = {MessageOption::TF_ASYNC};
882     int error = InnerTransact(
883         BluetoothAvrcpCtObserverInterfaceCode::AVRCP_CT_PLAY_APP_SETTING_CHANGED, option, data, reply);
884     if (error != NO_ERROR) {
885         HILOGE("BluetoothAvrcpCtObserverProxy::OnPlayerAppSettingChanged done fail, error: %{public}d", error);
886         return;
887     }
888 }
889 
OnNowPlayingContentChanged(const RawAddress & rawAddr,int result)890 void BluetoothAvrcpCtObserverProxy::OnNowPlayingContentChanged(const RawAddress &rawAddr, int result)
891 {
892     MessageParcel data;
893     if (!data.WriteInterfaceToken(BluetoothAvrcpCtObserverProxy::GetDescriptor())) {
894         HILOGE("[OnNowPlayingContentChanged] fail: write interface token failed.");
895         return;
896     }
897 
898     if (!data.WriteString(rawAddr.GetAddress())) {
899         HILOGE("[OnNowPlayingContentChanged] fail: write result failed");
900         return;
901     }
902 
903     if (!data.WriteInt32(result)) {
904         HILOGE("[OnNowPlayingContentChanged] fail: write result failed");
905         return;
906     }
907 
908     MessageParcel reply;
909     MessageOption option = {MessageOption::TF_ASYNC};
910     int error = InnerTransact(
911         BluetoothAvrcpCtObserverInterfaceCode::AVRCP_CT_NOW_PLAYING_CONTENT_CHANGED, option, data, reply);
912     if (error != NO_ERROR) {
913         HILOGE("BluetoothAvrcpCtObserverProxy::OnNowPlayingContentChanged done fail, error: %{public}d", error);
914         return;
915     }
916 }
917 
OnAvailablePlayersChanged(const RawAddress & rawAddr,int result)918 void BluetoothAvrcpCtObserverProxy::OnAvailablePlayersChanged(const RawAddress &rawAddr, int result)
919 {
920     MessageParcel data;
921     if (!data.WriteInterfaceToken(BluetoothAvrcpCtObserverProxy::GetDescriptor())) {
922         HILOGE("[OnAvailablePlayersChanged] fail: write interface token failed.");
923         return;
924     }
925 
926     if (!data.WriteString(rawAddr.GetAddress())) {
927         HILOGE("[OnAvailablePlayersChanged] fail: write result failed");
928         return;
929     }
930 
931     if (!data.WriteInt32(result)) {
932         HILOGE("[OnAvailablePlayersChanged] fail: write result failed");
933         return;
934     }
935 
936     MessageParcel reply;
937     MessageOption option = {MessageOption::TF_ASYNC};
938     int error = InnerTransact(
939         BluetoothAvrcpCtObserverInterfaceCode::AVRCP_CT_AVAILABLE_PLAYER_CHANGED, option, data, reply);
940     if (error != NO_ERROR) {
941         HILOGE("BluetoothAvrcpCtObserverProxy::OnAvailablePlayersChanged done fail, error: %{public}d", error);
942         return;
943     }
944 }
945 
OnAddressedPlayerChanged(const RawAddress & rawAddr,uint16_t playerId,uint16_t uidCounter,int result)946 void BluetoothAvrcpCtObserverProxy::OnAddressedPlayerChanged(
947     const RawAddress &rawAddr, uint16_t playerId, uint16_t uidCounter, int result)
948 {
949     MessageParcel data;
950     if (!data.WriteInterfaceToken(BluetoothAvrcpCtObserverProxy::GetDescriptor())) {
951         HILOGE("[OnAddressedPlayerChanged] fail: write interface token failed.");
952         return;
953     }
954 
955     if (!data.WriteString(rawAddr.GetAddress())) {
956         HILOGE("[OnAddressedPlayerChanged] fail: write result failed");
957         return;
958     }
959 
960     if (!data.WriteInt32(playerId)) {
961         HILOGE("[OnAddressedPlayerChanged] fail: write result failed");
962         return;
963     }
964 
965     if (!data.WriteInt32(uidCounter)) {
966         HILOGE("[OnAddressedPlayerChanged] fail: write result failed");
967         return;
968     }
969 
970     if (!data.WriteInt32(result)) {
971         HILOGE("[OnAddressedPlayerChanged] fail: write result failed");
972         return;
973     }
974 
975     MessageParcel reply;
976     MessageOption option = {MessageOption::TF_ASYNC};
977     int error = InnerTransact(
978         BluetoothAvrcpCtObserverInterfaceCode::AVRCP_CT_ADDRESSED_PLAYER_CHANGED, option, data, reply);
979     if (error != NO_ERROR) {
980         HILOGE("BluetoothAvrcpCtObserverProxy::OnAddressedPlayerChanged done fail, error: %{public}d", error);
981         return;
982     }
983 }
984 
OnUidChanged(const RawAddress & rawAddr,uint16_t uidCounter,int result)985 void BluetoothAvrcpCtObserverProxy::OnUidChanged(const RawAddress &rawAddr, uint16_t uidCounter, int result)
986 {
987     MessageParcel data;
988     if (!data.WriteInterfaceToken(BluetoothAvrcpCtObserverProxy::GetDescriptor())) {
989         HILOGE("[OnUidChanged] fail: write interface token failed.");
990         return;
991     }
992 
993     if (!data.WriteString(rawAddr.GetAddress())) {
994         HILOGE("[OnUidChanged] fail: write result failed");
995         return;
996     }
997 
998     if (!data.WriteInt32(uidCounter)) {
999         HILOGE("[OnUidChanged] fail: write result failed");
1000         return;
1001     }
1002 
1003     if (!data.WriteInt32(result)) {
1004         HILOGE("[OnUidChanged] fail: write result failed");
1005         return;
1006     }
1007 
1008     MessageParcel reply;
1009     MessageOption option = {MessageOption::TF_ASYNC};
1010     int error = InnerTransact(
1011         BluetoothAvrcpCtObserverInterfaceCode::AVRCP_CT_UID_CHANGED, option, data, reply);
1012     if (error != NO_ERROR) {
1013         HILOGE("BluetoothAvrcpCtObserverProxy::OnUidChanged done fail, error: %{public}d", error);
1014         return;
1015     }
1016 }
1017 
OnVolumeChanged(const RawAddress & rawAddr,uint8_t volume,int result)1018 void BluetoothAvrcpCtObserverProxy::OnVolumeChanged(const RawAddress &rawAddr, uint8_t volume, int result)
1019 {
1020     MessageParcel data;
1021     if (!data.WriteInterfaceToken(BluetoothAvrcpCtObserverProxy::GetDescriptor())) {
1022         HILOGE("[OnVolumeChanged] fail: write interface token failed.");
1023         return;
1024     }
1025 
1026     if (!data.WriteString(rawAddr.GetAddress())) {
1027         HILOGE("[OnVolumeChanged] fail: write result failed");
1028         return;
1029     }
1030 
1031     if (!data.WriteInt32(volume)) {
1032         HILOGE("[OnVolumeChanged] fail: write result failed");
1033         return;
1034     }
1035 
1036     if (!data.WriteInt32(result)) {
1037         HILOGE("[OnVolumeChanged] fail: write result failed");
1038         return;
1039     }
1040 
1041     MessageParcel reply;
1042     MessageOption option = {MessageOption::TF_ASYNC};
1043     int error = InnerTransact(
1044         BluetoothAvrcpCtObserverInterfaceCode::AVRCP_CT_VOLUME_CHANGED, option, data, reply);
1045     if (error != NO_ERROR) {
1046         HILOGE("BluetoothAvrcpCtObserverProxy::OnVolumeChanged done fail, error: %{public}d", error);
1047         return;
1048     }
1049 }
1050 
OnGetMediaPlayers(const RawAddress & rawAddr,uint16_t uidCounter,std::vector<BluetoothAvrcpMpItem> & items,int result,int detail)1051 void BluetoothAvrcpCtObserverProxy::OnGetMediaPlayers(const RawAddress &rawAddr, uint16_t uidCounter,
1052     std::vector<BluetoothAvrcpMpItem> &items, int result, int detail)
1053 {
1054     MessageParcel data;
1055     if (!data.WriteInterfaceToken(BluetoothAvrcpCtObserverProxy::GetDescriptor())) {
1056         HILOGE("[OnGetMediaPlayers] fail: write interface token failed.");
1057         return;
1058     }
1059 
1060     if (!data.WriteString(rawAddr.GetAddress())) {
1061         HILOGE("[OnGetMediaPlayers] fail: write result failed");
1062         return;
1063     }
1064 
1065     if (!data.WriteInt32(uidCounter)) {
1066         HILOGE("[OnGetMediaPlayers] fail: write result failed");
1067         return;
1068     }
1069 
1070     if (!data.WriteInt32(items.size())) {
1071         HILOGE("[OnGetMediaPlayers] fail: write result failed");
1072         return;
1073     }
1074     for (uint32_t i = 0; i < items.size(); i++) {
1075         if (!data.WriteParcelable(&items[i])) {
1076             HILOGE("[OnGetMediaPlayers] fail: write AvrcMpItem result failed");
1077             return;
1078         }
1079     }
1080 
1081     if (!data.WriteInt32(result)) {
1082         HILOGE("[OnGetMediaPlayers] fail: write result failed");
1083         return;
1084     }
1085 
1086     if (!data.WriteInt32(detail)) {
1087         HILOGE("[OnGetMediaPlayers] fail: write result failed");
1088         return;
1089     }
1090 
1091     MessageParcel reply;
1092     MessageOption option = {MessageOption::TF_ASYNC};
1093     int error = InnerTransact(
1094         BluetoothAvrcpCtObserverInterfaceCode::AVRCP_CT_GET_MEDIA_PLAYERS, option, data, reply);
1095     if (error != NO_ERROR) {
1096         HILOGE("BluetoothAvrcpCtObserverProxy::OnGetMediaPlayers done fail, error: %{public}d", error);
1097         return;
1098     }
1099 }
1100 
OnGetFolderItems(const RawAddress & rawAddr,uint16_t uidCounter,std::vector<BluetoothAvrcpMeItem> & items,int result,int detail)1101 void BluetoothAvrcpCtObserverProxy::OnGetFolderItems(const RawAddress &rawAddr, uint16_t uidCounter,
1102     std::vector<BluetoothAvrcpMeItem> &items, int result, int detail)
1103 {
1104     MessageParcel data;
1105     if (!data.WriteInterfaceToken(BluetoothAvrcpCtObserverProxy::GetDescriptor())) {
1106         HILOGE("[OnGetFolderItems] fail: write interface token failed.");
1107         return;
1108     }
1109 
1110     if (!data.WriteString(rawAddr.GetAddress())) {
1111         HILOGE("[OnGetFolderItems] fail: write result failed");
1112         return;
1113     }
1114 
1115     if (!data.WriteInt32(uidCounter)) {
1116         HILOGE("[OnGetFolderItems] fail: write result failed");
1117         return;
1118     }
1119 
1120     if (!data.WriteInt32(items.size())) {
1121         HILOGE("[OnGetFolderItems] fail: write result failed");
1122         return;
1123     }
1124     for (uint32_t i = 0; i < items.size(); i++) {
1125         if (!data.WriteParcelable(&items[i])) {
1126             HILOGE("[OnGetFolderItems] fail: write AvrcMeItem result failed");
1127             return;
1128         }
1129     }
1130 
1131     if (!data.WriteInt32(result)) {
1132         HILOGE("[OnGetFolderItems] fail: write result failed");
1133         return;
1134     }
1135 
1136     if (!data.WriteInt32(detail)) {
1137         HILOGE("[OnGetFolderItems] fail: write result failed");
1138         return;
1139     }
1140 
1141     MessageParcel reply;
1142     MessageOption option = {MessageOption::TF_ASYNC};
1143     int error = InnerTransact(
1144         BluetoothAvrcpCtObserverInterfaceCode::AVRCP_CT_GET_FOLDER_ITEMS, option, data, reply);
1145     if (error != NO_ERROR) {
1146         HILOGE("BluetoothAvrcpCtObserverProxy::OnGetFolderItems done fail, error: %{public}d", error);
1147         return;
1148     }
1149 }
1150 
WriteParcelableStringVector(const std::vector<std::string> & parcelableVector,Parcel & reply)1151 bool BluetoothAvrcpCtObserverProxy::WriteParcelableStringVector(
1152     const std::vector<std::string> &parcelableVector, Parcel &reply)
1153 {
1154     if (!reply.WriteInt32(parcelableVector.size())) {
1155         HILOGE("write WriteParcelableStringVector failed");
1156         return false;
1157     }
1158 
1159     for (auto parcelable : parcelableVector) {
1160         if (!reply.WriteString(parcelable)) {
1161             HILOGE("write WriteParcelableStringVector failed");
1162             return false;
1163         }
1164     }
1165     return true;
1166 }
1167 
WriteParcelableInt32Vector(const std::vector<std::int32_t> & parcelableVector,Parcel & reply)1168 bool BluetoothAvrcpCtObserverProxy::WriteParcelableInt32Vector(
1169     const std::vector<std::int32_t> &parcelableVector, Parcel &reply)
1170 {
1171     if (!reply.WriteInt32(parcelableVector.size())) {
1172         HILOGE("write WriteParcelableInt32Vector failed");
1173         return false;
1174     }
1175 
1176     for (auto parcelable : parcelableVector) {
1177         if (!reply.WriteInt32(parcelable)) {
1178             HILOGE("write WriteParcelableInt32Vector failed");
1179             return false;
1180         }
1181     }
1182     return true;
1183 }
1184 
WriteParcelableUint32Vector(const std::vector<std::uint32_t> & parcelableVector,Parcel & reply)1185 bool BluetoothAvrcpCtObserverProxy::WriteParcelableUint32Vector(
1186     const std::vector<std::uint32_t> &parcelableVector, Parcel &reply)
1187 {
1188     if (!reply.WriteInt32(parcelableVector.size())) {
1189         HILOGE("write WriteParcelableUint32Vector failed");
1190         return false;
1191     }
1192 
1193     for (auto parcelable : parcelableVector) {
1194         if (!reply.WriteUint32(parcelable)) {
1195             HILOGE("write WriteParcelableUint32Vector failed");
1196             return false;
1197         }
1198     }
1199     return true;
1200 }
1201 
InnerTransact(BluetoothAvrcpCtObserverInterfaceCode interfaceCode,MessageOption & flags,MessageParcel & data,MessageParcel & reply)1202 ErrCode BluetoothAvrcpCtObserverProxy::InnerTransact(BluetoothAvrcpCtObserverInterfaceCode interfaceCode,
1203     MessageOption &flags, MessageParcel &data, MessageParcel &reply)
1204 {
1205     uint32_t code = static_cast<uint32_t>(interfaceCode);
1206     auto remote = Remote();
1207     if (remote == nullptr) {
1208         HILOGW("[InnerTransact] fail: get Remote fail code %{public}d", code);
1209         return OBJECT_NULL;
1210     }
1211     int err = remote->SendRequest(code, data, reply, flags);
1212     switch (err) {
1213         case NO_ERROR: {
1214             return NO_ERROR;
1215         }
1216         case DEAD_OBJECT: {
1217             HILOGW("[InnerTransact] fail: ipcErr=%{public}d code %{public}d", err, code);
1218             return DEAD_OBJECT;
1219         }
1220         default: {
1221             HILOGW("[InnerTransact] fail: ipcErr=%{public}d code %{public}d", err, code);
1222             return TRANSACTION_ERR;
1223         }
1224     }
1225 }
1226 }  // namespace Bluetooth
1227 }  // namespace OHOS
1228