• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 /**
17  * @addtogroup Bluetooth
18  * @{
19  *
20  * @brief Defines a bluetooth system that provides basic bluetooth connection and profile functions,
21  *        including A2DP, AVRCP, BLE, GATT, HFP, MAP, PBAP, and SPP, etc.
22  *
23  * @since 6
24  */
25 
26 /**
27  * @file bluetooth_hfp_hf.h
28  *
29  * @brief Declares HFP HF role framework functions, including basic and observer functions.
30  *
31  * @since 6
32  */
33 
34 #ifndef BLUETOOTH_HFP_HF_H
35 #define BLUETOOTH_HFP_HF_H
36 
37 #include <string>
38 #include <vector>
39 #include <memory>
40 
41 #include "bluetooth_def.h"
42 #include "bluetooth_types.h"
43 #include "bluetooth_remote_device.h"
44 #include "bluetooth_hf_call.h"
45 
46 namespace OHOS {
47 namespace Bluetooth {
48 /**
49  * @brief Class for HandsFree Unit observer functions.
50  *
51  * @since 6
52  */
53 class HandsFreeUnitObserver {
54 public:
55     /**
56      * @brief The observer function to notify connection state changed.
57      *
58      * @param device Remote device object.
59      * @param state Connection state.
60      * @since 6
61      */
OnConnectionStateChanged(const BluetoothRemoteDevice & device,int state)62     virtual void OnConnectionStateChanged(const BluetoothRemoteDevice &device, int state)
63     {}
64 
65     /**
66      * @brief The observer function to notify audio connection state changed.
67      *
68      * @param device Remote device object.
69      * @param state Connection state.
70      * @since 6
71      */
OnScoStateChanged(const BluetoothRemoteDevice & device,int state)72     virtual void OnScoStateChanged(const BluetoothRemoteDevice &device, int state)
73     {}
74 
75     /**
76      * @brief The observer function to notify call object changed.
77      *
78      * @param device Remote device object.
79      * @param call Call object.
80      * @since 6
81      */
OnCallChanged(const BluetoothRemoteDevice & device,const HandsFreeUnitCall & call)82     virtual void OnCallChanged(const BluetoothRemoteDevice &device, const HandsFreeUnitCall &call)
83     {}
84 
85     /**
86      * @brief The observer function to notify signal strength changed.
87      *
88      * @param device Remote device object.
89      * @param batteryLevel Signal strength.
90      * @since 6
91      */
OnSignalStrengthChanged(const BluetoothRemoteDevice & device,int signal)92     virtual void OnSignalStrengthChanged(const BluetoothRemoteDevice &device, int signal)
93     {}
94 
95     /**
96      * @brief The observer function to notify registration status changed.
97      *
98      * @param device Remote device object.
99      * @param status Registration status.
100      * @since 6
101      */
OnRegistrationStatusChanged(const BluetoothRemoteDevice & device,int status)102     virtual void OnRegistrationStatusChanged(const BluetoothRemoteDevice &device, int status)
103     {}
104 
105     /**
106      * @brief The observer function to notify roaming status changed.
107      *
108      * @param device Remote device object.
109      * @param status Roaming status.
110      * @since 6
111      */
OnRoamingStatusChanged(const BluetoothRemoteDevice & device,int status)112     virtual void OnRoamingStatusChanged(const BluetoothRemoteDevice &device, int status)
113     {}
114 
115     /**
116      * @brief The observer function to notify operator selection name changed.
117      *
118      * @param device Remote device object.
119      * @param name Operator selection name.
120      * @since 6
121      */
OnOperatorSelectionChanged(const BluetoothRemoteDevice & device,const std::string & name)122     virtual void OnOperatorSelectionChanged(const BluetoothRemoteDevice &device, const std::string &name)
123     {}
124 
125     /**
126      * @brief The observer function to notify subscriber number changed.
127      *
128      * @param device Remote device object.
129      * @param number Subscriber number.
130      * @since 6
131      */
OnSubscriberNumberChanged(const BluetoothRemoteDevice & device,const std::string & number)132     virtual void OnSubscriberNumberChanged(const BluetoothRemoteDevice &device, const std::string &number)
133     {}
134 
135     /**
136      * @brief The observer function to notify voice recognition status changed.
137      *
138      * @param device Remote device object.
139      * @param status Voice recognition status.
140      * @since 6
141      */
OnVoiceRecognitionStatusChanged(const BluetoothRemoteDevice & device,int status)142     virtual void OnVoiceRecognitionStatusChanged(const BluetoothRemoteDevice &device, int status)
143     {}
144 
145     /**
146      * @brief The observer function to notify inBand ring tone status changed.
147      *
148      * @param device Remote device object.
149      * @param status InBand ring tone status.
150      * @since 6
151      */
OnInBandRingToneChanged(const BluetoothRemoteDevice & device,int status)152     virtual void OnInBandRingToneChanged(const BluetoothRemoteDevice &device, int status)
153     {}
154 
155     /**
156      * @brief Destroy the HandsFreeUnitObserver object.
157      *
158      * @since 6
159      */
~HandsFreeUnitObserver()160     virtual ~HandsFreeUnitObserver()
161     {}
162 };
163 
164 /**
165  * @brief Class for HandsFree Unit API.
166  *
167  * @since 6
168  */
169 class BLUETOOTH_API HandsFreeUnit {
170 public:
171     /**
172      * @brief Get the instance of HandsFreeAudioGateway object.
173      *
174      * @return Returns the pointer to the HandsFreeAudioGateway instance.
175      * @since 6
176      */
177     static HandsFreeUnit *GetProfile();
178 
179     /**
180      * @brief Initiate the establishment of an audio connection to remote AG device.
181      *
182      * @param  device Remote device object.
183      * @return Returns <b>true</b> if the operation is successful; returns <b>false</b> if the operation fails.
184      * @since 6
185      */
186     bool ConnectSco(const BluetoothRemoteDevice &device);
187 
188     /**
189      * @brief Release the audio connection from remote HF device.
190      *
191      * @param  device Remote device object.
192      * @return Returns <b>true</b> if the operation is successful; returns <b>false</b> if the operation fails.
193      * @since 6
194      */
195     bool DisconnectSco(const BluetoothRemoteDevice &device);
196 
197     /**
198      * @brief Get remote AG device list which are in the specified states.
199      *
200      * @param states List of remote device states.
201      * @return Returns the list of devices.
202      * @since 6
203      */
204     std::vector<BluetoothRemoteDevice> GetDevicesByStates(std::vector<int> states) const;
205 
206     /**
207      * @brief Get the connection state of the specified remote AG device.
208      *
209      * @param device Remote device object.
210      * @return Returns the connection state of the remote device.
211      * @since 6
212      */
213     int GetDeviceState(const BluetoothRemoteDevice &device) const;
214 
215     /**
216      * @brief Get the Audio connection state of the specified remote AG device.
217      *
218      * @param device Remote device object.
219      * @return Returns the Audio connection state.
220      * @since 6
221      */
222     int GetScoState(const BluetoothRemoteDevice &device) const;
223 
224     /**
225      * @brief Send DTMF tone code to remote AG device.
226      *
227      * @param device Remote device object.
228      * @param code DTMF tone code.
229      * @return Returns <b>true</b> if the operation is successful; returns <b>false</b> if the operation fails.
230      * @since 6
231      */
232     bool SendDTMFTone(const BluetoothRemoteDevice &device, uint8_t code);
233 
234     /**
235      * @brief Initiate the establishment of a service level connection to remote AG device.
236      *
237      * @param device Remote device object.
238      * @return Returns <b>true</b> if the operation is successful; returns <b>false</b> if the operation fails.
239      * @since 6
240      */
241     bool Connect(const BluetoothRemoteDevice &device);
242 
243     /**
244      * @brief Release the audio connection from remote AG device.
245      *
246      * @param device Remote device object.
247      * @return Returns <b>true</b> if the operation is successful; returns <b>false</b> if the operation fails.
248      * @since 6
249      */
250     bool Disconnect(const BluetoothRemoteDevice &device);
251 
252     /**
253      * @brief Open voice recognition.
254      *
255      * @param device Remote device object.
256      * @return Returns <b>true</b> if the operation is successful; returns <b>false</b> if the operation fails.
257      * @since 6
258      */
259     bool OpenVoiceRecognition(const BluetoothRemoteDevice &device);
260 
261     /**
262      * @brief Close voice recognition.
263      *
264      * @param device Remote device object.
265      * @return Returns <b>true</b> if the operation is successful; returns <b>false</b> if the operation fails.
266      * @since 6
267      */
268     bool CloseVoiceRecognition(const BluetoothRemoteDevice &device);
269 
270     /**
271      * @brief Get a list of all existing calls.
272      *
273      * @param device Remote device object.
274      * @return The list of all existing calls.
275      * @since 6
276      */
277     std::vector<HandsFreeUnitCall> GetExistingCalls(const BluetoothRemoteDevice &device);
278 
279     /**
280      * @brief Accept an incoming call.
281      *
282      * @param device Remote device object.
283      * @param flag Types of calls accepted.
284      * @return Returns <b>true</b> if the operation is successful; returns <b>false</b> if the operation fails.
285      * @since 6
286      */
287     bool AcceptIncomingCall(const BluetoothRemoteDevice &device, int flag);
288 
289     /**
290      * @brief Hold an active call.
291      *
292      * @param device Remote device object.
293      * @return Returns <b>true</b> if the operation is successful; returns <b>false</b> if the operation fails.
294      * @since 6
295      */
296     bool HoldActiveCall(const BluetoothRemoteDevice &device);
297 
298     /**
299      * @brief Reject an incoming call.
300      *
301      * @param device Remote device object.
302      * @return Returns <b>true</b> if the operation is successful; returns <b>false</b> if the operation fails.
303      * @since 6
304      */
305     bool RejectIncomingCall(const BluetoothRemoteDevice &device);
306 
307     /**
308      * @brief send key pressed event.
309      *
310      * @param device Remote device object.
311      * @return Returns <b>true</b> if the operation is successful; returns <b>false</b> if the operation fails.
312      * @since 9
313      */
314 
315     bool SendKeyPressed(const BluetoothRemoteDevice &device);
316 
317     /**
318      * @brief Handle an incoming call.
319      *
320      * @param device Remote device object.
321      * @param flag handle action
322      * @return Returns <b>true</b> if the operation is successful; returns <b>false</b> if the operation fails.
323      * @since 9
324      */
325     bool HandleIncomingCall(const BluetoothRemoteDevice &device, int flag);
326 
327     /**
328      * @brief Hande multi calll.
329      *
330      * @param device Remote device object.
331      * @param flag handle action
332      * @param index call index
333      * @return Returns <b>true</b> if the operation is successful; returns <b>false</b> if the operation fails.
334      * @since 9
335      */
336     bool HandleMultiCall(const BluetoothRemoteDevice &device, int flag, int index);
337 
338     /**
339      * @brief dial last number.
340      *
341      * @param device Remote device object.
342      * @return Returns <b>true</b> if the operation is successful; returns <b>false</b> if the operation fails.
343      * @since 9
344      */
345     bool DialLastNumber(const BluetoothRemoteDevice &device);
346 
347     /**
348      * @brief dial memory number.
349      *
350      * @param device Remote device object.
351      * @param index memory number index
352      * @return Returns <b>true</b> if the operation is successful; returns <b>false</b> if the operation fails.
353      * @since 9
354      */
355     bool DialMemory(const BluetoothRemoteDevice &device, int index);
356 
357 
358     /**
359      * @brief send voice tag.
360      *
361      * @param device Remote device object.
362      * @param index voice tag index.
363      * @return Returns <b>true</b> if the operation is successful; returns <b>false</b> if the operation fails.
364      * @since 9
365      */
366 
367     bool SendVoiceTag(const BluetoothRemoteDevice &device, int index);
368 
369     /**
370      * @brief brief Finish a specified active call.
371      *
372      * @param device Remote device object.
373      * @param call Call object.
374      * @return Returns <b>true</b> if the operation is successful; returns <b>false</b> if the operation fails.
375      * @since 6
376      */
377     bool FinishActiveCall(const BluetoothRemoteDevice &device, const HandsFreeUnitCall &call);
378 
379     /**
380      * @brief Start dial with specified call number.
381      *
382      * @param device Remote device object.
383      * @param number Call's number to dial.
384      * @return The object of dial out call or nullopt.
385      * @since 6
386      */
387     std::optional<HandsFreeUnitCall> StartDial(const BluetoothRemoteDevice &device, const std::string &number);
388 
389     /**
390      * @brief Register HandsFree Unit observer instance.
391      *
392      * @param observer HandsFreeUnitObserver instance.
393      * @since 6
394      */
395     void RegisterObserver(HandsFreeUnitObserver *observer);
396 
397     /**
398      * @brief Deregister HandsFree Unit observer instance.
399      *
400      * @param observer HandsFreeUnitObserver instance.
401      * @since 6
402      */
403     void DeregisterObserver(HandsFreeUnitObserver *observer);
404 
405     /**
406      * @brief Static HandsFree Unit observer instance.
407      *
408      * @since 6
409      */
410     static HandsFreeUnit *instance_;
411 
412 private:
413     HandsFreeUnit();
414     ~HandsFreeUnit();
415     BLUETOOTH_DISALLOW_COPY_AND_ASSIGN(HandsFreeUnit);
416     BLUETOOTH_DECLARE_IMPL();
417 };
418 }  // namespace Bluetooth
419 }  // namespace OHOS
420 #endif  // BLUETOOTH_HFP_HF_H
421