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