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 "inactive_state.h" 17 18 #include "telephony_log_wrapper.h" 19 20 #include "call_state_processor.h" 21 #include "audio_scene_processor.h" 22 23 namespace OHOS { 24 namespace Telephony { ProcessEvent(int32_t event)25bool InActiveState::ProcessEvent(int32_t event) 26 { 27 bool result = false; 28 std::lock_guard<std::mutex> lock(mutex_); 29 switch (event) { 30 case AudioEvent::NEW_DIALING_CALL: 31 // should switch alerting state while only one alerting call exists 32 if (DelayedSingleton<CallStateProcessor>::GetInstance()-> 33 ShouldSwitchState(TelCallState::CALL_STATUS_DIALING)) { 34 result = DelayedSingleton<AudioSceneProcessor>::GetInstance()->ProcessEvent( 35 AudioEvent::SWITCH_DIALING_STATE); 36 } 37 break; 38 case AudioEvent::NEW_ACTIVE_CS_CALL: 39 if (DelayedSingleton<CallStateProcessor>::GetInstance()-> 40 ShouldSwitchState(TelCallState::CALL_STATUS_ACTIVE)) { 41 result = DelayedSingleton<AudioSceneProcessor>::GetInstance()->ProcessEvent( 42 AudioEvent::SWITCH_CS_CALL_STATE); 43 } 44 break; 45 case AudioEvent::NEW_ACTIVE_IMS_CALL: 46 if (DelayedSingleton<CallStateProcessor>::GetInstance()-> 47 ShouldSwitchState(TelCallState::CALL_STATUS_ACTIVE)) { 48 result = DelayedSingleton<AudioSceneProcessor>::GetInstance()->ProcessEvent( 49 AudioEvent::SWITCH_IMS_CALL_STATE); 50 } 51 break; 52 case AudioEvent::NEW_ALERTING_CALL: 53 // should switch alerting state while only one alerting call exists 54 if (DelayedSingleton<CallStateProcessor>::GetInstance()-> 55 ShouldSwitchState(TelCallState::CALL_STATUS_ALERTING)) { 56 result = DelayedSingleton<AudioSceneProcessor>::GetInstance()->ProcessEvent( 57 AudioEvent::SWITCH_ALERTING_STATE); 58 } 59 break; 60 case AudioEvent::NEW_INCOMING_CALL: 61 // should switch incoming state while only one incoming call exists 62 if (DelayedSingleton<CallStateProcessor>::GetInstance()-> 63 ShouldSwitchState(TelCallState::CALL_STATUS_INCOMING)) { 64 result = DelayedSingleton<AudioSceneProcessor>::GetInstance()->ProcessEvent( 65 AudioEvent::SWITCH_INCOMING_STATE); 66 } 67 break; 68 default: 69 break; 70 } 71 TELEPHONY_LOGI("inactive state lock release"); 72 return result; 73 } 74 } // namespace Telephony 75 } // namespace OHOS