1 /*
2  * Copyright 2018 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #pragma once
18 
19 #include "avrcp_config.h"
20 #include "stack/include/a2dp_api.h"
21 #include "stack/include/avrc_api.h"
22 #include "stack/include/bt_hdr.h"
23 #include "stack/include/sdp_api.h"
24 #include "types/bluetooth/uuid.h"
25 #include "types/raw_address.h"
26 
27 /**
28  * Wrapper classes for the API functions currently defined in "packages/modules/Bluetooth/system/stack".
29  * ConnectionHandler and AvrcpDevice both use this interface to manage AVRCP
30  * SDP, connections, and packets. We use these intermediate interfaces instead
31  * of calling the functions directly in order to make mocking and testing
32  * easier.
33  */
34 // TODO (apanicke): Update the api's in "packages/modules/Bluetooth/system/stack" so that no wrapper is
35 // required
36 class AvrcpInterface {
37  public:
38   virtual uint16_t GetAvrcpVersion() = 0;
39 
40   virtual uint16_t AddRecord(uint16_t service_uuid, const char* p_service_name,
41                              const char* p_provider_name, uint16_t categories,
42                              uint32_t sdp_handle, bool browse_supported,
43                              uint16_t profile_version,
44                              uint16_t cover_art_psm) = 0;
45 
46   virtual uint16_t RemoveRecord(uint32_t sdp_handle) = 0;
47 
48   virtual uint16_t FindService(uint16_t service_uuid, const RawAddress& bd_addr,
49                                tAVRC_SDP_DB_PARAMS* p_db,
50                                tAVRC_FIND_CBACK p_cback) = 0;
51 
52   virtual uint16_t Open(uint8_t* p_handle, tAVRC_CONN_CB* p_ccb,
53                         const RawAddress& bd_addr) = 0;
54 
55   virtual uint16_t OpenBrowse(uint8_t handle, uint8_t conn_role) = 0;
56 
57   virtual uint16_t GetPeerMtu(uint8_t handle) = 0;
58 
59   virtual uint16_t GetBrowseMtu(uint8_t handle) = 0;
60 
61   virtual uint16_t Close(uint8_t handle) = 0;
62 
63   virtual uint16_t CloseBrowse(uint8_t handle) = 0;
64 
65   virtual uint16_t MsgReq(uint8_t handle, uint8_t label, uint8_t ctype,
66                           BT_HDR* p_pkt) = 0;
67 
68   virtual void SaveControllerVersion(const RawAddress& bdaddr,
69                                      uint16_t version) = 0;
70 
71   virtual ~AvrcpInterface() = default;
72 };
73 
74 class SdpInterface {
75  public:
76   virtual bool InitDiscoveryDb(tSDP_DISCOVERY_DB* a, uint32_t b, uint16_t c,
77                                const bluetooth::Uuid* d, uint16_t e,
78                                uint16_t* f) = 0;
79 
80   virtual bool ServiceSearchAttributeRequest(const RawAddress& a,
81                                              tSDP_DISCOVERY_DB* b,
82                                              tSDP_DISC_CMPL_CB* c) = 0;
83 
84   virtual tSDP_DISC_REC* FindServiceInDb(tSDP_DISCOVERY_DB* a, uint16_t b,
85                                          t_sdp_disc_rec* c) = 0;
86 
87   virtual tSDP_DISC_ATTR* FindAttributeInRec(t_sdp_disc_rec* a, uint16_t b) = 0;
88 
89   virtual bool FindProfileVersionInRec(t_sdp_disc_rec* a, uint16_t b,
90                                        uint16_t* c) = 0;
91 
92   virtual ~SdpInterface() = default;
93 };
94 
95 class A2dpInterface {
96  public:
97   virtual RawAddress active_peer() = 0;
98   virtual bool is_peer_in_silence_mode(const RawAddress& peer_address) = 0;
99   virtual void connect_audio_sink_delayed(uint8_t handle,
100                                           const RawAddress& peer_address) = 0;
101   virtual uint16_t find_audio_sink_service(const RawAddress& peer_address,
102                                            tA2DP_FIND_CBACK p_cback) = 0;
103   virtual ~A2dpInterface() = default;
104 };
105