1 /*
2 * Copyright (C) 2021 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 {
CallAbilityCallbackStub()25 CallAbilityCallbackStub::CallAbilityCallbackStub()
26 {
27 memberFuncMap_[UPDATE_CALL_STATE_INFO] = &CallAbilityCallbackStub::OnUpdateCallStateInfo;
28 memberFuncMap_[UPDATE_CALL_EVENT] = &CallAbilityCallbackStub::OnUpdateCallEvent;
29 memberFuncMap_[UPDATE_CALL_DISCONNECTED_CAUSE] = &CallAbilityCallbackStub::OnUpdateCallDisconnectedCause;
30 memberFuncMap_[UPDATE_CALL_ASYNC_RESULT_REQUEST] = &CallAbilityCallbackStub::OnUpdateAysncResults;
31 memberFuncMap_[REPORT_OTT_CALL_REQUEST] = &CallAbilityCallbackStub::OnUpdateOttCallRequest;
32 }
33
~CallAbilityCallbackStub()34 CallAbilityCallbackStub::~CallAbilityCallbackStub()
35 {
36 memberFuncMap_.clear();
37 }
38
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)39 int32_t CallAbilityCallbackStub::OnRemoteRequest(
40 uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
41 {
42 std::u16string myDescriptor = CallAbilityCallbackStub::GetDescriptor();
43 std::u16string remoteDescriptor = data.ReadInterfaceToken();
44 if (myDescriptor != remoteDescriptor) {
45 TELEPHONY_LOGE("descriptor checked failed");
46 return TELEPHONY_ERR_DESCRIPTOR_MISMATCH;
47 }
48 TELEPHONY_LOGI("OnReceived, cmd = %{public}u", code);
49 auto itFunc = memberFuncMap_.find(code);
50 if (itFunc != memberFuncMap_.end()) {
51 auto memberFunc = itFunc->second;
52 if (memberFunc != nullptr) {
53 return (this->*memberFunc)(data, reply);
54 }
55 }
56 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
57 }
58
OnUpdateCallStateInfo(MessageParcel & data,MessageParcel & reply)59 int32_t CallAbilityCallbackStub::OnUpdateCallStateInfo(MessageParcel &data, MessageParcel &reply)
60 {
61 int32_t result = TELEPHONY_SUCCESS;
62 const CallAttributeInfo *parcelPtr = nullptr;
63 int32_t len = data.ReadInt32();
64 if (len <= 0) {
65 TELEPHONY_LOGE("Invalid parameter, len = %{public}d", len);
66 return TELEPHONY_ERR_ARGUMENT_INVALID;
67 }
68 if (!data.ContainFileDescriptors()) {
69 TELEPHONY_LOGW("sent raw data is less than 32k");
70 }
71 if ((parcelPtr = reinterpret_cast<const CallAttributeInfo *>(data.ReadRawData(len))) == nullptr) {
72 TELEPHONY_LOGE("reading raw data failed, length = %{public}d", len);
73 return TELEPHONY_ERR_LOCAL_PTR_NULL;
74 }
75 result = OnCallDetailsChange(*parcelPtr);
76 if (!reply.WriteInt32(result)) {
77 TELEPHONY_LOGE("writing parcel failed");
78 return TELEPHONY_ERR_WRITE_REPLY_FAIL;
79 }
80 return TELEPHONY_SUCCESS;
81 }
82
OnUpdateCallEvent(MessageParcel & data,MessageParcel & reply)83 int32_t CallAbilityCallbackStub::OnUpdateCallEvent(MessageParcel &data, MessageParcel &reply)
84 {
85 int32_t result = TELEPHONY_SUCCESS;
86 const CallEventInfo *parcelPtr = nullptr;
87 int32_t len = data.ReadInt32();
88 if (len <= 0) {
89 TELEPHONY_LOGE("Invalid parameter, len = %{public}d", len);
90 return TELEPHONY_ERR_ARGUMENT_INVALID;
91 }
92 if (!data.ContainFileDescriptors()) {
93 TELEPHONY_LOGW("sent raw data is less than 32k");
94 }
95 if ((parcelPtr = reinterpret_cast<const CallEventInfo *>(data.ReadRawData(len))) == nullptr) {
96 TELEPHONY_LOGE("reading raw data failed, length = %d", len);
97 return TELEPHONY_ERR_LOCAL_PTR_NULL;
98 }
99
100 result = OnCallEventChange(*parcelPtr);
101 if (!reply.WriteInt32(result)) {
102 TELEPHONY_LOGE("writing parcel failed");
103 return TELEPHONY_ERR_WRITE_REPLY_FAIL;
104 }
105 return TELEPHONY_SUCCESS;
106 }
107
OnUpdateCallDisconnectedCause(MessageParcel & data,MessageParcel & reply)108 int32_t CallAbilityCallbackStub::OnUpdateCallDisconnectedCause(MessageParcel &data, MessageParcel &reply)
109 {
110 DisconnectedDetails cause = (DisconnectedDetails)data.ReadInt32();
111 int32_t result = OnCallDisconnectedCause(cause);
112 if (!reply.WriteInt32(result)) {
113 TELEPHONY_LOGE("writing parcel failed");
114 return TELEPHONY_ERR_WRITE_REPLY_FAIL;
115 }
116 return TELEPHONY_SUCCESS;
117 }
118
OnUpdateAysncResults(MessageParcel & data,MessageParcel & reply)119 int32_t CallAbilityCallbackStub::OnUpdateAysncResults(MessageParcel &data, MessageParcel &reply)
120 {
121 int32_t result = TELEPHONY_SUCCESS;
122 AppExecFwk::PacMap resultInfo;
123 CallResultReportId reportId = static_cast<CallResultReportId>(data.ReadInt32());
124 resultInfo.PutIntValue("result", data.ReadInt32());
125 switch (reportId) {
126 case CallResultReportId::GET_CALL_WAITING_REPORT_ID:
127 case CallResultReportId::GET_CALL_RESTRICTION_REPORT_ID:
128 resultInfo.PutIntValue("status", data.ReadInt32());
129 resultInfo.PutIntValue("classCw", data.ReadInt32());
130 break;
131 case CallResultReportId::GET_CALL_TRANSFER_REPORT_ID:
132 resultInfo.PutIntValue("status", data.ReadInt32());
133 resultInfo.PutIntValue("classx", data.ReadInt32());
134 resultInfo.PutStringValue("number", data.ReadString());
135 resultInfo.PutIntValue("type", data.ReadInt32());
136 break;
137 case CallResultReportId::GET_CALL_CLIP_ID:
138 resultInfo.PutIntValue("action", data.ReadInt32());
139 resultInfo.PutIntValue("clipStat", data.ReadInt32());
140 break;
141 case CallResultReportId::GET_CALL_CLIR_ID:
142 resultInfo.PutIntValue("action", data.ReadInt32());
143 resultInfo.PutIntValue("clirStat", data.ReadInt32());
144 break;
145 case CallResultReportId::GET_CALL_VOTLE_REPORT_ID:
146 resultInfo.PutIntValue("active", data.ReadInt32());
147 break;
148 case CallResultReportId::GET_IMS_CONFIG_REPORT_ID:
149 case CallResultReportId::GET_IMS_FEATURE_VALUE_REPORT_ID:
150 case CallResultReportId::GET_LTE_ENHANCE_MODE_REPORT_ID:
151 resultInfo.PutIntValue("value", data.ReadInt32());
152 break;
153 case CallResultReportId::START_RTT_REPORT_ID:
154 resultInfo.PutIntValue("active", data.ReadInt32());
155 break;
156 case CallResultReportId::STOP_RTT_REPORT_ID:
157 resultInfo.PutIntValue("inactive", data.ReadInt32());
158 break;
159 default:
160 break;
161 }
162 if (!data.ContainFileDescriptors()) {
163 TELEPHONY_LOGW("sent raw data is less than 32k");
164 }
165 result = OnReportAsyncResults(reportId, resultInfo);
166 if (!reply.WriteInt32(result)) {
167 TELEPHONY_LOGE("writing parcel failed");
168 return TELEPHONY_ERR_WRITE_REPLY_FAIL;
169 }
170 return TELEPHONY_SUCCESS;
171 }
172
OnUpdateOttCallRequest(MessageParcel & data,MessageParcel & reply)173 int32_t CallAbilityCallbackStub::OnUpdateOttCallRequest(MessageParcel &data, MessageParcel &reply)
174 {
175 int32_t result = TELEPHONY_SUCCESS;
176 AppExecFwk::PacMap resultInfo;
177 OttCallRequestId requestId = static_cast<OttCallRequestId>(data.ReadInt32());
178 resultInfo.PutStringValue("phoneNumber", data.ReadString());
179 resultInfo.PutStringValue("bundleName", data.ReadString());
180 resultInfo.PutIntValue("videoState", data.ReadInt32());
181 switch (requestId) {
182 case OttCallRequestId::OTT_REQUEST_INVITE_TO_CONFERENCE:
183 resultInfo.PutStringValue("number", data.ReadString());
184 break;
185 case OttCallRequestId::OTT_REQUEST_UPDATE_CALL_MEDIA_MODE:
186 resultInfo.PutIntValue("callMediaMode", data.ReadInt32());
187 break;
188 default:
189 break;
190 }
191 if (!data.ContainFileDescriptors()) {
192 TELEPHONY_LOGW("sent raw data is less than 32k");
193 }
194 result = OnOttCallRequest(requestId, resultInfo);
195 if (!reply.WriteInt32(result)) {
196 TELEPHONY_LOGE("writing parcel failed");
197 return TELEPHONY_ERR_WRITE_REPLY_FAIL;
198 }
199 return TELEPHONY_SUCCESS;
200 }
201 } // namespace Telephony
202 } // namespace OHOS
203