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 "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
23 namespace OHOS {
24 namespace Telephony {
VoipCallManagerProxy(const sptr<IRemoteObject> & impl)25 VoipCallManagerProxy::VoipCallManagerProxy(const sptr<IRemoteObject> &impl)
26 : IRemoteProxy<IVoipCallManagerService>(impl)
27 {}
28
ReportIncomingCall(AppExecFwk::PacMap & extras,std::vector<uint8_t> & userProfile,ErrorReason & reason)29 int32_t VoipCallManagerProxy::ReportIncomingCall(
30 AppExecFwk::PacMap &extras, std::vector<uint8_t> &userProfile, ErrorReason &reason)
31 {
32 MessageParcel dataParcel;
33 if (!dataParcel.WriteInterfaceToken(VoipCallManagerProxy::GetDescriptor())) {
34 TELEPHONY_LOGE("write descriptor fail");
35 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
36 }
37 dataParcel.WriteString(extras.GetStringValue("callId"));
38 dataParcel.WriteInt32(extras.GetIntValue("voipCallType"));
39 dataParcel.WriteString(extras.GetStringValue("userName"));
40 dataParcel.WriteString(extras.GetStringValue("abilityName"));
41 dataParcel.WriteInt32(extras.GetIntValue("voipCallState"));
42 dataParcel.WriteUInt8Vector(userProfile);
43 auto remote = Remote();
44 if (remote == nullptr) {
45 TELEPHONY_LOGE("ReportIncomingCall Remote is null");
46 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
47 }
48 MessageOption option;
49 MessageParcel replyParcel;
50 int32_t error =
51 remote->SendRequest(static_cast<int32_t>(INTERFACE_REPORT_INCOMING_CALL), dataParcel, replyParcel, option);
52 if (error != TELEPHONY_SUCCESS) {
53 TELEPHONY_LOGE("function ReportIncomingCall call failed! errCode:%{public}d", error);
54 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
55 }
56 int32_t result = replyParcel.ReadInt32();
57 reason = static_cast<ErrorReason>(replyParcel.ReadInt32());
58 return result;
59 }
60
ReportIncomingCallError(AppExecFwk::PacMap & extras)61 int32_t VoipCallManagerProxy::ReportIncomingCallError(AppExecFwk::PacMap &extras)
62 {
63 MessageParcel dataParcel;
64 if (!dataParcel.WriteInterfaceToken(VoipCallManagerProxy::GetDescriptor())) {
65 TELEPHONY_LOGE("write descriptor fail");
66 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
67 }
68 dataParcel.WriteString(extras.GetStringValue("callId"));
69 dataParcel.WriteInt32(extras.GetIntValue("reportVoipCallFailedCause"));
70 auto remote = Remote();
71 if (remote == nullptr) {
72 TELEPHONY_LOGE("ReportIncomingCallError Remote is null");
73 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
74 }
75 MessageOption option;
76 MessageParcel replyParcel;
77 int32_t error = remote->SendRequest(
78 static_cast<int32_t>(INTERFACE_REPORT_INCOMING_CALL_ERROR), dataParcel, replyParcel, option);
79 if (error != TELEPHONY_SUCCESS) {
80 TELEPHONY_LOGE("function ReportIncomingCallError call failed! errCode:%{public}d", error);
81 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
82 }
83 return replyParcel.ReadInt32();
84 }
85
ReportCallStateChange(std::string & callId,const VoipCallState & state)86 int32_t VoipCallManagerProxy::ReportCallStateChange(std::string &callId, const VoipCallState &state)
87 {
88 MessageParcel dataParcel;
89 if (!dataParcel.WriteInterfaceToken(VoipCallManagerProxy::GetDescriptor())) {
90 TELEPHONY_LOGE("write descriptor fail");
91 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
92 }
93 dataParcel.WriteString(callId);
94 dataParcel.WriteInt32(static_cast<int32_t>(state));
95 auto remote = Remote();
96 if (remote == nullptr) {
97 TELEPHONY_LOGE("ReportCallStateChange Remote is null");
98 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
99 }
100 MessageOption option;
101 MessageParcel replyParcel;
102 int32_t error =
103 remote->SendRequest(static_cast<int32_t>(INTERFACE_REPORT_CALL_STATE_CHANGE), dataParcel, replyParcel, option);
104 if (error != TELEPHONY_SUCCESS) {
105 TELEPHONY_LOGE("function ReportCallStateChange call failed! errCode:%{public}d", error);
106 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
107 }
108 return replyParcel.ReadInt32();
109 }
110
RegisterCallBack(const sptr<IVoipCallManagerCallback> & callback)111 int32_t VoipCallManagerProxy::RegisterCallBack(const sptr<IVoipCallManagerCallback> &callback)
112 {
113 MessageParcel dataParcel;
114 if (!dataParcel.WriteInterfaceToken(VoipCallManagerProxy::GetDescriptor())) {
115 TELEPHONY_LOGE("write descriptor fail");
116 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
117 }
118 dataParcel.WriteRemoteObject(callback->AsObject().GetRefPtr());
119 auto remote = Remote();
120 if (remote == nullptr) {
121 TELEPHONY_LOGE("RegisterCallBack Remote is null");
122 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
123 }
124 MessageOption option;
125 MessageParcel replyParcel;
126 int32_t error =
127 remote->SendRequest(static_cast<int32_t>(INTERFACE_REGISTER_CALLBACK), dataParcel, replyParcel, option);
128 if (error != TELEPHONY_SUCCESS) {
129 TELEPHONY_LOGE("function RegisterCallBack call failed! errCode:%{public}d", error);
130 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
131 }
132 return replyParcel.ReadInt32();
133 }
134
UnRegisterCallBack()135 int32_t VoipCallManagerProxy::UnRegisterCallBack()
136 {
137 MessageParcel dataParcel;
138 if (!dataParcel.WriteInterfaceToken(VoipCallManagerProxy::GetDescriptor())) {
139 TELEPHONY_LOGE("write descriptor fail");
140 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
141 }
142 auto remote = Remote();
143 if (remote == nullptr) {
144 TELEPHONY_LOGE("UnRegisterCallBack Remote is null");
145 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
146 }
147 MessageOption option;
148 MessageParcel replyParcel;
149 int32_t error =
150 remote->SendRequest(static_cast<int32_t>(INTERFACE_UN_REGISTER_CALLBACK), dataParcel, replyParcel, option);
151 if (error != TELEPHONY_SUCCESS) {
152 TELEPHONY_LOGE("function UnRegisterCallBack call failed! errCode:%{public}d", error);
153 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
154 }
155 return replyParcel.ReadInt32();
156 }
157
ReportVoipIncomingCall(std::string & callId,std::string & bundleName)158 int32_t VoipCallManagerProxy::ReportVoipIncomingCall(std::string &callId, std::string &bundleName)
159 {
160 MessageParcel dataParcel;
161 if (!dataParcel.WriteInterfaceToken(VoipCallManagerProxy::GetDescriptor())) {
162 TELEPHONY_LOGE("write descriptor fail");
163 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
164 }
165 dataParcel.WriteString(callId);
166 dataParcel.WriteString(bundleName);
167 auto remote = Remote();
168 if (remote == nullptr) {
169 TELEPHONY_LOGE("ReportVoipIncomingCall Remote is null");
170 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
171 }
172 MessageOption option;
173 MessageParcel replyParcel;
174 int32_t error =
175 remote->SendRequest(static_cast<int32_t>(INTERFACE_REPORT_VOIP_INCOMING_CALL), dataParcel, replyParcel, option);
176 if (error != TELEPHONY_SUCCESS) {
177 TELEPHONY_LOGE("function ReportVoipIncomingCall call failed! errCode:%{public}d", error);
178 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
179 }
180 return replyParcel.ReadInt32();
181 }
182
ReportVoipCallExtensionId(std::string & callId,std::string & bundleName,std::string & extensionId)183 int32_t VoipCallManagerProxy::ReportVoipCallExtensionId(
184 std::string &callId, std::string &bundleName, std::string &extensionId)
185 {
186 MessageParcel dataParcel;
187 if (!dataParcel.WriteInterfaceToken(VoipCallManagerProxy::GetDescriptor())) {
188 TELEPHONY_LOGE("write descriptor fail");
189 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
190 }
191 dataParcel.WriteString(callId);
192 dataParcel.WriteString(bundleName);
193 dataParcel.WriteString(extensionId);
194 auto remote = Remote();
195 if (remote == nullptr) {
196 TELEPHONY_LOGE("ReportVoipCallExtensionId Remote is null");
197 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
198 }
199 MessageOption option;
200 MessageParcel replyParcel;
201 int32_t error = remote->SendRequest(
202 static_cast<int32_t>(INTERFACE_REPORT_VOIP_CALL_EXTENSIONID), dataParcel, replyParcel, option);
203 if (error != TELEPHONY_SUCCESS) {
204 TELEPHONY_LOGE("function ReportVoipCallExtensionId call failed! errCode:%{public}d", error);
205 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
206 }
207 return replyParcel.ReadInt32();
208 }
209
Answer(const VoipCallEventInfo & events,int32_t videoState)210 int32_t VoipCallManagerProxy::Answer(const VoipCallEventInfo &events, int32_t videoState)
211 {
212 MessageParcel dataParcel;
213 if (!dataParcel.WriteInterfaceToken(VoipCallManagerProxy::GetDescriptor())) {
214 TELEPHONY_LOGE("write descriptor fail");
215 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
216 }
217 dataParcel.WriteString(events.voipCallId);
218 dataParcel.WriteString(events.bundleName);
219 dataParcel.WriteInt32(videoState);
220 auto remote = Remote();
221 if (remote == nullptr) {
222 TELEPHONY_LOGE("Answer voip Remote is null");
223 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
224 }
225 MessageOption option;
226 MessageParcel replyParcel;
227 int32_t error = remote->SendRequest(
228 static_cast<int32_t>(INTERFACE_ANSWER_VOIP_CALL), dataParcel, replyParcel, option);
229 if (error != TELEPHONY_SUCCESS) {
230 TELEPHONY_LOGE("function Answer voip call failed! errCode:%{public}d", error);
231 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
232 }
233 return replyParcel.ReadInt32();
234 }
235
HangUp(const VoipCallEventInfo & events)236 int32_t VoipCallManagerProxy::HangUp(const VoipCallEventInfo &events)
237 {
238 MessageParcel dataParcel;
239 if (!dataParcel.WriteInterfaceToken(VoipCallManagerProxy::GetDescriptor())) {
240 TELEPHONY_LOGE("write descriptor fail");
241 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
242 }
243 dataParcel.WriteString(events.voipCallId);
244 dataParcel.WriteString(events.bundleName);
245 dataParcel.WriteInt32(static_cast<int32_t>(events.errorReason));
246 auto remote = Remote();
247 if (remote == nullptr) {
248 TELEPHONY_LOGE("HangUp voip Remote is null");
249 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
250 }
251 MessageOption option;
252 MessageParcel replyParcel;
253 int32_t error = remote->SendRequest(
254 static_cast<int32_t>(INTERFACE_HANGUP_VOIP_CALL), dataParcel, replyParcel, option);
255 if (error != TELEPHONY_SUCCESS) {
256 TELEPHONY_LOGE("function HangUp voip call failed! errCode:%{public}d", error);
257 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
258 }
259 return replyParcel.ReadInt32();
260 }
261
Reject(const VoipCallEventInfo & events)262 int32_t VoipCallManagerProxy::Reject(const VoipCallEventInfo &events)
263 {
264 MessageParcel dataParcel;
265 if (!dataParcel.WriteInterfaceToken(VoipCallManagerProxy::GetDescriptor())) {
266 TELEPHONY_LOGE("write descriptor fail");
267 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
268 }
269 dataParcel.WriteString(events.voipCallId);
270 dataParcel.WriteString(events.bundleName);
271 auto remote = Remote();
272 if (remote == nullptr) {
273 TELEPHONY_LOGE("Reject voip Remote is null");
274 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
275 }
276 MessageOption option;
277 MessageParcel replyParcel;
278 int32_t error = remote->SendRequest(
279 static_cast<int32_t>(INTERFACE_REJECT_VOIP_CALL), dataParcel, replyParcel, option);
280 if (error != TELEPHONY_SUCCESS) {
281 TELEPHONY_LOGE("function Reject voip call failed! errCode:%{public}d", error);
282 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
283 }
284 return replyParcel.ReadInt32();
285 }
286
RegisterCallManagerCallBack(const sptr<ICallStatusCallback> & callback)287 int32_t VoipCallManagerProxy::RegisterCallManagerCallBack(const sptr<ICallStatusCallback> &callback)
288 {
289 if (callback == nullptr) {
290 return TELEPHONY_ERR_ARGUMENT_INVALID;
291 }
292
293 MessageParcel dataParcel;
294 if (!dataParcel.WriteInterfaceToken(VoipCallManagerProxy::GetDescriptor())) {
295 TELEPHONY_LOGE("write descriptor fail");
296 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
297 }
298
299 dataParcel.WriteRemoteObject(callback->AsObject().GetRefPtr());
300 auto remote = Remote();
301 if (remote == nullptr) {
302 TELEPHONY_LOGE("RegisterCallManagerCallBack Remote is null");
303 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
304 }
305 MessageOption option;
306 MessageParcel replyParcel;
307 int32_t error = remote->SendRequest(
308 static_cast<int32_t>(INTERFACE_REGISTER_CALL_MANAGER_CALLBACK), dataParcel, replyParcel, option);
309 if (error != TELEPHONY_SUCCESS) {
310 TELEPHONY_LOGE("function RegisterCallManagerCallBack call failed! errCode:%{public}d", error);
311 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
312 }
313 return replyParcel.ReadInt32();
314 }
315
UnRegisterCallManagerCallBack()316 int32_t VoipCallManagerProxy::UnRegisterCallManagerCallBack()
317 {
318 MessageParcel dataParcel;
319 if (!dataParcel.WriteInterfaceToken(VoipCallManagerProxy::GetDescriptor())) {
320 TELEPHONY_LOGE("write descriptor fail");
321 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
322 }
323 auto remote = Remote();
324 if (remote == nullptr) {
325 TELEPHONY_LOGE("UnRegisterCallManagerCallBack Remote is null");
326 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
327 }
328 MessageOption option;
329 MessageParcel replyParcel;
330 int32_t error = remote->SendRequest(
331 static_cast<int32_t>(INTERFACE_UNREGISTER_CALL_MANAGER_CALLBACK), dataParcel, replyParcel, option);
332 if (error != TELEPHONY_SUCCESS) {
333 TELEPHONY_LOGE("function UnRegisterCallManagerCallBack call failed! errCode:%{public}d", error);
334 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
335 }
336 return replyParcel.ReadInt32();
337 }
338
UnloadVoipSa()339 int32_t VoipCallManagerProxy::UnloadVoipSa()
340 {
341 MessageParcel dataParcel;
342 if (!dataParcel.WriteInterfaceToken(VoipCallManagerProxy::GetDescriptor())) {
343 TELEPHONY_LOGE("write descriptor fail");
344 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
345 }
346 auto remote = Remote();
347 if (remote == nullptr) {
348 TELEPHONY_LOGE("UnloadVoipSa Remote is null");
349 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
350 }
351
352 MessageOption option;
353 MessageParcel replyParcel;
354 int32_t error =
355 remote->SendRequest(static_cast<int32_t>(INTERFACE_UNLOAD_VOIP_SA), dataParcel, replyParcel, option);
356 if (error != TELEPHONY_SUCCESS) {
357 TELEPHONY_LOGE("function UnloadVoipSa failed! errCode:%{public}d", error);
358 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
359 }
360 return replyParcel.ReadInt32();
361 }
362
363 } // namespace Telephony
364 } // namespace OHOS
365