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 "incoming_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)25 bool IncomingState::ProcessEvent(int32_t event)
26 {
27     bool result = false;
28     std::lock_guard<std::mutex> lock(mutex_);
29     switch (event) {
30         case AudioEvent::NO_MORE_INCOMING_CALL:
31             result = DelayedSingleton<CallStateProcessor>::GetInstance()->UpdateCurrentCallState();
32             break;
33         case AudioEvent::NEW_ACTIVE_CS_CALL:
34             // switch to cs call state anyway.
35             if (DelayedSingleton<CallStateProcessor>::GetInstance()->
36                 ShouldSwitchState(TelCallState::CALL_STATUS_ACTIVE)) {
37                 TELEPHONY_LOGI("incoming state switch cs call to active state");
38                 result = DelayedSingleton<AudioSceneProcessor>::GetInstance()->ProcessEvent(
39                     AudioEvent::SWITCH_CS_CALL_STATE);
40             }
41             break;
42         case AudioEvent::NEW_ACTIVE_IMS_CALL:
43             if (DelayedSingleton<CallStateProcessor>::GetInstance()->
44                 ShouldSwitchState(TelCallState::CALL_STATUS_ACTIVE)) {
45                 // switch to ims call state anyway.
46                 TELEPHONY_LOGI("incoming state switch ims call to active state");
47                 result = DelayedSingleton<AudioSceneProcessor>::GetInstance()->ProcessEvent(
48                     AudioEvent::SWITCH_IMS_CALL_STATE);
49             }
50             break;
51         case AudioEvent::NEW_INCOMING_CALL:
52             TELEPHONY_LOGI("incoming state switch incoming state");
53             result = DelayedSingleton<AudioSceneProcessor>::GetInstance()->ProcessEvent(
54                 AudioEvent::SWITCH_INCOMING_STATE);
55             break;
56         default:
57             break;
58     }
59     TELEPHONY_LOGI("incoming state lock release");
60     return result;
61 }
62 } // namespace Telephony
63 } // namespace OHOS
64