1 /*
2 * Copyright (C) 2022-2023 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 * limitations under the License.
13 */
14
15 #include "satellite_call_proxy.h"
16
17 #include "cellular_call_hisysevent.h"
18 #include "message_option.h"
19 #include "message_parcel.h"
20 #include "telephony_errors.h"
21
22 namespace OHOS {
23 namespace Telephony {
Dial(const SatelliteCallInfo & callInfo,CLIRMode mode)24 int32_t SatelliteCallProxy::Dial(const SatelliteCallInfo &callInfo, CLIRMode mode)
25 {
26 MessageParcel in;
27 if (!in.WriteInterfaceToken(SatelliteCallProxy::GetDescriptor())) {
28 TELEPHONY_LOGE("[slot%{public}d]Write descriptor token fail!", callInfo.slotId);
29 CellularCallHiSysEvent::WriteDialCallFaultEvent(callInfo.slotId, INVALID_PARAMETER, INVALID_PARAMETER,
30 TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL, "satellite call proxy write descriptor token fail");
31 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
32 }
33 if (!in.WriteRawData((const void *)&callInfo, sizeof(SatelliteCallInfo))) {
34 TELEPHONY_LOGE("[slot%{public}d]Write callInfo fail!", callInfo.slotId);
35 CellularCallHiSysEvent::WriteDialCallFaultEvent(callInfo.slotId, INVALID_PARAMETER, INVALID_PARAMETER,
36 TELEPHONY_ERR_WRITE_DATA_FAIL, "satellite call proxy write data fail");
37 return TELEPHONY_ERR_WRITE_DATA_FAIL;
38 }
39 if (!in.WriteInt32(mode)) {
40 TELEPHONY_LOGE("[slot%{public}d]Write mode fail!", callInfo.slotId);
41 CellularCallHiSysEvent::WriteDialCallFaultEvent(callInfo.slotId, INVALID_PARAMETER, INVALID_PARAMETER,
42 TELEPHONY_ERR_WRITE_DATA_FAIL, "satellite call proxy write data fail");
43 return TELEPHONY_ERR_WRITE_DATA_FAIL;
44 }
45 sptr<IRemoteObject> remote = Remote();
46 if (remote == nullptr) {
47 TELEPHONY_LOGE("[slot%{public}d]Remote is null", callInfo.slotId);
48 CellularCallHiSysEvent::WriteDialCallFaultEvent(callInfo.slotId, INVALID_PARAMETER, INVALID_PARAMETER,
49 TELEPHONY_ERR_LOCAL_PTR_NULL, "satellite call proxy remote is null");
50 return TELEPHONY_ERR_LOCAL_PTR_NULL;
51 }
52 MessageParcel out;
53 MessageOption option;
54 int32_t error =
55 remote->SendRequest(static_cast<int32_t>(SatelliteCallInterfaceCode::SATELLITE_DIAL), in, out, option);
56 if (error == ERR_NONE) {
57 return out.ReadInt32();
58 }
59 TELEPHONY_LOGE("[slot%{public}d]SendRequest fail, error:%{public}d", callInfo.slotId, error);
60 CellularCallHiSysEvent::WriteDialCallFaultEvent(callInfo.slotId, INVALID_PARAMETER, INVALID_PARAMETER,
61 static_cast<int32_t>(CallErrorCode::CALL_ERROR_SEND_REQUEST_FAIL), "satellite call proxy send request fail");
62 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
63 }
64
HangUp(int32_t slotId,int32_t index)65 int32_t SatelliteCallProxy::HangUp(int32_t slotId, int32_t index)
66 {
67 MessageParcel in;
68 if (!in.WriteInterfaceToken(SatelliteCallProxy::GetDescriptor())) {
69 TELEPHONY_LOGE("[slot%{public}d]Write descriptor token fail!", slotId);
70 CellularCallHiSysEvent::WriteHangUpFaultEvent(slotId, INVALID_PARAMETER,
71 TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL, "HangUp satellite call proxy write descriptor token fail");
72 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
73 }
74 if (!in.WriteInt32(slotId)) {
75 TELEPHONY_LOGE("[slot%{public}d]Write mode fail!", slotId);
76 CellularCallHiSysEvent::WriteDialCallFaultEvent(slotId, INVALID_PARAMETER, INVALID_PARAMETER,
77 TELEPHONY_ERR_WRITE_DATA_FAIL, "satellite call proxy write data fail");
78 return TELEPHONY_ERR_WRITE_DATA_FAIL;
79 }
80 if (!in.WriteInt32(index)) {
81 TELEPHONY_LOGE("[slot%{public}d]Write mode fail!", slotId);
82 CellularCallHiSysEvent::WriteDialCallFaultEvent(slotId, INVALID_PARAMETER, INVALID_PARAMETER,
83 TELEPHONY_ERR_WRITE_DATA_FAIL, "satellite call proxy write data fail");
84 return TELEPHONY_ERR_WRITE_DATA_FAIL;
85 }
86 sptr<IRemoteObject> remote = Remote();
87 if (remote == nullptr) {
88 TELEPHONY_LOGE("[slot%{public}d]Remote is null", slotId);
89 return TELEPHONY_ERR_LOCAL_PTR_NULL;
90 }
91 MessageParcel out;
92 MessageOption option;
93 int32_t error =
94 remote->SendRequest(static_cast<int32_t>(SatelliteCallInterfaceCode::SATELLITE_HANG_UP), in, out, option);
95 if (error == ERR_NONE) {
96 return out.ReadInt32();
97 }
98 TELEPHONY_LOGE("[slot%{public}d]SendRequest fail, error:%{public}d", slotId, error);
99 CellularCallHiSysEvent::WriteHangUpFaultEvent(slotId, INVALID_PARAMETER,
100 static_cast<int32_t>(CallErrorCode::CALL_ERROR_SEND_REQUEST_FAIL), "HangUp ims call proxy send request fail");
101 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
102 }
103
Reject(int32_t slotId)104 int32_t SatelliteCallProxy::Reject(int32_t slotId)
105 {
106 MessageParcel in;
107 if (!in.WriteInterfaceToken(SatelliteCallProxy::GetDescriptor())) {
108 TELEPHONY_LOGE("[slot%{public}d]Write descriptor token fail!", slotId);
109 CellularCallHiSysEvent::WriteHangUpFaultEvent(slotId, INVALID_PARAMETER,
110 TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL, "Reject satellite call proxy write descriptor token fail");
111 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
112 }
113 if (!in.WriteInt32(slotId)) {
114 TELEPHONY_LOGE("[slot%{public}d]Write reason fail!", slotId);
115 return TELEPHONY_ERR_WRITE_DATA_FAIL;
116 }
117 sptr<IRemoteObject> remote = Remote();
118 if (remote == nullptr) {
119 TELEPHONY_LOGE("[slot%{public}d]Remote is null", slotId);
120 return TELEPHONY_ERR_LOCAL_PTR_NULL;
121 }
122 MessageParcel out;
123 MessageOption option;
124 int32_t error =
125 remote->SendRequest(static_cast<int32_t>(SatelliteCallInterfaceCode::SATELLITE_REJECT), in, out, option);
126 if (error == ERR_NONE) {
127 return out.ReadInt32();
128 }
129 TELEPHONY_LOGE("[slot%{public}d]SendRequest fail, error:%{public}d", slotId, error);
130 CellularCallHiSysEvent::WriteHangUpFaultEvent(slotId, INVALID_PARAMETER,
131 static_cast<int32_t>(CallErrorCode::CALL_ERROR_SEND_REQUEST_FAIL),
132 "Reject satellite call proxy send request fail");
133 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
134 }
135
Answer(int32_t slotId)136 int32_t SatelliteCallProxy::Answer(int32_t slotId)
137 {
138 MessageParcel in;
139 if (!in.WriteInterfaceToken(SatelliteCallProxy::GetDescriptor())) {
140 TELEPHONY_LOGE("[slot%{public}d]Write descriptor token fail!", slotId);
141 CellularCallHiSysEvent::WriteAnswerCallFaultEvent(slotId, INVALID_PARAMETER, INVALID_PARAMETER,
142 TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL, "satellite call proxy write descriptor token fail");
143 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
144 }
145 if (!in.WriteInt32(slotId)) {
146 TELEPHONY_LOGE("[slot%{public}d]Write reason fail!", slotId);
147 return TELEPHONY_ERR_WRITE_DATA_FAIL;
148 }
149 sptr<IRemoteObject> remote = Remote();
150 if (remote == nullptr) {
151 TELEPHONY_LOGE("[slot%{public}d]Remote is null", slotId);
152 return TELEPHONY_ERR_LOCAL_PTR_NULL;
153 }
154 MessageParcel out;
155 MessageOption option;
156 int32_t error =
157 remote->SendRequest(static_cast<int32_t>(SatelliteCallInterfaceCode::SATELLITE_ANSWER), in, out, option);
158 if (error == ERR_NONE) {
159 return out.ReadInt32();
160 }
161 TELEPHONY_LOGE("[slot%{public}d]SendRequest fail, error:%{public}d", slotId, error);
162 CellularCallHiSysEvent::WriteAnswerCallFaultEvent(slotId, INVALID_PARAMETER, INVALID_PARAMETER,
163 static_cast<int32_t>(CallErrorCode::CALL_ERROR_SEND_REQUEST_FAIL), "satellite call proxy send request fail");
164 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
165 }
166
GetSatelliteCallsDataRequest(int32_t slotId)167 int32_t SatelliteCallProxy::GetSatelliteCallsDataRequest(int32_t slotId)
168 {
169 MessageParcel in;
170 int32_t ret = WriteCommonInfo(slotId, __FUNCTION__, in);
171 if (ret != TELEPHONY_SUCCESS) {
172 return ret;
173 }
174 return SendRequest(slotId, in, static_cast<int32_t>(SatelliteCallInterfaceCode::SATELLITE_GET_CALL_DATA));
175 }
176
RegisterSatelliteCallCallback(const sptr<SatelliteCallCallbackInterface> & callback)177 int32_t SatelliteCallProxy::RegisterSatelliteCallCallback(const sptr<SatelliteCallCallbackInterface> &callback)
178 {
179 if (callback == nullptr) {
180 TELEPHONY_LOGE("callback is null!");
181 return TELEPHONY_ERR_ARGUMENT_INVALID;
182 }
183 MessageParcel in;
184 if (!in.WriteInterfaceToken(SatelliteCallProxy::GetDescriptor())) {
185 TELEPHONY_LOGE("Write descriptor token fail!");
186 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
187 }
188 if (!in.WriteRemoteObject(callback->AsObject().GetRefPtr())) {
189 TELEPHONY_LOGE("Write ImsCallCallbackInterface fail!");
190 return TELEPHONY_ERR_WRITE_DATA_FAIL;
191 }
192 return SendRequest(in, static_cast<int32_t>(SatelliteCallInterfaceCode::SATELLITE_CALL_REGISTER_CALLBACK));
193 }
194
WriteCommonInfo(int32_t slotId,std::string funcName,MessageParcel & in)195 int32_t SatelliteCallProxy::WriteCommonInfo(int32_t slotId, std::string funcName, MessageParcel &in)
196 {
197 if (!in.WriteInterfaceToken(SatelliteCallProxy::GetDescriptor())) {
198 TELEPHONY_LOGE("[slot%{public}d] %{public}s Write descriptor token fail!", slotId, funcName.c_str());
199 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
200 }
201 if (!in.WriteInt32(slotId)) {
202 TELEPHONY_LOGE("[slot%{public}d] %{public}s Write slotId fail!", slotId, funcName.c_str());
203 return TELEPHONY_ERR_WRITE_DATA_FAIL;
204 }
205 return TELEPHONY_SUCCESS;
206 }
207
WriteCommonInfo(int32_t slotId,std::string funcName,MessageParcel & in,int32_t callType)208 int32_t SatelliteCallProxy::WriteCommonInfo(int32_t slotId, std::string funcName, MessageParcel &in, int32_t callType)
209 {
210 int32_t ret = WriteCommonInfo(slotId, funcName, in);
211 if (ret != TELEPHONY_SUCCESS) {
212 return ret;
213 }
214 if (!in.WriteInt32(callType)) {
215 TELEPHONY_LOGE("[slot%{public}d] %{public}s Write callType fail!", slotId, funcName.c_str());
216 return TELEPHONY_ERR_WRITE_DATA_FAIL;
217 }
218 return TELEPHONY_SUCCESS;
219 }
220
SendRequest(MessageParcel & in,int32_t eventId)221 int32_t SatelliteCallProxy::SendRequest(MessageParcel &in, int32_t eventId)
222 {
223 sptr<IRemoteObject> remote = Remote();
224 if (remote == nullptr) {
225 TELEPHONY_LOGE("Remote is null, eventId:%{public}d", eventId);
226 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
227 }
228
229 MessageParcel out;
230 MessageOption option;
231 int32_t error = remote->SendRequest(eventId, in, out, option);
232 if (error == ERR_NONE) {
233 return out.ReadInt32();
234 }
235 TELEPHONY_LOGE("SendRequest fail, eventId:%{public}d, error:%{public}d", eventId, error);
236 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
237 }
238
SendRequest(int32_t slotId,MessageParcel & in,int32_t eventId)239 int32_t SatelliteCallProxy::SendRequest(int32_t slotId, MessageParcel &in, int32_t eventId)
240 {
241 sptr<IRemoteObject> remote = Remote();
242 if (remote == nullptr) {
243 TELEPHONY_LOGE("[slot%{public}d]Remote is null, eventId:%{public}d", slotId, eventId);
244 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
245 }
246
247 MessageParcel out;
248 MessageOption option;
249 int32_t error = remote->SendRequest(eventId, in, out, option);
250 if (error == ERR_NONE) {
251 return out.ReadInt32();
252 }
253 TELEPHONY_LOGE("[slot%{public}d]SendRequest fail, eventId:%{public}d, error:%{public}d", slotId, eventId, error);
254 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
255 }
256 } // namespace Telephony
257 } // namespace OHOS