• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2025 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 "voip_call_manager_proxy.h"
17 
18 #include "message_option.h"
19 #include "message_parcel.h"
20 #include "telephony_errors.h"
21 #include "telephony_log_wrapper.h"
22 #include "native_call_manager_hisysevent.h"
23 #include "hitrace/tracechain.h"
24 
25 namespace OHOS {
26 namespace Telephony {
VoipCallManagerProxy(const sptr<IRemoteObject> & impl)27 VoipCallManagerProxy::VoipCallManagerProxy(const sptr<IRemoteObject> &impl)
28     : IRemoteProxy<IVoipCallManagerService>(impl)
29 {}
30 
ReportIncomingCall(AppExecFwk::PacMap & extras,std::vector<uint8_t> & userProfile,ErrorReason & reason)31 int32_t VoipCallManagerProxy::ReportIncomingCall(
32     AppExecFwk::PacMap &extras, std::vector<uint8_t> &userProfile, ErrorReason &reason)
33 {
34     OHOS::HiviewDFX::HiTraceId chainId = OHOS::HiviewDFX::HiTraceChain::GetId();
35     if (!chainId.IsValid()) {
36         chainId = OHOS::HiviewDFX::HiTraceChain::Begin("ReportIncomingCall", HiTraceFlag::HITRACE_FLAG_INCLUDE_ASYNC);
37     }
38     MessageParcel dataParcel;
39     if (!dataParcel.WriteInterfaceToken(VoipCallManagerProxy::GetDescriptor())) {
40         TELEPHONY_LOGE("write descriptor fail");
41         return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
42     }
43     dataParcel.WriteString(extras.GetStringValue("callId"));
44     dataParcel.WriteInt32(extras.GetIntValue("voipCallType"));
45     dataParcel.WriteString(extras.GetStringValue("userName"));
46     dataParcel.WriteString(extras.GetStringValue("abilityName"));
47     dataParcel.WriteInt32(extras.GetIntValue("voipCallState"));
48     dataParcel.WriteBool(extras.GetBooleanValue("showBannerForIncomingCall"));
49     dataParcel.WriteBool(extras.GetBooleanValue("isConferenceCall"));
50     dataParcel.WriteBool(extras.GetBooleanValue("isVoiceAnswerSupported"));
51     dataParcel.WriteInt64(extras.GetLongValue("startReportTime"));
52     if (!dataParcel.WriteUInt8Vector(userProfile)) {
53         TELEPHONY_LOGE("ReportIncomingCall userProfile write fail, size:%{public}u",
54             static_cast<uint32_t>(userProfile.size()));
55     }
56     auto remote = Remote();
57     if (remote == nullptr) {
58         TELEPHONY_LOGE("ReportIncomingCall Remote is null");
59         NativeCallManagerHisysevent::WriteVoipCallEvent(extras.GetStringValue("callId"), "",
60             static_cast<int32_t>(Scenario::VOIP_PROXY_IPC_CONNECTTING), TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL,
61             "remote is nullptr!", extras.GetIntValue("voipCallType"),
62             static_cast<int32_t>(VoipCallState::VOIP_CALL_STATE_INCOMING),
63             static_cast<int32_t>(CallDirection::CALL_DIRECTION_IN));
64         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
65     }
66     MessageOption option;
67     MessageParcel replyParcel;
68     int32_t error =
69         remote->SendRequest(static_cast<int32_t>(INTERFACE_REPORT_INCOMING_CALL), dataParcel, replyParcel, option);
70     if (error != TELEPHONY_SUCCESS) {
71         TELEPHONY_LOGE("function ReportIncomingCall call failed! errCode:%{public}d", error);
72         NativeCallManagerHisysevent::WriteVoipCallEvent(extras.GetStringValue("callId"), "",
73             static_cast<int32_t>(Scenario::VOIP_PROXY_IPC_CONNECTTING), error,
74             "IncomingCall call failed!", extras.GetIntValue("voipCallType"),
75             static_cast<int32_t>(VoipCallState::VOIP_CALL_STATE_INCOMING),
76             static_cast<int32_t>(CallDirection::CALL_DIRECTION_IN));
77         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
78     }
79     int32_t result = replyParcel.ReadInt32();
80     reason = static_cast<ErrorReason>(replyParcel.ReadInt32());
81     return result;
82 }
83 
ReportIncomingCallError(AppExecFwk::PacMap & extras)84 int32_t VoipCallManagerProxy::ReportIncomingCallError(AppExecFwk::PacMap &extras)
85 {
86     OHOS::HiviewDFX::HiTraceId chainId = OHOS::HiviewDFX::HiTraceChain::GetId();
87     if (!chainId.IsValid()) {
88         chainId = OHOS::HiviewDFX::HiTraceChain::Begin("ReportIncomingCallError",
89             HiTraceFlag::HITRACE_FLAG_INCLUDE_ASYNC);
90     }
91     MessageParcel dataParcel;
92     if (!dataParcel.WriteInterfaceToken(VoipCallManagerProxy::GetDescriptor())) {
93         TELEPHONY_LOGE("write descriptor fail");
94         return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
95     }
96     dataParcel.WriteString(extras.GetStringValue("callId"));
97     dataParcel.WriteInt32(extras.GetIntValue("reportVoipCallFailedCause"));
98     dataParcel.WriteInt64(extras.GetLongValue("startReportTime"));
99     auto remote = Remote();
100     if (remote == nullptr) {
101         TELEPHONY_LOGE("ReportIncomingCallError Remote is null");
102         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
103     }
104     MessageOption option;
105     MessageParcel replyParcel;
106     int32_t error = remote->SendRequest(
107         static_cast<int32_t>(INTERFACE_REPORT_INCOMING_CALL_ERROR), dataParcel, replyParcel, option);
108     if (error != TELEPHONY_SUCCESS) {
109         TELEPHONY_LOGE("function ReportIncomingCallError call failed! errCode:%{public}d", error);
110         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
111     }
112     return replyParcel.ReadInt32();
113 }
114 
ReportCallStateChange(std::string callId,const VoipCallState & state,const VoipCallType & type)115 int32_t VoipCallManagerProxy::ReportCallStateChange(
116     std::string callId, const VoipCallState &state, const VoipCallType &type)
117 {
118     MessageParcel dataParcel;
119     if (!dataParcel.WriteInterfaceToken(VoipCallManagerProxy::GetDescriptor())) {
120         TELEPHONY_LOGE("write descriptor fail");
121         return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
122     }
123     dataParcel.WriteString(callId);
124     dataParcel.WriteInt32(static_cast<int32_t>(state));
125     dataParcel.WriteInt32(static_cast<int32_t>(type));
126     auto remote = Remote();
127     if (remote == nullptr) {
128         TELEPHONY_LOGE("ReportCallStateChange Remote is null");
129         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
130     }
131     MessageOption option;
132     MessageParcel replyParcel;
133     int32_t error =
134         remote->SendRequest(static_cast<int32_t>(INTERFACE_REPORT_CALL_STATE_CHANGE), dataParcel, replyParcel, option);
135     if (error != TELEPHONY_SUCCESS) {
136         TELEPHONY_LOGE("function ReportCallStateChange call failed! errCode:%{public}d", error);
137         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
138     }
139     return replyParcel.ReadInt32();
140 }
141 
ReportOutgoingCall(AppExecFwk::PacMap & extras,std::vector<uint8_t> & userProfile,ErrorReason & reason)142 int32_t VoipCallManagerProxy::ReportOutgoingCall(
143     AppExecFwk::PacMap &extras, std::vector<uint8_t> &userProfile, ErrorReason &reason)
144 {
145     MessageParcel dataParcel;
146     if (!dataParcel.WriteInterfaceToken(VoipCallManagerProxy::GetDescriptor())) {
147         TELEPHONY_LOGE("write descriptor fail");
148         return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
149     }
150     dataParcel.WriteString(extras.GetStringValue("callId"));
151     dataParcel.WriteInt32(extras.GetIntValue("voipCallType"));
152     dataParcel.WriteString(extras.GetStringValue("userName"));
153     dataParcel.WriteString(extras.GetStringValue("abilityName"));
154     dataParcel.WriteInt32(extras.GetIntValue("voipCallState"));
155     dataParcel.WriteBool(extras.GetBooleanValue("showBannerForIncomingCall"));
156     dataParcel.WriteBool(extras.GetBooleanValue("isConferenceCall"));
157     dataParcel.WriteBool(extras.GetBooleanValue("isVoiceAnswerSupported"));
158     if (!dataParcel.WriteUInt8Vector(userProfile)) {
159         TELEPHONY_LOGE("ReportOutgoingCall userProfile write fail, size:%{public}u",
160             static_cast<uint32_t>(userProfile.size()));
161     }
162     auto remote = Remote();
163     if (remote == nullptr) {
164         TELEPHONY_LOGE("ReportOutgoingCall Remote is null");
165         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
166     }
167     MessageOption option;
168     MessageParcel replyParcel;
169     int32_t error =
170         remote->SendRequest(static_cast<int32_t>(INTERFACE_REPORT_OUTGOING_CALL), dataParcel, replyParcel, option);
171     if (error != TELEPHONY_SUCCESS) {
172         TELEPHONY_LOGE("function ReportOutgoingCall call failed! errCode:%{public}d", error);
173         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
174     }
175     int32_t result = replyParcel.ReadInt32();
176     reason = static_cast<ErrorReason>(replyParcel.ReadInt32());
177     return result;
178 }
179 
RegisterCallBack(const sptr<IVoipCallManagerCallback> & callback)180 int32_t VoipCallManagerProxy::RegisterCallBack(const sptr<IVoipCallManagerCallback> &callback)
181 {
182     MessageParcel dataParcel;
183     if (!dataParcel.WriteInterfaceToken(VoipCallManagerProxy::GetDescriptor())) {
184         TELEPHONY_LOGE("write descriptor fail");
185         return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
186     }
187     dataParcel.WriteRemoteObject(callback->AsObject().GetRefPtr());
188     auto remote = Remote();
189     if (remote == nullptr) {
190         TELEPHONY_LOGE("RegisterCallBack Remote is null");
191         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
192     }
193     MessageOption option;
194     MessageParcel replyParcel;
195     int32_t error =
196         remote->SendRequest(static_cast<int32_t>(INTERFACE_REGISTER_CALLBACK), dataParcel, replyParcel, option);
197     if (error != TELEPHONY_SUCCESS) {
198         TELEPHONY_LOGE("function RegisterCallBack call failed! errCode:%{public}d", error);
199         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
200     }
201     return replyParcel.ReadInt32();
202 }
203 
UnRegisterCallBack()204 int32_t VoipCallManagerProxy::UnRegisterCallBack()
205 {
206     MessageParcel dataParcel;
207     if (!dataParcel.WriteInterfaceToken(VoipCallManagerProxy::GetDescriptor())) {
208         TELEPHONY_LOGE("write descriptor fail");
209         return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
210     }
211     auto remote = Remote();
212     if (remote == nullptr) {
213         TELEPHONY_LOGE("UnRegisterCallBack Remote is null");
214         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
215     }
216     MessageOption option;
217     MessageParcel replyParcel;
218     int32_t error =
219         remote->SendRequest(static_cast<int32_t>(INTERFACE_UN_REGISTER_CALLBACK), dataParcel, replyParcel, option);
220     if (error != TELEPHONY_SUCCESS) {
221         TELEPHONY_LOGE("function UnRegisterCallBack call failed! errCode:%{public}d", error);
222         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
223     }
224     return replyParcel.ReadInt32();
225 }
226 
ReportVoipIncomingCall(std::string callId,std::string bundleName,std::string processMode,int32_t uid)227 int32_t VoipCallManagerProxy::ReportVoipIncomingCall(
228     std::string callId, std::string bundleName, std::string processMode, int32_t uid)
229 {
230     MessageParcel dataParcel;
231     if (!dataParcel.WriteInterfaceToken(VoipCallManagerProxy::GetDescriptor())) {
232         TELEPHONY_LOGE("write descriptor fail");
233         return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
234     }
235     dataParcel.WriteString(callId);
236     dataParcel.WriteString(bundleName);
237     dataParcel.WriteString(processMode);
238     dataParcel.WriteInt32(uid);
239     auto remote = Remote();
240     if (remote == nullptr) {
241         TELEPHONY_LOGE("ReportVoipIncomingCall Remote is null");
242         NativeCallManagerHisysevent::WriteVoipCallEvent(callId, bundleName,
243             static_cast<int32_t>(Scenario::VOIP_PROXY_IPC_CONNECTTING), TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL,
244             "voip remote is nullptr!", static_cast<int32_t>(VoipCallType::VOIP_CALL_VOICE),
245             static_cast<int32_t>(VoipCallState::VOIP_CALL_STATE_INCOMING),
246             static_cast<int32_t>(CallDirection::CALL_DIRECTION_IN));
247         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
248     }
249     MessageOption option;
250     MessageParcel replyParcel;
251     int32_t error =
252         remote->SendRequest(static_cast<int32_t>(INTERFACE_REPORT_VOIP_INCOMING_CALL), dataParcel, replyParcel, option);
253     if (error != TELEPHONY_SUCCESS) {
254         TELEPHONY_LOGE("function ReportVoipIncomingCall call failed! errCode:%{public}d", error);
255         NativeCallManagerHisysevent::WriteVoipCallEvent(callId, bundleName,
256             static_cast<int32_t>(Scenario::VOIP_PROXY_IPC_CONNECTTING), error,
257             "voipIncomingCall call failed!", static_cast<int32_t>(VoipCallType::VOIP_CALL_VOICE),
258             static_cast<int32_t>(VoipCallState::VOIP_CALL_STATE_INCOMING),
259             static_cast<int32_t>(CallDirection::CALL_DIRECTION_IN));
260         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
261     }
262     return replyParcel.ReadInt32();
263 }
264 
ReportVoipCallExtensionId(std::string callId,std::string bundleName,std::string extensionId,int32_t uid)265 int32_t VoipCallManagerProxy::ReportVoipCallExtensionId(
266     std::string callId, std::string bundleName, std::string extensionId, int32_t uid)
267 {
268     MessageParcel dataParcel;
269     if (!dataParcel.WriteInterfaceToken(VoipCallManagerProxy::GetDescriptor())) {
270         TELEPHONY_LOGE("write descriptor fail");
271         return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
272     }
273     dataParcel.WriteString(callId);
274     dataParcel.WriteString(bundleName);
275     dataParcel.WriteString(extensionId);
276     dataParcel.WriteInt32(uid);
277     auto remote = Remote();
278     if (remote == nullptr) {
279         TELEPHONY_LOGE("ReportVoipCallExtensionId Remote is null");
280         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
281     }
282     MessageOption option;
283     MessageParcel replyParcel;
284     int32_t error = remote->SendRequest(
285         static_cast<int32_t>(INTERFACE_REPORT_VOIP_CALL_EXTENSIONID), dataParcel, replyParcel, option);
286     if (error != TELEPHONY_SUCCESS) {
287         TELEPHONY_LOGE("function ReportVoipCallExtensionId call failed! errCode:%{public}d", error);
288         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
289     }
290     return replyParcel.ReadInt32();
291 }
292 
Answer(const VoipCallEventInfo & events,int32_t videoState)293 int32_t VoipCallManagerProxy::Answer(const VoipCallEventInfo &events, int32_t videoState)
294 {
295     MessageParcel dataParcel;
296     if (!dataParcel.WriteInterfaceToken(VoipCallManagerProxy::GetDescriptor())) {
297         TELEPHONY_LOGE("write descriptor fail");
298         return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
299     }
300     dataParcel.WriteString(events.voipCallId);
301     dataParcel.WriteString(events.bundleName);
302     dataParcel.WriteInt32(events.uid);
303     dataParcel.WriteInt32(videoState);
304     auto remote = Remote();
305     if (remote == nullptr) {
306         TELEPHONY_LOGE("Answer voip Remote is null");
307         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
308     }
309     MessageOption option;
310     MessageParcel replyParcel;
311     int32_t error = remote->SendRequest(
312         static_cast<int32_t>(INTERFACE_ANSWER_VOIP_CALL), dataParcel, replyParcel, option);
313     if (error != TELEPHONY_SUCCESS) {
314         TELEPHONY_LOGE("function Answer voip call failed! errCode:%{public}d", error);
315         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
316     }
317     return replyParcel.ReadInt32();
318 }
319 
HangUp(const VoipCallEventInfo & events)320 int32_t VoipCallManagerProxy::HangUp(const VoipCallEventInfo &events)
321 {
322     MessageParcel dataParcel;
323     if (!dataParcel.WriteInterfaceToken(VoipCallManagerProxy::GetDescriptor())) {
324         TELEPHONY_LOGE("write descriptor fail");
325         return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
326     }
327     dataParcel.WriteString(events.voipCallId);
328     dataParcel.WriteString(events.bundleName);
329     dataParcel.WriteInt32(events.uid);
330     dataParcel.WriteInt32(static_cast<int32_t>(events.errorReason));
331     auto remote = Remote();
332     if (remote == nullptr) {
333         TELEPHONY_LOGE("HangUp voip Remote is null");
334         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
335     }
336     MessageOption option;
337     MessageParcel replyParcel;
338     int32_t error = remote->SendRequest(
339         static_cast<int32_t>(INTERFACE_HANGUP_VOIP_CALL), dataParcel, replyParcel, option);
340     if (error != TELEPHONY_SUCCESS) {
341         TELEPHONY_LOGE("function HangUp voip call failed! errCode:%{public}d", error);
342         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
343     }
344     return replyParcel.ReadInt32();
345 }
346 
Reject(const VoipCallEventInfo & events)347 int32_t VoipCallManagerProxy::Reject(const VoipCallEventInfo &events)
348 {
349     MessageParcel dataParcel;
350     if (!dataParcel.WriteInterfaceToken(VoipCallManagerProxy::GetDescriptor())) {
351         TELEPHONY_LOGE("write descriptor fail");
352         return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
353     }
354     dataParcel.WriteString(events.voipCallId);
355     dataParcel.WriteString(events.bundleName);
356     dataParcel.WriteInt32(events.uid);
357     auto remote = Remote();
358     if (remote == nullptr) {
359         TELEPHONY_LOGE("Reject voip  Remote is null");
360         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
361     }
362     MessageOption option;
363     MessageParcel replyParcel;
364     int32_t error = remote->SendRequest(
365         static_cast<int32_t>(INTERFACE_REJECT_VOIP_CALL), dataParcel, replyParcel, option);
366     if (error != TELEPHONY_SUCCESS) {
367         TELEPHONY_LOGE("function Reject voip call failed! errCode:%{public}d", error);
368         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
369     }
370     return replyParcel.ReadInt32();
371 }
372 
RegisterCallManagerCallBack(const sptr<ICallStatusCallback> & callback)373 int32_t VoipCallManagerProxy::RegisterCallManagerCallBack(const sptr<ICallStatusCallback> &callback)
374 {
375     if (callback == nullptr) {
376         return TELEPHONY_ERR_ARGUMENT_INVALID;
377     }
378 
379     MessageParcel dataParcel;
380     if (!dataParcel.WriteInterfaceToken(VoipCallManagerProxy::GetDescriptor())) {
381         TELEPHONY_LOGE("write descriptor fail");
382         return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
383     }
384 
385     dataParcel.WriteRemoteObject(callback->AsObject().GetRefPtr());
386     auto remote = Remote();
387     if (remote == nullptr) {
388         TELEPHONY_LOGE("RegisterCallManagerCallBack Remote is null");
389         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
390     }
391     MessageOption option;
392     MessageParcel replyParcel;
393     int32_t error = remote->SendRequest(
394         static_cast<int32_t>(INTERFACE_REGISTER_CALL_MANAGER_CALLBACK), dataParcel, replyParcel, option);
395     if (error != TELEPHONY_SUCCESS) {
396         TELEPHONY_LOGE("function RegisterCallManagerCallBack call failed! errCode:%{public}d", error);
397         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
398     }
399     return replyParcel.ReadInt32();
400 }
401 
UnRegisterCallManagerCallBack()402 int32_t VoipCallManagerProxy::UnRegisterCallManagerCallBack()
403 {
404     MessageParcel dataParcel;
405     if (!dataParcel.WriteInterfaceToken(VoipCallManagerProxy::GetDescriptor())) {
406         TELEPHONY_LOGE("write descriptor fail");
407         return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
408     }
409     auto remote = Remote();
410     if (remote == nullptr) {
411         TELEPHONY_LOGE("UnRegisterCallManagerCallBack Remote is null");
412         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
413     }
414     MessageOption option;
415     MessageParcel replyParcel;
416     int32_t error = remote->SendRequest(
417         static_cast<int32_t>(INTERFACE_UNREGISTER_CALL_MANAGER_CALLBACK), dataParcel, replyParcel, option);
418     if (error != TELEPHONY_SUCCESS) {
419         TELEPHONY_LOGE("function UnRegisterCallManagerCallBack call failed! errCode:%{public}d", error);
420         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
421     }
422     return replyParcel.ReadInt32();
423 }
424 
UnloadVoipSa()425 int32_t VoipCallManagerProxy::UnloadVoipSa()
426 {
427     MessageParcel dataParcel;
428     if (!dataParcel.WriteInterfaceToken(VoipCallManagerProxy::GetDescriptor())) {
429         TELEPHONY_LOGE("write descriptor fail");
430         return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
431     }
432     auto remote = Remote();
433     if (remote == nullptr) {
434         TELEPHONY_LOGE("UnloadVoipSa Remote is null");
435         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
436     }
437 
438     MessageOption option;
439     MessageParcel replyParcel;
440     int32_t error =
441         remote->SendRequest(static_cast<int32_t>(INTERFACE_UNLOAD_VOIP_SA), dataParcel, replyParcel, option);
442     if (error != TELEPHONY_SUCCESS) {
443         TELEPHONY_LOGE("function UnloadVoipSa failed! errCode:%{public}d", error);
444         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
445     }
446     return replyParcel.ReadInt32();
447 }
448 
SendCallUiEvent(std::string voipCallId,const CallAudioEvent & callAudioEvent)449 int32_t VoipCallManagerProxy::SendCallUiEvent(std::string voipCallId, const CallAudioEvent &callAudioEvent)
450 {
451     MessageParcel dataParcel;
452     if (!dataParcel.WriteInterfaceToken(VoipCallManagerProxy::GetDescriptor())) {
453         TELEPHONY_LOGE("write descriptor fail");
454         return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
455     }
456     dataParcel.WriteString(voipCallId);
457     dataParcel.WriteInt32(static_cast<int32_t>(callAudioEvent));
458     auto remote = Remote();
459     if (remote == nullptr) {
460         TELEPHONY_LOGE("SendCallUiEvent Remote is null");
461         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
462     }
463     MessageOption option;
464     MessageParcel replyParcel;
465     int32_t error =
466         remote->SendRequest(static_cast<int32_t>(INTERFACE_SEND_CALL_UI_EVENT), dataParcel, replyParcel, option);
467     if (error != TELEPHONY_SUCCESS) {
468         TELEPHONY_LOGE("function SendCallUiEvent call failed! errCode:%{public}d", error);
469         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
470     }
471     return replyParcel.ReadInt32();
472 }
473 
ReportCallAudioEventChange(std::string voipCallId,const CallAudioEvent & callAudioEvent)474 int32_t VoipCallManagerProxy::ReportCallAudioEventChange(std::string voipCallId, const CallAudioEvent &callAudioEvent)
475 {
476     MessageParcel dataParcel;
477     if (!dataParcel.WriteInterfaceToken(VoipCallManagerProxy::GetDescriptor())) {
478         TELEPHONY_LOGE("write descriptor fail");
479         return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
480     }
481     dataParcel.WriteString(voipCallId);
482     dataParcel.WriteInt32(static_cast<int32_t>(callAudioEvent));
483     auto remote = Remote();
484     if (remote == nullptr) {
485         TELEPHONY_LOGE("ReportCallAudioEventChange Remote is null");
486         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
487     }
488     MessageOption option;
489     MessageParcel replyParcel;
490     int32_t error = remote->SendRequest(
491         static_cast<int32_t>(INTERFACE_REPORT_CALL_AUDIO_EVENT_CHANGE), dataParcel, replyParcel, option);
492     if (error != TELEPHONY_SUCCESS) {
493         TELEPHONY_LOGE("function ReportCallAudioEventChange call failed! errCode:%{public}d", error);
494         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
495     }
496     return replyParcel.ReadInt32();
497 }
498 
SendCallUiEventForWindow(AppExecFwk::PacMap & extras)499 int32_t VoipCallManagerProxy::SendCallUiEventForWindow(AppExecFwk::PacMap &extras)
500 {
501     MessageParcel dataParcel;
502     if (!dataParcel.WriteInterfaceToken(VoipCallManagerProxy::GetDescriptor())) {
503         TELEPHONY_LOGE("write descriptor fail");
504         return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
505     }
506     dataParcel.WriteString(extras.GetStringValue("callId"));
507     dataParcel.WriteString(extras.GetStringValue("eventName"));
508     dataParcel.WriteInt64(extras.GetLongValue("publishTime"));
509 
510     auto remote = Remote();
511     if (remote == nullptr) {
512         TELEPHONY_LOGE("SendCallUiEventForWindow Remote is null");
513         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
514     }
515     MessageOption option;
516     MessageParcel replyParcel;
517     int32_t error = remote->SendRequest(static_cast<int32_t>(INTERFACE_SEND_CALL_UI_EVENT_FOR_WINDOW),
518         dataParcel, replyParcel, option);
519     if (error != TELEPHONY_SUCCESS) {
520         TELEPHONY_LOGE("function SendCallUiEventForWindow call failed! errCode:%{public}d", error);
521         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
522     }
523     return replyParcel.ReadInt32();
524 }
525 } // namespace Telephony
526 } // namespace OHOS
527