• 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 #include "bluetooth_call_manager.h"
17 
18 #include "call_manager_errors.h"
19 #include "telephony_log_wrapper.h"
20 
21 #include "audio_control_manager.h"
22 #include "call_control_manager.h"
23 #include "bluetooth_connection.h"
24 
25 namespace OHOS {
26 namespace Telephony {
BluetoothCallManager()27 BluetoothCallManager::BluetoothCallManager() : btConnection_(DelayedSingleton<BluetoothConnection>::GetInstance()) {}
28 
~BluetoothCallManager()29 BluetoothCallManager::~BluetoothCallManager() {}
30 
ConnectBtSco(const std::string & bluetoothAddress)31 bool BluetoothCallManager::ConnectBtSco(const std::string &bluetoothAddress)
32 {
33     if (btConnection_ == nullptr) {
34         TELEPHONY_LOGE("bluetooth connection nullptr");
35         return false;
36     }
37 
38 #ifdef ABILITY_BLUETOOTH_SUPPORT
39     if (!bluetoothAddress.empty()) {
40         return btConnection_->ConnectBtSco(bluetoothAddress);
41     }
42 #endif
43 
44     return btConnection_->ConnectBtSco();
45 }
46 
DisconnectBtSco()47 bool BluetoothCallManager::DisconnectBtSco()
48 {
49     if (btConnection_ == nullptr) {
50         TELEPHONY_LOGE("bluetooth connection nullptr");
51         return false;
52     }
53     return btConnection_->DisconnectBtSco();
54 }
55 
SendBtCallState(int32_t numActive,int32_t numHeld,int32_t callState,const std::string & number)56 int32_t BluetoothCallManager::SendBtCallState(
57     int32_t numActive, int32_t numHeld, int32_t callState, const std::string &number)
58 {
59     if (btConnection_ == nullptr) {
60         TELEPHONY_LOGE("bluetooth connection nullptr");
61         return false;
62     }
63     return btConnection_->SendBtCallState(numActive, numHeld, callState, number);
64 }
65 
GetBtScoState()66 BtScoState BluetoothCallManager::GetBtScoState()
67 {
68     if (btConnection_ == nullptr) {
69         TELEPHONY_LOGE("bluetooth connection nullptr");
70         return BtScoState::SCO_STATE_UNKNOWN;
71     }
72     return btConnection_->GetBtScoState();
73 }
74 
IsBtScoConnected()75 bool BluetoothCallManager::IsBtScoConnected()
76 {
77     if (btConnection_ == nullptr) {
78         TELEPHONY_LOGE("bluetooth connection nullptr");
79         return false;
80     }
81     return btConnection_->IsBtScoConnected();
82 }
83 
IsBtAvailble()84 bool BluetoothCallManager::IsBtAvailble()
85 {
86     if (btConnection_ == nullptr) {
87         TELEPHONY_LOGE("bluetooth connection nullptr");
88         return false;
89     }
90     bool isBtAvailble = false;
91 
92 #ifdef ABILITY_BLUETOOTH_SUPPORT
93     isBtAvailble = btConnection_->IsBtAvailble();
94 #endif
95     return isBtAvailble;
96 }
97 
GetConnectedScoAddr()98 std::string BluetoothCallManager::GetConnectedScoAddr()
99 {
100     return btConnection_->GetConnectedScoAddr();
101 }
102 } // namespace Telephony
103 } // namespace OHOS