1 /*
2 * Copyright (C) 2021-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 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "bluetooth_call_proxy.h"
17
18 #include "message_option.h"
19 #include "message_parcel.h"
20
21 #include "call_manager_errors.h"
22
23 namespace OHOS {
24 namespace Telephony {
25 static const int32_t MAX_SIZE = 10000;
BluetoothCallProxy(const sptr<IRemoteObject> & impl)26 BluetoothCallProxy::BluetoothCallProxy(const sptr<IRemoteObject> &impl)
27 : IRemoteProxy<IBluetoothCall>(impl)
28 {}
29
AnswerCall()30 int32_t BluetoothCallProxy::AnswerCall()
31 {
32 MessageOption option;
33 MessageParcel dataParcel;
34 MessageParcel replyParcel;
35 if (!dataParcel.WriteInterfaceToken(BluetoothCallProxy::GetDescriptor())) {
36 TELEPHONY_LOGE("write descriptor fail");
37 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
38 }
39 if (Remote() == nullptr) {
40 TELEPHONY_LOGE("function Remote() return nullptr!");
41 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
42 }
43 int32_t error = Remote()->SendRequest(static_cast<int32_t>(BluetoothCallInterfaceCode::INTERFACE_BT_ANSWER_CALL),
44 dataParcel, replyParcel, option);
45 if (error != TELEPHONY_SUCCESS) {
46 TELEPHONY_LOGE("function AnswerCall call failed! errCode:%{public}d", error);
47 return error;
48 }
49 return replyParcel.ReadInt32();
50 }
51
RejectCall()52 int32_t BluetoothCallProxy::RejectCall()
53 {
54 MessageOption option;
55 MessageParcel dataParcel;
56 MessageParcel replyParcel;
57 if (!dataParcel.WriteInterfaceToken(BluetoothCallProxy::GetDescriptor())) {
58 TELEPHONY_LOGE("write descriptor fail");
59 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
60 }
61 if (Remote() == nullptr) {
62 TELEPHONY_LOGE("function Remote() return nullptr!");
63 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
64 }
65 int32_t error = Remote()->SendRequest(static_cast<int32_t>(BluetoothCallInterfaceCode::INTERFACE_BT_REJECT_CALL),
66 dataParcel, replyParcel, option);
67 if (error != TELEPHONY_SUCCESS) {
68 TELEPHONY_LOGE("function RejectCall call failed! errCode:%{public}d", error);
69 return error;
70 }
71 return replyParcel.ReadInt32();
72 }
73
HangUpCall()74 int32_t BluetoothCallProxy::HangUpCall()
75 {
76 MessageOption option;
77 MessageParcel dataParcel;
78 MessageParcel replyParcel;
79 if (!dataParcel.WriteInterfaceToken(BluetoothCallProxy::GetDescriptor())) {
80 TELEPHONY_LOGE("write descriptor fail");
81 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
82 }
83 if (Remote() == nullptr) {
84 TELEPHONY_LOGE("function Remote() return nullptr!");
85 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
86 }
87 int32_t error = Remote()->SendRequest(
88 static_cast<int32_t>(BluetoothCallInterfaceCode::INTERFACE_BT_DISCONNECT_CALL), dataParcel,
89 replyParcel, option);
90 if (error != TELEPHONY_SUCCESS) {
91 TELEPHONY_LOGE("function HangUpCall call failed! errCode:%{public}d", error);
92 return error;
93 }
94 return replyParcel.ReadInt32();
95 }
96
GetCallState()97 int32_t BluetoothCallProxy::GetCallState()
98 {
99 MessageOption option;
100 MessageParcel dataParcel;
101 MessageParcel replyParcel;
102 if (!dataParcel.WriteInterfaceToken(BluetoothCallProxy::GetDescriptor())) {
103 TELEPHONY_LOGE("write descriptor fail");
104 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
105 }
106 if (Remote() == nullptr) {
107 TELEPHONY_LOGE("function Remote() return nullptr!");
108 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
109 }
110 int32_t error = Remote()->SendRequest(static_cast<int32_t>(BluetoothCallInterfaceCode::INTERFACE_BT_GET_CALL_STATE),
111 dataParcel, replyParcel, option);
112 if (error != TELEPHONY_SUCCESS) {
113 TELEPHONY_LOGE("function GetCallState! errCode:%{public}d", error);
114 return error;
115 }
116 return replyParcel.ReadInt32();
117 }
118
HoldCall()119 int32_t BluetoothCallProxy::HoldCall()
120 {
121 MessageOption option;
122 MessageParcel dataParcel;
123 MessageParcel replyParcel;
124 if (!dataParcel.WriteInterfaceToken(BluetoothCallProxy::GetDescriptor())) {
125 TELEPHONY_LOGE("write descriptor fail");
126 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
127 }
128 if (Remote() == nullptr) {
129 TELEPHONY_LOGE("function Remote() return nullptr!");
130 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
131 }
132 int32_t error = Remote()->SendRequest(static_cast<int32_t>(BluetoothCallInterfaceCode::INTERFACE_BT_HOLD_CALL),
133 dataParcel, replyParcel, option);
134 if (error != TELEPHONY_SUCCESS) {
135 TELEPHONY_LOGE("Function HoldCall call failed! errCode:%{public}d", error);
136 return error;
137 }
138 return replyParcel.ReadInt32();
139 }
140
UnHoldCall()141 int32_t BluetoothCallProxy::UnHoldCall()
142 {
143 MessageOption option;
144 MessageParcel dataParcel;
145 MessageParcel replyParcel;
146 if (!dataParcel.WriteInterfaceToken(BluetoothCallProxy::GetDescriptor())) {
147 TELEPHONY_LOGE("write descriptor fail");
148 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
149 }
150 if (Remote() == nullptr) {
151 TELEPHONY_LOGE("function Remote() return nullptr!");
152 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
153 }
154 int32_t error = Remote()->SendRequest(static_cast<int32_t>(BluetoothCallInterfaceCode::INTERFACE_BT_UNHOLD_CALL),
155 dataParcel, replyParcel, option);
156 if (error != TELEPHONY_SUCCESS) {
157 TELEPHONY_LOGE("Function UnHoldCall call failed! errCode:%{public}d", error);
158 return error;
159 }
160 return replyParcel.ReadInt32();
161 }
162
SwitchCall()163 int32_t BluetoothCallProxy::SwitchCall()
164 {
165 MessageOption option;
166 MessageParcel dataParcel;
167 MessageParcel replyParcel;
168 if (!dataParcel.WriteInterfaceToken(BluetoothCallProxy::GetDescriptor())) {
169 TELEPHONY_LOGE("write descriptor fail");
170 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
171 }
172 if (Remote() == nullptr) {
173 TELEPHONY_LOGE("function Remote() return nullptr!");
174 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
175 }
176 int32_t error = Remote()->SendRequest(static_cast<int32_t>(BluetoothCallInterfaceCode::INTERFACE_BT_SWAP_CALL),
177 dataParcel, replyParcel, option);
178 if (error != TELEPHONY_SUCCESS) {
179 TELEPHONY_LOGE("Function UnHoldCall call failed! errCode:%{public}d", error);
180 return error;
181 }
182 return replyParcel.ReadInt32();
183 }
184
StartDtmf(char str)185 int32_t BluetoothCallProxy::StartDtmf(char str)
186 {
187 MessageOption option;
188 MessageParcel dataParcel;
189 MessageParcel replyParcel;
190 if (!dataParcel.WriteInterfaceToken(BluetoothCallProxy::GetDescriptor())) {
191 TELEPHONY_LOGE("write descriptor fail");
192 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
193 }
194 if (Remote() == nullptr) {
195 TELEPHONY_LOGE("function Remote() return nullptr!");
196 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
197 }
198 dataParcel.WriteInt8(str);
199 int32_t error = Remote()->SendRequest(static_cast<int32_t>(BluetoothCallInterfaceCode::INTERFACE_BT_START_DTMF),
200 dataParcel, replyParcel, option);
201 if (error != TELEPHONY_SUCCESS) {
202 TELEPHONY_LOGE("Function StartDtmf! errCode:%{public}d", error);
203 return error;
204 }
205 return replyParcel.ReadInt32();
206 }
207
StopDtmf()208 int32_t BluetoothCallProxy::StopDtmf()
209 {
210 MessageOption option;
211 MessageParcel dataParcel;
212 MessageParcel replyParcel;
213 if (!dataParcel.WriteInterfaceToken(BluetoothCallProxy::GetDescriptor())) {
214 TELEPHONY_LOGE("write descriptor fail");
215 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
216 }
217 if (Remote() == nullptr) {
218 TELEPHONY_LOGE("function Remote() return nullptr!");
219 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
220 }
221 int32_t error = Remote()->SendRequest(static_cast<int32_t>(BluetoothCallInterfaceCode::INTERFACE_BT_STOP_DTMF),
222 dataParcel, replyParcel, option);
223 if (error != TELEPHONY_SUCCESS) {
224 TELEPHONY_LOGE("Function StopDtmf! errCode:%{public}d", error);
225 return error;
226 }
227 return replyParcel.ReadInt32();
228 }
229
CombineConference()230 int32_t BluetoothCallProxy::CombineConference()
231 {
232 MessageOption option;
233 MessageParcel dataParcel;
234 MessageParcel replyParcel;
235 if (!dataParcel.WriteInterfaceToken(BluetoothCallProxy::GetDescriptor())) {
236 TELEPHONY_LOGE("write descriptor fail");
237 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
238 }
239 if (Remote() == nullptr) {
240 TELEPHONY_LOGE("function Remote() return nullptr!");
241 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
242 }
243 int32_t error = Remote()->SendRequest(
244 static_cast<int32_t>(BluetoothCallInterfaceCode::INTERFACE_BT_COMBINE_CONFERENCE), dataParcel,
245 replyParcel, option);
246 if (error != TELEPHONY_SUCCESS) {
247 TELEPHONY_LOGE("Function CombineConference failed! errCode:%{public}d", error);
248 return error;
249 }
250 return replyParcel.ReadInt32();
251 }
252
SeparateConference()253 int32_t BluetoothCallProxy::SeparateConference()
254 {
255 MessageOption option;
256 MessageParcel dataParcel;
257 MessageParcel replyParcel;
258 if (!dataParcel.WriteInterfaceToken(BluetoothCallProxy::GetDescriptor())) {
259 TELEPHONY_LOGE("write descriptor fail");
260 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
261 }
262 if (Remote() == nullptr) {
263 TELEPHONY_LOGE("function Remote() return nullptr!");
264 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
265 }
266 int32_t error = Remote()->SendRequest(
267 static_cast<int32_t>(BluetoothCallInterfaceCode::INTERFACE_BT_SEPARATE_CONFERENCE), dataParcel,
268 replyParcel, option);
269 if (error != TELEPHONY_SUCCESS) {
270 TELEPHONY_LOGE("Function SeparateConference call failed! errCode:%{public}d", error);
271 return error;
272 }
273 return replyParcel.ReadInt32();
274 }
275
KickOutFromConference()276 int32_t BluetoothCallProxy::KickOutFromConference()
277 {
278 MessageOption option;
279 MessageParcel dataParcel;
280 MessageParcel replyParcel;
281 if (!dataParcel.WriteInterfaceToken(BluetoothCallProxy::GetDescriptor())) {
282 TELEPHONY_LOGE("write descriptor fail");
283 return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
284 }
285 if (Remote() == nullptr) {
286 TELEPHONY_LOGE("function Remote() return nullptr!");
287 return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
288 }
289 int32_t error = Remote()->SendRequest(
290 static_cast<int32_t>(BluetoothCallInterfaceCode::INTERFACE_BT_KICK_OUT_CONFERENCE), dataParcel,
291 replyParcel, option);
292 if (error != TELEPHONY_SUCCESS) {
293 TELEPHONY_LOGE("Function KickOutFromConference call failed! errCode:%{public}d", error);
294 return error;
295 }
296 return replyParcel.ReadInt32();
297 }
298
GetCurrentCallList(int32_t slotId)299 std::vector<CallAttributeInfo> BluetoothCallProxy::GetCurrentCallList(int32_t slotId)
300 {
301 std::vector<CallAttributeInfo> callVec;
302 MessageOption option;
303 MessageParcel dataParcel;
304 MessageParcel replyParcel;
305 if (!dataParcel.WriteInterfaceToken(BluetoothCallProxy::GetDescriptor())) {
306 TELEPHONY_LOGE("write descriptor fail");
307 return callVec;
308 }
309 dataParcel.WriteInt32(slotId);
310 if (Remote() == nullptr) {
311 TELEPHONY_LOGE("function Remote() return nullptr!");
312 return callVec;
313 }
314 int32_t error = Remote()->SendRequest(
315 static_cast<int32_t>(BluetoothCallInterfaceCode::INTERFACE_BT_GET_CURRENT_CALL_LIST), dataParcel,
316 replyParcel, option);
317 if (error != TELEPHONY_SUCCESS) {
318 TELEPHONY_LOGE("Function GetCurrentCallList call failed! errCode:%{public}d", error);
319 return callVec;
320 }
321 int32_t vecCnt = replyParcel.ReadInt32();
322 if (vecCnt <= 0 || vecCnt >= MAX_SIZE) {
323 TELEPHONY_LOGE("vector size is error");
324 return callVec;
325 }
326 for (int32_t i = 0; i < vecCnt; i++) {
327 auto value = reinterpret_cast<const CallAttributeInfo *>(replyParcel.ReadRawData(sizeof(CallAttributeInfo)));
328 if (value == nullptr) {
329 TELEPHONY_LOGE("data error");
330 return callVec;
331 }
332 callVec.push_back(*value);
333 }
334 return callVec;
335 }
336 } // namespace Telephony
337 } // namespace OHOS
338