1 /*
2 * Copyright (C) 2021-2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "bluetooth_avrcp_ct_observer_stub.h"
17 #include "bluetooth_log.h"
18 #include "ipc_types.h"
19 #include "string_ex.h"
20 #include "bluetooth_errorcode.h"
21
22 namespace OHOS {
23 namespace Bluetooth {
24 using namespace OHOS::bluetooth;
25
26 const uint32_t AVRCP_COMPANY_ID_COUNT_MAX = 0xFF;
27 const uint32_t AVRCP_CAPABILITY_COUNT_MAX = 0xFF;
28 const uint32_t AVRCP_PLAYER_APP_SETTING_ATTRIBUTES_NUM_MAX = 0xFF;
29 const uint32_t AVRCP_PLAYER_APP_SETTING_VALUE_NUM_MAX = 0xFF;
30 const uint32_t AVRCP_ELEMENT_ATTRIBUTE_NUM_MAX = 0xFF;
31 const uint32_t AVRCP_FOLDER_DEPTH_MAX = 0xFF;
32 const uint32_t AVRCP_MEDIA_PLAYER_NUM_MAX = 0xFF;
33 const uint32_t AVRCP_FOLDER_ITEMS_NUM_MAX = 0xFFFF;
34
BluetoothAvrcpCtObserverStub()35 BluetoothAvrcpCtObserverStub::BluetoothAvrcpCtObserverStub()
36 {
37 HILOGI("start.");
38 memberFuncMap_[static_cast<uint32_t>(BluetoothAvrcpCtObserverInterfaceCode::AVRCP_CT_CONNECTION_STATE_CHANGED)] =
39 &BluetoothAvrcpCtObserverStub::OnConnectionStateChangedInner;
40 memberFuncMap_[static_cast<uint32_t>(BluetoothAvrcpCtObserverInterfaceCode::AVRCP_CT_PRESS_BUTTON)] =
41 &BluetoothAvrcpCtObserverStub::OnPressButtonInner;
42 memberFuncMap_[static_cast<uint32_t>(BluetoothAvrcpCtObserverInterfaceCode::AVRCP_CT_RELEASE_BUTTON)] =
43 &BluetoothAvrcpCtObserverStub::OnReleaseButtonInner;
44 memberFuncMap_[static_cast<uint32_t>(BluetoothAvrcpCtObserverInterfaceCode::AVRCP_CT_SET_BROWSED_PLAYER)] =
45 &BluetoothAvrcpCtObserverStub::OnSetBrowsedPlayerInner;
46 memberFuncMap_[static_cast<uint32_t>(BluetoothAvrcpCtObserverInterfaceCode::AVRCP_CT_GET_CAPABILITIES)] =
47 &BluetoothAvrcpCtObserverStub::OnGetCapabilitiesInner;
48 memberFuncMap_[static_cast<uint32_t>(
49 BluetoothAvrcpCtObserverInterfaceCode::AVRCP_CT_GET_PLAYER_APP_SETTING_ATTRIBUTES)] =
50 &BluetoothAvrcpCtObserverStub::OnGetPlayerAppSettingAttributesInner;
51 memberFuncMap_[static_cast<uint32_t>(
52 BluetoothAvrcpCtObserverInterfaceCode::AVRCP_CT_GET_PLAYER_APP_SETTING_VALUES)] =
53 &BluetoothAvrcpCtObserverStub::OnGetPlayerAppSettingValuesInner;
54 memberFuncMap_[static_cast<uint32_t>(
55 BluetoothAvrcpCtObserverInterfaceCode::AVRCP_CT_GET_PLAYER_APP_SETTING_CURRENT_VALUE)] =
56 &BluetoothAvrcpCtObserverStub::OnGetPlayerAppSettingCurrentValueInner;
57 memberFuncMap_[static_cast<uint32_t>(
58 BluetoothAvrcpCtObserverInterfaceCode::AVRCP_CT_SET_PLAYER_APP_SETTING_CURRENT_VALUE)] =
59 &BluetoothAvrcpCtObserverStub::OnSetPlayerAppSettingCurrentValueInner;
60 memberFuncMap_[static_cast<uint32_t>(
61 BluetoothAvrcpCtObserverInterfaceCode::AVRCP_CT_GET_PLAYER_APP_SETTING_ATTRIBUTE_TEXT)] =
62 &BluetoothAvrcpCtObserverStub::OnGetPlayerAppSettingAttributeTextInner;
63 memberFuncMap_[static_cast<uint32_t>(
64 BluetoothAvrcpCtObserverInterfaceCode::AVRCP_CT_GET_PLAYER_APP_SETTING_VALUE_TEXT)] =
65 &BluetoothAvrcpCtObserverStub::OnGetPlayerAppSettingValueTextInner;
66 memberFuncMap_[static_cast<uint32_t>(BluetoothAvrcpCtObserverInterfaceCode::AVRCP_CT_ELEMENT_ATTRIBUTRES)] =
67 &BluetoothAvrcpCtObserverStub::OnGetElementAttributesInner;
68 memberFuncMap_[static_cast<uint32_t>(BluetoothAvrcpCtObserverInterfaceCode::AVRCP_CT_GET_PLAY_STATUS)] =
69 &BluetoothAvrcpCtObserverStub::OnGetPlayStatusInner;
70 memberFuncMap_[static_cast<uint32_t>(BluetoothAvrcpCtObserverInterfaceCode::AVRCP_CT_PLAY_ITEM)] =
71 &BluetoothAvrcpCtObserverStub::OnPlayItemInner;
72 memberFuncMap_[static_cast<uint32_t>(BluetoothAvrcpCtObserverInterfaceCode::AVRCP_CT_GET_TOTAL_NUMBER_OF_ITEMS)] =
73 &BluetoothAvrcpCtObserverStub::OnGetTotalNumberOfItemsInner;
74 memberFuncMap_[static_cast<uint32_t>(BluetoothAvrcpCtObserverInterfaceCode::AVRCP_CT_GET_ITEM_ATTRIBUTES)] =
75 &BluetoothAvrcpCtObserverStub::OnGetItemAttributesInner;
76 memberFuncMap_[static_cast<uint32_t>(BluetoothAvrcpCtObserverInterfaceCode::AVRCP_CT_SET_ABSOLUTE_VOLUME)] =
77 &BluetoothAvrcpCtObserverStub::OnSetAbsoluteVolumeInner;
78 memberFuncMap_[static_cast<uint32_t>(BluetoothAvrcpCtObserverInterfaceCode::AVRCP_CT_PLAYBACK_STATUS_CHANGED)] =
79 &BluetoothAvrcpCtObserverStub::OnPlaybackStatusChangedInner;
80 memberFuncMap_[static_cast<uint32_t>(BluetoothAvrcpCtObserverInterfaceCode::AVRCP_CT_TRACK_CHANGED)] =
81 &BluetoothAvrcpCtObserverStub::OnTrackChangedInner;
82 memberFuncMap_[static_cast<uint32_t>(BluetoothAvrcpCtObserverInterfaceCode::AVRCP_CT_TRACK_REACHED_END)] =
83 &BluetoothAvrcpCtObserverStub::OnTrackReachedEndInner;
84 memberFuncMap_[static_cast<uint32_t>(BluetoothAvrcpCtObserverInterfaceCode::AVRCP_CT_TRACK_REACHED_START)] =
85 &BluetoothAvrcpCtObserverStub::OnTrackReachedStartInner;
86 memberFuncMap_[static_cast<uint32_t>(BluetoothAvrcpCtObserverInterfaceCode::AVRCP_CT_PLAYBACK_POS_CHANGED)] =
87 &BluetoothAvrcpCtObserverStub::OnPlaybackPosChangedInner;
88 memberFuncMap_[static_cast<uint32_t>(BluetoothAvrcpCtObserverInterfaceCode::AVRCP_CT_PLAY_APP_SETTING_CHANGED)] =
89 &BluetoothAvrcpCtObserverStub::OnPlayerAppSettingChangedInner;
90 memberFuncMap_[static_cast<uint32_t>(BluetoothAvrcpCtObserverInterfaceCode::AVRCP_CT_NOW_PLAYING_CONTENT_CHANGED)] =
91 &BluetoothAvrcpCtObserverStub::OnNowPlayingContentChangedInner;
92 memberFuncMap_[static_cast<uint32_t>(BluetoothAvrcpCtObserverInterfaceCode::AVRCP_CT_AVAILABLE_PLAYER_CHANGED)] =
93 &BluetoothAvrcpCtObserverStub::OnAvailablePlayersChangedInner;
94 memberFuncMap_[static_cast<uint32_t>(BluetoothAvrcpCtObserverInterfaceCode::AVRCP_CT_ADDRESSED_PLAYER_CHANGED)] =
95 &BluetoothAvrcpCtObserverStub::OnAddressedPlayerChangedInner;
96 memberFuncMap_[static_cast<uint32_t>(BluetoothAvrcpCtObserverInterfaceCode::AVRCP_CT_UID_CHANGED)] =
97 &BluetoothAvrcpCtObserverStub::OnUidChangedInner;
98 memberFuncMap_[static_cast<uint32_t>(BluetoothAvrcpCtObserverInterfaceCode::AVRCP_CT_VOLUME_CHANGED)] =
99 &BluetoothAvrcpCtObserverStub::OnVolumeChangedInner;
100 memberFuncMap_[static_cast<uint32_t>(BluetoothAvrcpCtObserverInterfaceCode::AVRCP_CT_GET_MEDIA_PLAYERS)] =
101 &BluetoothAvrcpCtObserverStub::OnGetMediaPlayersInner;
102 memberFuncMap_[static_cast<uint32_t>(BluetoothAvrcpCtObserverInterfaceCode::AVRCP_CT_GET_FOLDER_ITEMS)] =
103 &BluetoothAvrcpCtObserverStub::OnGetFolderItemsInner;
104 }
105
~BluetoothAvrcpCtObserverStub()106 BluetoothAvrcpCtObserverStub::~BluetoothAvrcpCtObserverStub()
107 {
108 HILOGI("start.");
109 memberFuncMap_.clear();
110 }
111
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)112 int BluetoothAvrcpCtObserverStub::OnRemoteRequest(
113 uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
114 {
115 HILOGD("BluetoothAvrcpCtObserverStub::OnRemoteRequest, cmd = %{public}d, flags= %{public}d",
116 code, option.GetFlags());
117 if (BluetoothAvrcpCtObserverStub::GetDescriptor() != data.ReadInterfaceToken()) {
118 HILOGI("local descriptor is not equal to remote");
119 return ERR_INVALID_STATE;
120 }
121
122 auto itFunc = memberFuncMap_.find(code);
123 if (itFunc != memberFuncMap_.end()) {
124 auto memberFunc = itFunc->second;
125 if (memberFunc != nullptr) {
126 return (this->*memberFunc)(data, reply);
127 }
128 }
129
130 HILOGW("BluetoothAvrcpCtObserverStub::OnRemoteRequest, default case, need check.");
131 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
132 }
133
OnConnectionStateChangedInner(MessageParcel & data,MessageParcel & reply)134 ErrCode BluetoothAvrcpCtObserverStub::OnConnectionStateChangedInner(MessageParcel &data, MessageParcel &reply)
135 {
136 std::string addr = data.ReadString();
137 int state = data.ReadInt32();
138
139 OnConnectionStateChanged(RawAddress(addr), state);
140 return NO_ERROR;
141 }
142
OnPressButtonInner(MessageParcel & data,MessageParcel & reply)143 ErrCode BluetoothAvrcpCtObserverStub::OnPressButtonInner(MessageParcel &data, MessageParcel &reply)
144 {
145 std::string addr = data.ReadString();
146 int button = data.ReadInt32();
147 int result = data.ReadInt32();
148
149 OnPressButton(RawAddress(addr), button, result);
150 return NO_ERROR;
151 }
152
OnReleaseButtonInner(MessageParcel & data,MessageParcel & reply)153 ErrCode BluetoothAvrcpCtObserverStub::OnReleaseButtonInner(MessageParcel &data, MessageParcel &reply)
154 {
155 std::string addr = data.ReadString();
156 int button = data.ReadInt32();
157 int result = data.ReadInt32();
158
159 OnReleaseButton(RawAddress(addr), button, result);
160 return NO_ERROR;
161 }
162
OnSetBrowsedPlayerInner(MessageParcel & data,MessageParcel & reply)163 ErrCode BluetoothAvrcpCtObserverStub::OnSetBrowsedPlayerInner(MessageParcel &data, MessageParcel &reply)
164 {
165 std::string addr = data.ReadString();
166 int uidCounter = data.ReadInt32();
167 uint32_t numberOfItems = data.ReadUint32();
168 std::vector<std::string> folderNames {};
169 int32_t namesSize = data.ReadInt32();
170 if (static_cast<uint32_t>(namesSize) > AVRCP_FOLDER_DEPTH_MAX) {
171 return BT_ERR_INVALID_PARAM;
172 }
173 for (int i = 0; i < namesSize; i++) {
174 std::string name = data.ReadString();
175 folderNames.push_back(name);
176 }
177 int result = data.ReadInt32();
178 int detail = data.ReadInt32();
179
180 OnSetBrowsedPlayer(RawAddress(addr), uidCounter, numberOfItems, folderNames, result, detail);
181 return NO_ERROR;
182 }
183
OnGetCapabilitiesInner(MessageParcel & data,MessageParcel & reply)184 ErrCode BluetoothAvrcpCtObserverStub::OnGetCapabilitiesInner(MessageParcel &data, MessageParcel &reply)
185 {
186 std::string addr = data.ReadString();
187 std::vector<uint32_t> companies {};
188 int32_t companiesSize = data.ReadInt32();
189 if (static_cast<uint32_t>(companiesSize) > AVRCP_COMPANY_ID_COUNT_MAX) {
190 return BT_ERR_INVALID_PARAM;
191 }
192 for (int i = 0; i < companiesSize; i++) {
193 uint32_t company = data.ReadUint32();
194 companies.push_back(company);
195 }
196
197 std::vector<uint8_t> events {};
198 int32_t eventsSize = data.ReadInt32();
199 if (static_cast<uint32_t>(eventsSize) > AVRCP_CAPABILITY_COUNT_MAX) {
200 return BT_ERR_INVALID_PARAM;
201 }
202 for (int i = 0; i < eventsSize; i++) {
203 uint8_t event = data.ReadInt32();
204 events.push_back(event);
205 }
206
207 int result = data.ReadInt32();
208
209 OnGetCapabilities(RawAddress(addr), companies, events, result);
210 return NO_ERROR;
211 }
212
OnGetPlayerAppSettingAttributesInner(MessageParcel & data,MessageParcel & reply)213 ErrCode BluetoothAvrcpCtObserverStub::OnGetPlayerAppSettingAttributesInner(MessageParcel &data, MessageParcel &reply)
214 {
215 std::string addr = data.ReadString();
216
217 std::vector<uint8_t> attributes {};
218 int32_t attributesSize = data.ReadInt32();
219 if (static_cast<uint32_t>(attributesSize) > AVRCP_PLAYER_APP_SETTING_ATTRIBUTES_NUM_MAX) {
220 return BT_ERR_INVALID_PARAM;
221 }
222 for (int i = 0; i < attributesSize; i++) {
223 uint8_t attrbute = data.ReadInt32();
224 attributes.push_back(attrbute);
225 }
226
227 int result = data.ReadInt32();
228
229 OnGetPlayerAppSettingAttributes(RawAddress(addr), attributes, result);
230 return NO_ERROR;
231 }
232
OnGetPlayerAppSettingValuesInner(MessageParcel & data,MessageParcel & reply)233 ErrCode BluetoothAvrcpCtObserverStub::OnGetPlayerAppSettingValuesInner(MessageParcel &data, MessageParcel &reply)
234 {
235 std::string addr = data.ReadString();
236 int attrbute = data.ReadInt32();
237
238 std::vector<uint8_t> values {};
239 int32_t valuesSize = data.ReadInt32();
240 if (static_cast<uint32_t>(valuesSize) > AVRCP_PLAYER_APP_SETTING_VALUE_NUM_MAX) {
241 return BT_ERR_INVALID_PARAM;
242 }
243 for (int i = 0; i < valuesSize; i++) {
244 uint8_t value = data.ReadInt32();
245 values.push_back(value);
246 }
247 int result = data.ReadInt32();
248
249 OnGetPlayerAppSettingValues(RawAddress(addr), attrbute, values, result);
250 return NO_ERROR;
251 }
252
OnGetPlayerAppSettingCurrentValueInner(MessageParcel & data,MessageParcel & reply)253 ErrCode BluetoothAvrcpCtObserverStub::OnGetPlayerAppSettingCurrentValueInner(MessageParcel &data, MessageParcel &reply)
254 {
255 std::string addr = data.ReadString();
256 std::vector<uint8_t> attrbutes {};
257 int32_t attrbutesSize = data.ReadInt32();
258 if (static_cast<uint32_t>(attrbutesSize) > AVRCP_PLAYER_APP_SETTING_ATTRIBUTES_NUM_MAX) {
259 return BT_ERR_INVALID_PARAM;
260 }
261 for (int i = 0; i < attrbutesSize; i++) {
262 uint8_t attrbute = data.ReadInt32();
263 attrbutes.push_back(attrbute);
264 }
265
266 std::vector<uint8_t> values {};
267 int32_t valuesSize = data.ReadInt32();
268 if (static_cast<uint32_t>(valuesSize) > AVRCP_PLAYER_APP_SETTING_ATTRIBUTES_NUM_MAX) {
269 return BT_ERR_INVALID_PARAM;
270 }
271 for (int i = 0; i < valuesSize; i++) {
272 uint8_t value = data.ReadInt32();
273 values.push_back(value);
274 }
275 int result = data.ReadInt32();
276
277 OnGetPlayerAppSettingCurrentValue(RawAddress(addr), attrbutes, values, result);
278 return NO_ERROR;
279 }
280
OnSetPlayerAppSettingCurrentValueInner(MessageParcel & data,MessageParcel & reply)281 ErrCode BluetoothAvrcpCtObserverStub::OnSetPlayerAppSettingCurrentValueInner(MessageParcel &data, MessageParcel &reply)
282 {
283 std::string addr = data.ReadString();
284 int result = data.ReadInt32();
285
286 OnSetPlayerAppSettingCurrentValue(RawAddress(addr), result);
287 return NO_ERROR;
288 }
289
OnGetPlayerAppSettingAttributeTextInner(MessageParcel & data,MessageParcel & reply)290 ErrCode BluetoothAvrcpCtObserverStub::OnGetPlayerAppSettingAttributeTextInner(MessageParcel &data, MessageParcel &reply)
291 {
292 std::string addr = data.ReadString();
293 std::vector<uint8_t> attrbutes {};
294 int32_t attrbutesSize = data.ReadInt32();
295 if (static_cast<uint32_t>(attrbutesSize) > AVRCP_PLAYER_APP_SETTING_ATTRIBUTES_NUM_MAX) {
296 return BT_ERR_INVALID_PARAM;
297 }
298 for (int i = 0; i < attrbutesSize; i++) {
299 uint8_t attrbute = data.ReadInt32();
300 attrbutes.push_back(attrbute);
301 }
302
303 std::vector<std::string> attributeNames {};
304 int32_t valuesSize = data.ReadInt32();
305 if (static_cast<uint32_t>(valuesSize) > AVRCP_PLAYER_APP_SETTING_ATTRIBUTES_NUM_MAX) {
306 return BT_ERR_INVALID_PARAM;
307 }
308 for (int i = 0; i < valuesSize; i++) {
309 std::string value = data.ReadString();
310 attributeNames.push_back(value);
311 }
312
313 int result = data.ReadInt32();
314
315 OnGetPlayerAppSettingAttributeText(RawAddress(addr), attrbutes, attributeNames, result);
316 return NO_ERROR;
317 }
318
OnGetPlayerAppSettingValueTextInner(MessageParcel & data,MessageParcel & reply)319 ErrCode BluetoothAvrcpCtObserverStub::OnGetPlayerAppSettingValueTextInner(MessageParcel &data, MessageParcel &reply)
320 {
321 std::string addr = data.ReadString();
322 std::vector<uint8_t> values {};
323 int32_t valuesSize = data.ReadInt32();
324 if (static_cast<uint32_t>(valuesSize) > AVRCP_PLAYER_APP_SETTING_VALUE_NUM_MAX) {
325 return BT_ERR_INVALID_PARAM;
326 }
327 for (int i = 0; i < valuesSize; i++) {
328 uint8_t attrbute = data.ReadInt32();
329 values.push_back(attrbute);
330 }
331
332 std::vector<std::string> valueNames {};
333 int32_t valueNamesSize = data.ReadInt32();
334 if (static_cast<uint32_t>(valueNamesSize) > AVRCP_PLAYER_APP_SETTING_VALUE_NUM_MAX) {
335 return BT_ERR_INVALID_PARAM;
336 }
337 for (int i = 0; i < valueNamesSize; i++) {
338 std::string value = data.ReadString();
339 valueNames.push_back(value);
340 }
341
342 int result = data.ReadInt32();
343
344 OnGetPlayerAppSettingValueText(RawAddress(addr), values, valueNames, result);
345 return NO_ERROR;
346 }
347
OnGetElementAttributesInner(MessageParcel & data,MessageParcel & reply)348 ErrCode BluetoothAvrcpCtObserverStub::OnGetElementAttributesInner(MessageParcel &data, MessageParcel &reply)
349 {
350 std::string addr = data.ReadString();
351 std::vector<uint32_t> attribtues {};
352 int32_t valuesSize = data.ReadInt32();
353 if (static_cast<uint32_t>(valuesSize) > AVRCP_ELEMENT_ATTRIBUTE_NUM_MAX) {
354 return BT_ERR_INVALID_PARAM;
355 }
356 for (int i = 0; i < valuesSize; i++) {
357 uint32_t attrbute = data.ReadUint32();
358 attribtues.push_back(attrbute);
359 }
360
361 std::vector<std::string> valueNames {};
362 int32_t valueNamesSize = data.ReadInt32();
363 if (static_cast<uint32_t>(valueNamesSize) > AVRCP_ELEMENT_ATTRIBUTE_NUM_MAX) {
364 return BT_ERR_INVALID_PARAM;
365 }
366 for (int i = 0; i < valueNamesSize; i++) {
367 std::string value = data.ReadString();
368 valueNames.push_back(value);
369 }
370
371 int result = data.ReadInt32();
372
373 OnGetElementAttributes(RawAddress(addr), attribtues, valueNames, result);
374 return NO_ERROR;
375 }
376
OnGetPlayStatusInner(MessageParcel & data,MessageParcel & reply)377 ErrCode BluetoothAvrcpCtObserverStub::OnGetPlayStatusInner(MessageParcel &data, MessageParcel &reply)
378 {
379 std::string addr = data.ReadString();
380 uint32_t songLength = data.ReadUint32();
381 uint32_t songPosition = data.ReadUint32();
382 uint8_t playStatus = data.ReadInt32();
383
384 int result = data.ReadInt32();
385
386 OnGetPlayStatus(RawAddress(addr), songLength, songPosition, playStatus, result);
387 return NO_ERROR;
388 }
389
OnPlayItemInner(MessageParcel & data,MessageParcel & reply)390 ErrCode BluetoothAvrcpCtObserverStub::OnPlayItemInner(MessageParcel &data, MessageParcel &reply)
391 {
392 std::string addr = data.ReadString();
393 int status = data.ReadInt32();
394 int result = data.ReadInt32();
395
396 OnPlayItem(RawAddress(addr), status, result);
397 return NO_ERROR;
398 }
399
OnGetTotalNumberOfItemsInner(MessageParcel & data,MessageParcel & reply)400 ErrCode BluetoothAvrcpCtObserverStub::OnGetTotalNumberOfItemsInner(MessageParcel &data, MessageParcel &reply)
401 {
402 std::string addr = data.ReadString();
403 uint16_t uidCounter = data.ReadInt32();
404 uint32_t numOfItems = data.ReadUint32();
405 int result = data.ReadInt32();
406 int detail = data.ReadInt32();
407
408 OnGetTotalNumberOfItems(RawAddress(addr), uidCounter, numOfItems, result, detail);
409 return NO_ERROR;
410 }
411
OnGetItemAttributesInner(MessageParcel & data,MessageParcel & reply)412 ErrCode BluetoothAvrcpCtObserverStub::OnGetItemAttributesInner(MessageParcel &data, MessageParcel &reply)
413 {
414 std::string addr = data.ReadString();
415 std::vector<uint32_t> attribtues {};
416 int32_t attribtuesSize = data.ReadInt32();
417 if (static_cast<uint32_t>(attribtuesSize) > AVRCP_PLAYER_APP_SETTING_ATTRIBUTES_NUM_MAX) {
418 return BT_ERR_INVALID_PARAM;
419 }
420 for (int i = 0; i < attribtuesSize; i++) {
421 uint32_t attrbute = data.ReadUint32();
422 attribtues.push_back(attrbute);
423 }
424
425 std::vector<std::string> valueNames {};
426 int32_t valuesSize = data.ReadInt32();
427 if (static_cast<uint32_t>(valuesSize) > AVRCP_PLAYER_APP_SETTING_ATTRIBUTES_NUM_MAX) {
428 return BT_ERR_INVALID_PARAM;
429 }
430 for (int i = 0; i < valuesSize; i++) {
431 std::string value = data.ReadString();
432 valueNames.push_back(value);
433 }
434
435 int result = data.ReadInt32();
436 int detail = data.ReadInt32();
437
438 OnGetItemAttributes(RawAddress(addr), attribtues, valueNames, result, detail);
439 return NO_ERROR;
440 }
441
OnSetAbsoluteVolumeInner(MessageParcel & data,MessageParcel & reply)442 ErrCode BluetoothAvrcpCtObserverStub::OnSetAbsoluteVolumeInner(MessageParcel &data, MessageParcel &reply)
443 {
444 std::string addr = data.ReadString();
445 uint8_t volume = data.ReadInt32();
446 int result = data.ReadInt32();
447
448 OnSetAbsoluteVolume(RawAddress(addr), volume, result);
449 return NO_ERROR;
450 }
451
OnPlaybackStatusChangedInner(MessageParcel & data,MessageParcel & reply)452 ErrCode BluetoothAvrcpCtObserverStub::OnPlaybackStatusChangedInner(MessageParcel &data, MessageParcel &reply)
453 {
454 std::string addr = data.ReadString();
455 uint8_t playStatus = data.ReadInt32();
456 int result = data.ReadInt32();
457
458 OnPlaybackStatusChanged(RawAddress(addr), playStatus, result);
459 return NO_ERROR;
460 }
461
OnTrackChangedInner(MessageParcel & data,MessageParcel & reply)462 ErrCode BluetoothAvrcpCtObserverStub::OnTrackChangedInner(MessageParcel &data, MessageParcel &reply)
463 {
464 std::string addr = data.ReadString();
465 uint64_t uid = data.ReadUint64();
466 int result = data.ReadInt32();
467
468 OnTrackChanged(RawAddress(addr), uid, result);
469 return NO_ERROR;
470 }
471
OnTrackReachedEndInner(MessageParcel & data,MessageParcel & reply)472 ErrCode BluetoothAvrcpCtObserverStub::OnTrackReachedEndInner(MessageParcel &data, MessageParcel &reply)
473 {
474 std::string addr = data.ReadString();
475 int result = data.ReadInt32();
476
477 OnTrackReachedEnd(RawAddress(addr), result);
478 return NO_ERROR;
479 }
480
OnTrackReachedStartInner(MessageParcel & data,MessageParcel & reply)481 ErrCode BluetoothAvrcpCtObserverStub::OnTrackReachedStartInner(MessageParcel &data, MessageParcel &reply)
482 {
483 std::string addr = data.ReadString();
484 int result = data.ReadInt32();
485
486 OnTrackReachedStart(RawAddress(addr), result);
487 return NO_ERROR;
488 }
489
OnPlaybackPosChangedInner(MessageParcel & data,MessageParcel & reply)490 ErrCode BluetoothAvrcpCtObserverStub::OnPlaybackPosChangedInner(MessageParcel &data, MessageParcel &reply)
491 {
492 std::string addr = data.ReadString();
493 uint32_t playbackPos = data.ReadUint32();
494 int result = data.ReadInt32();
495
496 OnPlaybackPosChanged(RawAddress(addr), playbackPos, result);
497 return NO_ERROR;
498 }
499
OnPlayerAppSettingChangedInner(MessageParcel & data,MessageParcel & reply)500 ErrCode BluetoothAvrcpCtObserverStub::OnPlayerAppSettingChangedInner(MessageParcel &data, MessageParcel &reply)
501 {
502 std::string addr = data.ReadString();
503 std::vector<uint8_t> attribtues {};
504 int32_t attribtuesSize = data.ReadInt32();
505 if (static_cast<uint32_t>(attribtuesSize) > AVRCP_PLAYER_APP_SETTING_ATTRIBUTES_NUM_MAX) {
506 return BT_ERR_INVALID_PARAM;
507 }
508 for (int i = 0; i < attribtuesSize; i++) {
509 int32_t attrbute = data.ReadInt32();
510 attribtues.push_back(attrbute);
511 }
512
513 std::vector<uint8_t> values {};
514 int32_t valuesSize = data.ReadInt32();
515 if (static_cast<uint32_t>(valuesSize) > AVRCP_PLAYER_APP_SETTING_ATTRIBUTES_NUM_MAX) {
516 return BT_ERR_INVALID_PARAM;
517 }
518 for (int i = 0; i < valuesSize; i++) {
519 int32_t attrbute = data.ReadInt32();
520 values.push_back(attrbute);
521 }
522
523 int result = data.ReadInt32();
524
525 OnPlayerAppSettingChanged(RawAddress(addr), attribtues, values, result);
526 return NO_ERROR;
527 }
528
OnNowPlayingContentChangedInner(MessageParcel & data,MessageParcel & reply)529 ErrCode BluetoothAvrcpCtObserverStub::OnNowPlayingContentChangedInner(MessageParcel &data, MessageParcel &reply)
530 {
531 std::string addr = data.ReadString();
532 int result = data.ReadInt32();
533
534 OnNowPlayingContentChanged(RawAddress(addr), result);
535 return NO_ERROR;
536 }
537
OnAvailablePlayersChangedInner(MessageParcel & data,MessageParcel & reply)538 ErrCode BluetoothAvrcpCtObserverStub::OnAvailablePlayersChangedInner(MessageParcel &data, MessageParcel &reply)
539 {
540 std::string addr = data.ReadString();
541 int result = data.ReadInt32();
542
543 OnAvailablePlayersChanged(RawAddress(addr), result);
544 return NO_ERROR;
545 }
546
OnAddressedPlayerChangedInner(MessageParcel & data,MessageParcel & reply)547 ErrCode BluetoothAvrcpCtObserverStub::OnAddressedPlayerChangedInner(MessageParcel &data, MessageParcel &reply)
548 {
549 std::string addr = data.ReadString();
550 uint16_t playerId = data.ReadInt32();
551 uint16_t uidCounter = data.ReadInt32();
552 int result = data.ReadInt32();
553 OnAddressedPlayerChanged(RawAddress(addr), playerId, uidCounter, result);
554 return NO_ERROR;
555 }
556
OnUidChangedInner(MessageParcel & data,MessageParcel & reply)557 ErrCode BluetoothAvrcpCtObserverStub::OnUidChangedInner(MessageParcel &data, MessageParcel &reply)
558 {
559 std::string addr = data.ReadString();
560 uint16_t uidCounter = data.ReadInt32();
561 int result = data.ReadInt32();
562 OnUidChanged(RawAddress(addr), uidCounter, result);
563 return NO_ERROR;
564 }
565
OnVolumeChangedInner(MessageParcel & data,MessageParcel & reply)566 ErrCode BluetoothAvrcpCtObserverStub::OnVolumeChangedInner(MessageParcel &data, MessageParcel &reply)
567 {
568 std::string addr = data.ReadString();
569 uint8_t volume = data.ReadInt32();
570 int result = data.ReadInt32();
571 OnVolumeChanged(RawAddress(addr), volume, result);
572 return NO_ERROR;
573 }
574
OnGetMediaPlayersInner(MessageParcel & data,MessageParcel & reply)575 ErrCode BluetoothAvrcpCtObserverStub::OnGetMediaPlayersInner(MessageParcel &data, MessageParcel &reply)
576 {
577 std::string addr = data.ReadString();
578 uint16_t uidCounter = data.ReadInt32();
579
580 std::vector<BluetoothAvrcpMpItem> items {};
581 int32_t itemsSize = data.ReadInt32();
582 if (static_cast<uint32_t>(itemsSize) > AVRCP_MEDIA_PLAYER_NUM_MAX) {
583 return BT_ERR_INVALID_PARAM;
584 }
585 for (int i = 0; i < itemsSize; i++) {
586 std::shared_ptr<BluetoothAvrcpMpItem> item(data.ReadParcelable<BluetoothAvrcpMpItem>());
587 if (!item) {
588 return TRANSACTION_ERR;
589 }
590 items.push_back(*item);
591 }
592 int result = data.ReadInt32();
593 int detail = data.ReadInt32();
594 OnGetMediaPlayers(RawAddress(addr), uidCounter, items, result, detail);
595 return NO_ERROR;
596 }
597
OnGetFolderItemsInner(MessageParcel & data,MessageParcel & reply)598 ErrCode BluetoothAvrcpCtObserverStub::OnGetFolderItemsInner(MessageParcel &data, MessageParcel &reply)
599 {
600 std::string addr = data.ReadString();
601 uint8_t uidCounter = data.ReadInt32();
602
603 std::vector<BluetoothAvrcpMeItem> items {};
604 int32_t itemsSize = data.ReadInt32();
605 if (static_cast<uint32_t>(itemsSize) > AVRCP_FOLDER_ITEMS_NUM_MAX) {
606 return BT_ERR_INVALID_PARAM;
607 }
608 for (int i = 0; i < itemsSize; i++) {
609 std::shared_ptr<BluetoothAvrcpMeItem> item(data.ReadParcelable<BluetoothAvrcpMeItem>());
610 if (!item) {
611 return TRANSACTION_ERR;
612 }
613 items.push_back(*item);
614 }
615 int result = data.ReadInt32();
616 int detail = data.ReadInt32();
617 OnGetFolderItems(RawAddress(addr), uidCounter, items, result, detail);
618 return NO_ERROR;
619 }
620 } // namespace Bluetooth
621 } // namespace OHOS
622