summaryrefslogtreecommitdiff
path: root/system/service/hal/bluetooth_avrcp_interface.h
blob: 4646880169644651203e4b5a0c1284e1fed59e95 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
//
//  Copyright (C) 2017 Google, Inc.
//
//  Licensed under the Apache License, Version 2.0 (the "License");
//  you may not use this file except in compliance with the License.
//  You may obtain a copy of the License at:
//
//  http://www.apache.org/licenses/LICENSE-2.0
//
//  Unless required by applicable law or agreed to in writing, software
//  distributed under the License is distributed on an "AS IS" BASIS,
//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//  See the License for the specific language governing permissions and
//  limitations under the License.
//

#pragma once

#include <hardware/bluetooth.h>
#include <hardware/bt_rc.h>

#include "types/raw_address.h"

namespace bluetooth {
namespace hal {

class BluetoothAvrcpInterface {
 public:
  // The HAL interface doesn't allow registering "user data" that carries
  // context beyond the callback parameters, forcing implementations to deal
  // with global variables. The *Observer interface is to redirect these events
  // to interested parties in an object-oriented manner.
  class TargetObserver {
   public:
    virtual ~TargetObserver() = default;

    virtual void RemoteFeaturesCallback(const RawAddress& bd_addr,
                                        btrc_remote_features_t features);
    virtual void GetPlayStatusCallback(const RawAddress& bd_addr);
    virtual void ListPlayerAppAttrCallback(const RawAddress& bd_addr);
    virtual void ListPlayerAppValuesCallback(btrc_player_attr_t attr_id,
                                             const RawAddress& bd_addr);
    virtual void GetPlayerAppValueCallback(uint8_t num_attr,
                                           btrc_player_attr_t* p_attrs,
                                           const RawAddress& bd_addr);
    virtual void GetPlayerAppAttrsTextCallback(uint8_t num_attr,
                                               btrc_player_attr_t* p_attrs,
                                               const RawAddress& bd_addr);
    virtual void GetPlayerAppValuesTextCallback(uint8_t attr_id,
                                                uint8_t num_val,
                                                uint8_t* p_vals,
                                                const RawAddress& bd_addr);
    virtual void SetPlayerAppValueCallback(btrc_player_settings_t* p_vals,
                                           const RawAddress& bd_addr);
    virtual void GetElementAttrCallback(uint8_t num_attr,
                                        btrc_media_attr_t* p_attrs,
                                        const RawAddress& bd_addr);
    virtual void RegisterNotificationCallback(btrc_event_id_t event_id,
                                              uint32_t param,
                                              const RawAddress& bd_addr);
    virtual void VolumeChangeCallback(uint8_t volume, uint8_t ctype,
                                      const RawAddress& bd_addr);
    virtual void PassthroughCmdCallback(int id, int key_state,
                                        const RawAddress& bd_addr);
    virtual void SetAddressedPlayerCallback(uint16_t player_id,
                                            const RawAddress& bd_addr);
    virtual void SetBrowsedPlayerCallback(uint16_t player_id,
                                          const RawAddress& bd_addr);
    virtual void GetFolderItemsCallback(uint8_t scope, uint32_t start_item,
                                        uint32_t end_item, uint8_t num_attr,
                                        uint32_t* p_attr_ids,
                                        const RawAddress& bd_addr);
    virtual void ChangePathCallback(uint8_t direction, uint8_t* folder_uid,
                                    const RawAddress& bd_addr);
    virtual void GetItemAttrCallback(uint8_t scope, uint8_t* uid,
                                     uint16_t uid_counter, uint8_t num_attr,
                                     btrc_media_attr_t* p_attrs,
                                     const RawAddress& bd_addr);
    virtual void PlayItemCallback(uint8_t scope, uint16_t uid_counter,
                                  uint8_t* uid, const RawAddress& bd_addr);
    virtual void GetTotalNumOfItemsCallback(uint8_t scope,
                                            const RawAddress& bd_addr);
    virtual void SearchCallback(uint16_t str_len, uint8_t* p_str,
                                const RawAddress& bd_addr);
    virtual void AddToNowPlayingCallback(uint8_t scope, uint8_t* uid,
                                         uint16_t uid_counter,
                                         const RawAddress& bd_addr);
  };

  class ControlObserver {
   public:
    virtual ~ControlObserver() = default;

    virtual void PassthroughRspCallback(const RawAddress& bd_addr, int id,
                                        int key_state);
    virtual void GroupnavigationRspCallback(int id, int key_state);
    virtual void ConnectionStateCallback(bool rc_connect, bool bt_connect,
                                         const RawAddress& bd_addr);
    virtual void CtrlGetrcfeaturesCallback(const RawAddress& bd_addr,
                                           int features);
    virtual void CtrlSetplayerapplicationsettingRspCallback(
        const RawAddress& bd_addr, uint8_t accepted);
    virtual void CtrlPlayerapplicationsettingCallback(
        const RawAddress& bd_addr, uint8_t num_attr,
        btrc_player_app_attr_t* app_attrs, uint8_t num_ext_attr,
        btrc_player_app_ext_attr_t* ext_attrs);
    virtual void CtrlPlayerapplicationsettingChangedCallback(
        const RawAddress& bd_addr, const btrc_player_settings_t& p_vals);
    virtual void CtrlSetabsvolCmdCallback(const RawAddress& bd_addr,
                                          uint8_t abs_vol, uint8_t label);
    virtual void CtrlRegisternotificationAbsVolCallback(
        const RawAddress& bd_addr, uint8_t label);
    virtual void CtrlTrackChangedCallback(const RawAddress& bd_addr,
                                          uint8_t num_attr,
                                          btrc_element_attr_val_t* p_attrs);
    virtual void CtrlPlayPositionChangedCallback(const RawAddress& bd_addr,
                                                 uint32_t song_len,
                                                 uint32_t song_pos);
    virtual void CtrlPlayStatusChangedCallback(const RawAddress& bd_addr,
                                               btrc_play_status_t play_status);
    virtual void CtrlGetFolderItemsCallback(
        const RawAddress& bd_addr, btrc_status_t status,
        const btrc_folder_items_t* folder_items, uint8_t count);
    virtual void CtrlChangePathCallback(const RawAddress& bd_addr,
                                        uint32_t count);
    virtual void CtrlSetBrowsedPlayerCallback(const RawAddress& bd_addr,
                                              uint8_t num_items, uint8_t depth);
    virtual void CtrlSetAddressedPlayerCallback(const RawAddress& bd_addr,
                                                uint8_t status);
  };

  BluetoothAvrcpInterface(const BluetoothAvrcpInterface&) = delete;
  BluetoothAvrcpInterface& operator=(const BluetoothAvrcpInterface&) = delete;

  // Initialize and clean up the BluetoothInterface singleton. Returns false if
  // the underlying HAL interface failed to initialize, and true on success.
  static bool Initialize();

  // Shuts down and cleans up the interface. CleanUp must be called on the same
  // thread that called Initialize.
  static void CleanUp();

  // Returns true if the interface was initialized and a global singleton has
  // been created.
  static bool IsInitialized();

  // Initialize for testing. Use this to inject a test version of
  // BluetoothAvrcpInterface. To be used from unit tests only.
  static void InitializeForTesting(BluetoothAvrcpInterface* test_instance);

  // Returns the BluetoothAvrcpInterface singleton. If the interface has
  // not been initialized, returns nullptr. This method is thread-safe, in that
  // it will block if the internal lock is being held by another thread. Don't
  // call this re-entrantly from an observer event as this may cause a deadlock.
  static BluetoothAvrcpInterface* Get();

  virtual bool AvrcpControlEnable() = 0;
  virtual void AvrcpControlDisable() = 0;
  virtual bool AvrcpTargetEnable() = 0;
  virtual void AvrcpTargetDisable() = 0;

  // Thread-safety is guaranteed by ObserverList.
  virtual void AddTargetObserver(TargetObserver* observer) = 0;
  virtual void RemoveTargetObserver(TargetObserver* observer) = 0;

  // Thread-safety is guaranteed by ObserverList.
  virtual void AddControlObserver(ControlObserver* observer) = 0;
  virtual void RemoveControlObserver(ControlObserver* observer) = 0;

  // The HAL module pointers provided by the shared Bluetooth library
  virtual const btrc_interface_t* GetTargetHALInterface() const = 0;
  virtual const btrc_ctrl_interface_t* GetControlHALInterface() const = 0;

 protected:
  BluetoothAvrcpInterface() = default;
  virtual ~BluetoothAvrcpInterface() = default;
};

}  // namespace hal
}  // namespace bluetooth