• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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         detailsInfo.callVec.push_back(detailInfo);
107     }
108     detailsInfo.slotId = callsInfo.slotId;
109     CallManagerHisysevent::WriteCallStateBehaviorEvent(
110         detailsInfo.slotId, static_cast<int32_t>(detailInfo.state), detailInfo.index);
111     (void)memset_s(detailsInfo.bundleName, kMaxBundleNameLen, 0, kMaxBundleNameLen);
112 
113     if (detailInfo.state == TelCallState::CALL_STATUS_INCOMING) {
114         CallManagerHisysevent::WriteIncomingCallBehaviorEvent(
115             detailsInfo.slotId, static_cast<int32_t>(detailInfo.callType), static_cast<int32_t>(detailInfo.callMode));
116         TELEPHONY_LOGI("CallStatusCallback InComingCall StartAsyncTrace!");
117         DelayedSingleton<CallManagerHisysevent>::GetInstance()->SetIncomingStartTime();
118         StartAsyncTrace(HITRACE_TAG_OHOS, "InComingCall", getpid());
119     }
120     int32_t ret = DelayedSingleton<ReportCallInfoHandler>::GetInstance()->UpdateCallsReportInfo(detailsInfo);
121     if (ret != TELEPHONY_SUCCESS) {
122         TELEPHONY_LOGE("UpdateCallsReportInfo failed! errCode:%{public}d", ret);
123     } else {
124         TELEPHONY_LOGW("UpdateCallsReportInfo success!");
125     }
126     return ret;
127 }
128 
UpdateDisconnectedCause(const DisconnectedDetails & details)129 int32_t CallStatusCallback::UpdateDisconnectedCause(const DisconnectedDetails &details)
130 {
131     int32_t ret = DelayedSingleton<ReportCallInfoHandler>::GetInstance()->UpdateDisconnectedCause(details);
132     if (ret != TELEPHONY_SUCCESS) {
133         TELEPHONY_LOGE("UpdateDisconnectedCause failed! errCode:%{public}d", ret);
134     } else {
135         TELEPHONY_LOGI("UpdateDisconnectedCause success!");
136     }
137     return ret;
138 }
139 
UpdateEventResultInfo(const CellularCallEventInfo & info)140 int32_t CallStatusCallback::UpdateEventResultInfo(const CellularCallEventInfo &info)
141 {
142     int32_t ret = DelayedSingleton<ReportCallInfoHandler>::GetInstance()->UpdateEventResultInfo(info);
143     if (ret != TELEPHONY_SUCCESS) {
144         TELEPHONY_LOGE("UpdateEventResultInfo failed! errCode:%{public}d", ret);
145     } else {
146         TELEPHONY_LOGI("UpdateEventResultInfo success!");
147     }
148     return ret;
149 }
150 
UpdateVoipEventInfo(const VoipCallEventInfo & info)151 int32_t CallStatusCallback::UpdateVoipEventInfo(const VoipCallEventInfo &info)
152 {
153     int32_t ret = DelayedSingleton<ReportCallInfoHandler>::GetInstance()->UpdateVoipEventInfo(info);
154     if (ret != TELEPHONY_SUCCESS) {
155         TELEPHONY_LOGE("UpdateVoipEventInfo failed! errCode:%{public}d", ret);
156     } else {
157         TELEPHONY_LOGI("UpdateVoipEventInfo success!");
158     }
159     return ret;
160 }
161 
UpdateRBTPlayInfo(const RBTPlayInfo info)162 int32_t CallStatusCallback::UpdateRBTPlayInfo(const RBTPlayInfo info)
163 {
164     TELEPHONY_LOGI("UpdateRBTPlayInfo info = %{public}d", info);
165     bool isLocalRingbackNeeded = false;
166     if (info == RBTPlayInfo::LOCAL_ALERTING) {
167         isLocalRingbackNeeded = true;
168         CallEventInfo eventInfo;
169         eventInfo.eventId = CallAbilityEventId::EVENT_LOCAL_ALERTING;
170         DelayedSingleton<CallAbilityReportProxy>::GetInstance()->CallEventUpdated(eventInfo);
171     }
172     DelayedSingleton<AudioControlManager>::GetInstance()->SetLocalRingbackNeeded(isLocalRingbackNeeded);
173     return TELEPHONY_SUCCESS;
174 }
175 
StartDtmfResult(const int32_t result)176 int32_t CallStatusCallback::StartDtmfResult(const int32_t result)
177 {
178     CallResultReportId reportId = CallResultReportId::START_DTMF_REPORT_ID;
179     AppExecFwk::PacMap resultInfo;
180     resultInfo.PutIntValue("result", result);
181     TELEPHONY_LOGI("StartDtmfResult result = %{public}d", result);
182     return DelayedSingleton<CallAbilityReportProxy>::GetInstance()->ReportAsyncResults(reportId, resultInfo);
183 }
184 
StopDtmfResult(const int32_t result)185 int32_t CallStatusCallback::StopDtmfResult(const int32_t result)
186 {
187     CallResultReportId reportId = CallResultReportId::STOP_DTMF_REPORT_ID;
188     AppExecFwk::PacMap resultInfo;
189     resultInfo.PutIntValue("result", result);
190     TELEPHONY_LOGI("StopDtmfResult result = %{public}d", result);
191     return DelayedSingleton<CallAbilityReportProxy>::GetInstance()->ReportAsyncResults(reportId, resultInfo);
192 }
193 
SendUssdResult(const int32_t result)194 int32_t CallStatusCallback::SendUssdResult(const int32_t result)
195 {
196     CallResultReportId reportId = CallResultReportId::SEND_USSD_REPORT_ID;
197     AppExecFwk::PacMap resultInfo;
198     resultInfo.PutIntValue("result", result);
199     TELEPHONY_LOGI("SendUssdResult result = %{public}d", result);
200     return DelayedSingleton<CallAbilityReportProxy>::GetInstance()->ReportAsyncResults(reportId, resultInfo);
201 }
202 
SendMmiCodeResult(const MmiCodeInfo & info)203 int32_t CallStatusCallback::SendMmiCodeResult(const MmiCodeInfo &info)
204 {
205     ffrt::submit_h([info] {
206         TELEPHONY_LOGI("SendMmiCodeResult result = %{public}d, message = %{public}s", info.result, info.message);
207         int32_t ret = DelayedSingleton<CallAbilityReportProxy>::GetInstance()->ReportMmiCodeResult(info);
208         if (ret != TELEPHONY_SUCCESS) {
209             TELEPHONY_LOGE("SendMmiCodeResult failed! errCode:%{public}d", ret);
210         } else {
211             TELEPHONY_LOGI("SendMmiCodeResult success!");
212         }
213         return ret;
214         }, {}, {}, ffrt::task_attr().delay(REPORT_SEND_USSD_DELAY_TIME));
215     return TELEPHONY_SUCCESS;
216 }
217 
GetImsCallDataResult(const int32_t result)218 int32_t CallStatusCallback::GetImsCallDataResult(const int32_t result)
219 {
220     CallResultReportId reportId = CallResultReportId::GET_IMS_CALL_DATA_REPORT_ID;
221     AppExecFwk::PacMap resultInfo;
222     resultInfo.PutIntValue("result", result);
223     TELEPHONY_LOGI("GetImsCallDataResult result = %{public}d", result);
224     return DelayedSingleton<CallAbilityReportProxy>::GetInstance()->ReportAsyncResults(reportId, resultInfo);
225 }
226 
UpdateGetWaitingResult(const CallWaitResponse & response)227 int32_t CallStatusCallback::UpdateGetWaitingResult(const CallWaitResponse &response)
228 {
229     TELEPHONY_LOGI("GetWaitingResult status = %{public}d, classCw = %{public}d, result = %{public}d", response.status,
230         response.classCw, response.result);
231     CallResultReportId reportId = CallResultReportId::GET_CALL_WAITING_REPORT_ID;
232     AppExecFwk::PacMap resultInfo;
233     resultInfo.PutIntValue("result", response.result);
234     resultInfo.PutIntValue("status", response.status);
235     resultInfo.PutIntValue("classCw", response.classCw);
236     DelayedSingleton<CallAbilityReportProxy>::GetInstance()->ReportAsyncResults(reportId, resultInfo);
237     return TELEPHONY_SUCCESS;
238 }
239 
UpdateSetWaitingResult(const int32_t result)240 int32_t CallStatusCallback::UpdateSetWaitingResult(const int32_t result)
241 {
242     TELEPHONY_LOGI("SetWaitingResult result = %{public}d", result);
243     CallResultReportId reportId = CallResultReportId::SET_CALL_WAITING_REPORT_ID;
244     AppExecFwk::PacMap resultInfo;
245     resultInfo.PutIntValue("result", result);
246     DelayedSingleton<CallAbilityReportProxy>::GetInstance()->ReportAsyncResults(reportId, resultInfo);
247     return TELEPHONY_SUCCESS;
248 }
249 
UpdateGetRestrictionResult(const CallRestrictionResponse & result)250 int32_t CallStatusCallback::UpdateGetRestrictionResult(const CallRestrictionResponse &result)
251 {
252     TELEPHONY_LOGI("GetRestrictionResult status = %{public}d, classCw = %{public}d, result = %{public}d",
253         result.status, result.classCw, result.result);
254     CallResultReportId reportId = CallResultReportId::GET_CALL_RESTRICTION_REPORT_ID;
255     AppExecFwk::PacMap resultInfo;
256     resultInfo.PutIntValue("result", result.result);
257     resultInfo.PutIntValue("status", result.status);
258     resultInfo.PutIntValue("classCw", result.classCw);
259     return DelayedSingleton<CallAbilityReportProxy>::GetInstance()->ReportAsyncResults(reportId, resultInfo);
260 }
261 
UpdateSetRestrictionResult(const int32_t result)262 int32_t CallStatusCallback::UpdateSetRestrictionResult(const int32_t result)
263 {
264     TELEPHONY_LOGI("SetRestrictionResult result = %{public}d", result);
265     CallResultReportId reportId = CallResultReportId::SET_CALL_RESTRICTION_REPORT_ID;
266     AppExecFwk::PacMap resultInfo;
267     resultInfo.PutIntValue("result", result);
268     return DelayedSingleton<CallAbilityReportProxy>::GetInstance()->ReportAsyncResults(reportId, resultInfo);
269 }
270 
UpdateSetRestrictionPasswordResult(const int32_t result)271 int32_t CallStatusCallback::UpdateSetRestrictionPasswordResult(const int32_t result)
272 {
273     TELEPHONY_LOGI("SetRestrictionPassword result = %{public}d", result);
274     CallResultReportId reportId = CallResultReportId::SET_CALL_RESTRICTION_PWD_REPORT_ID;
275     AppExecFwk::PacMap resultInfo;
276     resultInfo.PutIntValue("result", result);
277     return DelayedSingleton<CallAbilityReportProxy>::GetInstance()->ReportAsyncResults(reportId, resultInfo);
278 }
279 
UpdateGetTransferResult(const CallTransferResponse & response)280 int32_t CallStatusCallback::UpdateGetTransferResult(const CallTransferResponse &response)
281 {
282     CallResultReportId reportId = CallResultReportId::GET_CALL_TRANSFER_REPORT_ID;
283     AppExecFwk::PacMap resultInfo;
284     resultInfo.PutIntValue("result", response.result);
285     resultInfo.PutIntValue("status", response.status);
286     resultInfo.PutIntValue("classx", response.classx);
287     resultInfo.PutStringValue("number", response.number);
288     resultInfo.PutIntValue("type", response.type);
289     resultInfo.PutIntValue("reason", response.reason);
290     resultInfo.PutIntValue("time", response.time);
291     resultInfo.PutIntValue("startHour", response.startHour);
292     resultInfo.PutIntValue("startMinute", response.startMinute);
293     resultInfo.PutIntValue("endHour", response.endHour);
294     resultInfo.PutIntValue("endMinute", response.endMinute);
295     return DelayedSingleton<CallAbilityReportProxy>::GetInstance()->ReportAsyncResults(reportId, resultInfo);
296 }
297 
UpdateSetTransferResult(const int32_t result)298 int32_t CallStatusCallback::UpdateSetTransferResult(const int32_t result)
299 {
300     TELEPHONY_LOGI("SetTransferResult result = %{public}d", result);
301     CallResultReportId reportId = CallResultReportId::SET_CALL_TRANSFER_REPORT_ID;
302     AppExecFwk::PacMap resultInfo;
303     resultInfo.PutIntValue("result", result);
304     return DelayedSingleton<CallAbilityReportProxy>::GetInstance()->ReportAsyncResults(reportId, resultInfo);
305 }
306 
UpdateGetCallClipResult(const ClipResponse & clipResponse)307 int32_t CallStatusCallback::UpdateGetCallClipResult(const ClipResponse &clipResponse)
308 {
309     TELEPHONY_LOGI("GetCallClipResult action = %{public}d, clipStat = %{public}d, result = %{public}d",
310         clipResponse.action, clipResponse.clipStat, clipResponse.result);
311     CallResultReportId reportId = CallResultReportId::GET_CALL_CLIP_ID;
312     AppExecFwk::PacMap resultInfo;
313     resultInfo.PutIntValue("result", clipResponse.result);
314     resultInfo.PutIntValue("action", clipResponse.action);
315     resultInfo.PutIntValue("clipStat", clipResponse.clipStat);
316     return DelayedSingleton<CallAbilityReportProxy>::GetInstance()->ReportAsyncResults(reportId, resultInfo);
317 }
318 
UpdateGetCallClirResult(const ClirResponse & clirResponse)319 int32_t CallStatusCallback::UpdateGetCallClirResult(const ClirResponse &clirResponse)
320 {
321     TELEPHONY_LOGI("GetCallClirResult action = %{public}d, clirStat = %{public}d, result = %{public}d",
322         clirResponse.action, clirResponse.clirStat, clirResponse.result);
323     CallResultReportId reportId = CallResultReportId::GET_CALL_CLIR_ID;
324     AppExecFwk::PacMap resultInfo;
325     resultInfo.PutIntValue("result", clirResponse.result);
326     resultInfo.PutIntValue("action", clirResponse.action);
327     resultInfo.PutIntValue("clirStat", clirResponse.clirStat);
328     return DelayedSingleton<CallAbilityReportProxy>::GetInstance()->ReportAsyncResults(reportId, resultInfo);
329 }
330 
UpdateSetCallClirResult(const int32_t result)331 int32_t CallStatusCallback::UpdateSetCallClirResult(const int32_t result)
332 {
333     TELEPHONY_LOGI("GetCallClirResult result = %{public}d", result);
334     CallResultReportId reportId = CallResultReportId::SET_CALL_CLIR_ID;
335     AppExecFwk::PacMap resultInfo;
336     resultInfo.PutIntValue("result", result);
337     return DelayedSingleton<CallAbilityReportProxy>::GetInstance()->ReportAsyncResults(reportId, resultInfo);
338 }
339 
StartRttResult(const int32_t result)340 int32_t CallStatusCallback::StartRttResult(const int32_t result)
341 {
342     TELEPHONY_LOGI("StartRttResult result = %{public}d", result);
343     CallResultReportId reportId = CallResultReportId::START_RTT_REPORT_ID;
344     AppExecFwk::PacMap resultInfo;
345     resultInfo.PutIntValue("result", result);
346     return DelayedSingleton<CallAbilityReportProxy>::GetInstance()->ReportAsyncResults(reportId, resultInfo);
347 }
348 
StopRttResult(const int32_t result)349 int32_t CallStatusCallback::StopRttResult(const int32_t result)
350 {
351     TELEPHONY_LOGI("StopRttResult result = %{public}d", result);
352     CallResultReportId reportId = CallResultReportId::STOP_RTT_REPORT_ID;
353     AppExecFwk::PacMap resultInfo;
354     resultInfo.PutIntValue("result", result);
355     return DelayedSingleton<CallAbilityReportProxy>::GetInstance()->ReportAsyncResults(reportId, resultInfo);
356 }
357 
GetImsConfigResult(const GetImsConfigResponse & response)358 int32_t CallStatusCallback::GetImsConfigResult(const GetImsConfigResponse &response)
359 {
360     CallResultReportId reportId = CallResultReportId::GET_IMS_CONFIG_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 
SetImsConfigResult(const int32_t result)368 int32_t CallStatusCallback::SetImsConfigResult(const int32_t result)
369 {
370     CallResultReportId reportId = CallResultReportId::SET_IMS_CONFIG_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 
GetImsFeatureValueResult(const GetImsFeatureValueResponse & response)377 int32_t CallStatusCallback::GetImsFeatureValueResult(const GetImsFeatureValueResponse &response)
378 {
379     CallResultReportId reportId = CallResultReportId::GET_IMS_FEATURE_VALUE_REPORT_ID;
380     AppExecFwk::PacMap resultInfo;
381     resultInfo.PutIntValue("result", response.result);
382     resultInfo.PutIntValue("value", response.value);
383     TELEPHONY_LOGI("result = %{public}d value = %{public}d", response.result, response.value);
384     return DelayedSingleton<CallAbilityReportProxy>::GetInstance()->ReportAsyncResults(reportId, resultInfo);
385 }
386 
SetImsFeatureValueResult(const int32_t result)387 int32_t CallStatusCallback::SetImsFeatureValueResult(const int32_t result)
388 {
389     CallResultReportId reportId = CallResultReportId::SET_IMS_FEATURE_VALUE_REPORT_ID;
390     AppExecFwk::PacMap resultInfo;
391     resultInfo.PutIntValue("result", result);
392     TELEPHONY_LOGI("result = %{public}d", result);
393     return DelayedSingleton<CallAbilityReportProxy>::GetInstance()->ReportAsyncResults(reportId, resultInfo);
394 }
395 
ReceiveUpdateCallMediaModeRequest(const CallModeReportInfo & response)396 int32_t CallStatusCallback::ReceiveUpdateCallMediaModeRequest(const CallModeReportInfo &response)
397 {
398     auto weak = weak_from_this();
399     TELEPHONY_LOGI("ReceiveUpdateCallMediaModeRequest result = %{public}d", response.result);
400     int32_t ret = DelayedSingleton<ReportCallInfoHandler>::GetInstance()->ReceiveImsCallModeRequest(response);
401     if (ret != TELEPHONY_SUCCESS) {
402         TELEPHONY_LOGE("ReceiveUpdateCallMediaModeRequest failed! errCode:%{public}d", ret);
403     } else {
404         TELEPHONY_LOGI("ReceiveUpdateCallMediaModeRequest success!");
405     }
406     sptr<CallBase> callPtr = CallObjectManager::GetOneCallObjectByIndexAndSlotId(response.callIndex, response.slotId);
407     if (callPtr != nullptr && callPtr->GetTelCallState() == TelCallState::CALL_STATUS_ACTIVE
408         && response.callMode == ImsCallMode::CALL_MODE_SEND_RECEIVE) {
409         if (DelayedSingleton<AudioControlManager>::GetInstance()->PlayWaitingTone() == TELEPHONY_SUCCESS) {
410             waitingToneHandle_ = ffrt::submit_h([weak]() {
411                 auto strong = weak.lock();
412                 if (strong) {
413                     strong->ShouldStopWaitingTone();
414                 }
415             }, {}, {}, ffrt::task_attr().delay(DELAY_STOP_PLAY_TIME));
416         }
417     }
418     return ret;
419 }
420 
ReceiveUpdateCallMediaModeResponse(const CallModeReportInfo & response)421 int32_t CallStatusCallback::ReceiveUpdateCallMediaModeResponse(const CallModeReportInfo &response)
422 {
423     TELEPHONY_LOGI("ReceiveUpdateCallMediaModeResponse result = %{public}d", response.result);
424     int32_t ret = DelayedSingleton<ReportCallInfoHandler>::GetInstance()->ReceiveImsCallModeResponse(response);
425     if (ret != TELEPHONY_SUCCESS) {
426         TELEPHONY_LOGE("ReceiveUpdateCallMediaModeResponse failed! errCode:%{public}d", ret);
427     } else {
428         TELEPHONY_LOGI("ReceiveUpdateCallMediaModeResponse success!");
429     }
430     if (waitingToneHandle_ != nullptr) {
431         if (int result = ffrt::skip(waitingToneHandle_) != TELEPHONY_SUCCESS) {
432             TELEPHONY_LOGE("ReceiveUpdateCallMediaModeResponse failed! result:%{public}d", result);
433         }
434         ShouldStopWaitingTone();
435     }
436     return ret;
437 }
438 
ShouldStopWaitingTone()439 void CallStatusCallback::ShouldStopWaitingTone()
440 {
441     bool hasRingingCall = false;
442     CallObjectManager::HasRingingCall(hasRingingCall);
443     if (!(hasRingingCall && (CallObjectManager::GetCurrentCallNum() >= MIN_MULITY_CALL_COUNT))) {
444         DelayedSingleton<AudioControlManager>::GetInstance()->StopWaitingTone();
445     }
446     waitingToneHandle_ = nullptr;
447 }
448 
InviteToConferenceResult(const int32_t result)449 int32_t CallStatusCallback::InviteToConferenceResult(const int32_t result)
450 {
451     CallResultReportId reportId = CallResultReportId::INVITE_TO_CONFERENCE_REPORT_ID;
452     AppExecFwk::PacMap resultInfo;
453     resultInfo.PutIntValue("result", result);
454     TELEPHONY_LOGI("InviteToConferenceResult result = %{public}d", result);
455     return DelayedSingleton<CallAbilityReportProxy>::GetInstance()->ReportAsyncResults(reportId, resultInfo);
456 }
457 
CloseUnFinishedUssdResult(const int32_t result)458 int32_t CallStatusCallback::CloseUnFinishedUssdResult(const int32_t result)
459 {
460     CallResultReportId reportId = CallResultReportId::CLOSE_UNFINISHED_USSD_REPORT_ID;
461     AppExecFwk::PacMap resultInfo;
462     resultInfo.PutIntValue("result", result);
463     TELEPHONY_LOGI("CloseUnFinishedUssdResult result = %{public}d", result);
464     return DelayedSingleton<CallAbilityReportProxy>::GetInstance()->ReportAsyncResults(reportId, resultInfo);
465 }
466 
ReportPostDialChar(const std::string & c)467 int32_t CallStatusCallback::ReportPostDialChar(const std::string &c)
468 {
469     TELEPHONY_LOGI("ReportPostDialChar");
470     char nextDtmf = ' ';
471     if (!c.empty() && c.length() > CHAR_INDEX) {
472         nextDtmf = c[CHAR_INDEX];
473     }
474     return DelayedSingleton<AudioControlManager>::GetInstance()->OnPostDialNextChar(nextDtmf);
475 }
476 
ReportPostDialDelay(const std::string & str)477 int32_t CallStatusCallback::ReportPostDialDelay(const std::string &str)
478 {
479     TELEPHONY_LOGI("ReportPostDialDelay");
480     return DelayedSingleton<CallAbilityReportProxy>::GetInstance()->ReportPostDialDelay(str);
481 }
482 
HandleCallSessionEventChanged(const CallSessionReportInfo & reportInfo)483 int32_t CallStatusCallback::HandleCallSessionEventChanged(const CallSessionReportInfo &reportInfo)
484 {
485     TELEPHONY_LOGI("HandleCallSessionEventChanged");
486     sptr<CallBase> callPtr = CallObjectManager::GetOneCallObjectByIndex(reportInfo.index);
487     CallSessionEvent sessionEvent;
488     if (callPtr == nullptr) {
489         sessionEvent.callId = ERR_CALL_ID;
490     } else {
491         sessionEvent.callId = callPtr->GetCallID();
492     }
493     sessionEvent.eventId = reportInfo.eventId;
494     return DelayedSingleton<CallAbilityReportProxy>::GetInstance()->ReportCallSessionEventChange(sessionEvent);
495 }
496 
HandlePeerDimensionsChanged(const PeerDimensionsReportInfo & dimensionsReportInfo)497 int32_t CallStatusCallback::HandlePeerDimensionsChanged(const PeerDimensionsReportInfo &dimensionsReportInfo)
498 {
499     TELEPHONY_LOGI("HandlePeerDimensionsChanged");
500     sptr<CallBase> callPtr = CallObjectManager::GetOneCallObjectByIndex(dimensionsReportInfo.index);
501     PeerDimensionsDetail detail;
502     if (callPtr == nullptr) {
503         detail.callId = ERR_CALL_ID;
504     } else {
505         detail.callId = callPtr->GetCallID();
506     }
507     detail.width = dimensionsReportInfo.width;
508     detail.height = dimensionsReportInfo.height;
509     return DelayedSingleton<CallAbilityReportProxy>::GetInstance()->ReportPeerDimensionsChange(detail);
510 }
511 
HandleCallDataUsageChanged(const int64_t dataUsage)512 int32_t CallStatusCallback::HandleCallDataUsageChanged(const int64_t dataUsage)
513 {
514     TELEPHONY_LOGI("HandleCallDataUsageChanged");
515     return DelayedSingleton<CallAbilityReportProxy>::GetInstance()->ReportCallDataUsageChange(dataUsage);
516 }
517 
HandleCameraCapabilitiesChanged(const CameraCapabilitiesReportInfo & cameraCapabilitiesReportInfo)518 int32_t CallStatusCallback::HandleCameraCapabilitiesChanged(
519     const CameraCapabilitiesReportInfo &cameraCapabilitiesReportInfo)
520 {
521     TELEPHONY_LOGI("CameraCapabilitiesChange");
522     sptr<CallBase> callPtr = CallObjectManager::GetOneCallObjectByIndex(cameraCapabilitiesReportInfo.index);
523     CameraCapabilities cameraCapabilities;
524     if (callPtr == nullptr) {
525         TELEPHONY_LOGI("callPtr is null, set callId as ERR_CALL_ID");
526         cameraCapabilities.callId = ERR_CALL_ID;
527     } else {
528         cameraCapabilities.callId = callPtr->GetCallID();
529     }
530     cameraCapabilities.width = cameraCapabilitiesReportInfo.width;
531     cameraCapabilities.height = cameraCapabilitiesReportInfo.height;
532     return DelayedSingleton<CallAbilityReportProxy>::GetInstance()->ReportCameraCapabilities(cameraCapabilities);
533 }
534 } // namespace Telephony
535 } // namespace OHOS
536