1
2 /*
3 * Copyright (C) 2022-2023 Huawei Device Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include "satellite_call_callback_stub.h"
18
19 #include "cellular_call_register.h"
20 #include "cellular_call_service.h"
21 #include "radio_event.h"
22 #include "satellite_call_client.h"
23 #include "satellite_radio_event.h"
24 #include "tel_event_handler.h"
25 #include "telephony_errors.h"
26 #include "telephony_log_wrapper.h"
27
28 namespace OHOS {
29 namespace Telephony {
30 const int32_t MAX_SIZE = 10;
31
SatelliteCallCallbackStub()32 SatelliteCallCallbackStub::SatelliteCallCallbackStub()
33 {
34 TELEPHONY_LOGI("SatelliteCallCallbackStub");
35 InitFuncMap();
36 }
37
InitFuncMap()38 void SatelliteCallCallbackStub::InitFuncMap()
39 {
40 InitCallBasicFuncMap();
41 }
42
InitCallBasicFuncMap()43 void SatelliteCallCallbackStub::InitCallBasicFuncMap()
44 {
45 /****************** call basic ******************/
46 requestFuncMap_[static_cast<uint32_t>(SatelliteCallCallbackInterfaceCode::SATELLITE_DIAL)] =
47 [this](MessageParcel &data, MessageParcel &reply) { return OnDialResponseInner(data, reply); };
48 requestFuncMap_[static_cast<uint32_t>(SatelliteCallCallbackInterfaceCode::SATELLITE_HANG_UP)] =
49 [this](MessageParcel &data, MessageParcel &reply) { return OnHangUpResponseInner(data, reply); };
50 requestFuncMap_[static_cast<uint32_t>(SatelliteCallCallbackInterfaceCode::SATELLITE_REJECT)] =
51 [this](MessageParcel &data, MessageParcel &reply) { return OnRejectResponseInner(data, reply); };
52 requestFuncMap_[static_cast<uint32_t>(SatelliteCallCallbackInterfaceCode::SATELLITE_ANSWER)] =
53 [this](MessageParcel &data, MessageParcel &reply) { return OnAnswerResponseInner(data, reply); };
54 requestFuncMap_[static_cast<uint32_t>(SatelliteCallCallbackInterfaceCode::SATELLITE_CALL_STATE_CHANGE)] =
55 [this](MessageParcel &data, MessageParcel &reply) { return OnCallStateChangeReportInner(data, reply); };
56 requestFuncMap_[static_cast<uint32_t>(SatelliteCallCallbackInterfaceCode::SATELLITE_GET_CALLS_DATA)] =
57 [this](MessageParcel &data, MessageParcel &reply) { return OnGetSatelliteCallsDataResponseInner(data, reply); };
58 }
59
~SatelliteCallCallbackStub()60 SatelliteCallCallbackStub::~SatelliteCallCallbackStub()
61 {
62 requestFuncMap_.clear();
63 }
64
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)65 int32_t SatelliteCallCallbackStub::OnRemoteRequest(
66 uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
67 {
68 std::u16string myDescriptor = SatelliteCallCallbackStub::GetDescriptor();
69 std::u16string remoteDescriptor = data.ReadInterfaceToken();
70 if (myDescriptor != remoteDescriptor) {
71 TELEPHONY_LOGE("descriptor checked fail");
72 return TELEPHONY_ERR_DESCRIPTOR_MISMATCH;
73 }
74 auto itFunc = requestFuncMap_.find(code);
75 if (itFunc != requestFuncMap_.end()) {
76 auto requestFunc = itFunc->second;
77 if (requestFunc != nullptr) {
78 return requestFunc(data, reply);
79 }
80 }
81 TELEPHONY_LOGI("Function not found, need check.");
82 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
83 }
84
OnDialResponseInner(MessageParcel & data,MessageParcel & reply)85 int32_t SatelliteCallCallbackStub::OnDialResponseInner(MessageParcel &data, MessageParcel &reply)
86 {
87 int32_t slotId = data.ReadInt32();
88 auto info = static_cast<const RadioResponseInfo *>(data.ReadRawData(sizeof(RadioResponseInfo)));
89 if (info == nullptr) {
90 TELEPHONY_LOGE("[slot%{public}d] info is null.", slotId);
91 return TELEPHONY_ERR_ARGUMENT_INVALID;
92 }
93 reply.WriteInt32(DialSatelliteResponse(slotId, *info));
94 return TELEPHONY_SUCCESS;
95 }
96
OnHangUpResponseInner(MessageParcel & data,MessageParcel & reply)97 int32_t SatelliteCallCallbackStub::OnHangUpResponseInner(MessageParcel &data, MessageParcel &reply)
98 {
99 int32_t slotId = data.ReadInt32();
100 auto info = static_cast<const RadioResponseInfo *>(data.ReadRawData(sizeof(RadioResponseInfo)));
101 if (info == nullptr) {
102 TELEPHONY_LOGE("[slot%{public}d] info is null.", slotId);
103 return TELEPHONY_ERR_ARGUMENT_INVALID;
104 }
105 reply.WriteInt32(HangUpSatelliteResponse(slotId, *info));
106 return TELEPHONY_SUCCESS;
107 }
108
OnRejectResponseInner(MessageParcel & data,MessageParcel & reply)109 int32_t SatelliteCallCallbackStub::OnRejectResponseInner(MessageParcel &data, MessageParcel &reply)
110 {
111 int32_t slotId = data.ReadInt32();
112 auto info = static_cast<const RadioResponseInfo *>(data.ReadRawData(sizeof(RadioResponseInfo)));
113 if (info == nullptr) {
114 TELEPHONY_LOGE("[slot%{public}d] info is null.", slotId);
115 return TELEPHONY_ERR_ARGUMENT_INVALID;
116 }
117 reply.WriteInt32(RejectSatelliteResponse(slotId, *info));
118 return TELEPHONY_SUCCESS;
119 }
120
OnAnswerResponseInner(MessageParcel & data,MessageParcel & reply)121 int32_t SatelliteCallCallbackStub::OnAnswerResponseInner(MessageParcel &data, MessageParcel &reply)
122 {
123 int32_t slotId = data.ReadInt32();
124 auto info = static_cast<const RadioResponseInfo *>(data.ReadRawData(sizeof(RadioResponseInfo)));
125 if (info == nullptr) {
126 TELEPHONY_LOGE("[slot%{public}d] info is null.", slotId);
127 return TELEPHONY_ERR_ARGUMENT_INVALID;
128 }
129 reply.WriteInt32(AnswerSatelliteResponse(slotId, *info));
130 return TELEPHONY_SUCCESS;
131 }
132
OnCallStateChangeReportInner(MessageParcel & data,MessageParcel & reply)133 int32_t SatelliteCallCallbackStub::OnCallStateChangeReportInner(MessageParcel &data, MessageParcel &reply)
134 {
135 int32_t slotId = data.ReadInt32();
136 reply.WriteInt32(CallStateChangeReport(slotId));
137 return TELEPHONY_SUCCESS;
138 }
139
OnGetSatelliteCallsDataResponseInner(MessageParcel & data,MessageParcel & reply)140 int32_t SatelliteCallCallbackStub::OnGetSatelliteCallsDataResponseInner(MessageParcel &data, MessageParcel &reply)
141 {
142 int32_t slotId = data.ReadInt32();
143 auto info = static_cast<const RadioResponseInfo *>(data.ReadRawData(sizeof(RadioResponseInfo)));
144 if (info == nullptr) {
145 TELEPHONY_LOGE("[slot%{public}d] info is null.", slotId);
146 auto callList = std::make_shared<SatelliteCurrentCallList>();
147 callList->callSize = data.ReadInt32();
148 callList->flag = data.ReadInt32();
149 int32_t len = data.ReadInt32();
150 if (len < 0 || len > MAX_SIZE) {
151 TELEPHONY_LOGE("SatelliteCallCallbackStub::OnGetImsCallsDataResponseInner callSize error");
152 return TELEPHONY_ERR_FAIL;
153 }
154 for (int32_t i = 0; i < len; i++) {
155 SatelliteCurrentCall call;
156 call.index = data.ReadInt32();
157 call.dir = data.ReadInt32();
158 call.state = data.ReadInt32();
159 call.mode = data.ReadInt32();
160 call.mpty = data.ReadInt32();
161 call.voiceDomain = data.ReadInt32();
162 call.callType = data.ReadInt32();
163 data.ReadString(call.number);
164 call.type = data.ReadInt32();
165 data.ReadString(call.alpha);
166 call.toa = data.ReadInt32();
167 callList->calls.push_back(call);
168 }
169 reply.WriteInt32(GetSatelliteCallsDataResponse(slotId, *callList));
170 return TELEPHONY_SUCCESS;
171 }
172 reply.WriteInt32(GetSatelliteCallsDataResponse(slotId, *info));
173 return TELEPHONY_SUCCESS;
174 }
175
DialSatelliteResponse(int32_t slotId,const RadioResponseInfo & info)176 int32_t SatelliteCallCallbackStub::DialSatelliteResponse(int32_t slotId, const RadioResponseInfo &info)
177 {
178 TELEPHONY_LOGI("[slot%{public}d] entry", slotId);
179 return SendEvent(slotId, SatelliteRadioEvent::SATELLITE_RADIO_DIAL, info);
180 }
181
HangUpSatelliteResponse(int32_t slotId,const RadioResponseInfo & info)182 int32_t SatelliteCallCallbackStub::HangUpSatelliteResponse(int32_t slotId, const RadioResponseInfo &info)
183 {
184 TELEPHONY_LOGI("[slot%{public}d] entry", slotId);
185 return SendEvent(slotId, SatelliteRadioEvent::SATELLITE_RADIO_HANGUP, info);
186 }
187
RejectSatelliteResponse(int32_t slotId,const RadioResponseInfo & info)188 int32_t SatelliteCallCallbackStub::RejectSatelliteResponse(int32_t slotId, const RadioResponseInfo &info)
189 {
190 TELEPHONY_LOGI("[slot%{public}d] entry", slotId);
191 return SendEvent(slotId, SatelliteRadioEvent::SATELLITE_RADIO_REJECT, info);
192 }
193
AnswerSatelliteResponse(int32_t slotId,const RadioResponseInfo & info)194 int32_t SatelliteCallCallbackStub::AnswerSatelliteResponse(int32_t slotId, const RadioResponseInfo &info)
195 {
196 TELEPHONY_LOGI("[slot%{public}d] entry", slotId);
197 return SendEvent(slotId, SatelliteRadioEvent::SATELLITE_RADIO_ANSWER, info);
198 }
199
CallStateChangeReport(int32_t slotId)200 int32_t SatelliteCallCallbackStub::CallStateChangeReport(int32_t slotId)
201 {
202 TELEPHONY_LOGI("[slot%{public}d] entry", slotId);
203 auto handler = DelayedSingleton<SatelliteCallClient>::GetInstance()->GetHandler(slotId);
204 if (handler == nullptr) {
205 TELEPHONY_LOGE("[slot%{public}d] handler is null", slotId);
206 return TELEPHONY_ERR_LOCAL_PTR_NULL;
207 }
208
209 bool ret = TelEventHandler::SendTelEvent(handler, SatelliteRadioEvent::SATELLITE_RADIO_CALL_STATE_CHANGED);
210 if (!ret) {
211 TELEPHONY_LOGE("[slot%{public}d] SendEvent failed!", slotId);
212 return TELEPHONY_ERR_FAIL;
213 }
214 return TELEPHONY_SUCCESS;
215 }
216
GetSatelliteCallsDataResponse(int32_t slotId,const RadioResponseInfo & info)217 int32_t SatelliteCallCallbackStub::GetSatelliteCallsDataResponse(int32_t slotId, const RadioResponseInfo &info)
218 {
219 TELEPHONY_LOGI("[slot%{public}d] entry", slotId);
220 return SendEvent(slotId, SatelliteRadioEvent::SATELLITE_RADIO_GET_CALL_DATA, info);
221 }
222
GetSatelliteCallsDataResponse(int32_t slotId,const SatelliteCurrentCallList & callList)223 int32_t SatelliteCallCallbackStub::GetSatelliteCallsDataResponse(
224 int32_t slotId, const SatelliteCurrentCallList &callList)
225 {
226 TELEPHONY_LOGI("[slot%{public}d] entry", slotId);
227 auto handler = DelayedSingleton<SatelliteCallClient>::GetInstance()->GetHandler(slotId);
228 if (handler == nullptr) {
229 TELEPHONY_LOGE("[slot%{public}d] handler is null", slotId);
230 return TELEPHONY_ERR_LOCAL_PTR_NULL;
231 }
232 auto satelliteCurrentCallList = std::make_shared<SatelliteCurrentCallList>();
233 *satelliteCurrentCallList = callList;
234 bool ret = TelEventHandler::SendTelEvent(
235 handler, SatelliteRadioEvent::SATELLITE_RADIO_GET_CALL_DATA, satelliteCurrentCallList);
236 if (!ret) {
237 TELEPHONY_LOGE("[slot%{public}d] SendEvent failed!", slotId);
238 return TELEPHONY_ERR_FAIL;
239 }
240 return TELEPHONY_SUCCESS;
241 }
242
SendEvent(int32_t slotId,int32_t eventId,const RadioResponseInfo & info)243 int32_t SatelliteCallCallbackStub::SendEvent(int32_t slotId, int32_t eventId, const RadioResponseInfo &info)
244 {
245 auto handler = DelayedSingleton<SatelliteCallClient>::GetInstance()->GetHandler(slotId);
246 if (handler == nullptr) {
247 TELEPHONY_LOGE("[slot%{public}d] handler is null", slotId);
248 return TELEPHONY_ERR_LOCAL_PTR_NULL;
249 }
250 std::shared_ptr<RadioResponseInfo> responseInfo = std::make_shared<RadioResponseInfo>();
251 *responseInfo = info;
252 bool ret = TelEventHandler::SendTelEvent(handler, eventId, responseInfo);
253 if (!ret) {
254 TELEPHONY_LOGE("[slot%{public}d] SendEvent failed!", slotId);
255 return TELEPHONY_ERR_FAIL;
256 }
257 return TELEPHONY_SUCCESS;
258 }
259 } // namespace Telephony
260 } // namespace OHOS