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_stub.h"
17
18 #include <securec.h>
19
20 #include "call_manager_errors.h"
21 #include "telephony_log_wrapper.h"
22 #include "native_call_manager_utils.h"
23
24 namespace OHOS {
25 namespace Telephony {
26 const int32_t MAX_LEN = 100000;
CallAbilityCallbackStub()27 CallAbilityCallbackStub::CallAbilityCallbackStub()
28 {
29 memberFuncMap_[static_cast<uint32_t>(CallManagerCallAbilityInterfaceCode::UPDATE_CALL_STATE_INFO)] =
30 [this](MessageParcel &data, MessageParcel &reply) { return OnUpdateCallStateInfo(data, reply); };
31 memberFuncMap_[static_cast<uint32_t>(CallManagerCallAbilityInterfaceCode::UPDATE_CALL_EVENT)] =
32 [this](MessageParcel &data, MessageParcel &reply) { return OnUpdateCallEvent(data, reply); };
33 memberFuncMap_[static_cast<uint32_t>(CallManagerCallAbilityInterfaceCode::UPDATE_CALL_DISCONNECTED_CAUSE)] =
34 [this](MessageParcel &data, MessageParcel &reply) { return OnUpdateCallDisconnectedCause(data, reply); };
35 memberFuncMap_[static_cast<uint32_t>(CallManagerCallAbilityInterfaceCode::UPDATE_CALL_ASYNC_RESULT_REQUEST)] =
36 [this](MessageParcel &data, MessageParcel &reply) { return OnUpdateAysncResults(data, reply); };
37 memberFuncMap_[static_cast<uint32_t>(CallManagerCallAbilityInterfaceCode::REPORT_OTT_CALL_REQUEST)] =
38 [this](MessageParcel &data, MessageParcel &reply) { return OnUpdateOttCallRequest(data, reply); };
39 memberFuncMap_[static_cast<uint32_t>(CallManagerCallAbilityInterfaceCode::UPDATE_MMI_CODE_RESULT_REQUEST)] =
40 [this](MessageParcel &data, MessageParcel &reply) { return OnUpdateMmiCodeResults(data, reply); };
41 memberFuncMap_[static_cast<uint32_t>(
42 CallManagerCallAbilityInterfaceCode::UPDATE_AUDIO_DEVICE_CHANGE_RESULT_REQUEST)] =
43 [this](MessageParcel &data, MessageParcel &reply) { return OnUpdateAudioDeviceChange(data, reply); };
44 memberFuncMap_[static_cast<uint32_t>(CallManagerCallAbilityInterfaceCode::REPORT_POST_DIAL_DELAY)] =
45 [this](MessageParcel &data, MessageParcel &reply) { return OnUpdatePostDialDelay(data, reply); };
46 memberFuncMap_[static_cast<uint32_t>(CallManagerCallAbilityInterfaceCode::UPDATE_IMS_CALL_MODE_RECEIVE)] =
47 [this](MessageParcel &data, MessageParcel &reply) { return OnUpdateImsCallModeChange(data, reply); };
48 memberFuncMap_[static_cast<uint32_t>(CallManagerCallAbilityInterfaceCode::CALL_SESSION_EVENT_CHANGE)] =
49 [this](MessageParcel &data, MessageParcel &reply) { return OnUpdateCallSessionEventChange(data, reply); };
50 memberFuncMap_[static_cast<uint32_t>(CallManagerCallAbilityInterfaceCode::PEERD_DIMENSIONS_CHANGE)] =
51 [this](MessageParcel &data, MessageParcel &reply) { return OnUpdatePeerDimensionsChange(data, reply); };
52 memberFuncMap_[static_cast<uint32_t>(CallManagerCallAbilityInterfaceCode::CALL_DATA_USAGE_CHANGE)] =
53 [this](MessageParcel &data, MessageParcel &reply) { return OnUpdateCallDataUsageChange(data, reply); };
54 memberFuncMap_[static_cast<uint32_t>(CallManagerCallAbilityInterfaceCode::CAMERA_CAPABILITIES_CHANGE)] =
55 [this](MessageParcel &data, MessageParcel &reply) { return OnUpdateCameraCapabilities(data, reply); };
56 }
57
~CallAbilityCallbackStub()58 CallAbilityCallbackStub::~CallAbilityCallbackStub()
59 {
60 memberFuncMap_.clear();
61 }
62
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)63 int32_t CallAbilityCallbackStub::OnRemoteRequest(
64 uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
65 {
66 std::u16string myDescriptor = CallAbilityCallbackStub::GetDescriptor();
67 std::u16string remoteDescriptor = data.ReadInterfaceToken();
68 if (myDescriptor != remoteDescriptor) {
69 TELEPHONY_LOGE("descriptor checked failed");
70 return TELEPHONY_ERR_DESCRIPTOR_MISMATCH;
71 }
72 TELEPHONY_LOGD("OnReceived, cmd = %{public}u", code);
73 auto itFunc = memberFuncMap_.find(code);
74 if (itFunc != memberFuncMap_.end()) {
75 auto memberFunc = itFunc->second;
76 if (memberFunc != nullptr) {
77 return memberFunc(data, reply);
78 }
79 }
80 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
81 }
82
OnUpdateCallStateInfo(MessageParcel & data,MessageParcel & reply)83 int32_t CallAbilityCallbackStub::OnUpdateCallStateInfo(MessageParcel &data, MessageParcel &reply)
84 {
85 int32_t result = TELEPHONY_SUCCESS;
86 if (!data.ContainFileDescriptors()) {
87 TELEPHONY_LOGD("sent raw data is less than 32k");
88 }
89 CallAttributeInfo parcelPtr = NativeCallManagerUtils::ReadCallAttributeInfo(data);
90 result = OnCallDetailsChange(parcelPtr);
91 if (!reply.WriteInt32(result)) {
92 TELEPHONY_LOGE("writing parcel failed");
93 return TELEPHONY_ERR_WRITE_REPLY_FAIL;
94 }
95 return TELEPHONY_SUCCESS;
96 }
97
OnUpdateCallEvent(MessageParcel & data,MessageParcel & reply)98 int32_t CallAbilityCallbackStub::OnUpdateCallEvent(MessageParcel &data, MessageParcel &reply)
99 {
100 int32_t result = TELEPHONY_SUCCESS;
101 const CallEventInfo *parcelPtr = nullptr;
102 int32_t len = data.ReadInt32();
103 if (len <= 0 || len >= MAX_LEN) {
104 TELEPHONY_LOGE("Invalid parameter, len = %{public}d", len);
105 return TELEPHONY_ERR_ARGUMENT_INVALID;
106 }
107 if (!data.ContainFileDescriptors()) {
108 TELEPHONY_LOGW("sent raw data is less than 32k");
109 }
110 if ((parcelPtr = reinterpret_cast<const CallEventInfo *>(data.ReadRawData(sizeof(CallEventInfo)))) == nullptr) {
111 TELEPHONY_LOGE("reading raw data failed, length = %d", len);
112 return TELEPHONY_ERR_LOCAL_PTR_NULL;
113 }
114
115 CallEventInfo info = *parcelPtr;
116 result = OnCallEventChange(info);
117 if (!reply.WriteInt32(result)) {
118 TELEPHONY_LOGE("writing parcel failed");
119 return TELEPHONY_ERR_WRITE_REPLY_FAIL;
120 }
121 return TELEPHONY_SUCCESS;
122 }
123
OnUpdateCallDisconnectedCause(MessageParcel & data,MessageParcel & reply)124 int32_t CallAbilityCallbackStub::OnUpdateCallDisconnectedCause(MessageParcel &data, MessageParcel &reply)
125 {
126 DisconnectedDetails dcDetails;
127 dcDetails.reason = static_cast<DisconnectedReason>(data.ReadInt32());
128 dcDetails.message = data.ReadString();
129 int32_t result = OnCallDisconnectedCause(dcDetails);
130 if (!reply.WriteInt32(result)) {
131 TELEPHONY_LOGE("writing parcel failed");
132 return TELEPHONY_ERR_WRITE_REPLY_FAIL;
133 }
134 return TELEPHONY_SUCCESS;
135 }
136
OnUpdateAysncResults(MessageParcel & data,MessageParcel & reply)137 int32_t CallAbilityCallbackStub::OnUpdateAysncResults(MessageParcel &data, MessageParcel &reply)
138 {
139 int32_t result = TELEPHONY_SUCCESS;
140 AppExecFwk::PacMap resultInfo;
141 CallResultReportId reportId = static_cast<CallResultReportId>(data.ReadInt32());
142 resultInfo.PutIntValue("result", data.ReadInt32());
143 switch (reportId) {
144 case CallResultReportId::GET_CALL_WAITING_REPORT_ID:
145 case CallResultReportId::GET_CALL_RESTRICTION_REPORT_ID:
146 resultInfo.PutIntValue("status", data.ReadInt32());
147 resultInfo.PutIntValue("classCw", data.ReadInt32());
148 break;
149 case CallResultReportId::GET_CALL_TRANSFER_REPORT_ID:
150 resultInfo.PutIntValue("status", data.ReadInt32());
151 resultInfo.PutIntValue("classx", data.ReadInt32());
152 resultInfo.PutStringValue("number", data.ReadString());
153 resultInfo.PutIntValue("type", data.ReadInt32());
154 resultInfo.PutIntValue("reason", data.ReadInt32());
155 resultInfo.PutIntValue("time", data.ReadInt32());
156 break;
157 case CallResultReportId::GET_CALL_CLIP_ID:
158 resultInfo.PutIntValue("action", data.ReadInt32());
159 resultInfo.PutIntValue("clipStat", data.ReadInt32());
160 break;
161 case CallResultReportId::GET_CALL_CLIR_ID:
162 resultInfo.PutIntValue("action", data.ReadInt32());
163 resultInfo.PutIntValue("clirStat", data.ReadInt32());
164 break;
165 case CallResultReportId::START_RTT_REPORT_ID:
166 resultInfo.PutIntValue("active", data.ReadInt32());
167 break;
168 case CallResultReportId::GET_IMS_CONFIG_REPORT_ID:
169 case CallResultReportId::GET_IMS_FEATURE_VALUE_REPORT_ID:
170 resultInfo.PutIntValue("value", data.ReadInt32());
171 break;
172 case CallResultReportId::STOP_RTT_REPORT_ID:
173 resultInfo.PutIntValue("inactive", data.ReadInt32());
174 break;
175 default:
176 break;
177 }
178 if (!data.ContainFileDescriptors()) {
179 TELEPHONY_LOGW("sent raw data is less than 32k");
180 }
181 result = OnReportAsyncResults(reportId, resultInfo);
182 if (!reply.WriteInt32(result)) {
183 TELEPHONY_LOGE("writing parcel failed");
184 return TELEPHONY_ERR_WRITE_REPLY_FAIL;
185 }
186 return TELEPHONY_SUCCESS;
187 }
188
OnUpdateMmiCodeResults(MessageParcel & data,MessageParcel & reply)189 int32_t CallAbilityCallbackStub::OnUpdateMmiCodeResults(MessageParcel &data, MessageParcel &reply)
190 {
191 int32_t result = TELEPHONY_SUCCESS;
192 const MmiCodeInfo *parcelPtr = nullptr;
193 int32_t len = data.ReadInt32();
194 if (len <= 0 || len >= MAX_LEN) {
195 TELEPHONY_LOGE("Invalid parameter, len = %{public}d", len);
196 return TELEPHONY_ERR_ARGUMENT_INVALID;
197 }
198 if (!data.ContainFileDescriptors()) {
199 TELEPHONY_LOGW("sent raw data is less than 32k");
200 }
201 if ((parcelPtr = reinterpret_cast<const MmiCodeInfo *>(data.ReadRawData(sizeof(MmiCodeInfo)))) == nullptr) {
202 TELEPHONY_LOGE("reading raw data failed, length = %d", len);
203 return TELEPHONY_ERR_LOCAL_PTR_NULL;
204 }
205
206 MmiCodeInfo info = *parcelPtr;
207 result = OnReportMmiCodeResult(info);
208 if (!reply.WriteInt32(result)) {
209 TELEPHONY_LOGE("writing parcel failed");
210 return TELEPHONY_ERR_WRITE_REPLY_FAIL;
211 }
212 return TELEPHONY_SUCCESS;
213 }
214
OnUpdateAudioDeviceChange(MessageParcel & data,MessageParcel & reply)215 int32_t CallAbilityCallbackStub::OnUpdateAudioDeviceChange(MessageParcel &data, MessageParcel &reply)
216 {
217 int32_t result = TELEPHONY_SUCCESS;
218 if (!data.ContainFileDescriptors()) {
219 TELEPHONY_LOGD("sent raw data is less than 32k");
220 }
221 AudioDeviceInfo info;
222 if (memset_s(&info, sizeof(AudioDeviceInfo), 0, sizeof(AudioDeviceInfo)) != EOK) {
223 TELEPHONY_LOGE("memset_s address fail");
224 return TELEPHONY_ERR_MEMSET_FAIL;
225 }
226 int32_t len = data.ReadInt32();
227 if (len <= 0 || len >= MAX_LEN) {
228 TELEPHONY_LOGE("Invalid parameter, len = %{public}d", len);
229 return TELEPHONY_ERR_ARGUMENT_INVALID;
230 }
231 AudioDevice *audioDevicePtr = nullptr;
232 for (int32_t i = 0; i < len + 1; i++) {
233 audioDevicePtr = static_cast<AudioDevice *>(const_cast<void *>(data.ReadRawData(sizeof(AudioDevice))));
234 if (audioDevicePtr == nullptr) {
235 TELEPHONY_LOGE("Invalid parameter audioDevicePtr");
236 return TELEPHONY_ERR_ARGUMENT_INVALID;
237 }
238 if (i < len) {
239 info.audioDeviceList.push_back(*audioDevicePtr);
240 } else {
241 info.currentAudioDevice = *audioDevicePtr;
242 }
243 }
244
245 info.isMuted = data.ReadBool();
246 result = OnReportAudioDeviceChange(info);
247 if (!reply.WriteInt32(result)) {
248 TELEPHONY_LOGE("writing parcel failed");
249 return TELEPHONY_ERR_WRITE_REPLY_FAIL;
250 }
251 return TELEPHONY_SUCCESS;
252 }
253
OnUpdateOttCallRequest(MessageParcel & data,MessageParcel & reply)254 int32_t CallAbilityCallbackStub::OnUpdateOttCallRequest(MessageParcel &data, MessageParcel &reply)
255 {
256 int32_t result = TELEPHONY_SUCCESS;
257 AppExecFwk::PacMap resultInfo;
258 OttCallRequestId requestId = static_cast<OttCallRequestId>(data.ReadInt32());
259 resultInfo.PutStringValue("phoneNumber", data.ReadString());
260 resultInfo.PutStringValue("bundleName", data.ReadString());
261 resultInfo.PutIntValue("videoState", data.ReadInt32());
262 switch (requestId) {
263 case OttCallRequestId::OTT_REQUEST_INVITE_TO_CONFERENCE:
264 resultInfo.PutStringValue("number", data.ReadString());
265 break;
266 case OttCallRequestId::OTT_REQUEST_UPDATE_CALL_MEDIA_MODE:
267 resultInfo.PutIntValue("callMediaMode", data.ReadInt32());
268 break;
269 default:
270 break;
271 }
272 if (!data.ContainFileDescriptors()) {
273 TELEPHONY_LOGW("sent raw data is less than 32k");
274 }
275 result = OnOttCallRequest(requestId, resultInfo);
276 if (!reply.WriteInt32(result)) {
277 TELEPHONY_LOGE("writing parcel failed");
278 return TELEPHONY_ERR_WRITE_REPLY_FAIL;
279 }
280 return TELEPHONY_SUCCESS;
281 }
282
OnUpdatePostDialDelay(MessageParcel & data,MessageParcel & reply)283 int32_t CallAbilityCallbackStub::OnUpdatePostDialDelay(MessageParcel &data, MessageParcel &reply)
284 {
285 std::string remainPostDial = data.ReadString();
286 int32_t result = OnReportPostDialDelay(remainPostDial);
287 if (!reply.WriteInt32(result)) {
288 TELEPHONY_LOGE("writing parcel failed");
289 return TELEPHONY_ERR_WRITE_REPLY_FAIL;
290 }
291 return TELEPHONY_SUCCESS;
292 }
293
OnUpdateImsCallModeChange(MessageParcel & data,MessageParcel & reply)294 int32_t CallAbilityCallbackStub::OnUpdateImsCallModeChange(MessageParcel &data, MessageParcel &reply)
295 {
296 int32_t result = TELEPHONY_SUCCESS;
297 const CallMediaModeInfo *parcelPtr = nullptr;
298 int32_t len = data.ReadInt32();
299 if (len <= 0 || len >= MAX_LEN) {
300 TELEPHONY_LOGE("Invalid parameter, len = %{public}d", len);
301 return TELEPHONY_ERR_ARGUMENT_INVALID;
302 }
303 if (!data.ContainFileDescriptors()) {
304 TELEPHONY_LOGD("sent raw data is less than 32k");
305 }
306 if ((parcelPtr = reinterpret_cast<const CallMediaModeInfo *>(data.ReadRawData(len))) == nullptr) {
307 TELEPHONY_LOGE("reading raw data failed, length = %d", len);
308 return TELEPHONY_ERR_LOCAL_PTR_NULL;
309 }
310
311 result = OnReportImsCallModeChange(*parcelPtr);
312 if (!reply.WriteInt32(result)) {
313 TELEPHONY_LOGE("writing parcel failed");
314 return TELEPHONY_ERR_WRITE_REPLY_FAIL;
315 }
316 return TELEPHONY_SUCCESS;
317 }
318
OnUpdateCallSessionEventChange(MessageParcel & data,MessageParcel & reply)319 int32_t CallAbilityCallbackStub::OnUpdateCallSessionEventChange(MessageParcel &data, MessageParcel &reply)
320 {
321 int32_t result = TELEPHONY_SUCCESS;
322 if (!data.ContainFileDescriptors()) {
323 TELEPHONY_LOGW("sent raw data is less than 32k");
324 }
325
326 const CallSessionEvent *parcelPtr = nullptr;
327 int32_t len = data.ReadInt32();
328 if (len <= 0 || len >= MAX_LEN) {
329 TELEPHONY_LOGE("Invalid parameter, len = %{public}d", len);
330 return TELEPHONY_ERR_ARGUMENT_INVALID;
331 }
332 if ((parcelPtr = reinterpret_cast<const CallSessionEvent *>(data.ReadRawData(len))) == nullptr) {
333 TELEPHONY_LOGE("reading raw data failed, length = %d", len);
334 return TELEPHONY_ERR_LOCAL_PTR_NULL;
335 }
336
337 result = OnReportCallSessionEventChange(*parcelPtr);
338 if (!reply.WriteInt32(result)) {
339 TELEPHONY_LOGE("writing parcel failed");
340 return TELEPHONY_ERR_WRITE_REPLY_FAIL;
341 }
342 return TELEPHONY_SUCCESS;
343 }
344
OnUpdatePeerDimensionsChange(MessageParcel & data,MessageParcel & reply)345 int32_t CallAbilityCallbackStub::OnUpdatePeerDimensionsChange(MessageParcel &data, MessageParcel &reply)
346 {
347 int32_t result = TELEPHONY_SUCCESS;
348 if (!data.ContainFileDescriptors()) {
349 TELEPHONY_LOGW("sent raw data is less than 32k");
350 }
351
352 const PeerDimensionsDetail *parcelPtr = nullptr;
353 int32_t len = data.ReadInt32();
354 if (len <= 0 || len >= MAX_LEN) {
355 TELEPHONY_LOGE("Invalid parameter, len = %{public}d", len);
356 return TELEPHONY_ERR_ARGUMENT_INVALID;
357 }
358 if ((parcelPtr = reinterpret_cast<const PeerDimensionsDetail *>(data.ReadRawData(len))) == nullptr) {
359 TELEPHONY_LOGE("reading raw data failed, length = %d", len);
360 return TELEPHONY_ERR_LOCAL_PTR_NULL;
361 }
362
363 result = OnReportPeerDimensionsChange(*parcelPtr);
364 if (!reply.WriteInt32(result)) {
365 TELEPHONY_LOGE("writing parcel failed");
366 return TELEPHONY_ERR_WRITE_REPLY_FAIL;
367 }
368 return TELEPHONY_SUCCESS;
369 }
370
OnUpdateCallDataUsageChange(MessageParcel & data,MessageParcel & reply)371 int32_t CallAbilityCallbackStub::OnUpdateCallDataUsageChange(MessageParcel &data, MessageParcel &reply)
372 {
373 int32_t result = TELEPHONY_SUCCESS;
374 if (!data.ContainFileDescriptors()) {
375 TELEPHONY_LOGW("sent raw data is less than 32k");
376 }
377
378 int64_t dataUsage = data.ReadInt64();
379 result = OnReportCallDataUsageChange(dataUsage);
380 if (!reply.WriteInt32(result)) {
381 TELEPHONY_LOGE("writing parcel failed");
382 return TELEPHONY_ERR_WRITE_REPLY_FAIL;
383 }
384 return TELEPHONY_SUCCESS;
385 }
386
OnUpdateCameraCapabilities(MessageParcel & data,MessageParcel & reply)387 int32_t CallAbilityCallbackStub::OnUpdateCameraCapabilities(MessageParcel &data, MessageParcel &reply)
388 {
389 int32_t result = TELEPHONY_SUCCESS;
390 if (!data.ContainFileDescriptors()) {
391 TELEPHONY_LOGW("sent raw data is less than 32k");
392 }
393
394 const CameraCapabilities *parcelPtr = nullptr;
395 int32_t len = data.ReadInt32();
396 if (len <= 0 || len >= MAX_LEN) {
397 TELEPHONY_LOGE("Invalid parameter, len = %{public}d", len);
398 return TELEPHONY_ERR_ARGUMENT_INVALID;
399 }
400 if ((parcelPtr = reinterpret_cast<const CameraCapabilities *>(data.ReadRawData(len))) == nullptr) {
401 TELEPHONY_LOGE("reading raw data failed, length = %d", len);
402 return TELEPHONY_ERR_LOCAL_PTR_NULL;
403 }
404
405 result = OnReportCameraCapabilities(*parcelPtr);
406 if (!reply.WriteInt32(result)) {
407 TELEPHONY_LOGE("writing parcel failed");
408 return TELEPHONY_ERR_WRITE_REPLY_FAIL;
409 }
410 return TELEPHONY_SUCCESS;
411 }
412 } // namespace Telephony
413 } // namespace OHOS
414