1 /*
2 * Copyright (C) 2022 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 "audio_device_manager.h"
17 #include "call_ability_connect_callback.h"
18 #include "call_ability_report_proxy.h"
19 #include "call_connect_ability.h"
20 #include "call_object_manager.h"
21 #include "telephony_log_wrapper.h"
22 #include "call_superprivacy_control_manager.h"
23 #include "call_voice_assistant_manager.h"
24
25 namespace OHOS {
26 namespace Telephony {
27 const int32_t CONNECT_ABILITY_SUCCESS = 0;
28 const int32_t UNEXPECT_DISCONNECT_CODE = -1;
29
OnAbilityConnectDone(const AppExecFwk::ElementName & element,const sptr<IRemoteObject> & remoteObject,int resultCode)30 void CallAbilityConnectCallback::OnAbilityConnectDone(
31 const AppExecFwk::ElementName &element, const sptr<IRemoteObject> &remoteObject, int resultCode)
32 {
33 TELEPHONY_LOGI("connect callui result code: %{public}d", resultCode);
34 if (resultCode == CONNECT_ABILITY_SUCCESS) {
35 DelayedSingleton<CallConnectAbility>::GetInstance()->SetConnectFlag(true);
36 DelayedSingleton<CallConnectAbility>::GetInstance()->SetConnectingFlag(false);
37 DelayedSingleton<CallConnectAbility>::GetInstance()->NotifyAll();
38 CallEventInfo eventInfo;
39 (void)memset_s(&eventInfo, sizeof(CallEventInfo), 0, sizeof(CallEventInfo));
40 bool isSuperPrivacyMode = DelayedSingleton<CallSuperPrivacyControlManager>::GetInstance()->
41 GetCurrentIsSuperPrivacyMode();
42 TELEPHONY_LOGI("OnAbilityConnectDone SuperPrivacyMode:%{public}d", isSuperPrivacyMode);
43 if (isSuperPrivacyMode) {
44 eventInfo.eventId = CallAbilityEventId::EVENT_IS_SUPER_PRIVACY_MODE_ON;
45 } else {
46 eventInfo.eventId = CallAbilityEventId::EVENT_IS_SUPER_PRIVACY_MODE_OFF;
47 }
48 DelayedSingleton<CallAbilityReportProxy>::GetInstance()->CallEventUpdated(eventInfo);
49 DelayedSingleton<AudioDeviceManager>::GetInstance()->UpdateEarpieceDevice();
50 CallVoiceAssistantManager::GetInstance()->PublishCommonEvent(true, std::string("call_ui_connect_done"));
51 }
52 }
53
OnAbilityDisconnectDone(const AppExecFwk::ElementName & element,int resultCode)54 void CallAbilityConnectCallback::OnAbilityDisconnectDone(const AppExecFwk::ElementName &element, int resultCode)
55 {
56 TELEPHONY_LOGI("disconnect callui result code: %{public}d", resultCode);
57 DelayedSingleton<CallConnectAbility>::GetInstance()->SetConnectFlag(false);
58 DelayedSingleton<CallConnectAbility>::GetInstance()->SetDisconnectingFlag(false);
59 if (resultCode == UNEXPECT_DISCONNECT_CODE) {
60 ReConnectAbility();
61 }
62 }
63
ReConnectAbility()64 void CallAbilityConnectCallback::ReConnectAbility()
65 {
66 TELEPHONY_LOGI("ReConnectAbility");
67 if (!CallObjectManager::HasCallExist()) {
68 TELEPHONY_LOGE("callObjectPtrList_ is empty, no need to report");
69 return;
70 }
71 std::vector<CallAttributeInfo> callAttributeInfo = CallObjectManager::GetAllCallInfoList();
72 std::vector<CallAttributeInfo>::iterator it = callAttributeInfo.begin();
73 while (it != callAttributeInfo.end()) {
74 CallAttributeInfo info = (*it);
75 TelCallState callState = info.callState;
76 it++;
77 if (callState == TelCallState::CALL_STATUS_DISCONNECTING ||
78 callState == TelCallState::CALL_STATUS_DISCONNECTED ||
79 callState == TelCallState::CALL_STATUS_UNKNOWN || callState == TelCallState::CALL_STATUS_IDLE) {
80 TELEPHONY_LOGE("no need to report");
81 continue;
82 }
83 DelayedSingleton<CallConnectAbility>::GetInstance()->ConnectAbility();
84 return;
85 }
86 }
87 } // namespace Telephony
88 } // namespace OHOS
89