• 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_ability_report_proxy.h"
17 
18 #include <string_ex.h>
19 
20 #include "app_mgr_interface.h"
21 #include "app_state_observer.h"
22 #include "bluetooth_call_manager.h"
23 #include "call_ability_callback_death_recipient.h"
24 #include "call_manager_errors.h"
25 #include "iservice_registry.h"
26 #include "system_ability.h"
27 #include "system_ability_definition.h"
28 #include "telephony_log_wrapper.h"
29 
30 namespace OHOS {
31 namespace Telephony {
CallAbilityReportProxy()32 CallAbilityReportProxy::CallAbilityReportProxy()
33 {
34     callbackPtrList_.clear();
35 }
36 
~CallAbilityReportProxy()37 CallAbilityReportProxy::~CallAbilityReportProxy()
38 {
39     std::lock_guard<std::mutex> lock(mutex_);
40     std::list<sptr<ICallAbilityCallback>>::iterator it = callbackPtrList_.begin();
41     while (it != callbackPtrList_.end()) {
42         if ((*it)) {
43             (*it).clear();
44             (*it) = nullptr;
45         }
46         callbackPtrList_.erase(it++);
47     }
48 }
49 
RegisterCallBack(sptr<ICallAbilityCallback> callAbilityCallbackPtr,const std::string & bundleInfo)50 int32_t CallAbilityReportProxy::RegisterCallBack(
51     sptr<ICallAbilityCallback> callAbilityCallbackPtr, const std::string &bundleInfo)
52 {
53     if (callAbilityCallbackPtr == nullptr) {
54         TELEPHONY_LOGE("callAbilityCallbackPtr is null");
55         return TELEPHONY_ERR_LOCAL_PTR_NULL;
56     }
57     callAbilityCallbackPtr->SetBundleInfo(bundleInfo);
58     std::lock_guard<std::mutex> lock(mutex_);
59     callbackPtrList_.emplace_back(callAbilityCallbackPtr);
60     TELEPHONY_LOGI("%{public}s successfully registered the callback!", bundleInfo.c_str());
61     if (callAbilityCallbackPtr->AsObject() != nullptr) {
62         sptr<CallAbilityCallbackDeathRecipient> deathRecipient =
63             new (std::nothrow) CallAbilityCallbackDeathRecipient();
64         if (deathRecipient == nullptr) {
65             TELEPHONY_LOGW("deathRecipient is nullptr");
66             return false;
67         }
68         callAbilityCallbackPtr->AsObject()->AddDeathRecipient(deathRecipient);
69     }
70     return TELEPHONY_SUCCESS;
71 }
72 
UnRegisterCallBack(const std::string & bundleInfo)73 int32_t CallAbilityReportProxy::UnRegisterCallBack(const std::string &bundleInfo)
74 {
75     std::lock_guard<std::mutex> lock(mutex_);
76     if (callbackPtrList_.empty()) {
77         TELEPHONY_LOGE("callbackPtrList_ is null! %{public}s UnRegisterCallBack failed", bundleInfo.c_str());
78         return TELEPHONY_ERR_LOCAL_PTR_NULL;
79     }
80     std::list<sptr<ICallAbilityCallback>>::iterator it = callbackPtrList_.begin();
81     for (; it != callbackPtrList_.end(); ++it) {
82         if ((*it)->GetBundleInfo() == bundleInfo) {
83             callbackPtrList_.erase(it);
84             TELEPHONY_LOGI("%{public}s UnRegisterCallBack success", bundleInfo.c_str());
85             break;
86         }
87     }
88     return TELEPHONY_SUCCESS;
89 }
90 
UnRegisterCallBack(sptr<IRemoteObject> object)91 int32_t CallAbilityReportProxy::UnRegisterCallBack(sptr<IRemoteObject> object)
92 {
93     std::lock_guard<std::mutex> lock(mutex_);
94     if (callbackPtrList_.empty()) {
95         TELEPHONY_LOGE("callbackPtrList_ is null!");
96         return TELEPHONY_ERR_LOCAL_PTR_NULL;
97     }
98     std::list<sptr<ICallAbilityCallback>>::iterator it = callbackPtrList_.begin();
99     for (; it != callbackPtrList_.end(); ++it) {
100         if ((*it)->AsObject() == object) {
101             TELEPHONY_LOGI("%{public}s UnRegisterCallBack success", (*it)->GetBundleInfo().c_str());
102             callbackPtrList_.erase(it);
103             break;
104         }
105     }
106     return TELEPHONY_SUCCESS;
107 }
108 
CallStateUpdated(sptr<CallBase> & callObjectPtr,TelCallState priorState,TelCallState nextState)109 void CallAbilityReportProxy::CallStateUpdated(
110     sptr<CallBase> &callObjectPtr, TelCallState priorState, TelCallState nextState)
111 {
112     if (callObjectPtr == nullptr) {
113         TELEPHONY_LOGE("callObjectPtr is nullptr!");
114         return;
115     }
116     CallAttributeInfo info;
117     callObjectPtr->GetCallAttributeInfo(info);
118     size_t accountLen = strlen(info.accountNumber);
119     if (accountLen > static_cast<size_t>(kMaxNumberLen)) {
120         accountLen = kMaxNumberLen;
121     }
122     for (size_t i = 0; i < accountLen; i++) {
123         if (info.accountNumber[i] == ',' || info.accountNumber[i] == ';') {
124             info.accountNumber[i] = '\0';
125             break;
126         }
127     }
128     if (nextState == TelCallState::CALL_STATUS_ANSWERED) {
129         TELEPHONY_LOGI("report answered state");
130         info.callState = TelCallState::CALL_STATUS_ANSWERED;
131     }
132     ReportCallStateInfo(info);
133 }
134 
MeeTimeStateUpdated(CallAttributeInfo info,TelCallState priorState,TelCallState nextState)135 void CallAbilityReportProxy::MeeTimeStateUpdated(
136     CallAttributeInfo info, TelCallState priorState, TelCallState nextState)
137 {
138     info.callState = nextState;
139     TELEPHONY_LOGI("MeeTimeStateUpdated");
140     ReportMeeTimeStateInfo(info);
141 }
142 
143 
CallEventUpdated(CallEventInfo & info)144 void CallAbilityReportProxy::CallEventUpdated(CallEventInfo &info)
145 {
146     ReportCallEvent(info);
147 }
148 
CallDestroyed(const DisconnectedDetails & details)149 void CallAbilityReportProxy::CallDestroyed(const DisconnectedDetails &details)
150 {
151     int32_t ret = TELEPHONY_ERR_FAIL;
152     std::lock_guard<std::mutex> lock(mutex_);
153     std::list<sptr<ICallAbilityCallback>>::iterator it = callbackPtrList_.begin();
154     for (; it != callbackPtrList_.end(); ++it) {
155         if ((*it)) {
156             ret = (*it)->OnCallDisconnectedCause(details);
157             if (ret != TELEPHONY_SUCCESS) {
158                 TELEPHONY_LOGW("OnCallDisconnectedCause failed, errcode:%{public}d, bundleInfo:%{public}s", ret,
159                     ((*it)->GetBundleInfo()).c_str());
160                 continue;
161             }
162         }
163     }
164     TELEPHONY_LOGI("report call disconnected cause[%{public}d] success", details.reason);
165 }
166 
ReportCallStateInfo(const CallAttributeInfo & info)167 int32_t CallAbilityReportProxy::ReportCallStateInfo(const CallAttributeInfo &info)
168 {
169     int32_t ret = TELEPHONY_ERR_FAIL;
170     std::string bundleInfo = "";
171     std::lock_guard<std::mutex> lock(mutex_);
172     std::list<sptr<ICallAbilityCallback>>::iterator it = callbackPtrList_.begin();
173     for (; it != callbackPtrList_.end(); ++it) {
174         if ((*it)) {
175             bundleInfo = (*it)->GetBundleInfo();
176             ret = (*it)->OnCallDetailsChange(info);
177             if (ret != TELEPHONY_SUCCESS) {
178                 TELEPHONY_LOGD(
179                     "OnCallDetailsChange failed, errcode:%{public}d, bundleInfo:%{public}s", ret, bundleInfo.c_str());
180                 continue;
181             }
182         }
183     }
184     DelayedSingleton<BluetoothCallManager>::GetInstance()->SendCallDetailsChange(static_cast<int32_t>(info.callId),
185         static_cast<int32_t>(info.callState));
186     TELEPHONY_LOGI("report call state info success, callId[%{public}d] state[%{public}d] conferenceState[%{public}d] "
187                    "videoState[%{public}d]",
188         info.callId, info.callState, info.conferenceState, info.videoState);
189     return ret;
190 }
191 
ReportMeeTimeStateInfo(const CallAttributeInfo & info)192 int32_t CallAbilityReportProxy::ReportMeeTimeStateInfo(const CallAttributeInfo &info)
193 {
194     int32_t ret = TELEPHONY_ERR_FAIL;
195     std::string bundleInfo = "";
196     std::lock_guard<std::mutex> lock(mutex_);
197     std::list<sptr<ICallAbilityCallback>>::iterator it = callbackPtrList_.begin();
198     for (; it != callbackPtrList_.end(); ++it) {
199         if ((*it)) {
200             bundleInfo = (*it)->GetBundleInfo();
201             ret = (*it)->OnMeeTimeDetailsChange(info);
202             if (ret != TELEPHONY_SUCCESS) {
203                 TELEPHONY_LOGD("OnMeeTimeDetailsChange failed, errcode:%{public}d, bundleInfo:%{public}s",
204                     ret, bundleInfo.c_str());
205                 continue;
206             }
207         }
208     }
209     DelayedSingleton<BluetoothCallManager>::GetInstance()->SendCallDetailsChange(static_cast<int32_t>(info.callId),
210         static_cast<int32_t>(info.callState));
211     TELEPHONY_LOGI("report meeTime state info success, callId[%{public}d] state[%{public}d] "
212         "conferenceState[%{public}d] videoState[%{public}d]",
213         info.callId, info.callState, info.conferenceState, info.videoState);
214     return ret;
215 }
216 
ReportCallStateInfo(const CallAttributeInfo & info,std::string bundleInfo)217 int32_t CallAbilityReportProxy::ReportCallStateInfo(const CallAttributeInfo &info, std::string bundleInfo)
218 {
219     int32_t ret = TELEPHONY_ERROR;
220     std::lock_guard<std::mutex> lock(mutex_);
221     for (auto callback : callbackPtrList_) {
222         if (callback->GetBundleInfo() == bundleInfo) {
223             ret = callback->OnCallDetailsChange(info);
224             break;
225         }
226     }
227     if (ret != TELEPHONY_SUCCESS) {
228         TELEPHONY_LOGE(
229             "OnCallDetailsChange failed, errcode:%{public}d, bundleInfo:%{public}s", ret, bundleInfo.c_str());
230     } else {
231         TELEPHONY_LOGI("callId[%{public}d] state[%{public}d] conferenceState[%{public}d] "
232                        "videoState[%{public}d], report bundleInfo %{public}s success",
233             info.callId, info.callState, info.conferenceState, info.videoState, bundleInfo.c_str());
234     }
235     return ret;
236 }
237 
ReportCallEvent(const CallEventInfo & info)238 int32_t CallAbilityReportProxy::ReportCallEvent(const CallEventInfo &info)
239 {
240     int32_t ret = TELEPHONY_ERR_FAIL;
241     TELEPHONY_LOGI("report call event, eventId:%{public}d", info.eventId);
242     std::lock_guard<std::mutex> lock(mutex_);
243     std::list<sptr<ICallAbilityCallback>>::iterator it = callbackPtrList_.begin();
244     for (; it != callbackPtrList_.end(); ++it) {
245         if ((*it)) {
246             ret = (*it)->OnCallEventChange(info);
247             if (ret != TELEPHONY_SUCCESS) {
248                 TELEPHONY_LOGW("OnCallEventChange failed, errcode:%{public}d, bundleInfo:%{public}s", ret,
249                     ((*it)->GetBundleInfo()).c_str());
250                 continue;
251             }
252         }
253     }
254     TELEPHONY_LOGI("report call event[%{public}d] info success", info.eventId);
255     return ret;
256 }
257 
ReportAsyncResults(const CallResultReportId reportId,AppExecFwk::PacMap & resultInfo)258 int32_t CallAbilityReportProxy::ReportAsyncResults(
259     const CallResultReportId reportId, AppExecFwk::PacMap &resultInfo)
260 {
261     int32_t ret = TELEPHONY_ERR_FAIL;
262     std::lock_guard<std::mutex> lock(mutex_);
263     std::list<sptr<ICallAbilityCallback>>::iterator it = callbackPtrList_.begin();
264     for (; it != callbackPtrList_.end(); ++it) {
265         if ((*it)) {
266             ret = (*it)->OnReportAsyncResults(reportId, resultInfo);
267             if (ret != TELEPHONY_SUCCESS) {
268                 TELEPHONY_LOGW("ReportAsyncResults failed, errcode:%{public}d, bundleInfo:%{public}s", ret,
269                     ((*it)->GetBundleInfo()).c_str());
270                 continue;
271             }
272         }
273     }
274     TELEPHONY_LOGI("ReportAsyncResults success, reportId:%{public}d", reportId);
275     return ret;
276 }
277 
ReportMmiCodeResult(const MmiCodeInfo & info)278 int32_t CallAbilityReportProxy::ReportMmiCodeResult(const MmiCodeInfo &info)
279 {
280     int32_t ret = TELEPHONY_ERR_FAIL;
281     std::lock_guard<std::mutex> lock(mutex_);
282     std::list<sptr<ICallAbilityCallback>>::iterator it = callbackPtrList_.begin();
283     for (; it != callbackPtrList_.end(); ++it) {
284         if ((*it)) {
285             ret = (*it)->OnReportMmiCodeResult(info);
286             if (ret != TELEPHONY_SUCCESS) {
287                 TELEPHONY_LOGW("ReportMmiCodeResult failed, errcode:%{public}d, bundleInfo:%{public}s", ret,
288                     ((*it)->GetBundleInfo()).c_str());
289                 continue;
290             }
291         }
292     }
293     TELEPHONY_LOGI("ReportMmiCodeResult success");
294     return ret;
295 }
296 
OttCallRequest(OttCallRequestId requestId,AppExecFwk::PacMap & info)297 int32_t CallAbilityReportProxy::OttCallRequest(OttCallRequestId requestId, AppExecFwk::PacMap &info)
298 {
299     int32_t ret = TELEPHONY_ERR_FAIL;
300     std::lock_guard<std::mutex> lock(mutex_);
301     std::list<sptr<ICallAbilityCallback>>::iterator it = callbackPtrList_.begin();
302     for (; it != callbackPtrList_.end(); ++it) {
303         std::string bundleInfo = (*it)->GetBundleInfo();
304         if (bundleInfo == "com.ohos.callservice") {
305             ret = (*it)->OnOttCallRequest(requestId, info);
306             if (ret != TELEPHONY_SUCCESS) {
307                 TELEPHONY_LOGW(
308                     "OttCallRequest failed, errcode:%{public}d, bundleInfo:%{public}s", ret, bundleInfo.c_str());
309                 break;
310             }
311         }
312     }
313     TELEPHONY_LOGI("OttCallRequest success, requestId:%{public}d", requestId);
314     return ret;
315 }
316 
ReportAudioDeviceChange(const AudioDeviceInfo & info)317 int32_t CallAbilityReportProxy::ReportAudioDeviceChange(const AudioDeviceInfo &info)
318 {
319     int32_t ret = TELEPHONY_ERR_FAIL;
320     std::lock_guard<std::mutex> lock(mutex_);
321     std::list<sptr<ICallAbilityCallback>>::iterator it = callbackPtrList_.begin();
322     for (; it != callbackPtrList_.end(); ++it) {
323         if ((*it)) {
324             ret = (*it)->OnReportAudioDeviceChange(info);
325             if (ret != TELEPHONY_SUCCESS) {
326                 TELEPHONY_LOGD("ReportAudioDeviceChange failed, errcode:%{public}d, bundleInfo:%{public}s", ret,
327                     ((*it)->GetBundleInfo()).c_str());
328                 continue;
329             }
330         }
331     }
332     TELEPHONY_LOGI("ReportAudioDeviceChange success");
333     return ret;
334 }
335 
ReportPostDialDelay(const std::string & str)336 int32_t CallAbilityReportProxy::ReportPostDialDelay(const std::string &str)
337 {
338     int32_t ret = TELEPHONY_ERR_FAIL;
339     std::lock_guard<std::mutex> lock(mutex_);
340     std::list<sptr<ICallAbilityCallback>>::iterator it = callbackPtrList_.begin();
341     for (; it != callbackPtrList_.end(); ++it) {
342         if ((*it)) {
343             ret = (*it)->OnReportPostDialDelay(str);
344             if (ret != TELEPHONY_SUCCESS) {
345                 TELEPHONY_LOGW("ReportPostDialDelay failed, errcode:%{public}d, bundleInfo:%{public}s", ret,
346                     ((*it)->GetBundleInfo()).c_str());
347                 continue;
348             }
349         }
350     }
351     TELEPHONY_LOGI("ReportPostDialDelay success");
352     return ret;
353 }
354 
ReportImsCallModeChange(const CallMediaModeInfo & imsCallModeInfo)355 int32_t CallAbilityReportProxy::ReportImsCallModeChange(const CallMediaModeInfo &imsCallModeInfo)
356 {
357     int32_t ret = TELEPHONY_ERR_FAIL;
358     std::lock_guard<std::mutex> lock(mutex_);
359     std::list<sptr<ICallAbilityCallback>>::iterator it = callbackPtrList_.begin();
360     for (; it != callbackPtrList_.end(); ++it) {
361         if ((*it)) {
362             ret = (*it)->OnReportImsCallModeChange(imsCallModeInfo);
363             if (ret != TELEPHONY_SUCCESS) {
364                 TELEPHONY_LOGW("ReportImsCallModeReceive failed, errcode:%{public}d, bundleInfo:%{public}s", ret,
365                     ((*it)->GetBundleInfo()).c_str());
366                 continue;
367             }
368         }
369     }
370     TELEPHONY_LOGI("ReportImsCallModeReceive success");
371     return ret;
372 }
373 
ReportCallSessionEventChange(const CallSessionEvent & callSessionEventOptions)374 int32_t CallAbilityReportProxy::ReportCallSessionEventChange(
375     const CallSessionEvent &callSessionEventOptions)
376 {
377     int32_t ret = TELEPHONY_ERR_FAIL;
378     std::lock_guard<std::mutex> lock(mutex_);
379     std::list<sptr<ICallAbilityCallback>>::iterator it = callbackPtrList_.begin();
380     for (; it != callbackPtrList_.end(); ++it) {
381         if ((*it)) {
382             ret = (*it)->OnReportCallSessionEventChange(callSessionEventOptions);
383             if (ret != TELEPHONY_SUCCESS) {
384                 TELEPHONY_LOGW("ReportCallSessionEventChange failed, errcode:%{public}d, bundleInfo:%{public}s", ret,
385                     ((*it)->GetBundleInfo()).c_str());
386                 continue;
387             }
388         }
389     }
390     TELEPHONY_LOGI("ReportCallSessionEventChange success");
391     return ret;
392 }
393 
ReportPeerDimensionsChange(const PeerDimensionsDetail & peerDimensionsDetail)394 int32_t CallAbilityReportProxy::ReportPeerDimensionsChange(const PeerDimensionsDetail &peerDimensionsDetail)
395 {
396     int32_t ret = TELEPHONY_ERR_FAIL;
397     std::lock_guard<std::mutex> lock(mutex_);
398     std::list<sptr<ICallAbilityCallback>>::iterator it = callbackPtrList_.begin();
399     for (; it != callbackPtrList_.end(); ++it) {
400         if ((*it)) {
401             ret = (*it)->OnReportPeerDimensionsChange(peerDimensionsDetail);
402             if (ret != TELEPHONY_SUCCESS) {
403                 TELEPHONY_LOGW("ReportPeerDimensionsChange failed, errcode:%{public}d, bundleInfo:%{public}s", ret,
404                     ((*it)->GetBundleInfo()).c_str());
405                 continue;
406             }
407         }
408     }
409     TELEPHONY_LOGI("ReportPeerDimensionsChange success");
410     return ret;
411 }
412 
ReportCallDataUsageChange(const int64_t dataUsage)413 int32_t CallAbilityReportProxy::ReportCallDataUsageChange(const int64_t dataUsage)
414 {
415     int32_t ret = TELEPHONY_ERR_FAIL;
416     std::lock_guard<std::mutex> lock(mutex_);
417     std::list<sptr<ICallAbilityCallback>>::iterator it = callbackPtrList_.begin();
418     for (; it != callbackPtrList_.end(); ++it) {
419         if ((*it)) {
420             ret = (*it)->OnReportCallDataUsageChange(dataUsage);
421             if (ret != TELEPHONY_SUCCESS) {
422                 TELEPHONY_LOGW("ReportCallDataUsageChange failed, errcode:%{public}d, bundleInfo:%{public}s", ret,
423                     ((*it)->GetBundleInfo()).c_str());
424                 continue;
425             }
426         }
427     }
428     TELEPHONY_LOGI("ReportCallDataUsageChange success");
429     return ret;
430 }
431 
ReportCameraCapabilities(const CameraCapabilities & cameraCapabilities)432 int32_t CallAbilityReportProxy::ReportCameraCapabilities(const CameraCapabilities &cameraCapabilities)
433 {
434     int32_t ret = TELEPHONY_ERR_FAIL;
435     std::lock_guard<std::mutex> lock(mutex_);
436     std::list<sptr<ICallAbilityCallback>>::iterator it = callbackPtrList_.begin();
437     for (; it != callbackPtrList_.end(); ++it) {
438         if ((*it)) {
439             ret = (*it)->OnReportCameraCapabilities(cameraCapabilities);
440             if (ret != TELEPHONY_SUCCESS) {
441                 TELEPHONY_LOGW("ReportCameraCapabilities failed, errcode:%{public}d, bundleInfo:%{public}s", ret,
442                     ((*it)->GetBundleInfo()).c_str());
443                 continue;
444             }
445         }
446     }
447     TELEPHONY_LOGI("ReportCameraCapabilities success");
448     return ret;
449 }
450 
ReportPhoneStateChange(int32_t numActive,int32_t numHeld,int32_t callState,const std::string & number)451 int32_t CallAbilityReportProxy::ReportPhoneStateChange(int32_t numActive, int32_t numHeld, int32_t callState,
452     const std::string &number)
453 {
454     int32_t ret = TELEPHONY_ERR_FAIL;
455     std::lock_guard<std::mutex> lock(mutex_);
456     std::list<sptr<ICallAbilityCallback>>::iterator it = callbackPtrList_.begin();
457     for (; it != callbackPtrList_.end(); ++it) {
458         if ((*it) != nullptr) {
459             ret = (*it)->OnPhoneStateChange(numActive, numHeld, callState, number);
460             if (ret != TELEPHONY_SUCCESS) {
461                 TELEPHONY_LOGW("ReportPhoneStateChange failed, errcode:%{public}d, bundleInfo:%{public}s", ret,
462                     ((*it)->GetBundleInfo()).c_str());
463             }
464         }
465     }
466     TELEPHONY_LOGI("ReportPhoneStateChange success");
467     return ret;
468 }
469 } // namespace Telephony
470 } // namespace OHOS
471