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