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