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