1 /*
2 * Copyright (C) 2023 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_manager_connect.h"
17
18 namespace OHOS {
19 namespace Telephony {
OnUpdateCallStateInfoRequest(MessageParcel & data,MessageParcel & reply)20 int32_t CallAbilityCallbackStub::OnUpdateCallStateInfoRequest(MessageParcel &data, MessageParcel &reply)
21 {
22 CallAttributeInfo parcelPtr;
23 if (!data.ContainFileDescriptors()) {
24 TELEPHONY_LOGW("sent raw data is less than 32k");
25 }
26 strncpy_s(parcelPtr.accountNumber, kMaxNumberLen + 1, data.ReadCString(), kMaxNumberLen + 1);
27 strncpy_s(parcelPtr.bundleName, kMaxNumberLen + 1, data.ReadCString(), kMaxNumberLen + 1);
28 parcelPtr.speakerphoneOn = data.ReadBool();
29 parcelPtr.accountId = data.ReadInt32();
30 parcelPtr.videoState = static_cast<VideoStateType>(data.ReadInt32());
31 parcelPtr.startTime = data.ReadInt64();
32 parcelPtr.isEcc = data.ReadBool();
33 parcelPtr.callType = static_cast<CallType>(data.ReadInt32());
34 parcelPtr.callId = data.ReadInt32();
35 parcelPtr.callState = static_cast<TelCallState>(data.ReadInt32());
36 parcelPtr.conferenceState = static_cast<TelConferenceState>(data.ReadInt32());
37 parcelPtr.callBeginTime = data.ReadInt64();
38 parcelPtr.callEndTime = data.ReadInt64();
39 parcelPtr.ringBeginTime = data.ReadInt64();
40 parcelPtr.ringEndTime = data.ReadInt64();
41 parcelPtr.callDirection = static_cast<CallDirection>(data.ReadInt32());
42 parcelPtr.answerType = static_cast<CallAnswerType>(data.ReadInt32());
43 parcelPtr.index = data.ReadInt32();
44 parcelPtr.voipCallInfo.voipCallId = data.ReadString();
45 parcelPtr.voipCallInfo.userName = data.ReadString();
46 parcelPtr.voipCallInfo.abilityName = data.ReadString();
47 parcelPtr.voipCallInfo.extensionId = data.ReadString();
48 parcelPtr.voipCallInfo.voipBundleName = data.ReadString();
49 int32_t result = OnCallDetailsChange(parcelPtr);
50 if (!reply.WriteInt32(result)) {
51 TELEPHONY_LOGE("writing parcel failed");
52 return TELEPHONY_ERR_WRITE_REPLY_FAIL;
53 }
54 return TELEPHONY_SUCCESS;
55 }
56
OnUpdateCallEventRequest(MessageParcel & data,MessageParcel & reply)57 int32_t CallAbilityCallbackStub::OnUpdateCallEventRequest(MessageParcel &data, MessageParcel &reply)
58 {
59 const CallEventInfo *parcelPtr = nullptr;
60 int32_t length = data.ReadInt32();
61 if (length <= 0 || length >= MAX_LEN) {
62 TELEPHONY_LOGE("Invalid parameter, length = %{public}d", length);
63 return TELEPHONY_ERR_ARGUMENT_INVALID;
64 }
65 if (!data.ContainFileDescriptors()) {
66 TELEPHONY_LOGW("sent raw data is less than 32k");
67 }
68 if ((parcelPtr = reinterpret_cast<const CallEventInfo *>(data.ReadRawData(length))) == nullptr) {
69 TELEPHONY_LOGE("reading raw data failed, length = %d", length);
70 return TELEPHONY_ERR_LOCAL_PTR_NULL;
71 }
72
73 int32_t result = OnCallEventChange(*parcelPtr);
74 if (!reply.WriteInt32(result)) {
75 TELEPHONY_LOGE("writing parcel failed");
76 return TELEPHONY_ERR_WRITE_REPLY_FAIL;
77 }
78 return TELEPHONY_SUCCESS;
79 }
80
OnUpdateAsyncResultRequest(MessageParcel & data,MessageParcel & reply)81 int32_t CallAbilityCallbackStub::OnUpdateAsyncResultRequest(MessageParcel &data, MessageParcel &reply)
82 {
83 AppExecFwk::PacMap info;
84 CallResultReportId reportId = static_cast<CallResultReportId>(data.ReadInt32());
85 info.PutIntValue("result", data.ReadInt32());
86 switch (reportId) {
87 case CallResultReportId::GET_CALL_WAITING_REPORT_ID:
88 case CallResultReportId::GET_CALL_RESTRICTION_REPORT_ID:
89 info.PutIntValue("status", data.ReadInt32());
90 info.PutIntValue("classCw", data.ReadInt32());
91 break;
92 case CallResultReportId::GET_CALL_TRANSFER_REPORT_ID:
93 info.PutIntValue("status", data.ReadInt32());
94 info.PutIntValue("classx", data.ReadInt32());
95 info.PutStringValue("number", data.ReadString());
96 info.PutIntValue("type", data.ReadInt32());
97 info.PutIntValue("reason", data.ReadInt32());
98 info.PutIntValue("time", data.ReadInt32());
99 break;
100 case CallResultReportId::GET_CALL_CLIP_ID:
101 info.PutIntValue("action", data.ReadInt32());
102 info.PutIntValue("clipStat", data.ReadInt32());
103 break;
104 case CallResultReportId::GET_CALL_CLIR_ID:
105 info.PutIntValue("action", data.ReadInt32());
106 info.PutIntValue("clirStat", data.ReadInt32());
107 break;
108 case CallResultReportId::START_RTT_REPORT_ID:
109 info.PutIntValue("active", data.ReadInt32());
110 break;
111 case CallResultReportId::GET_IMS_CONFIG_REPORT_ID:
112 case CallResultReportId::GET_IMS_FEATURE_VALUE_REPORT_ID:
113 info.PutIntValue("value", data.ReadInt32());
114 break;
115 case CallResultReportId::STOP_RTT_REPORT_ID:
116 info.PutIntValue("inactive", data.ReadInt32());
117 break;
118 default:
119 break;
120 }
121 if (!data.ContainFileDescriptors()) {
122 TELEPHONY_LOGW("sent raw data is less than 32k");
123 }
124 int32_t result = OnReportAsyncResults(reportId, info);
125 if (!reply.WriteInt32(result)) {
126 TELEPHONY_LOGE("writing parcel failed");
127 return TELEPHONY_ERR_WRITE_REPLY_FAIL;
128 }
129 return TELEPHONY_SUCCESS;
130 }
131
CallManagerConnect()132 CallManagerConnect::CallManagerConnect()
133 {
134 callAbilityCallbackPtr_ = nullptr;
135 callManagerServicePtr_ = nullptr;
136 systemAbilityId_ = TELEPHONY_CALL_MANAGER_SYS_ABILITY_ID;
137 }
138
~CallManagerConnect()139 CallManagerConnect::~CallManagerConnect()
140 {
141 if (callManagerServicePtr_) {
142 callManagerServicePtr_.clear();
143 callManagerServicePtr_ = nullptr;
144 }
145 }
146
Init(int32_t systemAbilityId)147 int32_t CallManagerConnect::Init(int32_t systemAbilityId)
148 {
149 AccessToken token;
150 TELEPHONY_LOGI("Enter CallManagerIpcClient::Init,systemAbilityId:%d\n", systemAbilityId);
151 systemAbilityId_ = systemAbilityId;
152 int32_t result = ConnectService();
153 TELEPHONY_LOGI("Connect service: %X\n", result);
154 return result;
155 }
156
UnInit()157 void CallManagerConnect::UnInit()
158 {
159 DisconnectService();
160 }
161
DialCall(std::u16string number,AppExecFwk::PacMap & extras) const162 int32_t CallManagerConnect::DialCall(std::u16string number, AppExecFwk::PacMap &extras) const
163 {
164 if (callManagerServicePtr_ != nullptr) {
165 return callManagerServicePtr_->DialCall(number, extras);
166 }
167 TELEPHONY_LOGE("callManagerServicePtr_ is nullptr!");
168 return TELEPHONY_ERR_LOCAL_PTR_NULL;
169 }
170
AnswerCall(int32_t callId,int32_t videoState) const171 int32_t CallManagerConnect::AnswerCall(int32_t callId, int32_t videoState) const
172 {
173 if (callManagerServicePtr_ != nullptr) {
174 return callManagerServicePtr_->AnswerCall(callId, videoState);
175 }
176 TELEPHONY_LOGE("callManagerServicePtr_ is nullptr!");
177 return TELEPHONY_ERR_LOCAL_PTR_NULL;
178 }
179
RejectCall(int32_t callId,bool isSendSms,std::u16string content) const180 int32_t CallManagerConnect::RejectCall(int32_t callId, bool isSendSms, std::u16string content) const
181 {
182 if (callManagerServicePtr_ != nullptr) {
183 return callManagerServicePtr_->RejectCall(callId, isSendSms, content);
184 }
185 TELEPHONY_LOGE("callManagerServicePtr_ is nullptr!");
186 return TELEPHONY_ERR_LOCAL_PTR_NULL;
187 }
188
HoldCall(int32_t callId) const189 int32_t CallManagerConnect::HoldCall(int32_t callId) const
190 {
191 if (callManagerServicePtr_ != nullptr) {
192 return callManagerServicePtr_->HoldCall(callId);
193 }
194 TELEPHONY_LOGE("callManagerServicePtr_ is nullptr!");
195 return TELEPHONY_ERR_LOCAL_PTR_NULL;
196 }
197
UnHoldCall(int32_t callId) const198 int32_t CallManagerConnect::UnHoldCall(int32_t callId) const
199 {
200 if (callManagerServicePtr_ != nullptr) {
201 return callManagerServicePtr_->UnHoldCall(callId);
202 }
203 TELEPHONY_LOGE("callManagerServicePtr_ is nullptr!");
204 return TELEPHONY_ERR_LOCAL_PTR_NULL;
205 }
206
HangUpCall(int32_t callId) const207 int32_t CallManagerConnect::HangUpCall(int32_t callId) const
208 {
209 if (callManagerServicePtr_ != nullptr) {
210 return callManagerServicePtr_->HangUpCall(callId);
211 }
212 TELEPHONY_LOGE("callManagerServicePtr_ is nullptr!");
213 return TELEPHONY_ERR_LOCAL_PTR_NULL;
214 }
215
GetCallState() const216 int32_t CallManagerConnect::GetCallState() const
217 {
218 if (callManagerServicePtr_ != nullptr) {
219 return callManagerServicePtr_->GetCallState();
220 }
221 TELEPHONY_LOGE("callManagerServicePtr_ is nullptr!");
222 return TELEPHONY_ERR_LOCAL_PTR_NULL;
223 }
224
SwitchCall(int32_t callId) const225 int32_t CallManagerConnect::SwitchCall(int32_t callId) const
226 {
227 if (callManagerServicePtr_ != nullptr) {
228 return callManagerServicePtr_->SwitchCall(callId);
229 }
230 TELEPHONY_LOGE("callManagerServicePtr_ is nullptr!");
231 return TELEPHONY_ERR_LOCAL_PTR_NULL;
232 }
233
HasCall() const234 bool CallManagerConnect::HasCall() const
235 {
236 if (callManagerServicePtr_ != nullptr) {
237 return callManagerServicePtr_->HasCall();
238 }
239 TELEPHONY_LOGE("callManagerServicePtr_ is nullptr!");
240 return false;
241 }
242
IsNewCallAllowed(bool & enabled) const243 int32_t CallManagerConnect::IsNewCallAllowed(bool &enabled) const
244 {
245 if (callManagerServicePtr_ != nullptr) {
246 return callManagerServicePtr_->IsNewCallAllowed(enabled);
247 }
248 TELEPHONY_LOGE("callManagerServicePtr_ is nullptr!");
249 return TELEPHONY_ERR_LOCAL_PTR_NULL;
250 }
251
IsRinging(bool & enabled) const252 int32_t CallManagerConnect::IsRinging(bool &enabled) const
253 {
254 if (callManagerServicePtr_ != nullptr) {
255 return callManagerServicePtr_->IsRinging(enabled);
256 }
257 TELEPHONY_LOGE("callManagerServicePtr_ is nullptr!");
258 return TELEPHONY_ERR_LOCAL_PTR_NULL;
259 }
260
IsInEmergencyCall(bool & enabled) const261 int32_t CallManagerConnect::IsInEmergencyCall(bool &enabled) const
262 {
263 if (callManagerServicePtr_ != nullptr) {
264 return callManagerServicePtr_->IsInEmergencyCall(enabled);
265 }
266 TELEPHONY_LOGE("callManagerServicePtr_ is nullptr!");
267 return TELEPHONY_ERR_LOCAL_PTR_NULL;
268 }
269
StartDtmf(int32_t callId,char c) const270 int32_t CallManagerConnect::StartDtmf(int32_t callId, char c) const
271 {
272 if (callManagerServicePtr_ != nullptr) {
273 return callManagerServicePtr_->StartDtmf(callId, c);
274 }
275 TELEPHONY_LOGE("callManagerServicePtr_ is nullptr!");
276 return TELEPHONY_ERR_LOCAL_PTR_NULL;
277 }
278
StopDtmf(int32_t callId) const279 int32_t CallManagerConnect::StopDtmf(int32_t callId) const
280 {
281 if (callManagerServicePtr_ != nullptr) {
282 return callManagerServicePtr_->StopDtmf(callId);
283 }
284 TELEPHONY_LOGE("callManagerServicePtr_ is nullptr!");
285 return TELEPHONY_ERR_LOCAL_PTR_NULL;
286 }
287
GetCallWaiting(int32_t slotId) const288 int32_t CallManagerConnect::GetCallWaiting(int32_t slotId) const
289 {
290 if (callManagerServicePtr_ != nullptr) {
291 return callManagerServicePtr_->GetCallWaiting(slotId);
292 }
293 TELEPHONY_LOGE("callManagerServicePtr_ is nullptr!");
294 return TELEPHONY_ERR_LOCAL_PTR_NULL;
295 }
296
SetCallWaiting(int32_t slotId,bool activate) const297 int32_t CallManagerConnect::SetCallWaiting(int32_t slotId, bool activate) const
298 {
299 if (callManagerServicePtr_ != nullptr) {
300 return callManagerServicePtr_->SetCallWaiting(slotId, activate);
301 }
302 TELEPHONY_LOGE("callManagerServicePtr_ is nullptr!");
303 return TELEPHONY_ERR_LOCAL_PTR_NULL;
304 }
305
GetCallRestriction(int32_t slotId,CallRestrictionType type)306 int32_t CallManagerConnect::GetCallRestriction(int32_t slotId, CallRestrictionType type)
307 {
308 if (callManagerServicePtr_ != nullptr) {
309 return callManagerServicePtr_->GetCallRestriction(slotId, type);
310 }
311 TELEPHONY_LOGE("callManagerServicePtr_ is nullptr!");
312 return TELEPHONY_ERR_LOCAL_PTR_NULL;
313 }
314
SetCallRestriction(int32_t slotId,CallRestrictionInfo & info)315 int32_t CallManagerConnect::SetCallRestriction(int32_t slotId, CallRestrictionInfo &info)
316 {
317 if (callManagerServicePtr_ != nullptr) {
318 return callManagerServicePtr_->SetCallRestriction(slotId, info);
319 }
320 TELEPHONY_LOGE("callManagerServicePtr_ is nullptr!");
321 return TELEPHONY_ERR_LOCAL_PTR_NULL;
322 }
323
GetCallTransferInfo(int32_t slotId,CallTransferType type)324 int32_t CallManagerConnect::GetCallTransferInfo(int32_t slotId, CallTransferType type)
325 {
326 if (callManagerServicePtr_ != nullptr) {
327 return callManagerServicePtr_->GetCallTransferInfo(slotId, type);
328 }
329 TELEPHONY_LOGE("callManagerServicePtr_ is nullptr!");
330 return TELEPHONY_ERR_LOCAL_PTR_NULL;
331 }
332
SetCallTransferInfo(int32_t slotId,CallTransferInfo & info)333 int32_t CallManagerConnect::SetCallTransferInfo(int32_t slotId, CallTransferInfo &info)
334 {
335 if (callManagerServicePtr_ != nullptr) {
336 return callManagerServicePtr_->SetCallTransferInfo(slotId, info);
337 }
338 TELEPHONY_LOGE("callManagerServicePtr_ is nullptr!");
339 return TELEPHONY_ERR_LOCAL_PTR_NULL;
340 }
341
CombineConference(int32_t mainCallId) const342 int32_t CallManagerConnect::CombineConference(int32_t mainCallId) const
343 {
344 if (callManagerServicePtr_ != nullptr) {
345 return callManagerServicePtr_->CombineConference(mainCallId);
346 }
347 TELEPHONY_LOGE("callManagerServicePtr_ is nullptr!");
348 return TELEPHONY_ERR_LOCAL_PTR_NULL;
349 }
350
SeparateConference(int32_t callId) const351 int32_t CallManagerConnect::SeparateConference(int32_t callId) const
352 {
353 if (callManagerServicePtr_ != nullptr) {
354 return callManagerServicePtr_->SeparateConference(callId);
355 }
356 TELEPHONY_LOGE("callManagerServicePtr_ is nullptr!");
357 return TELEPHONY_ERR_LOCAL_PTR_NULL;
358 }
359
KickOutFromConference(int32_t callId) const360 int32_t CallManagerConnect::KickOutFromConference(int32_t callId) const
361 {
362 if (callManagerServicePtr_ != nullptr) {
363 return callManagerServicePtr_->KickOutFromConference(callId);
364 }
365 TELEPHONY_LOGE("callManagerServicePtr_ is nullptr!");
366 return TELEPHONY_ERR_LOCAL_PTR_NULL;
367 }
368
IsEmergencyPhoneNumber(std::u16string & number,int32_t slotId,bool & enabled) const369 int32_t CallManagerConnect::IsEmergencyPhoneNumber(std::u16string &number, int32_t slotId, bool &enabled) const
370 {
371 if (callManagerServicePtr_ != nullptr) {
372 return callManagerServicePtr_->IsEmergencyPhoneNumber(number, slotId, enabled);
373 }
374 TELEPHONY_LOGE("callManagerServicePtr_ is nullptr!");
375 return TELEPHONY_ERR_LOCAL_PTR_NULL;
376 }
377
FormatPhoneNumber(std::u16string & number,std::u16string & countryCode,std::u16string & formatNumber) const378 int32_t CallManagerConnect::FormatPhoneNumber(
379 std::u16string &number, std::u16string &countryCode, std::u16string &formatNumber) const
380 {
381 if (callManagerServicePtr_ != nullptr) {
382 return callManagerServicePtr_->FormatPhoneNumber(number, countryCode, formatNumber);
383 }
384 TELEPHONY_LOGE("callManagerServicePtr_ is nullptr!");
385 return TELEPHONY_ERR_LOCAL_PTR_NULL;
386 }
387
FormatPhoneNumberToE164(std::u16string & number,std::u16string & countryCode,std::u16string & formatNumber) const388 int32_t CallManagerConnect::FormatPhoneNumberToE164(
389 std::u16string &number, std::u16string &countryCode, std::u16string &formatNumber) const
390 {
391 if (callManagerServicePtr_ != nullptr) {
392 return callManagerServicePtr_->FormatPhoneNumberToE164(number, countryCode, formatNumber);
393 }
394 TELEPHONY_LOGE("callManagerServicePtr_ is nullptr!");
395 return TELEPHONY_ERR_LOCAL_PTR_NULL;
396 }
397
GetMainCallId(int32_t callId,int32_t & mainCallId)398 int32_t CallManagerConnect::GetMainCallId(int32_t callId, int32_t &mainCallId)
399 {
400 if (callManagerServicePtr_ != nullptr) {
401 return callManagerServicePtr_->GetMainCallId(callId, mainCallId);
402 }
403 TELEPHONY_LOGE("callManagerServicePtr_ is nullptr!");
404 return TELEPHONY_ERR_LOCAL_PTR_NULL;
405 }
406
GetSubCallIdList(int32_t callId,std::vector<std::u16string> & callIdList)407 int32_t CallManagerConnect::GetSubCallIdList(int32_t callId, std::vector<std::u16string> &callIdList)
408 {
409 if (callManagerServicePtr_ != nullptr) {
410 return callManagerServicePtr_->GetSubCallIdList(callId, callIdList);
411 }
412 callIdList.clear();
413 return TELEPHONY_ERR_LOCAL_PTR_NULL;
414 }
415
GetCallIdListForConference(int32_t callId,std::vector<std::u16string> & callIdList)416 int32_t CallManagerConnect::GetCallIdListForConference(int32_t callId, std::vector<std::u16string> &callIdList)
417 {
418 if (callManagerServicePtr_ != nullptr) {
419 return callManagerServicePtr_->GetCallIdListForConference(callId, callIdList);
420 }
421 callIdList.clear();
422 return TELEPHONY_ERR_LOCAL_PTR_NULL;
423 }
424
ControlCamera(int32_t callId,std::u16string cameraId)425 int32_t CallManagerConnect::ControlCamera(int32_t callId, std::u16string cameraId)
426 {
427 if (callManagerServicePtr_ != nullptr) {
428 return callManagerServicePtr_->ControlCamera(callId, cameraId);
429 }
430 TELEPHONY_LOGE("callManagerServicePtr_ is nullptr!");
431 return TELEPHONY_ERR_LOCAL_PTR_NULL;
432 }
433
SetAudioDevice(const AudioDevice & audioDevice)434 int32_t CallManagerConnect::SetAudioDevice(const AudioDevice &audioDevice)
435 {
436 if (callManagerServicePtr_ == nullptr) {
437 TELEPHONY_LOGE("callManagerServicePtr_ is nullptr!");
438 return TELEPHONY_ERR_LOCAL_PTR_NULL;
439 }
440 return callManagerServicePtr_->SetAudioDevice(audioDevice);
441 }
442
SetPreviewWindow(int32_t callId,std::string surfaceId)443 int32_t CallManagerConnect::SetPreviewWindow(int32_t callId, std::string surfaceId)
444 {
445 if (callManagerServicePtr_ != nullptr) {
446 int len = static_cast<int>(surfaceId.length());
447 std::string subSurfaceId = surfaceId;
448 if (len >= 1) {
449 subSurfaceId = surfaceId.substr(0, 1);
450 }
451 if (subSurfaceId.empty() || subSurfaceId[0] < '0' || subSurfaceId[0] > '9') {
452 subSurfaceId = "";
453 return callManagerServicePtr_->SetPreviewWindow(callId, subSurfaceId, nullptr);
454 } else {
455 uint64_t tmpSurfaceId = std::stoull(subSurfaceId);
456 auto surface = SurfaceUtils::GetInstance()->GetSurface(tmpSurfaceId);
457 return callManagerServicePtr_->SetPreviewWindow(callId, subSurfaceId, surface);
458 }
459 }
460 TELEPHONY_LOGE("callManagerServicePtr_ is nullptr!");
461 return TELEPHONY_ERR_LOCAL_PTR_NULL;
462 }
463
SetDisplayWindow(int32_t callId,std::string surfaceId)464 int32_t CallManagerConnect::SetDisplayWindow(int32_t callId, std::string surfaceId)
465 {
466 if (callManagerServicePtr_ != nullptr) {
467 int len = static_cast<int>(surfaceId.length());
468 std::string subSurfaceId = surfaceId;
469 if (len >= 1) {
470 subSurfaceId = surfaceId.substr(0, 1);
471 }
472 if (subSurfaceId.empty() || subSurfaceId[0] < '0' || subSurfaceId[0] > '9') {
473 subSurfaceId = "";
474 return callManagerServicePtr_->SetPreviewWindow(callId, subSurfaceId, nullptr);
475 } else {
476 uint64_t tmpSurfaceId = std::stoull(subSurfaceId);
477 auto surface = SurfaceUtils::GetInstance()->GetSurface(tmpSurfaceId);
478 return callManagerServicePtr_->SetPreviewWindow(callId, subSurfaceId, surface);
479 }
480 }
481 TELEPHONY_LOGE("callManagerServicePtr_ is nullptr!");
482 return TELEPHONY_ERR_LOCAL_PTR_NULL;
483 }
484
SetCameraZoom(float zoomRatio)485 int32_t CallManagerConnect::SetCameraZoom(float zoomRatio)
486 {
487 if (callManagerServicePtr_ != nullptr) {
488 return callManagerServicePtr_->SetCameraZoom(zoomRatio);
489 }
490 TELEPHONY_LOGE("callManagerServicePtr_ is nullptr!");
491 return TELEPHONY_ERR_LOCAL_PTR_NULL;
492 }
493
SetPausePicture(int32_t callId,std::u16string path)494 int32_t CallManagerConnect::SetPausePicture(int32_t callId, std::u16string path)
495 {
496 if (callManagerServicePtr_ != nullptr) {
497 return callManagerServicePtr_->SetPausePicture(callId, path);
498 }
499 TELEPHONY_LOGE("callManagerServicePtr_ is nullptr!");
500 return TELEPHONY_ERR_LOCAL_PTR_NULL;
501 }
502
SetDeviceDirection(int32_t callId,int32_t rotation)503 int32_t CallManagerConnect::SetDeviceDirection(int32_t callId, int32_t rotation)
504 {
505 if (callManagerServicePtr_ != nullptr) {
506 return callManagerServicePtr_->SetDeviceDirection(callId, rotation);
507 }
508 TELEPHONY_LOGE("callManagerServicePtr_ is nullptr!");
509 return TELEPHONY_ERR_LOCAL_PTR_NULL;
510 }
511
CancelCallUpgrade(int32_t callId)512 int32_t CallManagerConnect::CancelCallUpgrade(int32_t callId)
513 {
514 if (callManagerServicePtr_ != nullptr) {
515 return callManagerServicePtr_->CancelCallUpgrade(callId);
516 }
517 TELEPHONY_LOGE("callManagerServicePtr_ is nullptr!");
518 return TELEPHONY_ERR_LOCAL_PTR_NULL;
519 }
520
RequestCameraCapabilities(int32_t callId)521 int32_t CallManagerConnect::RequestCameraCapabilities(int32_t callId)
522 {
523 if (callManagerServicePtr_ != nullptr) {
524 return callManagerServicePtr_->RequestCameraCapabilities(callId);
525 }
526 TELEPHONY_LOGE("callManagerServicePtr_ is nullptr!");
527 return TELEPHONY_ERR_LOCAL_PTR_NULL;
528 }
529
EnableImsSwitch(int32_t slotId)530 int32_t CallManagerConnect::EnableImsSwitch(int32_t slotId)
531 {
532 if (callManagerServicePtr_ != nullptr) {
533 return callManagerServicePtr_->EnableImsSwitch(slotId);
534 }
535 TELEPHONY_LOGE("callManagerServicePtr_ is nullptr!");
536 return TELEPHONY_ERR_LOCAL_PTR_NULL;
537 }
538
DisableImsSwitch(int32_t slotId)539 int32_t CallManagerConnect::DisableImsSwitch(int32_t slotId)
540 {
541 if (callManagerServicePtr_ != nullptr) {
542 return callManagerServicePtr_->DisableImsSwitch(slotId);
543 }
544 TELEPHONY_LOGE("callManagerServicePtr_ is nullptr!");
545 return TELEPHONY_ERR_LOCAL_PTR_NULL;
546 }
547
IsImsSwitchEnabled(int32_t slotId)548 int32_t CallManagerConnect::IsImsSwitchEnabled(int32_t slotId)
549 {
550 if (callManagerServicePtr_ != nullptr) {
551 bool enabled;
552 return callManagerServicePtr_->IsImsSwitchEnabled(slotId, enabled);
553 }
554 TELEPHONY_LOGE("callManagerServicePtr_ is nullptr!");
555 return TELEPHONY_ERR_LOCAL_PTR_NULL;
556 }
557
SetMuted(bool isMuted) const558 int32_t CallManagerConnect::SetMuted(bool isMuted) const
559 {
560 if (callManagerServicePtr_ != nullptr) {
561 return callManagerServicePtr_->SetMuted(isMuted);
562 }
563 TELEPHONY_LOGE("callManagerServicePtr_ is nullptr!");
564 return TELEPHONY_ERR_LOCAL_PTR_NULL;
565 }
566
RegisterCallBack()567 int32_t CallManagerConnect::RegisterCallBack()
568 {
569 if (callManagerServicePtr_ == nullptr) {
570 TELEPHONY_LOGE("callManagerServicePtr_ is null");
571 return TELEPHONY_ERR_LOCAL_PTR_NULL;
572 }
573 callAbilityCallbackPtr_ = (std::make_unique<CallAbilityCallbackStub>()).release();
574 if (callAbilityCallbackPtr_ == nullptr) {
575 DisconnectService();
576 TELEPHONY_LOGE("create CallAbilityCallbackStub object failed!");
577 return TELEPHONY_ERR_LOCAL_PTR_NULL;
578 }
579 int32_t ret = callManagerServicePtr_->RegisterCallBack(callAbilityCallbackPtr_);
580 if (ret != TELEPHONY_SUCCESS) {
581 DisconnectService();
582 TELEPHONY_LOGE("register callback to call manager service failed,result: %{public}d", ret);
583 return TELEPHONY_ERR_REGISTER_CALLBACK_FAIL;
584 }
585 TELEPHONY_LOGI("register call ability callback success!");
586 return TELEPHONY_SUCCESS;
587 }
588
ConnectService()589 int32_t CallManagerConnect::ConnectService()
590 {
591 Utils::UniqueWriteGuard<Utils::RWLock> guard(rwClientLock_);
592 if (callManagerServicePtr_ != nullptr) {
593 return TELEPHONY_SUCCESS;
594 }
595 sptr<ISystemAbilityManager> managerPtr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
596 if (managerPtr == nullptr) {
597 return TELEPHONY_ERR_LOCAL_PTR_NULL;
598 }
599 sptr<ICallManagerService> callManagerServicePtr = nullptr;
600 sptr<IRemoteObject> iRemoteObjectPtr = managerPtr->GetSystemAbility(systemAbilityId_);
601 if (iRemoteObjectPtr == nullptr) {
602 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
603 }
604 callManagerServicePtr = iface_cast<ICallManagerService>(iRemoteObjectPtr);
605 if (!callManagerServicePtr) {
606 return TELEPHONY_ERR_LOCAL_PTR_NULL;
607 }
608 callManagerServicePtr_ = callManagerServicePtr;
609 int32_t ret = RegisterCallBack();
610 if (ret != TELEPHONY_SUCCESS) {
611 return ret;
612 }
613 return TELEPHONY_SUCCESS;
614 }
615
DisconnectService()616 void CallManagerConnect::DisconnectService()
617 {
618 Utils::UniqueWriteGuard<Utils::RWLock> guard(rwClientLock_);
619 if (callManagerServicePtr_) {
620 callManagerServicePtr_.clear();
621 callManagerServicePtr_ = nullptr;
622 }
623 if (callAbilityCallbackPtr_) {
624 callAbilityCallbackPtr_.clear();
625 callAbilityCallbackPtr_ = nullptr;
626 }
627 }
628 } // namespace Telephony
629 } // namespace OHOS
630