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