1 /*
2 * Copyright (C) 2021-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 "call_status_callback.h"
17
18 #include "audio_control_manager.h"
19 #include "call_ability_report_proxy.h"
20 #include "call_manager_errors.h"
21 #include "call_manager_hisysevent.h"
22 #include "cpp/task_ext.h"
23 #include "hitrace_meter.h"
24 #include "report_call_info_handler.h"
25 #include "telephony_log_wrapper.h"
26
27 namespace OHOS {
28 namespace Telephony {
29 constexpr size_t CHAR_INDEX = 0;
30 constexpr int32_t ERR_CALL_ID = 0;
31 const uint64_t DELAY_STOP_PLAY_TIME = 3000000;
32 const uint64_t REPORT_SEND_USSD_DELAY_TIME = 1000000;
33 const int32_t MIN_MULITY_CALL_COUNT = 2;
34 constexpr int32_t INIT_INDEX = 0;
35
CallStatusCallback()36 CallStatusCallback::CallStatusCallback() {}
37
~CallStatusCallback()38 CallStatusCallback::~CallStatusCallback() {}
39
UpdateCallReportInfo(const CallReportInfo & info)40 int32_t CallStatusCallback::UpdateCallReportInfo(const CallReportInfo &info)
41 {
42 CallDetailInfo detailInfo;
43 if (info.callType == CallType::TYPE_VOIP) {
44 detailInfo.voipCallInfo.voipCallId = info.voipCallInfo.voipCallId;
45 detailInfo.voipCallInfo.userName = info.voipCallInfo.userName;
46 (detailInfo.voipCallInfo.userProfile).assign(
47 (info.voipCallInfo.userProfile).begin(), (info.voipCallInfo.userProfile).end());
48 detailInfo.voipCallInfo.extensionId = info.voipCallInfo.extensionId;
49 detailInfo.voipCallInfo.voipBundleName = info.voipCallInfo.voipBundleName;
50 detailInfo.voipCallInfo.abilityName = info.voipCallInfo.abilityName;
51 detailInfo.voipCallInfo.showBannerForIncomingCall = info.voipCallInfo.showBannerForIncomingCall;
52 detailInfo.voipCallInfo.isConferenceCall = info.voipCallInfo.isConferenceCall;
53 detailInfo.voipCallInfo.isVoiceAnswerSupported = info.voipCallInfo.isVoiceAnswerSupported;
54 detailInfo.voipCallInfo.hasMicPermission = info.voipCallInfo.hasMicPermission;
55 detailInfo.voipCallInfo.isCapsuleSticky = info.voipCallInfo.isCapsuleSticky;
56 detailInfo.voipCallInfo.uid = info.voipCallInfo.uid;
57 }
58 detailInfo.callType = info.callType;
59 detailInfo.accountId = info.accountId;
60 detailInfo.index = info.index;
61 detailInfo.state = info.state;
62 detailInfo.callMode = info.callMode;
63 detailInfo.voiceDomain = info.voiceDomain;
64 detailInfo.mpty = info.mpty;
65 (void)memcpy_s(detailInfo.phoneNum, kMaxNumberLen, info.accountNum, kMaxNumberLen);
66 (void)memset_s(detailInfo.bundleName, kMaxBundleNameLen, 0, kMaxBundleNameLen);
67 sptr<CallBase> callPtr = CallObjectManager::GetOneCallObjectByIndex(INIT_INDEX);
68 if (callPtr != nullptr && callPtr->GetCallType() == CallType::TYPE_BLUETOOTH &&
69 callPtr->GetTelCallState() == TelCallState::CALL_STATUS_DIALING && callPtr->GetCallIndex() == INIT_INDEX &&
70 info.callType == CallType::TYPE_BLUETOOTH && info.state == TelCallState::CALL_STATUS_DISCONNECTED &&
71 (info.index == -1 || info.index == INIT_INDEX)) {
72 detailInfo.index = INIT_INDEX;
73 }
74 int32_t ret = DelayedSingleton<ReportCallInfoHandler>::GetInstance()->UpdateCallReportInfo(detailInfo);
75 if (ret != TELEPHONY_SUCCESS) {
76 TELEPHONY_LOGE("UpdateCallReportInfo failed! errCode:%{public}d", ret);
77 } else {
78 TELEPHONY_LOGW("UpdateCallReportInfo success! state:%{public}d, index:%{public}d", info.state, info.index);
79 }
80 return ret;
81 }
82
UpdateCallsReportInfo(const CallsReportInfo & info)83 int32_t CallStatusCallback::UpdateCallsReportInfo(const CallsReportInfo &info)
84 {
85 CallDetailsInfo detailsInfo;
86 CallDetailInfo detailInfo;
87 detailInfo.index = 0;
88 detailInfo.state = TelCallState::CALL_STATUS_UNKNOWN;
89 CallsReportInfo callsInfo = info;
90 std::vector<CallReportInfo>::iterator it = callsInfo.callVec.begin();
91 for (; it != callsInfo.callVec.end(); ++it) {
92 detailInfo.callType = (*it).callType;
93 detailInfo.accountId = (*it).accountId;
94 detailInfo.index = (*it).index;
95 detailInfo.state = (*it).state;
96 detailInfo.callMode = (*it).callMode;
97 detailInfo.voiceDomain = (*it).voiceDomain;
98 detailInfo.mpty = (*it).mpty;
99 detailInfo.crsType = (*it).crsType;
100 detailInfo.originalCallType = (*it).originalCallType;
101 (void)memcpy_s(detailInfo.phoneNum, kMaxNumberLen, (*it).accountNum, kMaxNumberLen);
102 (void)memset_s(detailInfo.bundleName, kMaxBundleNameLen, 0, kMaxBundleNameLen);
103 detailInfo.name = (*it).name;
104 detailInfo.namePresentation = (*it).namePresentation;
105 detailInfo.reason = (*it).reason;
106 detailInfo.message = (*it).message;
107 detailInfo.newCallUseBox = (*it).newCallUseBox;
108 detailsInfo.callVec.push_back(detailInfo);
109 }
110 detailsInfo.slotId = callsInfo.slotId;
111 CallManagerHisysevent::WriteCallStateBehaviorEvent(
112 detailsInfo.slotId, static_cast<int32_t>(detailInfo.state), detailInfo.index);
113 (void)memset_s(detailsInfo.bundleName, kMaxBundleNameLen, 0, kMaxBundleNameLen);
114
115 if (detailInfo.state == TelCallState::CALL_STATUS_INCOMING) {
116 CallManagerHisysevent::WriteIncomingCallBehaviorEvent(
117 detailsInfo.slotId, static_cast<int32_t>(detailInfo.callType), static_cast<int32_t>(detailInfo.callMode));
118 TELEPHONY_LOGI("CallStatusCallback InComingCall StartAsyncTrace!");
119 DelayedSingleton<CallManagerHisysevent>::GetInstance()->SetIncomingStartTime();
120 StartAsyncTrace(HITRACE_TAG_OHOS, "InComingCall", getpid());
121 }
122 int32_t ret = DelayedSingleton<ReportCallInfoHandler>::GetInstance()->UpdateCallsReportInfo(detailsInfo);
123 if (ret != TELEPHONY_SUCCESS) {
124 TELEPHONY_LOGE("UpdateCallsReportInfo failed! errCode:%{public}d", ret);
125 } else {
126 TELEPHONY_LOGW("UpdateCallsReportInfo success!");
127 }
128 return ret;
129 }
130
UpdateDisconnectedCause(const DisconnectedDetails & details)131 int32_t CallStatusCallback::UpdateDisconnectedCause(const DisconnectedDetails &details)
132 {
133 int32_t ret = DelayedSingleton<ReportCallInfoHandler>::GetInstance()->UpdateDisconnectedCause(details);
134 if (ret != TELEPHONY_SUCCESS) {
135 TELEPHONY_LOGE("UpdateDisconnectedCause failed! errCode:%{public}d", ret);
136 } else {
137 TELEPHONY_LOGI("UpdateDisconnectedCause success!");
138 }
139 return ret;
140 }
141
UpdateEventResultInfo(const CellularCallEventInfo & info)142 int32_t CallStatusCallback::UpdateEventResultInfo(const CellularCallEventInfo &info)
143 {
144 int32_t ret = DelayedSingleton<ReportCallInfoHandler>::GetInstance()->UpdateEventResultInfo(info);
145 if (ret != TELEPHONY_SUCCESS) {
146 TELEPHONY_LOGE("UpdateEventResultInfo failed! errCode:%{public}d", ret);
147 } else {
148 TELEPHONY_LOGI("UpdateEventResultInfo success!");
149 }
150 return ret;
151 }
152
UpdateVoipEventInfo(const VoipCallEventInfo & info)153 int32_t CallStatusCallback::UpdateVoipEventInfo(const VoipCallEventInfo &info)
154 {
155 int32_t ret = DelayedSingleton<ReportCallInfoHandler>::GetInstance()->UpdateVoipEventInfo(info);
156 if (ret != TELEPHONY_SUCCESS) {
157 TELEPHONY_LOGE("UpdateVoipEventInfo failed! errCode:%{public}d", ret);
158 } else {
159 TELEPHONY_LOGI("UpdateVoipEventInfo success!");
160 }
161 return ret;
162 }
163
UpdateRBTPlayInfo(const RBTPlayInfo info)164 int32_t CallStatusCallback::UpdateRBTPlayInfo(const RBTPlayInfo info)
165 {
166 TELEPHONY_LOGI("UpdateRBTPlayInfo info = %{public}d", info);
167 bool isLocalRingbackNeeded = false;
168 if (info == RBTPlayInfo::LOCAL_ALERTING) {
169 isLocalRingbackNeeded = true;
170 CallEventInfo eventInfo;
171 eventInfo.eventId = CallAbilityEventId::EVENT_LOCAL_ALERTING;
172 DelayedSingleton<CallAbilityReportProxy>::GetInstance()->CallEventUpdated(eventInfo);
173 }
174 DelayedSingleton<AudioControlManager>::GetInstance()->SetLocalRingbackNeeded(isLocalRingbackNeeded);
175 return TELEPHONY_SUCCESS;
176 }
177
StartDtmfResult(const int32_t result)178 int32_t CallStatusCallback::StartDtmfResult(const int32_t result)
179 {
180 CallResultReportId reportId = CallResultReportId::START_DTMF_REPORT_ID;
181 AppExecFwk::PacMap resultInfo;
182 resultInfo.PutIntValue("result", result);
183 TELEPHONY_LOGI("StartDtmfResult result = %{public}d", result);
184 return DelayedSingleton<CallAbilityReportProxy>::GetInstance()->ReportAsyncResults(reportId, resultInfo);
185 }
186
StopDtmfResult(const int32_t result)187 int32_t CallStatusCallback::StopDtmfResult(const int32_t result)
188 {
189 CallResultReportId reportId = CallResultReportId::STOP_DTMF_REPORT_ID;
190 AppExecFwk::PacMap resultInfo;
191 resultInfo.PutIntValue("result", result);
192 TELEPHONY_LOGI("StopDtmfResult result = %{public}d", result);
193 return DelayedSingleton<CallAbilityReportProxy>::GetInstance()->ReportAsyncResults(reportId, resultInfo);
194 }
195
SendUssdResult(const int32_t result)196 int32_t CallStatusCallback::SendUssdResult(const int32_t result)
197 {
198 CallResultReportId reportId = CallResultReportId::SEND_USSD_REPORT_ID;
199 AppExecFwk::PacMap resultInfo;
200 resultInfo.PutIntValue("result", result);
201 TELEPHONY_LOGI("SendUssdResult result = %{public}d", result);
202 return DelayedSingleton<CallAbilityReportProxy>::GetInstance()->ReportAsyncResults(reportId, resultInfo);
203 }
204
SendMmiCodeResult(const MmiCodeInfo & info)205 int32_t CallStatusCallback::SendMmiCodeResult(const MmiCodeInfo &info)
206 {
207 ffrt::submit_h([info] {
208 TELEPHONY_LOGI("SendMmiCodeResult result = %{public}d, message = %{public}s", info.result, info.message);
209 int32_t ret = DelayedSingleton<CallAbilityReportProxy>::GetInstance()->ReportMmiCodeResult(info);
210 if (ret != TELEPHONY_SUCCESS) {
211 TELEPHONY_LOGE("SendMmiCodeResult failed! errCode:%{public}d", ret);
212 } else {
213 TELEPHONY_LOGI("SendMmiCodeResult success!");
214 }
215 return ret;
216 }, {}, {}, ffrt::task_attr().delay(REPORT_SEND_USSD_DELAY_TIME));
217 return TELEPHONY_SUCCESS;
218 }
219
GetImsCallDataResult(const int32_t result)220 int32_t CallStatusCallback::GetImsCallDataResult(const int32_t result)
221 {
222 CallResultReportId reportId = CallResultReportId::GET_IMS_CALL_DATA_REPORT_ID;
223 AppExecFwk::PacMap resultInfo;
224 resultInfo.PutIntValue("result", result);
225 TELEPHONY_LOGI("GetImsCallDataResult result = %{public}d", result);
226 return DelayedSingleton<CallAbilityReportProxy>::GetInstance()->ReportAsyncResults(reportId, resultInfo);
227 }
228
UpdateGetWaitingResult(const CallWaitResponse & response)229 int32_t CallStatusCallback::UpdateGetWaitingResult(const CallWaitResponse &response)
230 {
231 TELEPHONY_LOGI("GetWaitingResult status = %{public}d, classCw = %{public}d, result = %{public}d", response.status,
232 response.classCw, response.result);
233 CallResultReportId reportId = CallResultReportId::GET_CALL_WAITING_REPORT_ID;
234 AppExecFwk::PacMap resultInfo;
235 resultInfo.PutIntValue("result", response.result);
236 resultInfo.PutIntValue("status", response.status);
237 resultInfo.PutIntValue("classCw", response.classCw);
238 DelayedSingleton<CallAbilityReportProxy>::GetInstance()->ReportAsyncResults(reportId, resultInfo);
239 return TELEPHONY_SUCCESS;
240 }
241
UpdateSetWaitingResult(const int32_t result)242 int32_t CallStatusCallback::UpdateSetWaitingResult(const int32_t result)
243 {
244 TELEPHONY_LOGI("SetWaitingResult result = %{public}d", result);
245 CallResultReportId reportId = CallResultReportId::SET_CALL_WAITING_REPORT_ID;
246 AppExecFwk::PacMap resultInfo;
247 resultInfo.PutIntValue("result", result);
248 DelayedSingleton<CallAbilityReportProxy>::GetInstance()->ReportAsyncResults(reportId, resultInfo);
249 return TELEPHONY_SUCCESS;
250 }
251
UpdateGetRestrictionResult(const CallRestrictionResponse & result)252 int32_t CallStatusCallback::UpdateGetRestrictionResult(const CallRestrictionResponse &result)
253 {
254 TELEPHONY_LOGI("GetRestrictionResult status = %{public}d, classCw = %{public}d, result = %{public}d",
255 result.status, result.classCw, result.result);
256 CallResultReportId reportId = CallResultReportId::GET_CALL_RESTRICTION_REPORT_ID;
257 AppExecFwk::PacMap resultInfo;
258 resultInfo.PutIntValue("result", result.result);
259 resultInfo.PutIntValue("status", result.status);
260 resultInfo.PutIntValue("classCw", result.classCw);
261 return DelayedSingleton<CallAbilityReportProxy>::GetInstance()->ReportAsyncResults(reportId, resultInfo);
262 }
263
UpdateSetRestrictionResult(const int32_t result)264 int32_t CallStatusCallback::UpdateSetRestrictionResult(const int32_t result)
265 {
266 TELEPHONY_LOGI("SetRestrictionResult result = %{public}d", result);
267 CallResultReportId reportId = CallResultReportId::SET_CALL_RESTRICTION_REPORT_ID;
268 AppExecFwk::PacMap resultInfo;
269 resultInfo.PutIntValue("result", result);
270 return DelayedSingleton<CallAbilityReportProxy>::GetInstance()->ReportAsyncResults(reportId, resultInfo);
271 }
272
UpdateSetRestrictionPasswordResult(const int32_t result)273 int32_t CallStatusCallback::UpdateSetRestrictionPasswordResult(const int32_t result)
274 {
275 TELEPHONY_LOGI("SetRestrictionPassword result = %{public}d", result);
276 CallResultReportId reportId = CallResultReportId::SET_CALL_RESTRICTION_PWD_REPORT_ID;
277 AppExecFwk::PacMap resultInfo;
278 resultInfo.PutIntValue("result", result);
279 return DelayedSingleton<CallAbilityReportProxy>::GetInstance()->ReportAsyncResults(reportId, resultInfo);
280 }
281
UpdateGetTransferResult(const CallTransferResponse & response)282 int32_t CallStatusCallback::UpdateGetTransferResult(const CallTransferResponse &response)
283 {
284 CallResultReportId reportId = CallResultReportId::GET_CALL_TRANSFER_REPORT_ID;
285 AppExecFwk::PacMap resultInfo;
286 resultInfo.PutIntValue("result", response.result);
287 resultInfo.PutIntValue("status", response.status);
288 resultInfo.PutIntValue("classx", response.classx);
289 resultInfo.PutStringValue("number", response.number);
290 resultInfo.PutIntValue("type", response.type);
291 resultInfo.PutIntValue("reason", response.reason);
292 resultInfo.PutIntValue("time", response.time);
293 resultInfo.PutIntValue("startHour", response.startHour);
294 resultInfo.PutIntValue("startMinute", response.startMinute);
295 resultInfo.PutIntValue("endHour", response.endHour);
296 resultInfo.PutIntValue("endMinute", response.endMinute);
297 return DelayedSingleton<CallAbilityReportProxy>::GetInstance()->ReportAsyncResults(reportId, resultInfo);
298 }
299
UpdateSetTransferResult(const int32_t result)300 int32_t CallStatusCallback::UpdateSetTransferResult(const int32_t result)
301 {
302 TELEPHONY_LOGI("SetTransferResult result = %{public}d", result);
303 CallResultReportId reportId = CallResultReportId::SET_CALL_TRANSFER_REPORT_ID;
304 AppExecFwk::PacMap resultInfo;
305 resultInfo.PutIntValue("result", result);
306 return DelayedSingleton<CallAbilityReportProxy>::GetInstance()->ReportAsyncResults(reportId, resultInfo);
307 }
308
UpdateGetCallClipResult(const ClipResponse & clipResponse)309 int32_t CallStatusCallback::UpdateGetCallClipResult(const ClipResponse &clipResponse)
310 {
311 TELEPHONY_LOGI("GetCallClipResult action = %{public}d, clipStat = %{public}d, result = %{public}d",
312 clipResponse.action, clipResponse.clipStat, clipResponse.result);
313 CallResultReportId reportId = CallResultReportId::GET_CALL_CLIP_ID;
314 AppExecFwk::PacMap resultInfo;
315 resultInfo.PutIntValue("result", clipResponse.result);
316 resultInfo.PutIntValue("action", clipResponse.action);
317 resultInfo.PutIntValue("clipStat", clipResponse.clipStat);
318 return DelayedSingleton<CallAbilityReportProxy>::GetInstance()->ReportAsyncResults(reportId, resultInfo);
319 }
320
UpdateGetCallClirResult(const ClirResponse & clirResponse)321 int32_t CallStatusCallback::UpdateGetCallClirResult(const ClirResponse &clirResponse)
322 {
323 TELEPHONY_LOGI("GetCallClirResult action = %{public}d, clirStat = %{public}d, result = %{public}d",
324 clirResponse.action, clirResponse.clirStat, clirResponse.result);
325 CallResultReportId reportId = CallResultReportId::GET_CALL_CLIR_ID;
326 AppExecFwk::PacMap resultInfo;
327 resultInfo.PutIntValue("result", clirResponse.result);
328 resultInfo.PutIntValue("action", clirResponse.action);
329 resultInfo.PutIntValue("clirStat", clirResponse.clirStat);
330 return DelayedSingleton<CallAbilityReportProxy>::GetInstance()->ReportAsyncResults(reportId, resultInfo);
331 }
332
UpdateSetCallClirResult(const int32_t result)333 int32_t CallStatusCallback::UpdateSetCallClirResult(const int32_t result)
334 {
335 TELEPHONY_LOGI("GetCallClirResult result = %{public}d", result);
336 CallResultReportId reportId = CallResultReportId::SET_CALL_CLIR_ID;
337 AppExecFwk::PacMap resultInfo;
338 resultInfo.PutIntValue("result", result);
339 return DelayedSingleton<CallAbilityReportProxy>::GetInstance()->ReportAsyncResults(reportId, resultInfo);
340 }
341
StartRttResult(const int32_t result)342 int32_t CallStatusCallback::StartRttResult(const int32_t result)
343 {
344 TELEPHONY_LOGI("StartRttResult result = %{public}d", result);
345 CallResultReportId reportId = CallResultReportId::START_RTT_REPORT_ID;
346 AppExecFwk::PacMap resultInfo;
347 resultInfo.PutIntValue("result", result);
348 return DelayedSingleton<CallAbilityReportProxy>::GetInstance()->ReportAsyncResults(reportId, resultInfo);
349 }
350
StopRttResult(const int32_t result)351 int32_t CallStatusCallback::StopRttResult(const int32_t result)
352 {
353 TELEPHONY_LOGI("StopRttResult result = %{public}d", result);
354 CallResultReportId reportId = CallResultReportId::STOP_RTT_REPORT_ID;
355 AppExecFwk::PacMap resultInfo;
356 resultInfo.PutIntValue("result", result);
357 return DelayedSingleton<CallAbilityReportProxy>::GetInstance()->ReportAsyncResults(reportId, resultInfo);
358 }
359
GetImsConfigResult(const GetImsConfigResponse & response)360 int32_t CallStatusCallback::GetImsConfigResult(const GetImsConfigResponse &response)
361 {
362 CallResultReportId reportId = CallResultReportId::GET_IMS_CONFIG_REPORT_ID;
363 AppExecFwk::PacMap resultInfo;
364 resultInfo.PutIntValue("result", response.result);
365 resultInfo.PutIntValue("value", response.value);
366 TELEPHONY_LOGI("result = %{public}d value = %{public}d", response.result, response.value);
367 return DelayedSingleton<CallAbilityReportProxy>::GetInstance()->ReportAsyncResults(reportId, resultInfo);
368 }
369
SetImsConfigResult(const int32_t result)370 int32_t CallStatusCallback::SetImsConfigResult(const int32_t result)
371 {
372 CallResultReportId reportId = CallResultReportId::SET_IMS_CONFIG_REPORT_ID;
373 AppExecFwk::PacMap resultInfo;
374 resultInfo.PutIntValue("result", result);
375 TELEPHONY_LOGI("result = %{public}d", result);
376 return DelayedSingleton<CallAbilityReportProxy>::GetInstance()->ReportAsyncResults(reportId, resultInfo);
377 }
378
GetImsFeatureValueResult(const GetImsFeatureValueResponse & response)379 int32_t CallStatusCallback::GetImsFeatureValueResult(const GetImsFeatureValueResponse &response)
380 {
381 CallResultReportId reportId = CallResultReportId::GET_IMS_FEATURE_VALUE_REPORT_ID;
382 AppExecFwk::PacMap resultInfo;
383 resultInfo.PutIntValue("result", response.result);
384 resultInfo.PutIntValue("value", response.value);
385 TELEPHONY_LOGI("result = %{public}d value = %{public}d", response.result, response.value);
386 return DelayedSingleton<CallAbilityReportProxy>::GetInstance()->ReportAsyncResults(reportId, resultInfo);
387 }
388
SetImsFeatureValueResult(const int32_t result)389 int32_t CallStatusCallback::SetImsFeatureValueResult(const int32_t result)
390 {
391 CallResultReportId reportId = CallResultReportId::SET_IMS_FEATURE_VALUE_REPORT_ID;
392 AppExecFwk::PacMap resultInfo;
393 resultInfo.PutIntValue("result", result);
394 TELEPHONY_LOGI("result = %{public}d", result);
395 return DelayedSingleton<CallAbilityReportProxy>::GetInstance()->ReportAsyncResults(reportId, resultInfo);
396 }
397
ReceiveUpdateCallMediaModeRequest(const CallModeReportInfo & response)398 int32_t CallStatusCallback::ReceiveUpdateCallMediaModeRequest(const CallModeReportInfo &response)
399 {
400 auto weak = weak_from_this();
401 TELEPHONY_LOGI("ReceiveUpdateCallMediaModeRequest result = %{public}d", response.result);
402 int32_t ret = DelayedSingleton<ReportCallInfoHandler>::GetInstance()->ReceiveImsCallModeRequest(response);
403 if (ret != TELEPHONY_SUCCESS) {
404 TELEPHONY_LOGE("ReceiveUpdateCallMediaModeRequest failed! errCode:%{public}d", ret);
405 } else {
406 TELEPHONY_LOGI("ReceiveUpdateCallMediaModeRequest success!");
407 }
408 sptr<CallBase> callPtr = CallObjectManager::GetOneCallObjectByIndexAndSlotId(response.callIndex, response.slotId);
409 if (callPtr != nullptr && callPtr->GetTelCallState() == TelCallState::CALL_STATUS_ACTIVE
410 && response.callMode == ImsCallMode::CALL_MODE_SEND_RECEIVE) {
411 if (DelayedSingleton<AudioControlManager>::GetInstance()->PlayWaitingTone() == TELEPHONY_SUCCESS) {
412 waitingToneHandle_ = ffrt::submit_h([weak]() {
413 auto strong = weak.lock();
414 if (strong) {
415 TELEPHONY_LOGI("ReceiveUpdateCallMediaModeRequest timeout");
416 strong->ShouldStopWaitingTone();
417 }
418 }, {}, {}, ffrt::task_attr().delay(DELAY_STOP_PLAY_TIME));
419 }
420 }
421 return ret;
422 }
423
ReceiveUpdateCallMediaModeResponse(const CallModeReportInfo & response)424 int32_t CallStatusCallback::ReceiveUpdateCallMediaModeResponse(const CallModeReportInfo &response)
425 {
426 TELEPHONY_LOGI("ReceiveUpdateCallMediaModeResponse result = %{public}d", response.result);
427 int32_t ret = DelayedSingleton<ReportCallInfoHandler>::GetInstance()->ReceiveImsCallModeResponse(response);
428 if (ret != TELEPHONY_SUCCESS) {
429 TELEPHONY_LOGE("ReceiveUpdateCallMediaModeResponse failed! errCode:%{public}d", ret);
430 } else {
431 TELEPHONY_LOGI("ReceiveUpdateCallMediaModeResponse success!");
432 }
433 if (waitingToneHandle_ != nullptr) {
434 if (int result = ffrt::skip(waitingToneHandle_) != TELEPHONY_SUCCESS) {
435 TELEPHONY_LOGE("ReceiveUpdateCallMediaModeResponse failed! result:%{public}d", result);
436 }
437 ShouldStopWaitingTone();
438 }
439 return ret;
440 }
441
ShouldStopWaitingTone()442 void CallStatusCallback::ShouldStopWaitingTone()
443 {
444 bool hasRingingCall = false;
445 CallObjectManager::HasRingingCall(hasRingingCall);
446 if (!(hasRingingCall && (CallObjectManager::GetCurrentCallNum() >= MIN_MULITY_CALL_COUNT))) {
447 DelayedSingleton<AudioControlManager>::GetInstance()->StopWaitingTone();
448 }
449 waitingToneHandle_ = nullptr;
450 }
451
InviteToConferenceResult(const int32_t result)452 int32_t CallStatusCallback::InviteToConferenceResult(const int32_t result)
453 {
454 CallResultReportId reportId = CallResultReportId::INVITE_TO_CONFERENCE_REPORT_ID;
455 AppExecFwk::PacMap resultInfo;
456 resultInfo.PutIntValue("result", result);
457 TELEPHONY_LOGI("InviteToConferenceResult result = %{public}d", result);
458 return DelayedSingleton<CallAbilityReportProxy>::GetInstance()->ReportAsyncResults(reportId, resultInfo);
459 }
460
CloseUnFinishedUssdResult(const int32_t result)461 int32_t CallStatusCallback::CloseUnFinishedUssdResult(const int32_t result)
462 {
463 CallResultReportId reportId = CallResultReportId::CLOSE_UNFINISHED_USSD_REPORT_ID;
464 AppExecFwk::PacMap resultInfo;
465 resultInfo.PutIntValue("result", result);
466 TELEPHONY_LOGI("CloseUnFinishedUssdResult result = %{public}d", result);
467 return DelayedSingleton<CallAbilityReportProxy>::GetInstance()->ReportAsyncResults(reportId, resultInfo);
468 }
469
ReportPostDialChar(const std::string & c)470 int32_t CallStatusCallback::ReportPostDialChar(const std::string &c)
471 {
472 TELEPHONY_LOGI("ReportPostDialChar");
473 char nextDtmf = ' ';
474 if (!c.empty() && c.length() > CHAR_INDEX) {
475 nextDtmf = c[CHAR_INDEX];
476 }
477 return DelayedSingleton<AudioControlManager>::GetInstance()->OnPostDialNextChar(nextDtmf);
478 }
479
ReportPostDialDelay(const std::string & str)480 int32_t CallStatusCallback::ReportPostDialDelay(const std::string &str)
481 {
482 TELEPHONY_LOGI("ReportPostDialDelay");
483 return DelayedSingleton<CallAbilityReportProxy>::GetInstance()->ReportPostDialDelay(str);
484 }
485
HandleCallSessionEventChanged(const CallSessionReportInfo & reportInfo)486 int32_t CallStatusCallback::HandleCallSessionEventChanged(const CallSessionReportInfo &reportInfo)
487 {
488 TELEPHONY_LOGI("HandleCallSessionEventChanged");
489 sptr<CallBase> callPtr = CallObjectManager::GetOneCallObjectByIndex(reportInfo.index);
490 CallSessionEvent sessionEvent;
491 if (callPtr == nullptr) {
492 sessionEvent.callId = ERR_CALL_ID;
493 } else {
494 sessionEvent.callId = callPtr->GetCallID();
495 }
496 sessionEvent.eventId = reportInfo.eventId;
497 return DelayedSingleton<CallAbilityReportProxy>::GetInstance()->ReportCallSessionEventChange(sessionEvent);
498 }
499
HandlePeerDimensionsChanged(const PeerDimensionsReportInfo & dimensionsReportInfo)500 int32_t CallStatusCallback::HandlePeerDimensionsChanged(const PeerDimensionsReportInfo &dimensionsReportInfo)
501 {
502 TELEPHONY_LOGI("HandlePeerDimensionsChanged");
503 sptr<CallBase> callPtr = CallObjectManager::GetOneCallObjectByIndex(dimensionsReportInfo.index);
504 PeerDimensionsDetail detail;
505 if (callPtr == nullptr) {
506 detail.callId = ERR_CALL_ID;
507 } else {
508 detail.callId = callPtr->GetCallID();
509 }
510 detail.width = dimensionsReportInfo.width;
511 detail.height = dimensionsReportInfo.height;
512 return DelayedSingleton<CallAbilityReportProxy>::GetInstance()->ReportPeerDimensionsChange(detail);
513 }
514
HandleCallDataUsageChanged(const int64_t dataUsage)515 int32_t CallStatusCallback::HandleCallDataUsageChanged(const int64_t dataUsage)
516 {
517 TELEPHONY_LOGI("HandleCallDataUsageChanged");
518 return DelayedSingleton<CallAbilityReportProxy>::GetInstance()->ReportCallDataUsageChange(dataUsage);
519 }
520
HandleCameraCapabilitiesChanged(const CameraCapabilitiesReportInfo & cameraCapabilitiesReportInfo)521 int32_t CallStatusCallback::HandleCameraCapabilitiesChanged(
522 const CameraCapabilitiesReportInfo &cameraCapabilitiesReportInfo)
523 {
524 TELEPHONY_LOGI("CameraCapabilitiesChange");
525 sptr<CallBase> callPtr = CallObjectManager::GetOneCallObjectByIndex(cameraCapabilitiesReportInfo.index);
526 CameraCapabilities cameraCapabilities;
527 if (callPtr == nullptr) {
528 TELEPHONY_LOGI("callPtr is null, set callId as ERR_CALL_ID");
529 cameraCapabilities.callId = ERR_CALL_ID;
530 } else {
531 cameraCapabilities.callId = callPtr->GetCallID();
532 }
533 cameraCapabilities.width = cameraCapabilitiesReportInfo.width;
534 cameraCapabilities.height = cameraCapabilitiesReportInfo.height;
535 return DelayedSingleton<CallAbilityReportProxy>::GetInstance()->ReportCameraCapabilities(cameraCapabilities);
536 }
537 } // namespace Telephony
538 } // namespace OHOS
539