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