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