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_stub.h"
17 #include "bluetooth_log.h"
18 #include "ipc_types.h"
19 #include "string_ex.h"
20
21 namespace OHOS {
22 namespace Bluetooth {
23 const uint32_t AVRCP_NOTIDICATION_EVENT_COUNT_MAX = 0XFF;
24 const uint32_t AVRCP_PLAYER_APP_SETTING_ATTRIBUTES_NUM_MAX = 0XFF;
BluetoothAvrcpCtStub()25 BluetoothAvrcpCtStub::BluetoothAvrcpCtStub()
26 {
27 HILOGD("%{public}s start.", __func__);
28 memberFuncMap_[static_cast<uint32_t>(BluetoothAvrcpCtInterfaceCode::AVRCP_CT_REGISTER_OBSERVER)] =
29 &BluetoothAvrcpCtStub::RegisterObserverInner;
30 memberFuncMap_[static_cast<uint32_t>(BluetoothAvrcpCtInterfaceCode::AVRCP_CT_UNREGISTER_OBSERVER)] =
31 &BluetoothAvrcpCtStub::UnregisterObserverInner;
32 memberFuncMap_[static_cast<uint32_t>(BluetoothAvrcpCtInterfaceCode::AVRCP_CT_GET_CONNECTED_DEVICES)] =
33 &BluetoothAvrcpCtStub::GetConnectedDevicesInner;
34 memberFuncMap_[static_cast<uint32_t>(BluetoothAvrcpCtInterfaceCode::AVRCP_CT_GET_DEVICES_BY_STATES)] =
35 &BluetoothAvrcpCtStub::GetDevicesByStatesInner;
36 memberFuncMap_[static_cast<uint32_t>(BluetoothAvrcpCtInterfaceCode::AVRCP_CT_GET_DEVICE_STATE)] =
37 &BluetoothAvrcpCtStub::GetDeviceStateInner;
38 memberFuncMap_[static_cast<uint32_t>(BluetoothAvrcpCtInterfaceCode::AVRCP_CT_CONNECT)] =
39 nullptr;
40 memberFuncMap_[static_cast<uint32_t>(BluetoothAvrcpCtInterfaceCode::AVRCP_CT_DISCONNECT)] =
41 &BluetoothAvrcpCtStub::DisconnectInner;
42 memberFuncMap_[static_cast<uint32_t>(BluetoothAvrcpCtInterfaceCode::AVRCP_CT_PRESS_BUTTON)] =
43 &BluetoothAvrcpCtStub::PressButtonnner;
44 memberFuncMap_[static_cast<uint32_t>(BluetoothAvrcpCtInterfaceCode::AVRCP_CT_RELEASE_BUTTON)] =
45 &BluetoothAvrcpCtStub::ReleaseButtonInner;
46 memberFuncMap_[static_cast<uint32_t>(BluetoothAvrcpCtInterfaceCode::AVRCP_CT_GET_UNIT_INFO)] =
47 &BluetoothAvrcpCtStub::GetUnitInfoInner;
48 memberFuncMap_[static_cast<uint32_t>(BluetoothAvrcpCtInterfaceCode::AVRCP_CT_GET_SUB_UNIT_INFO)] =
49 &BluetoothAvrcpCtStub::GetSubUnitInfoInner;
50 memberFuncMap_[static_cast<uint32_t>(BluetoothAvrcpCtInterfaceCode::AVRCP_CT_GET_SUPPORTED_COMPANIES)] =
51 &BluetoothAvrcpCtStub::GetSupportedCompaniesInner;
52 memberFuncMap_[static_cast<uint32_t>(BluetoothAvrcpCtInterfaceCode::AVRCP_CT_GET_SUPPORTED_EVENTS)] =
53 &BluetoothAvrcpCtStub::GetSupportedEventsInner;
54 memberFuncMap_[static_cast<uint32_t>(BluetoothAvrcpCtInterfaceCode::AVRCP_CT_GET_PLAYER_APP_SETTING_ATTRIBUTES)] =
55 &BluetoothAvrcpCtStub::GetPlayerAppSettingAttributesInner;
56 memberFuncMap_[static_cast<uint32_t>(BluetoothAvrcpCtInterfaceCode::AVRCP_CT_GET_PLAYER_APP_SETTING_VALUES)] =
57 &BluetoothAvrcpCtStub::GetPlayerAppSettingValuesInner;
58 memberFuncMap_[static_cast<uint32_t>(
59 BluetoothAvrcpCtInterfaceCode::AVRCP_CT_GET_PLAYER_APP_SETTING_CURRENT_VALUE)] =
60 &BluetoothAvrcpCtStub::GetPlayerAppSettingCurrentValueInner;
61 memberFuncMap_[static_cast<uint32_t>(
62 BluetoothAvrcpCtInterfaceCode::AVRCP_CT_SET_PLAYER_APP_SETTING_CURRENT_VALUE)] =
63 &BluetoothAvrcpCtStub::SetPlayerAppSettingCurrentValueInner;
64 memberFuncMap_[static_cast<uint32_t>(
65 BluetoothAvrcpCtInterfaceCode::AVRCP_CT_GET_PLAYER_APP_SETTING_ATTRIBUTE_TEXT)] =
66 &BluetoothAvrcpCtStub::GetPlayerAppSettingAttributeTextInner;
67 memberFuncMap_[static_cast<uint32_t>(BluetoothAvrcpCtInterfaceCode::AVRCP_CT_GET_PLAYER_APP_SETTING_VALUES_TEXT)] =
68 &BluetoothAvrcpCtStub::GetPlayerAppSettingValueTextInner;
69 memberFuncMap_[static_cast<uint32_t>(BluetoothAvrcpCtInterfaceCode::AVRCP_CT_GET_ELEMENT_ATTRIBUTES)] =
70 &BluetoothAvrcpCtStub::GetElementAttributesInner;
71 memberFuncMap_[static_cast<uint32_t>(BluetoothAvrcpCtInterfaceCode::AVRCP_CT_GET_PLAYER_STATUS)] =
72 &BluetoothAvrcpCtStub::GetPlayStatusInner;
73 memberFuncMap_[static_cast<uint32_t>(BluetoothAvrcpCtInterfaceCode::AVRCP_CT_PLAY_ITEM)] =
74 &BluetoothAvrcpCtStub::PlayItemInner;
75 memberFuncMap_[static_cast<uint32_t>(BluetoothAvrcpCtInterfaceCode::AVRCP_CT_GET_FOLDER_ITEMS)] =
76 &BluetoothAvrcpCtStub::GetFolderItemsInner;
77 memberFuncMap_[static_cast<uint32_t>(BluetoothAvrcpCtInterfaceCode::AVRCP_CT_GET_TOTAL_NUMBER_OF_ITEMS)] =
78 &BluetoothAvrcpCtStub::GetTotalNumberOfItemsInner;
79 memberFuncMap_[static_cast<uint32_t>(BluetoothAvrcpCtInterfaceCode::AVRCP_CT_SET_ABSOLUTE_VOLUME)] =
80 &BluetoothAvrcpCtStub::SetAbsoluteVolumeInner;
81 memberFuncMap_[static_cast<uint32_t>(BluetoothAvrcpCtInterfaceCode::AVRCP_CT_ENABLE_NOTIFICATION)] =
82 &BluetoothAvrcpCtStub::EnableNotificationInner;
83 memberFuncMap_[static_cast<uint32_t>(BluetoothAvrcpCtInterfaceCode::AVRCP_CT_DISABLE_NOTIFICATION)] =
84 &BluetoothAvrcpCtStub::DisableNotificationInner;
85 memberFuncMap_[static_cast<uint32_t>(BluetoothAvrcpCtInterfaceCode::AVRCP_CT_GET_ITEM_ATTRIBUTES)] =
86 &BluetoothAvrcpCtStub::GetItemAttributesInner;
87 memberFuncMap_[static_cast<uint32_t>(BluetoothAvrcpCtInterfaceCode::AVRCP_CT_SET_BROWSERED_PLAYER)] =
88 &BluetoothAvrcpCtStub::SetBrowsedPlayerInner;
89 memberFuncMap_[static_cast<uint32_t>(BluetoothAvrcpCtInterfaceCode::AVRCP_CT_MEDIA_PLAYER_LIST)] =
90 &BluetoothAvrcpCtStub::GetMeidaPlayerListInner;
91 }
92
~BluetoothAvrcpCtStub()93 BluetoothAvrcpCtStub::~BluetoothAvrcpCtStub()
94 {
95 HILOGD("%{public}s start.", __func__);
96 memberFuncMap_.clear();
97 }
98
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)99 int BluetoothAvrcpCtStub::OnRemoteRequest(
100 uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
101 {
102 HILOGD("BluetoothAvrcpCtStub::OnRemoteRequest, cmd = %{public}d, flags= %{public}d",
103 code,
104 option.GetFlags());
105 std::u16string descriptor = BluetoothAvrcpCtStub::GetDescriptor();
106 std::u16string remoteDescriptor = data.ReadInterfaceToken();
107 if (descriptor != remoteDescriptor) {
108 HILOGI("local descriptor is not equal to remote");
109 return ERR_INVALID_STATE;
110 }
111
112 auto itFunc = memberFuncMap_.find(code);
113 if (itFunc != memberFuncMap_.end()) {
114 auto memberFunc = itFunc->second;
115 if (memberFunc != nullptr) {
116 return (this->*memberFunc)(data,reply);
117 }
118 }
119
120 HILOGW("BluetoothAvrcpCtStub::OnRemoteRequest, default case, need check.");
121 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
122 }
123
RegisterObserverInner(MessageParcel & data,MessageParcel & reply)124 ErrCode BluetoothAvrcpCtStub::RegisterObserverInner(MessageParcel &data, MessageParcel &reply)
125 {
126 sptr<IRemoteObject> tempObject = data.ReadRemoteObject();
127 sptr<IBluetoothAvrcpCtObserver> observer;
128 observer = iface_cast<IBluetoothAvrcpCtObserver>(tempObject);
129 RegisterObserver(observer);
130 return NO_ERROR;
131 }
132
UnregisterObserverInner(MessageParcel & data,MessageParcel & reply)133 ErrCode BluetoothAvrcpCtStub::UnregisterObserverInner(MessageParcel &data, MessageParcel &reply)
134 {
135 sptr<IRemoteObject> tempObject = data.ReadRemoteObject();
136 sptr<IBluetoothAvrcpCtObserver> observer;
137 observer = iface_cast<IBluetoothAvrcpCtObserver>(tempObject);
138 UnregisterObserver(observer);
139 return NO_ERROR;
140 }
141
GetConnectedDevicesInner(MessageParcel & data,MessageParcel & reply)142 ErrCode BluetoothAvrcpCtStub::GetConnectedDevicesInner(MessageParcel &data, MessageParcel &reply)
143 {
144 std::vector<RawAddress> rawAdds = GetConnectedDevices();
145 reply.WriteInt32(rawAdds.size());
146 for (auto rawAdd : rawAdds) {
147 if (!reply.WriteString(rawAdd.GetAddress())) {
148 HILOGE("GetConnectedDevicesInner: write WriteString failed");
149 return ERR_INVALID_STATE;
150 }
151 }
152 return NO_ERROR;
153 }
154
GetDevicesByStatesInner(MessageParcel & data,MessageParcel & reply)155 ErrCode BluetoothAvrcpCtStub::GetDevicesByStatesInner(MessageParcel &data, MessageParcel &reply)
156 {
157 std::vector<int32_t> states = {};
158 int32_t stateSize = data.ReadInt32();
159 if (IsInvalidDeviceStatesSize(stateSize)) {
160 HILOGE("BluetoothAvrcpCtStub::GetDevicesByStatesInner Invalid MessageParcel device states");
161 return ERR_INVALID_VALUE;
162 }
163 for (int i = 0; i < stateSize; i++) {
164 int32_t state = data.ReadInt32();
165 states.push_back(state);
166 }
167
168 std::vector<RawAddress> rawAdds = GetDevicesByStates(states);
169 reply.WriteInt32(rawAdds.size());
170
171 for (auto rawAdd : rawAdds) {
172 if (!reply.WriteString(rawAdd.GetAddress())) {
173 HILOGE("GetConnectedDevicesInner: write WriteString failed");
174 return ERR_INVALID_STATE;
175 }
176 }
177 return NO_ERROR;
178 }
179
GetDeviceStateInner(MessageParcel & data,MessageParcel & reply)180 ErrCode BluetoothAvrcpCtStub::GetDeviceStateInner(MessageParcel &data, MessageParcel &reply)
181 {
182 int32_t state = GetDeviceState(RawAddress(data.ReadString()));
183 reply.WriteInt32(state);
184
185 return NO_ERROR;
186 }
187
ConnectInner(MessageParcel & data,MessageParcel & reply)188 ErrCode BluetoothAvrcpCtStub::ConnectInner(MessageParcel &data, MessageParcel &reply)
189 {
190 int32_t result = Connect(RawAddress(data.ReadString()));
191 reply.WriteInt32(result);
192
193 return NO_ERROR;
194 }
195
DisconnectInner(MessageParcel & data,MessageParcel & reply)196 ErrCode BluetoothAvrcpCtStub::DisconnectInner(MessageParcel &data, MessageParcel &reply)
197 {
198 int32_t result = Disconnect(RawAddress(data.ReadString()));
199 reply.WriteInt32(result);
200
201 return NO_ERROR;
202 }
203
PressButtonnner(MessageParcel & data,MessageParcel & reply)204 ErrCode BluetoothAvrcpCtStub::PressButtonnner(MessageParcel &data, MessageParcel &reply)
205 {
206 int32_t result = PressButton(RawAddress(data.ReadString()), data.ReadInt32());
207 reply.WriteInt32(result);
208
209 return NO_ERROR;
210 }
211
ReleaseButtonInner(MessageParcel & data,MessageParcel & reply)212 ErrCode BluetoothAvrcpCtStub::ReleaseButtonInner(MessageParcel &data, MessageParcel &reply)
213 {
214 int32_t result = ReleaseButton(RawAddress(data.ReadString()), data.ReadInt32());
215 reply.WriteInt32(result);
216
217 return NO_ERROR;
218 }
219
GetUnitInfoInner(MessageParcel & data,MessageParcel & reply)220 ErrCode BluetoothAvrcpCtStub::GetUnitInfoInner(MessageParcel &data, MessageParcel &reply)
221 {
222 int32_t result = GetUnitInfo(RawAddress(data.ReadString()));
223 reply.WriteInt32(result);
224
225 return NO_ERROR;
226 }
227
GetSubUnitInfoInner(MessageParcel & data,MessageParcel & reply)228 ErrCode BluetoothAvrcpCtStub::GetSubUnitInfoInner(MessageParcel &data, MessageParcel &reply)
229 {
230 int32_t result = GetSubUnitInfo(RawAddress(data.ReadString()));
231 reply.WriteInt32(result);
232
233 return NO_ERROR;
234 }
235
GetSupportedCompaniesInner(MessageParcel & data,MessageParcel & reply)236 ErrCode BluetoothAvrcpCtStub::GetSupportedCompaniesInner(MessageParcel &data, MessageParcel &reply)
237 {
238 int32_t result = GetSupportedCompanies(RawAddress(data.ReadString()));
239 reply.WriteInt32(result);
240
241 return NO_ERROR;
242 }
243
GetSupportedEventsInner(MessageParcel & data,MessageParcel & reply)244 ErrCode BluetoothAvrcpCtStub::GetSupportedEventsInner(MessageParcel &data, MessageParcel &reply)
245 {
246 int32_t result = GetSupportedEvents(RawAddress(data.ReadString()));
247 reply.WriteInt32(result);
248
249 return NO_ERROR;
250 }
251
GetPlayerAppSettingAttributesInner(MessageParcel & data,MessageParcel & reply)252 ErrCode BluetoothAvrcpCtStub::GetPlayerAppSettingAttributesInner(MessageParcel &data, MessageParcel &reply)
253 {
254 int32_t result = GetPlayerAppSettingAttributes(RawAddress(data.ReadString()));
255 reply.WriteInt32(result);
256
257 return NO_ERROR;
258 }
259
GetPlayerAppSettingValuesInner(MessageParcel & data,MessageParcel & reply)260 ErrCode BluetoothAvrcpCtStub::GetPlayerAppSettingValuesInner(MessageParcel &data, MessageParcel &reply)
261 {
262 int32_t result = GetPlayerAppSettingValues(RawAddress(data.ReadString()), data.ReadInt32());
263 reply.WriteInt32(result);
264
265 return NO_ERROR;
266 }
267
GetPlayerAppSettingCurrentValueInner(MessageParcel & data,MessageParcel & reply)268 ErrCode BluetoothAvrcpCtStub::GetPlayerAppSettingCurrentValueInner(MessageParcel &data, MessageParcel &reply)
269 {
270 RawAddress raw = RawAddress(data.ReadString());
271 std::vector<int32_t> attributes = {};
272 int32_t attributesSize = data.ReadInt32();
273 if (IsInvalidAttributesSize(attributesSize)) {
274 HILOGE("BluetoothAvrcpCtStub::GetPlayerAppSettingCurrentValueInner Invalid MessageParcel attributes");
275 return ERR_INVALID_VALUE;
276 }
277 for (int i = 0; i < attributesSize; i++) {
278 int32_t attribute = data.ReadInt32();
279 attributes.push_back(attribute);
280 }
281 int32_t result = GetPlayerAppSettingCurrentValue(raw, attributes);
282 reply.WriteInt32(result);
283
284 return NO_ERROR;
285 }
286
SetPlayerAppSettingCurrentValueInner(MessageParcel & data,MessageParcel & reply)287 ErrCode BluetoothAvrcpCtStub::SetPlayerAppSettingCurrentValueInner(MessageParcel &data, MessageParcel &reply)
288 {
289 RawAddress raw = RawAddress(data.ReadString());
290 std::vector<int32_t> attributes = {};
291 int32_t attributesSize = data.ReadInt32();
292 if (IsInvalidAttributesSize(attributesSize)) {
293 HILOGE("BluetoothAvrcpCtStub::SetPlayerAppSettingCurrentValueInner Invalid MessageParcel attributes");
294 return ERR_INVALID_VALUE;
295 }
296 for (int i = 0; i < attributesSize; i++) {
297 int32_t attribute = data.ReadInt32();
298 attributes.push_back(attribute);
299 }
300
301 std::vector<int32_t> values = {};
302 int32_t valuesSize = data.ReadInt32();
303 if (IsInvalidAttributesSize(valuesSize)) {
304 HILOGE("BluetoothAvrcpCtStub::SetPlayerAppSettingCurrentValueInner Invalid MessageParcel values");
305 return ERR_INVALID_VALUE;
306 }
307 for (int i = 0; i < valuesSize; i++) {
308 int32_t value = data.ReadInt32();
309 values.push_back(value);
310 }
311
312 int32_t result = SetPlayerAppSettingCurrentValue(raw, attributes, values);
313 reply.WriteInt32(result);
314
315 return NO_ERROR;
316 }
317
GetPlayerAppSettingAttributeTextInner(MessageParcel & data,MessageParcel & reply)318 ErrCode BluetoothAvrcpCtStub::GetPlayerAppSettingAttributeTextInner(MessageParcel &data, MessageParcel &reply)
319 {
320 RawAddress raw = RawAddress(data.ReadString());
321 std::vector<int32_t> attributes = {};
322 int32_t attributesSize = data.ReadInt32();
323 if (IsInvalidAttributesSize(attributesSize)) {
324 HILOGE("BluetoothAvrcpCtStub::GetPlayerAppSettingAttributeTextInner Invalid MessageParcel attributes");
325 return ERR_INVALID_VALUE;
326 }
327 for (int i = 0; i < attributesSize; i++) {
328 int32_t attribute = data.ReadInt32();
329 attributes.push_back(attribute);
330 }
331 int32_t result = GetPlayerAppSettingAttributeText(raw, attributes);
332 reply.WriteInt32(result);
333
334 return NO_ERROR;
335 }
336
GetPlayerAppSettingValueTextInner(MessageParcel & data,MessageParcel & reply)337 ErrCode BluetoothAvrcpCtStub::GetPlayerAppSettingValueTextInner(MessageParcel &data, MessageParcel &reply)
338 {
339 RawAddress raw = RawAddress(data.ReadString());
340 int32_t attributes = data.ReadInt32();
341 std::vector<int32_t> values = {};
342 int32_t valuesSize = data.ReadInt32();
343 if (IsInvalidAttributesSize(valuesSize)) {
344 HILOGE("BluetoothAvrcpCtStub::GetPlayerAppSettingValueTextInner Invalid MessageParcel values");
345 return ERR_INVALID_VALUE;
346 }
347 for (int i = 0; i < valuesSize; i++) {
348 int32_t value = data.ReadInt32();
349 values.push_back(value);
350 }
351
352 int32_t result = GetPlayerAppSettingValueText(raw, attributes, values);
353 reply.WriteInt32(result);
354
355 return NO_ERROR;
356 }
357
GetElementAttributesInner(MessageParcel & data,MessageParcel & reply)358 ErrCode BluetoothAvrcpCtStub::GetElementAttributesInner(MessageParcel &data, MessageParcel &reply)
359 {
360 RawAddress raw = RawAddress(data.ReadString());
361 std::vector<int32_t> attributes = {};
362 int32_t attributesSize = data.ReadInt32();
363 if (IsInvalidAttributesSize(attributesSize)) {
364 HILOGE("BluetoothAvrcpCtStub::GetElementAttributesInner Invalid MessageParcel attributes");
365 return ERR_INVALID_VALUE;
366 }
367 for (int i = 0; i < attributesSize; i++) {
368 int32_t attribute = data.ReadInt32();
369 attributes.push_back(attribute);
370 }
371 int32_t result = GetElementAttributes(raw, attributes);
372 reply.WriteInt32(result);
373
374 return NO_ERROR;
375 }
376
GetPlayStatusInner(MessageParcel & data,MessageParcel & reply)377 ErrCode BluetoothAvrcpCtStub::GetPlayStatusInner(MessageParcel &data, MessageParcel &reply)
378 {
379 RawAddress raw = RawAddress(data.ReadString());
380 int32_t result = GetPlayStatus(raw);
381 reply.WriteInt32(result);
382
383 return NO_ERROR;
384 }
385
PlayItemInner(MessageParcel & data,MessageParcel & reply)386 ErrCode BluetoothAvrcpCtStub::PlayItemInner(MessageParcel &data, MessageParcel &reply)
387 {
388 RawAddress raw = RawAddress(data.ReadString());
389 int32_t result = PlayItem(raw, data.ReadInt32(), data.ReadInt64(), data.ReadInt32());
390 reply.WriteInt32(result);
391
392 return NO_ERROR;
393 }
394
GetFolderItemsInner(MessageParcel & data,MessageParcel & reply)395 ErrCode BluetoothAvrcpCtStub::GetFolderItemsInner(MessageParcel &data, MessageParcel &reply)
396 {
397 RawAddress raw = RawAddress(data.ReadString());
398 int32_t startItem = data.ReadInt32();
399 int32_t endItem = data.ReadInt32();
400 std::vector<int32_t> attributes = {};
401 int32_t attributesSize = data.ReadInt32();
402 if (IsInvalidAttributesSize(attributesSize)) {
403 HILOGE("BluetoothAvrcpCtStub::GetFolderItemsInner Invalid MessageParcel attributes");
404 return ERR_INVALID_VALUE;
405 }
406 for (int i = 0; i < attributesSize; i++) {
407 int32_t attribute = data.ReadInt32();
408 attributes.push_back(attribute);
409 }
410
411 int32_t result = GetFolderItems(raw, startItem, endItem, attributes);
412 reply.WriteInt32(result);
413
414 return NO_ERROR;
415 }
416
GetTotalNumberOfItemsInner(MessageParcel & data,MessageParcel & reply)417 ErrCode BluetoothAvrcpCtStub::GetTotalNumberOfItemsInner(MessageParcel &data, MessageParcel &reply)
418 {
419 RawAddress raw = RawAddress(data.ReadString());
420 int32_t scope = data.ReadInt32();
421 int32_t result = GetTotalNumberOfItems(raw, scope);
422 reply.WriteInt32(result);
423
424 return NO_ERROR;
425 }
426
SetAbsoluteVolumeInner(MessageParcel & data,MessageParcel & reply)427 ErrCode BluetoothAvrcpCtStub::SetAbsoluteVolumeInner(MessageParcel &data, MessageParcel &reply)
428 {
429 RawAddress raw = RawAddress(data.ReadString());
430 int32_t volume = data.ReadInt32();
431 int32_t result = SetAbsoluteVolume(raw, volume);
432 reply.WriteInt32(result);
433
434 return NO_ERROR;
435 }
436
EnableNotificationInner(MessageParcel & data,MessageParcel & reply)437 ErrCode BluetoothAvrcpCtStub::EnableNotificationInner(MessageParcel &data, MessageParcel &reply)
438 {
439 RawAddress raw = RawAddress(data.ReadString());
440 std::vector<int32_t> events = {};
441 int32_t attributesSize = data.ReadInt32();
442 if (static_cast<uint32_t>(attributesSize) > AVRCP_NOTIDICATION_EVENT_COUNT_MAX) {
443 return ERR_INVALID_STATE;
444 }
445 for (int i = 0; i < attributesSize; i++) {
446 int32_t attribute = data.ReadInt32();
447 events.push_back(attribute);
448 }
449 int32_t interval = data.ReadInt32();
450 int32_t result = EnableNotification(raw, events, interval);
451 reply.WriteInt32(result);
452
453 return NO_ERROR;
454 }
455
DisableNotificationInner(MessageParcel & data,MessageParcel & reply)456 ErrCode BluetoothAvrcpCtStub::DisableNotificationInner(MessageParcel &data, MessageParcel &reply)
457 {
458 RawAddress raw = RawAddress(data.ReadString());
459 std::vector<int32_t> events = {};
460 int32_t attributesSize = data.ReadInt32();
461 if (static_cast<uint32_t>(attributesSize) > AVRCP_NOTIDICATION_EVENT_COUNT_MAX) {
462 return ERR_INVALID_STATE;
463 }
464 for (int i = 0; i < attributesSize; i++) {
465 int32_t attribute = data.ReadInt32();
466 events.push_back(attribute);
467 }
468 int32_t result = DisableNotification(raw, events);
469 reply.WriteInt32(result);
470
471 return NO_ERROR;
472 }
473
GetItemAttributesInner(MessageParcel & data,MessageParcel & reply)474 ErrCode BluetoothAvrcpCtStub::GetItemAttributesInner(MessageParcel &data, MessageParcel &reply)
475 {
476 RawAddress raw = RawAddress(data.ReadString());
477 int64_t uid = data.ReadInt64();
478 int32_t uidCounter = data.ReadInt32();
479 std::vector<int32_t> events = {};
480 int32_t attributesSize = data.ReadInt32();
481 if (static_cast<uint32_t>(attributesSize) > AVRCP_PLAYER_APP_SETTING_ATTRIBUTES_NUM_MAX) {
482 return ERR_INVALID_STATE;
483 }
484 for (int i = 0; i < attributesSize; i++) {
485 int32_t attribute = data.ReadInt32();
486 events.push_back(attribute);
487 }
488 int32_t result = GetItemAttributes(raw, uid, uidCounter, events);
489 reply.WriteInt32(result);
490
491 return NO_ERROR;
492 }
493
SetBrowsedPlayerInner(MessageParcel & data,MessageParcel & reply)494 ErrCode BluetoothAvrcpCtStub::SetBrowsedPlayerInner(MessageParcel &data, MessageParcel &reply)
495 {
496 RawAddress raw = RawAddress(data.ReadString());
497 int32_t playerId = data.ReadInt32();
498
499 int32_t result = SetBrowsedPlayer(raw, playerId);
500 reply.WriteInt32(result);
501
502 return NO_ERROR;
503
504 }
505
GetMeidaPlayerListInner(MessageParcel & data,MessageParcel & reply)506 ErrCode BluetoothAvrcpCtStub::GetMeidaPlayerListInner(MessageParcel &data, MessageParcel &reply)
507 {
508 RawAddress raw = RawAddress(data.ReadString());
509 int32_t startItem = data.ReadInt32();
510 int32_t endItem = data.ReadInt32();
511
512 int32_t result = GetMeidaPlayerList(raw, startItem, endItem);
513 reply.WriteInt32(result);
514
515 return NO_ERROR;
516 }
517
IsInvalidAttributesSize(int32_t attributesSize)518 bool BluetoothAvrcpCtStub::IsInvalidAttributesSize(int32_t attributesSize)
519 {
520 bool ret = false;
521 const int32_t COUNT_OF_AVRC_PLAYER_ATTRIBUTE = 255;
522 if (attributesSize > COUNT_OF_AVRC_PLAYER_ATTRIBUTE) {
523 ret = true;
524 }
525 return ret;
526 }
527
IsInvalidDeviceStatesSize(int32_t statesSize)528 bool BluetoothAvrcpCtStub::IsInvalidDeviceStatesSize(int32_t statesSize)
529 {
530 bool ret = false;
531 const int32_t COUNT_OF_DEVICE_STATE = 4;
532 if (statesSize > COUNT_OF_DEVICE_STATE) {
533 ret = true;
534 }
535 return ret;
536 }
537 } // namespace Bluetooth
538 } // namespace OHOS
539