• 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 #ifndef TELEPHONY_BLUETOOTH_CONNECTION_H
17 #define TELEPHONY_BLUETOOTH_CONNECTION_H
18 
19 #include <memory>
20 #include <string>
21 
22 #include "singleton.h"
23 #include "unordered_map"
24 
25 #ifdef ABILITY_BLUETOOTH_SUPPORT
26 #include "bluetooth_hfp_ag.h"
27 #endif
28 
29 namespace OHOS {
30 namespace Telephony {
31 enum BtScoState {
32     SCO_STATE_UNKNOWN = 0,
33     SCO_STATE_CONNECTED,
34     SCO_STATE_DISCONNECTED,
35     SCO_STATE_PENDING,
36 };
37 
38 #ifdef ABILITY_BLUETOOTH_SUPPORT
39 class BluetoothConnection : public OHOS::Bluetooth::HandsFreeAudioGatewayObserver {
40 #else
41 class BluetoothConnection {
42 #endif
43     DECLARE_DELAYED_SINGLETON(BluetoothConnection)
44 public:
45     void Init();
46     bool ConnectBtSco();
47     bool ConnectBtSco(const std::string &bluetoothAddress);
48     bool DisconnectBtSco();
49     bool IsBtScoConnected();
50     BtScoState GetBtScoState();
51     void SetBtScoState(BtScoState state);
52     int32_t SendBtCallState(int32_t numActive, int32_t numHeld, int32_t callState, const std::string &number);
53     void RemoveBtDevice(const std::string &address);
54     bool IsBtAvailble();
55 
56 #ifdef ABILITY_BLUETOOTH_SUPPORT
57     void OnScoStateChanged(const Bluetooth::BluetoothRemoteDevice &device, int32_t state) override;
58     void OnConnectionStateChanged(const Bluetooth::BluetoothRemoteDevice &device, int32_t state) override;
59     Bluetooth::BluetoothRemoteDevice *GetBtDevice(const std::string &address);
60     void AddBtDevice(const std::string &address, Bluetooth::BluetoothRemoteDevice device);
61 #endif
62 
63 private:
64     bool IsAudioActivated();
65     BtScoState btScoState_ = BtScoState::SCO_STATE_DISCONNECTED;
66     std::string connectedScoAddr_;
67 
68 #ifdef ABILITY_BLUETOOTH_SUPPORT
69     bool ConnectBtSco(const Bluetooth::BluetoothRemoteDevice &device);
70     bool DisconnectBtSco(const Bluetooth::BluetoothRemoteDevice &device);
71 
72 private:
73     std::unordered_map<std::string, Bluetooth::BluetoothRemoteDevice> mapConnectedBtDevices_;
74 #endif
75 };
76 } // namespace Telephony
77 } // namespace OHOS
78 #endif
79