• 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_ag.h
28  *
29  * @brief Declares HFP AG role framework functions, including basic and observer functions.
30  *
31  * @since 6
32  */
33 
34 #ifndef BLUETOOTH_HFP_AG_H
35 #define BLUETOOTH_HFP_AG_H
36 
37 #include <string>
38 #include <vector>
39 #include <memory>
40 #include <list>
41 
42 #include "bluetooth_def.h"
43 #include "bluetooth_types.h"
44 #include "bluetooth_remote_device.h"
45 
46 namespace OHOS {
47 namespace Bluetooth {
48 /**
49  * @brief Class for HandsFree AudioGateway observer functions.
50  *
51  * @since 6
52  */
53 class HandsFreeAudioGatewayObserver {
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,int32_t state)62     virtual void OnConnectionStateChanged(const BluetoothRemoteDevice &device, int32_t 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 Audio connection state.
70      * @since 6
71      */
OnScoStateChanged(const BluetoothRemoteDevice & device,int32_t state)72     virtual void OnScoStateChanged(const BluetoothRemoteDevice &device, int32_t state)
73     {}
74 
75     /**
76      * @brief The observer function to notify active device changed.
77      *
78      * @param device Remote active device object.
79      * @since 6
80      */
OnActiveDeviceChanged(const BluetoothRemoteDevice & device)81     virtual void OnActiveDeviceChanged(const BluetoothRemoteDevice &device)
82     {}
83 
84     /**
85      * @brief The observer function to notify enhanced driver safety changed.
86      *
87      * @param device Remote device object.
88      * @param indValue Enhanced driver safety value.
89      * @since 6
90      */
OnHfEnhancedDriverSafetyChanged(const BluetoothRemoteDevice & device,int32_t indValue)91     virtual void OnHfEnhancedDriverSafetyChanged(const BluetoothRemoteDevice &device, int32_t indValue)
92     {}
93 
94     /**
95      * @brief Destroy the HandsFreeAudioGateway Observer object.
96      *
97      * @since 6
98      */
~HandsFreeAudioGatewayObserver()99     virtual ~HandsFreeAudioGatewayObserver()
100     {}
101 };
102 
103 /**
104  * @brief Class for HandsFree AudioGateway API.
105  *
106  * @since 6
107  */
108 class BLUETOOTH_API HandsFreeAudioGateway {
109 public:
110     /**
111      * @brief Get the instance of HandsFreeAudioGateway object.
112      *
113      * @return Returns the pointer to the HandsFreeAudioGateway instance.
114      * @since 6
115      */
116     static HandsFreeAudioGateway *GetProfile();
117 
118     /**
119      * @brief Get remote HF device list which are in the connected state.
120      *
121      * @return Returns the list of devices.
122      * @since 6
123      */
124     int32_t GetConnectedDevices(std::vector<BluetoothRemoteDevice>& devices);
125 
126     /**
127      * @brief Get remote HF device list which are in the specified states.
128      *
129      * @param states List of remote device states.
130      * @return Returns the list of devices.
131      * @since 6
132      */
133     std::vector<BluetoothRemoteDevice> GetDevicesByStates(std::vector<int> states);
134 
135     /**
136      * @brief Get the connection state of the specified remote HF device.
137      *
138      * @param device Remote device object.
139      * @return Returns the connection state of the remote device.
140      * @since 6
141      */
142     int32_t GetDeviceState(const BluetoothRemoteDevice &device, int32_t &state);
143 
144     /**
145      * @brief Initiate the establishment of a service level connection to remote HF device.
146      *
147      * @param device Remote device object.
148      * @return Returns <b>true</b> if the operation is successful; returns <b>false</b> if the operation fails.
149      * @since 6
150      */
151     int32_t Connect(const BluetoothRemoteDevice &device);
152 
153     /**
154      * @brief Release the audio connection from remote HF device.
155      *
156      * @param device Remote device object.
157      * @return Returns <b>true</b> if the operation is successful; returns <b>false</b> if the operation fails.
158      * @since 6
159      */
160     int32_t Disconnect(const BluetoothRemoteDevice &device);
161 
162     /**
163      * @brief Get the Audio connection state of the specified remote HF device.
164      *
165      * @param device Remote device object.
166      * @return Returns the Audio connection state.
167      * @since 6
168      */
169     int GetScoState(const BluetoothRemoteDevice &device) const;
170 
171     /**
172      * @brief Initiate the establishment of an audio connection to remote active HF device.
173      *
174      * @return Returns <b>true</b> if the operation is successful; returns <b>false</b> if the operation fails.
175      * @since 6
176      */
177     bool ConnectSco();
178 
179     /**
180      * @brief Release the audio connection from remote active HF device.
181      *
182      * @return Returns <b>true</b> if the operation is successful; returns <b>false</b> if the operation fails.
183      * @since 6
184      */
185     bool DisconnectSco();
186 
187     /**
188      * @brief This function used to Update changed phone call informations.
189      *
190      * @param numActive Active call number.
191      * @param numHeld Held call number.
192      * @param callState Current call state.
193      * @param number Phone call number.
194      * @param type Type of phone call number.
195      * @param name Name of phone call number.
196      * @since 6
197      */
198     void PhoneStateChanged(
199         int numActive, int numHeld, int callState, const std::string &number, int type, const std::string &name);
200 
201     /**
202      * @brief Send response for querying standard list current calls by remote Hf device.
203      *
204      * @param index Index of the current call.
205      * @param direction Direction of the current call.
206      * @param status Status of the current call.
207      * @param mode Source Mode of the current call.
208      * @param mpty Is this call a member of a conference call.
209      * @param number Phone call number.
210      * @param type Type of phone call number.
211      * @since 6
212      */
213     void ClccResponse(int index, int direction, int status, int mode, bool mpty, const std::string &number, int type);
214 
215     /**
216      * @brief Open the voice recognition.
217      *
218      * @param device Remote device object.
219      * @return Returns <b>true</b> if the operation is successful; returns <b>false</b> if the operation fails.
220      * @since 6
221      */
222     bool OpenVoiceRecognition(const BluetoothRemoteDevice &device);
223 
224     /**
225      * @brief Close the voice recognition.
226      *
227      * @param device Remote device object.
228      * @return Returns <b>true</b> if the operation is successful; returns <b>false</b> if the operation fails.
229      * @since 6
230      */
231     bool CloseVoiceRecognition(const BluetoothRemoteDevice &device);
232 
233     /**
234      * @brief Set the active device for audio connection.
235      *
236      * @param device Remote device object.
237      * @return Returns <b>true</b> if the operation is successful; returns <b>false</b> if the operation fails.
238      * @since 6
239      */
240     bool SetActiveDevice(const BluetoothRemoteDevice &device);
241 
242     bool IntoMock(const BluetoothRemoteDevice &device, int state);
243     bool SendNoCarrier(const BluetoothRemoteDevice &device);
244 
245     /**
246      * @brief Get the active device object.
247      *
248      * @param device Remote active device object.
249      * @return Returns <b>true</b> if the operation is successful; returns <b>false</b> if the operation fails.
250      * @since 6
251      */
252     BluetoothRemoteDevice GetActiveDevice() const;
253 
254     /**
255      * @brief Set connection strategy for peer bluetooth device.
256      *        If peer device is connected and the policy is set not allowed,then perform disconnect operation.
257      *        If peer device is disconnected and the policy is set allowed,then perform connect operation.
258      *
259      * @param device The address of the peer bluetooth device.
260      * @param strategy The device connect strategy.
261      * @return Returns <b>RET_NO_ERROR</b> if the operation is successful.
262      *         Returns <b>BT_ERR_PERMISSION_FAILED</b> Permission denied.
263      *         Returns <b>BT_ERR_INVALID_PARAM</b> Input error.
264      *         Returns <b>BT_ERR_INVALID_STATE</b> BT_ERR_INVALID_STATE.
265      *         Returns <b>BT_ERR_INTERNAL_ERROR</b> Operation failed.
266      * @since 10.0
267      */
268     int SetConnectStrategy(const BluetoothRemoteDevice &device, int strategy);
269 
270     /**
271      * @brief Get connection strategy of peer bluetooth device.
272      *
273      * @param device The address of the peer bluetooth device.
274      * @param strategy The device connect strategy.
275      * @return Returns <b>RET_NO_ERROR</b> if the operation is successful.
276      *         Returns <b>BT_ERR_PERMISSION_FAILED</b> Permission denied.
277      *         Returns <b>BT_ERR_INVALID_PARAM</b> Input error.
278      *         Returns <b>BT_ERR_INVALID_STATE</b> BT_ERR_INVALID_STATE.
279      *         Returns <b>BT_ERR_INTERNAL_ERROR</b> Operation failed.
280      * @since 10.0
281      */
282     int GetConnectStrategy(const BluetoothRemoteDevice &device, int &strategy) const;
283 
284     /**
285      * @brief Register HandsFree AudioGateway observer instance.
286      *
287      * @param observer HandsFree AudioGateway observer instance.
288      * @since 6
289      */
290     void RegisterObserver(HandsFreeAudioGatewayObserver *observer);
291 
292     /**
293      * @brief Deregister HandsFree AudioGateway observer instance.
294      *
295      * @param observer HandsFree AudioGateway observer instance.
296      * @since 6
297      */
298     void DeregisterObserver(HandsFreeAudioGatewayObserver *observer);
299 
300     /**
301      * @brief Get remote HF device list which are in the connected state.
302      *
303      * @return Returns the list of devices.
304      * @since 6
305      */
306     std::vector<BluetoothRemoteDevice> GetConnectedDevices() const;
307 
308     /**
309      * @brief Static HandsFree AudioGateway observer instance.
310      *
311      * @since 6
312      */
313     static HandsFreeAudioGateway *instance_;
314 
315     /**
316      * @brief The external process calls the HfpAg profile interface before the Bluetooth process starts. At this
317      * time, it needs to monitor the start of the Bluetooth process, and then call this interface to initialize the
318      * HfpAg proflie.
319      */
320     void Init();
321 
322 private:
323     HandsFreeAudioGateway();
324     ~HandsFreeAudioGateway();
325     BLUETOOTH_DISALLOW_COPY_AND_ASSIGN(HandsFreeAudioGateway);
326     BLUETOOTH_DECLARE_IMPL();
327 };
328 }  // namespace Bluetooth
329 }  // namespace OHOS
330 #endif  // BLUETOOTH_HFP_AG_H
331