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_ability_callback_proxy.h"
17
18 #include "call_manager_errors.h"
19 #include "message_option.h"
20 #include "message_parcel.h"
21 #include "call_manager_utils.h"
22
23 namespace OHOS {
24 namespace Telephony {
CallAbilityCallbackProxy(const sptr<IRemoteObject> & impl)25 CallAbilityCallbackProxy::CallAbilityCallbackProxy(const sptr<IRemoteObject> &impl)
26 : IRemoteProxy<ICallAbilityCallback>(impl)
27 {}
28
OnCallDetailsChange(const CallAttributeInfo & info)29 int32_t CallAbilityCallbackProxy::OnCallDetailsChange(const CallAttributeInfo &info)
30 {
31 MessageParcel dataParcel;
32 MessageParcel replyParcel;
33 MessageOption option(MessageOption::TF_ASYNC);
34 if (!dataParcel.WriteInterfaceToken(CallAbilityCallbackProxy::GetDescriptor())) {
35 TELEPHONY_LOGE("write descriptor fail");
36 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
37 }
38 CallManagerUtils::WriteCallAttributeInfo(info, dataParcel);
39 if (Remote() == nullptr) {
40 TELEPHONY_LOGE("function Remote() return nullptr!");
41 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
42 }
43 int32_t error =
44 Remote()->SendRequest(static_cast<uint32_t>(CallManagerCallAbilityInterfaceCode::UPDATE_CALL_STATE_INFO),
45 dataParcel, replyParcel, option);
46 if (error != TELEPHONY_SUCCESS) {
47 TELEPHONY_LOGD("update call state info errcode: %{public}d", error);
48 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
49 }
50 return replyParcel.ReadInt32();
51 }
52
OnCallEventChange(const CallEventInfo & info)53 int32_t CallAbilityCallbackProxy::OnCallEventChange(const CallEventInfo &info)
54 {
55 MessageParcel dataParcel;
56 MessageParcel replyParcel;
57 MessageOption option(MessageOption::TF_ASYNC);
58 if (!dataParcel.WriteInterfaceToken(CallAbilityCallbackProxy::GetDescriptor())) {
59 TELEPHONY_LOGE("write descriptor fail");
60 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
61 }
62 int32_t length = sizeof(CallEventInfo);
63 dataParcel.WriteInt32(length);
64 dataParcel.WriteRawData((const void *)&info, length);
65 if (Remote() == nullptr) {
66 TELEPHONY_LOGE("function Remote() return nullptr!");
67 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
68 }
69 int32_t error = Remote()->SendRequest(static_cast<uint32_t>(CallManagerCallAbilityInterfaceCode::UPDATE_CALL_EVENT),
70 dataParcel, replyParcel, option);
71 if (error != TELEPHONY_SUCCESS) {
72 TELEPHONY_LOGE("update call event failed, error: %{public}d", error);
73 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
74 }
75 return replyParcel.ReadInt32();
76 }
77
OnCallDisconnectedCause(const DisconnectedDetails & details)78 int32_t CallAbilityCallbackProxy::OnCallDisconnectedCause(const DisconnectedDetails &details)
79 {
80 MessageParcel dataParcel;
81 MessageParcel replyParcel;
82 MessageOption option(MessageOption::TF_ASYNC);
83 if (!dataParcel.WriteInterfaceToken(CallAbilityCallbackProxy::GetDescriptor())) {
84 TELEPHONY_LOGE("write descriptor fail");
85 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
86 }
87 if (!dataParcel.WriteInt32(static_cast<int32_t>(details.reason))) {
88 TELEPHONY_LOGE("write reason fail");
89 return TELEPHONY_ERR_WRITE_DATA_FAIL;
90 }
91 if (!dataParcel.WriteString(details.message)) {
92 TELEPHONY_LOGE("write message fail");
93 return TELEPHONY_ERR_WRITE_DATA_FAIL;
94 }
95 if (Remote() == nullptr) {
96 TELEPHONY_LOGE("function Remote() return nullptr!");
97 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
98 }
99 int32_t error = Remote()->SendRequest(
100 static_cast<uint32_t>(CallManagerCallAbilityInterfaceCode::UPDATE_CALL_DISCONNECTED_CAUSE), dataParcel,
101 replyParcel, option);
102 if (error != TELEPHONY_SUCCESS) {
103 TELEPHONY_LOGD("report call disconnected cause errcode: %{public}d", error);
104 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
105 }
106 return replyParcel.ReadInt32();
107 }
108
OnReportAsyncResults(CallResultReportId reportId,AppExecFwk::PacMap & resultInfo)109 int32_t CallAbilityCallbackProxy::OnReportAsyncResults(CallResultReportId reportId, AppExecFwk::PacMap &resultInfo)
110 {
111 MessageParcel dataParcel;
112 MessageParcel replyParcel;
113 MessageOption option(MessageOption::TF_ASYNC);
114 if (!dataParcel.WriteInterfaceToken(CallAbilityCallbackProxy::GetDescriptor())) {
115 TELEPHONY_LOGE("write descriptor fail");
116 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
117 }
118 PackDataParcel(reportId, resultInfo, dataParcel);
119 if (Remote() == nullptr) {
120 TELEPHONY_LOGE("function Remote() return nullptr!");
121 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
122 }
123 int32_t error = Remote()->SendRequest(
124 static_cast<uint32_t>(CallManagerCallAbilityInterfaceCode::UPDATE_CALL_ASYNC_RESULT_REQUEST), dataParcel,
125 replyParcel, option);
126 if (error != TELEPHONY_SUCCESS) {
127 TELEPHONY_LOGE("report async results failed, error: %{public}d", error);
128 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
129 }
130 return replyParcel.ReadInt32();
131 }
132
OnReportMmiCodeResult(const MmiCodeInfo & info)133 int32_t CallAbilityCallbackProxy::OnReportMmiCodeResult(const MmiCodeInfo &info)
134 {
135 MessageParcel dataParcel;
136 MessageParcel replyParcel;
137 MessageOption option(MessageOption::TF_ASYNC);
138 if (!dataParcel.WriteInterfaceToken(CallAbilityCallbackProxy::GetDescriptor())) {
139 TELEPHONY_LOGE("write descriptor fail");
140 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
141 }
142 int32_t length = sizeof(MmiCodeInfo);
143 dataParcel.WriteInt32(length);
144 dataParcel.WriteRawData((const void *)&info, length);
145 if (Remote() == nullptr) {
146 TELEPHONY_LOGE("function Remote() return nullptr!");
147 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
148 }
149 int32_t error = Remote()->SendRequest(static_cast<uint32_t>(
150 CallManagerCallAbilityInterfaceCode::UPDATE_MMI_CODE_RESULT_REQUEST), dataParcel,
151 replyParcel, option);
152 if (error != TELEPHONY_SUCCESS) {
153 TELEPHONY_LOGE("report async results failed, error: %{public}d", error);
154 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
155 }
156 return replyParcel.ReadInt32();
157 }
158
PackDataParcel(CallResultReportId reportId,AppExecFwk::PacMap & resultInfo,MessageParcel & dataParcel)159 void CallAbilityCallbackProxy::PackDataParcel(
160 CallResultReportId reportId, AppExecFwk::PacMap &resultInfo, MessageParcel &dataParcel)
161 {
162 dataParcel.WriteInt32(static_cast<int32_t>(reportId));
163 dataParcel.WriteInt32(resultInfo.GetIntValue("result"));
164 switch (reportId) {
165 case CallResultReportId::GET_CALL_WAITING_REPORT_ID:
166 case CallResultReportId::GET_CALL_RESTRICTION_REPORT_ID:
167 dataParcel.WriteInt32(resultInfo.GetIntValue("status"));
168 dataParcel.WriteInt32(resultInfo.GetIntValue("classCw"));
169 break;
170 case CallResultReportId::GET_CALL_TRANSFER_REPORT_ID:
171 dataParcel.WriteInt32(resultInfo.GetIntValue("status"));
172 dataParcel.WriteInt32(resultInfo.GetIntValue("classx"));
173 dataParcel.WriteString(resultInfo.GetStringValue("number"));
174 dataParcel.WriteInt32(resultInfo.GetIntValue("type"));
175 dataParcel.WriteInt32(resultInfo.GetIntValue("reason"));
176 break;
177 case CallResultReportId::GET_CALL_CLIP_ID:
178 dataParcel.WriteInt32(resultInfo.GetIntValue("action"));
179 dataParcel.WriteInt32(resultInfo.GetIntValue("clipStat"));
180 break;
181 case CallResultReportId::GET_CALL_CLIR_ID:
182 dataParcel.WriteInt32(resultInfo.GetIntValue("action"));
183 dataParcel.WriteInt32(resultInfo.GetIntValue("clirStat"));
184 break;
185 case CallResultReportId::GET_IMS_CONFIG_REPORT_ID:
186 case CallResultReportId::GET_IMS_FEATURE_VALUE_REPORT_ID:
187 dataParcel.WriteInt32(resultInfo.GetIntValue("value"));
188 break;
189 case CallResultReportId::START_RTT_REPORT_ID:
190 dataParcel.WriteInt32(resultInfo.GetIntValue("active"));
191 break;
192 case CallResultReportId::STOP_RTT_REPORT_ID:
193 dataParcel.WriteInt32(resultInfo.GetIntValue("inactive"));
194 break;
195 default:
196 break;
197 }
198 }
199
OnOttCallRequest(OttCallRequestId requestId,AppExecFwk::PacMap & info)200 int32_t CallAbilityCallbackProxy::OnOttCallRequest(OttCallRequestId requestId, AppExecFwk::PacMap &info)
201 {
202 MessageParcel dataParcel;
203 MessageParcel replyParcel;
204 MessageOption option(MessageOption::TF_ASYNC);
205 if (!dataParcel.WriteInterfaceToken(CallAbilityCallbackProxy::GetDescriptor())) {
206 TELEPHONY_LOGE("write descriptor fail");
207 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
208 }
209 dataParcel.WriteInt32(static_cast<int32_t>(requestId));
210 dataParcel.WriteString(info.GetStringValue("phoneNumber"));
211 dataParcel.WriteString(info.GetStringValue("bundleName"));
212 dataParcel.WriteInt32(info.GetIntValue("videoState"));
213 switch (requestId) {
214 case OttCallRequestId::OTT_REQUEST_INVITE_TO_CONFERENCE:
215 if (info.GetIntValue("listCnt") > 0) {
216 dataParcel.WriteString(info.GetStringValue("number"));
217 }
218 break;
219 case OttCallRequestId::OTT_REQUEST_UPDATE_CALL_MEDIA_MODE:
220 dataParcel.WriteInt32(info.GetIntValue("callMediaMode"));
221 break;
222 default:
223 break;
224 }
225 if (Remote() == nullptr) {
226 TELEPHONY_LOGE("function Remote() return nullptr!");
227 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
228 }
229 int32_t error =
230 Remote()->SendRequest(static_cast<uint32_t>(CallManagerCallAbilityInterfaceCode::REPORT_OTT_CALL_REQUEST),
231 dataParcel, replyParcel, option);
232 if (error != TELEPHONY_SUCCESS) {
233 TELEPHONY_LOGE("report ott call request failed, error: %{public}d", error);
234 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
235 }
236 return replyParcel.ReadInt32();
237 }
238
OnReportAudioDeviceChange(const AudioDeviceInfo & info)239 int32_t CallAbilityCallbackProxy::OnReportAudioDeviceChange(const AudioDeviceInfo &info)
240 {
241 MessageParcel dataParcel;
242 MessageParcel replyParcel;
243 MessageOption option(MessageOption::TF_ASYNC);
244 if (!dataParcel.WriteInterfaceToken(CallAbilityCallbackProxy::GetDescriptor())) {
245 TELEPHONY_LOGE("write descriptor fail");
246 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
247 }
248 size_t audioDeviceListLength = info.audioDeviceList.size();
249 dataParcel.WriteInt32(static_cast<int32_t>(audioDeviceListLength));
250 for (auto &audioDevice : info.audioDeviceList) {
251 dataParcel.WriteRawData((const void *)&audioDevice, sizeof(AudioDevice));
252 }
253 dataParcel.WriteRawData((const void *)&info.currentAudioDevice, sizeof(AudioDevice));
254 dataParcel.WriteBool(info.isMuted);
255
256 TELEPHONY_LOGD("audioDeviceListLength=%{public}zu", audioDeviceListLength);
257 if (Remote() == nullptr) {
258 TELEPHONY_LOGE("function Remote() return nullptr!");
259 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
260 }
261 int32_t error = Remote()->SendRequest(
262 static_cast<uint32_t>(CallManagerCallAbilityInterfaceCode::UPDATE_AUDIO_DEVICE_CHANGE_RESULT_REQUEST),
263 dataParcel, replyParcel, option);
264 if (error != TELEPHONY_SUCCESS) {
265 TELEPHONY_LOGD("report audio device info errcode: %{public}d", error);
266 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
267 }
268 return replyParcel.ReadInt32();
269 }
270
OnReportPostDialDelay(const std::string & str)271 int32_t CallAbilityCallbackProxy::OnReportPostDialDelay(const std::string &str)
272 {
273 MessageParcel dataParcel;
274 MessageParcel replyParcel;
275 MessageOption option(MessageOption::TF_ASYNC);
276 if (!dataParcel.WriteInterfaceToken(CallAbilityCallbackProxy::GetDescriptor())) {
277 TELEPHONY_LOGE("WriteInterfaceToken fail");
278 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
279 }
280 dataParcel.WriteString(str);
281 if (Remote() == nullptr) {
282 TELEPHONY_LOGE("Remote() return nullptr!");
283 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
284 }
285 int32_t error = Remote()->SendRequest(
286 static_cast<uint32_t>(CallManagerCallAbilityInterfaceCode::REPORT_POST_DIAL_DELAY),
287 dataParcel, replyParcel, option);
288 if (error != TELEPHONY_SUCCESS) {
289 TELEPHONY_LOGE("report post-dial wait failed, error: %{public}d", error);
290 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
291 }
292 return replyParcel.ReadInt32();
293 }
294
OnReportImsCallModeChange(const CallMediaModeInfo & imsCallModeInfo)295 int32_t CallAbilityCallbackProxy::OnReportImsCallModeChange(const CallMediaModeInfo &imsCallModeInfo)
296 {
297 MessageParcel dataParcel;
298 MessageParcel replyParcel;
299 MessageOption option(MessageOption::TF_ASYNC);
300 if (!dataParcel.WriteInterfaceToken(CallAbilityCallbackProxy::GetDescriptor())) {
301 TELEPHONY_LOGE("write descriptor fail");
302 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
303 }
304 int32_t length = sizeof(CallMediaModeInfo);
305 dataParcel.WriteInt32(length);
306 dataParcel.WriteRawData((const void *)&imsCallModeInfo, length);
307 if (Remote() == nullptr) {
308 TELEPHONY_LOGE("function Remote() return nullptr!");
309 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
310 }
311 int32_t error = Remote()->SendRequest(static_cast<uint32_t>(
312 CallManagerCallAbilityInterfaceCode::UPDATE_IMS_CALL_MODE_RECEIVE), dataParcel,
313 replyParcel, option);
314 if (error != TELEPHONY_SUCCESS) {
315 TELEPHONY_LOGD("report async results errcode: %{public}d", error);
316 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
317 }
318 return replyParcel.ReadInt32();
319 }
320
OnReportCallSessionEventChange(const CallSessionEvent & callSessionEventOptions)321 int32_t CallAbilityCallbackProxy::OnReportCallSessionEventChange(
322 const CallSessionEvent &callSessionEventOptions)
323 {
324 MessageParcel dataParcel;
325 MessageParcel replyParcel;
326 MessageOption option(MessageOption::TF_ASYNC);
327 if (!dataParcel.WriteInterfaceToken(CallAbilityCallbackProxy::GetDescriptor())) {
328 TELEPHONY_LOGE("write descriptor fail");
329 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
330 }
331 int32_t length = sizeof(CallSessionEvent);
332 dataParcel.WriteInt32(length);
333 dataParcel.WriteRawData((const void *)&callSessionEventOptions, length);
334 if (Remote() == nullptr) {
335 TELEPHONY_LOGE("function Remote() return nullptr!");
336 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
337 }
338 int32_t error = Remote()->SendRequest(static_cast<uint32_t>(
339 CallManagerCallAbilityInterfaceCode::CALL_SESSION_EVENT_CHANGE), dataParcel,
340 replyParcel, option);
341 if (error != TELEPHONY_SUCCESS) {
342 TELEPHONY_LOGD("report async results errcode: %{public}d", error);
343 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
344 }
345 return replyParcel.ReadInt32();
346 }
347
OnReportPeerDimensionsChange(const PeerDimensionsDetail & peerDimensionsDetail)348 int32_t CallAbilityCallbackProxy::OnReportPeerDimensionsChange(const PeerDimensionsDetail &peerDimensionsDetail)
349 {
350 MessageParcel dataParcel;
351 MessageParcel replyParcel;
352 MessageOption option(MessageOption::TF_ASYNC);
353 if (!dataParcel.WriteInterfaceToken(CallAbilityCallbackProxy::GetDescriptor())) {
354 TELEPHONY_LOGE("write descriptor fail");
355 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
356 }
357 int32_t length = sizeof(PeerDimensionsDetail);
358 dataParcel.WriteInt32(length);
359 dataParcel.WriteRawData((const void *)&peerDimensionsDetail, length);
360 if (Remote() == nullptr) {
361 TELEPHONY_LOGE("function Remote() return nullptr!");
362 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
363 }
364 int32_t error = Remote()->SendRequest(static_cast<uint32_t>(
365 CallManagerCallAbilityInterfaceCode::PEERD_DIMENSIONS_CHANGE), dataParcel,
366 replyParcel, option);
367 if (error != TELEPHONY_SUCCESS) {
368 TELEPHONY_LOGE("report async results failed, error: %{public}d", error);
369 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
370 }
371 return replyParcel.ReadInt32();
372 }
373
OnReportCallDataUsageChange(const int64_t dataUsage)374 int32_t CallAbilityCallbackProxy::OnReportCallDataUsageChange(const int64_t dataUsage)
375 {
376 MessageParcel dataParcel;
377 MessageParcel replyParcel;
378 MessageOption option(MessageOption::TF_ASYNC);
379 if (!dataParcel.WriteInterfaceToken(CallAbilityCallbackProxy::GetDescriptor())) {
380 TELEPHONY_LOGE("write descriptor fail");
381 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
382 }
383 dataParcel.WriteInt64(dataUsage);
384 if (Remote() == nullptr) {
385 TELEPHONY_LOGE("function Remote() return nullptr!");
386 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
387 }
388 int32_t error = Remote()->SendRequest(static_cast<uint32_t>(
389 CallManagerCallAbilityInterfaceCode::CALL_DATA_USAGE_CHANGE), dataParcel,
390 replyParcel, option);
391 if (error != TELEPHONY_SUCCESS) {
392 TELEPHONY_LOGE("report async results failed, error: %{public}d", error);
393 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
394 }
395 return replyParcel.ReadInt32();
396 }
397
OnReportCameraCapabilities(const CameraCapabilities & cameraCapabilities)398 int32_t CallAbilityCallbackProxy::OnReportCameraCapabilities(const CameraCapabilities &cameraCapabilities)
399 {
400 MessageParcel dataParcel;
401 MessageParcel replyParcel;
402 MessageOption option(MessageOption::TF_ASYNC);
403 if (!dataParcel.WriteInterfaceToken(CallAbilityCallbackProxy::GetDescriptor())) {
404 TELEPHONY_LOGE("write descriptor fail");
405 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
406 }
407 int32_t length = sizeof(CameraCapabilities);
408 dataParcel.WriteInt32(length);
409 dataParcel.WriteRawData((const void *)&cameraCapabilities, length);
410 if (Remote() == nullptr) {
411 TELEPHONY_LOGE("function Remote() return nullptr!");
412 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
413 }
414 int32_t error = Remote()->SendRequest(static_cast<uint32_t>(
415 CallManagerCallAbilityInterfaceCode::CAMERA_CAPABILITIES_CHANGE), dataParcel,
416 replyParcel, option);
417 if (error != TELEPHONY_SUCCESS) {
418 TELEPHONY_LOGE("report async results failed, error: %{public}d", error);
419 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
420 }
421 return replyParcel.ReadInt32();
422 }
423 } // namespace Telephony
424 } // namespace OHOS
425