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 "cellular_call_register.h"
17
18 #include "call_status_callback_proxy.h"
19 #include "cellular_call_hisysevent.h"
20 #include "hitrace_meter.h"
21 #include "iservice_registry.h"
22
23 namespace OHOS {
24 namespace Telephony {
CellularCallRegister()25 CellularCallRegister::CellularCallRegister() : callManagerCallBack_(nullptr) {}
26
~CellularCallRegister()27 CellularCallRegister::~CellularCallRegister() {}
28
ReportCallsInfo(const CallsReportInfo & callsReportInfo)29 void CellularCallRegister::ReportCallsInfo(const CallsReportInfo &callsReportInfo)
30 {
31 TELEPHONY_LOGI("ReportCallsInfo entry.");
32 CallsReportInfo callsInfo = callsReportInfo;
33 CallDetailInfo detailInfo;
34 detailInfo.state = TelCallState::CALL_STATUS_UNKNOWN;
35 std::vector<CallReportInfo>::iterator it = callsInfo.callVec.begin();
36 for (; it != callsInfo.callVec.end(); ++it) {
37 detailInfo.callType = (*it).callType;
38 detailInfo.accountId = (*it).accountId;
39 detailInfo.state = (*it).state;
40 detailInfo.callMode = (*it).callMode;
41 }
42
43 if (callManagerCallBack_ == nullptr) {
44 TELEPHONY_LOGE("ReportCallsInfo return, callManagerCallBack_ is nullptr, report fail!");
45 if (detailInfo.state == TelCallState::CALL_STATUS_INCOMING) {
46 FinishAsyncTrace(HITRACE_TAG_OHOS, "CellularCallIncoming", getpid());
47 }
48 return;
49 }
50
51 if (detailInfo.state == TelCallState::CALL_STATUS_INCOMING) {
52 DelayedSingleton<CellularCallHiSysEvent>::GetInstance()->SetIncomingCallParameterInfo(
53 static_cast<int32_t>(detailInfo.callType), static_cast<int32_t>(detailInfo.callMode));
54 FinishAsyncTrace(HITRACE_TAG_OHOS, "CellularCallIncoming", getpid());
55 }
56 callManagerCallBack_->UpdateCallsReportInfo(callsReportInfo);
57 }
58
RegisterCallManagerCallBack(const sptr<ICallStatusCallback> & callback)59 int32_t CellularCallRegister::RegisterCallManagerCallBack(const sptr<ICallStatusCallback> &callback)
60 {
61 callManagerCallBack_ = callback;
62 return TELEPHONY_SUCCESS;
63 }
64
ReportSingleCallInfo(const CallReportInfo & info,TelCallState callState)65 void CellularCallRegister::ReportSingleCallInfo(const CallReportInfo &info, TelCallState callState)
66 {
67 TELEPHONY_LOGI("ReportSingleCallInfo entry");
68 CallReportInfo cellularCallReportInfo = info;
69 cellularCallReportInfo.state = callState;
70 if (callManagerCallBack_ == nullptr) {
71 TELEPHONY_LOGE("ReportSingleCallInfo return, callManagerCallBack_ is nullptr, report fail!");
72 return;
73 }
74 callManagerCallBack_->UpdateCallReportInfo(cellularCallReportInfo);
75 }
76
UnRegisterCallManagerCallBack()77 int32_t CellularCallRegister::UnRegisterCallManagerCallBack()
78 {
79 callManagerCallBack_ = nullptr;
80 return TELEPHONY_SUCCESS;
81 }
82
ReportEventResultInfo(const CellularCallEventInfo & info)83 void CellularCallRegister::ReportEventResultInfo(const CellularCallEventInfo &info)
84 {
85 TELEPHONY_LOGI("ReportEventResultInfo entry eventId:%{public}d", info.eventId);
86 if (callManagerCallBack_ == nullptr) {
87 TELEPHONY_LOGE("ReportEventResultInfo return, callManagerCallBack_ is nullptr, report fail!");
88 return;
89 }
90 callManagerCallBack_->UpdateEventResultInfo(info);
91 }
92
ReportGetWaitingResult(const CallWaitResponse & response)93 void CellularCallRegister::ReportGetWaitingResult(const CallWaitResponse &response)
94 {
95 TELEPHONY_LOGI("ReportGetWaitingResult entry");
96 TELEPHONY_LOGI("ReportGetWaitingResult result:%{public}d, status:%{public}d, class:%{public}d", response.result,
97 response.status, response.classCw);
98 if (callManagerCallBack_ == nullptr) {
99 TELEPHONY_LOGE("ReportGetWaitingResult return, callManagerCallBack_ is nullptr, report fail!");
100 return;
101 }
102 callManagerCallBack_->UpdateGetWaitingResult(response);
103 }
104
ReportSetWaitingResult(int32_t result)105 void CellularCallRegister::ReportSetWaitingResult(int32_t result)
106 {
107 TELEPHONY_LOGI("ReportSetWaitingResult entry");
108 TELEPHONY_LOGI("ReportSetWaitingResult result:%{public}d", result);
109 if (callManagerCallBack_ == nullptr) {
110 TELEPHONY_LOGE("ReportSetWaitingResult return, callManagerCallBack_ is nullptr, report fail!");
111 return;
112 }
113 callManagerCallBack_->UpdateSetWaitingResult(result);
114 }
115
ReportGetRestrictionResult(const CallRestrictionResponse & response)116 void CellularCallRegister::ReportGetRestrictionResult(const CallRestrictionResponse &response)
117 {
118 TELEPHONY_LOGI("ReportGetRestrictionResult entry");
119 TELEPHONY_LOGI("ReportGetRestrictionResult result:%{public}d, status:%{public}d, class:%{public}d",
120 response.result, response.status, response.classCw);
121 if (callManagerCallBack_ == nullptr) {
122 TELEPHONY_LOGE("ReportGetRestrictionResult return, callManagerCallBack_ is nullptr, report fail!");
123 return;
124 }
125 callManagerCallBack_->UpdateGetRestrictionResult(response);
126 }
127
ReportSetRestrictionResult(int32_t result)128 void CellularCallRegister::ReportSetRestrictionResult(int32_t result)
129 {
130 TELEPHONY_LOGI("ReportSetRestrictionResult entry");
131 TELEPHONY_LOGI("ReportSetRestrictionResult result:%{public}d", result);
132 if (callManagerCallBack_ == nullptr) {
133 TELEPHONY_LOGE("ReportSetRestrictionResult return, callManagerCallBack_ is nullptr, report fail!");
134 return;
135 }
136 callManagerCallBack_->UpdateSetRestrictionResult(result);
137 }
138
ReportGetTransferResult(const CallTransferResponse & response)139 void CellularCallRegister::ReportGetTransferResult(const CallTransferResponse &response)
140 {
141 TELEPHONY_LOGI("ReportGetTransferResult entry");
142 TELEPHONY_LOGI("ReportGetTransferResult result:%{public}d, status:%{public}d, class:%{public}d", response.result,
143 response.status, response.classx);
144 TELEPHONY_LOGI("ReportGetTransferResult type:%{public}d, reason:%{public}d, time:%{public}d",
145 response.type, response.reason, response.time);
146 if (callManagerCallBack_ == nullptr) {
147 TELEPHONY_LOGE("ReportGetTransferResult return, callManagerCallBack_ is nullptr, report fail!");
148 return;
149 }
150 callManagerCallBack_->UpdateGetTransferResult(response);
151 }
152
ReportSetTransferResult(int32_t result)153 void CellularCallRegister::ReportSetTransferResult(int32_t result)
154 {
155 TELEPHONY_LOGI("ReportSetTransferResult entry");
156 TELEPHONY_LOGI("ReportSetTransferResult result:%{public}d", result);
157 if (callManagerCallBack_ == nullptr) {
158 TELEPHONY_LOGE("ReportSetTransferResult return, callManagerCallBack_ is nullptr, report fail!");
159 return;
160 }
161 callManagerCallBack_->UpdateSetTransferResult(result);
162 }
163
ReportGetClipResult(const ClipResponse & response)164 void CellularCallRegister::ReportGetClipResult(const ClipResponse &response)
165 {
166 TELEPHONY_LOGI("ReportGetClipResult entry");
167 TELEPHONY_LOGI("ReportGetClipResult result:%{public}d, action:%{public}d, stat:%{public}d", response.result,
168 response.action, response.clipStat);
169 if (callManagerCallBack_ == nullptr) {
170 TELEPHONY_LOGE("ReportGetClipResult return, callManagerCallBack_ is nullptr, report fail!");
171 return;
172 }
173 callManagerCallBack_->UpdateGetCallClipResult(response);
174 }
175
ReportGetClirResult(const ClirResponse & response)176 void CellularCallRegister::ReportGetClirResult(const ClirResponse &response)
177 {
178 TELEPHONY_LOGI("ReportGetClirResult entry");
179 TELEPHONY_LOGI("ReportGetClirResult result:%{public}d, action:%{public}d, stat:%{public}d", response.result,
180 response.action, response.clirStat);
181 if (callManagerCallBack_ == nullptr) {
182 TELEPHONY_LOGE("ReportGetClirResult return, callManagerCallBack_ is nullptr, report fail!");
183 return;
184 }
185 callManagerCallBack_->UpdateGetCallClirResult(response);
186 }
187
ReportSetClirResult(int32_t result)188 void CellularCallRegister::ReportSetClirResult(int32_t result)
189 {
190 TELEPHONY_LOGI("ReportSetClirResult entry");
191 TELEPHONY_LOGI("ReportSetClirResult result:%{public}d", result);
192 if (callManagerCallBack_ == nullptr) {
193 TELEPHONY_LOGE("ReportSetClirResult return, callManagerCallBack_ is nullptr, report fail!");
194 return;
195 }
196 callManagerCallBack_->UpdateSetCallClirResult(result);
197 }
198
ReportGetImsConfigResult(const GetImsConfigResponse & response)199 void CellularCallRegister::ReportGetImsConfigResult(const GetImsConfigResponse &response)
200 {
201 TELEPHONY_LOGI("ReportGetImsConfigResult entry, value:%{public}d", response.value);
202 if (callManagerCallBack_ == nullptr) {
203 TELEPHONY_LOGE("ReportGetImsConfigResult return, callManagerCallBack_ is nullptr, report fail!");
204 return;
205 }
206 callManagerCallBack_->GetImsConfigResult(response);
207 }
208
ReportSetImsConfigResult(int32_t result)209 void CellularCallRegister::ReportSetImsConfigResult(int32_t result)
210 {
211 if (callManagerCallBack_ == nullptr) {
212 TELEPHONY_LOGE("ReportSetImsConfigResult return, callManagerCallBack_ is nullptr, report fail!");
213 return;
214 }
215 callManagerCallBack_->SetImsConfigResult(result);
216 }
217
ReportSetImsFeatureResult(int32_t result)218 void CellularCallRegister::ReportSetImsFeatureResult(int32_t result)
219 {
220 if (callManagerCallBack_ == nullptr) {
221 TELEPHONY_LOGE("ReportSetImsFeatureResult return, callManagerCallBack_ is nullptr, report fail!");
222 return;
223 }
224 callManagerCallBack_->SetImsFeatureValueResult(result);
225 }
226
ReportGetImsFeatureResult(const GetImsFeatureValueResponse & response)227 void CellularCallRegister::ReportGetImsFeatureResult(const GetImsFeatureValueResponse &response)
228 {
229 TELEPHONY_LOGI("ReportGetImsFeatureResult entry, value:%{public}d", response.value);
230 if (callManagerCallBack_ == nullptr) {
231 TELEPHONY_LOGE("ReportGetImsFeatureResult return, callManagerCallBack_ is nullptr, report fail!");
232 return;
233 }
234 callManagerCallBack_->GetImsFeatureValueResult(response);
235 }
236
ReportCallRingBackResult(int32_t status)237 void CellularCallRegister::ReportCallRingBackResult(int32_t status)
238 {
239 TELEPHONY_LOGI("ReportCallRingBackResult entry");
240 if (callManagerCallBack_ == nullptr) {
241 TELEPHONY_LOGE("ReportCallRingBackResult return, callManagerCallBack_ is nullptr, report fail!");
242 return;
243 }
244 callManagerCallBack_->UpdateRBTPlayInfo(static_cast<RBTPlayInfo>(status));
245 }
246
ReportCallFailReason(const DisconnectedDetails & details)247 void CellularCallRegister::ReportCallFailReason(const DisconnectedDetails &details)
248 {
249 if (callManagerCallBack_ == nullptr) {
250 TELEPHONY_LOGE("ReportCallFailReason return, callManagerCallBack_ is nullptr, report fail!");
251 return;
252 }
253 callManagerCallBack_->UpdateDisconnectedCause(details);
254 }
255
ReportGetMuteResult(const MuteControlResponse & response)256 void CellularCallRegister::ReportGetMuteResult(const MuteControlResponse &response)
257 {
258 TELEPHONY_LOGI("ReportGetMuteResult entry result:%{public}d, value:%{public}d", response.result, response.value);
259 if (callManagerCallBack_ == nullptr) {
260 TELEPHONY_LOGE("ReportMuteResult return, callManagerCallBack_ is nullptr, report fail!");
261 return;
262 }
263 }
264
ReportSetMuteResult(const MuteControlResponse & response)265 void CellularCallRegister::ReportSetMuteResult(const MuteControlResponse &response)
266 {
267 TELEPHONY_LOGI("ReportSetMuteResult entry result:%{public}d, value:%{public}d", response.result, response.value);
268 }
269
ReportInviteToConferenceResult(int32_t result)270 void CellularCallRegister::ReportInviteToConferenceResult(int32_t result)
271 {
272 TELEPHONY_LOGI("ReportInviteToConferenceResult entry result:%{public}d", result);
273 if (callManagerCallBack_ == nullptr) {
274 TELEPHONY_LOGE("ReportInviteToConferenceResult return, callManagerCallBack_ is nullptr, report fail!");
275 return;
276 }
277 callManagerCallBack_->InviteToConferenceResult(result);
278 }
279
ReportUpdateCallMediaModeResult(int32_t result)280 void CellularCallRegister::ReportUpdateCallMediaModeResult(int32_t result)
281 {
282 if (callManagerCallBack_ == nullptr) {
283 TELEPHONY_LOGE("ReportUpdateCallMediaModeResult return, callManagerCallBack_ is nullptr, report fail!");
284 return;
285 }
286 CallMediaModeResponse response;
287 response.result = result;
288 callManagerCallBack_->ReceiveUpdateCallMediaModeResponse(response);
289 }
290
ReportGetCallDataResult(int32_t result)291 void CellularCallRegister::ReportGetCallDataResult(int32_t result)
292 {
293 if (callManagerCallBack_ == nullptr) {
294 TELEPHONY_LOGE("ReportGetCallDataResult return, callManagerCallBack_ is nullptr, report fail!");
295 return;
296 }
297 callManagerCallBack_->GetImsCallDataResult(result);
298 }
299
ReportStartDtmfResult(int32_t result)300 void CellularCallRegister::ReportStartDtmfResult(int32_t result)
301 {
302 if (callManagerCallBack_ == nullptr) {
303 TELEPHONY_LOGE("ReportStartDtmfResult return, callManagerCallBack_ is nullptr, report fail!");
304 return;
305 }
306 callManagerCallBack_->StartDtmfResult(result);
307 }
308
ReportStopDtmfResult(int32_t result)309 void CellularCallRegister::ReportStopDtmfResult(int32_t result)
310 {
311 if (callManagerCallBack_ == nullptr) {
312 TELEPHONY_LOGE("ReportStopDtmfResult return, callManagerCallBack_ is nullptr, report fail!");
313 return;
314 }
315 callManagerCallBack_->StopDtmfResult(result);
316 }
317
ReportStartRttResult(int32_t result)318 void CellularCallRegister::ReportStartRttResult(int32_t result)
319 {
320 if (callManagerCallBack_ == nullptr) {
321 TELEPHONY_LOGE("ReportStartRttResult return, callManagerCallBack_ is nullptr, report fail!");
322 return;
323 }
324 callManagerCallBack_->StartRttResult(result);
325 }
326
ReportStopRttResult(int32_t result)327 void CellularCallRegister::ReportStopRttResult(int32_t result)
328 {
329 if (callManagerCallBack_ == nullptr) {
330 TELEPHONY_LOGE("ReportStopRttResult return, callManagerCallBack_ is nullptr, report fail!");
331 return;
332 }
333 callManagerCallBack_->StopRttResult(result);
334 }
335
ReportSendUssdResult(int32_t result)336 void CellularCallRegister::ReportSendUssdResult(int32_t result)
337 {
338 if (callManagerCallBack_ == nullptr) {
339 TELEPHONY_LOGE("ReportSendUssdResult return, callManagerCallBack_ is nullptr, report fail!");
340 return;
341 }
342 callManagerCallBack_->SendUssdResult(result);
343 }
344
ReportMmiCodeResult(const MmiCodeInfo & info)345 void CellularCallRegister::ReportMmiCodeResult(const MmiCodeInfo &info)
346 {
347 TELEPHONY_LOGI("ReportMmiCodeResult entry result:%{public}d, value:%{public}s", info.result, info.message);
348 if (callManagerCallBack_ == nullptr) {
349 TELEPHONY_LOGE("ReportMmiCodeResult return, callManagerCallBack_ is nullptr, report fail!");
350 return;
351 }
352 callManagerCallBack_->SendMmiCodeResult(info);
353 }
354
ReportSetEmergencyCallListResponse(const SetEccListResponse & response)355 void CellularCallRegister::ReportSetEmergencyCallListResponse(const SetEccListResponse &response)
356 {
357 TELEPHONY_LOGI("ReportSetEmergencyCallListResponse entry result:%{public}d, value:%{public}d",
358 response.result, response.value);
359 }
360
IsCallManagerCallBackRegistered()361 bool CellularCallRegister::IsCallManagerCallBackRegistered()
362 {
363 return callManagerCallBack_ != nullptr;
364 }
365 } // namespace Telephony
366 } // namespace OHOS
367