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_device_state.h" 17 18 #include "telephony_log_wrapper.h" 19 20 #include "audio_control_manager.h" 21 22 namespace OHOS { 23 namespace Telephony { ProcessEvent(int32_t event)24bool BluetoothDeviceState::ProcessEvent(int32_t event) 25 { 26 bool result = false; 27 std::lock_guard<std::mutex> lock(mutex_); 28 switch (event) { 29 case AudioEvent::WIRED_HEADSET_CONNECTED: 30 // should switch to wired headset route while wired headset connected 31 result = DelayedSingleton<AudioDeviceManager>::GetInstance()->ProcessEvent( 32 AudioEvent::ENABLE_DEVICE_WIRED_HEADSET); 33 break; 34 case AudioEvent::BLUETOOTH_SCO_CONNECTED: 35 case AudioEvent::AUDIO_ACTIVATED: 36 case AudioEvent::AUDIO_RINGING: 37 // should switch to bluetooth sco route while bluetooth sco connected 38 result = 39 DelayedSingleton<AudioDeviceManager>::GetInstance()->ProcessEvent(AudioEvent::ENABLE_DEVICE_BLUETOOTH); 40 break; 41 case AudioEvent::BLUETOOTH_SCO_DISCONNECTED: 42 case AudioEvent::AUDIO_DEACTIVATED: 43 // should reinitialize audio device in order to switch to a proper audio route 44 TELEPHONY_LOGI("bt sco disconnected , reinitialize audio device"); 45 result = 46 DelayedSingleton<AudioDeviceManager>::GetInstance()->ProcessEvent(AudioEvent::INIT_AUDIO_DEVICE); 47 break; 48 default: 49 break; 50 } 51 TELEPHONY_LOGI("enable bluetooth device lock release"); 52 return result; 53 } 54 } // namespace Telephony 55 } // namespace OHOS