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