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 "hitrace_meter.h"
23 #include "report_call_info_handler.h"
24 #include "telephony_log_wrapper.h"
25
26 namespace OHOS {
27 namespace Telephony {
28 constexpr size_t CHAR_INDEX = 0;
29
CallStatusCallback()30 CallStatusCallback::CallStatusCallback() {}
31
~CallStatusCallback()32 CallStatusCallback::~CallStatusCallback() {}
33
UpdateCallReportInfo(const CallReportInfo & info)34 int32_t CallStatusCallback::UpdateCallReportInfo(const CallReportInfo &info)
35 {
36 CallDetailInfo detailInfo;
37 detailInfo.callType = info.callType;
38 detailInfo.accountId = info.accountId;
39 detailInfo.index = info.index;
40 detailInfo.state = info.state;
41 detailInfo.callMode = info.callMode;
42 detailInfo.voiceDomain = info.voiceDomain;
43 detailInfo.mpty = info.mpty;
44 (void)memcpy_s(detailInfo.phoneNum, kMaxNumberLen, info.accountNum, kMaxNumberLen);
45 (void)memset_s(detailInfo.bundleName, kMaxBundleNameLen, 0, kMaxBundleNameLen);
46 int32_t ret = DelayedSingleton<ReportCallInfoHandler>::GetInstance()->UpdateCallReportInfo(detailInfo);
47 if (ret != TELEPHONY_SUCCESS) {
48 TELEPHONY_LOGE("UpdateCallReportInfo failed! errCode:%{public}d", ret);
49 } else {
50 TELEPHONY_LOGI("UpdateCallReportInfo success! state:%{public}d", info.state);
51 }
52 return ret;
53 }
54
UpdateCallsReportInfo(const CallsReportInfo & info)55 int32_t CallStatusCallback::UpdateCallsReportInfo(const CallsReportInfo &info)
56 {
57 CallDetailsInfo detailsInfo;
58 CallDetailInfo detailInfo;
59 detailInfo.index = 0;
60 detailInfo.state = TelCallState::CALL_STATUS_UNKNOWN;
61 CallsReportInfo callsInfo = info;
62 std::vector<CallReportInfo>::iterator it = callsInfo.callVec.begin();
63 for (; it != callsInfo.callVec.end(); ++it) {
64 detailInfo.callType = (*it).callType;
65 detailInfo.accountId = (*it).accountId;
66 detailInfo.index = (*it).index;
67 detailInfo.state = (*it).state;
68 detailInfo.callMode = (*it).callMode;
69 detailInfo.voiceDomain = (*it).voiceDomain;
70 detailInfo.mpty = (*it).mpty;
71 (void)memcpy_s(detailInfo.phoneNum, kMaxNumberLen, (*it).accountNum, kMaxNumberLen);
72 (void)memset_s(detailInfo.bundleName, kMaxBundleNameLen, 0, kMaxBundleNameLen);
73 detailsInfo.callVec.push_back(detailInfo);
74 }
75 detailsInfo.slotId = callsInfo.slotId;
76 CallManagerHisysevent::WriteCallStateBehaviorEvent(
77 detailsInfo.slotId, static_cast<int32_t>(detailInfo.state), detailInfo.index);
78 (void)memset_s(detailsInfo.bundleName, kMaxBundleNameLen, 0, kMaxBundleNameLen);
79
80 if (detailInfo.state == TelCallState::CALL_STATUS_INCOMING) {
81 CallManagerHisysevent::WriteIncomingCallBehaviorEvent(
82 detailsInfo.slotId, static_cast<int32_t>(detailInfo.callType), static_cast<int32_t>(detailInfo.callMode));
83 TELEPHONY_LOGI("CallStatusCallback InComingCall StartAsyncTrace!");
84 DelayedSingleton<CallManagerHisysevent>::GetInstance()->SetIncomingStartTime();
85 StartAsyncTrace(HITRACE_TAG_OHOS, "InComingCall", getpid());
86 }
87 int32_t ret = DelayedSingleton<ReportCallInfoHandler>::GetInstance()->UpdateCallsReportInfo(detailsInfo);
88 if (ret != TELEPHONY_SUCCESS) {
89 TELEPHONY_LOGE("UpdateCallsReportInfo failed! errCode:%{public}d", ret);
90 } else {
91 TELEPHONY_LOGI("UpdateCallsReportInfo success!");
92 }
93 return ret;
94 }
95
UpdateDisconnectedCause(const DisconnectedDetails & details)96 int32_t CallStatusCallback::UpdateDisconnectedCause(const DisconnectedDetails &details)
97 {
98 int32_t ret = DelayedSingleton<ReportCallInfoHandler>::GetInstance()->UpdateDisconnectedCause(details);
99 if (ret != TELEPHONY_SUCCESS) {
100 TELEPHONY_LOGE("UpdateDisconnectedCause failed! errCode:%{public}d", ret);
101 } else {
102 TELEPHONY_LOGI("UpdateDisconnectedCause success!");
103 }
104 return ret;
105 }
106
UpdateEventResultInfo(const CellularCallEventInfo & info)107 int32_t CallStatusCallback::UpdateEventResultInfo(const CellularCallEventInfo &info)
108 {
109 int32_t ret = DelayedSingleton<ReportCallInfoHandler>::GetInstance()->UpdateEventResultInfo(info);
110 if (ret != TELEPHONY_SUCCESS) {
111 TELEPHONY_LOGE("UpdateEventResultInfo failed! errCode:%{public}d", ret);
112 } else {
113 TELEPHONY_LOGI("UpdateEventResultInfo success!");
114 }
115 return ret;
116 }
117
UpdateRBTPlayInfo(const RBTPlayInfo info)118 int32_t CallStatusCallback::UpdateRBTPlayInfo(const RBTPlayInfo info)
119 {
120 TELEPHONY_LOGI("UpdateRBTPlayInfo info = %{public}d", info);
121 bool isLocalRingbackNeeded = false;
122 if (info == RBTPlayInfo::LOCAL_ALERTING) {
123 isLocalRingbackNeeded = true;
124 }
125 DelayedSingleton<AudioControlManager>::GetInstance()->SetLocalRingbackNeeded(isLocalRingbackNeeded);
126 return TELEPHONY_SUCCESS;
127 }
128
StartDtmfResult(const int32_t result)129 int32_t CallStatusCallback::StartDtmfResult(const int32_t result)
130 {
131 CallResultReportId reportId = CallResultReportId::START_DTMF_REPORT_ID;
132 AppExecFwk::PacMap resultInfo;
133 resultInfo.PutIntValue("result", result);
134 TELEPHONY_LOGI("StartDtmfResult result = %{public}d", result);
135 return DelayedSingleton<CallAbilityReportProxy>::GetInstance()->ReportAsyncResults(reportId, resultInfo);
136 }
137
StopDtmfResult(const int32_t result)138 int32_t CallStatusCallback::StopDtmfResult(const int32_t result)
139 {
140 CallResultReportId reportId = CallResultReportId::STOP_DTMF_REPORT_ID;
141 AppExecFwk::PacMap resultInfo;
142 resultInfo.PutIntValue("result", result);
143 TELEPHONY_LOGI("StopDtmfResult result = %{public}d", result);
144 return DelayedSingleton<CallAbilityReportProxy>::GetInstance()->ReportAsyncResults(reportId, resultInfo);
145 }
146
SendUssdResult(const int32_t result)147 int32_t CallStatusCallback::SendUssdResult(const int32_t result)
148 {
149 CallResultReportId reportId = CallResultReportId::SEND_USSD_REPORT_ID;
150 AppExecFwk::PacMap resultInfo;
151 resultInfo.PutIntValue("result", result);
152 TELEPHONY_LOGI("SendUssdResult result = %{public}d", result);
153 return DelayedSingleton<CallAbilityReportProxy>::GetInstance()->ReportAsyncResults(reportId, resultInfo);
154 }
155
SendMmiCodeResult(const MmiCodeInfo & info)156 int32_t CallStatusCallback::SendMmiCodeResult(const MmiCodeInfo &info)
157 {
158 TELEPHONY_LOGI("SendMmiCodeResult result = %{public}d, message = %{public}s", info.result, info.message);
159 int32_t ret = DelayedSingleton<CallAbilityReportProxy>::GetInstance()->ReportMmiCodeResult(info);
160 if (ret != TELEPHONY_SUCCESS) {
161 TELEPHONY_LOGE("UpdateDisconnectedCause failed! errCode:%{public}d", ret);
162 } else {
163 TELEPHONY_LOGI("UpdateDisconnectedCause success!");
164 }
165 return ret;
166 }
167
GetImsCallDataResult(const int32_t result)168 int32_t CallStatusCallback::GetImsCallDataResult(const int32_t result)
169 {
170 CallResultReportId reportId = CallResultReportId::GET_IMS_CALL_DATA_REPORT_ID;
171 AppExecFwk::PacMap resultInfo;
172 resultInfo.PutIntValue("result", result);
173 TELEPHONY_LOGI("GetImsCallDataResult result = %{public}d", result);
174 return DelayedSingleton<CallAbilityReportProxy>::GetInstance()->ReportAsyncResults(reportId, resultInfo);
175 }
176
UpdateGetWaitingResult(const CallWaitResponse & response)177 int32_t CallStatusCallback::UpdateGetWaitingResult(const CallWaitResponse &response)
178 {
179 TELEPHONY_LOGI("GetWaitingResult status = %{public}d, classCw = %{public}d, result = %{public}d", response.status,
180 response.classCw, response.result);
181 CallResultReportId reportId = CallResultReportId::GET_CALL_WAITING_REPORT_ID;
182 AppExecFwk::PacMap resultInfo;
183 resultInfo.PutIntValue("result", response.result);
184 resultInfo.PutIntValue("status", response.status);
185 resultInfo.PutIntValue("classCw", response.classCw);
186 DelayedSingleton<CallAbilityReportProxy>::GetInstance()->ReportAsyncResults(reportId, resultInfo);
187 return TELEPHONY_SUCCESS;
188 }
189
UpdateSetWaitingResult(const int32_t result)190 int32_t CallStatusCallback::UpdateSetWaitingResult(const int32_t result)
191 {
192 TELEPHONY_LOGI("SetWaitingResult result = %{public}d", result);
193 CallResultReportId reportId = CallResultReportId::SET_CALL_WAITING_REPORT_ID;
194 AppExecFwk::PacMap resultInfo;
195 resultInfo.PutIntValue("result", result);
196 DelayedSingleton<CallAbilityReportProxy>::GetInstance()->ReportAsyncResults(reportId, resultInfo);
197 return TELEPHONY_SUCCESS;
198 }
199
UpdateGetRestrictionResult(const CallRestrictionResponse & result)200 int32_t CallStatusCallback::UpdateGetRestrictionResult(const CallRestrictionResponse &result)
201 {
202 TELEPHONY_LOGI("GetRestrictionResult status = %{public}d, classCw = %{public}d, result = %{public}d",
203 result.status, result.classCw, result.result);
204 CallResultReportId reportId = CallResultReportId::GET_CALL_RESTRICTION_REPORT_ID;
205 AppExecFwk::PacMap resultInfo;
206 resultInfo.PutIntValue("result", result.result);
207 resultInfo.PutIntValue("status", result.status);
208 resultInfo.PutIntValue("classCw", result.classCw);
209 return DelayedSingleton<CallAbilityReportProxy>::GetInstance()->ReportAsyncResults(reportId, resultInfo);
210 }
211
UpdateSetRestrictionResult(const int32_t result)212 int32_t CallStatusCallback::UpdateSetRestrictionResult(const int32_t result)
213 {
214 TELEPHONY_LOGI("SetRestrictionResult result = %{public}d", result);
215 CallResultReportId reportId = CallResultReportId::SET_CALL_RESTRICTION_REPORT_ID;
216 AppExecFwk::PacMap resultInfo;
217 resultInfo.PutIntValue("result", result);
218 return DelayedSingleton<CallAbilityReportProxy>::GetInstance()->ReportAsyncResults(reportId, resultInfo);
219 }
220
UpdateSetRestrictionPasswordResult(const int32_t result)221 int32_t CallStatusCallback::UpdateSetRestrictionPasswordResult(const int32_t result)
222 {
223 TELEPHONY_LOGI("SetRestrictionPassword result = %{public}d", result);
224 CallResultReportId reportId = CallResultReportId::SET_CALL_RESTRICTION_PWD_REPORT_ID;
225 AppExecFwk::PacMap resultInfo;
226 resultInfo.PutIntValue("result", result);
227 return DelayedSingleton<CallAbilityReportProxy>::GetInstance()->ReportAsyncResults(reportId, resultInfo);
228 }
229
UpdateGetTransferResult(const CallTransferResponse & response)230 int32_t CallStatusCallback::UpdateGetTransferResult(const CallTransferResponse &response)
231 {
232 CallResultReportId reportId = CallResultReportId::GET_CALL_TRANSFER_REPORT_ID;
233 AppExecFwk::PacMap resultInfo;
234 resultInfo.PutIntValue("result", response.result);
235 resultInfo.PutIntValue("status", response.status);
236 resultInfo.PutIntValue("classx", response.classx);
237 resultInfo.PutStringValue("number", response.number);
238 resultInfo.PutIntValue("type", response.type);
239 resultInfo.PutIntValue("reason", response.reason);
240 resultInfo.PutIntValue("time", response.time);
241 resultInfo.PutIntValue("startHour", response.startHour);
242 resultInfo.PutIntValue("startMinute", response.startMinute);
243 resultInfo.PutIntValue("endHour", response.endHour);
244 resultInfo.PutIntValue("endMinute", response.endMinute);
245 return DelayedSingleton<CallAbilityReportProxy>::GetInstance()->ReportAsyncResults(reportId, resultInfo);
246 }
247
UpdateSetTransferResult(const int32_t result)248 int32_t CallStatusCallback::UpdateSetTransferResult(const int32_t result)
249 {
250 TELEPHONY_LOGI("SetTransferResult result = %{public}d", result);
251 CallResultReportId reportId = CallResultReportId::SET_CALL_TRANSFER_REPORT_ID;
252 AppExecFwk::PacMap resultInfo;
253 resultInfo.PutIntValue("result", result);
254 return DelayedSingleton<CallAbilityReportProxy>::GetInstance()->ReportAsyncResults(reportId, resultInfo);
255 }
256
UpdateGetCallClipResult(const ClipResponse & clipResponse)257 int32_t CallStatusCallback::UpdateGetCallClipResult(const ClipResponse &clipResponse)
258 {
259 TELEPHONY_LOGI("GetCallClipResult action = %{public}d, clipStat = %{public}d, result = %{public}d",
260 clipResponse.action, clipResponse.clipStat, clipResponse.result);
261 CallResultReportId reportId = CallResultReportId::GET_CALL_CLIP_ID;
262 AppExecFwk::PacMap resultInfo;
263 resultInfo.PutIntValue("result", clipResponse.result);
264 resultInfo.PutIntValue("action", clipResponse.action);
265 resultInfo.PutIntValue("clipStat", clipResponse.clipStat);
266 return DelayedSingleton<CallAbilityReportProxy>::GetInstance()->ReportAsyncResults(reportId, resultInfo);
267 }
268
UpdateGetCallClirResult(const ClirResponse & clirResponse)269 int32_t CallStatusCallback::UpdateGetCallClirResult(const ClirResponse &clirResponse)
270 {
271 TELEPHONY_LOGI("GetCallClirResult action = %{public}d, clirStat = %{public}d, result = %{public}d",
272 clirResponse.action, clirResponse.clirStat, clirResponse.result);
273 CallResultReportId reportId = CallResultReportId::GET_CALL_CLIR_ID;
274 AppExecFwk::PacMap resultInfo;
275 resultInfo.PutIntValue("result", clirResponse.result);
276 resultInfo.PutIntValue("action", clirResponse.action);
277 resultInfo.PutIntValue("clirStat", clirResponse.clirStat);
278 return DelayedSingleton<CallAbilityReportProxy>::GetInstance()->ReportAsyncResults(reportId, resultInfo);
279 }
280
UpdateSetCallClirResult(const int32_t result)281 int32_t CallStatusCallback::UpdateSetCallClirResult(const int32_t result)
282 {
283 TELEPHONY_LOGI("GetCallClirResult result = %{public}d", result);
284 CallResultReportId reportId = CallResultReportId::SET_CALL_CLIR_ID;
285 AppExecFwk::PacMap resultInfo;
286 resultInfo.PutIntValue("result", result);
287 return DelayedSingleton<CallAbilityReportProxy>::GetInstance()->ReportAsyncResults(reportId, resultInfo);
288 }
289
StartRttResult(const int32_t result)290 int32_t CallStatusCallback::StartRttResult(const int32_t result)
291 {
292 TELEPHONY_LOGI("StartRttResult result = %{public}d", result);
293 CallResultReportId reportId = CallResultReportId::START_RTT_REPORT_ID;
294 AppExecFwk::PacMap resultInfo;
295 resultInfo.PutIntValue("result", result);
296 return DelayedSingleton<CallAbilityReportProxy>::GetInstance()->ReportAsyncResults(reportId, resultInfo);
297 }
298
StopRttResult(const int32_t result)299 int32_t CallStatusCallback::StopRttResult(const int32_t result)
300 {
301 TELEPHONY_LOGI("StopRttResult result = %{public}d", result);
302 CallResultReportId reportId = CallResultReportId::STOP_RTT_REPORT_ID;
303 AppExecFwk::PacMap resultInfo;
304 resultInfo.PutIntValue("result", result);
305 return DelayedSingleton<CallAbilityReportProxy>::GetInstance()->ReportAsyncResults(reportId, resultInfo);
306 }
307
GetImsConfigResult(const GetImsConfigResponse & response)308 int32_t CallStatusCallback::GetImsConfigResult(const GetImsConfigResponse &response)
309 {
310 CallResultReportId reportId = CallResultReportId::GET_IMS_CONFIG_REPORT_ID;
311 AppExecFwk::PacMap resultInfo;
312 resultInfo.PutIntValue("result", response.result);
313 resultInfo.PutIntValue("value", response.value);
314 TELEPHONY_LOGI("result = %{public}d value = %{public}d", response.result, response.value);
315 return DelayedSingleton<CallAbilityReportProxy>::GetInstance()->ReportAsyncResults(reportId, resultInfo);
316 }
317
SetImsConfigResult(const int32_t result)318 int32_t CallStatusCallback::SetImsConfigResult(const int32_t result)
319 {
320 CallResultReportId reportId = CallResultReportId::SET_IMS_CONFIG_REPORT_ID;
321 AppExecFwk::PacMap resultInfo;
322 resultInfo.PutIntValue("result", result);
323 TELEPHONY_LOGI("result = %{public}d", result);
324 return DelayedSingleton<CallAbilityReportProxy>::GetInstance()->ReportAsyncResults(reportId, resultInfo);
325 }
326
GetImsFeatureValueResult(const GetImsFeatureValueResponse & response)327 int32_t CallStatusCallback::GetImsFeatureValueResult(const GetImsFeatureValueResponse &response)
328 {
329 CallResultReportId reportId = CallResultReportId::GET_IMS_FEATURE_VALUE_REPORT_ID;
330 AppExecFwk::PacMap resultInfo;
331 resultInfo.PutIntValue("result", response.result);
332 resultInfo.PutIntValue("value", response.value);
333 TELEPHONY_LOGI("result = %{public}d value = %{public}d", response.result, response.value);
334 return DelayedSingleton<CallAbilityReportProxy>::GetInstance()->ReportAsyncResults(reportId, resultInfo);
335 }
336
SetImsFeatureValueResult(const int32_t result)337 int32_t CallStatusCallback::SetImsFeatureValueResult(const int32_t result)
338 {
339 CallResultReportId reportId = CallResultReportId::SET_IMS_FEATURE_VALUE_REPORT_ID;
340 AppExecFwk::PacMap resultInfo;
341 resultInfo.PutIntValue("result", result);
342 TELEPHONY_LOGI("result = %{public}d", result);
343 return DelayedSingleton<CallAbilityReportProxy>::GetInstance()->ReportAsyncResults(reportId, resultInfo);
344 }
345
ReceiveUpdateCallMediaModeResponse(const CallMediaModeResponse & response)346 int32_t CallStatusCallback::ReceiveUpdateCallMediaModeResponse(const CallMediaModeResponse &response)
347 {
348 CallResultReportId reportId = CallResultReportId::UPDATE_MEDIA_MODE_REPORT_ID;
349 AppExecFwk::PacMap resultInfo;
350 resultInfo.PutIntValue("result", response.result);
351 TELEPHONY_LOGI("UpdateImsCallMode result = %{public}d", response.result);
352 (void)DelayedSingleton<ReportCallInfoHandler>::GetInstance()->UpdateMediaModeResponse(response);
353 return DelayedSingleton<CallAbilityReportProxy>::GetInstance()->ReportAsyncResults(reportId, resultInfo);
354 }
355
InviteToConferenceResult(const int32_t result)356 int32_t CallStatusCallback::InviteToConferenceResult(const int32_t result)
357 {
358 CallResultReportId reportId = CallResultReportId::INVITE_TO_CONFERENCE_REPORT_ID;
359 AppExecFwk::PacMap resultInfo;
360 resultInfo.PutIntValue("result", result);
361 TELEPHONY_LOGI("InviteToConferenceResult result = %{public}d", result);
362 return DelayedSingleton<CallAbilityReportProxy>::GetInstance()->ReportAsyncResults(reportId, resultInfo);
363 }
364
CloseUnFinishedUssdResult(const int32_t result)365 int32_t CallStatusCallback::CloseUnFinishedUssdResult(const int32_t result)
366 {
367 CallResultReportId reportId = CallResultReportId::CLOSE_UNFINISHED_USSD_REPORT_ID;
368 AppExecFwk::PacMap resultInfo;
369 resultInfo.PutIntValue("result", result);
370 TELEPHONY_LOGI("CloseUnFinishedUssdResult result = %{public}d", result);
371 return DelayedSingleton<CallAbilityReportProxy>::GetInstance()->ReportAsyncResults(reportId, resultInfo);
372 }
373
ReportPostDialChar(const std::string & c)374 int32_t CallStatusCallback::ReportPostDialChar(const std::string &c)
375 {
376 TELEPHONY_LOGI("CallStatusCallback::ReportPostDialChar");
377 char nextDtmf = ' ';
378 if (!c.empty() && c.length() > CHAR_INDEX) {
379 nextDtmf = c[CHAR_INDEX];
380 }
381 return DelayedSingleton<AudioControlManager>::GetInstance()->OnPostDialNextChar(nextDtmf);
382 }
383
ReportPostDialDelay(const std::string & str)384 int32_t CallStatusCallback::ReportPostDialDelay(const std::string &str)
385 {
386 TELEPHONY_LOGI("CallStatusCallback::ReportPostDialDelay");
387 return DelayedSingleton<CallAbilityReportProxy>::GetInstance()->ReportPostDialDelay(str);
388 }
389 } // namespace Telephony
390 } // namespace OHOS
391