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 "bluetooth_hfp_ag_proxy.h"
17 #include "bluetooth_errorcode.h"
18 #include "bluetooth_log.h"
19
20 namespace OHOS {
21 namespace Bluetooth {
22 #define MAX_HFP_VIRTUAL_DEVICE 10
GetConnectDevices(std::vector<BluetoothRawAddress> &devices)23 int32_t BluetoothHfpAgProxy::GetConnectDevices(std::vector<BluetoothRawAddress> &devices)
24 {
25 MessageParcel data;
26 CHECK_AND_RETURN_LOG_RET(data.WriteInterfaceToken(BluetoothHfpAgProxy::GetDescriptor()),
27 BT_ERR_IPC_TRANS_FAILED, "WriteInterfaceToken error");
28
29 MessageParcel reply;
30 MessageOption option(MessageOption::TF_SYNC);
31
32 SEND_IPC_REQUEST_RETURN_RESULT(BluetoothHfpAgInterfaceCode::BT_HFP_AG_GET_CONNECT_DEVICES,
33 data, reply, option, BT_ERR_IPC_TRANS_FAILED);
34
35 uint32_t DevNum = reply.ReadUint32();
36 for (uint32_t i = 0; i < DevNum; i++) {
37 std::shared_ptr<BluetoothRawAddress> dev(reply.ReadParcelable<BluetoothRawAddress>());
38 if (!dev) {
39 return BT_ERR_IPC_TRANS_FAILED;
40 }
41 devices.push_back(*dev);
42 }
43 return BT_NO_ERROR;
44 }
45
GetDevicesByStates(const std::vector<int> &states, std::vector<BluetoothRawAddress> &devices)46 int BluetoothHfpAgProxy::GetDevicesByStates(const std::vector<int> &states, std::vector<BluetoothRawAddress> &devices)
47 {
48 MessageParcel data;
49 CHECK_AND_RETURN_LOG_RET(data.WriteInterfaceToken(BluetoothHfpAgProxy::GetDescriptor()),
50 BT_ERR_IPC_TRANS_FAILED, "WriteInterfaceToken error");
51 CHECK_AND_RETURN_LOG_RET(data.WriteInt32Vector(states), BT_ERR_IPC_TRANS_FAILED, "write states error");
52
53 MessageParcel reply;
54 MessageOption option(MessageOption::TF_SYNC);
55
56 SEND_IPC_REQUEST_RETURN_RESULT(BluetoothHfpAgInterfaceCode::BT_HFP_AG_GET_DEVICES_BY_STATES,
57 data, reply, option, BT_ERR_IPC_TRANS_FAILED);
58
59 uint32_t DevNum = reply.ReadUint32();
60 for (uint32_t i = 0; i < DevNum; i++) {
61 std::shared_ptr<BluetoothRawAddress> dev(reply.ReadParcelable<BluetoothRawAddress>());
62 if (!dev) {
63 return BT_ERR_IPC_TRANS_FAILED;
64 }
65 devices.push_back(*dev);
66 }
67 return BT_NO_ERROR;
68 }
GetDeviceState(const BluetoothRawAddress &device, int32_t &state)69 int32_t BluetoothHfpAgProxy::GetDeviceState(const BluetoothRawAddress &device, int32_t &state)
70 {
71 MessageParcel data;
72 CHECK_AND_RETURN_LOG_RET(data.WriteInterfaceToken(BluetoothHfpAgProxy::GetDescriptor()),
73 BT_ERR_IPC_TRANS_FAILED, "WriteInterfaceToken error");
74 CHECK_AND_RETURN_LOG_RET(data.WriteParcelable(&device), BT_ERR_IPC_TRANS_FAILED, "write device error");
75
76 MessageParcel reply;
77 MessageOption option(MessageOption::TF_SYNC);
78
79 SEND_IPC_REQUEST_RETURN_RESULT(BluetoothHfpAgInterfaceCode::BT_HFP_AG_GET_DEVICE_STATE,
80 data, reply, option, BT_ERR_IPC_TRANS_FAILED);
81
82 // read error code
83 int32_t errCode = reply.ReadInt32();
84 if (errCode != BT_NO_ERROR) {
85 HILOGE("reply errCode: %{public}d", errCode);
86 return errCode;
87 }
88 // read state
89 state = reply.ReadInt32();
90 return BT_NO_ERROR;
91 }
92
Connect(const BluetoothRawAddress &device)93 int32_t BluetoothHfpAgProxy::Connect(const BluetoothRawAddress &device)
94 {
95 MessageParcel data;
96 CHECK_AND_RETURN_LOG_RET(data.WriteInterfaceToken(BluetoothHfpAgProxy::GetDescriptor()),
97 BT_ERR_IPC_TRANS_FAILED, "WriteInterfaceToken error");
98 CHECK_AND_RETURN_LOG_RET(data.WriteParcelable(&device), BT_ERR_IPC_TRANS_FAILED, "write device error");
99
100 MessageParcel reply;
101 MessageOption option(MessageOption::TF_SYNC);
102
103 SEND_IPC_REQUEST_RETURN_RESULT(BluetoothHfpAgInterfaceCode::BT_HFP_AG_CONNECT,
104 data, reply, option, BT_ERR_IPC_TRANS_FAILED);
105
106 return reply.ReadInt32();
107 }
108
Disconnect(const BluetoothRawAddress &device)109 int32_t BluetoothHfpAgProxy::Disconnect(const BluetoothRawAddress &device)
110 {
111 MessageParcel data;
112 CHECK_AND_RETURN_LOG_RET(data.WriteInterfaceToken(BluetoothHfpAgProxy::GetDescriptor()),
113 BT_ERR_IPC_TRANS_FAILED, "WriteInterfaceToken error");
114 CHECK_AND_RETURN_LOG_RET(data.WriteParcelable(&device), BT_ERR_IPC_TRANS_FAILED, "write device error");
115
116 MessageParcel reply;
117 MessageOption option(MessageOption::TF_SYNC);
118
119 SEND_IPC_REQUEST_RETURN_RESULT(BluetoothHfpAgInterfaceCode::BT_HFP_AG_DISCONNECT,
120 data, reply, option, BT_ERR_IPC_TRANS_FAILED);
121
122 return reply.ReadInt32();
123 }
124
GetScoState(const BluetoothRawAddress &device)125 int BluetoothHfpAgProxy::GetScoState(const BluetoothRawAddress &device)
126 {
127 MessageParcel data;
128 CHECK_AND_RETURN_LOG_RET(data.WriteInterfaceToken(BluetoothHfpAgProxy::GetDescriptor()),
129 BT_ERR_IPC_TRANS_FAILED, "WriteInterfaceToken error");
130 CHECK_AND_RETURN_LOG_RET(data.WriteParcelable(&device), BT_ERR_IPC_TRANS_FAILED, "write device error");
131
132 MessageParcel reply;
133 MessageOption option(MessageOption::TF_SYNC);
134
135 SEND_IPC_REQUEST_RETURN_RESULT(BluetoothHfpAgInterfaceCode::BT_HFP_AG_GET_SCO_STATE,
136 data, reply, option, BT_ERR_IPC_TRANS_FAILED);
137
138 return reply.ReadInt32();
139 }
140
ConnectSco(uint8_t callType)141 int32_t BluetoothHfpAgProxy::ConnectSco(uint8_t callType)
142 {
143 MessageParcel data;
144 CHECK_AND_RETURN_LOG_RET(data.WriteInterfaceToken(BluetoothHfpAgProxy::GetDescriptor()),
145 BT_ERR_IPC_TRANS_FAILED, "WriteInterfaceToken error");
146 CHECK_AND_RETURN_LOG_RET(data.WriteUint8(callType), BT_ERR_IPC_TRANS_FAILED, "write callType error");
147
148 MessageParcel reply;
149 MessageOption option(MessageOption::TF_SYNC);
150
151 SEND_IPC_REQUEST_RETURN_RESULT(BluetoothHfpAgInterfaceCode::BT_HFP_AG_CONNECT_SCO_EX,
152 data, reply, option, BT_ERR_IPC_TRANS_FAILED);
153
154 return reply.ReadInt32();
155 }
156
DisconnectSco(uint8_t callType)157 int32_t BluetoothHfpAgProxy::DisconnectSco(uint8_t callType)
158 {
159 MessageParcel data;
160 CHECK_AND_RETURN_LOG_RET(data.WriteInterfaceToken(BluetoothHfpAgProxy::GetDescriptor()),
161 BT_ERR_IPC_TRANS_FAILED, "WriteInterfaceToken error");
162 CHECK_AND_RETURN_LOG_RET(data.WriteUint8(callType), BT_ERR_IPC_TRANS_FAILED, "write callType error");
163
164 MessageParcel reply;
165 MessageOption option(MessageOption::TF_SYNC);
166
167 SEND_IPC_REQUEST_RETURN_RESULT(BluetoothHfpAgInterfaceCode::BT_HFP_AG_DISCONNECT_SCO_EX,
168 data, reply, option, BT_ERR_IPC_TRANS_FAILED);
169
170 return reply.ReadInt32();
171 }
172
ConnectSco()173 bool BluetoothHfpAgProxy::ConnectSco()
174 {
175 MessageParcel data;
176 CHECK_AND_RETURN_LOG_RET(data.WriteInterfaceToken(BluetoothHfpAgProxy::GetDescriptor()),
177 false, "WriteInterfaceToken error");
178
179 MessageParcel reply;
180 MessageOption option(MessageOption::TF_SYNC);
181 SEND_IPC_REQUEST_RETURN_RESULT(BluetoothHfpAgInterfaceCode::BT_HFP_AG_CONNECT_SCO, data, reply, option, false);
182
183 return reply.ReadBool();
184 }
185
DisconnectSco()186 bool BluetoothHfpAgProxy::DisconnectSco()
187 {
188 MessageParcel data;
189 CHECK_AND_RETURN_LOG_RET(data.WriteInterfaceToken(BluetoothHfpAgProxy::GetDescriptor()),
190 false, "WriteInterfaceToken error");
191
192 MessageParcel reply;
193 MessageOption option(MessageOption::TF_SYNC);
194
195 SEND_IPC_REQUEST_RETURN_RESULT(BluetoothHfpAgInterfaceCode::BT_HFP_AG_DISCONNECT_SCO, data, reply, option, false);
196
197 return reply.ReadBool();
198 }
199
PhoneStateChanged(BluetoothPhoneState &phoneState)200 void BluetoothHfpAgProxy::PhoneStateChanged(BluetoothPhoneState &phoneState)
201 {
202 MessageParcel data;
203 CHECK_AND_RETURN_LOG(data.WriteInterfaceToken(BluetoothHfpAgProxy::GetDescriptor()), "WriteInterfaceToken error");
204 CHECK_AND_RETURN_LOG(data.WriteParcelable(&phoneState), "write phoneState error");
205 MessageParcel reply;
206 MessageOption option(MessageOption::TF_SYNC);
207
208 SEND_IPC_REQUEST_RETURN(BluetoothHfpAgInterfaceCode::BT_HFP_AG_PHONE_STATE_CHANGED, data, reply, option);
209 }
210
ClccResponse( int index, int direction, int status, int mode, bool mpty, const std::string &number, int type)211 void BluetoothHfpAgProxy::ClccResponse(
212 int index, int direction, int status, int mode, bool mpty, const std::string &number, int type)
213 {
214 MessageParcel data;
215 CHECK_AND_RETURN_LOG(data.WriteInterfaceToken(BluetoothHfpAgProxy::GetDescriptor()), "WriteInterfaceToken error");
216 CHECK_AND_RETURN_LOG(data.WriteInt32(index), "write index error");
217 CHECK_AND_RETURN_LOG(data.WriteInt32(direction), "write direction error");
218 CHECK_AND_RETURN_LOG(data.WriteInt32(status), "write status error");
219 CHECK_AND_RETURN_LOG(data.WriteInt32(mode), "write mode error");
220 CHECK_AND_RETURN_LOG(data.WriteBool(mpty), "write mpty error");
221 CHECK_AND_RETURN_LOG(data.WriteString(number), "write number error");
222 CHECK_AND_RETURN_LOG(data.WriteInt32(type), "write type error");
223
224 MessageParcel reply;
225 MessageOption option(MessageOption::TF_SYNC);
226
227 SEND_IPC_REQUEST_RETURN(BluetoothHfpAgInterfaceCode::BT_HFP_AG_CLCC_RESPONSE, data, reply, option);
228 }
229
OpenVoiceRecognition(const BluetoothRawAddress &device)230 bool BluetoothHfpAgProxy::OpenVoiceRecognition(const BluetoothRawAddress &device)
231 {
232 MessageParcel data;
233 CHECK_AND_RETURN_LOG_RET(data.WriteInterfaceToken(BluetoothHfpAgProxy::GetDescriptor()),
234 false, "WriteInterfaceToken error");
235 CHECK_AND_RETURN_LOG_RET(data.WriteParcelable(&device), false, "write device error");
236
237 MessageParcel reply;
238 MessageOption option(MessageOption::TF_SYNC);
239
240 SEND_IPC_REQUEST_RETURN_RESULT(BluetoothHfpAgInterfaceCode::BT_HFP_AG_OPEN_VOICE_RECOGNITION,
241 data, reply, option, false);
242
243 return reply.ReadBool();
244 }
245
CloseVoiceRecognition(const BluetoothRawAddress &device)246 bool BluetoothHfpAgProxy::CloseVoiceRecognition(const BluetoothRawAddress &device)
247 {
248 MessageParcel data;
249 CHECK_AND_RETURN_LOG_RET(data.WriteInterfaceToken(BluetoothHfpAgProxy::GetDescriptor()),
250 false, "WriteInterfaceToken error");
251 CHECK_AND_RETURN_LOG_RET(data.WriteParcelable(&device), false, "write device error");
252
253 MessageParcel reply;
254 MessageOption option(MessageOption::TF_SYNC);
255
256 SEND_IPC_REQUEST_RETURN_RESULT(BluetoothHfpAgInterfaceCode::BT_HFP_AG_CLOSE_VOICE_RECOGNITION,
257 data, reply, option, false);
258
259 return reply.ReadBool();
260 }
261
SetActiveDevice(const BluetoothRawAddress &device)262 bool BluetoothHfpAgProxy::SetActiveDevice(const BluetoothRawAddress &device)
263 {
264 MessageParcel data;
265 CHECK_AND_RETURN_LOG_RET(data.WriteInterfaceToken(BluetoothHfpAgProxy::GetDescriptor()),
266 false, "WriteInterfaceToken error");
267 CHECK_AND_RETURN_LOG_RET(data.WriteParcelable(&device), false, "write device error");
268
269 MessageParcel reply;
270 MessageOption option(MessageOption::TF_SYNC);
271
272 SEND_IPC_REQUEST_RETURN_RESULT(
273 BluetoothHfpAgInterfaceCode::BT_HFP_AG_SET_ACTIVE_DEVICE, data, reply, option, false);
274
275 return reply.ReadBool();
276 }
277
IntoMock(const BluetoothRawAddress &device, int state)278 bool BluetoothHfpAgProxy::IntoMock(const BluetoothRawAddress &device, int state)
279 {
280 MessageParcel data;
281 CHECK_AND_RETURN_LOG_RET(data.WriteInterfaceToken(BluetoothHfpAgProxy::GetDescriptor()),
282 false, "WriteInterfaceToken error");
283 CHECK_AND_RETURN_LOG_RET(data.WriteParcelable(&device), false, "write device error");
284 CHECK_AND_RETURN_LOG_RET(data.WriteInt32(state), false, "write state error");
285
286 MessageParcel reply;
287 MessageOption option(MessageOption::TF_SYNC);
288
289 SEND_IPC_REQUEST_RETURN_RESULT(BluetoothHfpAgInterfaceCode::BT_HFP_AG_INTO_MOCK, data, reply, option, false);
290
291 return reply.ReadBool();
292 }
293
SendNoCarrier(const BluetoothRawAddress &device)294 bool BluetoothHfpAgProxy::SendNoCarrier(const BluetoothRawAddress &device)
295 {
296 MessageParcel data;
297 CHECK_AND_RETURN_LOG_RET(data.WriteInterfaceToken(BluetoothHfpAgProxy::GetDescriptor()),
298 false, "WriteInterfaceToken error");
299 CHECK_AND_RETURN_LOG_RET(data.WriteParcelable(&device), false, "write device error");
300
301 MessageParcel reply;
302 MessageOption option(MessageOption::TF_SYNC);
303
304 SEND_IPC_REQUEST_RETURN_RESULT(BluetoothHfpAgInterfaceCode::BT_HFP_AG_SEND_NO_CARRIER, data, reply, option, false);
305
306 return reply.ReadBool();
307 }
308
GetActiveDevice()309 std::string BluetoothHfpAgProxy::GetActiveDevice()
310 {
311 MessageParcel data;
312 CHECK_AND_RETURN_LOG_RET(
313 data.WriteInterfaceToken(BluetoothHfpAgProxy::GetDescriptor()), "", "WriteInterfaceToken error");
314
315 MessageParcel reply;
316 MessageOption option(MessageOption::TF_SYNC);
317
318 SEND_IPC_REQUEST_RETURN_RESULT(BluetoothHfpAgInterfaceCode::BT_HFP_AG_GET_ACTIVE_DEVICE, data, reply, option, "");
319
320 return reply.ReadString();
321 }
322
SetConnectStrategy(const BluetoothRawAddress &device, int strategy)323 int BluetoothHfpAgProxy::SetConnectStrategy(const BluetoothRawAddress &device, int strategy)
324 {
325 MessageParcel data;
326 CHECK_AND_RETURN_LOG_RET(data.WriteInterfaceToken(BluetoothHfpAgProxy::GetDescriptor()),
327 BT_ERR_IPC_TRANS_FAILED, "WriteInterfaceToken error");
328 CHECK_AND_RETURN_LOG_RET(data.WriteParcelable(&device), BT_ERR_IPC_TRANS_FAILED, "write device error");
329 CHECK_AND_RETURN_LOG_RET(data.WriteInt32(strategy), BT_ERR_IPC_TRANS_FAILED, "write strategy error");
330
331 MessageParcel reply;
332 MessageOption option(MessageOption::TF_SYNC);
333
334 SEND_IPC_REQUEST_RETURN_RESULT(BluetoothHfpAgInterfaceCode::BT_HFP_AG_SET_CONNECT_STRATEGY,
335 data, reply, option, BT_ERR_IPC_TRANS_FAILED);
336
337 return reply.ReadInt32();
338 }
339
GetConnectStrategy(const BluetoothRawAddress &device, int &strategy)340 int BluetoothHfpAgProxy::GetConnectStrategy(const BluetoothRawAddress &device, int &strategy)
341 {
342 MessageParcel data;
343 CHECK_AND_RETURN_LOG_RET(data.WriteInterfaceToken(BluetoothHfpAgProxy::GetDescriptor()),
344 BT_ERR_IPC_TRANS_FAILED, "WriteInterfaceToken error");
345 CHECK_AND_RETURN_LOG_RET(data.WriteParcelable(&device), BT_ERR_IPC_TRANS_FAILED, "write device error");
346
347 MessageParcel reply;
348 MessageOption option(MessageOption::TF_SYNC);
349
350 SEND_IPC_REQUEST_RETURN_RESULT(BluetoothHfpAgInterfaceCode::BT_HFP_AG_GET_CONNECT_STRATEGY,
351 data, reply, option, BT_ERR_IPC_TRANS_FAILED);
352
353 int32_t res = reply.ReadInt32();
354 if (res == NO_ERROR) {
355 strategy = reply.ReadInt32();
356 }
357
358 return res;
359 }
360
IsInbandRingingEnabled(bool &isEnabled)361 int BluetoothHfpAgProxy::IsInbandRingingEnabled(bool &isEnabled)
362 {
363 MessageParcel data;
364 CHECK_AND_RETURN_LOG_RET(data.WriteInterfaceToken(BluetoothHfpAgProxy::GetDescriptor()),
365 BT_ERR_IPC_TRANS_FAILED, "WriteInterfaceToken error");
366
367 MessageParcel reply;
368 MessageOption option(MessageOption::TF_SYNC);
369
370 SEND_IPC_REQUEST_RETURN_RESULT(BluetoothHfpAgInterfaceCode::BT_HFP_AG_IS_IN_BAND_RINGING_ENABLE,
371 data, reply, option, BT_ERR_IPC_TRANS_FAILED);
372
373 int ret = reply.ReadInt32();
374 isEnabled = reply.ReadBool();
375 return ret;
376 }
377
CallDetailsChanged(int callId, int callState)378 void BluetoothHfpAgProxy::CallDetailsChanged(int callId, int callState)
379 {
380 MessageParcel data;
381 CHECK_AND_RETURN_LOG(data.WriteInterfaceToken(BluetoothHfpAgProxy::GetDescriptor()), "WriteInterfaceToken error");
382 CHECK_AND_RETURN_LOG(data.WriteInt32(callId), "write callId error");
383 CHECK_AND_RETURN_LOG(data.WriteInt32(callState), "write callState error");
384
385 MessageParcel reply;
386 MessageOption option(MessageOption::TF_SYNC);
387
388 SEND_IPC_REQUEST_RETURN(BluetoothHfpAgInterfaceCode::BT_HFP_AG_CALL_DETAILS_CHANGED, data, reply, option);
389 }
390
IsVgsSupported(const BluetoothRawAddress &device, bool &isSupported)391 int BluetoothHfpAgProxy::IsVgsSupported(const BluetoothRawAddress &device, bool &isSupported)
392 {
393 MessageParcel data;
394 CHECK_AND_RETURN_LOG_RET(data.WriteInterfaceToken(BluetoothHfpAgProxy::GetDescriptor()),
395 BT_ERR_IPC_TRANS_FAILED, "WriteInterfaceToken error");
396 CHECK_AND_RETURN_LOG_RET(data.WriteParcelable(&device), BT_ERR_IPC_TRANS_FAILED, "write device error");
397
398 MessageParcel reply;
399 MessageOption option(MessageOption::TF_SYNC);
400
401 SEND_IPC_REQUEST_RETURN_RESULT(BluetoothHfpAgInterfaceCode::BT_HFP_AG_IS_VGS_SUPPORTED,
402 data, reply, option, BT_ERR_IPC_TRANS_FAILED);
403
404 int32_t res = reply.ReadInt32();
405 if (res == NO_ERROR) {
406 isSupported = reply.ReadBool();
407 }
408
409 return res;
410 }
411
RegisterObserver(const sptr<IBluetoothHfpAgObserver> &observer)412 void BluetoothHfpAgProxy::RegisterObserver(const sptr<IBluetoothHfpAgObserver> &observer)
413 {
414 MessageParcel data;
415 CHECK_AND_RETURN_LOG(data.WriteInterfaceToken(BluetoothHfpAgProxy::GetDescriptor()), "WriteInterfaceToken error");
416 CHECK_AND_RETURN_LOG(data.WriteRemoteObject(observer->AsObject()), "write object error");
417
418 MessageParcel reply;
419 MessageOption option(MessageOption::TF_SYNC);
420
421 SEND_IPC_REQUEST_RETURN(BluetoothHfpAgInterfaceCode::BT_HFP_AG_REGISTER_OBSERVER, data, reply, option);
422 }
423
DeregisterObserver(const sptr<IBluetoothHfpAgObserver> &observer)424 void BluetoothHfpAgProxy::DeregisterObserver(const sptr<IBluetoothHfpAgObserver> &observer)
425 {
426 MessageParcel data;
427 CHECK_AND_RETURN_LOG(data.WriteInterfaceToken(BluetoothHfpAgProxy::GetDescriptor()), "WriteInterfaceToken error");
428 CHECK_AND_RETURN_LOG(data.WriteRemoteObject(observer->AsObject()), "write object error");
429
430 MessageParcel reply;
431 MessageOption option(MessageOption::TF_SYNC);
432
433 SEND_IPC_REQUEST_RETURN(BluetoothHfpAgInterfaceCode::BT_HFP_AG_DEREGISTER_OBSERVER, data, reply, option);
434 }
435
EnableBtCallLog(bool state)436 void BluetoothHfpAgProxy::EnableBtCallLog(bool state)
437 {
438 MessageParcel data;
439 CHECK_AND_RETURN_LOG(data.WriteInterfaceToken(BluetoothHfpAgProxy::GetDescriptor()), "WriteInterfaceToken error");
440 CHECK_AND_RETURN_LOG(data.WriteBool(state), "Write state error");
441
442 MessageParcel reply;
443 MessageOption option(MessageOption::TF_SYNC);
444
445 SEND_IPC_REQUEST_RETURN(BluetoothHfpAgInterfaceCode::BT_HFP_AG_CALL_LOG, data, reply, option);
446 }
447
GetVirtualDeviceList(std::vector<std::string> &devices)448 void BluetoothHfpAgProxy::GetVirtualDeviceList(std::vector<std::string> &devices)
449 {
450 MessageParcel data;
451 CHECK_AND_RETURN_LOG(data.WriteInterfaceToken(BluetoothHfpAgProxy::GetDescriptor()), "WriteInterfaceToken error");
452
453 MessageParcel reply;
454 MessageOption option(MessageOption::TF_SYNC);
455
456 SEND_IPC_REQUEST_RETURN(BluetoothHfpAgInterfaceCode::BT_HFP_AG_GET_VIRTUALDEVICE_LIST, data, reply, option);
457
458 int32_t rawAddsSize = reply.ReadInt32();
459
460 CHECK_AND_RETURN_LOG(rawAddsSize <= MAX_HFP_VIRTUAL_DEVICE, "virtual device size error.");
461
462 for (int i = 0; i < rawAddsSize; i++) {
463 devices.push_back(reply.ReadString());
464 }
465
466 return;
467 }
468
UpdateVirtualDevice(int32_t action, const std::string &address)469 void BluetoothHfpAgProxy::UpdateVirtualDevice(int32_t action, const std::string &address)
470 {
471 MessageParcel data;
472 CHECK_AND_RETURN_LOG(data.WriteInterfaceToken(BluetoothHfpAgProxy::GetDescriptor()), "WriteInterfaceToken error");
473 CHECK_AND_RETURN_LOG(data.WriteInt32(action), "write action error");
474 CHECK_AND_RETURN_LOG(data.WriteString(address), "write address error");
475
476 MessageParcel reply;
477 MessageOption option(MessageOption::TF_SYNC);
478
479 SEND_IPC_REQUEST_RETURN(BluetoothHfpAgInterfaceCode::BT_HFP_AG_UPDATE_VIRTUALDEVICE, data, reply, option);
480 }
481 } // namespace Bluetooth
482 } // namespace OHOS
483