• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2024 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_state.h"
17 #include "telephony_log_wrapper.h"
18 #include "audio_device_manager.h"
19 #include "bluetooth_call_connection.h"
20 
21 namespace OHOS {
22 namespace Telephony {
23 
BluetoothCallState()24 BluetoothCallState::BluetoothCallState() {}
~BluetoothCallState()25 BluetoothCallState::~BluetoothCallState() {}
26 
OnConnectionStateChanged(const Bluetooth::BluetoothRemoteDevice & device,int32_t state,int32_t cause)27 void BluetoothCallState::OnConnectionStateChanged(const Bluetooth::BluetoothRemoteDevice &device,
28     int32_t state, int32_t cause)
29 {
30     switch (state) {
31         case (int32_t)Bluetooth::BTConnectState::CONNECTED:
32             DelayedSingleton<BluetoothCallConnection>::GetInstance()->SetHfpConnected(true);
33             break;
34         case (int32_t)Bluetooth::BTConnectState::DISCONNECTED:
35             DelayedSingleton<BluetoothCallConnection>::GetInstance()->SetHfpContactName("", "");
36             DelayedSingleton<BluetoothCallConnection>::GetInstance()->SetHfpConnected(false);
37             DelayedSingleton<BluetoothCallConnection>::GetInstance()->SetBtCallScoConnected(false);
38             break;
39         default:
40             break;
41     }
42 }
43 
OnScoStateChanged(const Bluetooth::BluetoothRemoteDevice & device,int32_t state)44 void BluetoothCallState::OnScoStateChanged(const Bluetooth::BluetoothRemoteDevice &device, int32_t state)
45 {
46     TELEPHONY_LOGI("BluetoothCallState OnScoStateChanged, state = %{public}d", state);
47     if (state == static_cast<int32_t>(Bluetooth::HfpScoConnectState::SCO_CONNECTED)) {
48         DelayedSingleton<BluetoothCallConnection>::GetInstance()->SetBtCallScoConnected(true);
49         DelayedSingleton<AudioDeviceManager>::GetInstance()->ReportAudioDeviceInfo();
50     } else if (state == static_cast<int32_t>(Bluetooth::HfpScoConnectState::SCO_DISCONNECTED)) {
51         DelayedSingleton<BluetoothCallConnection>::GetInstance()->SetBtCallScoConnected(false);
52         DelayedSingleton<AudioDeviceManager>::GetInstance()->ReportAudioDeviceInfo();
53     }
54 }
55 } // namespace Telephony
56 } // namespace OHOS
57