1 /*
2  * Copyright (C) 2021-2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef AVRCP_TG_PROFILE_H
17 #define AVRCP_TG_PROFILE_H
18 
19 #include <deque>
20 #include "avrcp_media.h"
21 #include "avrcp_tg_internal.h"
22 #include "avrcp_tg_state_machine.h"
23 #include "base_def.h"
24 #include "dispatcher.h"
25 #include "packet.h"
26 #include "raw_address.h"
27 
28 /**
29  * @brief The bluetooth subsystem.
30  */
31 namespace OHOS {
32 namespace bluetooth {
33 /**
34  * @brief This class provides a set of methods related to the role of the target described in the Audio/Video Remote
35  * Control profile.
36  */
37 class AvrcTgProfile {
38 public:
39     /**
40      * @brief This struct provides a set of pointers for informing the state change.
41      */
42     struct Observer {
43     public:
44         /**
45          * @brief Informs that the AVRCP TG profile is disabled.
46          */
47         std::function<void()> onDisabled;
48 
49         /**
50          * @brief Informs that the connection state is changed.
51          *
52          * @param[in] rawAddr The address of the bluetooth device.
53          * @param[in] state   The connection state. Refer to <b>BTConnectState</b>.
54          */
55         std::function<void(const RawAddress &rawAddr, int state)> onConnectionStateChanged;
56 
57         /**
58          * @brief Informs that want to find the AVRCP CT record of the specified device.
59          *
60          * @param[in] rawAddr The address of the peer bluetooth device.
61          */
62         std::function<void(const RawAddress &rawAddr)> findCtService;
63 
64         /**
65          * @brief Informs that the button is pressed.
66          *
67          * @param[in] rawAddr The address of the bluetooth device.
68          * @param[in] button  The value of the key operation.
69          * @param[in] label   The label which is used to distinguish different call.
70          */
71         std::function<void(const RawAddress &rawAddr, uint8_t button, uint8_t label)> onButtonPressed;
72 
73         /**
74          * @brief Informs that the button is released.
75          *
76          * @param[in] rawAddr The address of the bluetooth device.
77          * @param[in] button  The value of the key operation.
78          * @param[in] label   The label which is used to distinguish different call.
79          */
80         std::function<void(const RawAddress &rawAddr, uint8_t button, uint8_t label)> onButtonReleased;
81 
82         /**
83          * @brief Informs that the button is held.
84          *
85          * @param[in] rawAddr The address of the bluetooth device.
86          * @param[in] button  The value of the key operation.
87          * @param[in] label   The label which is used to distinguish different call.
88          */
89         std::function<void(const RawAddress &rawAddr, uint8_t button, uint8_t label)> onButtonHeld;
90 
91         /**
92          * @brief Responds the command of the <b>GetCapabilities</b>.
93          *
94          * @param[in] rawAddr      The address of the bluetooth device.
95          * @param[in] label        The label which is used to distinguish different call.
96          */
97         std::function<void(const RawAddress &rawAddr, uint8_t label)> getCapabilities;
98 
99         /**
100          * @brief Responds the command of the <b>ListPlayerApplicationSettingAttributes</b>.
101          *
102          * @param[in] rawAddr   The address of the bluetooth device.
103          * @param[in] label     The label which is used to distinguish different call.
104          */
105         std::function<void(const RawAddress &rawAddr, uint8_t label)> listPlayerApplicationSettingAttributes;
106 
107         /**
108          * @brief Responds the command of the <b>ListPlayerApplicationSettingValues</b>.
109          *
110          * @param[in] rawAddr   The address of the bluetooth device.
111          * @param[in] attribute The attribute of the player application setting. Refer to <b>AvrcPlayerAttribute</b>.
112          * @param[in] label     The label which is used to distinguish different call.
113          */
114         std::function<void(const RawAddress &rawAddr, uint8_t attribute, uint8_t label)>
115             listPlayerApplicationSettingValues;
116 
117         /**
118          * @brief Responds the command of the <b>ListPlayerApplicationSettingValues</b>.
119          *
120          * @param[in] rawAddr    The address of the bluetooth device.
121          * @param[in] attributes The attribute of the player application settings. Refer to <b>AvrcPlayerAttribute</b>.
122          * @param[in] label      The label which is used to distinguish different call.
123          * @param[in] context    The context which is used to distinguish different purpose.
124          */
125         std::function<void(
126             const RawAddress &rawAddr, const std::deque<uint8_t> &attributes, uint8_t label, uint8_t context)>
127             getCurrentPlayerApplicationSettingValue;
128 
129         /**
130          * @brief Responds the command of the <b>SetPlayerApplicationSettingValue</b>.
131          *
132          * @param[in] rawAddr    The address of the bluetooth device.
133          * @param[in] attributes The attribute of the player application settings. Refer to <b>AvrcPlayerAttribute</b>.
134          * @param[in] values     The value of the player application setting attributes.
135          * @param[in] label      The label which is used to distinguish different call.
136          */
137         std::function<void(const RawAddress &rawAddr, const std::deque<uint8_t> &attributes,
138             const std::deque<uint8_t> &values, uint8_t label)>
139             setPlayerApplicationSettingValue;
140 
141         /**
142          * @brief Responds the command of the <b>GetPlayerApplicationSettingAttributeText</b>.
143          *
144          * @param[in] rawAddr    The address of the bluetooth device.
145          * @param[in] attributes The attribute of the player application settings.
146          * @param[in] label      The label which is used to distinguish different call.
147          */
148         std::function<void(const RawAddress &rawAddr, const std::vector<uint8_t> &attributes, uint8_t label)>
149             getPlayerApplicationSettingAttributeText;
150 
151         /**
152          * @brief Responds the command of the <b>GetPlayerApplicationSettingValueText</b>.
153          *
154          * @param[in] rawAddr     The address of the bluetooth device.
155          * @param[in] attributeId Player application setting attribute ID.
156          * @param[in] values      Player application setting value ID.
157          * @param[in] label       The label which is used to distinguish different call.
158          */
159         std::function<void(
160             const RawAddress &rawAddr, uint8_t attributeId, const std::vector<uint8_t> &values, uint8_t label)>
161             getPlayerApplicationSettingValueText;
162 
163         /**
164          * @brief Responds the command of the <b>GetElementAttribtues</b>.
165          *
166          * @param[in] rawAddr    The address of the bluetooth device.
167          * @param[in] identifier Unique identifier to identify an element on TG.
168          * @param[in] attributes  Specifies the attribute ID for the attributes to be retrieved.
169          * @param[in] label      The label which is used to distinguish different call.
170          */
171         std::function<void(
172             const RawAddress &rawAddr, uint64_t identifier, const std::vector<uint32_t> &attributes, uint8_t label)>
173             getElementAttributes;
174 
175         /**
176          * @brief Responds the command of the <b>GetPlayStatus</b>.
177          *
178          * @param[in] rawAddr The address of the bluetooth device.
179          * @param[in] label   The label which is used to distinguish different call.
180          * @param[in] context The context which is used to distinguish different purpose.
181          */
182         std::function<void(const RawAddress &rawAddr, uint8_t label, uint8_t context)> getPlayStatus;
183 
184         /**
185          * @brief Responds the command of the <b>SetAddressedPlayer</b>.
186          *
187          * @param[in] rawAddr    The address of the bluetooth device.
188          * @param[in] playerId   The unique media player id.
189          * @param[in] uidCounter The value of the uid counter.
190          * @param[in] label      The label which is used to distinguish different call.
191          */
192         std::function<void(const RawAddress &rawAddr, uint16_t playerId, uint16_t uidCounter, uint8_t label)>
193             setAddressedPlayer;
194 
195         /**
196          * @brief Responds the command of the <b>SetBrowsedPlayer</b>.
197          *
198          * @param[in] rawAddr    The address of the bluetooth device.
199          * @param[in] playerId   The unique media player id.
200          * @param[in] uidCounter The value of the uid counter.
201          * @param[in] label      The label which is used to distinguish different call.
202          */
203         std::function<void(const RawAddress &rawAddr, uint16_t playerId, uint16_t uidCounter, uint8_t label)>
204             setBrowsedPlayer;
205 
206         /**
207          * @brief Responds the command of the <b>ChangePath</b>.
208          *
209          * @param[in] rawAddr    The address of the bluetooth device.
210          * @param[in] uidCounter The value of the uid counter.
211          * @param[in] direction  The flag of the navigation. Refer to <b>bluetooth::AvrcFolderDirection</b>.
212          * @param[in] folderUid  The UID of the folder to navigate to. This may be retrieved via a GetFolderItems
213          * command. If the navigation command is Folder Up this field is reserved.
214          * @param[in] label      The label which is used to distinguish different call.
215          */
216         std::function<void(
217             const RawAddress &rawAddr, uint16_t uidCounter, uint8_t direction, uint64_t folderUid, uint8_t label)>
218             changePath;
219 
220         /**
221          * @brief Responds the command of the <b>GetFolderItems</b>.
222          *
223          * @param[in] rawAddr    The address of the bluetooth device.
224          * @param[in] scope      The scope in which media content navigation may take place. Refer to
225          * <b>AvrcMediaScope</b>.
226          * @param[in] startItem  The offset within the listing of the item, which should be the first returned item. The
227          * first element in the listing is at offset 0.
228          * @param[in] endItem    The offset within the listing of the item which should be the final returned item. If
229          * this is set to a value beyond what is available, the TG shall return items from the provided Start Item index
230          * to the index of the final item. If the End Item index is smaller than the Start Item index, the TG shall
231          * return an error. If CT requests too many items, TG can respond with a sub-set of the requested items.
232          * @param[in] attributes The list of media attributes.
233          * @param[in] label      The label which is used to distinguish different call.
234          */
235         std::function<void(const RawAddress &rawAddr, uint8_t scope, uint32_t startItem, uint32_t endItem,
236             const std::vector<uint32_t> &attributes, uint8_t label)>
237             getFolderItems;
238 
239         /**
240          * @brief Responds the command of the <b>GetItemAttributes</b>.
241          *
242          * @param[in] rawAddr    The address of the bluetooth device.
243          * @param[in] scope      The scope in which media content navigation may take place. Refer to
244          * <b>AvrcMediaScope</b>.
245          * @param[in] uid        The UID of the media element item or folder item.
246          * @param[in] uidCounter The UID Counter.
247          * @param[in] attributes The list of media attributes.
248          * @param[in] label      The label which is used to distinguish different call.
249          */
250         std::function<void(const RawAddress &rawAddr, uint8_t scope, uint64_t uid, uint16_t uidCounter,
251             const std::vector<uint32_t> &attributes, uint8_t label)>
252             getGetItemAttributes;
253 
254         /**
255          * @brief Responds the command of the <b>GetTotalNumberOfItems</b>.
256          *
257          * @param[in] rawAddr    The address of the bluetooth device.
258          * @param[in] scope      The scope in which media content navigation may take place. Refer to
259          * <b>AvrcMediaScope</b>.
260          * @param[in] label      The label which is used to distinguish different call.
261          */
262         std::function<void(const RawAddress &rawAddr, uint8_t scope, uint8_t label)> getTotalNumberOfItems;
263 
264         /**
265          * @brief Informs that receive the command of the <b>PlayItem</b>.
266          *
267          * @param[in] rawAddr    The address of the bluetooth device.
268          * @param[in] scope      The scope in which media content navigation may take place. Refer to
269          * <b>AvrcMediaScope</b>.
270          * @param[in] uid        The UID of the media element item or folder item.
271          * @param[in] uidCounter The UID Counter.
272          * @param[in] label      The label which is used to distinguish different call.
273          */
274         std::function<void(const RawAddress &rawAddr, uint8_t scope, uint64_t uid, uint16_t uidCounter, uint8_t label)>
275             playItem;
276 
277         /**
278          * @brief Responds the command of the <b>AddToNowPlaying</b>.
279          *
280          * @param[in] rawAddr    The address of the bluetooth device.
281          * @param[in] scope      The scope in which media content navigation may take place. Refer to
282          * <b>AvrcMediaScope</b>.
283          * @param[in] uid        The UID of the media element item or folder item.
284          * @param[in] uidCounter The UID Counter.
285          * @param[in] label      The label which is used to distinguish different call.
286          */
287         std::function<void(const RawAddress &rawAddr, uint8_t scope, uint64_t uid, uint16_t uidCounter, uint8_t label)>
288             addToNowPlaying;
289 
290         /**
291          * @brief Responds the command of the <b>SetAbsoluteVolume</b>.
292          *
293          * @param[in] rawAddr The address of the bluetooth device.
294          * @param[in] volume  The percentage of the absolute volume. Refer to <b>AvrcAbsoluteVolume</b>.
295          * @param[in] label   The label which is used to distinguish different call.
296          */
297         std::function<void(const RawAddress &rawAddr, uint8_t volume, uint8_t label)> setAbsoluteVolume;
298 
299         /**
300          * @brief Responds the command of the <b>EVENT_TRACK_CHANGED</b>.
301          *
302          * @param[in] rawAddr  The address of the bluetooth device.
303          * @return The id of the addressed player.
304          */
305         std::function<void(const RawAddress &rawAddr, uint8_t label)> getSelectedTrack;
306 
307         /**
308          * @brief Responds the command of the <b>EVENT_ADDRESSED_PLAYER_CHANGED</b>.
309          *
310          * @param[in] rawAddr  The address of the bluetooth device.
311          * @return The id of the addressed player.
312          */
313         std::function<void(const RawAddress &rawAddr, uint8_t label)> getAddressedPlayer;
314 
315         /**
316          * @brief Responds the command of the <b>EVENT_UIDS_CHANGED</b>.
317          *
318          * @param[in] rawAddr  The address of the bluetooth device.
319          * @return The id of the current playing item.
320          */
321         std::function<void(const RawAddress &rawAddr, uint8_t label)> getUidCounter;
322 
323         /**
324          * @brief Responds the command of the <b>EVENT_ VOLUME_CHANGED</b>.
325          *
326          * @param[in] rawAddr  The address of the bluetooth device.
327          * @return The id of the current playing item.
328          */
329         std::function<void(const RawAddress &rawAddr, uint8_t label)> getCurrentAbsoluteVolume;
330 
331         /**
332          * @brief Responds the command of the <b>RegisterNotification</b>.
333          *
334          * @param[in] rawAddr  The address of the bluetooth device.
335          * @param[in] interval The specifies the time interval (in seconds) at which the change in playback position
336          * will be notified. If the song is being forwarded / rewound, a notification will be received whenever the
337          * playback position will change by this value.
338          */
339         std::function<void(const RawAddress &rawAddr, uint32_t interval)> setPlaybackInterval;
340 
341         /**
342          * @brief Sets the address of the active bluetooth device.
343          *
344          * @param[in] rawAddr  The address of the bluetooth device.
345          */
346         std::function<void(const RawAddress &rawAddr)> setActiveDevice;
347     };
348 
349     /**
350      * @brief A constructor used to create an <b>AvrcTgProfile</b> instance.
351      */
352     AvrcTgProfile(uint16_t features, uint32_t companyId, uint16_t controlMtu, uint16_t browseMtu,
353         utility::Dispatcher *dispatcher, AvctChannelEventCallback eventCallback, AvctMsgCallback msgCallback);
354 
355     /**
356      * @brief A destructor used to delete the <b>AvrcTgProfile</b> instance.
357      */
358     ~AvrcTgProfile();
359 
360     /******************************************************************
361      * REGISTER / UNREGISTER OBSERVER                                 *
362      ******************************************************************/
363 
364     /**
365      * @brief Registers the observer.
366      *
367      * @param observer The pointer to the instance of the <b>AvrcTgProfile::Observer</b> struct.
368      */
369     void RegisterObserver(AvrcTgProfile::Observer *observer);
370 
371     /**
372      * @brief Unregisters the observer.
373      */
374     void UnregisterObserver(void);
375 
376     /******************************************************************
377      * ENABLE / DISABLE                                               *
378      ******************************************************************/
379 
380     /**
381      * @brief Enables the AVRCP TG profile.
382      *
383      * @return The result of the method execution.
384      * @retval BT_SUCCESS   Execute success.
385      * @retval RET_BAD_STATUS Execute failure.
386      */
387     int Enable(void);
388 
389     /**
390      * @brief Disables the AVRCP TG profile.
391      *
392      * @return The result of the method execution.
393      * @retval BT_SUCCESS   Execute success.
394      * @retval RET_BAD_STATUS Execute failure.
395      */
396     int Disable(void);
397 
398     /**
399      * @brief Sets the flag of the profile enabled or not.
400      *
401      * @param[in] isEnabled The service is enabled or not.
402      *            @a true  : The service is enabled.<br>
403      *            @a false : The service is disabled.<br>
404      */
405     static void SetEnableFlag(bool isEnabled);
406 
407     /******************************************************************
408      * CONNECTION                                                     *
409      ******************************************************************/
410 
411     /**
412      * @brief Sets the active device.
413      *
414      * @detail Only one CT can interact witch TG.
415      */
416     void SetActiveDevice(const RawAddress &rawAddr);
417 
418     /**
419      * @brief Gets the connected devices.
420      *
421      * @return The list of the instance of the <b>RawAddress</b> class.
422      */
423     std::vector<RawAddress> GetConnectedDevices(void);
424 
425     /**
426      * @brief Gets the devices of the specified states.
427      *
428      * @param[in] states The connection states. Refer to <b>BTConnectState</b>.
429      * @return The list of the instance of the <b>RawAddress</b> class.
430      */
431     std::vector<RawAddress> GetDevicesByStates(const std::vector<int> &states);
432 
433     /**
434      * @brief Gets the connection state of the specified bluetooth device.
435      *
436      * @param[in] rawAddr The address of the bluetooth device.
437      * @return The connection state. Refer to <b>BTConnectState</b>.
438      */
439     int GetDeviceState(const RawAddress &rawAddr);
440 
441     /**
442      * @brief Gets the maximum number of connections.
443      *
444      * @return The maximum number of connections.
445      */
446     int GetMaxConnectNum(void);
447 
448     /**
449      * @brief Connects to the connection of the control channel.
450      *
451      * @param[in] rawAddr The address of the bluetooth device.
452      * @return The result of the method execution.
453      * @retval BT_SUCCESS   Execute success.
454      * @retval RET_BAD_STATUS Execute failure.
455      */
456     int Connect(const RawAddress &rawAddr) const;
457 
458     /**
459      * @brief Connects to the connection of the browse channel.
460      *
461      * @param[in] rawAddr The address of the bluetooth device.
462      * @return The result of the method execution.
463      * @retval BT_SUCCESS   Execute success.
464      * @retval RET_BAD_STATUS Execute failure.
465      */
466     static int ConnectBr(const RawAddress &rawAddr);
467 
468     /**
469      * @brief Disconnects the connection of the control channel.
470      *
471      * @param[in] rawAddr The address of the bluetooth device.
472      * @return The result of the method execution.
473      * @retval BT_SUCCESS   Execute success.
474      * @retval RET_BAD_STATUS Execute failure.
475      */
476     int Disconnect(const RawAddress &rawAddr) const;
477 
478     /**
479      * @brief Disconnects the connection of the browse channel.
480      *
481      * @param[in] rawAddr The address of the bluetooth device.
482      * @return The result of the method execution.
483      * @retval BT_SUCCESS   Execute success.
484      * @retval RET_BAD_STATUS Execute failure.
485      */
486     static int DisconnectBr(const RawAddress &rawAddr);
487 
488     /**
489      * @brief Gets the connection states.
490      *
491      * @return The connection states. The values are in bits.
492      */
493     int GetConnectState(void);
494 
495     /**
496      * @brief Accepts the passive connection.
497      *
498      * @param[in] rawAddr The address of the bluetooth device.
499      */
500     static void AcceptPassiveConnect(const RawAddress &rawAddr);
501 
502     /**
503      * @brief Rejects the passive connection.
504      *
505      * @param[in] rawAddr The address of the bluetooth device.
506      */
507     void RejectPassiveConnect(const RawAddress &rawAddr);
508 
509     /******************************************************************
510      * PASS THROUGH COMMAND                                           *
511      ******************************************************************/
512 
513     /**
514      * @brief Sends the press response of the <b>PASS THROUGH</b>.
515      *
516      * @param[in] rawAddr The address of the bluetooth device.
517      * @param[in] button  The value of the key operation. Refer to <b>AvrcKeyOperation</b>.
518      * @param[in] label   The label which is used to distinguish different call.
519      * @param[in] result  Whether accepted the key operation.
520      *            @a true  : Accepted.
521      *            @a false : Rejected.
522      */
523     void SendPressButtonRsp(const RawAddress &rawAddr, uint8_t button, uint8_t label, int result);
524 
525     /**
526      * @brief Sends the release response of the <b>PASS THROUGH</b>.
527      *
528      * @param[in] rawAddr The address of the bluetooth device.
529      * @param[in] button  The value of the key operation. Refer to <b>AvrcKeyOperation</b>.
530      * @param[in] label   The label which is used to distinguish different call.
531      * @param[in] result  Whether accepted the key operation.
532      *            @a true  : Accepted.
533      *            @a false : Rejected.
534      */
535     void SendReleaseButtonRsp(const RawAddress &rawAddr, uint8_t button, uint8_t label, int result);
536 
537     /******************************************************************
538      * VENDOR COMMAND                                                 *
539      ******************************************************************/
540 
541     /**
542      * @brief Sends the response of the <b>GetCapabilities</b>.
543      *
544      * @details This is sent by CT to get the capabilities of the peer device.
545      * @param[in] rawAddr      The address of the bluetooth device.
546      * @param[in] capabilityId Specific capability requested.
547      * @param[in] companies    The list of CompanyId.
548      * @param[in] events       The list of EventIds.
549      * @param[in] label        The label which is used to distinguish different call.
550      * @param[in] result       The result of calling the <b>ListPlayerApplicationSettingAttributes</b>.
551      *            @a BT_SUCCESS   : Accepted.
552      *            @a RET_NO_SUPPORT : Not support.
553      *            @a RET_BAD_STATUS : Rejected.
554      */
555     void SendGetCapabilitiesRsp(
556         const RawAddress &rawAddr, const std::vector<uint32_t> &companies, uint8_t label, int result);
557     void SendGetCapabilitiesRsp(
558         const RawAddress &rawAddr, const std::vector<uint8_t> &events, uint8_t label, int result);
559 
560     /**
561      * @brief Sends the response of the <b>ListPlayerApplicationSettingAttributes</b>.
562      *
563      * @param[in] rawAddr    The address of the bluetooth device.
564      * @param[in] attributes The attribute of the player application settings.
565      * @param[in] label      The label which is used to distinguish different call.
566      * @param[in] result     The result of calling the <b>ListPlayerApplicationSettingAttributes</b>.
567      *            @a BT_SUCCESS   : Accepted.
568      *            @a RET_NO_SUPPORT : Not support.
569      *            @a RET_BAD_STATUS : Rejected.
570      */
571     void SendListPlayerApplicationSettingAttributesRsp(
572         const RawAddress &rawAddr, std::deque<uint8_t> attributes, uint8_t label, int result);
573 
574     /**
575      * @brief Sends the response of the <b>ListPlayerApplicationSettingValues</b>.
576 
577      * @param[in] rawAddr The address of the bluetooth device.
578      * @param[in] values  The value of the player application setting attribute.
579      * @param[in] label   The label which is used to distinguish different call.
580      * @param[in] result  The result of calling the <b>ListPlayerApplicationSettingValues</b>.
581      *            @a BT_SUCCESS   : Accepted.
582      *            @a RET_NO_SUPPORT : Not support.
583      *            @a RET_BAD_STATUS : Rejected.
584      */
585     void SendListPlayerApplicationSettingValuesRsp(
586         const RawAddress &rawAddr, const std::deque<uint8_t> &values, uint8_t label, int result);
587 
588     /**
589      * @brief Sends the response of the <b>GetCurrentPlayerApplicationSettingValue</b>.
590 
591      * @param[in] rawAddr    The address of the bluetooth device.
592      * @param[in] attributes The attribute of the player application settings.
593      * @param[in] values     The value of the player application setting attribute.
594      * @param[in] label      The label which is used to distinguish different call.
595      * @param[in] result     The result of calling the <b>ListPlayerApplicationSettingValues</b>.
596      *            @a BT_SUCCESS   : Accepted.
597      *            @a RET_NO_SUPPORT : Not support.
598      *            @a RET_BAD_STATUS : Rejected.
599      */
600     void SendGetCurrentPlayerApplicationSettingValueRsp(const RawAddress &rawAddr,
601         const std::deque<uint8_t> &attributes, const std::deque<uint8_t> &values, uint8_t label, int result);
602 
603     /**
604      * @brief Sends the response of the <b>SetPlayerApplicationSettingValue</b>.
605 
606      * @param[in] rawAddr    The address of the bluetooth device.
607      * @param[in] label      The label which is used to distinguish different call.
608      * @param[in] result     The result of calling the <b>ListPlayerApplicationSettingValues</b>.
609      *            @a BT_SUCCESS   : Accepted.
610      *            @a RET_NO_SUPPORT : Not support.
611      *            @a RET_BAD_STATUS : Rejected.
612      */
613     void SendSetPlayerApplicationSettingValueRsp(const RawAddress &rawAddr, uint8_t label, int result);
614 
615     /**
616      * @brief Sends the response of the <b>GetPlayerApplicationSettingAttributeText</b>.
617 
618      * @param[in] rawAddr    The address of the bluetooth device.
619      * @param[in] attributes The attribute of the player application settings.
620      * @param[in] attrStr    The values associated witch the attribute.
621      * @param[in] label      The label which is used to distinguish different call.
622      * @param[in] result     The result of calling the <b>ListPlayerApplicationSettingValues</b>.
623      *            @a BT_SUCCESS   : Accepted.
624      *            @a RET_NO_SUPPORT : Not support.
625      *            @a RET_BAD_STATUS : Rejected.
626      */
627     void SendGetPlayerApplicationSettingAttributeTextRsp(const RawAddress &rawAddr,
628         const std::vector<uint8_t> &attributes, const std::vector<std::string> &attrStr, uint8_t label, int result);
629 
630     /**
631      * @brief Sends the response of the <b>GetPlayerApplicationSettingValueText</b>.
632 
633      * @param[in] rawAddr    The address of the bluetooth device.
634      * @param[in] values     Player application setting value ID for which the text is returned.
635      * @param[in] valueStr   Specifies the player application setting value string.
636      * @param[in] label      The label which is used to distinguish different call.
637      * @param[in] result     The result of calling the <b>ListPlayerApplicationSettingValues</b>.
638      *            @a BT_SUCCESS   : Accepted.
639      *            @a RET_NO_SUPPORT : Not support.
640      *            @a RET_BAD_STATUS : Rejected.
641      */
642     void SendGetPlayerApplicationSettingValueTextRsp(const RawAddress &rawAddr, const std::vector<uint8_t> &values,
643         const std::vector<std::string> &valueStr, uint8_t label, int result);
644 
645     /**
646      * @brief Responds the data of the <b>GetElementAttributes</b>.
647      *
648      * @details Switch to the thread of the AVRCP CT service in this function.
649      * @param[in] rawAddr    The address of the bluetooth device.
650      * @param[in] attributes Specifies the attribute ID for the attributes to be retrieved.
651      * @param[in] values     The list of the value of this attribute.
652      * @param[in] label      The label which is used to distinguish different call.
653      * @param[in] result     The result of calling the <b>ListPlayerApplicationSettingValues</b>.
654      *            @a BT_SUCCESS   : Accepted.
655      *            @a RET_NO_SUPPORT : Not support.
656      *            @a RET_BAD_STATUS : Rejected.
657      */
658     void SendGetElementAttributesRsp(const RawAddress &rawAddr, const std::vector<uint32_t> &attribtues,
659         const std::vector<std::string> &values, uint8_t label, int result);
660 
661     /**
662      * @brief Sends the response of the <b>GetPlayStatus</b>.
663      *
664      * @param[in] rawAddr      The address of the bluetooth device.
665      * @param[in] songLength   The total length of the playing song in milliseconds.
666      * @param[in] songPosition The current position of the playing in milliseconds elapsed.
667      * @param[in] playStatus   The current status of playing. Refer to <b>AvrcPlayStatus</b>.
668      * @param[in] label        The label which is used to distinguish different call.
669      * @param[in] result       The result of calling the <b>GetPlayStatus</b>.
670      *            @a BT_SUCCESS   : Accepted.
671      *            @a RET_NO_SUPPORT : Not support.
672      *            @a RET_BAD_STATUS : Rejected.
673      */
674     void SendGetPlayStatusRsp(const RawAddress &rawAddr, uint32_t songLength, uint32_t songPosition, uint8_t playStatus,
675         uint8_t label, int result);
676 
677     /**
678      * @brief Sends the response of the <b>SetAddressedPlayer</b>.
679      *
680      * @param[in] rawAddr The address of the bluetooth device.
681      * @param[in] status  The detail result of the execution. Refer to <b>AvrcEsCode</b>.<br>
682      *            @a AVRC_ES_CODE_NO_ERROR<br>
683      *            @a AVRC_ES_CODE_INTERNAL_ERROR<br>
684      *            @a AVRC_ES_CODE_UID_CHANGED<br>
685      *            @a AVRC_ES_CODE_INVALID_PLAYER_ID<br>
686      *            @a AVRC_ES_CODE_NO_AVAILABLE_PLAYERS
687      * @param[in] label   The label which is used to distinguish different call.
688      * @param[in] result  The result of calling the <b>SetAddressedPlayer</b>.
689      *            @a BT_SUCCESS   : Accepted.
690      *            @a RET_NO_SUPPORT : Not support.
691      *            @a RET_BAD_STATUS : Rejected.
692      */
693     void SendSetAddressedPlayerRsp(const RawAddress &rawAddr, int status, uint8_t label, int result);
694 
695     /**
696      * @brief Sends the response of the <b>PlayItem</b>.
697      *
698      * @param[in] rawAddr The address of the bluetooth device.
699      * @param[in] status  The current status of media. Refer to <b>AvrcEsCode</>.<br>
700      *            @a AVRC_ES_CODE_INVALID_COMMAND<br>
701      *            @a AVRC_ES_CODE_INTERNAL_ERROR<br>
702      *            @a AVRC_ES_CODE_INVALID_PARAMETER<br>
703      *            @a AVRC_ES_CODE_PARAMETER_CONTENT_ERROR<br>
704      *            @a AVRC_ES_CODE_NO_ERROR<br>
705      *            @a AVRC_ES_CODE_UID_CHANGED<br>
706      *            @a AVRC_ES_CODE_RESERVED<br>
707      *            @a AVRC_ES_CODE_DOES_NOT_EXIST<br>
708      *            @a AVRC_ES_CODE_INVALID_SCOPE
709      *            @a AVRC_ES_CODE_FOLDER_ITEM_IS_NOT_PLAYABLE
710      *            @a AVRC_ES_CODE_MEDIA_IN_USE
711      *            @a AVRC_ES_CODE_NO_AVAILABLE_PLAYERS
712      *            @a AVRC_ES_CODE_FOLDER_ITEM_IS_NOT_PLAYABLE
713      * @param[in] label   The label which is used to distinguish different call.
714      * @param[in] result  The result of calling the <b>PlayItem</b>.
715      *            @a BT_SUCCESS   : Accepted.
716      *            @a RET_NO_SUPPORT : Not support.
717      *            @a RET_BAD_STATUS : Rejected.
718      */
719     void SendPlayItemRsp(const RawAddress &rawAddr, int status, uint8_t label, int result);
720 
721     /**
722      * @brief Sends the response of the <b>AddToNowPlaying</b>.
723      *
724      * @param[in] rawAddr The address of the bluetooth device.
725      * @param[in] status  The detail result of the execution. Refer to <b>AvrcEsCode</b>.<br>
726      *            @a AVRC_ES_CODE_NO_ERROR<br>
727      *            @a AVRC_ES_CODE_INTERNAL_ERROR<br>
728      *            @a AVRC_ES_CODE_UID_CHANGED<br>
729      *            @a AVRC_ES_CODE_DOES_NOT_EXIST<br>
730      *            @a AVRC_ES_CODE_INVALID_SCOPE<br>
731      *            @a AVRC_ES_CODE_FOLDER_ITEM_IS_NOT_PLAYABLE<br>
732      *            @a AVRC_ES_CODE_MEDIA_IN_USE<br>
733      *            @a AVRC_ES_CODE_NOW_PLAYING_LIST_FULL<br>
734      *            @a AVRC_ES_CODE_NO_AVAILABLE_PLAYERS
735      * @param[in] label   The label which is used to distinguish different call.
736      * @param[in] result  The result of calling the <b>AddToNowPlaying</b>.
737      *            @a BT_SUCCESS   : Accepted.
738      *            @a RET_NO_SUPPORT : Not support.
739      *            @a RET_BAD_STATUS : Rejected.
740      */
741     void SendAddToNowPlayingRsp(const RawAddress &rawAddr, int status, uint8_t label, int result);
742 
743     /**
744      * @brief Sends the response of the <b>SetAbsoluteVolume</b>.
745      *
746      * @param[in] rawAddr The address of the bluetooth device.
747      * @param[in] volume  The percentage of the absolute volume. Refer to <b>AvrcAbsoluteVolume</b>.
748      * @param[in] label   The label which is used to distinguish different call.
749      * @param[in] result  The result of calling the <b>SetAbsoluteVolume</b>.
750      *            @a BT_SUCCESS   : Accepted.
751      *            @a RET_NO_SUPPORT : Not support.
752      *            @a RET_BAD_STATUS : Rejected.
753      */
754     void SendSetAbsoluteVolumeRsp(const RawAddress &rawAddr, uint8_t volume, uint8_t label, int result);
755 
756     /**
757      * @brief Sends the response of the <b>EVENT_PLAYBACK_STATUS_CHANGED</b>.
758      *
759      * @param[in] playStatus Indicates the current status of playback.
760      * @param[in] label      The label which is used to distinguish different call.
761      * @param[in] result  The result of calling the <b>SetAbsoluteVolume</b>.
762      *            @a BT_SUCCESS   : Accepted.
763      *            @a RET_NO_SUPPORT : Not support.
764      *            @a RET_BAD_STATUS : Rejected.
765      */
766     void SendPlaybackStatusChangedRsp(bool isInterim, uint8_t playStatus, uint8_t label, int result);
767 
768     /**
769      * @brief Sends the response of the <b>EVENT_TRACK_CHANGED</b>.
770      *
771      * @param[in] rawAddr    The address of the bluetooth device.
772      * @param[in] Identifier Unique Identifier to identify an element on TG, as is used for GetElementAttribute command
773      * in case Browsing is not supported and GetItemAttribute command in case Browsing is supported.
774      * @param[in] label      The label which is used to distinguish different call.
775      */
776     void SendTrackChangedRsp(bool isInterim, uint64_t identifier, uint8_t label, int result);
777 
778     void SendTrackReachedEndRsp(bool isInterim, uint8_t label, int result);
779     void SendTrackReachedStartRsp(bool isInterim, uint8_t label, int result);
780 
781     /**
782      * @brief Sends the response of the <b>EVENT_PLAYBACK_POS_CHANGED</b>.
783      *
784      * @param[in] rawAddr     The address of the bluetooth device.
785      * @param[in] playbackPos Current playback position in millisecond.
786      * @param[in] label       The label which is used to distinguish different call.
787      */
788     void SendPlaybackPosChangedRsp(bool isInterim, uint32_t playbackPos, uint8_t label, int result);
789 
790     /**
791      * @brief Sends the response of the <b>EVENT_PLAYER_APPLICATION_SETTING_CHANGED</b>.
792      *
793      * @param[in] rawAddr    The address of the bluetooth device.
794      * @param[in] attributes Player application setting attribute ID for which the value is returned.
795      * @param[in] values     Currently set Player Application Setting value on the TG for the above attributes.
796      * @param[in] label      The label which is used to distinguish different call.
797      */
798     void SendPlayerApplicationSettingChangedRsp(bool isInterim, const std::deque<uint8_t> &attributes,
799         const std::deque<uint8_t> &values, uint8_t label, int result);
800 
801     void SendNowPlayingContentChangedRsp(bool isInterim, uint8_t label, int result);
802 
803     void SendAvailablePlayersChangedRsp(bool isInterim, uint8_t label, int result);
804     /**
805      * @brief Sends the response of the <b>EVENT_ADDRESSED_PLAYER_CHANGED</b>.
806      *
807      * @param[in] rawAddr    The address of the bluetooth device.
808      * @param[in] playerId   The player id.
809      * @param[in] uidCounter The uid counter.
810      * @param[in] label      The label which is used to distinguish different call.
811      */
812     void SendAddressedPlayerChangedRsp(
813         bool isInterim, uint16_t playerId, uint16_t uidCounter, uint8_t label, int result);
814 
815     /**
816      * @brief Sends the response of the <b>EVENT_UIDS_CHANGED</b>.
817      *
818      * @param[in] rawAddr The address of the bluetooth device.
819      * @param[in] uid     The uid.
820      */
821     void SendUidsChangedRsp(bool isInterim, uint16_t uidCounter, uint8_t label, int result);
822 
823     /**
824      * @brief Sends the response of the <b>EVENT_VOLUME_CHANGED</b>.
825      *
826      * @param[in] rawAddr The address of the bluetooth device.
827      * @param[in] volume  The absolute volume.
828      */
829     void SendVolumeChangedRsp(bool isInterim, uint8_t volume, uint8_t label, int result);
830 
831     /******************************************************************
832      * BROWSING COMMAND                                               *
833      ******************************************************************/
834 
835     /**
836      * @brief Sends the response of the <b>SetBrowsedPlayer</b>.
837      *
838      * @param[in] rawAddr    The address of the bluetooth device.
839      * @param[in] uidCounter The value of the uid counter.
840      * @param[in] numOfItems The number of items in the directory.
841      * @param[in] label      The label which is used to distinguish different call.
842      * @param[in] status     The detail result of the execution. Refer to <b>AvrcEsCode</b>.<br>
843      *            @a AVRC_ES_CODE_NO_ERROR<br>
844      *            @a AVRC_ES_CODE_INTERNAL_ERROR<br>
845      *            @a AVRC_ES_CODE_UID_CHANGED<br>
846      *            @a AVRC_ES_CODE_INVALID_PLAYER_ID<br>
847      *            @a AVRC_ES_CODE_PLAYER_NOT_BROWSABLE<br>
848      *            @a AVRC_ES_CODE_PLAYER_NOT_ADDRESSED<br>
849      *            @a AVRC_ES_CODE_NO_AVAILABLE_PLAYERS
850      */
851     void SendSetBrowsedPlayerRsp(const RawAddress &rawAddr, uint16_t uidCounter, uint32_t numOfItems,
852         const std::vector<std::string> &folderNames, uint8_t label, int status);
853 
854     /**
855      * @brief Sends the response of the <b>ChangePath</b>.
856      *
857      * @param[in] rawAddr    The address of the bluetooth device.
858      * @param[in] numOfItems The number of items in the directory.
859      * @param[in] label      The label which is used to distinguish different call.
860      * @param[in] status     The detail result of the execution. Refer to <b>AvrcEsCode</b>.<br>
861      *            @a AVRC_ES_CODE_NO_ERROR<br>
862      *            @a AVRC_ES_CODE_INTERNAL_ERROR<br>
863      *            @a AVRC_ES_CODE_UID_CHANGED<br>
864      *            @a AVRC_ES_CODE_INVALID_DIRECTION<br>
865      *            @a AVRC_ES_CODE_NOT_A_DIRECTORY<br>
866      *            @a AVRC_ES_CODE_DOES_NOT_EXIST<br>
867      *            @a AVRC_ES_CODE_NO_AVAILABLE_PLAYERS
868      */
869     void SendChangePathRsp(const RawAddress &rawAddr, uint32_t numOfItems, uint8_t label, int status);
870 
871     /**
872      * @brief Sends the response of the <b>GetFolderItems</b>.
873      *
874      * @param[in] rawAddr    The address of the bluetooth device.
875      * @param[in] uidCounter The value of the uid counter.
876      * @param[in] items      The list of <b>AvrcMpItem</b> class.
877      * @param[in] values     The list of the value of this attribute.
878      * @param[in] label      The label which is used to distinguish different call.
879      * @param[in] status     The detail result of the execution. Refer to <b>AvrcEsCode</b>.<br>
880      *            @a AVRC_ES_CODE_NO_ERROR<br>
881      *            @a AVRC_ES_CODE_INTERNAL_ERROR<br>
882      *            @a AVRC_ES_CODE_UID_CHANGED<br>
883      *            @a AVRC_ES_CODE_DOES_NOT_EXIST<br>
884      *            @a AVRC_ES_CODE_INVALID_SCOPE<br>
885      *            @a AVRC_ES_CODE_NO_AVAILABLE_PLAYERS
886      */
887     void SendGetFolderItemsRsp(const RawAddress &rawAddr, uint16_t uidCounter, const std::vector<AvrcMpItem> &items,
888         uint8_t label, int status);
889 
890     /**
891      * @brief Sends the response of the <b>GetFolderItems</b>.
892      *
893      * @param[in] rawAddr    The address of the bluetooth device.
894      * @param[in] uidCounter The value of the uid counter.
895      * @param[in] items      The list of <b>AvrcMeItem</b> class.
896      * @param[in] values     The list of the value of this attribute.
897      * @param[in] label      The label which is used to distinguish different call.
898      * @param[in] status     The detail result of the execution. Refer to <b>AvrcEsCode</b>.<br>
899      *            @a AVRC_ES_CODE_NO_ERROR<br>
900      *            @a AVRC_ES_CODE_INTERNAL_ERROR<br>
901      *            @a AVRC_ES_CODE_UID_CHANGED<br>
902      *            @a AVRC_ES_CODE_DOES_NOT_EXIST<br>
903      *            @a AVRC_ES_CODE_INVALID_SCOPE<br>
904      *            @a AVRC_ES_CODE_NO_AVAILABLE_PLAYERS
905      */
906     void SendGetFolderItemsRsp(const RawAddress &rawAddr, uint16_t uidCounter, const std::vector<AvrcMeItem> &items,
907         uint8_t label, int status);
908 
909     /**
910      * @brief Sends the response of the <b>GetItemAttributes</b>.
911      *
912      * @param[in] rawAddr    The address of the bluetooth device.
913      * @param[in] attributes The list of media attributes.
914      * @param[in] values     The list of the value of this attribute.
915      * @param[in] label      The label which is used to distinguish different call.
916      * @param[in] status     The detail result of the execution. Refer to <b>AvrcEsCode</b>.<br>
917      *            @a AVRC_ES_CODE_NO_ERROR<br>
918      *            @a AVRC_ES_CODE_INTERNAL_ERROR<br>
919      *            @a AVRC_ES_CODE_UID_CHANGED<br>
920      *            @a AVRC_ES_CODE_DOES_NOT_EXIST<br>
921      *            @a AVRC_ES_CODE_INVALID_SCOPE<br>
922      *            @a AVRC_ES_CODE_NO_AVAILABLE_PLAYERS
923      */
924     void SendGetItemAttributesRsp(const RawAddress &rawAddr, const std::vector<uint32_t> &attributes,
925         const std::vector<std::string> &values, uint8_t label, int status);
926 
927     /**
928      * @brief Sends the response of the <b>GetTotalNumberOfItems</b>.
929      *
930      * @param[in] rawAddr    The address of the bluetooth device.
931      * @param[in] uidCounter The value of the uid counter.
932      * @param[in] numOfItems The number of items in the directory.
933      * @param[in] label      The label which is used to distinguish different call.
934      * @param[in] status     The detail result of the execution. Refer to <b>AvrcEsCode</b>.<br>
935      *            @a AVRC_ES_CODE_NO_ERROR<br>
936      *            @a AVRC_ES_CODE_INTERNAL_ERROR<br>
937      *            @a AVRC_ES_CODE_UID_CHANGED<br>
938      *            @a AVRC_ES_CODE_NO_AVAILABLE_PLAYERS
939      */
940     void SendGetTotalNumberOfItemsRsp(
941         const RawAddress &rawAddr, uint16_t uidCounter, uint32_t numOfItems, uint8_t label, int status);
942 
943     /**
944      * @brief Processes events received from the AVCTP.
945      *
946      * @param[in] rawAddr   The address of the bluetooth device.
947      * @param[in] connectId The ID of the connection.
948      * @param[in] event     The event from the underlying module.
949      * @param[in] result    The result of the event.
950      * @param[in] context   The context is used to send the event in the callback.
951      */
952     void ProcessChannelEvent(
953         const RawAddress &rawAddr, uint8_t connectId, uint8_t event, uint16_t result, void *context);
954 
955     void ProcessChannelEventConnectIndEvt(
956         const RawAddress &rawAddr, uint8_t connectId, uint8_t event, uint16_t result, void *context);
957     void ProcessChannelEventDisconnectIndEvt(
958         const RawAddress &rawAddr, uint8_t connectId, uint8_t event, uint16_t result, void *context);
959     void ProcessChannelEventDisconnectCfmEvt(
960         const RawAddress &rawAddr, uint8_t connectId, uint8_t event, uint16_t result, void *context);
961 
962     void ProcessChannelEventBrConnectIndEvt(
963         const RawAddress &rawAddr, uint8_t connectId, uint8_t event, uint16_t result, void *context);
964     void ProcessChannelEventBrConnectCfmEvt(
965         const RawAddress &rawAddr, uint8_t connectId, uint8_t event, uint16_t result, void *context);
966     void ProcessChannelEventConnectCfmEvt(
967         const RawAddress &rawAddr, uint8_t connectId, uint8_t event, uint16_t result, void *context);
968     /**
969      * @brief Processes messages received from the AVCTP.
970      *
971      * @param[in] connectId The ID of the connection.
972      * @param[in] label     The label used to distinguish between different calls to the same function.
973      * @param[in] crType    The type used to distinguish between the command frame and the response frame.
974      * @param[in] chType    The type used to distinguish the message returned from the control channel or the browse
975      * channel.
976      * @param[in] pkt       The message sent by the peer bluetooth device.
977      * @param[in] context   The context is used to send the message in the callback.
978      */
979     void ProcessChannelMessage(
980         uint8_t connectId, uint8_t label, uint8_t crType, uint8_t chType, Packet *pkt, void *context);
981 
982     /**
983      * @brief get the label for notification changed event.
984      */
985     std::pair<bool, uint8_t> GetNotificationLabel(uint8_t event);
986 
987     /**
988      * @brief set the label for notification changed event.
989      */
990     void SetNotificationLabel(uint8_t event, uint8_t label);
991 
992 private:
993     /// The flag is used to indicate that the AVRCP TG profile is enabled or not.
994     static bool g_isEnabled;
995 
996     /// The features supported by the AVRCP CT profile.
997     uint32_t features_;
998     /// The SIG company ID.
999     uint32_t companyId_;
1000     /// The max MTU size of the control channel.
1001     uint16_t controlMtu_;
1002     /// The max MTU size of the browse channel.
1003     uint16_t browseMtu_;
1004     /// The dispatcher that is used to switch to the thread of the AVRCP CT service.
1005     utility::Dispatcher *dispatcher_ {nullptr};
1006     /// The connect id of the passive connection.
1007     uint8_t connectId_;
1008 
1009     /// The pointer to the observer of the <b>AvrcTgProfile</b> class.
1010     AvrcTgProfile::Observer *myObserver_ {nullptr};
1011 
1012     /// Notification label trackers
1013     std::pair<bool, uint8_t> playStatusChanged;
1014     std::pair<bool, uint8_t> trackChanged;
1015 
1016     /// The callback function, which registers into the AVCTP for receiving the events.
1017     AvctChannelEventCallback eventCallback_ {nullptr};
1018     /// The callback function, which registers into the AVCTP for receiving the messages.
1019     AvctMsgCallback msgCallback_ {nullptr};
1020     // Locks the local variable in a multi-threaded environment.
1021     std::recursive_mutex mutex_ {};
1022     /**
1023      * @brief A deleted default constructor.
1024      */
1025     AvrcTgProfile() = delete;
1026 
1027     /**
1028      * @brief Checks whether the AVRCP TG profile is enabled.
1029      *
1030      * @return The result of the method execution.
1031      * @retval true  The profile is enabled.
1032      * @retval false The profile is disabled.
1033      */
1034     static bool IsEnabled(void);
1035 
1036     /******************************************************************
1037      * PASS THROUGH COMMAND                                           *
1038      ******************************************************************/
1039 
1040     /**
1041      * @brief Checks whether the PASS THROUGH press command is same or not.
1042      *
1043      * @param[in] rawAddr The address of the bluetooth device.
1044      * @param[in] button  The value of the key operation.
1045      * @return The result of the method execution.
1046      * @retval true  Same pass press command.
1047      * @retval false Different pass press command.
1048      */
1049     static bool IsSamePassPressCommand(const RawAddress &rawAddr, uint8_t button);
1050 
1051     /**
1052      * @brief Checks whether the PASS THROUGH release command is same or not.
1053      *
1054      * @param[in] rawAddr The address of the bluetooth device.
1055      * @param[in] button  The value of the key operation.
1056      * @return The result of the method execution.
1057      * @retval true  Same pass release command.
1058      * @retval false Different release press command.
1059      */
1060     static bool IsIgnorePassReleaseCommand(const RawAddress &rawAddr, uint8_t button);
1061 
1062     /**
1063      * @brief Sends the response of the <b>PASS THROUGH</b>.
1064      *
1065      * @param[in] rawAddr The address of the bluetooth device.
1066      * @param[in] pkt     The reference of the shared pointer to the instance of the <b>AvrcTgVendorPacket</b> class.
1067      */
1068     void SendPassRsp(const RawAddress &rawAddr, std::shared_ptr<AvrcTgPassPacket> &pkt);
1069 
1070     /**
1071      * @brief Receives the command of the <b>PASS THROUGH</b>.
1072      *
1073      * @param[in] rawAddr The address of the bluetooth device.
1074      * @param[in] label   The label which is used to distinguish different call.
1075      * @param[in] pkt     The frame packet.
1076      */
1077     void ReceivePassCmd(const RawAddress &rawAddr, uint8_t label, Packet *pkt);
1078 
1079     /**
1080      * @brief Processes the timeout of command of the <b>PASS THROUGH</b>.
1081      *
1082      * @param[in] rawAddr The address of the bluetooth device.
1083      * @param[in] button  The value of the key operation. Refer to <b>AvrcKeyOperation</b>.
1084      * @param[in] state   The value of the key state. Refer to <b>AvrcTgKeyState</b>.
1085      * @param[in] label   The label which is used to distinguish different call.
1086      */
1087     void ProcessPassTimeout(RawAddress rawAddr, uint8_t button, uint8_t state, uint8_t label);
1088 
1089     /**
1090      * @brief The callback function, which registers into the <b>utility::Timer</b>.
1091      *
1092      * @details This function switches to the thread of the AVRCP TG service firstly, then processes the timeout.
1093      * @param[in] rawAddr The address of the bluetooth device.
1094      * @param[in] button  The value of the key operation. Refer to <b>AvrcKeyOperation</b>.
1095      * @param[in] state   The value of the key state. Refer to <b>AvrcTgKeyState</b>.
1096      * @param[in] label   The label which is used to distinguish different call.
1097      */
1098     void PassTimeoutCallback(const RawAddress &rawAddr, uint8_t button, uint8_t state, uint8_t label);
1099 
1100     /******************************************************************
1101      * UNIT INFO / SUB UNIT INFO COMMAND                              *
1102      ******************************************************************/
1103 
1104     /**
1105      * @brief Sends the response of the <b>UNIT INFO</b> or the <b>SUB UNIT INFO</b>.
1106      *
1107      * @param[in] rawAddr The address of the bluetooth device.
1108      * @param[in] pkt     The reference of the shared pointer to the instance of the <b>AvrcTgUnitPacket</b> class.
1109      */
1110     static void SendUnitRsp(const RawAddress &rawAddr, std::shared_ptr<AvrcTgUnitPacket> &pkt, AvrcTgSmEvent event);
1111 
1112     /**
1113      * @brief Receives the command of the <b>UNIT INFO</b>.
1114      *
1115      * @param[in] rawAddr The address of the bluetooth device.
1116      * @param[in] label   The label which is used to distinguish different call.
1117      * @param[in] pkt     The frame packet.
1118      */
1119     void ReceiveUnitCmd(const RawAddress &rawAddr, uint8_t label, Packet *pkt);
1120 
1121     /**
1122      * @brief Receives the command of the <b>SUB UNIT INFO</b>.
1123      *
1124      * @param[in] rawAddr The address of the bluetooth device.
1125      * @param[in] label   The label which is used to distinguish different call.
1126      * @param[in] pkt     The frame packet.
1127      */
1128     void ReceiveSubUnitCmd(const RawAddress &rawAddr, uint8_t label, Packet *pkt);
1129 
1130     /******************************************************************
1131      * VENDOR COMMAND                                                 *
1132      ******************************************************************/
1133 
1134     /**
1135      * @brief Sends the response of the <b>VENDOR DEPENDENT</b>.
1136      *
1137      * @param[in] rawAddr The address of the bluetooth device.
1138      * @param[in] pkt     The reference of the shared pointer to the instance of the <b>AvrcTgVendorPacket</b> class.
1139      * @param[in] event   The event which is responded by the state machine.
1140      */
1141     static void SendVendorRsp(const RawAddress &rawAddr, std::shared_ptr<AvrcTgVendorPacket> &pkt, AvrcTgSmEvent event);
1142 
1143     /**
1144      * @brief Receives the command of the <b>GetCapabilities</b>.
1145      *
1146      * @param[in] rawAddr The address of the bluetooth device.
1147      * @param[in] label   The label which is used to distinguish different call.
1148      * @param[in] pkt     The frame packet.
1149      */
1150     void ReceiveGetCapabilitiesCmd(const RawAddress &rawAddr, uint8_t label, Packet *pkt);
1151 
1152     /**
1153      * @brief Receives the command of the <b>ListPlayerApplicationSettingAttributes</b>.
1154      *
1155      * @param[in] rawAddr The address of the bluetooth device.
1156      * @param[in] label   The label which is used to distinguish different call.
1157      * @param[in] pkt     The frame packet.
1158      */
1159     void ReceiveListPlayerApplicationSettingAttributesCmd(const RawAddress &rawAddr, uint8_t label, Packet *pkt);
1160 
1161     /**
1162      * @brief Receives the command of the <b>ListPlayerApplicationSettingValues</b>.
1163      *
1164      * @param[in] rawAddr The address of the bluetooth device.
1165      * @param[in] label   The label which is used to distinguish different call.
1166      * @param[in] pkt     The frame packet.
1167      */
1168     void ReceiveListPlayerApplicationSettingValuesCmd(const RawAddress &rawAddr, uint8_t label, Packet *pkt);
1169 
1170     /**
1171      * @brief Receives the command of the <b>GetCurrentPlayerApplicationSettingValue</b>.
1172      *
1173      * @param[in] rawAddr The address of the bluetooth device.
1174      * @param[in] label   The label which is used to distinguish different call.
1175      * @param[in] pkt     The frame packet.
1176      */
1177     void ReceiveGetCurrentPlayerApplicationSettingValueCmd(const RawAddress &rawAddr, uint8_t label, Packet *pkt);
1178 
1179     /**
1180      * @brief Receives the command of the <b>SetPlayerApplicationSettingValue</b>.
1181      *
1182      * @param[in] rawAddr The address of the bluetooth device.
1183      * @param[in] label   The label which is used to distinguish different call.
1184      * @param[in] pkt     The frame packet.
1185      */
1186     void ReceiveSetPlayerApplicationSettingValueCmd(const RawAddress &rawAddr, uint8_t label, Packet *pkt);
1187 
1188     /**
1189      * @brief Receives the command of the <b>GetPlayerApplicationSettingAttributeText</b>.
1190      *
1191      * @param[in] rawAddr The address of the bluetooth device.
1192      * @param[in] label   The label which is used to distinguish different call.
1193      * @param[in] pkt     The frame packet.
1194      */
1195     void ReceiveGetPlayerApplicationSettingAttributeTextCmd(const RawAddress &rawAddr, uint8_t label, Packet *pkt);
1196 
1197     /**
1198      * @brief Receives the command of the <b>GetPlayerApplicationSettingValueText</b>.
1199      *
1200      * @param[in] rawAddr The address of the bluetooth device.
1201      * @param[in] label   The label which is used to distinguish different call.
1202      * @param[in] pkt     The frame packet.
1203      */
1204     void ReceiveGetPlayerApplicationSettingValueTextCmd(const RawAddress &rawAddr, uint8_t label, Packet *pkt);
1205 
1206     /**
1207      * @brief Receives the command of the <b>GetElementAttributes</b>.
1208      *
1209      * @param[in] rawAddr The address of the bluetooth device.
1210      * @param[in] label   The label which is used to distinguish different call.
1211      * @param[in] pkt     The frame packet.
1212      */
1213     void ReceiveGetElementAttributesCmd(const RawAddress &rawAddr, uint8_t label, Packet *pkt);
1214 
1215     /**
1216      * @brief Receives the command of the <b>GetPlayStatus</b>.
1217      *
1218      * @param[in] rawAddr The address of the bluetooth device.
1219      * @param[in] label   The label which is used to distinguish different call.
1220      * @param[in] pkt     The frame packet.
1221      */
1222     void ReceiveGetPlayStatusCmd(const RawAddress &rawAddr, uint8_t label, Packet *pkt);
1223 
1224     /**
1225      * @brief Receives the command of the <b>RequestContinuingResponse</b>.
1226      *
1227      * @param[in] rawAddr The address of the bluetooth device.
1228      * @param[in] label   The label which is used to distinguish different call.
1229      * @param[in] pkt     The frame packet.
1230      */
1231     void ReceiveRequestContinuingResponseCmd(const RawAddress &rawAddr, uint8_t label, Packet *pkt);
1232 
1233     /**
1234      * @brief Receives the command of the "AbortContinuingResponse".
1235      *
1236      * @param[in] rawAddr The address of the bluetooth device.
1237      * @param[in] label   The label which is used to distinguish different call.
1238      * @param[in] pkt     The frame packet.
1239      */
1240     void ReceiveAbortContinuingResponseCmd(const RawAddress &rawAddr, uint8_t label, Packet *pkt);
1241 
1242     /**
1243      * @brief Receives the command of the <b>SetAddressedPlayer</b>.
1244      *
1245      * @param[in] rawAddr The address of the bluetooth device.
1246      * @param[in] label   The label which is used to distinguish different call.
1247      * @param[in] pkt     The frame packet.
1248      */
1249     void ReceiveSetAddressedPlayerCmd(const RawAddress &rawAddr, uint8_t label, Packet *pkt);
1250 
1251     /**
1252      * @brief Receives the command of the <b>PlayItem</b>.
1253      *
1254      * @param[in] rawAddr The address of the bluetooth device.
1255      * @param[in] label   The label which is used to distinguish different call.
1256      * @param[in] pkt     The frame packet.
1257      */
1258     void ReceivePlayItemCmd(const RawAddress &rawAddr, uint8_t label, Packet *pkt);
1259 
1260     /**
1261      * @brief Receives the command of the <b>AddToNowPlaying</b>.
1262      *
1263      * @param[in] rawAddr The address of the bluetooth device.
1264      * @param[in] label   The label which is used to distinguish different call.
1265      * @param[in] pkt     The frame packet.
1266      */
1267     void ReceiveAddToNowPlayingCmd(const RawAddress &rawAddr, uint8_t label, Packet *pkt);
1268 
1269     /**
1270      * @brief Receives the command of the <b>SetAbsoluteVolume</b>.
1271      *
1272      * @param[in] rawAddr The address of the bluetooth device.
1273      * @param[in] label   The label which is used to distinguish different call.
1274      * @param[in] pkt     The frame packet.
1275      */
1276     void ReceiveSetAbsoluteVolumeCmd(const RawAddress &rawAddr, uint8_t label, Packet *pkt);
1277 
1278     /**
1279      * @brief Receives the command of the <b>RegisterNotification</b>.
1280      *
1281      * @param[in] rawAddr The address of the bluetooth device.
1282      * @param[in] label   The label which is used to distinguish different call.
1283      * @param[in] pkt     The frame packet.
1284      */
1285     void ReceiveRegisterNotificationCmd(const RawAddress &rawAddr, uint8_t label, Packet *pkt);
1286 
1287     /**
1288      * @brief Receives the command of the <b>VENDOR DEPENDENT</b>.
1289      *
1290      * @param[in] rawAddr The address of the bluetooth device.
1291      * @param[in] label   The label which is used to distinguish different call.
1292      * @param[in] pkt     The frame packet.
1293      */
1294     void ReceiveVendorCmd(const RawAddress &rawAddr, uint8_t label, Packet *pkt);
1295 
1296     /******************************************************************
1297      * BROWSING COMMAND                                               *
1298      ******************************************************************/
1299 
1300     /**
1301      * @brief Sends the response of the <b>BROWSING</b>.
1302      *
1303      * @param[in] rawAddr The address of the bluetooth device.
1304      * @param[in] pkt     The frame packet.
1305      */
1306     static void SendBrowseRsp(const RawAddress &rawAddr, std::shared_ptr<AvrcTgBrowsePacket> &pkt, AvrcTgSmEvent event);
1307 
1308     /**
1309      * @brief Receives the command of the <b>SetBrowsedPlayer</b>.
1310      *
1311      * @param[in] rawAddr The address of the bluetooth device.
1312      * @param[in] label   The label which is used to distinguish different call.
1313      * @param[in] pkt     The frame packet.
1314      */
1315     void ReceiveSetBrowsedPlayerCmd(const RawAddress &rawAddr, uint8_t label, Packet *pkt);
1316 
1317     /**
1318      * @brief Receives the command of the <b>ChangePath</b>.
1319      *
1320      * @param[in] rawAddr The address of the bluetooth device.
1321      * @param[in] label   The label which is used to distinguish different call.
1322      * @param[in] pkt     The frame packet.
1323      */
1324     void ReceiveChangePathCmd(const RawAddress &rawAddr, uint8_t label, Packet *pkt);
1325 
1326     /**
1327      * @brief Receives the command of the <b>GetFolderItems</b>.
1328      *
1329      * @param[in] rawAddr The address of the bluetooth device.
1330      * @param[in] label   The label which is used to distinguish different call.
1331      * @param[in] pkt     The frame packet.
1332      */
1333     void ReceiveGetFolderItemsCmd(const RawAddress &rawAddr, uint8_t label, Packet *pkt);
1334 
1335     /**
1336      * @brief Receives the command of the <b>GetItemAttributes</b>.
1337      *
1338      * @param[in] rawAddr The address of the bluetooth device.
1339      * @param[in] label   The label which is used to distinguish different call.
1340      * @param[in] pkt     The frame packet.
1341      */
1342     void ReceiveGetItemAttributesCmd(const RawAddress &rawAddr, uint8_t label, Packet *pkt);
1343 
1344     /**
1345      * @brief Receives the command of the <b>GetTotalNumberOfItems</b>.
1346      *
1347      * @param[in] rawAddr The address of the bluetooth device.
1348      * @param[in] label   The label which is used to distinguish different call.
1349      * @param[in] pkt     The frame packet.
1350      */
1351     void ReceiveGetTotalNumberOfItemsCmd(const RawAddress &rawAddr, uint8_t label, Packet *pkt);
1352 
1353     /**
1354      * @brief Receives the command of the <b>BROWSING</b>.
1355      *
1356      * @param[in] rawAddr The address of the bluetooth device.
1357      * @param[in] label   The label which is used to distinguish different call.
1358      * @param[in] pkt     The frame packet.
1359      */
1360     void ReceiveBrowseCmd(const RawAddress &rawAddr, uint8_t label, Packet *pkt);
1361 
1362     /**
1363      * @brief Deletes all the data of the specified device, include the connection information and the state machines.
1364      *
1365      * @param[in] rawAddr The address of the bluetooth device.
1366      */
1367     static void DeleteResource(const RawAddress &rawAddr);
1368 
1369     /**
1370      * @brief Deletes the browse state machine.
1371      *
1372      * @param[in] rawAddr The address of the bluetooth device.
1373      */
1374     static void DeleteBrowseStateMachine(const RawAddress &rawAddr);
1375 
1376     /**
1377      * @briefs Checks the browsing channel is supported or not.
1378      *
1379      * @return The result of the method execution.
1380      * @retval true  Supported.
1381      * @retval false Unsupported.
1382      */
IsSupportedBrowsing(void)1383     bool IsSupportedBrowsing(void) const
1384     {
1385         return ((features_ & AVRC_TG_FEATURE_BROWSING) == AVRC_TG_FEATURE_BROWSING);
1386     }
1387 
1388     /**
1389      * @brief Explains the response of the <b>AVCTP</b> function to the result.
1390      *
1391      * @param avctRet The response code.
1392      * @return The requested result.
1393      */
1394     static int ExpainAvctResult(uint16_t avctRet);
1395 
1396     /**
1397      * @briefs Explains the result to the response of the <b>PASS THROUGH</b> command.
1398      *
1399      * @return The value of the "response".
1400      */
1401     static uint8_t ExplainResultToPassCrCode(int result);
1402 
1403     /**
1404      * @briefs Explains the result to the "crCode" of the <b>STATUS</b> command.
1405      *
1406      * @return The value of the "crCode".
1407      */
1408     static uint8_t ExplainResultToStatusCrCode(int result);
1409 
1410     /**
1411      * @briefs Explains the result to the "crCode" of the <b>CONTROL</b> command.
1412      *
1413      * @return The value of the "crCode".
1414      */
1415     static uint8_t ExplainResultToControlCrCode(int result);
1416 
1417     BT_DISALLOW_COPY_AND_ASSIGN(AvrcTgProfile);
1418 };
1419 }  // namespace bluetooth
1420 }  // namespace OHOS
1421 
1422 #endif  // !AVRCP_TG_PROFILE_H
1423