1 /*
2  * Copyright 2017 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 "bt_hf.h"
20 #include "types/raw_address.h"
21 
22 namespace bluetooth {
23 namespace headset {
24 
25 /**
26  * Headset related callbacks invoked from from the Bluetooth native stack
27  * All callbacks are invoked on the JNI thread
28  */
29 class Callbacks {
30 public:
31   virtual ~Callbacks() = default;
32   /**
33    * Callback for connection state change.
34    *
35    * @param state one of the values from bthf_connection_state_t
36    * @param bd_addr remote device address
37    */
38   virtual void ConnectionStateCallback(bthf_connection_state_t state, RawAddress* bd_addr) = 0;
39 
40   /**
41    * Callback for audio connection state change.
42    *
43    * @param state one of the values from bthf_audio_state_t
44    * @param bd_addr remote device address
45    */
46   virtual void AudioStateCallback(bthf_audio_state_t state, RawAddress* bd_addr) = 0;
47 
48   /**
49    * Callback for VR connection state change.
50    *
51    * @param state one of the values from bthf_vr_state_t
52    * @param bd_addr
53    */
54   virtual void VoiceRecognitionCallback(bthf_vr_state_t state, RawAddress* bd_addr) = 0;
55 
56   /**
57    * Callback for answer incoming call (ATA)
58    *
59    * @param bd_addr remote device address
60    */
61   virtual void AnswerCallCallback(RawAddress* bd_addr) = 0;
62 
63   /**
64    * Callback for disconnect call (AT+CHUP)
65    *
66    * @param bd_addr remote device address
67    */
68   virtual void HangupCallCallback(RawAddress* bd_addr) = 0;
69 
70   /**
71    * Callback for disconnect call (AT+CHUP)
72    *
73    * @param type denote Speaker/Mic gain bthf_volume_type_t
74    * @param volume volume value 0 to 15, p69, HFP 1.7.1 spec
75    * @param bd_addr remote device address
76    */
77   virtual void VolumeControlCallback(bthf_volume_type_t type, int volume, RawAddress* bd_addr) = 0;
78 
79   /**
80    * Callback for dialing an outgoing call
81    *
82    * @param number intended phone number, if number is NULL, redial
83    * @param bd_addr remote device address
84    */
85   virtual void DialCallCallback(char* number, RawAddress* bd_addr) = 0;
86 
87   /**
88    * Callback for sending DTMF tones
89    *
90    * @param tone contains the dtmf character to be sent
91    * @param bd_addr remote device address
92    */
93   virtual void DtmfCmdCallback(char tone, RawAddress* bd_addr) = 0;
94 
95   /**
96    * Callback for enabling/disabling noise reduction/echo cancellation
97    *
98    * @param nrec 1 to enable, 0 to disable
99    * @param bd_addr remote device address
100    */
101   virtual void NoiseReductionCallback(bthf_nrec_t nrec, RawAddress* bd_addr) = 0;
102 
103   /**
104    * Callback for AT+BCS and event from BAC
105    *
106    * @param wbs WBS enable, WBS disable
107    * @param bd_addr remote device address
108    */
109   virtual void WbsCallback(bthf_wbs_config_t wbs, RawAddress* bd_addr) = 0;
110 
111   /**
112    * Callback for AT+BCS and event from BAC
113    *
114    * @param codec SWB codec
115    * @param swb SWB enable, SWB disable
116    * @param bd_addr remote device address
117    */
118   virtual void SwbCallback(bthf_swb_codec_t codec, bthf_swb_config_t swb, RawAddress* bd_addr) = 0;
119 
120   /**
121    * Callback for call hold handling (AT+CHLD)
122    *
123    * @param chld the call hold command (0, 1, 2, 3)
124    * @param bd_addr remote device address
125    */
126   virtual void AtChldCallback(bthf_chld_type_t chld, RawAddress* bd_addr) = 0;
127 
128   /**
129    * Callback for CNUM (subscriber number)
130    *
131    * @param bd_addr remote device address
132    */
133   virtual void AtCnumCallback(RawAddress* bd_addr) = 0;
134 
135   /**
136    * Callback for indicators (CIND)
137    *
138    * @param bd_addr remote device address
139    */
140   virtual void AtCindCallback(RawAddress* bd_addr) = 0;
141 
142   /**
143    * Callback for operator selection (COPS)
144    *
145    * @param bd_addr remote device address
146    */
147   virtual void AtCopsCallback(RawAddress* bd_addr) = 0;
148 
149   /**
150    * Callback for call list (AT+CLCC)
151    *
152    * @param bd_addr remote device address
153    */
154   virtual void AtClccCallback(RawAddress* bd_addr) = 0;
155 
156   /**
157    * Callback for unknown AT command recd from HF
158    *
159    * @param at_string he unparsed AT string
160    * @param bd_addr remote device address
161    */
162   virtual void UnknownAtCallback(char* at_string, RawAddress* bd_addr) = 0;
163 
164   /**
165    * Callback for keypressed (HSP) event.
166    *
167    * @param bd_addr remote device address
168    */
169   virtual void KeyPressedCallback(RawAddress* bd_addr) = 0;
170 
171   /**
172    * Callback for BIND. Pass the remote HF Indicators supported.
173    *
174    * @param at_string unparsed AT command string
175    * @param bd_addr remote device address
176    */
177   virtual void AtBindCallback(char* at_string, RawAddress* bd_addr) = 0;
178 
179   /**
180    * Callback for BIEV. Pass the change in the Remote HF indicator values
181    *
182    * @param ind_id HF indicator id
183    * @param ind_value HF indicator value
184    * @param bd_addr remote device address
185    */
186   virtual void AtBievCallback(bthf_hf_ind_type_t ind_id, int ind_value, RawAddress* bd_addr) = 0;
187 
188   /**
189    * Callback for BIA. Pass the change in AG indicator activation.
190    * NOTE: Call, Call Setup and Call Held indicators are mandatory and cannot
191    *       be disabled. Thus, they are not included here.
192    *
193    * @param service whether HF should receive network service state update
194    * @param roam whether HF should receive roaming state update
195    * @param signal whether HF should receive signal strength update
196    * @param battery whether HF should receive AG battery level update
197    * @param bd_addr remote HF device address
198    */
199   virtual void AtBiaCallback(bool service, bool roam, bool signal, bool battery,
200                              RawAddress* bd_addr) = 0;
201 
202   /**
203    * Callback for DebugDump.
204    *
205    * @param active whether the SCO is active
206    * @param codec_id the codec ID per spec: mSBC=2, LC3=3.
207    * @param total_num_decoded_frames the number of frames decoded.
208    * @param pkt_loss_ratio the ratio of lost frames
209    * @param begin_ts time of the packet status window starts in microseconds.
210    * @param end_ts time of the packet status window ends in microseconds.
211    * @param pkt_status_in_hex recorded packets' status in hex string.
212    * @param pkt_status_in_binary recorde packets' status in binary string.
213    */
214   virtual void DebugDumpCallback(bool active, uint16_t codec_id, int total_num_decoded_frames,
215                                  double pkt_loss_ratio, uint64_t begin_ts, uint64_t end_ts,
216                                  const char* pkt_status_in_hex,
217                                  const char* pkt_status_in_binary) = 0;
218 };
219 
220 }  // namespace headset
221 }  // namespace bluetooth
222