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 <deque>
17 #include <list>
18 #include <mutex>
19
20 #include "bluetooth_avrcp_ct.h"
21
22 #include "bluetooth_avrcp_ct_stub.h"
23 #include "bluetooth_avrcp_ct_observer_stub.h"
24 #include "bluetooth_def.h"
25 #include "bluetooth_host.h"
26 #include "bluetooth_log.h"
27 #include "bluetooth_observer_list.h"
28 #include "i_bluetooth_avrcp_ct.h"
29 #include "iservice_registry.h"
30 #include "system_ability_definition.h"
31
32 namespace OHOS {
33 namespace Bluetooth {
34 using namespace bluetooth;
35
AvrcpCtResponse(uint8_t type,int resp)36 AvrcpCtResponse::AvrcpCtResponse(uint8_t type, int resp) : type_(type), resp_(resp)
37 {
38 HILOGD("%{public}s start.", __func__);
39 }
40
~AvrcpCtResponse()41 AvrcpCtResponse::~AvrcpCtResponse()
42 {
43 HILOGD("%{public}s start.", __func__);
44 }
45
46 struct AvrcpController::impl {
47 public:
48 class ObserverImpl : public BluetoothAvrcpCtObserverStub {
49 public:
ObserverImpl(AvrcpController::impl * impl)50 explicit ObserverImpl(AvrcpController::impl *impl) : impl_(impl)
51 {}
52 ~ObserverImpl() override = default;
53
OnConnectionStateChanged(const RawAddress & rawAddr,int state)54 void OnConnectionStateChanged(const RawAddress &rawAddr, int state) override
55 {
56 HILOGD("%{public}s start.", __func__);
57
58 BluetoothRemoteDevice device(rawAddr.GetAddress(), BTTransport::ADAPTER_BREDR);
59 impl_->OnConnectionStateChanged(device, static_cast<int>(state));
60
61 return;
62 }
63
OnPressButton(const RawAddress & rawAddr,uint8_t button,int result)64 void OnPressButton(const RawAddress &rawAddr, uint8_t button, int result) override
65 {
66 HILOGD("%{public}s start.", __func__);
67
68 BluetoothRemoteDevice device(rawAddr.GetAddress(), BTTransport::ADAPTER_BREDR);
69 impl_->OnPressButton(device, static_cast<uint8_t>(button), static_cast<int>(result));
70
71 return;
72 }
73
OnReleaseButton(const RawAddress & rawAddr,uint8_t button,int result)74 void OnReleaseButton(const RawAddress &rawAddr, uint8_t button, int result) override
75 {
76 HILOGD("%{public}s start.", __func__);
77
78 BluetoothRemoteDevice device(rawAddr.GetAddress(), BTTransport::ADAPTER_BREDR);
79 impl_->OnReleaseButton(device, static_cast<uint8_t>(button), static_cast<int>(result));
80
81 return;
82 }
83
OnSetBrowsedPlayer(const RawAddress & rawAddr,uint16_t uidCounter,uint32_t numberOfItems,const std::vector<std::string> & folderNames,int result,int detail)84 void OnSetBrowsedPlayer(const RawAddress &rawAddr, uint16_t uidCounter,
85 uint32_t numberOfItems, const std::vector<std::string> &folderNames, int result, int detail) override
86 {
87 HILOGD("%{public}s start.", __func__);
88
89 BluetoothRemoteDevice device(rawAddr.GetAddress(), BTTransport::ADAPTER_BREDR);
90
91 impl_->OnSetBrowsedPlayer(device,
92 static_cast<uint16_t>(uidCounter),
93 static_cast<uint32_t>(numberOfItems),
94 folderNames,
95 result,
96 detail);
97 return;
98 }
99
OnGetCapabilities(const RawAddress & rawAddr,const std::vector<uint32_t> & companies,const std::vector<uint8_t> & events,int result)100 void OnGetCapabilities(const RawAddress &rawAddr, const std::vector<uint32_t> &companies,
101 const std::vector<uint8_t> &events, int result) override
102 {
103 HILOGD("%{public}s start.", __func__);
104
105 BluetoothRemoteDevice device(rawAddr.GetAddress(), BTTransport::ADAPTER_BREDR);
106 impl_->OnGetCapabilities(device, companies, events, result);
107
108 return;
109 }
110
OnGetPlayerAppSettingAttributes(const RawAddress & rawAddr,std::vector<uint8_t> attributes,int result)111 void OnGetPlayerAppSettingAttributes(
112 const RawAddress &rawAddr, std::vector<uint8_t> attributes, int result) override
113 {
114 HILOGD("%{public}s start.", __func__);
115
116 BluetoothRemoteDevice device(rawAddr.GetAddress(), BTTransport::ADAPTER_BREDR);
117
118 impl_->OnGetPlayerAppSettingAttributes(device, attributes, static_cast<int>(result));
119
120 return;
121 }
122
OnGetPlayerAppSettingValues(const RawAddress & rawAddr,int attribute,const std::vector<uint8_t> & values,int result)123 void OnGetPlayerAppSettingValues(const RawAddress &rawAddr,
124 int attribute, const std::vector<uint8_t> &values, int result) override
125 {
126 HILOGD("%{public}s start.", __func__);
127
128 BluetoothRemoteDevice device(rawAddr.GetAddress(), BTTransport::ADAPTER_BREDR);
129
130 impl_->OnGetPlayerAppSettingValues(
131 device, static_cast<uint8_t>(attribute), values, static_cast<int>(result));
132
133 return;
134 }
135
OnGetPlayerAppSettingCurrentValue(const RawAddress & rawAddr,const std::vector<uint8_t> attributes,const std::vector<uint8_t> & values,int result)136 void OnGetPlayerAppSettingCurrentValue(const RawAddress &rawAddr, const std::vector<uint8_t> attributes,
137 const std::vector<uint8_t> &values, int result) override
138 {
139 HILOGD("%{public}s start.", __func__);
140
141 BluetoothRemoteDevice device(rawAddr.GetAddress(), BTTransport::ADAPTER_BREDR);
142
143 impl_->OnGetPlayerAppSettingCurrentValue(device, attributes, values, static_cast<int>(result));
144
145 return;
146 }
147
OnSetPlayerAppSettingCurrentValue(const RawAddress & rawAddr,int result)148 void OnSetPlayerAppSettingCurrentValue(const RawAddress &rawAddr, int result) override
149 {
150 HILOGD("%{public}s start.", __func__);
151
152 BluetoothRemoteDevice device(rawAddr.GetAddress(), BTTransport::ADAPTER_BREDR);
153
154 impl_->OnSetPlayerAppSettingCurrentValue(device, static_cast<int>(result));
155
156 return;
157 }
158
OnGetPlayerAppSettingAttributeText(const RawAddress & rawAddr,const std::vector<uint8_t> attribtues,const std::vector<std::string> & attributeName,int result)159 void OnGetPlayerAppSettingAttributeText(const RawAddress &rawAddr,
160 const std::vector<uint8_t> attribtues, const std::vector<std::string> &attributeName, int result) override
161 {
162 HILOGD("%{public}s start.", __func__);
163
164 BluetoothRemoteDevice device(rawAddr.GetAddress(), BTTransport::ADAPTER_BREDR);
165
166 impl_->OnGetPlayerAppSettingAttributeText(device, attribtues, attributeName, static_cast<int>(result));
167
168 return;
169 }
170
OnGetPlayerAppSettingValueText(const RawAddress & rawAddr,const std::vector<uint8_t> & values,const std::vector<std::string> & valueName,int result)171 void OnGetPlayerAppSettingValueText(const RawAddress &rawAddr,
172 const std::vector<uint8_t> &values, const std::vector<std::string> &valueName, int result) override
173 {
174 HILOGD("%{public}s start.", __func__);
175
176 BluetoothRemoteDevice device(rawAddr.GetAddress(), BTTransport::ADAPTER_BREDR);
177
178 impl_->OnGetPlayerAppSettingValueText(device, values, valueName, static_cast<int>(result));
179
180 return;
181 }
182
OnGetElementAttributes(const RawAddress & rawAddr,const std::vector<uint32_t> & attribtues,const std::vector<std::string> & valueName,int result)183 void OnGetElementAttributes(const RawAddress &rawAddr,
184 const std::vector<uint32_t> &attribtues, const std::vector<std::string> &valueName, int result) override
185 {
186 HILOGD("%{public}s start.", __func__);
187
188 BluetoothRemoteDevice device(rawAddr.GetAddress(), BTTransport::ADAPTER_BREDR);
189
190 impl_->OnGetElementAttributes(device, attribtues, valueName, static_cast<int>(result));
191
192 return;
193 }
194
OnGetPlayStatus(const RawAddress & rawAddr,uint32_t songLength,uint32_t songPosition,uint8_t playStatus,int result)195 void OnGetPlayStatus(const RawAddress &rawAddr,
196 uint32_t songLength, uint32_t songPosition, uint8_t playStatus, int result) override
197 {
198 HILOGD("%{public}s start.", __func__);
199
200 BluetoothRemoteDevice device(rawAddr.GetAddress(), BTTransport::ADAPTER_BREDR);
201 impl_->OnGetPlayStatus(device,
202 static_cast<uint32_t>(songLength),
203 static_cast<uint32_t>(songPosition),
204 static_cast<uint8_t>(playStatus),
205 static_cast<int>(result));
206
207 return;
208 }
209
OnPlayItem(const RawAddress & rawAddr,int status,int result)210 void OnPlayItem(const RawAddress &rawAddr, int status, int result) override
211 {
212 HILOGD("%{public}s start.", __func__);
213
214 BluetoothRemoteDevice device(rawAddr.GetAddress(), BTTransport::ADAPTER_BREDR);
215 impl_->OnPlayItem(device, static_cast<int>(status), static_cast<int>(result));
216
217 return;
218 }
219
OnGetMediaPlayers(const RawAddress & rawAddr,uint16_t uidCounter,std::vector<BluetoothAvrcpMpItem> & items,int result,int detail)220 void OnGetMediaPlayers(const RawAddress &rawAddr, uint16_t uidCounter,
221 std::vector<BluetoothAvrcpMpItem> &items, int result, int detail) override
222 {
223 HILOGD("%{public}s start.", __func__);
224
225 BluetoothRemoteDevice device(rawAddr.GetAddress(), BTTransport::ADAPTER_BREDR);
226 std::vector<AvrcMpItem> myItems;
227 for (size_t i = 0; i < items.size(); i++) {
228 AvrcMpItem myItem;
229 myItem.itemType_ = items.at(i).itemType_;
230 myItem.playerId_ = items.at(i).playerId_;
231 myItem.majorType_ = items.at(i).majorType_;
232 myItem.subType_ = items.at(i).subType_;
233 myItem.playStatus_ = items.at(i).playStatus_;
234 myItem.features_ = items.at(i).features_;
235 myItem.name_ = items.at(i).name_;
236 myItems.push_back(myItem);
237 }
238
239 impl_->OnGetMediaPlayers(
240 device, static_cast<uint32_t>(uidCounter), myItems, static_cast<int>(result), static_cast<int>(detail));
241
242 return;
243 }
244
OnGetFolderItems(const RawAddress & rawAddr,uint16_t uidCounter,std::vector<BluetoothAvrcpMeItem> & items,int result,int detail)245 void OnGetFolderItems(const RawAddress &rawAddr, uint16_t uidCounter, std::vector<BluetoothAvrcpMeItem> &items,
246 int result, int detail) override
247 {
248 BluetoothRemoteDevice device(rawAddr.GetAddress(), BTTransport::ADAPTER_BREDR);
249 std::vector<AvrcMeItem> myItems;
250 for (size_t i = 0; i < items.size(); i++) {
251 AvrcMeItem myItem;
252 myItem.uid_ = items.at(i).uid_;
253 myItem.type_ = items.at(i).type_;
254 myItem.playable_ = items.at(i).playable_;
255 myItem.name_ = items.at(i).name_;
256 myItem.attributes_ = items.at(i).attributes_;
257 myItem.values_ = items.at(i).values_;
258
259 myItems.push_back(myItem);
260 }
261 impl_->OnGetFolderItems(
262 device, static_cast<uint32_t>(uidCounter), myItems, static_cast<int>(result), static_cast<int>(detail));
263
264 return;
265 }
266
OnGetItemAttributes(const RawAddress & rawAddr,const std::vector<uint32_t> & attribtues,const std::vector<std::string> & values,int result,int detail)267 void OnGetItemAttributes(const RawAddress &rawAddr, const std::vector<uint32_t> &attribtues,
268 const std::vector<std::string> &values, int result, int detail) override
269 {
270 HILOGD("%{public}s start.", __func__);
271
272 BluetoothRemoteDevice device(rawAddr.GetAddress(), BTTransport::ADAPTER_BREDR);
273
274 impl_->OnGetItemAttributes(device, attribtues, values, static_cast<int>(result), static_cast<int>(detail));
275
276 return;
277 }
278
OnGetTotalNumberOfItems(const RawAddress & rawAddr,uint16_t uidCounter,uint32_t numOfItems,int result,int detail)279 void OnGetTotalNumberOfItems(const RawAddress &rawAddr, uint16_t uidCounter, uint32_t numOfItems,
280 int result, int detail) override
281 {
282 HILOGD("%{public}s start.", __func__);
283
284 BluetoothRemoteDevice device(rawAddr.GetAddress(), BTTransport::ADAPTER_BREDR);
285 impl_->OnGetTotalNumberOfItems(device,
286 static_cast<uint32_t>(uidCounter),
287 static_cast<uint32_t>(numOfItems),
288 static_cast<uint8_t>(result),
289 static_cast<int>(detail));
290
291 return;
292 }
293
OnSetAbsoluteVolume(const RawAddress & rawAddr,uint8_t volume,int result)294 void OnSetAbsoluteVolume(const RawAddress &rawAddr, uint8_t volume, int result) override
295 {
296 HILOGD("%{public}s start.", __func__);
297
298 BluetoothRemoteDevice device(rawAddr.GetAddress(), BTTransport::ADAPTER_BREDR);
299 impl_->OnSetAbsoluteVolume(device, static_cast<uint8_t>(volume), result);
300
301 return;
302 }
303
OnPlaybackStatusChanged(const RawAddress & rawAddr,uint8_t playStatus,int result)304 void OnPlaybackStatusChanged(const RawAddress &rawAddr, uint8_t playStatus, int result) override
305 {
306 HILOGD("%{public}s start.", __func__);
307
308 BluetoothRemoteDevice device(rawAddr.GetAddress(), BTTransport::ADAPTER_BREDR);
309 impl_->OnPlaybackStatusChanged(device, static_cast<uint8_t>(playStatus), static_cast<int>(result));
310
311 return;
312 }
313
OnTrackChanged(const RawAddress & rawAddr,uint64_t uid,int result)314 void OnTrackChanged(const RawAddress &rawAddr, uint64_t uid, int result) override
315 {
316 HILOGD("%{public}s start.", __func__);
317
318 BluetoothRemoteDevice device(rawAddr.GetAddress(), BTTransport::ADAPTER_BREDR);
319 impl_->OnTrackChanged(device, static_cast<uint64_t>(uid), static_cast<int>(result));
320
321 return;
322 }
323
OnTrackReachedEnd(const RawAddress & rawAddr,int result)324 void OnTrackReachedEnd(const RawAddress &rawAddr, int result) override
325 {
326 HILOGD("%{public}s start.", __func__);
327
328 BluetoothRemoteDevice device(rawAddr.GetAddress(), BTTransport::ADAPTER_BREDR);
329 impl_->OnTrackReachedEnd(device, static_cast<int>(result));
330
331 return;
332 }
333
OnTrackReachedStart(const RawAddress & rawAddr,int result)334 void OnTrackReachedStart(const RawAddress &rawAddr, int result) override
335 {
336 HILOGD("%{public}s start.", __func__);
337
338 BluetoothRemoteDevice device(rawAddr.GetAddress(), BTTransport::ADAPTER_BREDR);
339 impl_->OnTrackReachedStart(device, static_cast<int>(result));
340
341 return;
342 }
343
OnPlaybackPosChanged(const RawAddress & rawAddr,uint32_t playbackPos,int result)344 void OnPlaybackPosChanged(const RawAddress &rawAddr, uint32_t playbackPos, int result) override
345 {
346 HILOGD("%{public}s start.", __func__);
347
348 BluetoothRemoteDevice device(rawAddr.GetAddress(), BTTransport::ADAPTER_BREDR);
349 impl_->OnPlaybackPosChanged(device, static_cast<uint32_t>(playbackPos), static_cast<int>(result));
350
351 return;
352 }
353
OnPlayerAppSettingChanged(const RawAddress & rawAddr,const std::vector<uint8_t> & attributes,const std::vector<uint8_t> & values,int result)354 void OnPlayerAppSettingChanged(const RawAddress &rawAddr, const std::vector<uint8_t> &attributes,
355 const std::vector<uint8_t> &values, int result) override
356 {
357 HILOGD("%{public}s start.", __func__);
358
359 BluetoothRemoteDevice device(rawAddr.GetAddress(), BTTransport::ADAPTER_BREDR);
360 impl_->OnPlayerAppSettingChanged(device, attributes, values, static_cast<int>(result));
361
362 return;
363 }
364
OnNowPlayingContentChanged(const RawAddress & rawAddr,int result)365 void OnNowPlayingContentChanged(const RawAddress &rawAddr, int result) override
366 {
367 HILOGD("%{public}s start.", __func__);
368
369 BluetoothRemoteDevice device(rawAddr.GetAddress(), BTTransport::ADAPTER_BREDR);
370 impl_->OnNowPlayingContentChanged(device, static_cast<int>(result));
371
372 return;
373 }
374
OnAvailablePlayersChanged(const RawAddress & rawAddr,int result)375 void OnAvailablePlayersChanged(const RawAddress &rawAddr, int result) override
376 {
377 HILOGD("%{public}s start.", __func__);
378
379 BluetoothRemoteDevice device(rawAddr.GetAddress(), BTTransport::ADAPTER_BREDR);
380 impl_->OnAvailablePlayersChanged(device, static_cast<int>(result));
381
382 return;
383 }
384
OnAddressedPlayerChanged(const RawAddress & rawAddr,uint16_t playerId,uint16_t uidCounter,int result)385 void OnAddressedPlayerChanged(
386 const RawAddress &rawAddr, uint16_t playerId, uint16_t uidCounter, int result) override
387 {
388 HILOGD("%{public}s start.", __func__);
389
390 BluetoothRemoteDevice device(rawAddr.GetAddress(), BTTransport::ADAPTER_BREDR);
391 impl_->OnAddressedPlayerChanged(
392 device, static_cast<uint16_t>(playerId), static_cast<uint16_t>(uidCounter), static_cast<int>(result));
393
394 return;
395 }
396
OnUidChanged(const RawAddress & rawAddr,uint16_t uidCounter,int result)397 void OnUidChanged(const RawAddress &rawAddr, uint16_t uidCounter, int result) override
398 {
399 HILOGD("%{public}s start.", __func__);
400
401 BluetoothRemoteDevice device(rawAddr.GetAddress(), BTTransport::ADAPTER_BREDR);
402 impl_->OnUidChanged(device, static_cast<uint16_t>(uidCounter), static_cast<int>(result));
403
404 return;
405 }
406
OnVolumeChanged(const RawAddress & rawAddr,uint8_t volume,int result)407 void OnVolumeChanged(const RawAddress &rawAddr, uint8_t volume, int result) override
408 {
409 HILOGD("%{public}s start.", __func__);
410
411 BluetoothRemoteDevice device(rawAddr.GetAddress(), BTTransport::ADAPTER_BREDR);
412 impl_->OnVolumeChanged(device, static_cast<uint8_t>(volume), static_cast<int>(result));
413
414 return;
415 }
416
417 private:
418 AvrcpController::impl *impl_;
419 };
420
421 impl();
~implOHOS::Bluetooth::AvrcpController::impl422 ~impl()
423 {
424 HILOGD("%{public}s start.", __func__);
425 proxy_->UnregisterObserver(observer_);
426 }
427
IsEnabledOHOS::Bluetooth::AvrcpController::impl428 bool IsEnabled(void)
429 {
430 HILOGD("%{public}s start.", __func__);
431
432 return (proxy_ != nullptr && !BluetoothHost::GetDefaultHost().IsBtDiscovering());
433 }
434
OnConnectionStateChangedOHOS::Bluetooth::AvrcpController::impl435 void OnConnectionStateChanged(const BluetoothRemoteDevice &device, int state)
436 {
437 HILOGD("%{public}s start.", __func__);
438
439 std::lock_guard<std::mutex> lock(observerMutex_);
440
441 observers_.ForEach([device, state](std::shared_ptr<IObserver> observer) {
442 observer->OnConnectionStateChanged(device, state);
443 });
444 }
445
OnPressButtonOHOS::Bluetooth::AvrcpController::impl446 void OnPressButton(const BluetoothRemoteDevice &device, uint8_t button, int result)
447 {
448 HILOGD("%{public}s start.", __func__);
449
450 std::lock_guard<std::mutex> lock(observerMutex_);
451
452 observers_.ForEach([device, button, result](std::shared_ptr<IObserver> observer) {
453 AvrcpCtResponse resp(AVRC_ACTION_TYPE_PRESS_BUTTON, result);
454 resp.button_ = std::make_unique<AvrcpCtResponse::Button>(button);
455 observer->OnActionCompleted(device, resp);
456 });
457 }
458
OnReleaseButtonOHOS::Bluetooth::AvrcpController::impl459 void OnReleaseButton(const BluetoothRemoteDevice &device, uint8_t button, int result)
460 {
461 HILOGD("%{public}s start.", __func__);
462
463 std::lock_guard<std::mutex> lock(observerMutex_);
464
465 observers_.ForEach([device, button, result](std::shared_ptr<IObserver> observer) {
466 AvrcpCtResponse resp(AVRC_ACTION_TYPE_RELEASE_BUTTON, result);
467 resp.button_ = std::make_unique<AvrcpCtResponse::Button>(button);
468 observer->OnActionCompleted(device, resp);
469 });
470 }
471
OnSetBrowsedPlayerOHOS::Bluetooth::AvrcpController::impl472 void OnSetBrowsedPlayer(const BluetoothRemoteDevice &device, uint16_t uidCounter, uint32_t numOfItems,
473 const std::vector<std::string> &folderNames, int result, int detail)
474 {
475 HILOGD("%{public}s start.", __func__);
476
477 std::lock_guard<std::mutex> lock(observerMutex_);
478
479 observers_.ForEach([device, result](std::shared_ptr<IObserver> observer) {
480 AvrcpCtResponse resp(AVRC_ACTION_TYPE_SET_BROWSED_PLAYER, result);
481 observer->OnActionCompleted(device, resp);
482 });
483 }
484
OnGetCapabilitiesOHOS::Bluetooth::AvrcpController::impl485 void OnGetCapabilities(const BluetoothRemoteDevice &device, const std::vector<uint32_t> &companies,
486 const std::vector<uint8_t> &events, int result)
487 {
488 HILOGD("%{public}s start.", __func__);
489
490 std::lock_guard<std::mutex> lock(observerMutex_);
491
492 observers_.ForEach([device, companies, events, result](std::shared_ptr<IObserver> observer) {
493 AvrcpCtResponse resp(AVRC_ACTION_TYPE_GET_CAPABILITIES, result);
494 if (companies.size() == 0) {
495 resp.capabilities_ = std::make_unique<AvrcpCtResponse::Capabilities>(events);
496 } else {
497 resp.capabilities_ = std::make_unique<AvrcpCtResponse::Capabilities>(companies);
498 }
499
500 observer->OnActionCompleted(device, resp);
501 });
502 }
503
OnGetPlayerAppSettingAttributesOHOS::Bluetooth::AvrcpController::impl504 void OnGetPlayerAppSettingAttributes(
505 const BluetoothRemoteDevice &device, std::vector<uint8_t> attributes, int result)
506 {
507 HILOGD("%{public}s start.", __func__);
508
509 std::lock_guard<std::mutex> lock(observerMutex_);
510
511 observers_.ForEach([device, attributes, result](std::shared_ptr<IObserver> observer) {
512 AvrcpCtResponse resp(AVRC_ACTION_TYPE_GET_PLAYER_APP_SETTING_ATTRIBUTES, result);
513 resp.playerAttrs_ = std::make_unique<AvrcpCtResponse::PlayerSettingAttributes>(attributes);
514 observer->OnActionCompleted(device, resp);
515 });
516 }
517
OnGetPlayerAppSettingValuesOHOS::Bluetooth::AvrcpController::impl518 void OnGetPlayerAppSettingValues(
519 const BluetoothRemoteDevice &device, uint8_t attribute, std::vector<uint8_t> values, int result)
520 {
521 HILOGD("%{public}s start.", __func__);
522
523 std::lock_guard<std::mutex> lock(observerMutex_);
524
525 observers_.ForEach([device, attribute, values, result](std::shared_ptr<IObserver> observer) {
526 AvrcpCtResponse resp(AVRC_ACTION_TYPE_GET_PLAYER_APP_SETTING_VALUES, result);
527 resp.playerVals_ = std::make_unique<AvrcpCtResponse::PlayerSettingValues>(attribute, values);
528 observer->OnActionCompleted(device, resp);
529 });
530 }
531
OnGetPlayerAppSettingCurrentValueOHOS::Bluetooth::AvrcpController::impl532 void OnGetPlayerAppSettingCurrentValue(
533 const BluetoothRemoteDevice &device, std::vector<uint8_t> attributes, std::vector<uint8_t> values, int result)
534 {
535 HILOGD("%{public}s start.", __func__);
536
537 std::lock_guard<std::mutex> lock(observerMutex_);
538
539 observers_.ForEach([device, attributes, values, result](std::shared_ptr<IObserver> observer) {
540 AvrcpCtResponse resp(AVRC_ACTION_TYPE_GET_PLAYER_APP_SETTING_CURRENT_VALUE, result);
541 resp.playerCurVal_ = std::make_unique<AvrcpCtResponse::PlayerSettingCurrentValue>(attributes, values);
542 observer->OnActionCompleted(device, resp);
543 });
544 }
545
OnSetPlayerAppSettingCurrentValueOHOS::Bluetooth::AvrcpController::impl546 void OnSetPlayerAppSettingCurrentValue(const BluetoothRemoteDevice &device, int result)
547 {
548 HILOGD("%{public}s start.", __func__);
549
550 std::lock_guard<std::mutex> lock(observerMutex_);
551
552 observers_.ForEach([device, result](std::shared_ptr<IObserver> observer) {
553 AvrcpCtResponse resp(AVRC_ACTION_TYPE_SET_PLAYER_APP_SETTING_CURRENT_VALUE, result);
554 observer->OnActionCompleted(device, resp);
555 });
556 }
557
OnGetPlayerAppSettingAttributeTextOHOS::Bluetooth::AvrcpController::impl558 void OnGetPlayerAppSettingAttributeText(const BluetoothRemoteDevice &device, const std::vector<uint8_t> &attributes,
559 const std::vector<std::string> &valueName, int result)
560 {
561 HILOGD("%{public}s start.", __func__);
562
563 std::lock_guard<std::mutex> lock(observerMutex_);
564
565 observers_.ForEach([device, attributes, valueName, result](std::shared_ptr<IObserver> observer) {
566 AvrcpCtResponse resp(AVRC_ACTION_TYPE_GET_PLAYER_APP_SETTING_ATTRIBUTE_TEXT, result);
567 resp.playerText_ = std::make_unique<AvrcpCtResponse::PlayerGettingText>(attributes, valueName);
568 observer->OnActionCompleted(device, resp);
569 });
570 }
571
OnGetPlayerAppSettingValueTextOHOS::Bluetooth::AvrcpController::impl572 void OnGetPlayerAppSettingValueText(const BluetoothRemoteDevice &device, const std::vector<uint8_t> &values,
573 const std::vector<std::string> &valueName, int result)
574 {
575 HILOGD("%{public}s start.", __func__);
576
577 std::lock_guard<std::mutex> lock(observerMutex_);
578
579 observers_.ForEach([device, result, values, valueName](std::shared_ptr<IObserver> observer) {
580 AvrcpCtResponse resp(AVRC_ACTION_TYPE_GET_PLAYER_APP_SETTING_VALUE_TEXT, result);
581 resp.playerText_ = std::make_unique<AvrcpCtResponse::PlayerGettingText>(values, valueName);
582 observer->OnActionCompleted(device, resp);
583 });
584 }
585
OnGetElementAttributesOHOS::Bluetooth::AvrcpController::impl586 void OnGetElementAttributes(const BluetoothRemoteDevice &device, const std::vector<uint32_t> &attributes,
587 const std::vector<std::string> &valueName, int result)
588 {
589 HILOGD("%{public}s start.", __func__);
590
591 std::lock_guard<std::mutex> lock(observerMutex_);
592
593 observers_.ForEach([device, result, attributes, valueName](std::shared_ptr<IObserver> observer) {
594 AvrcpCtResponse resp(AVRC_ACTION_TYPE_GET_ELEMENT_ATTRIBUTES, result);
595 resp.eleSts_ = std::make_unique<AvrcpCtResponse::ElementAttributes>(attributes, valueName);
596 observer->OnActionCompleted(device, resp);
597 });
598 }
599
OnGetPlayStatusOHOS::Bluetooth::AvrcpController::impl600 void OnGetPlayStatus(
601 const BluetoothRemoteDevice &device, uint32_t songLength, uint32_t songPosition, uint8_t playStatus, int result)
602 {
603 HILOGD("%{public}s start.", __func__);
604
605 std::lock_guard<std::mutex> lock(observerMutex_);
606
607 observers_.ForEach([device, result](std::shared_ptr<IObserver> observer) {
608 AvrcpCtResponse resp(AVRC_ACTION_TYPE_GET_PLAY_STATUS, result);
609 observer->OnActionCompleted(device, resp);
610 });
611 }
612
OnPlayItemOHOS::Bluetooth::AvrcpController::impl613 void OnPlayItem(const BluetoothRemoteDevice &device, int result, int detail)
614 {
615 HILOGD("%{public}s start.", __func__);
616
617 std::lock_guard<std::mutex> lock(observerMutex_);
618
619 observers_.ForEach([device, result](std::shared_ptr<IObserver> observer) {
620 AvrcpCtResponse resp(AVRC_ACTION_TYPE_PLAY_ITEM, result);
621 observer->OnActionCompleted(device, resp);
622 });
623 }
624
OnGetMediaPlayersOHOS::Bluetooth::AvrcpController::impl625 void OnGetMediaPlayers(const BluetoothRemoteDevice &device, uint16_t uidCounter,
626 const std::vector<AvrcMpItem> &items, int result, int detail)
627 {
628 HILOGD("%{public}s start.", __func__);
629
630 std::vector<AvrcpCtResponse::MediaPlayers::MediaPlayer> MediaPlayers;
631 for (int i = 0; i < static_cast<int>(items.size()); i++) {
632 AvrcpCtResponse::MediaPlayers::MediaPlayer mediaPlayer;
633 mediaPlayer.itemType_ = items.at(i).itemType_;
634 mediaPlayer.playerId_ = items.at(i).playerId_;
635 mediaPlayer.majorType_ = items.at(i).majorType_;
636 mediaPlayer.subType_ = items.at(i).subType_;
637 mediaPlayer.playStatus_ = items.at(i).playStatus_;
638 mediaPlayer.features_ = items.at(i).features_;
639 mediaPlayer.name_ = items.at(i).name_;
640
641 MediaPlayers.push_back(mediaPlayer);
642 }
643
644 std::lock_guard<std::mutex> lock(observerMutex_);
645 observers_.ForEach([device, result, MediaPlayers, uidCounter](std::shared_ptr<IObserver> observer) {
646 AvrcpCtResponse resp(AVRC_ACTION_TYPE_GET_MEDIA_PLAYER_LIST, result);
647 resp.mediaPlayers_ = std::make_unique<AvrcpCtResponse::MediaPlayers>(uidCounter, MediaPlayers);
648 observer->OnActionCompleted(device, resp);
649 });
650 }
651
OnGetFolderItemsOHOS::Bluetooth::AvrcpController::impl652 void OnGetFolderItems(const BluetoothRemoteDevice &device, uint16_t uidCounter,
653 const std::vector<AvrcMeItem> &items, int result, int detail)
654 {
655 HILOGD("%{public}s start.", __func__);
656
657 std::vector<AvrcpCtResponse::MediaItems::MediaItem> mediaItems;
658 for (int i = 0; i < static_cast<int>(items.size()); i++) {
659 AvrcpCtResponse::MediaItems::MediaItem mediaItem;
660 mediaItem.uid_ = items.at(i).uid_;
661 mediaItem.type_ = items.at(i).type_;
662 mediaItem.playable_ = items.at(i).playable_;
663 mediaItem.name_ = items.at(i).name_;
664 mediaItem.attributes_ = items.at(i).attributes_;
665 mediaItem.values_ = items.at(i).values_;
666
667 mediaItems.push_back(mediaItem);
668 }
669
670 std::lock_guard<std::mutex> lock(observerMutex_);
671 observers_.ForEach([device, result, mediaItems, uidCounter](std::shared_ptr<IObserver> observer) {
672 AvrcpCtResponse resp(AVRC_ACTION_TYPE_GET_FOLDER_ITEMS, result);
673 resp.mediaItems_ = std::make_unique<AvrcpCtResponse::MediaItems>(uidCounter, mediaItems);
674 observer->OnActionCompleted(device, resp);
675 });
676
677 }
678
OnGetItemAttributesOHOS::Bluetooth::AvrcpController::impl679 void OnGetItemAttributes(const BluetoothRemoteDevice &device, const std::vector<uint32_t> &attributes,
680 const std::vector<std::string> &values, int result, int detail)
681 {
682 HILOGD("%{public}s start.", __func__);
683 std::vector<AvrcpCtResponse::ItemAttributes::ItemAttribute> itemAttrs;
684 for (int i = 0; i < static_cast<int>(attributes.size()); i++) {
685 AvrcpCtResponse::ItemAttributes::ItemAttribute itemAttr;
686 itemAttr.attribute_ = attributes.at(i);
687 itemAttr.value_ = values.at(i);
688 itemAttrs.push_back(itemAttr);
689 }
690
691 std::lock_guard<std::mutex> lock(observerMutex_);
692 observers_.ForEach([device, result, itemAttrs](std::shared_ptr<IObserver> observer) {
693 AvrcpCtResponse resp(AVRC_ACTION_TYPE_GET_ITEM_ATTRIBUTES, result);
694 resp.itemAttrs_ = std::make_unique<AvrcpCtResponse::ItemAttributes>(itemAttrs);
695 observer->OnActionCompleted(device, resp);
696 });
697 }
698
OnGetTotalNumberOfItemsOHOS::Bluetooth::AvrcpController::impl699 void OnGetTotalNumberOfItems(
700 const BluetoothRemoteDevice &device, uint16_t uidCounter, uint32_t numOfItems, int result, int detail)
701 {
702 HILOGD("%{public}s start.", __func__);
703 std::lock_guard<std::mutex> lock(observerMutex_);
704
705 observers_.ForEach([device, uidCounter, numOfItems, result](std::shared_ptr<IObserver> observer) {
706 AvrcpCtResponse resp(AVRC_ACTION_TYPE_GET_TOTAL_NUMBER_OF_ITEMS, result);
707 resp.totalItems_ = std::make_unique<AvrcpCtResponse::TotalNumberOfItems>(uidCounter, numOfItems);
708 observer->OnActionCompleted(device, resp);
709 });
710 }
711
OnSetAbsoluteVolumeOHOS::Bluetooth::AvrcpController::impl712 void OnSetAbsoluteVolume(const BluetoothRemoteDevice &device, uint16_t volume, int result)
713 {
714 HILOGD("%{public}s start.", __func__);
715 std::lock_guard<std::mutex> lock(observerMutex_);
716
717 observers_.ForEach([device, volume, result](std::shared_ptr<IObserver> observer) {
718 AvrcpCtResponse resp(AVRC_ACTION_TYPE_SET_ABSOLUTE_VOLUME, result);
719 resp.absVolume_ = std::make_unique<AvrcpCtResponse::AbsoluteVolume>(volume);
720 observer->OnActionCompleted(device, resp);
721 });
722 }
723
OnPlaybackStatusChangedOHOS::Bluetooth::AvrcpController::impl724 void OnPlaybackStatusChanged(const BluetoothRemoteDevice &device, uint8_t playStatus, int result)
725 {
726 HILOGD("%{public}s start.", __func__);
727 std::lock_guard<std::mutex> lock(observerMutex_);
728
729 observers_.ForEach([device, playStatus, result](std::shared_ptr<IObserver> observer) {
730 AvrcpCtResponse resp(AVRC_ACTION_TYPE_NOTIFY_PLAYBACK_STATUS_CHANGED, result);
731 resp.notify_ = std::make_unique<AvrcpCtResponse::Notification>(playStatus, 0x00);
732 observer->OnActionCompleted(device, resp);
733 });
734 }
735
OnTrackChangedOHOS::Bluetooth::AvrcpController::impl736 void OnTrackChanged(const BluetoothRemoteDevice &device, uint64_t uid, int result)
737 {
738 HILOGD("%{public}s start.", __func__);
739 std::lock_guard<std::mutex> lock(observerMutex_);
740
741 observers_.ForEach([device, uid, result](std::shared_ptr<IObserver> observer) {
742 AvrcpCtResponse resp(AVRC_ACTION_TYPE_NOTIFY_TRACK_CHANGED, result);
743 resp.notify_ = std::make_unique<AvrcpCtResponse::Notification>(uid);
744 observer->OnActionCompleted(device, resp);
745 });
746 }
747
OnTrackReachedEndOHOS::Bluetooth::AvrcpController::impl748 void OnTrackReachedEnd(const BluetoothRemoteDevice &device, int result)
749 {
750 HILOGD("%{public}s start.", __func__);
751 std::lock_guard<std::mutex> lock(observerMutex_);
752
753 observers_.ForEach([device, result](std::shared_ptr<IObserver> observer) {
754 AvrcpCtResponse resp(AVRC_ACTION_TYPE_NOTIFY_TRACK_REACHED_END, result);
755 observer->OnActionCompleted(device, resp);
756 });
757 }
758
OnTrackReachedStartOHOS::Bluetooth::AvrcpController::impl759 void OnTrackReachedStart(const BluetoothRemoteDevice &device, int result)
760 {
761 HILOGD("%{public}s start.", __func__);
762 std::lock_guard<std::mutex> lock(observerMutex_);
763
764 observers_.ForEach([device, result](std::shared_ptr<IObserver> observer) {
765 AvrcpCtResponse resp(AVRC_ACTION_TYPE_NOTIFY_TRACK_REACHED_START, result);
766 observer->OnActionCompleted(device, resp);
767 });
768 }
769
OnPlaybackPosChangedOHOS::Bluetooth::AvrcpController::impl770 void OnPlaybackPosChanged(const BluetoothRemoteDevice &device, uint32_t playbackPos, int result)
771 {
772 HILOGD("%{public}s start.", __func__);
773 std::lock_guard<std::mutex> lock(observerMutex_);
774
775 observers_.ForEach([device, playbackPos, result](std::shared_ptr<IObserver> observer) {
776 AvrcpCtResponse resp(AVRC_ACTION_TYPE_NOTIFY_PLAYBACK_POS_CHANGED, result);
777 resp.notify_ = std::make_unique<AvrcpCtResponse::Notification>(playbackPos);
778 observer->OnActionCompleted(device, resp);
779 });
780 }
781
OnPlayerAppSettingChangedOHOS::Bluetooth::AvrcpController::impl782 void OnPlayerAppSettingChanged(const BluetoothRemoteDevice &device, const std::vector<uint8_t> &attributes,
783 const std::vector<uint8_t> &values, int result)
784 {
785 HILOGD("%{public}s start.", __func__);
786 std::lock_guard<std::mutex> lock(observerMutex_);
787
788 observers_.ForEach([device, attributes, values, result](std::shared_ptr<IObserver> observer) {
789 AvrcpCtResponse resp(AVRC_ACTION_TYPE_NOTIFY_PLAYER_APPLICATION_SETTING_CHANGED, result);
790 resp.notify_ = std::make_unique<AvrcpCtResponse::Notification>(attributes, values);
791 observer->OnActionCompleted(device, resp);
792 });
793 }
794
OnNowPlayingContentChangedOHOS::Bluetooth::AvrcpController::impl795 void OnNowPlayingContentChanged(const BluetoothRemoteDevice &device, int result)
796 {
797 HILOGD("%{public}s start.", __func__);
798 std::lock_guard<std::mutex> lock(observerMutex_);
799
800 observers_.ForEach([device, result](std::shared_ptr<IObserver> observer) {
801 AvrcpCtResponse resp(AVRC_ACTION_TYPE_NOTIFY_NOW_PLAYING_CONTENT_CHANGED, result);
802 observer->OnActionCompleted(device, resp);
803 });
804 }
805
OnAvailablePlayersChangedOHOS::Bluetooth::AvrcpController::impl806 void OnAvailablePlayersChanged(const BluetoothRemoteDevice &device, int result)
807 {
808 HILOGD("%{public}s start.", __func__);
809 std::lock_guard<std::mutex> lock(observerMutex_);
810
811 observers_.ForEach([device, result](std::shared_ptr<IObserver> observer) {
812 AvrcpCtResponse resp(AVRC_ACTION_TYPE_NOTIFY_AVAILABLE_PLAYERS_CHANGED, result);
813 observer->OnActionCompleted(device, resp);
814 });
815 }
816
OnAddressedPlayerChangedOHOS::Bluetooth::AvrcpController::impl817 void OnAddressedPlayerChanged(
818 const BluetoothRemoteDevice &device, uint16_t playerId, uint16_t uidCounter, int result)
819 {
820 HILOGD("%{public}s start.", __func__);
821 std::lock_guard<std::mutex> lock(observerMutex_);
822
823 observers_.ForEach([device, uidCounter, result](std::shared_ptr<IObserver> observer) {
824 AvrcpCtResponse resp(AVRC_ACTION_TYPE_NOTIFY_ADDRESSED_PLAYER_CHANGED, result);
825 resp.notify_ = std::make_unique<AvrcpCtResponse::Notification>(uidCounter);
826 observer->OnActionCompleted(device, resp);
827 });
828 }
829
OnUidChangedOHOS::Bluetooth::AvrcpController::impl830 void OnUidChanged(const BluetoothRemoteDevice &device, uint16_t uidCounter, int result)
831 {
832 HILOGD("%{public}s start.", __func__);
833 std::lock_guard<std::mutex> lock(observerMutex_);
834
835 observers_.ForEach([device, result, uidCounter](std::shared_ptr<IObserver> observer) {
836 AvrcpCtResponse resp(AVRC_ACTION_TYPE_NOTIFY_UIDS_CHANGED, result);
837 resp.notify_ = std::make_unique<AvrcpCtResponse::Notification>(uidCounter);
838 observer->OnActionCompleted(device, resp);
839 });
840 }
841
OnVolumeChangedOHOS::Bluetooth::AvrcpController::impl842 void OnVolumeChanged(const BluetoothRemoteDevice &device, uint8_t volume, int result)
843 {
844 HILOGD("%{public}s start.", __func__);
845 std::lock_guard<std::mutex> lock(observerMutex_);
846
847 observers_.ForEach([device, volume, result](std::shared_ptr<IObserver> observer) {
848 AvrcpCtResponse resp(AVRC_ACTION_TYPE_NOTIFY_VOLUME_CHANGED, result);
849 resp.notify_ = std::make_unique<AvrcpCtResponse::Notification>(0x00, volume);
850 observer->OnActionCompleted(device, resp);
851 });
852 }
853
854 std::mutex observerMutex_;
855 BluetoothObserverList<AvrcpController::IObserver> observers_;
856
857 sptr<ObserverImpl> observer_;
858 sptr<IBluetoothAvrcpCt> proxy_ = nullptr;
859 class BluetoothAvrcpCtDeathRecipient;
860 sptr<BluetoothAvrcpCtDeathRecipient> deathRecipient_;
861 };
862
863 class AvrcpController::impl::BluetoothAvrcpCtDeathRecipient final : public IRemoteObject::DeathRecipient {
864 public:
BluetoothAvrcpCtDeathRecipient(AvrcpController::impl & AvrcpController)865 BluetoothAvrcpCtDeathRecipient(AvrcpController::impl &AvrcpController) : avrcpCt_(AvrcpController) {};
866 ~BluetoothAvrcpCtDeathRecipient() final = default;
867 BLUETOOTH_DISALLOW_COPY_AND_ASSIGN(BluetoothAvrcpCtDeathRecipient);
868
OnRemoteDied(const wptr<IRemoteObject> & remote)869 void OnRemoteDied(const wptr<IRemoteObject> &remote) final
870 {
871 HILOGI("AvrcpController::impl::BluetoothAvrcpCtDeathRecipient::OnRemoteDied starts");
872 avrcpCt_.proxy_->AsObject()->RemoveDeathRecipient(avrcpCt_.deathRecipient_);
873 avrcpCt_.proxy_ = nullptr;
874 }
875
876 private:
877 AvrcpController::impl &avrcpCt_;
878 };
879
impl()880 AvrcpController::impl::impl()
881 {
882 HILOGD("%{public}s start.", __func__);
883
884 observer_ = new (std::nothrow) ObserverImpl(this);
885 HILOGI("AvrcpController::impl::impl starts");
886 sptr<ISystemAbilityManager> samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
887 sptr<IRemoteObject> hostRemote = samgr->GetSystemAbility(BLUETOOTH_HOST_SYS_ABILITY_ID);
888
889 if (!hostRemote) {
890 HILOGI("AvrcpController::impl:impl() failed: no hostRemote");
891 return;
892 }
893 sptr<IBluetoothHost> hostProxy = iface_cast<IBluetoothHost>(hostRemote);
894 sptr<IRemoteObject> remote = hostProxy->GetProfile(PROFILE_AVRCP_CT);
895
896 if (!remote) {
897 HILOGE("AvrcpController::impl:impl() failed: no remote");
898 return;
899 }
900 HILOGI("AvrcpController::impl:impl() remote obtained");
901
902 proxy_ = iface_cast<IBluetoothAvrcpCt>(remote);
903 proxy_->RegisterObserver(observer_);
904
905 deathRecipient_ = new BluetoothAvrcpCtDeathRecipient(*this);
906 proxy_->AsObject()->AddDeathRecipient(deathRecipient_);
907 }
908
GetProfile(void)909 AvrcpController *AvrcpController::GetProfile(void)
910 {
911 HILOGD("%{public}s start.", __func__);
912
913 static AvrcpController instance;
914
915 return &instance;
916 }
917
918 /******************************************************************
919 * REGISTER / UNREGISTER OBSERVER *
920 ******************************************************************/
921
RegisterObserver(IObserver * observer)922 void AvrcpController::RegisterObserver(IObserver *observer)
923 {
924 HILOGD("%{public}s start.", __func__);
925
926 std::lock_guard<std::mutex> lock(pimpl->observerMutex_);
927
928 if (pimpl->IsEnabled()) {
929 std::shared_ptr<IObserver> pointer(observer, [](IObserver *) {});
930 pimpl->observers_.Register(pointer);
931 }
932 }
933
UnregisterObserver(IObserver * observer)934 void AvrcpController::UnregisterObserver(IObserver *observer)
935 {
936 HILOGD("%{public}s start.", __func__);
937
938 std::lock_guard<std::mutex> lock(pimpl->observerMutex_);
939
940 if (pimpl->IsEnabled()) {
941 std::shared_ptr<IObserver> pointer(observer, [](IObserver *) {});
942 pimpl->observers_.Deregister(pointer);
943 }
944 }
945
946 /******************************************************************
947 * CONNECTION *
948 ******************************************************************/
949
GetConnectedDevices(void)950 std::vector<BluetoothRemoteDevice> AvrcpController::GetConnectedDevices(void)
951 {
952 HILOGD("%{public}s start.", __func__);
953
954 std::vector<BluetoothRemoteDevice> devices;
955
956 if (pimpl->IsEnabled()) {
957 std::vector<RawAddress> rawAddrs;
958 rawAddrs = pimpl->proxy_->GetConnectedDevices();
959
960 for (auto rawAddr : rawAddrs) {
961 BluetoothRemoteDevice device(rawAddr.GetAddress(), BTTransport::ADAPTER_BREDR);
962 devices.push_back(device);
963 }
964 }
965
966 return devices;
967 }
968
GetDevicesByStates(const std::vector<int> & states)969 std::vector<BluetoothRemoteDevice> AvrcpController::GetDevicesByStates(const std::vector<int> &states)
970 {
971 HILOGD("%{public}s start.", __func__);
972
973 std::vector<BluetoothRemoteDevice> devices;
974
975 if (pimpl->IsEnabled()) {
976 std::vector<int32_t> convertStates;
977 for (auto state : states) {
978 convertStates.push_back(static_cast<int32_t>(state));
979 }
980 std::vector<RawAddress> rawAddrs;
981 rawAddrs = pimpl->proxy_->GetDevicesByStates(convertStates);
982
983 for (auto rawAddr : rawAddrs) {
984 BluetoothRemoteDevice device(rawAddr.GetAddress(), BTTransport::ADAPTER_BREDR);
985 devices.push_back(device);
986 }
987 }
988
989 return devices;
990 }
991
GetDeviceState(const BluetoothRemoteDevice & device)992 int AvrcpController::GetDeviceState(const BluetoothRemoteDevice &device)
993 {
994 HILOGD("%{public}s start.", __func__);
995
996 int result = static_cast<int>(BTConnectState::DISCONNECTED);
997
998 if (pimpl->IsEnabled()) {
999 BluetoothRawAddress rawAddr(device.GetDeviceAddr());
1000 result = pimpl->proxy_->GetDeviceState(rawAddr);
1001 }
1002
1003 return result;
1004 }
1005
Connect(const BluetoothRemoteDevice & device)1006 bool AvrcpController::Connect(const BluetoothRemoteDevice &device)
1007 {
1008 HILOGD("%{public}s start.", __func__);
1009
1010 int result = RET_BAD_STATUS;
1011
1012 if (pimpl->IsEnabled()) {
1013 BluetoothRawAddress rawAddr(device.GetDeviceAddr());
1014 result = pimpl->proxy_->Connect(rawAddr);
1015 }
1016
1017 return result == RET_NO_ERROR ? true : false;
1018 }
1019
Disconnect(const BluetoothRemoteDevice & device)1020 bool AvrcpController::Disconnect(const BluetoothRemoteDevice &device)
1021 {
1022 HILOGD("%{public}s start.", __func__);
1023
1024 int result = RET_BAD_STATUS;
1025
1026 if (pimpl->IsEnabled()) {
1027 BluetoothRawAddress rawAddr(device.GetDeviceAddr());
1028 result = pimpl->proxy_->Disconnect(rawAddr);
1029 }
1030
1031 return result == RET_NO_ERROR ? true : false;
1032 }
1033
1034 /******************************************************************
1035 * BUTTON OPERATION *
1036 ******************************************************************/
1037
PressButton(const BluetoothRemoteDevice & device,uint8_t button)1038 int AvrcpController::PressButton(const BluetoothRemoteDevice &device, uint8_t button)
1039 {
1040 HILOGD("%{public}s start.", __func__);
1041
1042 int result = RET_BAD_STATUS;
1043
1044 if (pimpl->IsEnabled()) {
1045 switch (button) {
1046 case AVRC_KEY_OPERATION_VOLUME_UP:
1047 case AVRC_KEY_OPERATION_VOLUME_DOWN:
1048 case AVRC_KEY_OPERATION_MUTE:
1049 case AVRC_KEY_OPERATION_PLAY:
1050 case AVRC_KEY_OPERATION_STOP:
1051 case AVRC_KEY_OPERATION_PAUSE:
1052 case AVRC_KEY_OPERATION_REWIND:
1053 case AVRC_KEY_OPERATION_FAST_FORWARD:
1054 case AVRC_KEY_OPERATION_FORWARD:
1055 case AVRC_KEY_OPERATION_BACKWARD: {
1056 BluetoothRawAddress rawAddr(device.GetDeviceAddr());
1057 result = pimpl->proxy_->PressButton(rawAddr, static_cast<int32_t>(button));
1058 break;
1059 }
1060 default:
1061 result = RET_NO_SUPPORT;
1062
1063 if (button >= AVRC_KEY_OPERATION_INVALID) {
1064 result = RET_BAD_PARAM;
1065 }
1066 break;
1067 }
1068 }
1069 return result;
1070 }
1071
ReleaseButton(const BluetoothRemoteDevice & device,uint8_t button)1072 int AvrcpController::ReleaseButton(const BluetoothRemoteDevice &device, uint8_t button)
1073 {
1074 HILOGD("%{public}s start.", __func__);
1075
1076 int result = RET_BAD_STATUS;
1077
1078 if (pimpl->IsEnabled()) {
1079 switch (button) {
1080 case AVRC_KEY_OPERATION_VOLUME_UP:
1081 case AVRC_KEY_OPERATION_VOLUME_DOWN:
1082 case AVRC_KEY_OPERATION_MUTE:
1083 case AVRC_KEY_OPERATION_PLAY:
1084 case AVRC_KEY_OPERATION_STOP:
1085 case AVRC_KEY_OPERATION_PAUSE:
1086 case AVRC_KEY_OPERATION_REWIND:
1087 case AVRC_KEY_OPERATION_FAST_FORWARD:
1088 case AVRC_KEY_OPERATION_FORWARD:
1089 case AVRC_KEY_OPERATION_BACKWARD: {
1090 BluetoothRawAddress rawAddr(device.GetDeviceAddr());
1091 result = pimpl->proxy_->ReleaseButton(rawAddr, static_cast<int32_t>(button));
1092 break;
1093 }
1094 default:
1095 result = RET_NO_SUPPORT;
1096
1097 if (button >= AVRC_KEY_OPERATION_INVALID) {
1098 result = RET_BAD_PARAM;
1099 }
1100 break;
1101 }
1102 }
1103 return result;
1104 }
1105
1106 /******************************************************************
1107 * TEMP UNIT INFO / SUB UNIT INFO *
1108 ******************************************************************/
1109
GetUnitInfo(const BluetoothRemoteDevice & device)1110 int AvrcpController::GetUnitInfo(const BluetoothRemoteDevice &device)
1111 {
1112 HILOGD("%{public}s start.", __func__);
1113
1114 int result = RET_BAD_STATUS;
1115
1116 if (pimpl->IsEnabled()) {
1117 BluetoothRawAddress rawAddr(device.GetDeviceAddr());
1118 result = pimpl->proxy_->GetUnitInfo(rawAddr);
1119 }
1120
1121 return result;
1122 }
1123
GetSubUnitInfo(const BluetoothRemoteDevice & device)1124 int AvrcpController::GetSubUnitInfo(const BluetoothRemoteDevice &device)
1125 {
1126 HILOGD("%{public}s start.", __func__);
1127
1128 int result = RET_BAD_STATUS;
1129
1130 if (pimpl->IsEnabled()) {
1131 BluetoothRawAddress rawAddr(device.GetDeviceAddr());
1132 result = pimpl->proxy_->GetSubUnitInfo(rawAddr);
1133 }
1134
1135 return result;
1136 }
1137
1138 /******************************************************************
1139 * Capabilities *
1140 ******************************************************************/
1141
GetSupportedCompanies(const BluetoothRemoteDevice & device)1142 int AvrcpController::GetSupportedCompanies(const BluetoothRemoteDevice &device)
1143 {
1144 HILOGD("%{public}s start.", __func__);
1145
1146 int result = RET_BAD_STATUS;
1147
1148 if (pimpl->IsEnabled()) {
1149 BluetoothRawAddress rawAddr(device.GetDeviceAddr());
1150 result = pimpl->proxy_->GetSupportedCompanies(rawAddr);
1151 }
1152
1153 return result;
1154 }
1155
GetSupportedEvents(const BluetoothRemoteDevice & device)1156 int AvrcpController::GetSupportedEvents(const BluetoothRemoteDevice &device)
1157 {
1158 HILOGD("%{public}s start.", __func__);
1159
1160 int result = RET_BAD_STATUS;
1161
1162 if (pimpl->IsEnabled()) {
1163 BluetoothRawAddress rawAddr(device.GetDeviceAddr());
1164 result = pimpl->proxy_->GetSupportedEvents(rawAddr);
1165 }
1166
1167 return result;
1168 }
1169
1170 /******************************************************************
1171 * PLAYER APPLICATION SETTINGS *
1172 ******************************************************************/
1173
GetPlayerAppSettingAttributes(const BluetoothRemoteDevice & device)1174 int AvrcpController::GetPlayerAppSettingAttributes(const BluetoothRemoteDevice &device)
1175 {
1176 HILOGD("%{public}s start.", __func__);
1177
1178 int result = RET_BAD_STATUS;
1179
1180 if (pimpl->IsEnabled()) {
1181 BluetoothRawAddress rawAddr(device.GetDeviceAddr());
1182 result = pimpl->proxy_->GetPlayerAppSettingAttributes(rawAddr);
1183 }
1184
1185 return result;
1186 }
1187
GetPlayerAppSettingValues(const BluetoothRemoteDevice & device,uint8_t attribute)1188 int AvrcpController::GetPlayerAppSettingValues(const BluetoothRemoteDevice &device, uint8_t attribute)
1189 {
1190 HILOGD("%{public}s start.", __func__);
1191
1192 int result = RET_BAD_STATUS;
1193
1194 if (pimpl->IsEnabled()) {
1195 do {
1196 if (attribute == AVRC_PLAYER_ATTRIBUTE_ILLEGAL) {
1197 result = RET_BAD_PARAM;
1198 break;
1199 }
1200
1201 if (attribute >= AVRC_PLAYER_ATTRIBUTE_RESERVED_MIN && attribute <= AVRC_PLAYER_ATTRIBUTE_RESERVED_MAX) {
1202 result = RET_BAD_PARAM;
1203 break;
1204 }
1205
1206 BluetoothRawAddress rawAddr(device.GetDeviceAddr());
1207 result = pimpl->proxy_->GetPlayerAppSettingValues(rawAddr, static_cast<int32_t>(attribute));
1208 } while (false);
1209 }
1210
1211 return result;
1212 }
1213
GetPlayerAppSettingCurrentValue(const BluetoothRemoteDevice & device,const std::vector<uint8_t> & attributes)1214 int AvrcpController::GetPlayerAppSettingCurrentValue(
1215 const BluetoothRemoteDevice &device, const std::vector<uint8_t> &attributes)
1216 {
1217 HILOGD("%{public}s start.", __func__);
1218
1219 int result = RET_NO_ERROR;
1220
1221 if (pimpl->IsEnabled()) {
1222 do {
1223 std::vector<int32_t> attrs;
1224
1225 for (auto attribute : attributes) {
1226 if (attribute == AVRC_PLAYER_ATTRIBUTE_ILLEGAL) {
1227 result = RET_BAD_PARAM;
1228 break;
1229 }
1230
1231 if (attribute >= AVRC_PLAYER_ATTRIBUTE_RESERVED_MIN &&
1232 attribute <= AVRC_PLAYER_ATTRIBUTE_RESERVED_MAX) {
1233 result = RET_BAD_PARAM;
1234 break;
1235 }
1236
1237 attrs.push_back(attribute);
1238 }
1239
1240 if (result != RET_NO_ERROR) {
1241 break;
1242 }
1243
1244 BluetoothRawAddress rawAddr(device.GetDeviceAddr());
1245 result = pimpl->proxy_->GetPlayerAppSettingCurrentValue(rawAddr, attrs);
1246 } while (false);
1247 }
1248
1249 return result;
1250 }
1251
SetPlayerAppSettingCurrentValue(const BluetoothRemoteDevice & device,const std::vector<uint8_t> & attributes,const std::vector<uint8_t> & values)1252 int AvrcpController::SetPlayerAppSettingCurrentValue(
1253 const BluetoothRemoteDevice &device, const std::vector<uint8_t> &attributes, const std::vector<uint8_t> &values)
1254 {
1255 HILOGD("%{public}s start.", __func__);
1256
1257 int result = RET_NO_ERROR;
1258 std::vector<int32_t> myAttributes;
1259 std::vector<int32_t> myValues;
1260
1261 if (pimpl->IsEnabled()) {
1262 do {
1263 if (attributes.size() != values.size()) {
1264 break;
1265 }
1266
1267 for (auto attribute : attributes) {
1268 if (attribute == AVRC_PLAYER_ATTRIBUTE_ILLEGAL) {
1269 result = RET_BAD_PARAM;
1270 break;
1271 }
1272
1273 if (attribute >= AVRC_PLAYER_ATTRIBUTE_RESERVED_MIN &&
1274 attribute <= AVRC_PLAYER_ATTRIBUTE_RESERVED_MAX) {
1275 result = RET_BAD_PARAM;
1276 break;
1277 }
1278 }
1279
1280 BluetoothRawAddress rawAddr(device.GetDeviceAddr());
1281 for (auto attribute : attributes) {
1282 myAttributes.push_back(static_cast<int32_t>(attribute));
1283 }
1284 for (auto value : values) {
1285 myValues.push_back(static_cast<int32_t>(value));
1286 }
1287
1288 if (result != RET_NO_ERROR) {
1289 break;
1290 }
1291
1292 result = pimpl->proxy_->SetPlayerAppSettingCurrentValue(rawAddr, myAttributes, myValues);
1293 } while (false);
1294 }
1295
1296 return result;
1297 }
1298
GetPlayerApplicationSettingAttributeText(const BluetoothRemoteDevice & device,const std::vector<uint8_t> & attributes)1299 int AvrcpController::GetPlayerApplicationSettingAttributeText(
1300 const BluetoothRemoteDevice &device, const std::vector<uint8_t> &attributes)
1301 {
1302 HILOGD("%{public}s start.", __func__);
1303
1304 int result = RET_BAD_STATUS;
1305 if (pimpl->IsEnabled()) {
1306 do {
1307 std::vector<int32_t> attrs;
1308
1309 for (auto attribute : attributes) {
1310 if (attribute == AVRC_PLAYER_ATTRIBUTE_ILLEGAL) {
1311 result = RET_BAD_PARAM;
1312 break;
1313 }
1314
1315 if (attribute >= AVRC_PLAYER_ATTRIBUTE_RESERVED_MIN &&
1316 attribute <= AVRC_PLAYER_ATTRIBUTE_RESERVED_MAX) {
1317 result = RET_BAD_PARAM;
1318 break;
1319 }
1320
1321 attrs.push_back(static_cast<int32_t>(attribute));
1322 }
1323
1324 BluetoothRawAddress rawAddr(device.GetDeviceAddr());
1325
1326 result = pimpl->proxy_->GetPlayerAppSettingAttributeText(rawAddr, attrs);
1327 } while (false);
1328 }
1329 return result;
1330 }
1331
GetPlayerApplicationSettingValueText(const BluetoothRemoteDevice & device,uint8_t attributeId,const std::vector<uint8_t> & values)1332 int AvrcpController::GetPlayerApplicationSettingValueText(
1333 const BluetoothRemoteDevice &device, uint8_t attributeId, const std::vector<uint8_t> &values)
1334 {
1335 HILOGD("%{public}s start.", __func__);
1336
1337 int result = RET_BAD_STATUS;
1338
1339 if (pimpl->IsEnabled()) {
1340 do {
1341 std::vector<int32_t> myValues;
1342
1343 if (attributeId == AVRC_PLAYER_ATTRIBUTE_ILLEGAL) {
1344 result = RET_BAD_PARAM;
1345 break;
1346 }
1347
1348 if (attributeId >= AVRC_PLAYER_ATTRIBUTE_RESERVED_MIN &&
1349 attributeId <= AVRC_PLAYER_ATTRIBUTE_RESERVED_MAX) {
1350 result = RET_BAD_PARAM;
1351 break;
1352 }
1353
1354 for (auto value : values) {
1355 myValues.push_back(static_cast<int32_t>(value));
1356 }
1357
1358 BluetoothRawAddress rawAddr(device.GetDeviceAddr());
1359 result = pimpl->proxy_->GetPlayerAppSettingValueText(
1360 rawAddr, static_cast<int32_t>(attributeId), myValues);
1361 } while (false);
1362 }
1363
1364 return result;
1365 }
1366
1367 /******************************************************************
1368 * MEDIA INFORMATION *
1369 ******************************************************************/
1370
GetElementAttributes(const BluetoothRemoteDevice & device,const std::vector<uint32_t> & attributes)1371 int AvrcpController::GetElementAttributes(const BluetoothRemoteDevice &device, const std::vector<uint32_t> &attributes)
1372 {
1373 HILOGD("%{public}s start.", __func__);
1374
1375 int result = RET_BAD_STATUS;
1376
1377 std::vector<int32_t> attrs;
1378
1379 for (auto attribute : attributes) {
1380 attrs.push_back(static_cast<int32_t>(attribute));
1381 }
1382
1383 if (pimpl->IsEnabled()) {
1384 BluetoothRawAddress rawAddr(device.GetDeviceAddr());
1385 result = pimpl->proxy_->GetElementAttributes(rawAddr, attrs);
1386 }
1387
1388 return result;
1389 }
1390
1391 /******************************************************************
1392 * PLAY *
1393 ******************************************************************/
1394
GetPlayStatus(const BluetoothRemoteDevice & device)1395 int AvrcpController::GetPlayStatus(const BluetoothRemoteDevice &device)
1396 {
1397 HILOGD("%{public}s start.", __func__);
1398
1399 int result = RET_BAD_STATUS;
1400
1401 if (pimpl->IsEnabled()) {
1402 BluetoothRawAddress rawAddr(device.GetDeviceAddr());
1403 result = pimpl->proxy_->GetPlayStatus(rawAddr);
1404 }
1405
1406 return result;
1407 }
1408
PlayItem(const BluetoothRemoteDevice & device,uint64_t uid,uint16_t uidCounter)1409 int AvrcpController::PlayItem(const BluetoothRemoteDevice &device, uint64_t uid, uint16_t uidCounter)
1410 {
1411 HILOGD("%{public}s start.", __func__);
1412
1413 int result = RET_BAD_STATUS;
1414
1415 if (pimpl->IsEnabled()) {
1416 BluetoothRawAddress rawAddr(device.GetDeviceAddr());
1417 result = pimpl->proxy_->PlayItem(rawAddr,
1418 static_cast<int32_t>(AVRC_MEDIA_SCOPE_NOW_PLAYING),
1419 static_cast<int64_t>(uid),
1420 static_cast<int32_t>(uidCounter)
1421 );
1422 }
1423
1424 return result;
1425 }
1426
1427 /******************************************************************
1428 * OPERATE THE VIRTUAL FILE SYSTEM *
1429 ******************************************************************/
1430
GetFolderItems(const BluetoothRemoteDevice & device,uint32_t startItem,uint32_t endItem,const std::vector<uint32_t> & attributes)1431 int AvrcpController::GetFolderItems(
1432 const BluetoothRemoteDevice &device, uint32_t startItem, uint32_t endItem, const std::vector<uint32_t> &attributes)
1433 {
1434 HILOGD("%{public}s start.", __func__);
1435
1436 int result = RET_NO_ERROR;
1437
1438 if (pimpl->IsEnabled()) {
1439
1440 do {
1441 if (startItem > endItem) {
1442 result = RET_BAD_PARAM;
1443 break;
1444 }
1445
1446 for (auto attribute : attributes) {
1447 if (attribute <= AVRC_MEDIA_ATTRIBUTE_NOT_USED || attribute >= AVRC_MEDIA_ATTRIBUTE_RESERVED) {
1448 result = RET_BAD_PARAM;
1449 break;
1450 }
1451 }
1452
1453 if (result != RET_NO_ERROR) {
1454 break;
1455 }
1456
1457 BluetoothRawAddress rawAddr(device.GetDeviceAddr());
1458 std::vector<int32_t> attrs;
1459
1460 for (auto attribute : attributes) {
1461 attrs.push_back(static_cast<int32_t>(attribute));
1462 }
1463 result = pimpl->proxy_->GetFolderItems(
1464 rawAddr, static_cast<int32_t>(startItem), static_cast<int32_t>(endItem), attrs);
1465 } while (false);
1466 }
1467
1468 return result;
1469 }
1470
GetMeidaPlayerList(const BluetoothRemoteDevice & device,uint32_t startItem,uint32_t endItem)1471 int AvrcpController::GetMeidaPlayerList(const BluetoothRemoteDevice &device, uint32_t startItem, uint32_t endItem)
1472 {
1473 HILOGD("%{public}s start.", __func__);
1474 int result = RET_BAD_STATUS;
1475 if (pimpl->IsEnabled()) {
1476 BluetoothRawAddress rawAddr(device.GetDeviceAddr());
1477 result = pimpl->proxy_->GetMeidaPlayerList(
1478 rawAddr, static_cast<int32_t>(startItem), static_cast<int32_t>(endItem));
1479 }
1480
1481 return result;
1482 }
1483
GetTotalNumberOfItems(const BluetoothRemoteDevice & device)1484 int AvrcpController::GetTotalNumberOfItems(const BluetoothRemoteDevice &device)
1485 {
1486 HILOGD("%{public}s start.", __func__);
1487
1488 int result = RET_BAD_STATUS;
1489 uint8_t scope = AVRC_MEDIA_SCOPE_NOW_PLAYING;
1490 if (pimpl->IsEnabled()) {
1491 BluetoothRawAddress rawAddr(device.GetDeviceAddr());
1492 result = pimpl->proxy_->GetTotalNumberOfItems(rawAddr, static_cast<int32_t>(scope));
1493 }
1494
1495 return result;
1496 }
1497
1498 /******************************************************************
1499 * ABSOLUTE VOLUME *
1500 ******************************************************************/
1501
SetAbsoluteVolume(const BluetoothRemoteDevice & device,uint8_t volume)1502 int AvrcpController::SetAbsoluteVolume(const BluetoothRemoteDevice &device, uint8_t volume)
1503 {
1504 HILOGD("%{public}s start.", __func__);
1505
1506 int result = RET_BAD_STATUS;
1507
1508 if (pimpl->IsEnabled()) {
1509 BluetoothRawAddress rawAddr(device.GetDeviceAddr());
1510 result = pimpl->proxy_->SetAbsoluteVolume(rawAddr, static_cast<int32_t>(volume));
1511 }
1512
1513 return result;
1514 }
1515
1516 /******************************************************************
1517 * NOTIFY *
1518 ******************************************************************/
1519
EnableNotification(const BluetoothRemoteDevice & device,const std::vector<uint8_t> & events,uint32_t interval)1520 int AvrcpController::EnableNotification(
1521 const BluetoothRemoteDevice &device, const std::vector<uint8_t> &events, uint32_t interval)
1522 {
1523 HILOGD("%{public}s start.", __func__);
1524
1525 int result = RET_BAD_STATUS;
1526
1527 std::vector<int32_t> myEvents;
1528 for (auto event : events) {
1529 myEvents.push_back(static_cast<int32_t>(event));
1530 }
1531
1532 if (pimpl->IsEnabled()) {
1533 BluetoothRawAddress rawAddr(device.GetDeviceAddr());
1534 result = pimpl->proxy_->EnableNotification(rawAddr, myEvents, static_cast<int32_t>(interval));
1535 }
1536
1537 return result;
1538 }
1539
DisableNotification(const BluetoothRemoteDevice & device,const std::vector<uint8_t> & events)1540 int AvrcpController::DisableNotification(const BluetoothRemoteDevice &device, const std::vector<uint8_t> &events)
1541 {
1542 HILOGD("%{public}s start.", __func__);
1543
1544 int result = RET_BAD_STATUS;
1545
1546 std::vector<int32_t> myEvents;
1547 for (auto event : events) {
1548 myEvents.push_back(static_cast<int32_t>(event));
1549 }
1550
1551 if (pimpl->IsEnabled()) {
1552 BluetoothRawAddress rawAddr(device.GetDeviceAddr());
1553 result = pimpl->proxy_->DisableNotification(rawAddr, myEvents);
1554 }
1555
1556 return result;
1557 }
1558
1559 /******************************************************************
1560 * DO NOT EXPOSE THE INTERFACE *
1561 ******************************************************************/
1562
SetAddressedPlayer(const BluetoothRemoteDevice & device,uint16_t playerId)1563 int AvrcpController::SetAddressedPlayer(const BluetoothRemoteDevice &device, uint16_t playerId)
1564 {
1565 HILOGD("%{public}s start.", __func__);
1566
1567 int result = RET_BAD_STATUS;
1568
1569 return result;
1570 }
1571
SetBrowsedPlayer(const BluetoothRemoteDevice & device,uint16_t playerId)1572 int AvrcpController::SetBrowsedPlayer(const BluetoothRemoteDevice &device, uint16_t playerId)
1573 {
1574 HILOGD("%{public}s start.", __func__);
1575
1576 int result = RET_BAD_STATUS;
1577
1578 if (pimpl->IsEnabled()) {
1579 BluetoothRawAddress rawAddr(device.GetDeviceAddr());
1580 result = pimpl->proxy_->SetBrowsedPlayer(rawAddr, (int32_t)playerId);
1581 }
1582
1583 return result;
1584 }
1585
ChangePath(const BluetoothRemoteDevice & device,uint16_t uidCounter,uint16_t direction,uint64_t folderUid)1586 int AvrcpController::ChangePath(
1587 const BluetoothRemoteDevice &device, uint16_t uidCounter, uint16_t direction, uint64_t folderUid)
1588 {
1589 HILOGD("%{public}s start.", __func__);
1590
1591 int result = RET_BAD_STATUS;
1592
1593 return result;
1594 }
1595
GetItemAttributes(const BluetoothRemoteDevice & device,uint64_t uid,uint16_t uidCounter,const std::vector<uint32_t> & attributes)1596 int AvrcpController::GetItemAttributes(
1597 const BluetoothRemoteDevice &device, uint64_t uid, uint16_t uidCounter, const std::vector<uint32_t> &attributes)
1598 {
1599 HILOGD("%{public}s start.", __func__);
1600
1601 int result = RET_BAD_STATUS;
1602 std::vector<int32_t> attrs;
1603
1604 for (auto attribute : attributes) {
1605 attrs.push_back(static_cast<int32_t>(attribute));
1606 }
1607
1608 if (pimpl->IsEnabled()) {
1609 BluetoothRawAddress rawAddr(device.GetDeviceAddr());
1610 result = pimpl->proxy_->GetItemAttributes(rawAddr, (int64_t)uid, (int32_t)uidCounter, attrs);
1611 }
1612 return result;
1613 }
1614
RequestContinuingResponse(const BluetoothRemoteDevice & device,uint8_t pduId)1615 int AvrcpController::RequestContinuingResponse(const BluetoothRemoteDevice &device, uint8_t pduId)
1616 {
1617 HILOGD("%{public}s start.", __func__);
1618
1619 int result = RET_BAD_STATUS;
1620
1621 return result;
1622 }
1623
AbortContinuingResponse(const BluetoothRemoteDevice & device,uint8_t pduId)1624 int AvrcpController::AbortContinuingResponse(const BluetoothRemoteDevice &device, uint8_t pduId)
1625 {
1626 HILOGD("%{public}s start.", __func__);
1627
1628 int result = RET_BAD_STATUS;
1629
1630 return result;
1631 }
1632
AddToNowPlaying(const BluetoothRemoteDevice & device,uint64_t uid,uint16_t uidCounter)1633 int AvrcpController::AddToNowPlaying(const BluetoothRemoteDevice &device, uint64_t uid, uint16_t uidCounter)
1634 {
1635 HILOGD("%{public}s start.", __func__);
1636
1637 int result = RET_BAD_STATUS;
1638
1639 return result;
1640 }
1641
AvrcpController(void)1642 AvrcpController::AvrcpController(void)
1643 {
1644 HILOGD("%{public}s start.", __func__);
1645
1646 pimpl = std::make_unique<AvrcpController::impl>();
1647 }
1648
~AvrcpController(void)1649 AvrcpController::~AvrcpController(void)
1650 {
1651 HILOGD("%{public}s start.", __func__);
1652 pimpl->proxy_->AsObject()->RemoveDeathRecipient(pimpl->deathRecipient_);
1653 pimpl = nullptr;
1654 }
1655
1656 } // namespace Bluetooth
1657 } // namespace OHOS
1658