1 /*
2 * Copyright (C) 2023 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 "voip_call.h"
17
18 #include "call_control_manager.h"
19 #include "call_manager_errors.h"
20 #include "call_object_manager.h"
21 #include "telephony_log_wrapper.h"
22 #include "voip_call_connection.h"
23
24 namespace OHOS {
25 namespace Telephony {
VoIPCall(DialParaInfo & info)26 VoIPCall::VoIPCall(DialParaInfo &info) : CarrierCall(info)
27 {
28 callId_ = info.callId;
29 voipCallId_ = info.voipCallInfo.voipCallId;
30 userName_ = info.voipCallInfo.userName;
31 userProfile_.assign((info.voipCallInfo.userProfile).begin(), (info.voipCallInfo.userProfile).end());
32 abilityName_ = info.voipCallInfo.abilityName;
33 extensionId_ = info.voipCallInfo.extensionId;
34 voipBundleName_ = info.voipCallInfo.voipBundleName;
35 showBannerForIncomingCall_ = info.voipCallInfo.showBannerForIncomingCall;
36 isConferenceCall_ = info.voipCallInfo.isConferenceCall;
37 isVoiceAnswerSupported_ = info.voipCallInfo.isVoiceAnswerSupported;
38 hasMicPermission_ = info.voipCallInfo.hasMicPermission;
39 isCapsuleSticky_ = info.voipCallInfo.isCapsuleSticky;
40 uid_ = info.voipCallInfo.uid;
41 }
42
~VoIPCall()43 VoIPCall::~VoIPCall() {}
44
DialingProcess()45 int32_t VoIPCall::DialingProcess()
46 {
47 return TELEPHONY_SUCCESS;
48 }
49
AnswerCall(int32_t videoState)50 int32_t VoIPCall::AnswerCall(int32_t videoState)
51 {
52 TELEPHONY_LOGI("VoIPCall::AnswerCall");
53 VoipCallEventInfo voipcallInfo;
54 int32_t ret = TELEPHONY_ERROR;
55 ret = PackVoipCallInfo(voipcallInfo);
56 if (ret != TELEPHONY_SUCCESS) {
57 TELEPHONY_LOGW("PackVoipCallInfo failed!");
58 }
59 DelayedSingleton<VoipCallConnection>::GetInstance()->AnswerCall(voipcallInfo, videoState);
60 if (ret != TELEPHONY_SUCCESS) {
61 TELEPHONY_LOGE("answer call failed!");
62 return CALL_ERR_ANSWER_FAILED;
63 }
64 return TELEPHONY_SUCCESS;
65 }
66
PackVoipCallInfo(VoipCallEventInfo & voipcallInfo)67 int32_t VoIPCall::PackVoipCallInfo(VoipCallEventInfo &voipcallInfo)
68 {
69 voipcallInfo.voipCallId = voipCallId_;
70 voipcallInfo.bundleName = voipBundleName_;
71 voipcallInfo.uid = uid_;
72 return TELEPHONY_SUCCESS;
73 }
74
RejectCall()75 int32_t VoIPCall::RejectCall()
76 {
77 TELEPHONY_LOGI("VoIPCall::RejectCall enter");
78 VoipCallEventInfo voipcallInfo;
79 int32_t ret = TELEPHONY_ERROR;
80 ret = PackVoipCallInfo(voipcallInfo);
81 if (ret != TELEPHONY_SUCCESS) {
82 TELEPHONY_LOGW("PackVoipCallInfo failed!");
83 }
84 DelayedSingleton<VoipCallConnection>::GetInstance()->RejectCall(voipcallInfo);
85 if (ret != TELEPHONY_SUCCESS) {
86 TELEPHONY_LOGE("reject call failed!");
87 return CALL_ERR_ANSWER_FAILED;
88 }
89 return TELEPHONY_SUCCESS;
90 }
91
HangUpCall()92 int32_t VoIPCall::HangUpCall()
93 {
94 TELEPHONY_LOGI("VoIPCall::HangUpCall enter");
95 VoipCallEventInfo voipcallInfo;
96 int32_t ret = TELEPHONY_ERROR;
97 ret = PackVoipCallInfo(voipcallInfo);
98 if (ret != TELEPHONY_SUCCESS) {
99 TELEPHONY_LOGW("PackVoipCallInfo failed!");
100 }
101 voipcallInfo.errorReason = ErrorReason::USER_ANSWER_CELLULAR_FIRST;
102 DelayedSingleton<VoipCallConnection>::GetInstance()->HangUpCall(voipcallInfo);
103 if (ret != TELEPHONY_SUCCESS) {
104 TELEPHONY_LOGE("hangup call failed!");
105 return CALL_ERR_ANSWER_FAILED;
106 }
107 return TELEPHONY_SUCCESS;
108 }
109
HangUpCall(const ErrorReason & status)110 int32_t VoIPCall::HangUpCall(const ErrorReason &status)
111 {
112 TELEPHONY_LOGI("VoIPCall::dial cellularcall HangUpvoipCall enter");
113 VoipCallEventInfo voipcallInfo;
114 int32_t ret = TELEPHONY_ERROR;
115 ret = PackVoipCallInfo(voipcallInfo);
116 if (ret != TELEPHONY_SUCCESS) {
117 TELEPHONY_LOGW("PackVoipCallInfo failed!");
118 }
119 voipcallInfo.errorReason = status;
120 DelayedSingleton<VoipCallConnection>::GetInstance()->HangUpCall(voipcallInfo);
121 if (ret != TELEPHONY_SUCCESS) {
122 TELEPHONY_LOGE("hangup call failed!");
123 return CALL_ERR_ANSWER_FAILED;
124 }
125 return TELEPHONY_SUCCESS;
126 }
127
HoldCall()128 int32_t VoIPCall::HoldCall()
129 {
130 return TELEPHONY_SUCCESS;
131 }
132
UnHoldCall()133 int32_t VoIPCall::UnHoldCall()
134 {
135 return TELEPHONY_SUCCESS;
136 }
137
SwitchCall()138 int32_t VoIPCall::SwitchCall()
139 {
140 return TELEPHONY_SUCCESS;
141 }
142
SetMute(int32_t mute,int32_t slotId)143 int32_t VoIPCall::SetMute(int32_t mute, int32_t slotId)
144 {
145 CallAttributeInfo info;
146 GetCallAttributeInfo(info);
147 std::string voipCallId = info.voipCallInfo.voipBundleName + ":" + std::to_string(info.voipCallInfo.uid) + ":" +
148 info.voipCallInfo.voipCallId;
149 CallAudioEvent callAudioEvent = mute == 1 ? CallAudioEvent::AUDIO_EVENT_MUTED : CallAudioEvent::AUDIO_EVENT_UNMUTED;
150 TELEPHONY_LOGI("VoIPCall::setMute voipCallId: %{public}s, callAudioEvent: %{public}d", voipCallId.c_str(),
151 callAudioEvent);
152 DelayedSingleton<VoipCallConnection>::GetInstance()->SendCallUiEvent(voipCallId, callAudioEvent);
153 return TELEPHONY_SUCCESS;
154 }
155
GetCallAttributeInfo(CallAttributeInfo & info)156 void VoIPCall::GetCallAttributeInfo(CallAttributeInfo &info)
157 {
158 GetCallAttributeCarrierInfo(info);
159 info.callId = callId_;
160 info.voipCallInfo.voipCallId = voipCallId_;
161 info.voipCallInfo.userName = userName_;
162 (info.voipCallInfo.userProfile).assign(userProfile_.begin(), userProfile_.end());
163 info.voipCallInfo.extensionId = extensionId_;
164 info.voipCallInfo.abilityName = abilityName_;
165 info.voipCallInfo.voipBundleName = voipBundleName_;
166 info.voipCallInfo.showBannerForIncomingCall = showBannerForIncomingCall_;
167 info.voipCallInfo.isConferenceCall = isConferenceCall_;
168 info.voipCallInfo.isVoiceAnswerSupported = isVoiceAnswerSupported_;
169 info.voipCallInfo.hasMicPermission = hasMicPermission_;
170 info.voipCallInfo.isCapsuleSticky = isCapsuleSticky_;
171 info.voipCallInfo.uid = uid_;
172 return;
173 }
174
CombineConference()175 int32_t VoIPCall::CombineConference()
176 {
177 return TELEPHONY_SUCCESS;
178 }
179
HandleCombineConferenceFailEvent()180 void VoIPCall::HandleCombineConferenceFailEvent()
181 {
182 return;
183 }
184
SeparateConference()185 int32_t VoIPCall::SeparateConference()
186 {
187 return TELEPHONY_SUCCESS;
188 }
189
KickOutFromConference()190 int32_t VoIPCall::KickOutFromConference()
191 {
192 return TELEPHONY_SUCCESS;
193 }
194
CanCombineConference()195 int32_t VoIPCall::CanCombineConference()
196 {
197 return TELEPHONY_SUCCESS;
198 }
199
CanSeparateConference()200 int32_t VoIPCall::CanSeparateConference()
201 {
202 return TELEPHONY_SUCCESS;
203 }
204
CanKickOutFromConference()205 int32_t VoIPCall::CanKickOutFromConference()
206 {
207 return TELEPHONY_SUCCESS;
208 }
209
GetMainCallId(int32_t & mainCallId)210 int32_t VoIPCall::GetMainCallId(int32_t &mainCallId)
211 {
212 return TELEPHONY_SUCCESS;
213 }
214
GetSubCallIdList(std::vector<std::u16string> & callIdList)215 int32_t VoIPCall::GetSubCallIdList(std::vector<std::u16string> &callIdList)
216 {
217 return TELEPHONY_SUCCESS;
218 }
219
GetCallIdListForConference(std::vector<std::u16string> & callIdList)220 int32_t VoIPCall::GetCallIdListForConference(std::vector<std::u16string> &callIdList)
221 {
222 return TELEPHONY_SUCCESS;
223 }
224
IsSupportConferenceable()225 int32_t VoIPCall::IsSupportConferenceable()
226 {
227 return TELEPHONY_SUCCESS;
228 }
229
LaunchConference()230 int32_t VoIPCall::LaunchConference()
231 {
232 return TELEPHONY_SUCCESS;
233 }
234
ExitConference()235 int32_t VoIPCall::ExitConference()
236 {
237 return TELEPHONY_SUCCESS;
238 }
239
HoldConference()240 int32_t VoIPCall::HoldConference()
241 {
242 return TELEPHONY_SUCCESS;
243 }
244
GetVoipCallId()245 std::string VoIPCall::GetVoipCallId()
246 {
247 return voipCallId_;
248 }
249
GetVoipBundleName()250 std::string VoIPCall::GetVoipBundleName()
251 {
252 return voipBundleName_;
253 }
254
GetVoipUid()255 int32_t VoIPCall::GetVoipUid()
256 {
257 return uid_;
258 }
259 } // namespace Telephony
260 } // namespace OHOS
261