• 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_manager_service_proxy.h"
17 
18 #include "call_manager_errors.h"
19 #include "message_option.h"
20 #include "message_parcel.h"
21 
22 namespace OHOS {
23 namespace Telephony {
CallManagerServiceProxy(const sptr<IRemoteObject> & impl)24 CallManagerServiceProxy::CallManagerServiceProxy(const sptr<IRemoteObject> &impl)
25     : IRemoteProxy<ICallManagerService>(impl)
26 {}
27 
RegisterCallBack(const sptr<ICallAbilityCallback> & callback)28 int32_t CallManagerServiceProxy::RegisterCallBack(const sptr<ICallAbilityCallback> &callback)
29 {
30     MessageOption option;
31     MessageParcel dataParcel;
32     MessageParcel replyParcel;
33     if (!dataParcel.WriteInterfaceToken(CallManagerServiceProxy::GetDescriptor())) {
34         TELEPHONY_LOGE("write descriptor fail");
35         return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
36     }
37     dataParcel.WriteRemoteObject(callback->AsObject().GetRefPtr());
38     auto remote = Remote();
39     if (remote == nullptr) {
40         TELEPHONY_LOGE("function Remote() return nullptr!");
41         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
42     }
43     int32_t error = remote->SendRequest(INTERFACE_REGISTER_CALLBACK, dataParcel, replyParcel, option);
44     if (error != TELEPHONY_SUCCESS) {
45         TELEPHONY_LOGE("Function RegisterCallBack! errCode:%{public}d", error);
46         return error;
47     }
48     return replyParcel.ReadInt32();
49 }
50 
UnRegisterCallBack()51 int32_t CallManagerServiceProxy::UnRegisterCallBack()
52 {
53     MessageOption option;
54     MessageParcel dataParcel;
55     MessageParcel replyParcel;
56     if (!dataParcel.WriteInterfaceToken(CallManagerServiceProxy::GetDescriptor())) {
57         TELEPHONY_LOGE("write descriptor fail");
58         return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
59     }
60     auto remote = Remote();
61     if (remote == nullptr) {
62         TELEPHONY_LOGE("function Remote() return nullptr!");
63         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
64     }
65     int32_t error = remote->SendRequest(INTERFACE_UNREGISTER_CALLBACK, dataParcel, replyParcel, option);
66     if (error != TELEPHONY_SUCCESS) {
67         TELEPHONY_LOGE("Function RegisterCallBack! errCode:%{public}d", error);
68         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
69     }
70     return replyParcel.ReadInt32();
71 }
72 
DialCall(std::u16string number,AppExecFwk::PacMap & extras)73 int32_t CallManagerServiceProxy::DialCall(std::u16string number, AppExecFwk::PacMap &extras)
74 {
75     MessageOption option;
76     MessageParcel dataParcel;
77     MessageParcel replyParcel;
78     if (!dataParcel.WriteInterfaceToken(CallManagerServiceProxy::GetDescriptor())) {
79         TELEPHONY_LOGE("write descriptor fail");
80         return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
81     }
82     if (number.empty()) {
83         TELEPHONY_LOGE("number is empty");
84         return TELEPHONY_ERR_ARGUMENT_INVALID;
85     }
86     dataParcel.WriteString16(number);
87     dataParcel.WriteInt32(extras.GetIntValue("accountId"));
88     dataParcel.WriteInt32(extras.GetIntValue("videoState"));
89     dataParcel.WriteInt32(extras.GetIntValue("dialScene"));
90     dataParcel.WriteInt32(extras.GetIntValue("dialType"));
91     dataParcel.WriteInt32(extras.GetIntValue("callType"));
92     auto remote = Remote();
93     if (remote == nullptr) {
94         TELEPHONY_LOGE("function Remote() return nullptr!");
95         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
96     }
97     int32_t error = remote->SendRequest(INTERFACE_DIAL_CALL, dataParcel, replyParcel, option);
98     if (error != TELEPHONY_SUCCESS) {
99         TELEPHONY_LOGE("function DialCall call failed! errCode:%{public}d", error);
100         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
101     }
102     return replyParcel.ReadInt32();
103 }
104 
AnswerCall(int32_t callId,int32_t videoState)105 int32_t CallManagerServiceProxy::AnswerCall(int32_t callId, int32_t videoState)
106 {
107     MessageOption option;
108     MessageParcel dataParcel;
109     MessageParcel replyParcel;
110     if (!dataParcel.WriteInterfaceToken(CallManagerServiceProxy::GetDescriptor())) {
111         TELEPHONY_LOGE("write descriptor fail");
112         return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
113     }
114     dataParcel.WriteInt32(callId);
115     dataParcel.WriteInt32(videoState);
116     auto remote = Remote();
117     if (remote == nullptr) {
118         TELEPHONY_LOGE("function Remote() return nullptr!");
119         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
120     }
121     int32_t error = remote->SendRequest(INTERFACE_ANSWER_CALL, dataParcel, replyParcel, option);
122     if (error != TELEPHONY_SUCCESS) {
123         TELEPHONY_LOGE("function AnswerCall call failed! errCode:%{public}d", error);
124         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
125     }
126     return replyParcel.ReadInt32();
127 }
128 
RejectCall(int32_t callId,bool rejectWithMessage,std::u16string textMessage)129 int32_t CallManagerServiceProxy::RejectCall(int32_t callId, bool rejectWithMessage, std::u16string textMessage)
130 {
131     MessageOption option;
132     MessageParcel dataParcel;
133     MessageParcel replyParcel;
134     if (!dataParcel.WriteInterfaceToken(CallManagerServiceProxy::GetDescriptor())) {
135         TELEPHONY_LOGE("write descriptor fail");
136         return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
137     }
138     dataParcel.WriteInt32(callId);
139     dataParcel.WriteBool(rejectWithMessage);
140     dataParcel.WriteString16(textMessage);
141     auto remote = Remote();
142     if (remote == nullptr) {
143         TELEPHONY_LOGE("function Remote() return nullptr!");
144         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
145     }
146     int32_t error = remote->SendRequest(INTERFACE_REJECT_CALL, dataParcel, replyParcel, option);
147     if (error != TELEPHONY_SUCCESS) {
148         TELEPHONY_LOGE("function RejectCall call failed! errCode:%{public}d", error);
149         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
150     }
151     return replyParcel.ReadInt32();
152 }
153 
HangUpCall(int32_t callId)154 int32_t CallManagerServiceProxy::HangUpCall(int32_t callId)
155 {
156     MessageOption option;
157     MessageParcel dataParcel;
158     MessageParcel replyParcel;
159     if (!dataParcel.WriteInterfaceToken(CallManagerServiceProxy::GetDescriptor())) {
160         TELEPHONY_LOGE("write descriptor fail");
161         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
162     }
163     dataParcel.WriteInt32(callId);
164     auto remote = Remote();
165     if (remote == nullptr) {
166         TELEPHONY_LOGE("function Remote() return nullptr!");
167         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
168     }
169     int32_t error = remote->SendRequest(INTERFACE_DISCONNECT_CALL, dataParcel, replyParcel, option);
170     if (error != TELEPHONY_SUCCESS) {
171         TELEPHONY_LOGE("function HangUpCall call failed! errCode:%{public}d", error);
172         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
173     }
174     return replyParcel.ReadInt32();
175 }
176 
GetCallState()177 int32_t CallManagerServiceProxy::GetCallState()
178 {
179     MessageOption option;
180     MessageParcel dataParcel;
181     MessageParcel replyParcel;
182     if (!dataParcel.WriteInterfaceToken(CallManagerServiceProxy::GetDescriptor())) {
183         TELEPHONY_LOGE("write descriptor fail");
184         return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
185     }
186     auto remote = Remote();
187     if (remote == nullptr) {
188         TELEPHONY_LOGE("function Remote() return nullptr!");
189         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
190     }
191     int32_t error = remote->SendRequest(INTERFACE_GET_CALL_STATE, dataParcel, replyParcel, option);
192     if (error != TELEPHONY_SUCCESS) {
193         TELEPHONY_LOGE("function GetCallState! errCode:%{public}d", error);
194         return error;
195     }
196     return replyParcel.ReadInt32();
197 }
198 
HoldCall(int32_t callId)199 int32_t CallManagerServiceProxy::HoldCall(int32_t callId)
200 {
201     MessageOption option;
202     MessageParcel dataParcel;
203     MessageParcel replyParcel;
204     if (!dataParcel.WriteInterfaceToken(CallManagerServiceProxy::GetDescriptor())) {
205         TELEPHONY_LOGE("write descriptor fail");
206         return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
207     }
208     dataParcel.WriteInt32(callId);
209     auto remote = Remote();
210     if (remote == nullptr) {
211         TELEPHONY_LOGE("function Remote() return nullptr!");
212         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
213     }
214     int32_t error = remote->SendRequest(INTERFACE_HOLD_CALL, dataParcel, replyParcel, option);
215     if (error != TELEPHONY_SUCCESS) {
216         TELEPHONY_LOGE("Function HoldCall call failed! errCode:%{public}d", error);
217         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
218     }
219     return replyParcel.ReadInt32();
220 }
221 
UnHoldCall(int32_t callId)222 int32_t CallManagerServiceProxy::UnHoldCall(int32_t callId)
223 {
224     MessageOption option;
225     MessageParcel dataParcel;
226     MessageParcel replyParcel;
227     if (!dataParcel.WriteInterfaceToken(CallManagerServiceProxy::GetDescriptor())) {
228         TELEPHONY_LOGE("write descriptor fail");
229         return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
230     }
231     dataParcel.WriteInt32(callId);
232     auto remote = Remote();
233     if (remote == nullptr) {
234         TELEPHONY_LOGE("function Remote() return nullptr!");
235         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
236     }
237     int32_t error = remote->SendRequest(INTERFACE_UNHOLD_CALL, dataParcel, replyParcel, option);
238     if (error != TELEPHONY_SUCCESS) {
239         TELEPHONY_LOGE("Function UnHoldCall call failed! errCode:%{public}d", error);
240         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
241     }
242     return replyParcel.ReadInt32();
243 }
244 
SwitchCall(int32_t callId)245 int32_t CallManagerServiceProxy::SwitchCall(int32_t callId)
246 {
247     MessageOption option;
248     MessageParcel dataParcel;
249     MessageParcel replyParcel;
250     if (!dataParcel.WriteInterfaceToken(CallManagerServiceProxy::GetDescriptor())) {
251         TELEPHONY_LOGE("write descriptor fail");
252         return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
253     }
254     dataParcel.WriteInt32(callId);
255     auto remote = Remote();
256     if (remote == nullptr) {
257         TELEPHONY_LOGE("function Remote() return nullptr!");
258         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
259     }
260     int32_t error = remote->SendRequest(INTERFACE_SWAP_CALL, dataParcel, replyParcel, option);
261     if (error != TELEPHONY_SUCCESS) {
262         TELEPHONY_LOGE("Function UnHoldCall call failed! errCode:%{public}d", error);
263         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
264     }
265     return replyParcel.ReadInt32();
266 }
267 
HasCall()268 bool CallManagerServiceProxy::HasCall()
269 {
270     MessageOption option;
271     MessageParcel dataParcel;
272     MessageParcel replyParcel;
273     if (!dataParcel.WriteInterfaceToken(CallManagerServiceProxy::GetDescriptor())) {
274         TELEPHONY_LOGE("write descriptor fail");
275         return false;
276     }
277     auto remote = Remote();
278     if (remote == nullptr) {
279         TELEPHONY_LOGE("function Remote() return nullptr!");
280         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
281     }
282     int32_t error = remote->SendRequest(INTERFACE_HAS_CALL, dataParcel, replyParcel, option);
283     if (error != TELEPHONY_SUCCESS) {
284         TELEPHONY_LOGE("Function HasCall! errCode:%{public}d", error);
285         return false;
286     }
287     return replyParcel.ReadBool();
288 }
289 
IsNewCallAllowed(bool & enabled)290 int32_t CallManagerServiceProxy::IsNewCallAllowed(bool &enabled)
291 {
292     MessageOption option;
293     MessageParcel dataParcel;
294     MessageParcel replyParcel;
295     if (!dataParcel.WriteInterfaceToken(CallManagerServiceProxy::GetDescriptor())) {
296         TELEPHONY_LOGE("write descriptor fail");
297         return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
298     }
299     auto remote = Remote();
300     if (remote == nullptr) {
301         TELEPHONY_LOGE("function Remote() return nullptr!");
302         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
303     }
304     int32_t error = remote->SendRequest(INTERFACE_IS_NEW_CALL_ALLOWED, dataParcel, replyParcel, option);
305     if (error != TELEPHONY_SUCCESS) {
306         TELEPHONY_LOGE("Function IsNewCallAllowed! errCode:%{public}d", error);
307         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
308     }
309     int32_t result = replyParcel.ReadInt32();
310     if (result == TELEPHONY_ERR_SUCCESS) {
311         enabled = replyParcel.ReadBool();
312     }
313     return result;
314 }
315 
SetMuted(bool isMute)316 int32_t CallManagerServiceProxy::SetMuted(bool isMute)
317 {
318     MessageOption option;
319     MessageParcel dataParcel;
320     MessageParcel replyParcel;
321     if (!dataParcel.WriteInterfaceToken(CallManagerServiceProxy::GetDescriptor())) {
322         TELEPHONY_LOGE("write descriptor fail");
323         return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
324     }
325     dataParcel.WriteBool(isMute);
326     auto remote = Remote();
327     if (remote == nullptr) {
328         TELEPHONY_LOGE("function Remote() return nullptr!");
329         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
330     }
331     int32_t error = remote->SendRequest(INTERFACE_SET_MUTE, dataParcel, replyParcel, option);
332     if (error != TELEPHONY_SUCCESS) {
333         TELEPHONY_LOGE("function SetMute failed! errCode:%{public}d", error);
334         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
335     }
336     return replyParcel.ReadInt32();
337 }
338 
MuteRinger()339 int32_t CallManagerServiceProxy::MuteRinger()
340 {
341     MessageOption option;
342     MessageParcel dataParcel;
343     MessageParcel replyParcel;
344     if (!dataParcel.WriteInterfaceToken(CallManagerServiceProxy::GetDescriptor())) {
345         TELEPHONY_LOGE("write descriptor fail");
346         return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
347     }
348     auto remote = Remote();
349     if (remote == nullptr) {
350         TELEPHONY_LOGE("function Remote() return nullptr!");
351         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
352     }
353     int32_t error = remote->SendRequest(INTERFACE_MUTE_RINGER, dataParcel, replyParcel, option);
354     if (error != TELEPHONY_SUCCESS) {
355         TELEPHONY_LOGE("function MuteRinger failed! errCode:%{public}d", error);
356         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
357     }
358     return replyParcel.ReadInt32();
359 }
360 
SetAudioDevice(AudioDevice deviceType,const std::string & bluetoothAddress)361 int32_t CallManagerServiceProxy::SetAudioDevice(AudioDevice deviceType, const std::string &bluetoothAddress)
362 {
363     MessageOption option;
364     MessageParcel dataParcel;
365     MessageParcel replyParcel;
366     if (!dataParcel.WriteInterfaceToken(CallManagerServiceProxy::GetDescriptor())) {
367         TELEPHONY_LOGE("write descriptor fail");
368         return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
369     }
370     dataParcel.WriteInt32(static_cast<int32_t>(deviceType));
371     dataParcel.WriteString(bluetoothAddress);
372     auto remote = Remote();
373     if (remote == nullptr) {
374         TELEPHONY_LOGE("function Remote() return nullptr!");
375         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
376     }
377     int32_t error = remote->SendRequest(INTERFACE_SET_AUDIO_DEVICE, dataParcel, replyParcel, option);
378     if (error != TELEPHONY_SUCCESS) {
379         TELEPHONY_LOGE("function SetAudioDevice failed! errCode:%{public}d", error);
380         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
381     }
382     return replyParcel.ReadInt32();
383 }
384 
IsRinging(bool & enabled)385 int32_t CallManagerServiceProxy::IsRinging(bool &enabled)
386 {
387     MessageOption option;
388     MessageParcel dataParcel;
389     MessageParcel replyParcel;
390     if (!dataParcel.WriteInterfaceToken(CallManagerServiceProxy::GetDescriptor())) {
391         TELEPHONY_LOGE("write descriptor fail");
392         return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
393     }
394     auto remote = Remote();
395     if (remote == nullptr) {
396         TELEPHONY_LOGE("function Remote() return nullptr!");
397         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
398     }
399     int32_t error = remote->SendRequest(INTERFACE_IS_RINGING, dataParcel, replyParcel, option);
400     if (error != TELEPHONY_SUCCESS) {
401         TELEPHONY_LOGE("function IsRinging errCode:%{public}d", error);
402         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
403     }
404     int32_t result = replyParcel.ReadInt32();
405     if (result == TELEPHONY_ERR_SUCCESS) {
406         enabled = replyParcel.ReadBool();
407     }
408     return result;
409 }
410 
IsInEmergencyCall(bool & enabled)411 int32_t CallManagerServiceProxy::IsInEmergencyCall(bool &enabled)
412 {
413     MessageOption option;
414     MessageParcel dataParcel;
415     MessageParcel replyParcel;
416     if (!dataParcel.WriteInterfaceToken(CallManagerServiceProxy::GetDescriptor())) {
417         TELEPHONY_LOGE("write descriptor fail");
418         return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
419     }
420     auto remote = Remote();
421     if (remote == nullptr) {
422         TELEPHONY_LOGE("function Remote() return nullptr!");
423         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
424     }
425     int32_t error = remote->SendRequest(INTERFACE_IS_EMERGENCY_CALL, dataParcel, replyParcel, option);
426     if (error != TELEPHONY_SUCCESS) {
427         TELEPHONY_LOGE("function IsInEmergencyCall errCode:%{public}d", error);
428         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
429     }
430     int32_t result = replyParcel.ReadInt32();
431     if (result == TELEPHONY_ERR_SUCCESS) {
432         enabled = replyParcel.ReadBool();
433     }
434     return result;
435 }
436 
StartDtmf(int32_t callId,char str)437 int32_t CallManagerServiceProxy::StartDtmf(int32_t callId, char str)
438 {
439     MessageOption option;
440     MessageParcel dataParcel;
441     MessageParcel replyParcel;
442     if (!dataParcel.WriteInterfaceToken(CallManagerServiceProxy::GetDescriptor())) {
443         TELEPHONY_LOGE("write descriptor fail");
444         return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
445     }
446     auto remote = Remote();
447     if (remote == nullptr) {
448         TELEPHONY_LOGE("function Remote() return nullptr!");
449         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
450     }
451     dataParcel.WriteInt32(callId);
452     dataParcel.WriteInt8(str);
453     int32_t error = remote->SendRequest(CallManagerSurfaceCode::INTERFACE_START_DTMF, dataParcel, replyParcel, option);
454     if (error != TELEPHONY_SUCCESS) {
455         TELEPHONY_LOGE("Function StartDtmf! errCode:%{public}d", error);
456         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
457     }
458     return replyParcel.ReadInt32();
459 }
460 
StopDtmf(int32_t callId)461 int32_t CallManagerServiceProxy::StopDtmf(int32_t callId)
462 {
463     MessageOption option;
464     MessageParcel dataParcel;
465     MessageParcel replyParcel;
466     if (!dataParcel.WriteInterfaceToken(CallManagerServiceProxy::GetDescriptor())) {
467         TELEPHONY_LOGE("write descriptor fail");
468         return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
469     }
470     auto remote = Remote();
471     if (remote == nullptr) {
472         TELEPHONY_LOGE("function Remote() return nullptr!");
473         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
474     }
475     dataParcel.WriteInt32(callId);
476     int32_t error = remote->SendRequest(CallManagerSurfaceCode::INTERFACE_STOP_DTMF, dataParcel, replyParcel, option);
477     if (error != TELEPHONY_SUCCESS) {
478         TELEPHONY_LOGE("Function StopDtmf! errCode:%{public}d", error);
479         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
480     }
481     return replyParcel.ReadInt32();
482 }
483 
GetCallWaiting(int32_t slotId)484 int32_t CallManagerServiceProxy::GetCallWaiting(int32_t slotId)
485 {
486     MessageOption option;
487     MessageParcel dataParcel;
488     MessageParcel replyParcel;
489     if (!dataParcel.WriteInterfaceToken(CallManagerServiceProxy::GetDescriptor())) {
490         TELEPHONY_LOGE("write descriptor fail");
491         return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
492     }
493     auto remote = Remote();
494     if (remote == nullptr) {
495         TELEPHONY_LOGE("function Remote() return nullptr!");
496         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
497     }
498     dataParcel.WriteInt32(slotId);
499     int32_t error =
500         remote->SendRequest(CallManagerSurfaceCode::INTERFACE_GET_CALL_WAITING, dataParcel, replyParcel, option);
501     if (error != TELEPHONY_SUCCESS) {
502         TELEPHONY_LOGE("Function GetCallWaiting! errCode:%{public}d", error);
503         return error;
504     }
505     return replyParcel.ReadInt32();
506 }
507 
SetCallWaiting(int32_t slotId,bool activate)508 int32_t CallManagerServiceProxy::SetCallWaiting(int32_t slotId, bool activate)
509 {
510     MessageOption option;
511     MessageParcel dataParcel;
512     MessageParcel replyParcel;
513     if (!dataParcel.WriteInterfaceToken(CallManagerServiceProxy::GetDescriptor())) {
514         TELEPHONY_LOGE("write descriptor fail");
515         return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
516     }
517     auto remote = Remote();
518     if (remote == nullptr) {
519         TELEPHONY_LOGE("function Remote() return nullptr!");
520         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
521     }
522     dataParcel.WriteInt32(slotId);
523     dataParcel.WriteBool(activate);
524     int32_t error =
525         remote->SendRequest(CallManagerSurfaceCode::INTERFACE_SET_CALL_WAITING, dataParcel, replyParcel, option);
526     if (error != TELEPHONY_SUCCESS) {
527         TELEPHONY_LOGE("Function SetCallWaiting! errCode:%{public}d", error);
528         return error;
529     }
530     return replyParcel.ReadInt32();
531 }
532 
GetCallRestriction(int32_t slotId,CallRestrictionType type)533 int32_t CallManagerServiceProxy::GetCallRestriction(int32_t slotId, CallRestrictionType type)
534 {
535     MessageOption option;
536     MessageParcel dataParcel;
537     MessageParcel replyParcel;
538     if (!dataParcel.WriteInterfaceToken(CallManagerServiceProxy::GetDescriptor())) {
539         TELEPHONY_LOGE("write descriptor fail");
540         return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
541     }
542     auto remote = Remote();
543     if (remote == nullptr) {
544         TELEPHONY_LOGE("function Remote() return nullptr!");
545         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
546     }
547     dataParcel.WriteInt32(slotId);
548     dataParcel.WriteInt32(static_cast<int32_t>(type));
549     int32_t error =
550         remote->SendRequest(CallManagerSurfaceCode::INTERFACE_GET_CALL_RESTRICTION, dataParcel, replyParcel, option);
551     if (error != TELEPHONY_SUCCESS) {
552         TELEPHONY_LOGE("Function GetCallRestriction! errCode:%{public}d", error);
553         return error;
554     }
555     return replyParcel.ReadInt32();
556 }
557 
SetCallRestriction(int32_t slotId,CallRestrictionInfo & info)558 int32_t CallManagerServiceProxy::SetCallRestriction(int32_t slotId, CallRestrictionInfo &info)
559 {
560     MessageOption option;
561     MessageParcel dataParcel;
562     MessageParcel replyParcel;
563     if (!dataParcel.WriteInterfaceToken(CallManagerServiceProxy::GetDescriptor())) {
564         TELEPHONY_LOGE("write descriptor fail");
565         return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
566     }
567     auto remote = Remote();
568     if (remote == nullptr) {
569         TELEPHONY_LOGE("function Remote() return nullptr!");
570         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
571     }
572     dataParcel.WriteInt32(slotId);
573     dataParcel.WriteRawData((const void *)&info, sizeof(CallRestrictionInfo));
574     int32_t error =
575         remote->SendRequest(CallManagerSurfaceCode::INTERFACE_SET_CALL_RESTRICTION, dataParcel, replyParcel, option);
576     if (error != TELEPHONY_SUCCESS) {
577         TELEPHONY_LOGE("Function SetCallRestriction! errCode:%{public}d", error);
578         return error;
579     }
580     return replyParcel.ReadInt32();
581 }
582 
GetCallTransferInfo(int32_t slotId,CallTransferType type)583 int32_t CallManagerServiceProxy::GetCallTransferInfo(int32_t slotId, CallTransferType type)
584 {
585     MessageOption option;
586     MessageParcel dataParcel;
587     MessageParcel replyParcel;
588     if (!dataParcel.WriteInterfaceToken(CallManagerServiceProxy::GetDescriptor())) {
589         TELEPHONY_LOGE("write descriptor fail");
590         return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
591     }
592     auto remote = Remote();
593     if (remote == nullptr) {
594         TELEPHONY_LOGE("function Remote() return nullptr!");
595         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
596     }
597     dataParcel.WriteInt32(slotId);
598     dataParcel.WriteInt32(static_cast<int32_t>(type));
599     int32_t error =
600         remote->SendRequest(CallManagerSurfaceCode::INTERFACE_GET_CALL_TRANSFER, dataParcel, replyParcel, option);
601     if (error != TELEPHONY_SUCCESS) {
602         TELEPHONY_LOGE("Function GetCallTransfer! errCode:%{public}d", error);
603         return error;
604     }
605     return replyParcel.ReadInt32();
606 }
607 
SetCallTransferInfo(int32_t slotId,CallTransferInfo & info)608 int32_t CallManagerServiceProxy::SetCallTransferInfo(int32_t slotId, CallTransferInfo &info)
609 {
610     MessageOption option;
611     MessageParcel dataParcel;
612     MessageParcel replyParcel;
613     if (!dataParcel.WriteInterfaceToken(CallManagerServiceProxy::GetDescriptor())) {
614         TELEPHONY_LOGE("write descriptor fail");
615         return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
616     }
617     auto remote = Remote();
618     if (remote == nullptr) {
619         TELEPHONY_LOGE("function Remote() return nullptr!");
620         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
621     }
622     dataParcel.WriteInt32(slotId);
623     dataParcel.WriteRawData((const void *)&info, sizeof(CallTransferInfo));
624     int32_t error =
625         remote->SendRequest(CallManagerSurfaceCode::INTERFACE_SET_CALL_TRANSFER, dataParcel, replyParcel, option);
626     if (error != TELEPHONY_SUCCESS) {
627         TELEPHONY_LOGE("Function SetCallTransfer! errCode:%{public}d", error);
628         return error;
629     }
630     return replyParcel.ReadInt32();
631 }
632 
SetCallPreferenceMode(int32_t slotId,int32_t mode)633 int32_t CallManagerServiceProxy::SetCallPreferenceMode(int32_t slotId, int32_t mode)
634 {
635     MessageOption option;
636     MessageParcel dataParcel;
637     MessageParcel replyParcel;
638     if (!dataParcel.WriteInterfaceToken(CallManagerServiceProxy::GetDescriptor())) {
639         TELEPHONY_LOGE("write descriptor fail");
640         return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
641     }
642     auto remote = Remote();
643     if (remote == nullptr) {
644         TELEPHONY_LOGE("function Remote() return nullptr!");
645         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
646     }
647     dataParcel.WriteInt32(slotId);
648     dataParcel.WriteInt32(mode);
649     int32_t error =
650         remote->SendRequest(CallManagerSurfaceCode::INTERFACE_SETCALL_PREFERENCEMODE, dataParcel, replyParcel, option);
651     if (error != TELEPHONY_SUCCESS) {
652         TELEPHONY_LOGE("Function SetCallPreferenceMode! errCode:%{public}d", error);
653         return error;
654     }
655     return replyParcel.ReadInt32();
656 }
657 
StartRtt(int32_t callId,std::u16string & msg)658 int32_t CallManagerServiceProxy::StartRtt(int32_t callId, std::u16string &msg)
659 {
660     MessageOption option;
661     MessageParcel dataParcel;
662     MessageParcel replyParcel;
663     if (!dataParcel.WriteInterfaceToken(CallManagerServiceProxy::GetDescriptor())) {
664         TELEPHONY_LOGE("write descriptor fail");
665         return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
666     }
667     if (msg.empty()) {
668         TELEPHONY_LOGE("msg is empty");
669         return TELEPHONY_ERR_ARGUMENT_INVALID;
670     }
671     auto remote = Remote();
672     if (remote == nullptr) {
673         TELEPHONY_LOGE("function Remote() return nullptr!");
674         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
675     }
676     dataParcel.WriteInt32(callId);
677     dataParcel.WriteString16(msg);
678     int32_t error = remote->SendRequest(CallManagerSurfaceCode::INTERFACE_START_RTT, dataParcel, replyParcel, option);
679     if (error != TELEPHONY_SUCCESS) {
680         TELEPHONY_LOGE("Function StartRtt errCode:%{public}d", error);
681         return error;
682     }
683     return replyParcel.ReadInt32();
684 }
685 
StopRtt(int32_t callId)686 int32_t CallManagerServiceProxy::StopRtt(int32_t callId)
687 {
688     MessageOption option;
689     MessageParcel dataParcel;
690     MessageParcel replyParcel;
691     if (!dataParcel.WriteInterfaceToken(CallManagerServiceProxy::GetDescriptor())) {
692         TELEPHONY_LOGE("write descriptor fail");
693         return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
694     }
695     auto remote = Remote();
696     if (remote == nullptr) {
697         TELEPHONY_LOGE("function Remote() return nullptr!");
698         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
699     }
700     dataParcel.WriteInt32(callId);
701     int32_t error = remote->SendRequest(CallManagerSurfaceCode::INTERFACE_STOP_RTT, dataParcel, replyParcel, option);
702     if (error != TELEPHONY_SUCCESS) {
703         TELEPHONY_LOGE("Function StopRtt errCode:%{public}d", error);
704         return error;
705     }
706     return replyParcel.ReadInt32();
707 }
708 
CombineConference(int32_t mainCallId)709 int32_t CallManagerServiceProxy::CombineConference(int32_t mainCallId)
710 {
711     MessageOption option;
712     MessageParcel dataParcel;
713     MessageParcel replyParcel;
714     if (!dataParcel.WriteInterfaceToken(CallManagerServiceProxy::GetDescriptor())) {
715         TELEPHONY_LOGE("write descriptor fail");
716         return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
717     }
718     auto remote = Remote();
719     if (remote == nullptr) {
720         TELEPHONY_LOGE("function Remote() return nullptr!");
721         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
722     }
723     dataParcel.WriteInt32(mainCallId);
724     int32_t error = remote->SendRequest(INTERFACE_COMBINE_CONFERENCE, dataParcel, replyParcel, option);
725     if (error != TELEPHONY_SUCCESS) {
726         TELEPHONY_LOGE("Function CombineConference failed! errCode:%{public}d", error);
727         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
728     }
729     return replyParcel.ReadInt32();
730 }
731 
SeparateConference(int32_t callId)732 int32_t CallManagerServiceProxy::SeparateConference(int32_t callId)
733 {
734     MessageOption option;
735     MessageParcel dataParcel;
736     MessageParcel replyParcel;
737     if (!dataParcel.WriteInterfaceToken(CallManagerServiceProxy::GetDescriptor())) {
738         TELEPHONY_LOGE("write descriptor fail");
739         return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
740     }
741     dataParcel.WriteInt32(callId);
742     auto remote = Remote();
743     if (remote == nullptr) {
744         TELEPHONY_LOGE("function Remote() return nullptr!");
745         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
746     }
747     int32_t error = remote->SendRequest(INTERFACE_SEPARATE_CONFERENCE, dataParcel, replyParcel, option);
748     if (error != TELEPHONY_SUCCESS) {
749         TELEPHONY_LOGE("Function SeparateConference call failed! errCode:%{public}d", error);
750         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
751     }
752     return replyParcel.ReadInt32();
753 }
754 
ControlCamera(std::u16string cameraId)755 int32_t CallManagerServiceProxy::ControlCamera(std::u16string cameraId)
756 {
757     MessageOption option;
758     MessageParcel dataParcel;
759     MessageParcel replyParcel;
760     if (!dataParcel.WriteInterfaceToken(CallManagerServiceProxy::GetDescriptor())) {
761         TELEPHONY_LOGE("write descriptor fail");
762         return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
763     }
764     dataParcel.WriteString16(cameraId);
765     auto remote = Remote();
766     if (remote == nullptr) {
767         TELEPHONY_LOGE("function Remote() return nullptr!");
768         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
769     }
770     int32_t error = remote->SendRequest(INTERFACE_CTRL_CAMERA, dataParcel, replyParcel, option);
771     if (error != TELEPHONY_SUCCESS) {
772         TELEPHONY_LOGE("Function CtrlCamera call failed! errCode:%{public}d", error);
773         return error;
774     }
775     return replyParcel.ReadInt32();
776 }
777 
SetPreviewWindow(VideoWindow & window)778 int32_t CallManagerServiceProxy::SetPreviewWindow(VideoWindow &window)
779 {
780     MessageOption option;
781     MessageParcel dataParcel;
782     MessageParcel replyParcel;
783     if (!dataParcel.WriteInterfaceToken(CallManagerServiceProxy::GetDescriptor())) {
784         TELEPHONY_LOGE("write descriptor fail");
785         return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
786     }
787     dataParcel.WriteRawData((const void *)&window, sizeof(VideoWindow));
788     auto remote = Remote();
789     if (remote == nullptr) {
790         TELEPHONY_LOGE("function Remote() return nullptr!");
791         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
792     }
793     int32_t error = remote->SendRequest(INTERFACE_SET_PREVIEW_WINDOW, dataParcel, replyParcel, option);
794     if (error != TELEPHONY_SUCCESS) {
795         TELEPHONY_LOGE("Function SetPreviewWindow call failed! errCode:%{public}d", error);
796         return error;
797     }
798     return replyParcel.ReadInt32();
799 }
800 
SetDisplayWindow(VideoWindow & window)801 int32_t CallManagerServiceProxy::SetDisplayWindow(VideoWindow &window)
802 {
803     MessageOption option;
804     MessageParcel dataParcel;
805     MessageParcel replyParcel;
806     if (!dataParcel.WriteInterfaceToken(CallManagerServiceProxy::GetDescriptor())) {
807         TELEPHONY_LOGE("write descriptor fail");
808         return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
809     }
810     dataParcel.WriteRawData((const void *)&window, sizeof(VideoWindow));
811     auto remote = Remote();
812     if (remote == nullptr) {
813         TELEPHONY_LOGE("function Remote() return nullptr!");
814         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
815     }
816     int32_t error = remote->SendRequest(INTERFACE_SET_DISPLAY_WINDOW, dataParcel, replyParcel, option);
817     if (error != TELEPHONY_SUCCESS) {
818         TELEPHONY_LOGE("Function SetDisplayWindow call failed! errCode:%{public}d", error);
819         return error;
820     }
821     return replyParcel.ReadInt32();
822 }
823 
SetCameraZoom(float zoomRatio)824 int32_t CallManagerServiceProxy::SetCameraZoom(float zoomRatio)
825 {
826     MessageOption option;
827     MessageParcel dataParcel;
828     MessageParcel replyParcel;
829     if (!dataParcel.WriteInterfaceToken(CallManagerServiceProxy::GetDescriptor())) {
830         TELEPHONY_LOGE("write descriptor fail");
831         return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
832     }
833     dataParcel.WriteFloat(zoomRatio);
834     auto remote = Remote();
835     if (remote == nullptr) {
836         TELEPHONY_LOGE("function Remote() return nullptr!");
837         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
838     }
839     int32_t error = remote->SendRequest(INTERFACE_SET_CAMERA_ZOOM, dataParcel, replyParcel, option);
840     if (error != TELEPHONY_SUCCESS) {
841         TELEPHONY_LOGE("Function SetCameraZoom call failed! errCode:%{public}d", error);
842         return error;
843     }
844     return replyParcel.ReadInt32();
845 }
846 
SetPausePicture(std::u16string path)847 int32_t CallManagerServiceProxy::SetPausePicture(std::u16string path)
848 {
849     MessageOption option;
850     MessageParcel dataParcel;
851     MessageParcel replyParcel;
852     if (!dataParcel.WriteInterfaceToken(CallManagerServiceProxy::GetDescriptor())) {
853         TELEPHONY_LOGE("write descriptor fail");
854         return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
855     }
856     if (path.empty()) {
857         TELEPHONY_LOGE("path is empty");
858         return TELEPHONY_ERR_ARGUMENT_INVALID;
859     }
860     dataParcel.WriteString16(path);
861     auto remote = Remote();
862     if (remote == nullptr) {
863         TELEPHONY_LOGE("function Remote() return nullptr!");
864         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
865     }
866     int32_t error = remote->SendRequest(INTERFACE_SET_PAUSE_IMAGE, dataParcel, replyParcel, option);
867     if (error != TELEPHONY_SUCCESS) {
868         TELEPHONY_LOGE("Function SetPausePicture call failed! errCode:%{public}d", error);
869         return error;
870     }
871     return replyParcel.ReadInt32();
872 }
873 
SetDeviceDirection(int32_t rotation)874 int32_t CallManagerServiceProxy::SetDeviceDirection(int32_t rotation)
875 {
876     MessageOption option;
877     MessageParcel dataParcel;
878     MessageParcel replyParcel;
879     if (!dataParcel.WriteInterfaceToken(CallManagerServiceProxy::GetDescriptor())) {
880         TELEPHONY_LOGE("write descriptor fail");
881         return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
882     }
883     dataParcel.WriteInt32(rotation);
884     auto remote = Remote();
885     if (remote == nullptr) {
886         TELEPHONY_LOGE("function Remote() return nullptr!");
887         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
888     }
889     int32_t error = remote->SendRequest(INTERFACE_SET_DEVICE_DIRECTION, dataParcel, replyParcel, option);
890     if (error != TELEPHONY_SUCCESS) {
891         TELEPHONY_LOGE("Function SetDeviceDirection call failed! errCode:%{public}d", error);
892         return error;
893     }
894     return replyParcel.ReadInt32();
895 }
896 
IsEmergencyPhoneNumber(std::u16string & number,int32_t slotId,bool & enabled)897 int32_t CallManagerServiceProxy::IsEmergencyPhoneNumber(std::u16string &number, int32_t slotId, bool &enabled)
898 {
899     MessageOption option;
900     MessageParcel dataParcel;
901     MessageParcel replyParcel;
902     if (!dataParcel.WriteInterfaceToken(CallManagerServiceProxy::GetDescriptor())) {
903         TELEPHONY_LOGE("write descriptor fail");
904         return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
905     }
906     if (number.empty()) {
907         TELEPHONY_LOGE("number is empty");
908         return TELEPHONY_ERR_ARGUMENT_INVALID;
909     }
910     dataParcel.WriteString16(number);
911     dataParcel.WriteInt32(slotId);
912     auto remote = Remote();
913     if (remote == nullptr) {
914         TELEPHONY_LOGE("function Remote() return nullptr!");
915         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
916     }
917     int32_t error = remote->SendRequest(INTERFACE_IS_EMERGENCY_NUMBER, dataParcel, replyParcel, option);
918     if (error != TELEPHONY_SUCCESS) {
919         TELEPHONY_LOGE("Function IsEmergencyPhoneNumber call failed! errCode:%{public}d", error);
920         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
921     }
922     int32_t result = replyParcel.ReadInt32();
923     if (result == TELEPHONY_SUCCESS) {
924         enabled = replyParcel.ReadBool();
925     }
926     return result;
927 }
928 
FormatPhoneNumber(std::u16string & number,std::u16string & countryCode,std::u16string & formatNumber)929 int32_t CallManagerServiceProxy::FormatPhoneNumber(
930     std::u16string &number, std::u16string &countryCode, std::u16string &formatNumber)
931 {
932     MessageOption option;
933     MessageParcel dataParcel;
934     MessageParcel replyParcel;
935     if (!dataParcel.WriteInterfaceToken(CallManagerServiceProxy::GetDescriptor())) {
936         TELEPHONY_LOGE("write descriptor fail");
937         return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
938     }
939     if (number.empty() || countryCode.empty()) {
940         TELEPHONY_LOGE("number or countryCode is empty");
941         return TELEPHONY_ERR_ARGUMENT_INVALID;
942     }
943     dataParcel.WriteString16(number);
944     dataParcel.WriteString16(countryCode);
945     auto remote = Remote();
946     if (remote == nullptr) {
947         TELEPHONY_LOGE("function Remote() return nullptr!");
948         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
949     }
950     int32_t error = remote->SendRequest(INTERFACE_IS_FORMAT_NUMBER, dataParcel, replyParcel, option);
951     if (error != TELEPHONY_SUCCESS) {
952         TELEPHONY_LOGE("Function FormatPhoneNumber call failed! errCode:%{public}d", error);
953         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
954     }
955     int32_t result = replyParcel.ReadInt32();
956     if (result == TELEPHONY_SUCCESS) {
957         formatNumber = replyParcel.ReadString16();
958     }
959     return result;
960 }
961 
FormatPhoneNumberToE164(std::u16string & number,std::u16string & countryCode,std::u16string & formatNumber)962 int32_t CallManagerServiceProxy::FormatPhoneNumberToE164(
963     std::u16string &number, std::u16string &countryCode, std::u16string &formatNumber)
964 {
965     MessageOption option;
966     MessageParcel dataParcel;
967     MessageParcel replyParcel;
968     if (!dataParcel.WriteInterfaceToken(CallManagerServiceProxy::GetDescriptor())) {
969         TELEPHONY_LOGE("write descriptor fail");
970         return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
971     }
972     if (number.empty() || countryCode.empty()) {
973         TELEPHONY_LOGE("number or countryCode is empty");
974         return TELEPHONY_ERR_ARGUMENT_INVALID;
975     }
976     dataParcel.WriteString16(number);
977     dataParcel.WriteString16(countryCode);
978     auto remote = Remote();
979     if (remote == nullptr) {
980         TELEPHONY_LOGE("function Remote() return nullptr!");
981         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
982     }
983     int32_t error = remote->SendRequest(INTERFACE_IS_FORMAT_NUMBER_E164, dataParcel, replyParcel, option);
984     if (error != TELEPHONY_SUCCESS) {
985         TELEPHONY_LOGE("Function FormatPhoneNumberToE164 call failed! errCode:%{public}d", error);
986         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
987     }
988     int32_t result = replyParcel.ReadInt32();
989     if (result == TELEPHONY_SUCCESS) {
990         formatNumber = replyParcel.ReadString16();
991     }
992     return result;
993 }
994 
GetMainCallId(int32_t callId,int32_t & mainCallId)995 int32_t CallManagerServiceProxy::GetMainCallId(int32_t callId, int32_t &mainCallId)
996 {
997     MessageOption option;
998     MessageParcel dataParcel;
999     MessageParcel replyParcel;
1000     if (!dataParcel.WriteInterfaceToken(CallManagerServiceProxy::GetDescriptor())) {
1001         TELEPHONY_LOGE("write descriptor fail");
1002         return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
1003     }
1004     dataParcel.WriteInt32(callId);
1005     auto remote = Remote();
1006     if (remote == nullptr) {
1007         TELEPHONY_LOGE("function Remote() return nullptr!");
1008         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
1009     }
1010     int32_t error = remote->SendRequest(INTERFACE_GET_MAINID, dataParcel, replyParcel, option);
1011     if (error != TELEPHONY_SUCCESS) {
1012         TELEPHONY_LOGE("Function StartConference call failed! errCode:%{public}d", error);
1013         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
1014     }
1015     int32_t result = replyParcel.ReadInt32();
1016     if (result == TELEPHONY_ERR_SUCCESS) {
1017         mainCallId = replyParcel.ReadInt32();
1018     }
1019     return result;
1020 }
1021 
GetSubCallIdList(int32_t callId,std::vector<std::u16string> & callIdList)1022 int32_t CallManagerServiceProxy::GetSubCallIdList(int32_t callId, std::vector<std::u16string> &callIdList)
1023 {
1024     MessageOption option;
1025     MessageParcel dataParcel;
1026     MessageParcel replyParcel;
1027     if (!dataParcel.WriteInterfaceToken(CallManagerServiceProxy::GetDescriptor())) {
1028         TELEPHONY_LOGE("write descriptor fail");
1029         return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
1030     }
1031     dataParcel.WriteInt32(callId);
1032     auto remote = Remote();
1033     if (remote == nullptr) {
1034         TELEPHONY_LOGE("function Remote() return nullptr!");
1035         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
1036     }
1037     int32_t error = remote->SendRequest(INTERFACE_GET_SUBCALL_LIST_ID, dataParcel, replyParcel, option);
1038     if (error != TELEPHONY_SUCCESS) {
1039         TELEPHONY_LOGE("Function GetSubCallIdList call failed! errCode:%{public}d", error);
1040         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
1041     }
1042     int32_t result = replyParcel.ReadInt32();
1043     if (result == TELEPHONY_ERR_SUCCESS) {
1044         replyParcel.ReadString16Vector(&callIdList);
1045     }
1046     return result;
1047 }
1048 
GetCallIdListForConference(int32_t callId,std::vector<std::u16string> & callIdList)1049 int32_t CallManagerServiceProxy::GetCallIdListForConference(int32_t callId, std::vector<std::u16string> &callIdList)
1050 {
1051     MessageOption option;
1052     MessageParcel dataParcel;
1053     MessageParcel replyParcel;
1054     if (!dataParcel.WriteInterfaceToken(CallManagerServiceProxy::GetDescriptor())) {
1055         TELEPHONY_LOGE("write descriptor fail");
1056         return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
1057     }
1058     dataParcel.WriteInt32(callId);
1059     auto remote = Remote();
1060     if (remote == nullptr) {
1061         TELEPHONY_LOGE("function Remote() return nullptr!");
1062         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
1063     }
1064     int32_t error = remote->SendRequest(INTERFACE_GET_CALL_LIST_ID_FOR_CONFERENCE, dataParcel, replyParcel, option);
1065     if (error != TELEPHONY_SUCCESS) {
1066         TELEPHONY_LOGE("Function GetCallIdListForConference call failed! errCode:%{public}d", error);
1067         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
1068     }
1069     int32_t result = replyParcel.ReadInt32();
1070     if (result == TELEPHONY_ERR_SUCCESS) {
1071         replyParcel.ReadString16Vector(&callIdList);
1072     }
1073     return result;
1074 }
1075 
GetImsConfig(int32_t slotId,ImsConfigItem item)1076 int32_t CallManagerServiceProxy::GetImsConfig(int32_t slotId, ImsConfigItem item)
1077 {
1078     MessageOption option;
1079     MessageParcel dataParcel;
1080     MessageParcel replyParcel;
1081     if (!dataParcel.WriteInterfaceToken(CallManagerServiceProxy::GetDescriptor())) {
1082         TELEPHONY_LOGE("write descriptor fail");
1083         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
1084     }
1085     dataParcel.WriteInt32(slotId);
1086     dataParcel.WriteInt32(item);
1087     auto remote = Remote();
1088     if (remote == nullptr) {
1089         TELEPHONY_LOGE("function Remote() return nullptr!");
1090         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
1091     }
1092     int32_t error = remote->SendRequest(INTERFACE_GET_IMS_CONFIG, dataParcel, replyParcel, option);
1093     if (error != TELEPHONY_SUCCESS) {
1094         TELEPHONY_LOGE("function GetImsConfig failed! errCode:%{public}d", error);
1095         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
1096     }
1097     return replyParcel.ReadInt32();
1098 }
1099 
SetImsConfig(int32_t slotId,ImsConfigItem item,std::u16string & value)1100 int32_t CallManagerServiceProxy::SetImsConfig(int32_t slotId, ImsConfigItem item, std::u16string &value)
1101 {
1102     MessageOption option;
1103     MessageParcel dataParcel;
1104     MessageParcel replyParcel;
1105     if (!dataParcel.WriteInterfaceToken(CallManagerServiceProxy::GetDescriptor())) {
1106         TELEPHONY_LOGE("write descriptor fail");
1107         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
1108     }
1109     dataParcel.WriteInt32(slotId);
1110     dataParcel.WriteInt32(item);
1111     dataParcel.WriteString16(value);
1112     auto remote = Remote();
1113     if (remote == nullptr) {
1114         TELEPHONY_LOGE("function Remote() return nullptr!");
1115         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
1116     }
1117     int32_t error = remote->SendRequest(INTERFACE_SET_IMS_CONFIG, dataParcel, replyParcel, option);
1118     if (error != TELEPHONY_SUCCESS) {
1119         TELEPHONY_LOGE("function SetImsConfig failed! errCode:%{public}d", error);
1120         return error;
1121     }
1122     return replyParcel.ReadInt32();
1123 }
1124 
GetImsFeatureValue(int32_t slotId,FeatureType type)1125 int32_t CallManagerServiceProxy::GetImsFeatureValue(int32_t slotId, FeatureType type)
1126 {
1127     MessageOption option;
1128     MessageParcel dataParcel;
1129     MessageParcel replyParcel;
1130     if (!dataParcel.WriteInterfaceToken(CallManagerServiceProxy::GetDescriptor())) {
1131         TELEPHONY_LOGE("write descriptor fail");
1132         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
1133     }
1134     dataParcel.WriteInt32(slotId);
1135     dataParcel.WriteInt32(type);
1136     auto remote = Remote();
1137     if (remote == nullptr) {
1138         TELEPHONY_LOGE("function Remote() return nullptr!");
1139         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
1140     }
1141     int32_t error = remote->SendRequest(INTERFACE_GET_IMS_FEATURE_VALUE, dataParcel, replyParcel, option);
1142     if (error != TELEPHONY_SUCCESS) {
1143         TELEPHONY_LOGE("function GetImsFeatureValue failed! errCode:%{public}d", error);
1144         return error;
1145     }
1146     return replyParcel.ReadInt32();
1147 }
1148 
SetImsFeatureValue(int32_t slotId,FeatureType type,int32_t value)1149 int32_t CallManagerServiceProxy::SetImsFeatureValue(int32_t slotId, FeatureType type, int32_t value)
1150 {
1151     MessageOption option;
1152     MessageParcel dataParcel;
1153     MessageParcel replyParcel;
1154     if (!dataParcel.WriteInterfaceToken(CallManagerServiceProxy::GetDescriptor())) {
1155         TELEPHONY_LOGE("write descriptor fail");
1156         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
1157     }
1158     dataParcel.WriteInt32(slotId);
1159     dataParcel.WriteInt32(type);
1160     dataParcel.WriteInt32(value);
1161     auto remote = Remote();
1162     if (remote == nullptr) {
1163         TELEPHONY_LOGE("function Remote() return nullptr!");
1164         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
1165     }
1166     int32_t error = remote->SendRequest(INTERFACE_SET_IMS_FEATURE_VALUE, dataParcel, replyParcel, option);
1167     if (error != TELEPHONY_SUCCESS) {
1168         TELEPHONY_LOGE("function SetImsFeatureValue failed! errCode:%{public}d", error);
1169         return error;
1170     }
1171     return replyParcel.ReadInt32();
1172 }
1173 
UpdateImsCallMode(int32_t callId,ImsCallMode mode)1174 int32_t CallManagerServiceProxy::UpdateImsCallMode(int32_t callId, ImsCallMode mode)
1175 {
1176     MessageOption option;
1177     MessageParcel dataParcel;
1178     MessageParcel replyParcel;
1179     if (!dataParcel.WriteInterfaceToken(CallManagerServiceProxy::GetDescriptor())) {
1180         TELEPHONY_LOGE("write descriptor fail");
1181         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
1182     }
1183     dataParcel.WriteInt32(callId);
1184     dataParcel.WriteUint32(mode);
1185     auto remote = Remote();
1186     if (remote == nullptr) {
1187         TELEPHONY_LOGE("function Remote() return nullptr!");
1188         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
1189     }
1190     int32_t error = remote->SendRequest(INTERFACE_UPDATE_CALL_MEDIA_MODE, dataParcel, replyParcel, option);
1191     if (error != TELEPHONY_SUCCESS) {
1192         TELEPHONY_LOGE("function UpdateImsCallMode failed! errCode:%{public}d", error);
1193         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
1194     }
1195     return replyParcel.ReadInt32();
1196 }
1197 
EnableImsSwitch(int32_t slotId)1198 int32_t CallManagerServiceProxy::EnableImsSwitch(int32_t slotId)
1199 {
1200     MessageOption option;
1201     MessageParcel dataParcel;
1202     MessageParcel replyParcel;
1203     if (!dataParcel.WriteInterfaceToken(CallManagerServiceProxy::GetDescriptor())) {
1204         TELEPHONY_LOGE("write descriptor fail");
1205         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
1206     }
1207     dataParcel.WriteInt32(slotId);
1208     auto remote = Remote();
1209     if (remote == nullptr) {
1210         TELEPHONY_LOGE("function Remote() return nullptr!");
1211         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
1212     }
1213     int32_t error = remote->SendRequest(INTERFACE_ENABLE_VOLTE, dataParcel, replyParcel, option);
1214     if (error != ERR_NONE) {
1215         TELEPHONY_LOGE("function EnableImsSwitch failed! errCode:%{public}d", error);
1216         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
1217     }
1218     return replyParcel.ReadInt32();
1219 }
1220 
DisableImsSwitch(int32_t slotId)1221 int32_t CallManagerServiceProxy::DisableImsSwitch(int32_t slotId)
1222 {
1223     MessageOption option;
1224     MessageParcel dataParcel;
1225     MessageParcel replyParcel;
1226     if (!dataParcel.WriteInterfaceToken(CallManagerServiceProxy::GetDescriptor())) {
1227         TELEPHONY_LOGE("write descriptor fail");
1228         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
1229     }
1230     dataParcel.WriteInt32(slotId);
1231     auto remote = Remote();
1232     if (remote == nullptr) {
1233         TELEPHONY_LOGE("function Remote() return nullptr!");
1234         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
1235     }
1236     int32_t error = remote->SendRequest(INTERFACE_DISABLE_VOLTE, dataParcel, replyParcel, option);
1237     if (error != ERR_NONE) {
1238         TELEPHONY_LOGE("function DisableImsSwitch failed! errCode:%{public}d", error);
1239         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
1240     }
1241     return replyParcel.ReadInt32();
1242 }
1243 
IsImsSwitchEnabled(int32_t slotId,bool & enabled)1244 int32_t CallManagerServiceProxy::IsImsSwitchEnabled(int32_t slotId, bool &enabled)
1245 {
1246     MessageParcel dataParcel;
1247     MessageParcel replyParcel;
1248     MessageOption option;
1249     if (!dataParcel.WriteInterfaceToken(CallManagerServiceProxy::GetDescriptor())) {
1250         TELEPHONY_LOGE("write descriptor fail");
1251         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
1252     }
1253     dataParcel.WriteInt32(slotId);
1254     auto remote = Remote();
1255     if (remote == nullptr) {
1256         TELEPHONY_LOGE("function Remote() return nullptr!");
1257         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
1258     }
1259     int32_t error = remote->SendRequest(INTERFACE_IS_VOLTE_ENABLED, dataParcel, replyParcel, option);
1260     if (error != ERR_NONE) {
1261         TELEPHONY_LOGE("function IsImsSwitchEnabled failed! errCode:%{public}d", error);
1262         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
1263     }
1264     enabled = replyParcel.ReadBool();
1265     return replyParcel.ReadInt32();
1266 }
1267 
JoinConference(int32_t callId,std::vector<std::u16string> & numberList)1268 int32_t CallManagerServiceProxy::JoinConference(int32_t callId, std::vector<std::u16string> &numberList)
1269 {
1270     MessageOption option;
1271     MessageParcel dataParcel;
1272     MessageParcel replyParcel;
1273     if (!dataParcel.WriteInterfaceToken(CallManagerServiceProxy::GetDescriptor())) {
1274         TELEPHONY_LOGE("write descriptor fail");
1275         return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
1276     }
1277     dataParcel.WriteInt32(callId);
1278     dataParcel.WriteString16Vector(numberList);
1279     auto remote = Remote();
1280     if (remote == nullptr) {
1281         TELEPHONY_LOGE("function Remote() return nullptr!");
1282         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
1283     }
1284     int32_t error = remote->SendRequest(INTERFACE_JOIN_CONFERENCE, dataParcel, replyParcel, option);
1285     if (error != TELEPHONY_SUCCESS) {
1286         TELEPHONY_LOGE("function JoinConference failed! errCode:%{public}d", error);
1287         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
1288     }
1289     return replyParcel.ReadInt32();
1290 }
1291 
ReportOttCallDetailsInfo(std::vector<OttCallDetailsInfo> & ottVec)1292 int32_t CallManagerServiceProxy::ReportOttCallDetailsInfo(std::vector<OttCallDetailsInfo> &ottVec)
1293 {
1294     MessageOption option;
1295     MessageParcel dataParcel;
1296     MessageParcel replyParcel;
1297     if (!dataParcel.WriteInterfaceToken(CallManagerServiceProxy::GetDescriptor())) {
1298         TELEPHONY_LOGE("write descriptor fail");
1299         return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
1300     }
1301     if (ottVec.empty()) {
1302         TELEPHONY_LOGE("ottVec is empty");
1303         return TELEPHONY_ERR_ARGUMENT_INVALID;
1304     }
1305     dataParcel.WriteInt32(ottVec.size());
1306     std::vector<OttCallDetailsInfo>::iterator it = ottVec.begin();
1307     for (; it != ottVec.end(); ++it) {
1308         dataParcel.WriteRawData((const void *)&(*it), sizeof(OttCallDetailsInfo));
1309     }
1310     auto remote = Remote();
1311     if (remote == nullptr) {
1312         TELEPHONY_LOGE("function Remote() return nullptr!");
1313         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
1314     }
1315     int32_t error = remote->SendRequest(INTERFACE_REPORT_OTT_CALL_DETAIL_INFO, dataParcel, replyParcel, option);
1316     if (error != TELEPHONY_SUCCESS) {
1317         TELEPHONY_LOGE("function ReportOttCallDetailsInfo failed! errCode:%{public}d", error);
1318         return error;
1319     }
1320     return replyParcel.ReadInt32();
1321 }
1322 
ReportOttCallEventInfo(OttCallEventInfo & eventInfo)1323 int32_t CallManagerServiceProxy::ReportOttCallEventInfo(OttCallEventInfo &eventInfo)
1324 {
1325     MessageOption option;
1326     MessageParcel dataParcel;
1327     MessageParcel replyParcel;
1328     if (!dataParcel.WriteInterfaceToken(CallManagerServiceProxy::GetDescriptor())) {
1329         TELEPHONY_LOGE("write descriptor fail");
1330         return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
1331     }
1332     dataParcel.WriteRawData((const void *)&eventInfo, sizeof(OttCallEventInfo));
1333     auto remote = Remote();
1334     if (remote == nullptr) {
1335         TELEPHONY_LOGE("function Remote() return nullptr!");
1336         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
1337     }
1338     int32_t error = remote->SendRequest(INTERFACE_REPORT_OTT_CALL_EVENT_INFO, dataParcel, replyParcel, option);
1339     if (error != TELEPHONY_SUCCESS) {
1340         TELEPHONY_LOGE("function ReportOttCallDetailsInfo failed! errCode:%{public}d", error);
1341         return error;
1342     }
1343     return replyParcel.ReadInt32();
1344 }
1345 
GetProxyObjectPtr(CallManagerProxyType proxyType)1346 sptr<IRemoteObject> CallManagerServiceProxy::GetProxyObjectPtr(CallManagerProxyType proxyType)
1347 {
1348     MessageOption option;
1349     MessageParcel dataParcel;
1350     MessageParcel replyParcel;
1351     if (!dataParcel.WriteInterfaceToken(CallManagerServiceProxy::GetDescriptor())) {
1352         TELEPHONY_LOGE("write descriptor fail");
1353         return nullptr;
1354     }
1355     dataParcel.WriteInt32(static_cast<int32_t>(proxyType));
1356     auto remote = Remote();
1357     if (remote == nullptr) {
1358         TELEPHONY_LOGE("function Remote() return nullptr!");
1359         return nullptr;
1360     }
1361     int32_t error = remote->SendRequest(INTERFACE_GET_PROXY_OBJECT_PTR, dataParcel, replyParcel, option);
1362     if (error != TELEPHONY_SUCCESS) {
1363         TELEPHONY_LOGE("function GetProxyObjectPtr failed! errCode:%{public}d", error);
1364         return nullptr;
1365     }
1366     return replyParcel.ReadRemoteObject();
1367 }
1368 } // namespace Telephony
1369 } // namespace OHOS
1370