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_host_proxy.h"
17 #include "bluetooth_log.h"
18 #include "bluetooth_errorcode.h"
19 namespace OHOS {
20 namespace Bluetooth {
RegisterObserver(const sptr<IBluetoothHostObserver> & observer)21 void BluetoothHostProxy::RegisterObserver(const sptr<IBluetoothHostObserver> &observer)
22 {
23 HILOGI("BluetoothHostProxy::RegisterObserver start");
24 MessageParcel data;
25 if (!data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor())) {
26 HILOGE("BluetoothHostProxy::RegisterObserver WriteInterfaceToken error");
27 return;
28 }
29 if (!data.WriteRemoteObject(observer->AsObject())) {
30 HILOGE("BluetoothHostProxy::RegisterObserver error");
31 return;
32 }
33 MessageParcel reply;
34 MessageOption option = {MessageOption::TF_SYNC};
35 int32_t error = InnerTransact(BluetoothHostInterfaceCode::BT_REGISTER_OBSERVER, option, data, reply);
36 if (error != NO_ERROR) {
37 HILOGE("BluetoothHostProxy::RegisterObserver done fail, error: %{public}d", error);
38 return;
39 }
40 HILOGI("BluetoothHostProxy::RegisterObserver success");
41 }
42
DeregisterObserver(const sptr<IBluetoothHostObserver> & observer)43 void BluetoothHostProxy::DeregisterObserver(const sptr<IBluetoothHostObserver> &observer)
44 {
45 MessageParcel data;
46 if (!data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor())) {
47 HILOGE("BluetoothHostProxy::DeregisterObserver WriteInterfaceToken error");
48 return;
49 }
50 if (!data.WriteRemoteObject(observer->AsObject())) {
51 HILOGE("BluetoothHostProxy::DeregisterObserver error");
52 return;
53 }
54 MessageParcel reply;
55 MessageOption option = {MessageOption::TF_SYNC};
56 int32_t error = InnerTransact(BluetoothHostInterfaceCode::BT_DEREGISTER_OBSERVER, option, data, reply);
57 if (error != NO_ERROR) {
58 HILOGE("BluetoothHostProxy::DeregisterObserver done fail, error: %{public}d", error);
59 return;
60 }
61 }
62
EnableBt()63 int32_t BluetoothHostProxy::EnableBt()
64 {
65 MessageParcel data;
66 HILOGI("BluetoothHostProxy::EnableBt starts");
67 if (!data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor())) {
68 HILOGE("BluetoothHostProxy::EnableBt WriteInterfaceToken error");
69 return BT_ERR_IPC_TRANS_FAILED;
70 }
71
72 MessageParcel reply;
73 MessageOption option = {MessageOption::TF_SYNC};
74 int32_t error = InnerTransact(BluetoothHostInterfaceCode::BT_ENABLE, option, data, reply);
75 if (error != NO_ERROR) {
76 HILOGE("BluetoothHostProxy::EnableBt done fail, error: %{public}d", error);
77 return BT_ERR_IPC_TRANS_FAILED;
78 }
79 return reply.ReadInt32();
80 }
81
DisableBt()82 int32_t BluetoothHostProxy::DisableBt()
83 {
84 HILOGI("BluetoothHostProxy::DisableBt starts");
85 MessageParcel data;
86 if (!data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor())) {
87 HILOGE("BluetoothHostProxy::DisableBt WriteInterfaceToken error");
88 return BT_ERR_IPC_TRANS_FAILED;
89 }
90
91 MessageParcel reply;
92 MessageOption option = {MessageOption::TF_SYNC};
93 int32_t error = InnerTransact(BluetoothHostInterfaceCode::BT_DISABLE, option, data, reply);
94 if (error != BT_NO_ERROR) {
95 HILOGE("BluetoothHostProxy::DisableBt done fail, error: %{public}d", error);
96 return BT_ERR_IPC_TRANS_FAILED;
97 }
98 return reply.ReadInt32();
99 }
100
GetProfile(const std::string & name)101 sptr<IRemoteObject> BluetoothHostProxy::GetProfile(const std::string &name)
102 {
103 MessageParcel data;
104 if (!data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor())) {
105 HILOGE("BluetoothHostProxy::GetProfile WriteInterfaceToken error");
106 return nullptr;
107 }
108 if (!data.WriteString(name)) {
109 HILOGE("BluetoothHostProxy::GetProfile name error");
110 return nullptr;
111 }
112 MessageParcel reply;
113 MessageOption option = {MessageOption::TF_SYNC};
114 int32_t error = InnerTransact(BluetoothHostInterfaceCode::BT_GETPROFILE, option, data, reply);
115 if (error != NO_ERROR) {
116 HILOGE("BluetoothHostProxy::GetProfile done fail, error: %{public}d", error);
117 return nullptr;
118 }
119 return reply.ReadRemoteObject();
120 }
121
GetBleRemote(const std::string & name)122 sptr<IRemoteObject> BluetoothHostProxy::GetBleRemote(const std::string &name)
123 {
124 MessageParcel data;
125 if (!data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor())) {
126 HILOGE("BluetoothHostProxy::GetProfile WriteInterfaceToken error");
127 return nullptr;
128 }
129 if (!data.WriteString(name)) {
130 HILOGE("BluetoothHostProxy::GetProfile name error");
131 return nullptr;
132 }
133 MessageParcel reply;
134 MessageOption option = {MessageOption::TF_SYNC};
135 int32_t error = InnerTransact(BluetoothHostInterfaceCode::BT_GET_BLE, option, data, reply);
136 if (error != NO_ERROR) {
137 HILOGE("BluetoothHostProxy::GetProfile done fail, error: %{public}d", error);
138 return nullptr;
139 }
140 return reply.ReadRemoteObject();
141 }
142
BluetoothFactoryReset()143 bool BluetoothHostProxy::BluetoothFactoryReset()
144 {
145 MessageParcel data;
146 if (!data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor())) {
147 HILOGE("BluetoothHostProxy::BluetoothFactoryReset WriteInterfaceToken error");
148 return false;
149 }
150 MessageParcel reply;
151 MessageOption option = {MessageOption::TF_SYNC};
152 int32_t error = InnerTransact(BluetoothHostInterfaceCode::BT_FACTORY_RESET, option, data, reply);
153 if (error != NO_ERROR) {
154 HILOGE("BluetoothHostProxy::BluetoothFactoryReset done fail, error: %{public}d", error);
155 return false;
156 }
157 return reply.ReadBool();
158 }
159
GetBtState(int & state)160 int32_t BluetoothHostProxy::GetBtState(int &state)
161 {
162 HILOGD("BluetoothHostProxy::GetBtState starts");
163 MessageParcel data;
164 if (!data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor())) {
165 HILOGE("BluetoothHostProxy::GetBtState WriteInterfaceToken error");
166 return -1;
167 }
168 MessageParcel reply;
169 MessageOption option = {MessageOption::TF_SYNC};
170 int32_t error = InnerTransact(BluetoothHostInterfaceCode::BT_GETSTATE, option, data, reply);
171 if (error != NO_ERROR) {
172 HILOGE("BluetoothHostProxy::GetBtState done fail, error: %{public}d", error);
173 return BT_ERR_IPC_TRANS_FAILED;
174 }
175
176 int32_t exception = reply.ReadInt32();
177 if (exception == NO_ERROR) {
178 state = reply.ReadInt32();
179 }
180 return exception;
181 }
182
GetLocalAddress()183 std::string BluetoothHostProxy::GetLocalAddress()
184 {
185 MessageParcel data;
186 if (!data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor())) {
187 HILOGE("BluetoothHostProxy::GetLocalAddress WriteInterfaceToken error");
188 return std::string();
189 }
190 MessageParcel reply;
191 MessageOption option = {MessageOption::TF_SYNC};
192 int32_t error = InnerTransact(BluetoothHostInterfaceCode::BT_GET_LOCAL_ADDRESS, option, data, reply);
193 if (error != NO_ERROR) {
194 HILOGE("BluetoothHostProxy::GetLocalAddress done fail, error: %{public}d", error);
195 return std::string();
196 }
197 return reply.ReadString();
198 }
199
DisableBle()200 int32_t BluetoothHostProxy::DisableBle()
201 {
202 MessageParcel data;
203 if (!data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor())) {
204 HILOGE("BluetoothHostProxy::DisableBle WriteInterfaceToken error");
205 return BT_ERR_IPC_TRANS_FAILED;
206 }
207 MessageParcel reply;
208 MessageOption option = {MessageOption::TF_SYNC};
209 int32_t error = InnerTransact(BluetoothHostInterfaceCode::BT_DISABLE_BLE, option, data, reply);
210 if (error != BT_NO_ERROR) {
211 HILOGE("BluetoothHostProxy::DisableBle done fail, error: %{public}d", error);
212 return BT_ERR_IPC_TRANS_FAILED;
213 }
214 return reply.ReadInt32();
215 }
216
EnableBle()217 int32_t BluetoothHostProxy::EnableBle()
218 {
219 MessageParcel data;
220 if (!data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor())) {
221 HILOGE("BluetoothHostProxy::EnableBle WriteInterfaceToken error");
222 return BT_ERR_IPC_TRANS_FAILED;
223 }
224 MessageParcel reply;
225 MessageOption option = {MessageOption::TF_SYNC};
226
227 int32_t error = InnerTransact(BluetoothHostInterfaceCode::BT_ENABLE_BLE, option, data, reply);
228 if (error != BT_NO_ERROR) {
229 HILOGE("BluetoothHostProxy::EnableBle done fail, error: %{public}d", error);
230 return BT_ERR_IPC_TRANS_FAILED;
231 }
232 return reply.ReadInt32();
233 }
234
IsBrEnabled()235 bool BluetoothHostProxy::IsBrEnabled()
236 {
237 MessageParcel data;
238 if (!data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor())) {
239 HILOGE("BluetoothHostProxy::IsBrEnabled WriteInterfaceToken error");
240 return false;
241 }
242 MessageParcel reply;
243 MessageOption option = {MessageOption::TF_SYNC};
244 int32_t error = InnerTransact(BluetoothHostInterfaceCode::BT_IS_BR_ENABLED, option, data, reply);
245 if (error != NO_ERROR) {
246 HILOGE("BluetoothHostProxy::IsBrEnabled done fail, error: %{public}d", error);
247 return false;
248 }
249 return reply.ReadBool();
250 }
251
IsBleEnabled()252 bool BluetoothHostProxy::IsBleEnabled()
253 {
254 MessageParcel data;
255 if (!data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor())) {
256 HILOGE("BluetoothHostProxy::IsBleEnabled WriteInterfaceToken error");
257 return false;
258 }
259 MessageParcel reply;
260 MessageOption option = {MessageOption::TF_SYNC};
261 int32_t error = InnerTransact(BluetoothHostInterfaceCode::BT_IS_BLE_ENABLED, option, data, reply);
262 if (error != NO_ERROR) {
263 HILOGE("BluetoothHostProxy::IsBleEnabled done fail, error: %{public}d", error);
264 return false;
265 }
266 return reply.ReadBool();
267 }
268
GetProfileList()269 std::vector<uint32_t> BluetoothHostProxy::GetProfileList()
270 {
271 std::vector<uint32_t> vec;
272 MessageParcel data;
273 if (!data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor())) {
274 HILOGE("BluetoothHostProxy::GetProfileList WriteInterfaceToken error");
275 return vec;
276 }
277 MessageParcel reply;
278 MessageOption option = {MessageOption::TF_SYNC};
279 int32_t error = InnerTransact(BluetoothHostInterfaceCode::BT_GET_PROFILE_LIST, option, data, reply);
280 if (error != NO_ERROR) {
281 HILOGE("BluetoothHostProxy::GetProfileList done fail, error: %{public}d", error);
282 return vec;
283 }
284 if (!reply.ReadUInt32Vector(&vec)) {
285 HILOGE("BluetoothHostProxy::GetProfileList Read reply fail");
286 return vec;
287 }
288 return vec;
289 }
290
GetMaxNumConnectedAudioDevices()291 int32_t BluetoothHostProxy::GetMaxNumConnectedAudioDevices()
292 {
293 MessageParcel data;
294 if (!data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor())) {
295 HILOGE("BluetoothHostProxy::GetMaxNumConnectedAudioDevices WriteInterfaceToken error");
296 return -1;
297 }
298 MessageParcel reply;
299 MessageOption option = {MessageOption::TF_SYNC};
300 int32_t error = InnerTransact(
301 BluetoothHostInterfaceCode::BT_GET_MAXNUM_CONNECTED_AUDIODEVICES, option, data, reply);
302 if (error != NO_ERROR) {
303 HILOGE("BluetoothHostProxy::GetMaxNumConnectedAudioDevices done fail, error: %{public}d", error);
304 return -1;
305 }
306 int32_t maxNum;
307 if (!reply.ReadInt32(maxNum)) {
308 HILOGE("BluetoothHostProxy::GetMaxNumConnectedAudioDevices Read reply fail");
309 return -1;
310 }
311 return maxNum;
312 }
313
GetBtConnectionState(int & state)314 int32_t BluetoothHostProxy::GetBtConnectionState(int &state)
315 {
316 HILOGI("BluetoothHostProxy::GetBtConnectionState starts");
317 MessageParcel data;
318 if (!data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor())) {
319 HILOGE("BluetoothHostProxy::GetBtConnectionState WriteInterfaceToken error");
320 return BT_ERR_IPC_TRANS_FAILED;
321 }
322 MessageParcel reply;
323 MessageOption option = {MessageOption::TF_SYNC};
324 int32_t error = InnerTransact(BluetoothHostInterfaceCode::BT_GET_BT_STATE, option, data, reply);
325 if (error != BT_NO_ERROR) {
326 HILOGE("BluetoothHostProxy::GetBtConnectionState done fail, error: %{public}d", error);
327 return BT_ERR_IPC_TRANS_FAILED;
328 }
329 int32_t exception = reply.ReadInt32();
330 if (exception == BT_NO_ERROR) {
331 state = reply.ReadInt32();
332 }
333 return exception;
334 }
335
GetBtProfileConnState(uint32_t profileId,int & state)336 int32_t BluetoothHostProxy::GetBtProfileConnState(uint32_t profileId, int &state)
337 {
338 MessageParcel data;
339 if (!data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor())) {
340 HILOGE("BluetoothHostProxy::GetBtProfileConnState WriteInterfaceToken error");
341 return BT_ERR_IPC_TRANS_FAILED;
342 }
343 if (!data.WriteUint32(profileId)) {
344 HILOGE("BluetoothHostProxy::GetBtProfileConnState WriteInterfaceToken error");
345 return BT_ERR_IPC_TRANS_FAILED;
346 }
347 MessageParcel reply;
348 MessageOption option = {MessageOption::TF_SYNC};
349 int32_t error = InnerTransact(BluetoothHostInterfaceCode::BT_GET_BT_PROFILE_CONNSTATE, option, data, reply);
350 if (error != BT_NO_ERROR) {
351 HILOGE("BluetoothHostProxy::GetBtProfileConnState done fail, error: %{public}d", error);
352 return BT_ERR_IPC_TRANS_FAILED;
353 }
354
355 int32_t exception = reply.ReadInt32();
356 if (exception == BT_NO_ERROR) {
357 state = reply.ReadInt32();
358 }
359 return exception;
360 }
361
GetLocalDeviceClass()362 int32_t BluetoothHostProxy::GetLocalDeviceClass()
363 {
364 MessageParcel data;
365 if (!data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor())) {
366 HILOGE("BluetoothHostProxy::GetLocalDeviceClass WriteInterfaceToken error");
367 return -1;
368 }
369 MessageParcel reply;
370 MessageOption option = {MessageOption::TF_SYNC};
371 int32_t error = InnerTransact(BluetoothHostInterfaceCode::BT_GET_LOCAL_DEVICE_CLASS, option, data, reply);
372 if (error != NO_ERROR) {
373 HILOGE("BluetoothHostProxy::GetLocalDeviceClass done fail, error: %{public}d", error);
374 return -1;
375 }
376
377 int32_t result;
378 if (!reply.ReadInt32(result)) {
379 HILOGE("BluetoothHostProxy::GetLocalDeviceClass Read reply fail");
380 return -1;
381 }
382 return result;
383 }
384
SetLocalDeviceClass(const int32_t & deviceClass)385 bool BluetoothHostProxy::SetLocalDeviceClass(const int32_t &deviceClass)
386 {
387 MessageParcel data;
388 if (!data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor())) {
389 HILOGE("BluetoothHostProxy::SetLocalDeviceClass WriteInterfaceToken error");
390 return false;
391 }
392 if (!data.WriteUint32(deviceClass)) {
393 HILOGE("BluetoothHostProxy::SetLocalDeviceClass WriteInterfaceToken error");
394 return false;
395 }
396 MessageParcel reply;
397 MessageOption option = {MessageOption::TF_SYNC};
398 int32_t error = InnerTransact(BluetoothHostInterfaceCode::BT_SET_LOCAL_DEVICE_CLASS, option, data, reply);
399 if (error != NO_ERROR) {
400 HILOGE("BluetoothHostProxy::SetLocalDeviceClass done fail, error: %{public}d", error);
401 return false;
402 }
403 return reply.ReadBool();
404 }
405
GetLocalName(std::string & name)406 int32_t BluetoothHostProxy::GetLocalName(std::string &name)
407 {
408 MessageParcel data;
409 if (!data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor())) {
410 HILOGE("BluetoothHostProxy::GetLocalName WriteInterfaceToken error");
411 return BT_ERR_IPC_TRANS_FAILED;
412 }
413 MessageParcel reply;
414 MessageOption option = {MessageOption::TF_SYNC};
415 int32_t error = InnerTransact(BluetoothHostInterfaceCode::BT_GET_LOCAL_NAME, option, data, reply);
416 if (error != BT_NO_ERROR) {
417 HILOGE("BluetoothHostProxy::GetLocalName done fail, error: %{public}d", error);
418 return BT_ERR_IPC_TRANS_FAILED;
419 }
420 int32_t exception = reply.ReadInt32();
421 if (exception == BT_NO_ERROR) {
422 name = reply.ReadString();
423 }
424 return exception;
425 }
426
SetLocalName(const std::string & name)427 int32_t BluetoothHostProxy::SetLocalName(const std::string &name)
428 {
429 MessageParcel data;
430 if (!data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor())) {
431 HILOGE("BluetoothHostProxy::SetLocalName WriteInterfaceToken error");
432 return BT_ERR_IPC_TRANS_FAILED;
433 }
434 if (!data.WriteString(name)) {
435 HILOGE("BluetoothHostProxy::SetLocalName WriteInterfaceToken error");
436 return BT_ERR_IPC_TRANS_FAILED;
437 }
438 MessageParcel reply;
439 MessageOption option = {MessageOption::TF_SYNC};
440 int32_t error = InnerTransact(BluetoothHostInterfaceCode::BT_SET_LOCAL_NAME, option, data, reply);
441 if (error != BT_NO_ERROR) {
442 HILOGE("BluetoothHostProxy::SetLocalName done fail, error: %{public}d", error);
443 return BT_ERR_IPC_TRANS_FAILED;
444 }
445 return reply.ReadInt32();
446 }
447
GetBtScanMode(int32_t & scanMode)448 int32_t BluetoothHostProxy::GetBtScanMode(int32_t &scanMode)
449 {
450 MessageParcel data;
451 if (!data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor())) {
452 HILOGE("BluetoothHostProxy::GetBtScanMode WriteInterfaceToken error");
453 return BT_ERR_IPC_TRANS_FAILED;
454 }
455 MessageParcel reply;
456 MessageOption option = {MessageOption::TF_SYNC};
457 int32_t error = InnerTransact(BluetoothHostInterfaceCode::BT_GET_BT_SCAN_MODE, option, data, reply);
458 if (error != BT_NO_ERROR) {
459 HILOGE("BluetoothHostProxy::GetBtScanMode done fail, error: %{public}d", error);
460 return BT_ERR_IPC_TRANS_FAILED;
461 }
462 int32_t exception = reply.ReadInt32();
463 if (exception == BT_NO_ERROR) {
464 scanMode = reply.ReadInt32();
465 }
466 return exception;
467 }
468
SetBtScanMode(int32_t mode,int32_t duration)469 int32_t BluetoothHostProxy::SetBtScanMode(int32_t mode, int32_t duration)
470 {
471 MessageParcel data;
472 if (!data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor())) {
473 HILOGE("BluetoothHostProxy::SetBtScanMode WriteInterfaceToken error");
474 return BT_ERR_IPC_TRANS_FAILED;
475 }
476 if (!data.WriteInt32(mode)) {
477 HILOGE("BluetoothHostProxy::SetBtScanMode WriteInterfaceToken error");
478 return BT_ERR_IPC_TRANS_FAILED;
479 }
480 if (!data.WriteInt32(duration)) {
481 HILOGE("BluetoothHostProxy::SetBtScanMode WriteInterfaceToken error");
482 return BT_ERR_IPC_TRANS_FAILED;
483 }
484 MessageParcel reply;
485 MessageOption option = {MessageOption::TF_SYNC};
486 int32_t error = InnerTransact(BluetoothHostInterfaceCode::BT_SET_BT_SCAN_MODE, option, data, reply);
487 if (error != BT_NO_ERROR) {
488 HILOGE("BluetoothHostProxy::SetBtScanMode done fail, error: %{public}d", error);
489 return BT_ERR_IPC_TRANS_FAILED;
490 }
491 return reply.ReadInt32();
492 }
493
GetBondableMode(const int32_t transport)494 int32_t BluetoothHostProxy::GetBondableMode(const int32_t transport)
495 {
496 int32_t Mode;
497 MessageParcel data;
498 if (!data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor())) {
499 HILOGE("BluetoothHostProxy::GetBondableMode WriteInterfaceToken error");
500 return -1;
501 }
502 if (!data.WriteInt32(transport)) {
503 HILOGE("BluetoothHostProxy::GetBondableMode WriteInterfaceToken error");
504 return -1;
505 }
506 MessageParcel reply;
507 MessageOption option = {MessageOption::TF_SYNC};
508 int32_t error = InnerTransact(BluetoothHostInterfaceCode::BT_GET_BONDABLE_MODE, option, data, reply);
509 if (error != NO_ERROR) {
510 HILOGE("BluetoothHostProxy::GetBondableMode done fail, error: %{public}d", error);
511 return -1;
512 }
513 if (!reply.ReadInt32(Mode)) {
514 HILOGE("BluetoothHostProxy::GetBondableMode Read reply fail");
515 return -1;
516 }
517 return Mode;
518 }
519
SetBondableMode(int32_t transport,int32_t mode)520 bool BluetoothHostProxy::SetBondableMode(int32_t transport, int32_t mode)
521 {
522 MessageParcel data;
523 if (!data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor())) {
524 HILOGE("BluetoothHostProxy::SetBondableMode WriteInterfaceToken error");
525 return false;
526 }
527 if (!data.WriteInt32(transport)) {
528 HILOGE("BluetoothHostProxy::SetBondableMode WriteInterfaceToken error");
529 return false;
530 }
531 if (!data.WriteInt32(mode)) {
532 HILOGE("BluetoothHostProxy::SetBondableMode WriteInterfaceToken error");
533 return false;
534 }
535 MessageParcel reply;
536 MessageOption option = {MessageOption::TF_SYNC};
537 int32_t error = InnerTransact(BluetoothHostInterfaceCode::BT_SET_BONDABLE_MODE, option, data, reply);
538 if (error != NO_ERROR) {
539 HILOGE("BluetoothHostProxy::SetBondableMode done fail, error: %{public}d", error);
540 return false;
541 }
542 return reply.ReadBool();
543 }
544
StartBtDiscovery()545 int32_t BluetoothHostProxy::StartBtDiscovery()
546 {
547 MessageParcel data;
548 if (!data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor())) {
549 HILOGE("BluetoothHostProxy::StartBtDiscovery WriteInterfaceToken error");
550 return BT_ERR_IPC_TRANS_FAILED;
551 }
552 MessageParcel reply;
553 MessageOption option = {MessageOption::TF_SYNC};
554 int32_t error = InnerTransact(BluetoothHostInterfaceCode::BT_START_BT_DISCOVERY, option, data, reply);
555 if (error != BT_NO_ERROR) {
556 HILOGE("BluetoothHostProxy::StartBtDiscovery done fail, error: %{public}d", error);
557 return BT_ERR_IPC_TRANS_FAILED;
558 }
559 return reply.ReadInt32();
560 }
561
CancelBtDiscovery()562 int32_t BluetoothHostProxy::CancelBtDiscovery()
563 {
564 MessageParcel data;
565 if (!data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor())) {
566 HILOGE("BluetoothHostProxy::CancelBtDiscovery WriteInterfaceToken error");
567 return BT_ERR_IPC_TRANS_FAILED;
568 }
569 MessageParcel reply;
570 MessageOption option = {MessageOption::TF_SYNC};
571
572 int32_t error = InnerTransact(BluetoothHostInterfaceCode::BT_CANCEL_BT_DISCOVERY, option, data, reply);
573 if (error != BT_NO_ERROR) {
574 HILOGE("BluetoothHostProxy::CancelBtDiscovery done fail, error: %{public}d", error);
575 return BT_ERR_IPC_TRANS_FAILED;
576 }
577 return reply.ReadInt32();
578 }
579
IsBtDiscovering(const int32_t transport)580 bool BluetoothHostProxy::IsBtDiscovering(const int32_t transport)
581 {
582 MessageParcel data;
583 if (!data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor())) {
584 HILOGE("BluetoothHostProxy::IsBtDiscovering WriteInterfaceToken error");
585 return false;
586 }
587 if (!data.WriteInt32(transport)) {
588 HILOGE("BluetoothHostProxy::IsBtDiscovering WriteInterfaceToken error");
589 return false;
590 }
591 MessageParcel reply;
592 MessageOption option = {MessageOption::TF_SYNC};
593 int32_t error = InnerTransact(BluetoothHostInterfaceCode::BT_IS_BT_DISCOVERING, option, data, reply);
594 if (error != NO_ERROR) {
595 HILOGE("BluetoothHostProxy::Start done fail, error: %{public}d", error);
596 return false;
597 }
598 return reply.ReadBool();
599 }
600
GetBtDiscoveryEndMillis()601 long BluetoothHostProxy::GetBtDiscoveryEndMillis()
602 {
603 long millis;
604 MessageParcel data;
605 if (!data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor())) {
606 HILOGE("BluetoothHostProxy::GetBtDiscoveryEndMillis WriteInterfaceToken error");
607 return -1;
608 }
609 MessageParcel reply;
610 MessageOption option = {MessageOption::TF_SYNC};
611 int32_t error = InnerTransact(BluetoothHostInterfaceCode::BT_GET_BT_DISCOVERY_END_MILLIS, option, data, reply);
612 if (error != NO_ERROR) {
613 HILOGE("BluetoothHostProxy::GetBtDiscoveryEndMillis done fail, error: %{public}d", error);
614 return -1;
615 }
616 millis = static_cast<long>(reply.ReadInt64());
617 return millis;
618 }
619
GetPairedDevices(int32_t transport,std::vector<BluetoothRawAddress> & pairedAddr)620 int32_t BluetoothHostProxy::GetPairedDevices(int32_t transport, std::vector<BluetoothRawAddress> &pairedAddr)
621 {
622 MessageParcel data;
623 if (!data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor())) {
624 HILOGE("BluetoothHostProxy::GetPairedDevices WriteInterfaceToken error");
625 return BT_ERR_IPC_TRANS_FAILED;
626 }
627 if (!data.WriteInt32(transport)) {
628 HILOGE("BluetoothHostProxy::GetPairedDevices WriteInterfaceToken error");
629 return BT_ERR_IPC_TRANS_FAILED;
630 }
631 MessageParcel reply;
632 MessageOption option = {MessageOption::TF_SYNC};
633 int32_t error = InnerTransact(BluetoothHostInterfaceCode::BT_GET_PAIRED_DEVICES, option, data, reply);
634 if (error != BT_NO_ERROR) {
635 HILOGE("BluetoothHostProxy::GetPairedDevices done fail, error: %{public}d", error);
636 return BT_ERR_IPC_TRANS_FAILED;
637 }
638 int32_t size = reply.ReadInt32();
639 for (int32_t i = 0; i < size; i++) {
640 std::shared_ptr<BluetoothRawAddress> rawAddress(reply.ReadParcelable<BluetoothRawAddress>());
641 if (!rawAddress) {
642 return BT_ERR_IPC_TRANS_FAILED;
643 }
644 pairedAddr.push_back(*rawAddress);
645 }
646 return reply.ReadInt32();
647 }
648
RemovePair(const int32_t transport,const sptr<BluetoothRawAddress> & device)649 int32_t BluetoothHostProxy::RemovePair(const int32_t transport, const sptr<BluetoothRawAddress> &device)
650 {
651 MessageParcel data;
652 if (!data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor())) {
653 HILOGE("BluetoothHostProxy::RemovePair WriteInterfaceToken error");
654 return BT_ERR_IPC_TRANS_FAILED;
655 }
656 if (!data.WriteInt32(transport)) {
657 HILOGE("BluetoothHostProxy::RemovePair WriteInterfaceToken error");
658 return BT_ERR_IPC_TRANS_FAILED;
659 }
660 if (!data.WriteParcelable(device.GetRefPtr())) {
661 HILOGE("BluetoothHostProxy::RemovePair WriteInterfaceToken error");
662 return BT_ERR_IPC_TRANS_FAILED;
663 }
664 MessageParcel reply;
665 MessageOption option = {MessageOption::TF_SYNC};
666 int32_t error = InnerTransact(BluetoothHostInterfaceCode::BT_REMOVE_PAIR, option, data, reply);
667 if (error != BT_NO_ERROR) {
668 HILOGE("BluetoothHostProxy::RemovePair done fail, error: %{public}d", error);
669 return BT_ERR_IPC_TRANS_FAILED;
670 }
671 return reply.ReadInt32();
672 }
673
RemoveAllPairs()674 bool BluetoothHostProxy::RemoveAllPairs()
675 {
676 MessageParcel data;
677 if (!data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor())) {
678 HILOGE("BluetoothHostProxy::RemoveAllPairs WriteInterfaceToken error");
679 return false;
680 }
681 MessageParcel reply;
682 MessageOption option = {MessageOption::TF_SYNC};
683
684 int32_t error = InnerTransact(BluetoothHostInterfaceCode::BT_REMOVE_ALL_PAIRS, option, data, reply);
685 if (error != NO_ERROR) {
686 HILOGE("BluetoothHostProxy::RemoveAllPairs done fail, error: %{public}d", error);
687 return false;
688 }
689 return reply.ReadBool();
690 }
691
RegisterRemoteDeviceObserver(const sptr<IBluetoothRemoteDeviceObserver> & observer)692 void BluetoothHostProxy::RegisterRemoteDeviceObserver(const sptr<IBluetoothRemoteDeviceObserver> &observer)
693 {
694 MessageParcel data;
695 if (!data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor())) {
696 HILOGE("BluetoothHostProxy::RegisterRemoteDeviceObserver WriteInterfaceToken error");
697 return;
698 }
699 if (!data.WriteRemoteObject(observer->AsObject())) {
700 HILOGE("BluetoothHostProxy::RegisterRemoteDeviceObserver WriteInterfaceToken error");
701 return;
702 }
703 MessageParcel reply;
704 MessageOption option = {MessageOption::TF_SYNC};
705 int32_t error = InnerTransact(BluetoothHostInterfaceCode::BT_REGISTER_REMOTE_DEVICE_OBSERVER, option, data, reply);
706 if (error != NO_ERROR) {
707 HILOGE("BluetoothHostProxy::GetBtConnectionState done fail, error: %{public}d", error);
708 return;
709 }
710 return;
711 }
712
DeregisterRemoteDeviceObserver(const sptr<IBluetoothRemoteDeviceObserver> & observer)713 void BluetoothHostProxy::DeregisterRemoteDeviceObserver(const sptr<IBluetoothRemoteDeviceObserver> &observer)
714 {
715 MessageParcel data;
716 if (!data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor())) {
717 HILOGE("BluetoothHostProxy::DeregisterRemoteDeviceObserver WriteInterfaceToken error");
718 return;
719 }
720 if (!data.WriteRemoteObject(observer->AsObject())) {
721 HILOGE("BluetoothHostProxy::DeregisterRemoteDeviceObserver WriteInterfaceToken error");
722 return;
723 }
724 MessageParcel reply;
725 MessageOption option = {MessageOption::TF_SYNC};
726 int32_t error = InnerTransact(
727 BluetoothHostInterfaceCode::BT_DEREGISTER_REMOTE_DEVICE_OBSERVER, option, data, reply);
728 if (error != NO_ERROR) {
729 HILOGE("BluetoothHostProxy::DeregisterRemoteDeviceObserver done fail, error: %{public}d", error);
730 return;
731 }
732 return;
733 }
734
GetBleMaxAdvertisingDataLength()735 int32_t BluetoothHostProxy::GetBleMaxAdvertisingDataLength()
736 {
737 MessageParcel data;
738 if (!data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor())) {
739 HILOGE("BluetoothHostProxy::GetBleMaxAdvertisingDataLength WriteInterfaceToken error");
740 return false;
741 }
742 MessageParcel reply;
743 MessageOption option = {MessageOption::TF_SYNC};
744 int32_t error = InnerTransact(
745 BluetoothHostInterfaceCode::BT_GET_BLE_MAX_ADVERTISING_DATALENGTH, option, data, reply);
746 if (error != NO_ERROR) {
747 HILOGE("BluetoothHostProxy::GetBleMaxAdvertisingDataLength done fail, error: %{public}d", error);
748 return false;
749 }
750 return reply.ReadInt32();
751 }
752
GetDeviceType(int32_t transport,const std::string & address)753 int32_t BluetoothHostProxy::GetDeviceType(int32_t transport, const std::string &address)
754 {
755 MessageParcel data;
756 if (!data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor())) {
757 HILOGE("BluetoothHostProxy::GetDeviceType WriteInterfaceToken error");
758 return 0;
759 }
760 if (!data.WriteInt32(transport)) {
761 HILOGE("BluetoothHostProxy::GetDeviceType transport error");
762 return 0;
763 }
764 if (!data.WriteString(address)) {
765 HILOGE("BluetoothHostProxy::GetDeviceType address error");
766 return 0;
767 }
768 MessageParcel reply;
769 MessageOption option = {MessageOption::TF_SYNC};
770 int32_t error = InnerTransact(BluetoothHostInterfaceCode::GET_DEVICE_TYPE, option, data, reply);
771 if (error != NO_ERROR) {
772 HILOGE("BluetoothHostProxy::GetDeviceType done fail, error: %{public}d", error);
773 return 0;
774 }
775 return reply.ReadInt32();
776 }
777
GetPhonebookPermission(const std::string & address)778 int32_t BluetoothHostProxy::GetPhonebookPermission(const std::string &address)
779 {
780 MessageParcel data;
781 if (!data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor())) {
782 HILOGE("BluetoothHostProxy::GetPhonebookPermission WriteInterfaceToken error");
783 return 0;
784 }
785 if (!data.WriteString(address)) {
786 HILOGE("BluetoothHostProxy::GetPhonebookPermission address error");
787 return 0;
788 }
789 MessageParcel reply;
790 MessageOption option = {MessageOption::TF_SYNC};
791 int32_t error = InnerTransact(BluetoothHostInterfaceCode::GET_PHONEBOOK_PERMISSION, option, data, reply);
792 if (error != NO_ERROR) {
793 HILOGE("BluetoothHostProxy::GetPhonebookPermission done fail, error: %{public}d", error);
794 return 0;
795 }
796 return reply.ReadInt32();
797 }
798
SetPhonebookPermission(const std::string & address,int32_t permission)799 bool BluetoothHostProxy::SetPhonebookPermission(const std::string &address, int32_t permission)
800 {
801 MessageParcel data;
802 if (!data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor())) {
803 HILOGE("BluetoothHostProxy::SetPhonebookPermission WriteInterfaceToken error");
804 return false;
805 }
806 if (!data.WriteString(address)) {
807 HILOGE("BluetoothHostProxy::SetPhonebookPermission address error");
808 return false;
809 }
810 if (!data.WriteInt32(permission)) {
811 HILOGE("BluetoothHostProxy::SetPhonebookPermission permission error");
812 return false;
813 }
814 MessageParcel reply;
815 MessageOption option = {MessageOption::TF_SYNC};
816 int32_t error = InnerTransact(BluetoothHostInterfaceCode::SET_PHONEBOOK_PERMISSION, option, data, reply);
817 if (error != NO_ERROR) {
818 HILOGE("BluetoothHostProxy::SetPhonebookPermission done fail, error: %{public}d", error);
819 return false;
820 }
821 return reply.ReadBool();
822 }
823
GetMessagePermission(const std::string & address)824 int32_t BluetoothHostProxy::GetMessagePermission(const std::string &address)
825 {
826 MessageParcel data;
827 if (!data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor())) {
828 HILOGE("BluetoothHostProxy::GetMessagePermission WriteInterfaceToken error");
829 return 0;
830 }
831 if (!data.WriteString(address)) {
832 HILOGE("BluetoothHostProxy::GetMessagePermission address error");
833 return 0;
834 }
835 MessageParcel reply;
836 MessageOption option = {MessageOption::TF_SYNC};
837 int32_t error = InnerTransact(BluetoothHostInterfaceCode::GET_MESSAGE_PERMISSION, option, data, reply);
838 if (error != NO_ERROR) {
839 HILOGE("BluetoothHostProxy::GetMessagePermission done fail, error: %{public}d", error);
840 return 0;
841 }
842 return reply.ReadInt32();
843 }
844
SetMessagePermission(const std::string & address,int32_t permission)845 bool BluetoothHostProxy::SetMessagePermission(const std::string &address, int32_t permission)
846 {
847 MessageParcel data;
848 if (!data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor())) {
849 HILOGE("BluetoothHostProxy::SetMessagePermission WriteInterfaceToken error");
850 return false;
851 }
852 if (!data.WriteString(address)) {
853 HILOGE("BluetoothHostProxy::SetMessagePermission address error");
854 return false;
855 }
856 if (!data.WriteInt32(permission)) {
857 HILOGE("BluetoothHostProxy::SetMessagePermission permission error");
858 return false;
859 }
860 MessageParcel reply;
861 MessageOption option = {MessageOption::TF_SYNC};
862 int32_t error = InnerTransact(BluetoothHostInterfaceCode::SET_MESSAGE_PERMISSION, option, data, reply);
863 if (error != NO_ERROR) {
864 HILOGE("BluetoothHostProxy::SetMessagePermission done fail, error: %{public}d", error);
865 return false;
866 }
867 return reply.ReadBool();
868 }
869
GetPowerMode(const std::string & address)870 int32_t BluetoothHostProxy::GetPowerMode(const std::string &address)
871 {
872 MessageParcel data;
873 if (!data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor())) {
874 HILOGE("BluetoothHostProxy::GetPowerMode WriteInterfaceToken error");
875 return 0;
876 }
877 if (!data.WriteString(address)) {
878 HILOGE("BluetoothHostProxy::GetPowerMode address error");
879 return 0;
880 }
881 MessageParcel reply;
882 MessageOption option = {MessageOption::TF_SYNC};
883 int32_t error = InnerTransact(BluetoothHostInterfaceCode::GET_POWER_MODE, option, data, reply);
884 if (error != NO_ERROR) {
885 HILOGE("BluetoothHostProxy::GetPowerMode done fail, error: %{public}d", error);
886 return 0;
887 }
888 return reply.ReadInt32();
889 }
890
GetDeviceName(int32_t transport,const std::string & address,std::string & name)891 int32_t BluetoothHostProxy::GetDeviceName(int32_t transport, const std::string &address, std::string &name)
892 {
893 MessageParcel data;
894 if (!data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor())) {
895 HILOGE("BluetoothHostProxy::GetDeviceName WriteInterfaceToken error");
896 return BT_ERR_IPC_TRANS_FAILED;
897 }
898 if (!data.WriteInt32(transport)) {
899 HILOGE("BluetoothHostProxy::GetDeviceName transport error");
900 return BT_ERR_IPC_TRANS_FAILED;
901 }
902 if (!data.WriteString(address)) {
903 HILOGE("BluetoothHostProxy::GetDeviceName address error");
904 return BT_ERR_IPC_TRANS_FAILED;
905 }
906 MessageParcel reply;
907 MessageOption option = {MessageOption::TF_SYNC};
908 int32_t error = InnerTransact(BluetoothHostInterfaceCode::GET_DEVICE_NAME, option, data, reply);
909 if (error != BT_NO_ERROR) {
910 HILOGE("BluetoothHostProxy::GetDeviceName done fail, error: %{public}d", error);
911 return BT_ERR_IPC_TRANS_FAILED;
912 }
913
914 int32_t exception = reply.ReadInt32();
915 if (exception == BT_NO_ERROR) {
916 name = reply.ReadString();
917 }
918 return exception;
919 }
920
GetDeviceAlias(const std::string & address)921 std::string BluetoothHostProxy::GetDeviceAlias(const std::string &address)
922 {
923 MessageParcel data;
924 if (!data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor())) {
925 HILOGE("BluetoothHostProxy::GetDeviceAlias WriteInterfaceToken error");
926 return std::string();
927 }
928 if (!data.WriteString(address)) {
929 HILOGE("BluetoothHostProxy::GetDeviceAlias address error");
930 return std::string();
931 }
932 MessageParcel reply;
933 MessageOption option = {MessageOption::TF_SYNC};
934 int32_t error = InnerTransact(BluetoothHostInterfaceCode::GET_DEVICE_ALIAS, option, data, reply);
935 if (error != NO_ERROR) {
936 HILOGE("BluetoothHostProxy::GetDeviceAlias done fail, error: %{public}d", error);
937 return std::string();
938 }
939 return reply.ReadString();
940 }
941
SetDeviceAlias(const std::string & address,const std::string & aliasName)942 bool BluetoothHostProxy::SetDeviceAlias(const std::string &address, const std::string &aliasName)
943 {
944 MessageParcel data;
945 if (!data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor())) {
946 HILOGE("BluetoothHostProxy::SetDeviceAlias WriteInterfaceToken error");
947 return false;
948 }
949 if (!data.WriteString(address)) {
950 HILOGE("BluetoothHostProxy::SetDeviceAlias address error");
951 return false;
952 }
953 if (!data.WriteString(aliasName)) {
954 HILOGE("BluetoothHostProxy::SetDeviceAlias aliasName error");
955 return false;
956 }
957 MessageParcel reply;
958 MessageOption option = {MessageOption::TF_SYNC};
959 int32_t error = InnerTransact(BluetoothHostInterfaceCode::SET_DEVICE_ALIAS, option, data, reply);
960 if (error != NO_ERROR) {
961 HILOGE("BluetoothHostProxy::SetDeviceAlias done fail, error: %{public}d", error);
962 return false;
963 }
964 return reply.ReadBool();
965 }
966
GetDeviceBatteryLevel(const std::string & address)967 int32_t BluetoothHostProxy::GetDeviceBatteryLevel(const std::string &address)
968 {
969 MessageParcel data;
970 if (!data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor())) {
971 HILOGE("BluetoothHostProxy::GetDeviceBatteryLevel WriteInterfaceToken error");
972 return 0;
973 }
974 if (!data.WriteString(address)) {
975 HILOGE("BluetoothHostProxy::GetDeviceBatteryLevel address error");
976 return 0;
977 }
978 MessageParcel reply;
979 MessageOption option = {MessageOption::TF_SYNC};
980 int32_t error = InnerTransact(BluetoothHostInterfaceCode::GET_DEVICE_BATTERY_LEVEL, option, data, reply);
981 if (error != NO_ERROR) {
982 HILOGE("BluetoothHostProxy::GetDeviceBatteryLevel done fail, error: %{public}d", error);
983 return 0;
984 }
985 return reply.ReadInt32();
986 }
987
GetPairState(int32_t transport,const std::string & address)988 int32_t BluetoothHostProxy::GetPairState(int32_t transport, const std::string &address)
989 {
990 MessageParcel data;
991 if (!data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor())) {
992 HILOGE("BluetoothHostProxy::GetPairState WriteInterfaceToken error");
993 return 0;
994 }
995 if (!data.WriteInt32(transport)) {
996 HILOGE("BluetoothHostProxy::GetPairState transport error");
997 return 0;
998 }
999 if (!data.WriteString(address)) {
1000 HILOGE("BluetoothHostProxy::GetPairState address error");
1001 return 0;
1002 }
1003 MessageParcel reply;
1004 MessageOption option = {MessageOption::TF_SYNC};
1005 int32_t error = InnerTransact(BluetoothHostInterfaceCode::GET_PAIR_STATE, option, data, reply);
1006 if (error != NO_ERROR) {
1007 HILOGE("BluetoothHostProxy::GetPairState done fail, error: %{public}d", error);
1008 return 0;
1009 }
1010 return reply.ReadInt32();
1011 }
1012
StartPair(int32_t transport,const std::string & address)1013 int32_t BluetoothHostProxy::StartPair(int32_t transport, const std::string &address)
1014 {
1015 MessageParcel data;
1016 if (!data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor())) {
1017 HILOGE("BluetoothHostProxy::StartPair WriteInterfaceToken error");
1018 return BT_ERR_IPC_TRANS_FAILED;
1019 }
1020 if (!data.WriteInt32(transport)) {
1021 HILOGE("BluetoothHostProxy::StartPair transport error");
1022 return BT_ERR_IPC_TRANS_FAILED;
1023 }
1024 if (!data.WriteString(address)) {
1025 HILOGE("BluetoothHostProxy::StartPair address error");
1026 return BT_ERR_IPC_TRANS_FAILED;
1027 }
1028 MessageParcel reply;
1029 MessageOption option = {MessageOption::TF_SYNC};
1030 int32_t error = InnerTransact(BluetoothHostInterfaceCode::START_PAIR, option, data, reply);
1031 if (error != BT_NO_ERROR) {
1032 HILOGE("BluetoothHostProxy::StartPair done fail, error: %{public}d", error);
1033 return BT_ERR_IPC_TRANS_FAILED;
1034 }
1035 return reply.ReadInt32();
1036 }
1037
CancelPairing(int32_t transport,const std::string & address)1038 bool BluetoothHostProxy::CancelPairing(int32_t transport, const std::string &address)
1039 {
1040 MessageParcel data;
1041 if (!data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor())) {
1042 HILOGE("BluetoothHostProxy::CancelPairing WriteInterfaceToken error");
1043 return false;
1044 }
1045 if (!data.WriteInt32(transport)) {
1046 HILOGE("BluetoothHostProxy::CancelPairing transport error");
1047 return false;
1048 }
1049 if (!data.WriteString(address)) {
1050 HILOGE("BluetoothHostProxy::CancelPairing address error");
1051 return false;
1052 }
1053 MessageParcel reply;
1054 MessageOption option = {MessageOption::TF_SYNC};
1055 int32_t error = InnerTransact(BluetoothHostInterfaceCode::CANCEL_PAIRING, option, data, reply);
1056 if (error != NO_ERROR) {
1057 HILOGE("BluetoothHostProxy::CancelPairing done fail, error: %{public}d", error);
1058 return false;
1059 }
1060 return reply.ReadBool();
1061 }
1062
IsBondedFromLocal(int32_t transport,const std::string & address)1063 bool BluetoothHostProxy::IsBondedFromLocal(int32_t transport, const std::string &address)
1064 {
1065 MessageParcel data;
1066 if (!data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor())) {
1067 HILOGE("BluetoothHostProxy::IsBondedFromLocal WriteInterfaceToken error");
1068 return false;
1069 }
1070 if (!data.WriteInt32(transport)) {
1071 HILOGE("BluetoothHostProxy::IsBondedFromLocal transport error");
1072 return false;
1073 }
1074 if (!data.WriteString(address)) {
1075 HILOGE("BluetoothHostProxy::IsBondedFromLocal address error");
1076 return false;
1077 }
1078 MessageParcel reply;
1079 MessageOption option = {MessageOption::TF_SYNC};
1080 int32_t error = InnerTransact(BluetoothHostInterfaceCode::IS_BONDED_FROM_LOCAL, option, data, reply);
1081 if (error != NO_ERROR) {
1082 HILOGE("BluetoothHostProxy::IsBondedFromLocal done fail, error: %{public}d", error);
1083 return false;
1084 }
1085 return reply.ReadBool();
1086 }
1087
IsAclConnected(int32_t transport,const std::string & address)1088 bool BluetoothHostProxy::IsAclConnected(int32_t transport, const std::string &address)
1089 {
1090 MessageParcel data;
1091 if (!data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor())) {
1092 HILOGE("BluetoothHostProxy::IsAclConnected WriteInterfaceToken error");
1093 return false;
1094 }
1095 if (!data.WriteInt32(transport)) {
1096 HILOGE("BluetoothHostProxy::IsAclConnected transport error");
1097 return false;
1098 }
1099 if (!data.WriteString(address)) {
1100 HILOGE("BluetoothHostProxy::IsAclConnected address error");
1101 return false;
1102 }
1103 MessageParcel reply;
1104 MessageOption option = {MessageOption::TF_SYNC};
1105 int32_t error = InnerTransact(BluetoothHostInterfaceCode::IS_ACL_CONNECTED, option, data, reply);
1106 if (error != NO_ERROR) {
1107 HILOGE("BluetoothHostProxy::IsAclConnected done fail, error: %{public}d", error);
1108 return false;
1109 }
1110 return reply.ReadBool();
1111 }
1112
IsAclEncrypted(int32_t transport,const std::string & address)1113 bool BluetoothHostProxy::IsAclEncrypted(int32_t transport, const std::string &address)
1114 {
1115 MessageParcel data;
1116 if (!data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor())) {
1117 HILOGE("BluetoothHostProxy::IsAclEncrypted WriteInterfaceToken error");
1118 return false;
1119 }
1120 if (!data.WriteInt32(transport)) {
1121 HILOGE("BluetoothHostProxy::IsAclEncrypted transport error");
1122 return false;
1123 }
1124 if (!data.WriteString(address)) {
1125 HILOGE("BluetoothHostProxy::IsAclEncrypted address error");
1126 return false;
1127 }
1128 MessageParcel reply;
1129 MessageOption option = {MessageOption::TF_SYNC};
1130 int32_t error = InnerTransact(BluetoothHostInterfaceCode::IS_ACL_ENCRYPTED, option, data, reply);
1131 if (error != NO_ERROR) {
1132 HILOGE("BluetoothHostProxy::IsAclEncrypted done fail, error: %{public}d", error);
1133 return false;
1134 }
1135 return reply.ReadBool();
1136 }
1137
GetDeviceClass(const std::string & address,int & cod)1138 int32_t BluetoothHostProxy::GetDeviceClass(const std::string &address, int &cod)
1139 {
1140 MessageParcel data;
1141 if (!data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor())) {
1142 HILOGE("BluetoothHostProxy::GetDeviceClass WriteInterfaceToken error");
1143 return BT_ERR_INTERNAL_ERROR;
1144 }
1145 if (!data.WriteString(address)) {
1146 HILOGE("BluetoothHostProxy::GetDeviceClass address error");
1147 return BT_ERR_INTERNAL_ERROR;
1148 }
1149 MessageParcel reply;
1150 MessageOption option = {MessageOption::TF_SYNC};
1151 int32_t error = InnerTransact(BluetoothHostInterfaceCode::GET_DEVICE_CLASS, option, data, reply);
1152 if (error != BT_NO_ERROR) {
1153 HILOGE("BluetoothHostProxy::GetDeviceClass done fail, error: %{public}d", error);
1154 return BT_ERR_IPC_TRANS_FAILED;
1155 }
1156 int32_t exception = reply.ReadInt32();
1157 if (exception == BT_NO_ERROR) {
1158 cod = reply.ReadInt32();
1159 }
1160 return exception;
1161 }
1162
SetDevicePin(const std::string & address,const std::string & pin)1163 int32_t BluetoothHostProxy::SetDevicePin(const std::string &address, const std::string &pin)
1164 {
1165 MessageParcel data;
1166 if (!data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor())) {
1167 HILOGE("BluetoothHostProxy::SetDevicePin WriteInterfaceToken error");
1168 return BT_ERR_IPC_TRANS_FAILED;
1169 }
1170 if (!data.WriteString(address)) {
1171 HILOGE("BluetoothHostProxy::SetDevicePin address error");
1172 return BT_ERR_IPC_TRANS_FAILED;
1173 }
1174 if (!data.WriteString(pin)) {
1175 HILOGE("BluetoothHostProxy::SetDevicePin pin error");
1176 return BT_ERR_IPC_TRANS_FAILED;
1177 }
1178 MessageParcel reply;
1179 MessageOption option = {MessageOption::TF_SYNC};
1180 int32_t error = InnerTransact(BluetoothHostInterfaceCode::SET_DEVICE_PIN, option, data, reply);
1181 if (error != BT_NO_ERROR) {
1182 HILOGE("BluetoothHostProxy::SetDevicePin done fail, error: %{public}d", error);
1183 return BT_ERR_IPC_TRANS_FAILED;
1184 }
1185 return reply.ReadInt32();
1186 }
1187
SetDevicePairingConfirmation(int32_t transport,const std::string & address,bool accept)1188 int32_t BluetoothHostProxy::SetDevicePairingConfirmation(int32_t transport, const std::string &address, bool accept)
1189 {
1190 MessageParcel data;
1191 if (!data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor())) {
1192 HILOGE("BluetoothHostProxy::SetDevicePairingConfirmation WriteInterfaceToken error");
1193 return BT_ERR_IPC_TRANS_FAILED;
1194 }
1195 if (!data.WriteInt32(transport)) {
1196 HILOGE("BluetoothHostProxy::SetDevicePairingConfirmation transport error");
1197 return BT_ERR_IPC_TRANS_FAILED;
1198 }
1199 if (!data.WriteString(address)) {
1200 HILOGE("BluetoothHostProxy::SetDevicePairingConfirmation address error");
1201 return BT_ERR_IPC_TRANS_FAILED;
1202 }
1203 if (!data.WriteBool(accept)) {
1204 HILOGE("BluetoothHostProxy::SetDevicePairingConfirmation accept error");
1205 return BT_ERR_IPC_TRANS_FAILED;
1206 }
1207 MessageParcel reply;
1208 MessageOption option = {MessageOption::TF_SYNC};
1209 int32_t error = InnerTransact(BluetoothHostInterfaceCode::SET_DEVICE_PAIRING_CONFIRMATION, option, data, reply);
1210 if (error != BT_NO_ERROR) {
1211 HILOGE("BluetoothHostProxy::SetDevicePairingConfirmation done fail, error: %{public}d", error);
1212 return BT_ERR_IPC_TRANS_FAILED;
1213 }
1214 return reply.ReadInt32();
1215 }
1216
SetDevicePasskey(int32_t transport,const std::string & address,int32_t passkey,bool accept)1217 bool BluetoothHostProxy::SetDevicePasskey(int32_t transport, const std::string &address, int32_t passkey, bool accept)
1218 {
1219 MessageParcel data;
1220 if (!data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor())) {
1221 HILOGE("BluetoothHostProxy::SetDevicePasskey WriteInterfaceToken error");
1222 return false;
1223 }
1224 if (!data.WriteInt32(transport)) {
1225 HILOGE("BluetoothHostProxy::SetDevicePasskey transport error");
1226 return false;
1227 }
1228 if (!data.WriteString(address)) {
1229 HILOGE("BluetoothHostProxy::SetDevicePasskey address error");
1230 return false;
1231 }
1232 if (!data.WriteInt32(passkey)) {
1233 HILOGE("BluetoothHostProxy::SetDevicePasskey passkey error");
1234 return false;
1235 }
1236 if (!data.WriteBool(accept)) {
1237 HILOGE("BluetoothHostProxy::SetDevicePasskey accept error");
1238 return false;
1239 }
1240 MessageParcel reply;
1241 MessageOption option = {MessageOption::TF_SYNC};
1242 int32_t error = InnerTransact(BluetoothHostInterfaceCode::SET_DEVICE_PASSKEY, option, data, reply);
1243 if (error != NO_ERROR) {
1244 HILOGE("BluetoothHostProxy::SetDevicePasskey done fail, error: %{public}d", error);
1245 return false;
1246 }
1247 return reply.ReadBool();
1248 }
1249
PairRequestReply(int32_t transport,const std::string & address,bool accept)1250 bool BluetoothHostProxy::PairRequestReply(int32_t transport, const std::string &address, bool accept)
1251 {
1252 MessageParcel data;
1253 if (!data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor())) {
1254 HILOGE("BluetoothHostProxy::PairRequestReply WriteInterfaceToken error");
1255 return false;
1256 }
1257 if (!data.WriteInt32(transport)) {
1258 HILOGE("BluetoothHostProxy::PairRequestReply transport error");
1259 return false;
1260 }
1261 if (!data.WriteString(address)) {
1262 HILOGE("BluetoothHostProxy::PairRequestReply address error");
1263 return false;
1264 }
1265 if (!data.WriteBool(accept)) {
1266 HILOGE("BluetoothHostProxy::PairRequestReply accept error");
1267 return false;
1268 }
1269 MessageParcel reply;
1270 MessageOption option = {MessageOption::TF_SYNC};
1271 int32_t error = InnerTransact(BluetoothHostInterfaceCode::PAIR_REQUEST_PEPLY, option, data, reply);
1272 if (error != NO_ERROR) {
1273 HILOGE("BluetoothHostProxy::PairRequestReply done fail, error: %{public}d", error);
1274 return false;
1275 }
1276 return reply.ReadBool();
1277 }
1278
ReadRemoteRssiValue(const std::string & address)1279 bool BluetoothHostProxy::ReadRemoteRssiValue(const std::string &address)
1280 {
1281 MessageParcel data;
1282 if (!data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor())) {
1283 HILOGE("BluetoothHostProxy::ReadRemoteRssiValue WriteInterfaceToken error");
1284 return false;
1285 }
1286 if (!data.WriteString(address)) {
1287 HILOGE("BluetoothHostProxy::ReadRemoteRssiValue address error");
1288 return false;
1289 }
1290 MessageParcel reply;
1291 MessageOption option = {MessageOption::TF_SYNC};
1292 int32_t error = InnerTransact(BluetoothHostInterfaceCode::READ_REMOTE_RSSI_VALUE, option, data, reply);
1293 if (error != NO_ERROR) {
1294 HILOGE("BluetoothHostProxy::ReadRemoteRssiValue done fail, error: %{public}d", error);
1295 return false;
1296 }
1297 return reply.ReadBool();
1298 }
1299
GetLocalSupportedUuids(std::vector<std::string> & uuids)1300 void BluetoothHostProxy::GetLocalSupportedUuids(std::vector<std::string> &uuids)
1301 {
1302 MessageParcel data;
1303 if (!data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor())) {
1304 HILOGE("BluetoothHostProxy::GetLocalSupportedUuids WriteInterfaceToken error");
1305 return;
1306 }
1307 MessageParcel reply;
1308 MessageOption option = {MessageOption::TF_SYNC};
1309 int32_t error = InnerTransact(BluetoothHostInterfaceCode::GET_LOCAL_SUPPORTED_UUIDS, option, data, reply);
1310 if (error != NO_ERROR) {
1311 HILOGE("BluetoothHostProxy::GetLocalSupportedUuids done fail, error: %{public}d", error);
1312 return;
1313 }
1314 int32_t size = reply.ReadInt32();
1315 std::string uuid;
1316 for (int32_t i = 0; i < size; i++) {
1317 uuid = reply.ReadString();
1318 uuids.push_back(uuid);
1319 }
1320 }
1321
GetDeviceUuids(const std::string & address,std::vector<std::string> & uuids)1322 int32_t BluetoothHostProxy::GetDeviceUuids(const std::string &address, std::vector<std::string> &uuids)
1323 {
1324 MessageParcel data;
1325 if (!data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor())) {
1326 HILOGE("BluetoothHostProxy::GetDeviceUuids WriteInterfaceToken error");
1327 return BT_ERR_IPC_TRANS_FAILED;
1328 }
1329 if (!data.WriteString(address)) {
1330 HILOGE("BluetoothHostProxy::GetDeviceUuids Write address error");
1331 return BT_ERR_IPC_TRANS_FAILED;
1332 }
1333 MessageParcel reply;
1334 MessageOption option = {MessageOption::TF_SYNC};
1335 int32_t error = InnerTransact(BluetoothHostInterfaceCode::GET_DEVICE_UUIDS, option, data, reply);
1336 if (error != NO_ERROR) {
1337 HILOGE("BluetoothHostProxy::GetDeviceUuids done fail, error: %{public}d", error);
1338 return BT_ERR_IPC_TRANS_FAILED;
1339 }
1340
1341 int32_t size = reply.ReadInt32();
1342 std::string uuid;
1343 for (int32_t i = 0; i < size; i++) {
1344 uuid = reply.ReadString();
1345 uuids.push_back(uuid);
1346 }
1347 return reply.ReadInt32();
1348 }
1349
GetLocalProfileUuids(std::vector<std::string> & uuids)1350 int32_t BluetoothHostProxy::GetLocalProfileUuids(std::vector<std::string> &uuids)
1351 {
1352 MessageParcel data;
1353 if (!data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor())) {
1354 HILOGE("BluetoothHostProxy::GetLocalProfileUuids WriteInterfaceToken error");
1355 return BT_ERR_IPC_TRANS_FAILED;
1356 }
1357 MessageParcel reply;
1358 MessageOption option = {MessageOption::TF_SYNC};
1359 int32_t error = InnerTransact(BluetoothHostInterfaceCode::GET_LOCAL_PROFILE_UUIDS, option, data, reply);
1360 if (error != NO_ERROR) {
1361 HILOGE("BluetoothHostProxy::GetLocalProfileUuids done fail, error: %{public}d", error);
1362 return BT_ERR_IPC_TRANS_FAILED;
1363 }
1364 int32_t size = reply.ReadInt32();
1365 std::string uuid;
1366 for (int32_t i = 0; i < size; i++) {
1367 uuid = reply.ReadString();
1368 uuids.push_back(uuid);
1369 }
1370 return reply.ReadInt32();
1371 }
1372
RegisterBleAdapterObserver(const sptr<IBluetoothHostObserver> & observer)1373 void BluetoothHostProxy::RegisterBleAdapterObserver(const sptr<IBluetoothHostObserver> &observer)
1374 {
1375 HILOGI("BluetoothHostProxy::RegisterBleAdapterObserver start");
1376 MessageParcel data;
1377 if (!data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor())) {
1378 HILOGE("BluetoothHostProxy::RegisterBleAdapterObserver WriteInterfaceToken error");
1379 return;
1380 }
1381 if (!data.WriteRemoteObject(observer->AsObject())) {
1382 HILOGE("BluetoothHostProxy::RegisterBleAdapterObserver error");
1383 return;
1384 }
1385 MessageParcel reply;
1386 MessageOption option = {MessageOption::TF_SYNC};
1387 int32_t error = InnerTransact(BluetoothHostInterfaceCode::BT_REGISTER_BLE_ADAPTER_OBSERVER, option, data, reply);
1388 if (error != NO_ERROR) {
1389 HILOGE("BluetoothHostProxy::RegisterBleAdapterObserver done fail, error: %{public}d", error);
1390 return;
1391 }
1392 HILOGI("BluetoothHostProxy::RegisterBleAdapterObserver success");
1393 }
1394
DeregisterBleAdapterObserver(const sptr<IBluetoothHostObserver> & observer)1395 void BluetoothHostProxy::DeregisterBleAdapterObserver(const sptr<IBluetoothHostObserver> &observer)
1396 {
1397 HILOGI("BluetoothHostProxy::DeregisterBleAdapterObserver start");
1398 MessageParcel data;
1399 if (!data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor())) {
1400 HILOGE("BluetoothHostProxy::DeregisterBleAdapterObserver WriteInterfaceToken error");
1401 return;
1402 }
1403 if (!data.WriteRemoteObject(observer->AsObject())) {
1404 HILOGE("BluetoothHostProxy::DeregisterBleAdapterObserver error");
1405 return;
1406 }
1407 MessageParcel reply;
1408 MessageOption option = {MessageOption::TF_SYNC};
1409 int32_t error = InnerTransact(BluetoothHostInterfaceCode::BT_DEREGISTER_BLE_ADAPTER_OBSERVER, option, data, reply);
1410 if (error != NO_ERROR) {
1411 HILOGE("BluetoothHostProxy::DeregisterBleAdapterObserver done fail, error: %{public}d", error);
1412 return;
1413 }
1414 }
1415
RegisterBlePeripheralCallback(const sptr<IBluetoothBlePeripheralObserver> & observer)1416 void BluetoothHostProxy::RegisterBlePeripheralCallback(const sptr<IBluetoothBlePeripheralObserver> &observer)
1417 {
1418 HILOGI("BluetoothHostProxy::RegisterBlePeripheralCallback start");
1419 MessageParcel data;
1420 if (!data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor())) {
1421 HILOGE("BluetoothHostProxy::RegisterBlePeripheralCallback WriteInterfaceToken error");
1422 return;
1423 }
1424 if (!data.WriteRemoteObject(observer->AsObject())) {
1425 HILOGE("BluetoothHostProxy::RegisterBlePeripheralCallback WriteInterfaceToken error");
1426 return;
1427 }
1428 MessageParcel reply;
1429 MessageOption option = {MessageOption::TF_SYNC};
1430 int32_t error = InnerTransact(BluetoothHostInterfaceCode::BT_REGISTER_BLE_PERIPHERAL_OBSERVER, option, data, reply);
1431 if (error != NO_ERROR) {
1432 HILOGE("BluetoothHostProxy::RegisterBlePeripheralCallback done fail, error: %{public}d", error);
1433 return;
1434 }
1435 return;
1436 }
1437
DeregisterBlePeripheralCallback(const sptr<IBluetoothBlePeripheralObserver> & observer)1438 void BluetoothHostProxy::DeregisterBlePeripheralCallback(const sptr<IBluetoothBlePeripheralObserver> &observer)
1439 {
1440 HILOGI("BluetoothHostProxy::DeregisterBlePeripheralCallback start");
1441 MessageParcel data;
1442 if (!data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor())) {
1443 HILOGE("BluetoothHostProxy::DeregisterBlePeripheralCallback WriteInterfaceToken error");
1444 return;
1445 }
1446 if (!data.WriteRemoteObject(observer->AsObject())) {
1447 HILOGE("BluetoothHostProxy::DeregisterBlePeripheralCallback WriteInterfaceToken error");
1448 return;
1449 }
1450 MessageParcel reply;
1451 MessageOption option = {MessageOption::TF_SYNC};
1452 int32_t error = InnerTransact(
1453 BluetoothHostInterfaceCode::BT_DEREGISTER_BLE_PERIPHERAL_OBSERVER, option, data, reply);
1454 if (error != NO_ERROR) {
1455 HILOGE("BluetoothHostProxy::DeregisterBlePeripheralCallback done fail, error: %{public}d", error);
1456 return;
1457 }
1458 return;
1459 }
1460
InnerTransact(uint32_t code,MessageOption & flags,MessageParcel & data,MessageParcel & reply)1461 int32_t BluetoothHostProxy::InnerTransact(
1462 uint32_t code, MessageOption &flags, MessageParcel &data, MessageParcel &reply)
1463 {
1464 auto remote = Remote();
1465 if (remote == nullptr) {
1466 HILOGW("[InnerTransact] fail: get Remote fail code %{public}d", code);
1467 return OBJECT_NULL;
1468 }
1469 int32_t err = remote->SendRequest(code, data, reply, flags);
1470 if (err != NO_ERROR) {
1471 HILOGW("[InnerTransact] fail: ipcErr=%{public}d code %{public}d", err, code);
1472 }
1473 return err;
1474 }
1475
SetFastScan(bool isEnable)1476 int32_t BluetoothHostProxy::SetFastScan(bool isEnable)
1477 {
1478 MessageParcel data;
1479 if (!data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor())) {
1480 HILOGE("BluetoothHostProxy::SetBtScanMode WriteInterfaceToken error");
1481 return BT_ERR_IPC_TRANS_FAILED;
1482 }
1483 if (!data.WriteBool(isEnable)) {
1484 HILOGE("BluetoothHostProxy::SetFastScan WriteInterfaceToken error");
1485 return BT_ERR_IPC_TRANS_FAILED;
1486 }
1487 MessageParcel reply;
1488 MessageOption option = {MessageOption::TF_SYNC};
1489 int32_t error = InnerTransact(BluetoothHostInterfaceCode::BT_SET_FAST_SCAN, option, data, reply);
1490 if (error != BT_NO_ERROR) {
1491 HILOGE("BluetoothHostProxy::SetFastScan done fail, error: %{public}d", error);
1492 return BT_ERR_IPC_TRANS_FAILED;
1493 }
1494 return reply.ReadInt32();
1495 }
1496
GetRandomAddress(const std::string & realAddr,std::string & randomAddr)1497 int32_t BluetoothHostProxy::GetRandomAddress(const std::string &realAddr, std::string &randomAddr)
1498 {
1499 MessageParcel data;
1500 if (!data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor())) {
1501 HILOGE("BluetoothHostProxy::GetRandomAddress WriteInterfaceToken error");
1502 return BT_ERR_IPC_TRANS_FAILED;
1503 }
1504 if (!data.WriteString(realAddr)) {
1505 HILOGE("BluetoothHostProxy::GetRandomAddress Write realAddr error");
1506 return BT_ERR_IPC_TRANS_FAILED;
1507 }
1508 MessageParcel reply;
1509 MessageOption option = {MessageOption::TF_SYNC};
1510 int32_t error = InnerTransact(BluetoothHostInterfaceCode::GET_RANDOM_ADDRESS, option, data, reply);
1511 if (error != BT_NO_ERROR) {
1512 HILOGE("BluetoothHostProxy::GetRandomAddress fail, error: %{public}d", error);
1513 return BT_ERR_IPC_TRANS_FAILED;
1514 }
1515 randomAddr = reply.ReadString();
1516 return reply.ReadInt32();
1517 }
1518
SyncRandomAddress(const std::string & realAddr,const std::string & randomAddr)1519 int32_t BluetoothHostProxy::SyncRandomAddress(const std::string &realAddr, const std::string &randomAddr)
1520 {
1521 MessageParcel data;
1522 if (!data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor())) {
1523 HILOGE("BluetoothHostProxy::SyncRandomAddress WriteInterfaceToken error");
1524 return BT_ERR_IPC_TRANS_FAILED;
1525 }
1526 if (!data.WriteString(realAddr)) {
1527 HILOGE("BluetoothHostProxy::SyncRandomAddress Write realAddr error");
1528 return BT_ERR_IPC_TRANS_FAILED;
1529 }
1530 if (!data.WriteString(randomAddr)) {
1531 HILOGE("BluetoothHostProxy::SyncRandomAddress Write randomAddr error");
1532 return BT_ERR_IPC_TRANS_FAILED;
1533 }
1534 MessageParcel reply;
1535 MessageOption option = {MessageOption::TF_SYNC};
1536 int32_t error = InnerTransact(BluetoothHostInterfaceCode::SYNC_RANDOM_ADDRESS, option, data, reply);
1537 if (error != BT_NO_ERROR) {
1538 HILOGE("BluetoothHostProxy::SyncRandomAddress fail, error: %{public}d", error);
1539 return BT_ERR_IPC_TRANS_FAILED;
1540 }
1541 return reply.ReadInt32();
1542 }
1543 } // namespace Bluetooth
1544 } // namespace OHOS
1545