• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #include <mutex>
16 #include "bluetooth_avrcp_ct_server.h"
17 #include "bluetooth_log.h"
18 
19 #include "interface_adapter_manager.h"
20 #include "interface_profile.h"
21 #include "interface_profile_avrcp_ct.h"
22 #include "interface_profile_manager.h"
23 #include "remote_observer_list.h"
24 
25 
26 namespace OHOS {
27 namespace Bluetooth {
28 using namespace bluetooth;
29 
30 struct BluetoothAvrcpCtServer::impl {
31 public:
32     class SysStsObserverImpl : public ISystemStateObserver {
33     public:
SysStsObserverImpl(BluetoothAvrcpCtServer::impl * impl)34         explicit SysStsObserverImpl(BluetoothAvrcpCtServer::impl *impl) : impl_(impl)
35         {}
~SysStsObserverImpl()36         virtual ~SysStsObserverImpl()
37         {}
38 
OnSystemStateChange(const BTSystemState state)39         void OnSystemStateChange(const BTSystemState state) override
40         {
41             impl_->OnSystemStateChange(state);
42         }
43 
44     private:
45         BluetoothAvrcpCtServer::impl *impl_;
46     };
47     class ObserverImpl : public IProfileAvrcpCt::IObserver {
48     public:
ObserverImpl(BluetoothAvrcpCtServer::impl * impl)49         explicit ObserverImpl(BluetoothAvrcpCtServer::impl *impl) : impl_(impl)
50         {}
~ObserverImpl()51         virtual ~ObserverImpl()
52         {}
53 
OnConnectionStateChanged(const RawAddress & rawAddr,int state)54         void OnConnectionStateChanged(const RawAddress &rawAddr, int state) override
55         {
56             impl_->OnConnectionStateChanged(rawAddr, state);
57         }
58 
OnPressButton(const RawAddress & rawAddr,uint8_t button,int result)59         void OnPressButton(const RawAddress &rawAddr, uint8_t button, int result) override
60         {
61             impl_->OnPressButton(rawAddr, button, result);
62         }
63 
OnReleaseButton(const RawAddress & rawAddr,uint8_t button,int result)64         void OnReleaseButton(const RawAddress &rawAddr, uint8_t button, int result) override
65         {
66             impl_->OnReleaseButton(rawAddr, button, result);
67         }
68 
OnSetAddressedPlayer(const RawAddress & rawAddr,int result,int detail)69         void OnSetAddressedPlayer(const RawAddress &rawAddr, int result, int detail) override
70         {
71             // The interface is not exposed
72         }
73 
OnSetBrowsedPlayer(const RawAddress & rawAddr,uint16_t uidCounter,uint32_t numOfItems,const std::vector<std::string> & folderNames,int result,int detail)74         void OnSetBrowsedPlayer(const RawAddress &rawAddr, uint16_t uidCounter, uint32_t numOfItems,
75             const std::vector<std::string> &folderNames, int result, int detail) override
76         {
77             impl_->OnSetBrowsedPlayer(rawAddr, uidCounter, numOfItems, folderNames, result, detail);
78         }
79 
OnGetCapabilities(const RawAddress & rawAddr,const std::vector<uint32_t> & companies,const std::vector<uint8_t> & events,int result)80         void OnGetCapabilities(const RawAddress &rawAddr, const std::vector<uint32_t> &companies,
81             const std::vector<uint8_t> &events, int result) override
82         {
83             impl_->OnGetCapabilities(rawAddr, companies, events, result);
84         }
85 
OnGetPlayerAppSettingAttributes(const RawAddress & rawAddr,std::vector<uint8_t> attributes,int result)86         void OnGetPlayerAppSettingAttributes(
87             const RawAddress &rawAddr, std::vector<uint8_t> attributes, int result) override
88         {
89             impl_->OnGetPlayerAppSettingAttributes(rawAddr, attributes, result);
90         }
91 
OnGetPlayerAppSettingValues(const RawAddress & rawAddr,uint8_t attribute,const std::vector<uint8_t> & values,int result)92         void OnGetPlayerAppSettingValues(
93             const RawAddress &rawAddr, uint8_t attribute, const std::vector<uint8_t> &values, int result) override
94         {
95             impl_->OnGetPlayerAppSettingValues(rawAddr, attribute, values, result);
96         }
97 
OnGetPlayerAppSettingCurrentValue(const RawAddress & rawAddr,const std::vector<uint8_t> & attributes,const std::vector<uint8_t> & values,int result)98         void OnGetPlayerAppSettingCurrentValue(const RawAddress &rawAddr, const std::vector<uint8_t> &attributes,
99             const std::vector<uint8_t> &values, int result) override
100         {
101             impl_->OnGetPlayerAppSettingCurrentValue(rawAddr, attributes, values, result);
102         }
103 
OnSetPlayerAppSettingCurrentValue(const RawAddress & rawAddr,int result)104         void OnSetPlayerAppSettingCurrentValue(const RawAddress &rawAddr, int result) override
105         {
106             impl_->OnSetPlayerAppSettingCurrentValue(rawAddr, result);
107         }
108 
OnGetPlayerAppSettingAttributeText(const RawAddress & rawAddr,const std::vector<uint8_t> & attributes,const std::vector<std::string> & attributeName,int result)109         void OnGetPlayerAppSettingAttributeText(const RawAddress &rawAddr, const std::vector<uint8_t> &attributes,
110             const std::vector<std::string> &attributeName, int result) override
111         {
112             impl_->OnGetPlayerAppSettingAttributeText(rawAddr, attributes, attributeName, result);
113         }
114 
OnGetPlayerAppSettingValueText(const RawAddress & rawAddr,const std::vector<uint8_t> & values,const std::vector<std::string> & valueName,int result)115         void OnGetPlayerAppSettingValueText(const RawAddress &rawAddr, const std::vector<uint8_t> &values,
116             const std::vector<std::string> &valueName, int result) override
117         {
118             impl_->OnGetPlayerAppSettingValueText(rawAddr, values, valueName, result);
119         }
120 
OnGetElementAttributes(const RawAddress & rawAddr,const std::vector<uint32_t> & attributes,const std::vector<std::string> & valueName,int result)121         void OnGetElementAttributes(const RawAddress &rawAddr, const std::vector<uint32_t> &attributes,
122             const std::vector<std::string> &valueName, int result) override
123         {
124             impl_->OnGetElementAttributes(rawAddr, attributes, valueName, result);
125         }
126 
OnGetPlayStatus(const RawAddress & rawAddr,uint32_t songLength,uint32_t songPosition,uint8_t playStatus,int result)127         void OnGetPlayStatus(const RawAddress &rawAddr, uint32_t songLength, uint32_t songPosition, uint8_t playStatus,
128             int result) override
129         {
130             impl_->OnGetPlayStatus(rawAddr, songLength, songPosition, playStatus, result);
131         }
132 
OnPlayItem(const RawAddress & rawAddr,int status,int result)133         void OnPlayItem(const RawAddress &rawAddr, int status, int result) override
134         {
135             impl_->OnPlayItem(rawAddr, status, result);
136         }
137 
OnAddToNowPlaying(const RawAddress & rawAddr,int status,int detail)138         void OnAddToNowPlaying(const RawAddress &rawAddr, int status, int detail) override
139         {
140             // The interface is not exposed
141         }
142 
OnChangePath(const RawAddress & rawAddr,uint32_t numOfItems,int result,int detail)143         void OnChangePath(const RawAddress &rawAddr, uint32_t numOfItems, int result, int detail) override
144         {
145             // The interface is not exposed
146         }
147 
OnGetMediaPlayers(const RawAddress & rawAddr,uint16_t uidCounter,const std::vector<AvrcMpItem> & items,int result,int detail)148         void OnGetMediaPlayers(const RawAddress &rawAddr, uint16_t uidCounter, const std::vector<AvrcMpItem> &items,
149             int result, int detail) override
150         {
151             impl_->OnGetMediaPlayers(rawAddr, uidCounter, items, result, detail);
152         }
153 
OnGetFolderItems(const RawAddress & rawAddr,uint16_t uidCounter,const std::vector<AvrcMeItem> & items,int result,int detail)154         void OnGetFolderItems(const RawAddress &rawAddr, uint16_t uidCounter, const std::vector<AvrcMeItem> &items,
155             int result, int detail) override
156         {
157             impl_->OnGetFolderItems(rawAddr, uidCounter, items, result, detail);
158         }
159 
OnGetItemAttributes(const RawAddress & rawAddr,const std::vector<uint32_t> & attributes,const std::vector<std::string> & values,int result,int detail)160         void OnGetItemAttributes(const RawAddress &rawAddr, const std::vector<uint32_t> &attributes,
161             const std::vector<std::string> &values, int result, int detail) override
162         {
163             impl_->OnGetItemAttributes(rawAddr, attributes, values, result, detail);
164         }
165 
OnGetTotalNumberOfItems(const RawAddress & rawAddr,uint16_t uidCounter,uint32_t numOfItems,int result,int detail)166         void OnGetTotalNumberOfItems(
167             const RawAddress &rawAddr, uint16_t uidCounter, uint32_t numOfItems, int result, int detail) override
168         {
169             impl_->OnGetTotalNumberOfItems(rawAddr, uidCounter, numOfItems, result, detail);
170         }
171 
OnSetAbsoluteVolume(const RawAddress & rawAddr,uint8_t volume,int result)172         void OnSetAbsoluteVolume(const RawAddress &rawAddr, uint8_t volume, int result) override
173         {
174             impl_->OnSetAbsoluteVolume(rawAddr, volume, result);
175         }
176 
OnPlaybackStatusChanged(const RawAddress & rawAddr,uint8_t playStatus,int result)177         void OnPlaybackStatusChanged(const RawAddress &rawAddr, uint8_t playStatus, int result) override
178         {
179             impl_->OnPlaybackStatusChanged(rawAddr, playStatus, result);
180         }
181 
OnTrackChanged(const RawAddress & rawAddr,uint64_t uid,int result)182         void OnTrackChanged(const RawAddress &rawAddr, uint64_t uid, int result) override
183         {
184             impl_->OnTrackChanged(rawAddr, uid, result);
185         }
186 
OnTrackReachedEnd(const RawAddress & rawAddr,int result)187         void OnTrackReachedEnd(const RawAddress &rawAddr, int result) override
188         {
189             impl_->OnTrackReachedEnd(rawAddr, result);
190         }
191 
OnTrackReachedStart(const RawAddress & rawAddr,int result)192         void OnTrackReachedStart(const RawAddress &rawAddr, int result) override
193         {
194             impl_->OnTrackReachedStart(rawAddr, result);
195         }
196 
OnPlaybackPosChanged(const RawAddress & rawAddr,uint32_t playbackPos,int result)197         void OnPlaybackPosChanged(const RawAddress &rawAddr, uint32_t playbackPos, int result) override
198         {
199             impl_->OnPlaybackPosChanged(rawAddr, playbackPos, result);
200         }
201 
OnPlayerAppSettingChanged(const RawAddress & rawAddr,const std::vector<uint8_t> & attributes,const std::vector<uint8_t> & values,int result)202         void OnPlayerAppSettingChanged(const RawAddress &rawAddr, const std::vector<uint8_t> &attributes,
203             const std::vector<uint8_t> &values, int result) override
204         {
205             impl_->OnPlayerAppSettingChanged(rawAddr, attributes, values, result);
206         }
207 
OnNowPlayingContentChanged(const RawAddress & rawAddr,int result)208         void OnNowPlayingContentChanged(const RawAddress &rawAddr, int result) override
209         {
210             impl_->OnNowPlayingContentChanged(rawAddr, result);
211         }
212 
OnAvailablePlayersChanged(const RawAddress & rawAddr,int result)213         void OnAvailablePlayersChanged(const RawAddress &rawAddr, int result) override
214         {
215             impl_->OnAvailablePlayersChanged(rawAddr, result);
216         }
217 
OnAddressedPlayerChanged(const RawAddress & rawAddr,uint16_t playerId,uint16_t uidCounter,int result)218         void OnAddressedPlayerChanged(
219             const RawAddress &rawAddr, uint16_t playerId, uint16_t uidCounter, int result) override
220         {
221             impl_->OnAddressedPlayerChanged(rawAddr, playerId, uidCounter, result);
222         }
223 
OnUidChanged(const RawAddress & rawAddr,uint16_t uidCounter,int result)224         void OnUidChanged(const RawAddress &rawAddr, uint16_t uidCounter, int result) override
225         {
226             impl_->OnUidChanged(rawAddr, uidCounter, result);
227         }
228 
OnVolumeChanged(const RawAddress & rawAddr,uint8_t volume,int result)229         void OnVolumeChanged(const RawAddress &rawAddr, uint8_t volume, int result) override
230         {
231             impl_->OnVolumeChanged(rawAddr, volume, result);
232         }
233 
234     private:
235         BluetoothAvrcpCtServer::impl *impl_;
236     };
237 
implOHOS::Bluetooth::BluetoothAvrcpCtServer::impl238     impl()
239     {
240         HILOGD("%{public}s start.", __func__);
241 
242         auto svManager = IProfileManager::GetInstance();
243         service_ = static_cast<IProfileAvrcpCt *>(svManager->GetProfileService(PROFILE_NAME_AVRCP_CT));
244         if (service_ != nullptr) {
245             observer_ = std::make_unique<ObserverImpl>(this);
246             service_->RegisterObserver(observer_.get());
247         }
248 
249         sysObserver_ = std::make_unique<SysStsObserverImpl>(this);
250         IAdapterManager::GetInstance()->RegisterSystemStateObserver(*sysObserver_);
251     }
252 
~implOHOS::Bluetooth::BluetoothAvrcpCtServer::impl253     ~impl()
254     {
255         HILOGD("%{public}s start.", __func__);
256 
257         auto svManager = IProfileManager::GetInstance();
258         service_ = static_cast<IProfileAvrcpCt *>(svManager->GetProfileService(PROFILE_NAME_AVRCP_CT));
259         if (service_ != nullptr) {
260             service_->UnregisterObserver();
261             observer_ = nullptr;
262             service_ = nullptr;
263         }
264 
265         IAdapterManager::GetInstance()->DeregisterSystemStateObserver(*sysObserver_);
266         sysObserver_ = nullptr;
267     }
268 
IsEnabledOHOS::Bluetooth::BluetoothAvrcpCtServer::impl269     bool IsEnabled()
270     {
271         HILOGD("%{public}s start.", __func__);
272 
273         auto servManager = IProfileManager::GetInstance();
274         service_ = static_cast<IProfileAvrcpCt *>(servManager->GetProfileService(PROFILE_NAME_AVRCP_CT));
275 
276         return (service_ != nullptr && service_->IsEnabled());
277     }
278 
OnSystemStateChangeOHOS::Bluetooth::BluetoothAvrcpCtServer::impl279     void OnSystemStateChange(const BTSystemState state)
280     {
281         HILOGD("%{public}s start.", __func__);
282 
283         std::lock_guard<std::mutex> lock(serviceMutex_);
284 
285         switch (state) {
286             case BTSystemState::ON: {
287                 auto svManager = IProfileManager::GetInstance();
288                 service_ = static_cast<IProfileAvrcpCt *>(svManager->GetProfileService(PROFILE_NAME_AVRCP_CT));
289                 if (service_ != nullptr) {
290                     observer_ = std::make_unique<ObserverImpl>(this);
291                     service_->RegisterObserver(observer_.get());
292                 }
293                 break;
294             }
295             case BTSystemState::OFF:
296                 /// FALL THROUGH
297             default:
298                 if (service_ != nullptr) {
299                     service_->UnregisterObserver();
300                     observer_ = nullptr;
301                     service_ = nullptr;
302                 }
303                 break;
304         }
305     }
306 
OnConnectionStateChangedOHOS::Bluetooth::BluetoothAvrcpCtServer::impl307     void OnConnectionStateChanged(const RawAddress &rawAddr, int state)
308     {
309         HILOGD("%{public}s start state:%{public}d.", __func__, state);
310         std::lock_guard<std::mutex> lock(observerMutex_);
311 
312         observers_.ForEach([rawAddr, state](IBluetoothAvrcpCtObserver *observer) {
313             observer->OnConnectionStateChanged(
314                 rawAddr, static_cast<int32_t>(state));
315         });
316     }
317 
OnPressButtonOHOS::Bluetooth::BluetoothAvrcpCtServer::impl318     void OnPressButton(const RawAddress &rawAddr, uint8_t button, int result)
319     {
320         HILOGD("%{public}s start.", __func__);
321 
322         std::lock_guard<std::mutex> lock(observerMutex_);
323 
324         observers_.ForEach([rawAddr, button, result](IBluetoothAvrcpCtObserver *observer) {
325             observer->OnPressButton(rawAddr,
326                 static_cast<int32_t>(button),
327                 static_cast<int32_t>(result));
328         });
329     }
330 
OnReleaseButtonOHOS::Bluetooth::BluetoothAvrcpCtServer::impl331     void OnReleaseButton(const RawAddress &rawAddr, uint8_t button, int result)
332     {
333         HILOGD("%{public}s start.", __func__);
334 
335         std::lock_guard<std::mutex> lock(observerMutex_);
336 
337         observers_.ForEach([rawAddr, button, result](IBluetoothAvrcpCtObserver *observer) {
338             observer->OnReleaseButton(rawAddr,
339                 static_cast<int32_t>(button),
340                 static_cast<int32_t>(result));
341         });
342     }
343 
OnSetBrowsedPlayerOHOS::Bluetooth::BluetoothAvrcpCtServer::impl344     void OnSetBrowsedPlayer(const RawAddress &rawAddr, uint16_t uidCounter, uint32_t numOfItems,
345         const std::vector<std::string> &folderNames, int result, int detail)
346     {
347         HILOGD("%{public}s start.", __func__);
348 
349         std::lock_guard<std::mutex> lock(observerMutex_);
350 
351         observers_.ForEach(
352             [rawAddr, uidCounter, numOfItems, folderNames, result, detail](IBluetoothAvrcpCtObserver *observer) {
353                 observer->OnSetBrowsedPlayer(rawAddr,
354                     static_cast<int32_t>(uidCounter),
355                     static_cast<int32_t>(numOfItems),
356                     folderNames,
357                     static_cast<int32_t>(result),
358                     static_cast<int32_t>(detail));
359             });
360     }
361 
OnGetCapabilitiesOHOS::Bluetooth::BluetoothAvrcpCtServer::impl362     void OnGetCapabilities(const RawAddress &rawAddr, const std::vector<uint32_t> &companies,
363         const std::vector<uint8_t> &events, int result)
364     {
365         HILOGD("%{public}s start.", __func__);
366 
367         std::lock_guard<std::mutex> lock(observerMutex_);
368 
369         observers_.ForEach([rawAddr, companies, events, result](IBluetoothAvrcpCtObserver *observer) {
370             observer->OnGetCapabilities(rawAddr,
371                 companies,
372                 events,
373                 static_cast<int32_t>(result));
374         });
375     }
376 
OnGetPlayerAppSettingAttributesOHOS::Bluetooth::BluetoothAvrcpCtServer::impl377     void OnGetPlayerAppSettingAttributes(const RawAddress &rawAddr, std::vector<uint8_t> attributes, int result)
378     {
379         HILOGD("%{public}s start.", __func__);
380 
381         std::lock_guard<std::mutex> lock(observerMutex_);
382 
383         observers_.ForEach([rawAddr, attributes, result](IBluetoothAvrcpCtObserver *observer) {
384             observer->OnGetPlayerAppSettingAttributes(
385                 rawAddr, attributes, static_cast<int32_t>(result));
386         });
387     }
388 
OnGetPlayerAppSettingValuesOHOS::Bluetooth::BluetoothAvrcpCtServer::impl389     void OnGetPlayerAppSettingValues(
390         const RawAddress &rawAddr, uint8_t attribute, const std::vector<uint8_t> values, int result)
391     {
392         HILOGD("%{public}s start.", __func__);
393 
394         std::lock_guard<std::mutex> lock(observerMutex_);
395 
396         observers_.ForEach([rawAddr, attribute, values, result](IBluetoothAvrcpCtObserver *observer) {
397             observer->OnGetPlayerAppSettingValues(
398                 rawAddr, static_cast<int32_t>(attribute), values, static_cast<int32_t>(result));
399         });
400     }
401 
OnGetPlayerAppSettingCurrentValueOHOS::Bluetooth::BluetoothAvrcpCtServer::impl402     void OnGetPlayerAppSettingCurrentValue(const RawAddress &rawAddr, const std::vector<uint8_t> &attributes,
403         const std::vector<uint8_t> &values, int result)
404     {
405         HILOGD("%{public}s start.", __func__);
406 
407         std::lock_guard<std::mutex> lock(observerMutex_);
408 
409         observers_.ForEach([rawAddr, attributes, values, result](IBluetoothAvrcpCtObserver *observer) {
410             observer->OnGetPlayerAppSettingCurrentValue(rawAddr,
411                 attributes,
412                 values,
413                 static_cast<int32_t>(result));
414         });
415     }
416 
OnSetPlayerAppSettingCurrentValueOHOS::Bluetooth::BluetoothAvrcpCtServer::impl417     void OnSetPlayerAppSettingCurrentValue(const RawAddress &rawAddr, int result)
418     {
419         HILOGD("%{public}s start.", __func__);
420 
421         std::lock_guard<std::mutex> lock(observerMutex_);
422 
423         observers_.ForEach([rawAddr, result](IBluetoothAvrcpCtObserver *observer) {
424             observer->OnSetPlayerAppSettingCurrentValue(
425                 rawAddr, static_cast<int32_t>(result));
426         });
427     }
428 
OnGetPlayerAppSettingAttributeTextOHOS::Bluetooth::BluetoothAvrcpCtServer::impl429     void OnGetPlayerAppSettingAttributeText(const RawAddress &rawAddr, const std::vector<uint8_t> &attributes,
430         const std::vector<std::string> &attributeName, int result)
431     {
432         HILOGD("%{public}s start.", __func__);
433 
434         std::lock_guard<std::mutex> lock(observerMutex_);
435 
436         observers_.ForEach([rawAddr, attributes, attributeName, result](IBluetoothAvrcpCtObserver *observer) {
437             observer->OnGetPlayerAppSettingAttributeText(rawAddr,
438                 attributes,
439                 attributeName,
440                 static_cast<int32_t>(result));
441         });
442     }
443 
OnGetPlayerAppSettingValueTextOHOS::Bluetooth::BluetoothAvrcpCtServer::impl444     void OnGetPlayerAppSettingValueText(const RawAddress &rawAddr, const std::vector<uint8_t> &values,
445         const std::vector<std::string> &valueName, int result)
446     {
447         HILOGD("%{public}s start.", __func__);
448 
449         std::lock_guard<std::mutex> lock(observerMutex_);
450 
451         observers_.ForEach([rawAddr, values, valueName, result](IBluetoothAvrcpCtObserver *observer) {
452             observer->OnGetPlayerAppSettingValueText(
453                 rawAddr, values, valueName, static_cast<int32_t>(result));
454         });
455     }
456 
OnGetElementAttributesOHOS::Bluetooth::BluetoothAvrcpCtServer::impl457     void OnGetElementAttributes(const RawAddress &rawAddr, const std::vector<uint32_t> &attributes,
458         const std::vector<std::string> &valueName, int result)
459     {
460         HILOGD("%{public}s start.", __func__);
461 
462         std::lock_guard<std::mutex> lock(observerMutex_);
463 
464         observers_.ForEach([rawAddr, attributes, valueName, result](IBluetoothAvrcpCtObserver *observer) {
465             observer->OnGetElementAttributes(rawAddr,
466                 attributes,
467                 valueName,
468                 static_cast<int32_t>(result));
469         });
470     }
471 
OnGetPlayStatusOHOS::Bluetooth::BluetoothAvrcpCtServer::impl472     void OnGetPlayStatus(
473         const RawAddress &rawAddr, uint32_t songLength, uint32_t songPosition, uint8_t playStatus, int result)
474     {
475         HILOGD("%{public}s start.", __func__);
476 
477         std::lock_guard<std::mutex> lock(observerMutex_);
478 
479         observers_.ForEach(
480             [rawAddr, songLength, songPosition, playStatus, result](IBluetoothAvrcpCtObserver *observer) {
481                 observer->OnGetPlayStatus(rawAddr,
482                     songLength,
483                     songPosition,
484                     static_cast<int32_t>(playStatus),
485                     static_cast<int32_t>(result));
486             });
487     }
488 
OnPlayItemOHOS::Bluetooth::BluetoothAvrcpCtServer::impl489     void OnPlayItem(const RawAddress &rawAddr, int result, int detail)
490     {
491         HILOGD("%{public}s start.", __func__);
492 
493         std::lock_guard<std::mutex> lock(observerMutex_);
494 
495         observers_.ForEach([rawAddr, result, detail](IBluetoothAvrcpCtObserver *observer) {
496             observer->OnPlayItem(rawAddr,
497                 static_cast<int32_t>(result),
498                 static_cast<int32_t>(detail));
499         });
500     }
501 
OnGetMediaPlayersOHOS::Bluetooth::BluetoothAvrcpCtServer::impl502     void OnGetMediaPlayers(
503         const RawAddress &rawAddr, uint16_t uidCounter, const std::vector<AvrcMpItem> &items, int result, int detail)
504     {
505         HILOGD("%{public}s start.", __func__);
506 
507         std::lock_guard<std::mutex> lock(observerMutex_);
508 
509         observers_.ForEach([rawAddr, uidCounter, items, result, detail](IBluetoothAvrcpCtObserver *observer) {
510             std::vector<BluetoothAvrcpMpItem> myItems;
511             for (size_t i = 0; i < items.size(); i++) {
512                 myItems.push_back(BluetoothAvrcpMpItem(items.at(i)));
513             }
514             observer->OnGetMediaPlayers(rawAddr,
515                 static_cast<int32_t>(uidCounter),
516                 myItems,
517                 static_cast<int32_t>(result),
518                 static_cast<int32_t>(detail));
519         });
520     }
521 
OnGetFolderItemsOHOS::Bluetooth::BluetoothAvrcpCtServer::impl522     void OnGetFolderItems(
523         const RawAddress &rawAddr, uint16_t uidCounter, const std::vector<AvrcMeItem> &items, int result, int detail)
524     {
525         HILOGD("%{public}s start items.size = %{public}d.", __func__, items.size());
526 
527         std::lock_guard<std::mutex> lock(observerMutex_);
528 
529         observers_.ForEach([rawAddr, uidCounter, items, result, detail](IBluetoothAvrcpCtObserver *observer) {
530             std::vector<BluetoothAvrcpMeItem> myItems;
531             for (size_t i = 0; i < items.size(); i++) {
532                 myItems.push_back(BluetoothAvrcpMeItem(items.at(i)));
533             }
534             observer->OnGetFolderItems(rawAddr,
535                 static_cast<int32_t>(uidCounter),
536                 myItems,
537                 static_cast<int32_t>(result),
538                 static_cast<int32_t>(detail));
539         });
540     }
541 
OnGetItemAttributesOHOS::Bluetooth::BluetoothAvrcpCtServer::impl542     void OnGetItemAttributes(const RawAddress &rawAddr, const std::vector<uint32_t> &attributes,
543         const std::vector<std::string> &values, int result, int detail)
544     {
545         HILOGD("%{public}s start.", __func__);
546 
547         std::lock_guard<std::mutex> lock(observerMutex_);
548 
549         observers_.ForEach([rawAddr, attributes, values, result, detail](IBluetoothAvrcpCtObserver *observer) {
550             observer->OnGetItemAttributes(rawAddr,
551                 attributes,
552                 values,
553                 static_cast<int32_t>(result),
554                 static_cast<int32_t>(detail));
555         });
556     }
557 
OnGetTotalNumberOfItemsOHOS::Bluetooth::BluetoothAvrcpCtServer::impl558     void OnGetTotalNumberOfItems(
559         const RawAddress &rawAddr, uint16_t uidCounter, uint32_t numOfItems, int result, int detail)
560     {
561         HILOGD("%{public}s start.", __func__);
562 
563         std::lock_guard<std::mutex> lock(observerMutex_);
564 
565         observers_.ForEach([rawAddr, uidCounter, numOfItems, result, detail](IBluetoothAvrcpCtObserver *observer) {
566             observer->OnGetTotalNumberOfItems(rawAddr,
567                 static_cast<int32_t>(uidCounter),
568                 numOfItems,
569                 static_cast<int32_t>(result),
570                 static_cast<int32_t>(detail));
571         });
572     }
573 
OnSetAbsoluteVolumeOHOS::Bluetooth::BluetoothAvrcpCtServer::impl574     void OnSetAbsoluteVolume(const RawAddress &rawAddr, uint8_t volume, int result)
575     {
576         HILOGD("%{public}s start.", __func__);
577 
578         std::lock_guard<std::mutex> lock(observerMutex_);
579 
580         observers_.ForEach([rawAddr, volume, result](IBluetoothAvrcpCtObserver *observer) {
581             observer->OnSetAbsoluteVolume(rawAddr,
582                 static_cast<int32_t>(volume),
583                 static_cast<int32_t>(result));
584         });
585     }
586 
OnPlaybackStatusChangedOHOS::Bluetooth::BluetoothAvrcpCtServer::impl587     void OnPlaybackStatusChanged(const RawAddress &rawAddr, uint8_t playStatus, int result)
588     {
589         HILOGD("%{public}s start.", __func__);
590 
591         std::lock_guard<std::mutex> lock(observerMutex_);
592 
593         observers_.ForEach([rawAddr, playStatus, result](IBluetoothAvrcpCtObserver *observer) {
594             observer->OnPlaybackStatusChanged(rawAddr,
595                 static_cast<int32_t>(playStatus),
596                 static_cast<int32_t>(result));
597         });
598     }
599 
OnTrackChangedOHOS::Bluetooth::BluetoothAvrcpCtServer::impl600     void OnTrackChanged(const RawAddress &rawAddr, uint64_t uid, int result)
601     {
602         HILOGD("%{public}s start.", __func__);
603 
604         std::lock_guard<std::mutex> lock(observerMutex_);
605 
606         observers_.ForEach([rawAddr, uid, result](IBluetoothAvrcpCtObserver *observer) {
607             observer->OnTrackChanged(rawAddr,
608                 uid,
609                 static_cast<int32_t>(result));
610         });
611     }
612 
OnTrackReachedEndOHOS::Bluetooth::BluetoothAvrcpCtServer::impl613     void OnTrackReachedEnd(const RawAddress &rawAddr, int result)
614     {
615         HILOGD("%{public}s start.", __func__);
616 
617         std::lock_guard<std::mutex> lock(observerMutex_);
618 
619         observers_.ForEach([rawAddr, result](IBluetoothAvrcpCtObserver *observer) {
620             observer->OnTrackReachedEnd(
621                 rawAddr, static_cast<int32_t>(result));
622         });
623     }
624 
OnTrackReachedStartOHOS::Bluetooth::BluetoothAvrcpCtServer::impl625     void OnTrackReachedStart(const RawAddress &rawAddr, int result)
626     {
627         HILOGD("%{public}s start.", __func__);
628 
629         std::lock_guard<std::mutex> lock(observerMutex_);
630 
631         observers_.ForEach([rawAddr, result](IBluetoothAvrcpCtObserver *observer) {
632             observer->OnTrackReachedStart(
633                 rawAddr, static_cast<int32_t>(result));
634         });
635     }
636 
OnPlaybackPosChangedOHOS::Bluetooth::BluetoothAvrcpCtServer::impl637     void OnPlaybackPosChanged(const RawAddress &rawAddr, uint32_t playbackPos, int result)
638     {
639         HILOGD("%{public}s start.", __func__);
640 
641         std::lock_guard<std::mutex> lock(observerMutex_);
642 
643         observers_.ForEach([rawAddr, playbackPos, result](IBluetoothAvrcpCtObserver *observer) {
644             observer->OnPlaybackPosChanged(rawAddr,
645                 playbackPos,
646                 static_cast<int32_t>(result));
647         });
648     }
649 
OnPlayerAppSettingChangedOHOS::Bluetooth::BluetoothAvrcpCtServer::impl650     void OnPlayerAppSettingChanged(const RawAddress &rawAddr, const std::vector<uint8_t> &attributes,
651         const std::vector<uint8_t> &values, int result)
652     {
653         HILOGD("%{public}s start.", __func__);
654 
655         std::lock_guard<std::mutex> lock(observerMutex_);
656 
657         observers_.ForEach([rawAddr, attributes, values, result](IBluetoothAvrcpCtObserver *observer) {
658             observer->OnPlayerAppSettingChanged(rawAddr,
659                 attributes,
660                 values,
661                 static_cast<int32_t>(result));
662         });
663     }
664 
OnNowPlayingContentChangedOHOS::Bluetooth::BluetoothAvrcpCtServer::impl665     void OnNowPlayingContentChanged(const RawAddress &rawAddr, int result)
666     {
667         HILOGD("%{public}s start.", __func__);
668 
669         std::lock_guard<std::mutex> lock(observerMutex_);
670 
671         observers_.ForEach([rawAddr, result](IBluetoothAvrcpCtObserver *observer) {
672             observer->OnNowPlayingContentChanged(
673                 rawAddr, static_cast<int32_t>(result));
674         });
675     }
676 
OnAvailablePlayersChangedOHOS::Bluetooth::BluetoothAvrcpCtServer::impl677     void OnAvailablePlayersChanged(const RawAddress &rawAddr, int result)
678     {
679         HILOGD("%{public}s start.", __func__);
680 
681         std::lock_guard<std::mutex> lock(observerMutex_);
682 
683         observers_.ForEach([rawAddr, result](IBluetoothAvrcpCtObserver *observer) {
684             observer->OnAvailablePlayersChanged(
685                 rawAddr, static_cast<int32_t>(result));
686         });
687     }
688 
OnAddressedPlayerChangedOHOS::Bluetooth::BluetoothAvrcpCtServer::impl689     void OnAddressedPlayerChanged(const RawAddress &rawAddr, uint16_t playerId, uint16_t uidCounter, int result)
690     {
691         HILOGD("%{public}s start.", __func__);
692 
693         std::lock_guard<std::mutex> lock(observerMutex_);
694 
695         observers_.ForEach([rawAddr, playerId, uidCounter, result](IBluetoothAvrcpCtObserver *observer) {
696             observer->OnAddressedPlayerChanged(rawAddr,
697                 static_cast<int32_t>(playerId),
698                 static_cast<int32_t>(uidCounter),
699                 static_cast<int32_t>(result));
700         });
701     }
702 
OnUidChangedOHOS::Bluetooth::BluetoothAvrcpCtServer::impl703     void OnUidChanged(const RawAddress &rawAddr, uint16_t uidCounter, int result)
704     {
705         HILOGD("%{public}s start.", __func__);
706 
707         std::lock_guard<std::mutex> lock(observerMutex_);
708 
709         observers_.ForEach([rawAddr, uidCounter, result](IBluetoothAvrcpCtObserver *observer) {
710             observer->OnUidChanged(rawAddr,
711                 static_cast<int32_t>(uidCounter),
712                 static_cast<int32_t>(result));
713         });
714     }
715 
OnVolumeChangedOHOS::Bluetooth::BluetoothAvrcpCtServer::impl716     void OnVolumeChanged(const RawAddress &rawAddr, uint8_t volume, int result)
717     {
718         HILOGD("%{public}s start.", __func__);
719 
720         std::lock_guard<std::mutex> lock(observerMutex_);
721 
722         observers_.ForEach([rawAddr, volume, result](IBluetoothAvrcpCtObserver *observer) {
723             observer->OnVolumeChanged(rawAddr,
724                 static_cast<int32_t>(volume),
725                 static_cast<int32_t>(result));
726         });
727     }
728 
729     std::mutex serviceMutex_;
730     IProfileAvrcpCt *service_;
731 
732     std::mutex observerMutex_;
733     RemoteObserverList<IBluetoothAvrcpCtObserver> observers_;
734 
735     std::unique_ptr<ObserverImpl> observer_;
736     std::unique_ptr<SysStsObserverImpl> sysObserver_;
737 };
738 
BluetoothAvrcpCtServer()739 BluetoothAvrcpCtServer::BluetoothAvrcpCtServer()
740 {
741     HILOGD("%{public}s start.", __func__);
742 
743     pimpl = std::make_unique<impl>();
744 }
745 
~BluetoothAvrcpCtServer()746 BluetoothAvrcpCtServer::~BluetoothAvrcpCtServer()
747 {
748     pimpl = nullptr;
749 }
750 
RegisterObserver(const sptr<IBluetoothAvrcpCtObserver> & observer)751 void BluetoothAvrcpCtServer::RegisterObserver(const sptr<IBluetoothAvrcpCtObserver> &observer)
752 {
753     HILOGD("%{public}s start.", __func__);
754 
755     std::lock_guard<std::mutex> lock(pimpl->observerMutex_);
756 
757     if (observer == nullptr) {
758         HILOGD("RegisterObserver called with NULL binder. Ignoring.");
759         return ;
760     }
761     pimpl->observers_.Register(observer);
762     HILOGD("%{public}s end.", __func__);
763 
764     return ;
765 }
766 
UnregisterObserver(const sptr<IBluetoothAvrcpCtObserver> & observer)767 void BluetoothAvrcpCtServer::UnregisterObserver(const sptr<IBluetoothAvrcpCtObserver> &observer)
768 {
769     HILOGD("%{public}s start.", __func__);
770 
771     std::lock_guard<std::mutex> lock(pimpl->observerMutex_);
772 
773     if (observer == nullptr) {
774         HILOGD("UnregisterObserver called with NULL binder. Ignoring.");
775         return;
776     }
777     pimpl->observers_.Deregister(observer);
778     HILOGD("%{public}s end.", __func__);
779 
780     return;
781 }
782 
GetConnectedDevices()783 std::vector<RawAddress> BluetoothAvrcpCtServer::GetConnectedDevices()
784 {
785     HILOGD("%{public}s start.", __func__);
786     std::vector<RawAddress> devices {};
787     if (pimpl->IsEnabled()) {
788         devices = pimpl->service_->GetConnectedDevices();
789     } else {
790         HILOGE("%{public}s: service is null or disable ", __func__);
791     }
792     HILOGD("%{public}s end.", __func__);
793 
794     return devices;
795 }
796 
GetDevicesByStates(const std::vector<int32_t> & states)797 std::vector<RawAddress> BluetoothAvrcpCtServer::GetDevicesByStates(const std::vector<int32_t> &states)
798 {
799     HILOGD("%{public}s start.", __func__);
800     std::vector<RawAddress> devices {};
801     if (pimpl->IsEnabled()) {
802         std::vector<int> convertStates;
803         for (auto state : states) {
804             convertStates.push_back(static_cast<int>(state));
805         }
806 
807         devices = pimpl->service_->GetDevicesByStates(convertStates);
808     } else {
809         HILOGE("%{public}s: service is null or disable ", __func__);
810     }
811     HILOGD("%{public}s end.", __func__);
812     return devices;
813 }
814 
GetDeviceState(const RawAddress & device)815 int32_t BluetoothAvrcpCtServer::GetDeviceState(const RawAddress &device)
816 {
817     HILOGD("%{public}s start.", __func__);
818     int32_t result = 0;
819 
820     if (pimpl->IsEnabled()) {
821         result = pimpl->service_->GetDeviceState(BluetoothRawAddress(device));
822     } else {
823         HILOGE("%{public}s: service is null or disable ", __func__);
824     }
825     HILOGD("%{public}s end.", __func__);
826 
827     return result;
828 }
829 
Connect(const RawAddress & device)830 int32_t BluetoothAvrcpCtServer::Connect(const RawAddress &device)
831 {
832     HILOGD("%{public}s start.", __func__);
833     int32_t result = 0;
834 
835     if (pimpl->IsEnabled()) {
836         result = pimpl->service_->Connect(BluetoothRawAddress(device));
837     } else {
838         HILOGE("%{public}s: service is null or disable ", __func__);
839     }
840     HILOGD("%{public}s end.", __func__);
841 
842     return result;
843 }
844 
Disconnect(const RawAddress & device)845 int32_t BluetoothAvrcpCtServer::Disconnect(const RawAddress &device)
846 {
847     HILOGD("%{public}s start.", __func__);
848     int32_t result = 0;
849 
850     if (pimpl->IsEnabled()) {
851         result = pimpl->service_->Disconnect(BluetoothRawAddress(device));
852     } else {
853         HILOGE("%{public}s: service is null or disable ", __func__);
854     }
855 
856     HILOGD("%{public}s end.", __func__);
857     return result;
858 }
859 
PressButton(const RawAddress & device,int32_t button)860 int32_t BluetoothAvrcpCtServer::PressButton(const RawAddress &device, int32_t button)
861 {
862     HILOGD("%{public}s start.", __func__);
863     HILOGD("%{public}s: button = %{public}d", __func__, button);
864     int32_t result = 0;
865 
866     if (pimpl->IsEnabled()) {
867         result = pimpl->service_->PressButton(BluetoothRawAddress(device), static_cast<uint8_t>(button));
868     } else {
869         HILOGE("%{public}s: service is null or disable ", __func__);
870     }
871     HILOGD("%{public}s end.", __func__);
872 
873     return result;
874 }
875 
ReleaseButton(const RawAddress & device,int32_t button)876 int32_t BluetoothAvrcpCtServer::ReleaseButton(const RawAddress &device, int32_t button)
877 {
878     HILOGD("%{public}s start.", __func__);
879     HILOGD("%{public}s: button = %{public}d", __func__, button);
880     int32_t result = 0;
881 
882     if (pimpl->IsEnabled()) {
883         result = pimpl->service_->ReleaseButton(BluetoothRawAddress(device), static_cast<uint8_t>(button));
884     } else {
885         HILOGE("%{public}s: service is null or disable ", __func__);
886     }
887     HILOGD("%{public}s end.", __func__);
888 
889     return result;
890 }
891 
GetUnitInfo(const RawAddress & device)892 int32_t BluetoothAvrcpCtServer::GetUnitInfo(const RawAddress &device)
893 {
894     HILOGD("%{public}s start.", __func__);
895     int32_t result = 0;
896 
897     if (pimpl->IsEnabled()) {
898         result = pimpl->service_->GetUnitInfo(BluetoothRawAddress(device));
899     } else {
900         HILOGE("%{public}s: service is null or disable ", __func__);
901     }
902     HILOGD("%{public}s end.", __func__);
903 
904     return result;
905 }
906 
GetSubUnitInfo(const RawAddress & device)907 int32_t BluetoothAvrcpCtServer::GetSubUnitInfo(const RawAddress &device)
908 {
909     HILOGD("%{public}s start.", __func__);
910     int32_t result = 0;
911 
912     if (pimpl->IsEnabled()) {
913         result = pimpl->service_->GetSubUnitInfo(BluetoothRawAddress(device));
914     } else {
915         HILOGE("%{public}s: service is null or disable ", __func__);
916     }
917     HILOGD("%{public}s end.", __func__);
918 
919     return result;
920 }
921 
GetSupportedCompanies(const RawAddress & device)922 int32_t BluetoothAvrcpCtServer::GetSupportedCompanies(const RawAddress &device)
923 {
924     HILOGD("%{public}s start.", __func__);
925     int32_t result = 0;
926 
927     if (pimpl->IsEnabled()) {
928         result = pimpl->service_->GetSupportedCompanies(BluetoothRawAddress(device));
929     } else {
930         HILOGE("%{public}s: service is null or disable ", __func__);
931     }
932     HILOGD("%{public}s end.", __func__);
933 
934     return result;
935 }
936 
GetSupportedEvents(const RawAddress & device)937 int32_t BluetoothAvrcpCtServer::GetSupportedEvents(const RawAddress &device)
938 {
939     HILOGD("%{public}s start.", __func__);
940     int32_t result = 0;
941 
942     if (pimpl->IsEnabled()) {
943         result = pimpl->service_->GetSupportedEvents(device);
944     } else {
945         HILOGE("%{public}s: service is null or disable ", __func__);
946     }
947     HILOGD("%{public}s end.", __func__);
948 
949     return result;
950 }
951 
GetPlayerAppSettingAttributes(const RawAddress & device)952 int32_t BluetoothAvrcpCtServer::GetPlayerAppSettingAttributes(const RawAddress &device)
953 {
954     HILOGD("%{public}s start.", __func__);
955     int32_t result = 0;
956 
957     if (pimpl->IsEnabled()) {
958         result = pimpl->service_->GetPlayerAppSettingAttributes(BluetoothRawAddress(device));
959     } else {
960         HILOGE("%{public}s: service is null or disable ", __func__);
961     }
962     HILOGD("%{public}s end.", __func__);
963 
964     return result;
965 }
966 
GetPlayerAppSettingValues(const RawAddress & device,int32_t attribute)967 int32_t BluetoothAvrcpCtServer::GetPlayerAppSettingValues(const RawAddress &device, int32_t attribute)
968 {
969     HILOGD("%{public}s start.", __func__);
970     HILOGD("%{public}s: attribute = %{public}d", __func__, attribute);
971     int32_t result = 0;
972 
973     if (pimpl->IsEnabled()) {
974         result = pimpl->service_->GetPlayerAppSettingValues(BluetoothRawAddress(device), static_cast<uint8_t>(attribute));
975     } else {
976         HILOGE("%{public}s: service is null or disable ", __func__);
977     }
978     HILOGD("%{public}s end.", __func__);
979 
980     return result;
981 }
982 
GetPlayerAppSettingCurrentValue(const RawAddress & device,const std::vector<int32_t> & attributes)983 int32_t BluetoothAvrcpCtServer::GetPlayerAppSettingCurrentValue(const RawAddress &device,
984         const std::vector<int32_t> &attributes)
985 {
986     HILOGD("%{public}s start.", __func__);
987     int32_t result = 0;
988     std::vector<uint8_t> myAttributes;
989 
990     for (auto attribute : attributes) {
991         HILOGD("%{public}s: attribute = %{public}d", __func__, attribute);
992         myAttributes.push_back(static_cast<uint8_t>(attribute));
993     }
994 
995     if (pimpl->IsEnabled()) {
996         result = pimpl->service_->GetPlayerAppSettingCurrentValue(BluetoothRawAddress(device), myAttributes);
997     } else {
998         HILOGE("%{public}s: service is null or disable ", __func__);
999     }
1000     HILOGD("%{public}s end.", __func__);
1001 
1002     return result;
1003 }
1004 
SetPlayerAppSettingCurrentValue(const RawAddress & device,const std::vector<int32_t> & attributes,const std::vector<int32_t> & values)1005 int32_t BluetoothAvrcpCtServer::SetPlayerAppSettingCurrentValue(const RawAddress &device,
1006         const std::vector<int32_t> &attributes, const std::vector<int32_t> &values)
1007 {
1008     HILOGD("%{public}s start.", __func__);
1009     int32_t result = 0;
1010     std::vector<uint8_t> myAttributes;
1011     std::vector<uint8_t> myValues;
1012     for (auto attribute : attributes) {
1013         HILOGD("%{public}s: attribute = %{public}d", __func__, attribute);
1014         myAttributes.push_back(static_cast<uint8_t>(attribute));
1015     }
1016     for (auto value : values) {
1017         HILOGD("%{public}s: value = %{public}d", __func__, value);
1018         myValues.push_back(static_cast<uint8_t>(value));
1019     }
1020 
1021     if (pimpl->IsEnabled()) {
1022         result = pimpl->service_->SetPlayerAppSettingCurrentValue(BluetoothRawAddress(device), myAttributes, myValues);
1023     } else {
1024         HILOGE("%{public}s: service is null or disable ", __func__);
1025     }
1026     HILOGD("%{public}s end.", __func__);
1027 
1028     return result;
1029 }
1030 
GetPlayerAppSettingAttributeText(const RawAddress & device,const std::vector<int32_t> & attributes)1031 int32_t BluetoothAvrcpCtServer::GetPlayerAppSettingAttributeText(const RawAddress &device,
1032         const std::vector<int32_t> &attributes)
1033 {
1034     HILOGD("%{public}s start.", __func__);
1035     int32_t result = 0;
1036     if (pimpl->IsEnabled()) {
1037         std::vector<uint8_t> attrs;
1038         for (auto attribute : attributes) {
1039             HILOGD("%{public}s: attribute = %{public}d", __func__, attribute);
1040             attrs.push_back(static_cast<uint8_t>(attribute));
1041         }
1042 
1043         result = pimpl->service_->GetPlayerAppSettingAttributeText(BluetoothRawAddress(device), attrs);
1044     } else {
1045         HILOGE("%{public}s: service is null or disable ", __func__);
1046     }
1047     HILOGD("%{public}s end.", __func__);
1048 
1049     return result;
1050 }
1051 
GetPlayerAppSettingValueText(const RawAddress & device,int32_t attributes,const std::vector<int32_t> & values)1052 int32_t BluetoothAvrcpCtServer::GetPlayerAppSettingValueText(const RawAddress &device, int32_t attributes,
1053         const std::vector<int32_t> &values)
1054 {
1055     HILOGD("%{public}s start.", __func__);
1056     HILOGD("%{public}s: button = %{public}d", __func__, attributes);
1057     int32_t result = 0;
1058 
1059     if (pimpl->IsEnabled()) {
1060         std::vector<uint8_t> myValues;
1061         for (auto value : values) {
1062             HILOGD("%{public}s: value = %{public}d", __func__, value);
1063             myValues.push_back(static_cast<uint8_t>(value));
1064         }
1065 
1066         result =
1067             pimpl->service_->GetPlayerAppSettingValueText(BluetoothRawAddress(device), static_cast<uint8_t>(attributes), myValues);
1068     } else {
1069         HILOGE("%{public}s: service is null or disable ", __func__);
1070     }
1071     HILOGD("%{public}s end.", __func__);
1072 
1073     return result;
1074 }
1075 
GetElementAttributes(const RawAddress & device,const std::vector<int32_t> & attributes)1076 int32_t BluetoothAvrcpCtServer::GetElementAttributes(const RawAddress &device,
1077         const std::vector<int32_t> &attributes)
1078 {
1079     HILOGD("%{public}s start.", __func__);
1080     int32_t result = 0;
1081 
1082     if (pimpl->IsEnabled()) {
1083         std::vector<uint32_t> attrs;
1084         for (auto attribute : attributes) {
1085             HILOGD("%{public}s: attribute = %{public}d", __func__, attribute);
1086             attrs.push_back(static_cast<uint32_t>(attribute));
1087         }
1088 
1089         result =
1090             pimpl->service_->GetElementAttributes(BluetoothRawAddress(device), AVRC_ELEMENT_ATTRIBUTES_IDENTIFIER_PLAYING, attrs);
1091     } else {
1092         HILOGE("%{public}s: service is null or disable ", __func__);
1093     }
1094     HILOGD("%{public}s end.", __func__);
1095 
1096     return result;
1097 }
1098 
GetPlayStatus(const RawAddress & device)1099 int32_t BluetoothAvrcpCtServer::GetPlayStatus(const RawAddress &device)
1100 {
1101     HILOGD("%{public}s start.", __func__);
1102     int32_t result = 0;
1103 
1104     if (pimpl->IsEnabled()) {
1105         result = pimpl->service_->GetPlayStatus(BluetoothRawAddress(device));
1106     } else {
1107         HILOGE("%{public}s: service is null or disable ", __func__);
1108     }
1109     HILOGD("%{public}s end.", __func__);
1110 
1111     return result;
1112 }
1113 
PlayItem(const RawAddress & device,int32_t scope,int64_t uid,int32_t uidCounter)1114 int32_t BluetoothAvrcpCtServer::PlayItem(const RawAddress &device, int32_t scope, int64_t uid, int32_t uidCounter)
1115 {
1116     HILOGD("%{public}s start.", __func__);
1117     HILOGD("%{public}s: scope = %{public}d, uid = %{public}jd, uidCounter = %{public}d", __func__, scope, uid, uidCounter);
1118     int32_t result = 0;
1119 
1120     if (pimpl->IsEnabled()) {
1121         result = pimpl->service_->PlayItem(
1122             BluetoothRawAddress(device), static_cast<uint8_t>(scope),
1123             static_cast<uint64_t>(uid), static_cast<uint16_t>(uidCounter));
1124     } else {
1125         HILOGE("%{public}s: service is null or disable ", __func__);
1126     }
1127     HILOGD("%{public}s end.", __func__);
1128 
1129     return result;
1130 }
1131 
GetFolderItems(const RawAddress & device,int32_t startItem,int32_t endItem,const std::vector<int32_t> & attributes)1132 int32_t BluetoothAvrcpCtServer::GetFolderItems(const RawAddress &device, int32_t startItem, int32_t endItem,
1133         const std::vector<int32_t> &attributes)
1134 {
1135     HILOGD("%{public}s start.", __func__);
1136     HILOGD("%{public}s: startItem = %{public}d, endItem = %{public}d", __func__, startItem, endItem);
1137     int32_t result = 0;
1138     if (pimpl->IsEnabled()) {
1139         std::vector<uint32_t> attrs;
1140         for (auto attribute : attributes) {
1141             HILOGD("%{public}s: attribute = %{public}d,", __func__, attribute);
1142             attrs.push_back(static_cast<uint32_t>(attribute));
1143         }
1144         result = pimpl->service_->GetFolderItems(BluetoothRawAddress(device),
1145             AVRC_MEDIA_SCOPE_NOW_PLAYING,
1146             static_cast<uint32_t>(startItem),
1147             static_cast<uint32_t>(endItem),
1148             attrs);
1149     } else {
1150         HILOGE("%{public}s: service is null or disable ", __func__);
1151     }
1152     HILOGD("%{public}s end.", __func__);
1153 
1154     return result;
1155 }
1156 
GetTotalNumberOfItems(const RawAddress & device,int32_t scope)1157 int32_t BluetoothAvrcpCtServer::GetTotalNumberOfItems(const RawAddress &device, int32_t scope)
1158 {
1159     HILOGD("%{public}s start.", __func__);
1160     HILOGD("%{public}s: scope = %{public}d,", __func__, scope);
1161     int32_t result = 0;
1162 
1163     if (pimpl->IsEnabled()) {
1164         result = pimpl->service_->GetTotalNumberOfItems(BluetoothRawAddress(device), static_cast<uint8_t>(scope));
1165     } else {
1166         HILOGE("%{public}s: service is null or disable ", __func__);
1167     }
1168     HILOGD("%{public}s end.", __func__);
1169 
1170     return result;
1171 }
1172 
SetAbsoluteVolume(const RawAddress & device,int32_t volume)1173 int32_t BluetoothAvrcpCtServer::SetAbsoluteVolume(const RawAddress &device, int32_t volume)
1174 {
1175     HILOGD("%{public}s start.", __func__);
1176     HILOGD("%{public}s: volume = %{public}d,", __func__, volume);
1177     int32_t result = 0;
1178 
1179     if (pimpl->IsEnabled()) {
1180         result = pimpl->service_->SetAbsoluteVolume(BluetoothRawAddress(device), static_cast<uint8_t>(volume));
1181     } else {
1182         HILOGE("%{public}s: service is null or disable ", __func__);
1183     }
1184     HILOGD("%{public}s end.", __func__);
1185 
1186     return result;
1187 }
1188 
EnableNotification(const RawAddress & device,const std::vector<int32_t> & events,int32_t interval)1189 int32_t BluetoothAvrcpCtServer::EnableNotification(const RawAddress &device,
1190         const std::vector<int32_t> &events, int32_t interval)
1191 {
1192     HILOGD("%{public}s start.", __func__);
1193     HILOGD("%{public}s: interval = %{public}d,", __func__, interval);
1194     int32_t result = 0;
1195 
1196     std::vector<uint8_t> myEvents;
1197     for (auto event : events) {
1198         HILOGD("%{public}s: event = %{public}d,", __func__, event);
1199         myEvents.push_back(static_cast<uint8_t>(event));
1200     }
1201 
1202     if (pimpl->IsEnabled()) {
1203         result = pimpl->service_->EnableNotification(BluetoothRawAddress(device), myEvents, static_cast<uint32_t>(interval));
1204     } else {
1205         HILOGE("%{public}s: service is null or disable ", __func__);
1206     }
1207     HILOGD("%{public}s end.", __func__);
1208 
1209     return result;
1210 }
1211 
DisableNotification(const RawAddress & device,const std::vector<int32_t> & events)1212 int32_t BluetoothAvrcpCtServer::DisableNotification(const RawAddress &device, const std::vector<int32_t> &events)
1213 {
1214     HILOGD("%{public}s start.", __func__);
1215     int32_t result = 0;
1216 
1217     std::vector<uint8_t> myEvents;
1218     for (auto event : events) {
1219         HILOGD("%{public}s: event = %{public}d,", __func__, event);
1220         myEvents.push_back(static_cast<uint8_t>(event));
1221     }
1222 
1223     if (pimpl->IsEnabled()) {
1224         result = pimpl->service_->DisableNotification(BluetoothRawAddress(device), myEvents);
1225     } else {
1226         HILOGE("%{public}s: service is null or disable ", __func__);
1227     }
1228     HILOGD("%{public}s end.", __func__);
1229 
1230     return result;
1231 }
1232 
GetItemAttributes(const RawAddress & device,int64_t uid,int32_t uidCounter,const std::vector<int32_t> & attributes)1233 int32_t BluetoothAvrcpCtServer::GetItemAttributes(const RawAddress &device, int64_t uid, int32_t uidCounter,
1234         const std::vector<int32_t> &attributes)
1235 {
1236     HILOGD("%{public}s start.", __func__);
1237     HILOGD("%{public}s: uid = %{public}jd, uidCounter = %{public}d", __func__, uid, uidCounter);
1238     int32_t result = 0;
1239 
1240     std::vector<uint32_t> myAttribtues;
1241     for (auto attribue : attributes) {
1242         HILOGD("%{public}s: attribue = %{public}d", __func__, attribue);
1243         myAttribtues.push_back(static_cast<uint32_t>(attribue));
1244     }
1245 
1246     if (pimpl->IsEnabled()) {
1247         result = pimpl->service_->GetItemAttributes(
1248             BluetoothRawAddress(device), AVRC_MEDIA_SCOPE_NOW_PLAYING, (uint64_t)uid, (uint16_t)uidCounter, myAttribtues);
1249     } else {
1250         HILOGE("%{public}s: service is null or disable ", __func__);
1251     }
1252     HILOGD("%{public}s end.", __func__);
1253 
1254     return result;
1255 }
1256 
SetBrowsedPlayer(const RawAddress & device,int32_t playerId)1257 int32_t BluetoothAvrcpCtServer::SetBrowsedPlayer(const RawAddress &device, int32_t playerId)
1258 {
1259     HILOGD("%{public}s start.", __func__);
1260     HILOGD("%{public}s: playerId = %{public}d", __func__, playerId);
1261     int32_t result = 0;
1262 
1263     if (pimpl->IsEnabled()) {
1264         result = pimpl->service_->SetBrowsedPlayer(BluetoothRawAddress(device), (uint16_t)playerId);
1265     } else {
1266         HILOGE("%{public}s: service is null or disable ", __func__);
1267     }
1268     HILOGD("%{public}s end.", __func__);
1269 
1270     return result;
1271 }
1272 
GetMeidaPlayerList(const RawAddress & device,int32_t startItem,int32_t endItem)1273 int32_t BluetoothAvrcpCtServer::GetMeidaPlayerList(const RawAddress &device, int32_t startItem, int32_t endItem)
1274 {
1275     HILOGD("%{public}s start.", __func__);
1276     HILOGD("%{public}s: startItem = %{public}d, endItem = %{public}d", __func__, startItem, endItem);
1277     int32_t result = 0;
1278     std::vector<uint32_t> attrs;
1279 
1280     if (pimpl->IsEnabled()) {
1281         result = pimpl->service_->GetFolderItems(BluetoothRawAddress(device),
1282             AVRC_MEDIA_SCOPE_PLAYER_LIST,
1283             static_cast<uint32_t>(startItem),
1284             static_cast<uint32_t>(endItem),
1285             attrs);
1286     } else {
1287         HILOGE("%{public}s: service is null or disable ", __func__);
1288     }
1289     HILOGD("%{public}s end.", __func__);
1290 
1291     return result;
1292 }
1293 
1294 }  // namespace binder
1295 
1296 }  // namespace ipc