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