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 "alerting_state.h"
17 
18 #include "telephony_log_wrapper.h"
19 
20 #include "call_state_processor.h"
21 #include "audio_scene_processor.h"
22 #include "audio_control_manager.h"
23 
24 namespace OHOS {
25 namespace Telephony {
ProcessEvent(int32_t event)26 bool AlertingState::ProcessEvent(int32_t event)
27 {
28     bool result = false;
29     std::lock_guard<std::mutex> lock(mutex_);
30     switch (event) {
31         case AudioEvent::NO_MORE_ALERTING_CALL:
32             result = DelayedSingleton<CallStateProcessor>::GetInstance()->UpdateCurrentCallState();
33             break;
34         case AudioEvent::NEW_ACTIVE_CS_CALL:
35             // switch to cs call state anyway.
36             if (DelayedSingleton<CallStateProcessor>::GetInstance()->
37                 ShouldSwitchState(TelCallState::CALL_STATUS_ACTIVE)) {
38                 TELEPHONY_LOGI("alerting state switch cs call to active state");
39                 result = DelayedSingleton<AudioSceneProcessor>::GetInstance()->ProcessEvent(
40                     AudioEvent::SWITCH_CS_CALL_STATE);
41             }
42             break;
43         case AudioEvent::NEW_ACTIVE_IMS_CALL:
44             // switch to ims call state anyway.
45             if (DelayedSingleton<CallStateProcessor>::GetInstance()->
46                 ShouldSwitchState(TelCallState::CALL_STATUS_ACTIVE)) {
47                 TELEPHONY_LOGI("alerting state switch ims call to active state");
48                 result = DelayedSingleton<AudioSceneProcessor>::GetInstance()->ProcessEvent(
49                     AudioEvent::SWITCH_IMS_CALL_STATE);
50             }
51             break;
52         case AudioEvent::NEW_ALERTING_CALL:
53             if (DelayedSingleton<CallStateProcessor>::GetInstance()->
54                 ShouldSwitchState(TelCallState::CALL_STATUS_ALERTING)) {
55                 TELEPHONY_LOGI("alerting state: check is should play ringback tone.");
56                 result = DelayedSingleton<AudioSceneProcessor>::GetInstance()->ProcessEvent(
57                     AudioEvent::SWITCH_ALERTING_STATE);
58             }
59             break;
60         case AudioEvent::NEW_INCOMING_CALL:
61             result = DelayedSingleton<AudioControlManager>::GetInstance()->PlayWaitingTone();
62             break;
63         default:
64             break;
65     }
66     TELEPHONY_LOGI("alerting state lock release");
67     return result;
68 }
69 } // namespace Telephony
70 } // namespace OHOS