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
23 namespace OHOS {
24 namespace Telephony {
25 const int32_t MAX_LEN = 100000;
CallAbilityCallbackStub()26 CallAbilityCallbackStub::CallAbilityCallbackStub()
27 {
28 memberFuncMap_[static_cast<uint32_t>(CallManagerCallAbilityInterfaceCode::UPDATE_CALL_STATE_INFO)] =
29 &CallAbilityCallbackStub::OnUpdateCallStateInfo;
30 memberFuncMap_[static_cast<uint32_t>(CallManagerCallAbilityInterfaceCode::UPDATE_CALL_EVENT)] =
31 &CallAbilityCallbackStub::OnUpdateCallEvent;
32 memberFuncMap_[static_cast<uint32_t>(CallManagerCallAbilityInterfaceCode::UPDATE_CALL_DISCONNECTED_CAUSE)] =
33 &CallAbilityCallbackStub::OnUpdateCallDisconnectedCause;
34 memberFuncMap_[static_cast<uint32_t>(CallManagerCallAbilityInterfaceCode::UPDATE_CALL_ASYNC_RESULT_REQUEST)] =
35 &CallAbilityCallbackStub::OnUpdateAysncResults;
36 memberFuncMap_[static_cast<uint32_t>(CallManagerCallAbilityInterfaceCode::REPORT_OTT_CALL_REQUEST)] =
37 &CallAbilityCallbackStub::OnUpdateOttCallRequest;
38 memberFuncMap_[static_cast<uint32_t>(CallManagerCallAbilityInterfaceCode::UPDATE_MMI_CODE_RESULT_REQUEST)] =
39 &CallAbilityCallbackStub::OnUpdateMmiCodeResults;
40 memberFuncMap_[static_cast<uint32_t>(
41 CallManagerCallAbilityInterfaceCode::UPDATE_AUDIO_DEVICE_CHANGE_RESULT_REQUEST)] =
42 &CallAbilityCallbackStub::OnUpdateAudioDeviceChange;
43 memberFuncMap_[static_cast<uint32_t>(CallManagerCallAbilityInterfaceCode::REPORT_POST_DIAL_DELAY)] =
44 &CallAbilityCallbackStub::OnUpdatePostDialDelay;
45 }
46
~CallAbilityCallbackStub()47 CallAbilityCallbackStub::~CallAbilityCallbackStub()
48 {
49 memberFuncMap_.clear();
50 }
51
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)52 int32_t CallAbilityCallbackStub::OnRemoteRequest(
53 uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
54 {
55 std::u16string myDescriptor = CallAbilityCallbackStub::GetDescriptor();
56 std::u16string remoteDescriptor = data.ReadInterfaceToken();
57 if (myDescriptor != remoteDescriptor) {
58 TELEPHONY_LOGE("descriptor checked failed");
59 return TELEPHONY_ERR_DESCRIPTOR_MISMATCH;
60 }
61 TELEPHONY_LOGI("OnReceived, cmd = %{public}u", code);
62 auto itFunc = memberFuncMap_.find(code);
63 if (itFunc != memberFuncMap_.end()) {
64 auto memberFunc = itFunc->second;
65 if (memberFunc != nullptr) {
66 return (this->*memberFunc)(data, reply);
67 }
68 }
69 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
70 }
71
OnUpdateCallStateInfo(MessageParcel & data,MessageParcel & reply)72 int32_t CallAbilityCallbackStub::OnUpdateCallStateInfo(MessageParcel &data, MessageParcel &reply)
73 {
74 int32_t result = TELEPHONY_SUCCESS;
75 const CallAttributeInfo *parcelPtr = nullptr;
76 int32_t len = data.ReadInt32();
77 if (len <= 0 || len >= MAX_LEN) {
78 TELEPHONY_LOGE("Invalid parameter, len = %{public}d", len);
79 return TELEPHONY_ERR_ARGUMENT_INVALID;
80 }
81 if (!data.ContainFileDescriptors()) {
82 TELEPHONY_LOGW("sent raw data is less than 32k");
83 }
84 if ((parcelPtr = reinterpret_cast<const CallAttributeInfo *>(data.ReadRawData(len))) == nullptr) {
85 TELEPHONY_LOGE("reading raw data failed, length = %{public}d", len);
86 return TELEPHONY_ERR_LOCAL_PTR_NULL;
87 }
88 result = OnCallDetailsChange(*parcelPtr);
89 if (!reply.WriteInt32(result)) {
90 TELEPHONY_LOGE("writing parcel failed");
91 return TELEPHONY_ERR_WRITE_REPLY_FAIL;
92 }
93 return TELEPHONY_SUCCESS;
94 }
95
OnUpdateCallEvent(MessageParcel & data,MessageParcel & reply)96 int32_t CallAbilityCallbackStub::OnUpdateCallEvent(MessageParcel &data, MessageParcel &reply)
97 {
98 int32_t result = TELEPHONY_SUCCESS;
99 const CallEventInfo *parcelPtr = nullptr;
100 int32_t len = data.ReadInt32();
101 if (len <= 0 || len >= MAX_LEN) {
102 TELEPHONY_LOGE("Invalid parameter, len = %{public}d", len);
103 return TELEPHONY_ERR_ARGUMENT_INVALID;
104 }
105 if (!data.ContainFileDescriptors()) {
106 TELEPHONY_LOGW("sent raw data is less than 32k");
107 }
108 if ((parcelPtr = reinterpret_cast<const CallEventInfo *>(data.ReadRawData(len))) == nullptr) {
109 TELEPHONY_LOGE("reading raw data failed, length = %d", len);
110 return TELEPHONY_ERR_LOCAL_PTR_NULL;
111 }
112
113 result = OnCallEventChange(*parcelPtr);
114 if (!reply.WriteInt32(result)) {
115 TELEPHONY_LOGE("writing parcel failed");
116 return TELEPHONY_ERR_WRITE_REPLY_FAIL;
117 }
118 return TELEPHONY_SUCCESS;
119 }
120
OnUpdateCallDisconnectedCause(MessageParcel & data,MessageParcel & reply)121 int32_t CallAbilityCallbackStub::OnUpdateCallDisconnectedCause(MessageParcel &data, MessageParcel &reply)
122 {
123 DisconnectedDetails dcDetails;
124 dcDetails.reason = static_cast<DisconnectedReason>(data.ReadInt32());
125 dcDetails.message = data.ReadString();
126 int32_t result = OnCallDisconnectedCause(dcDetails);
127 if (!reply.WriteInt32(result)) {
128 TELEPHONY_LOGE("writing parcel failed");
129 return TELEPHONY_ERR_WRITE_REPLY_FAIL;
130 }
131 return TELEPHONY_SUCCESS;
132 }
133
OnUpdateAysncResults(MessageParcel & data,MessageParcel & reply)134 int32_t CallAbilityCallbackStub::OnUpdateAysncResults(MessageParcel &data, MessageParcel &reply)
135 {
136 int32_t result = TELEPHONY_SUCCESS;
137 AppExecFwk::PacMap resultInfo;
138 CallResultReportId reportId = static_cast<CallResultReportId>(data.ReadInt32());
139 resultInfo.PutIntValue("result", data.ReadInt32());
140 switch (reportId) {
141 case CallResultReportId::GET_CALL_WAITING_REPORT_ID:
142 case CallResultReportId::GET_CALL_RESTRICTION_REPORT_ID:
143 resultInfo.PutIntValue("status", data.ReadInt32());
144 resultInfo.PutIntValue("classCw", data.ReadInt32());
145 break;
146 case CallResultReportId::GET_CALL_TRANSFER_REPORT_ID:
147 resultInfo.PutIntValue("status", data.ReadInt32());
148 resultInfo.PutIntValue("classx", data.ReadInt32());
149 resultInfo.PutStringValue("number", data.ReadString());
150 resultInfo.PutIntValue("type", data.ReadInt32());
151 resultInfo.PutIntValue("reason", data.ReadInt32());
152 resultInfo.PutIntValue("time", data.ReadInt32());
153 break;
154 case CallResultReportId::GET_CALL_CLIP_ID:
155 resultInfo.PutIntValue("action", data.ReadInt32());
156 resultInfo.PutIntValue("clipStat", data.ReadInt32());
157 break;
158 case CallResultReportId::GET_CALL_CLIR_ID:
159 resultInfo.PutIntValue("action", data.ReadInt32());
160 resultInfo.PutIntValue("clirStat", data.ReadInt32());
161 break;
162 case CallResultReportId::START_RTT_REPORT_ID:
163 resultInfo.PutIntValue("active", data.ReadInt32());
164 break;
165 case CallResultReportId::GET_IMS_CONFIG_REPORT_ID:
166 case CallResultReportId::GET_IMS_FEATURE_VALUE_REPORT_ID:
167 resultInfo.PutIntValue("value", data.ReadInt32());
168 break;
169 case CallResultReportId::STOP_RTT_REPORT_ID:
170 resultInfo.PutIntValue("inactive", data.ReadInt32());
171 break;
172 default:
173 break;
174 }
175 if (!data.ContainFileDescriptors()) {
176 TELEPHONY_LOGW("sent raw data is less than 32k");
177 }
178 result = OnReportAsyncResults(reportId, resultInfo);
179 if (!reply.WriteInt32(result)) {
180 TELEPHONY_LOGE("writing parcel failed");
181 return TELEPHONY_ERR_WRITE_REPLY_FAIL;
182 }
183 return TELEPHONY_SUCCESS;
184 }
185
OnUpdateMmiCodeResults(MessageParcel & data,MessageParcel & reply)186 int32_t CallAbilityCallbackStub::OnUpdateMmiCodeResults(MessageParcel &data, MessageParcel &reply)
187 {
188 int32_t result = TELEPHONY_SUCCESS;
189 const MmiCodeInfo *parcelPtr = nullptr;
190 int32_t len = data.ReadInt32();
191 if (len <= 0 || len >= MAX_LEN) {
192 TELEPHONY_LOGE("Invalid parameter, len = %{public}d", len);
193 return TELEPHONY_ERR_ARGUMENT_INVALID;
194 }
195 if (!data.ContainFileDescriptors()) {
196 TELEPHONY_LOGW("sent raw data is less than 32k");
197 }
198 if ((parcelPtr = reinterpret_cast<const MmiCodeInfo *>(data.ReadRawData(len))) == nullptr) {
199 TELEPHONY_LOGE("reading raw data failed, length = %d", len);
200 return TELEPHONY_ERR_LOCAL_PTR_NULL;
201 }
202
203 result = OnReportMmiCodeResult(*parcelPtr);
204 if (!reply.WriteInt32(result)) {
205 TELEPHONY_LOGE("writing parcel failed");
206 return TELEPHONY_ERR_WRITE_REPLY_FAIL;
207 }
208 return TELEPHONY_SUCCESS;
209 }
210
OnUpdateAudioDeviceChange(MessageParcel & data,MessageParcel & reply)211 int32_t CallAbilityCallbackStub::OnUpdateAudioDeviceChange(MessageParcel &data, MessageParcel &reply)
212 {
213 int32_t result = TELEPHONY_SUCCESS;
214 if (!data.ContainFileDescriptors()) {
215 TELEPHONY_LOGW("sent raw data is less than 32k");
216 }
217 AudioDeviceInfo info;
218 if (memset_s(&info, sizeof(AudioDeviceInfo), 0, sizeof(AudioDeviceInfo)) != EOK) {
219 TELEPHONY_LOGE("memset_s address fail");
220 return TELEPHONY_ERR_MEMSET_FAIL;
221 }
222 int32_t len = data.ReadInt32();
223 if (len <= 0 || len >= MAX_LEN) {
224 TELEPHONY_LOGE("Invalid parameter, len = %{public}d", len);
225 return TELEPHONY_ERR_ARGUMENT_INVALID;
226 }
227 AudioDevice *audioDevicePtr = nullptr;
228 for (int32_t i = 0; i < len + 1; i++) {
229 audioDevicePtr = static_cast<AudioDevice *>(const_cast<void *>(data.ReadRawData(sizeof(AudioDevice))));
230 if (audioDevicePtr == nullptr) {
231 TELEPHONY_LOGE("Invalid parameter audioDevicePtr");
232 return TELEPHONY_ERR_ARGUMENT_INVALID;
233 }
234 if (i < len) {
235 info.audioDeviceList.push_back(*audioDevicePtr);
236 } else {
237 info.currentAudioDevice = *audioDevicePtr;
238 }
239 }
240
241 info.isMuted = data.ReadBool();
242 result = OnReportAudioDeviceChange(info);
243 if (!reply.WriteInt32(result)) {
244 TELEPHONY_LOGE("writing parcel failed");
245 return TELEPHONY_ERR_WRITE_REPLY_FAIL;
246 }
247 return TELEPHONY_SUCCESS;
248 }
249
OnUpdateOttCallRequest(MessageParcel & data,MessageParcel & reply)250 int32_t CallAbilityCallbackStub::OnUpdateOttCallRequest(MessageParcel &data, MessageParcel &reply)
251 {
252 int32_t result = TELEPHONY_SUCCESS;
253 AppExecFwk::PacMap resultInfo;
254 OttCallRequestId requestId = static_cast<OttCallRequestId>(data.ReadInt32());
255 resultInfo.PutStringValue("phoneNumber", data.ReadString());
256 resultInfo.PutStringValue("bundleName", data.ReadString());
257 resultInfo.PutIntValue("videoState", data.ReadInt32());
258 switch (requestId) {
259 case OttCallRequestId::OTT_REQUEST_INVITE_TO_CONFERENCE:
260 resultInfo.PutStringValue("number", data.ReadString());
261 break;
262 case OttCallRequestId::OTT_REQUEST_UPDATE_CALL_MEDIA_MODE:
263 resultInfo.PutIntValue("callMediaMode", data.ReadInt32());
264 break;
265 default:
266 break;
267 }
268 if (!data.ContainFileDescriptors()) {
269 TELEPHONY_LOGW("sent raw data is less than 32k");
270 }
271 result = OnOttCallRequest(requestId, resultInfo);
272 if (!reply.WriteInt32(result)) {
273 TELEPHONY_LOGE("writing parcel failed");
274 return TELEPHONY_ERR_WRITE_REPLY_FAIL;
275 }
276 return TELEPHONY_SUCCESS;
277 }
278
OnUpdatePostDialDelay(MessageParcel & data,MessageParcel & reply)279 int32_t CallAbilityCallbackStub::OnUpdatePostDialDelay(MessageParcel &data, MessageParcel &reply)
280 {
281 std::string remainPostDial = data.ReadString();
282 int32_t result = OnReportPostDialDelay(remainPostDial);
283 if (!reply.WriteInt32(result)) {
284 TELEPHONY_LOGE("writing parcel failed");
285 return TELEPHONY_ERR_WRITE_REPLY_FAIL;
286 }
287 return TELEPHONY_SUCCESS;
288 }
289 } // namespace Telephony
290 } // namespace OHOS
291