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 #ifndef LOG_TAG
16 #define LOG_TAG "bt_ipc_host_proxy"
17 #endif
18
19 #include "bluetooth_host_proxy.h"
20 #include "bluetooth_log.h"
21 #include "bluetooth_errorcode.h"
22
23 using namespace OHOS::bluetooth;
24
25 namespace OHOS {
26 namespace Bluetooth {
RegisterObserver(const sptr<IBluetoothHostObserver> & observer)27 void BluetoothHostProxy::RegisterObserver(const sptr<IBluetoothHostObserver> &observer)
28 {
29 HILOGD("BluetoothHostProxy::RegisterObserver start");
30 MessageParcel data;
31 if (!data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor())) {
32 HILOGE("BluetoothHostProxy::RegisterObserver WriteInterfaceToken error");
33 return;
34 }
35 if (!data.WriteRemoteObject(observer->AsObject())) {
36 HILOGE("BluetoothHostProxy::RegisterObserver error");
37 return;
38 }
39 MessageParcel reply;
40 MessageOption option = {MessageOption::TF_SYNC};
41 int32_t error = InnerTransact(BluetoothHostInterfaceCode::BT_REGISTER_OBSERVER, option, data, reply);
42 if (error != NO_ERROR) {
43 HILOGE("BluetoothHostProxy::RegisterObserver done fail, error: %{public}d", error);
44 return;
45 }
46 HILOGD("BluetoothHostProxy::RegisterObserver success");
47 }
48
DeregisterObserver(const sptr<IBluetoothHostObserver> & observer)49 void BluetoothHostProxy::DeregisterObserver(const sptr<IBluetoothHostObserver> &observer)
50 {
51 MessageParcel data;
52 if (!data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor())) {
53 HILOGE("BluetoothHostProxy::DeregisterObserver WriteInterfaceToken error");
54 return;
55 }
56 if (!data.WriteRemoteObject(observer->AsObject())) {
57 HILOGE("BluetoothHostProxy::DeregisterObserver error");
58 return;
59 }
60 MessageParcel reply;
61 MessageOption option = {MessageOption::TF_SYNC};
62 int32_t error = InnerTransact(BluetoothHostInterfaceCode::BT_DEREGISTER_OBSERVER, option, data, reply);
63 if (error != NO_ERROR) {
64 HILOGE("BluetoothHostProxy::DeregisterObserver done fail, error: %{public}d", error);
65 return;
66 }
67 }
68
EnableBt()69 int32_t BluetoothHostProxy::EnableBt()
70 {
71 MessageParcel data;
72 HILOGI("BluetoothHostProxy::EnableBt starts");
73 if (!data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor())) {
74 HILOGE("BluetoothHostProxy::EnableBt WriteInterfaceToken error");
75 return BT_ERR_IPC_TRANS_FAILED;
76 }
77
78 MessageParcel reply;
79 MessageOption option = {MessageOption::TF_SYNC};
80 int32_t error = InnerTransact(BluetoothHostInterfaceCode::BT_ENABLE, option, data, reply);
81 if (error != NO_ERROR) {
82 HILOGE("BluetoothHostProxy::EnableBt done fail, error: %{public}d", error);
83 return BT_ERR_IPC_TRANS_FAILED;
84 }
85 return reply.ReadInt32();
86 }
87
DisableBt()88 int32_t BluetoothHostProxy::DisableBt()
89 {
90 HILOGI("BluetoothHostProxy::DisableBt starts");
91 MessageParcel data;
92 if (!data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor())) {
93 HILOGE("BluetoothHostProxy::DisableBt WriteInterfaceToken error");
94 return BT_ERR_IPC_TRANS_FAILED;
95 }
96
97 MessageParcel reply;
98 MessageOption option = {MessageOption::TF_SYNC};
99 int32_t error = InnerTransact(BluetoothHostInterfaceCode::BT_DISABLE, option, data, reply);
100 if (error != BT_NO_ERROR) {
101 HILOGE("BluetoothHostProxy::DisableBt done fail, error: %{public}d", error);
102 return BT_ERR_IPC_TRANS_FAILED;
103 }
104 return reply.ReadInt32();
105 }
106
SatelliteControl(int type,int state)107 int32_t BluetoothHostProxy::SatelliteControl(int type, int state)
108 {
109 HILOGI("BluetoothHostProxy::SatelliteControl starts");
110 MessageParcel data;
111 if (!data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor())) {
112 HILOGI("BluetoothHostProxy::SatelliteControl WriteInterfaceToken error");
113 return BT_ERR_IPC_TRANS_FAILED;
114 }
115 CHECK_AND_RETURN_LOG_RET(data.WriteInt32(type), BT_ERR_IPC_TRANS_FAILED, "Write type error");
116 CHECK_AND_RETURN_LOG_RET(data.WriteInt32(state), BT_ERR_IPC_TRANS_FAILED, "Write state error");
117
118 MessageParcel reply;
119 MessageOption option = {MessageOption::TF_SYNC};
120 int32_t error = InnerTransact(BluetoothHostInterfaceCode::SATELLITE_CONTROL, option, data, reply);
121 if (error != BT_NO_ERROR) {
122 HILOGE("BluetoothHostProxy::SatelliteControl done fail, error: %{public}d", error);
123 return BT_ERR_IPC_TRANS_FAILED;
124 }
125 return reply.ReadInt32();
126 }
127
GetProfile(const std::string & name)128 sptr<IRemoteObject> BluetoothHostProxy::GetProfile(const std::string &name)
129 {
130 MessageParcel data;
131 if (!data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor())) {
132 HILOGE("BluetoothHostProxy::GetProfile WriteInterfaceToken error");
133 return nullptr;
134 }
135 if (!data.WriteString(name)) {
136 HILOGE("BluetoothHostProxy::GetProfile name error");
137 return nullptr;
138 }
139 MessageParcel reply;
140 MessageOption option = {MessageOption::TF_SYNC};
141 int32_t error = InnerTransact(BluetoothHostInterfaceCode::BT_GETPROFILE, option, data, reply);
142 if (error != NO_ERROR) {
143 HILOGD("BluetoothHostProxy::GetProfile done fail, error: %{public}d", error);
144 return nullptr;
145 }
146 return reply.ReadRemoteObject();
147 }
148
GetBleRemote(const std::string & name)149 sptr<IRemoteObject> BluetoothHostProxy::GetBleRemote(const std::string &name)
150 {
151 MessageParcel data;
152 if (!data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor())) {
153 HILOGE("BluetoothHostProxy::GetProfile WriteInterfaceToken error");
154 return nullptr;
155 }
156 if (!data.WriteString(name)) {
157 HILOGE("BluetoothHostProxy::GetProfile name error");
158 return nullptr;
159 }
160 MessageParcel reply;
161 MessageOption option = {MessageOption::TF_SYNC};
162 int32_t error = InnerTransact(BluetoothHostInterfaceCode::BT_GET_BLE, option, data, reply);
163 if (error != NO_ERROR) {
164 HILOGE("BluetoothHostProxy::GetProfile done fail, error: %{public}d", error);
165 return nullptr;
166 }
167 return reply.ReadRemoteObject();
168 }
169
BluetoothFactoryReset()170 int32_t BluetoothHostProxy::BluetoothFactoryReset()
171 {
172 MessageParcel data;
173 CHECK_AND_RETURN_LOG_RET(data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor()),
174 BT_ERR_IPC_TRANS_FAILED, "WriteInterfaceToken error");
175
176 MessageParcel reply;
177 MessageOption option = {MessageOption::TF_SYNC};
178 int32_t ret = InnerTransact(BluetoothHostInterfaceCode::BT_FACTORY_RESET, option, data, reply);
179 CHECK_AND_RETURN_LOG_RET(ret == BT_NO_ERROR, BT_ERR_IPC_TRANS_FAILED, "error: %{public}d", ret);
180
181 return reply.ReadInt32();
182 }
183
GetBtState(int & state)184 int32_t BluetoothHostProxy::GetBtState(int &state)
185 {
186 HILOGD("BluetoothHostProxy::GetBtState starts");
187 MessageParcel data;
188 if (!data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor())) {
189 HILOGE("BluetoothHostProxy::GetBtState WriteInterfaceToken error");
190 return -1;
191 }
192 MessageParcel reply;
193 MessageOption option = {MessageOption::TF_SYNC};
194 int32_t error = InnerTransact(BluetoothHostInterfaceCode::BT_GETSTATE, option, data, reply);
195 if (error != NO_ERROR) {
196 HILOGE("BluetoothHostProxy::GetBtState done fail, error: %{public}d", error);
197 return BT_ERR_IPC_TRANS_FAILED;
198 }
199
200 int32_t exception = reply.ReadInt32();
201 if (exception == NO_ERROR) {
202 state = reply.ReadInt32();
203 }
204 return exception;
205 }
206
GetLocalAddress(std::string & addr)207 int32_t BluetoothHostProxy::GetLocalAddress(std::string &addr)
208 {
209 MessageParcel data;
210 CHECK_AND_RETURN_LOG_RET(data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor()),
211 BT_ERR_IPC_TRANS_FAILED, "GetLocalAddress WriteInterfaceToken error");
212
213 MessageParcel reply;
214 MessageOption option = {MessageOption::TF_SYNC};
215 int32_t error = InnerTransact(BluetoothHostInterfaceCode::BT_GET_LOCAL_ADDRESS, option, data, reply);
216 CHECK_AND_RETURN_LOG_RET((error == BT_NO_ERROR), BT_ERR_IPC_TRANS_FAILED, "error: %{public}d", error);
217
218 int32_t exception = reply.ReadInt32();
219 if (exception == BT_NO_ERROR) {
220 addr = reply.ReadString();
221 }
222 return exception;
223 }
224
DisableBle()225 int32_t BluetoothHostProxy::DisableBle()
226 {
227 MessageParcel data;
228 if (!data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor())) {
229 HILOGE("BluetoothHostProxy::DisableBle WriteInterfaceToken error");
230 return BT_ERR_IPC_TRANS_FAILED;
231 }
232 MessageParcel reply;
233 MessageOption option = {MessageOption::TF_SYNC};
234 int32_t error = InnerTransact(BluetoothHostInterfaceCode::BT_DISABLE_BLE, option, data, reply);
235 if (error != BT_NO_ERROR) {
236 HILOGE("BluetoothHostProxy::DisableBle done fail, error: %{public}d", error);
237 return BT_ERR_IPC_TRANS_FAILED;
238 }
239 return reply.ReadInt32();
240 }
241
EnableBle(bool noAutoConnect)242 int32_t BluetoothHostProxy::EnableBle(bool noAutoConnect)
243 {
244 MessageParcel data;
245 if (!data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor())) {
246 HILOGE("BluetoothHostProxy::EnableBle WriteInterfaceToken error");
247 return BT_ERR_IPC_TRANS_FAILED;
248 }
249 if (!data.WriteBool(noAutoConnect)) {
250 HILOGE("BluetoothHostProxy::EnableBle WriteBool error");
251 return BT_ERR_IPC_TRANS_FAILED;
252 }
253 MessageParcel reply;
254 MessageOption option = {MessageOption::TF_SYNC};
255
256 int32_t error = InnerTransact(BluetoothHostInterfaceCode::BT_ENABLE_BLE, option, data, reply);
257 if (error != BT_NO_ERROR) {
258 HILOGE("BluetoothHostProxy::EnableBle done fail, error: %{public}d", error);
259 return BT_ERR_IPC_TRANS_FAILED;
260 }
261 return reply.ReadInt32();
262 }
263
GetProfileList()264 std::vector<uint32_t> BluetoothHostProxy::GetProfileList()
265 {
266 std::vector<uint32_t> vec;
267 MessageParcel data;
268 if (!data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor())) {
269 HILOGE("BluetoothHostProxy::GetProfileList WriteInterfaceToken error");
270 return vec;
271 }
272 MessageParcel reply;
273 MessageOption option = {MessageOption::TF_SYNC};
274 int32_t error = InnerTransact(BluetoothHostInterfaceCode::BT_GET_PROFILE_LIST, option, data, reply);
275 if (error != NO_ERROR) {
276 HILOGE("BluetoothHostProxy::GetProfileList done fail, error: %{public}d", error);
277 return vec;
278 }
279 if (!reply.ReadUInt32Vector(&vec)) {
280 HILOGE("BluetoothHostProxy::GetProfileList Read reply fail");
281 return vec;
282 }
283 return vec;
284 }
285
GetMaxNumConnectedAudioDevices()286 int32_t BluetoothHostProxy::GetMaxNumConnectedAudioDevices()
287 {
288 MessageParcel data;
289 if (!data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor())) {
290 HILOGE("BluetoothHostProxy::GetMaxNumConnectedAudioDevices WriteInterfaceToken error");
291 return -1;
292 }
293 MessageParcel reply;
294 MessageOption option = {MessageOption::TF_SYNC};
295 int32_t error = InnerTransact(
296 BluetoothHostInterfaceCode::BT_GET_MAXNUM_CONNECTED_AUDIODEVICES, option, data, reply);
297 if (error != NO_ERROR) {
298 HILOGE("BluetoothHostProxy::GetMaxNumConnectedAudioDevices done fail, error: %{public}d", error);
299 return -1;
300 }
301 int32_t maxNum;
302 if (!reply.ReadInt32(maxNum)) {
303 HILOGE("BluetoothHostProxy::GetMaxNumConnectedAudioDevices Read reply fail");
304 return -1;
305 }
306 return maxNum;
307 }
308
GetBtConnectionState(int & state)309 int32_t BluetoothHostProxy::GetBtConnectionState(int &state)
310 {
311 HILOGD("BluetoothHostProxy::GetBtConnectionState starts");
312 MessageParcel data;
313 if (!data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor())) {
314 HILOGE("BluetoothHostProxy::GetBtConnectionState WriteInterfaceToken error");
315 return BT_ERR_IPC_TRANS_FAILED;
316 }
317 MessageParcel reply;
318 MessageOption option = {MessageOption::TF_SYNC};
319 int32_t error = InnerTransact(BluetoothHostInterfaceCode::BT_GET_BT_STATE, option, data, reply);
320 if (error != BT_NO_ERROR) {
321 HILOGE("BluetoothHostProxy::GetBtConnectionState done fail, error: %{public}d", error);
322 return BT_ERR_IPC_TRANS_FAILED;
323 }
324 int32_t exception = reply.ReadInt32();
325 if (exception == BT_NO_ERROR) {
326 state = reply.ReadInt32();
327 }
328 return exception;
329 }
330
GetBtProfileConnState(uint32_t profileId,int & state)331 int32_t BluetoothHostProxy::GetBtProfileConnState(uint32_t profileId, int &state)
332 {
333 MessageParcel data;
334 if (!data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor())) {
335 HILOGE("BluetoothHostProxy::GetBtProfileConnState WriteInterfaceToken error");
336 return BT_ERR_IPC_TRANS_FAILED;
337 }
338 if (!data.WriteUint32(profileId)) {
339 HILOGE("BluetoothHostProxy::GetBtProfileConnState WriteInterfaceToken error");
340 return BT_ERR_IPC_TRANS_FAILED;
341 }
342 MessageParcel reply;
343 MessageOption option = {MessageOption::TF_SYNC};
344 int32_t error = InnerTransact(BluetoothHostInterfaceCode::BT_GET_BT_PROFILE_CONNSTATE, option, data, reply);
345 if (error != BT_NO_ERROR) {
346 HILOGE("BluetoothHostProxy::GetBtProfileConnState done fail, error: %{public}d", error);
347 return BT_ERR_IPC_TRANS_FAILED;
348 }
349
350 int32_t exception = reply.ReadInt32();
351 if (exception == BT_NO_ERROR) {
352 state = reply.ReadInt32();
353 }
354 return exception;
355 }
356
GetLocalDeviceClass()357 int32_t BluetoothHostProxy::GetLocalDeviceClass()
358 {
359 MessageParcel data;
360 if (!data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor())) {
361 HILOGE("BluetoothHostProxy::GetLocalDeviceClass WriteInterfaceToken error");
362 return -1;
363 }
364 MessageParcel reply;
365 MessageOption option = {MessageOption::TF_SYNC};
366 int32_t error = InnerTransact(BluetoothHostInterfaceCode::BT_GET_LOCAL_DEVICE_CLASS, option, data, reply);
367 if (error != NO_ERROR) {
368 HILOGE("BluetoothHostProxy::GetLocalDeviceClass done fail, error: %{public}d", error);
369 return -1;
370 }
371
372 int32_t result;
373 if (!reply.ReadInt32(result)) {
374 HILOGE("BluetoothHostProxy::GetLocalDeviceClass Read reply fail");
375 return -1;
376 }
377 return result;
378 }
379
SetLocalDeviceClass(const int32_t & deviceClass)380 bool BluetoothHostProxy::SetLocalDeviceClass(const int32_t &deviceClass)
381 {
382 MessageParcel data;
383 if (!data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor())) {
384 HILOGE("BluetoothHostProxy::SetLocalDeviceClass WriteInterfaceToken error");
385 return false;
386 }
387 if (!data.WriteUint32(deviceClass)) {
388 HILOGE("BluetoothHostProxy::SetLocalDeviceClass WriteInterfaceToken error");
389 return false;
390 }
391 MessageParcel reply;
392 MessageOption option = {MessageOption::TF_SYNC};
393 int32_t error = InnerTransact(BluetoothHostInterfaceCode::BT_SET_LOCAL_DEVICE_CLASS, option, data, reply);
394 if (error != NO_ERROR) {
395 HILOGE("BluetoothHostProxy::SetLocalDeviceClass done fail, error: %{public}d", error);
396 return false;
397 }
398 return reply.ReadBool();
399 }
400
GetLocalName(std::string & name)401 int32_t BluetoothHostProxy::GetLocalName(std::string &name)
402 {
403 MessageParcel data;
404 if (!data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor())) {
405 HILOGE("BluetoothHostProxy::GetLocalName WriteInterfaceToken error");
406 return BT_ERR_IPC_TRANS_FAILED;
407 }
408 MessageParcel reply;
409 MessageOption option = {MessageOption::TF_SYNC};
410 int32_t error = InnerTransact(BluetoothHostInterfaceCode::BT_GET_LOCAL_NAME, option, data, reply);
411 if (error != BT_NO_ERROR) {
412 HILOGE("BluetoothHostProxy::GetLocalName done fail, error: %{public}d", error);
413 return BT_ERR_IPC_TRANS_FAILED;
414 }
415 int32_t exception = reply.ReadInt32();
416 if (exception == BT_NO_ERROR) {
417 name = reply.ReadString();
418 }
419 return exception;
420 }
421
SetLocalName(const std::string & name)422 int32_t BluetoothHostProxy::SetLocalName(const std::string &name)
423 {
424 MessageParcel data;
425 if (!data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor())) {
426 HILOGE("BluetoothHostProxy::SetLocalName WriteInterfaceToken error");
427 return BT_ERR_IPC_TRANS_FAILED;
428 }
429 if (!data.WriteString(name)) {
430 HILOGE("BluetoothHostProxy::SetLocalName WriteInterfaceToken error");
431 return BT_ERR_IPC_TRANS_FAILED;
432 }
433 MessageParcel reply;
434 MessageOption option = {MessageOption::TF_SYNC};
435 int32_t error = InnerTransact(BluetoothHostInterfaceCode::BT_SET_LOCAL_NAME, option, data, reply);
436 if (error != BT_NO_ERROR) {
437 HILOGE("BluetoothHostProxy::SetLocalName done fail, error: %{public}d", error);
438 return BT_ERR_IPC_TRANS_FAILED;
439 }
440 return reply.ReadInt32();
441 }
442
GetBtScanMode(int32_t & scanMode)443 int32_t BluetoothHostProxy::GetBtScanMode(int32_t &scanMode)
444 {
445 MessageParcel data;
446 if (!data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor())) {
447 HILOGE("BluetoothHostProxy::GetBtScanMode WriteInterfaceToken error");
448 return BT_ERR_IPC_TRANS_FAILED;
449 }
450 MessageParcel reply;
451 MessageOption option = {MessageOption::TF_SYNC};
452 int32_t error = InnerTransact(BluetoothHostInterfaceCode::BT_GET_BT_SCAN_MODE, option, data, reply);
453 if (error != BT_NO_ERROR) {
454 HILOGE("BluetoothHostProxy::GetBtScanMode done fail, error: %{public}d", error);
455 return BT_ERR_IPC_TRANS_FAILED;
456 }
457 int32_t exception = reply.ReadInt32();
458 if (exception == BT_NO_ERROR) {
459 scanMode = reply.ReadInt32();
460 }
461 return exception;
462 }
463
SetBtScanMode(int32_t mode,int32_t duration)464 int32_t BluetoothHostProxy::SetBtScanMode(int32_t mode, int32_t duration)
465 {
466 MessageParcel data;
467 if (!data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor())) {
468 HILOGE("BluetoothHostProxy::SetBtScanMode WriteInterfaceToken error");
469 return BT_ERR_IPC_TRANS_FAILED;
470 }
471 if (!data.WriteInt32(mode)) {
472 HILOGE("BluetoothHostProxy::SetBtScanMode WriteInterfaceToken error");
473 return BT_ERR_IPC_TRANS_FAILED;
474 }
475 if (!data.WriteInt32(duration)) {
476 HILOGE("BluetoothHostProxy::SetBtScanMode WriteInterfaceToken error");
477 return BT_ERR_IPC_TRANS_FAILED;
478 }
479 MessageParcel reply;
480 MessageOption option = {MessageOption::TF_SYNC};
481 int32_t error = InnerTransact(BluetoothHostInterfaceCode::BT_SET_BT_SCAN_MODE, option, data, reply);
482 if (error != BT_NO_ERROR) {
483 HILOGE("BluetoothHostProxy::SetBtScanMode done fail, error: %{public}d", error);
484 return BT_ERR_IPC_TRANS_FAILED;
485 }
486 return reply.ReadInt32();
487 }
488
GetBondableMode(const int32_t transport)489 int32_t BluetoothHostProxy::GetBondableMode(const int32_t transport)
490 {
491 int32_t Mode;
492 MessageParcel data;
493 if (!data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor())) {
494 HILOGE("BluetoothHostProxy::GetBondableMode WriteInterfaceToken error");
495 return -1;
496 }
497 if (!data.WriteInt32(transport)) {
498 HILOGE("BluetoothHostProxy::GetBondableMode WriteInterfaceToken error");
499 return -1;
500 }
501 MessageParcel reply;
502 MessageOption option = {MessageOption::TF_SYNC};
503 int32_t error = InnerTransact(BluetoothHostInterfaceCode::BT_GET_BONDABLE_MODE, option, data, reply);
504 if (error != NO_ERROR) {
505 HILOGE("BluetoothHostProxy::GetBondableMode done fail, error: %{public}d", error);
506 return -1;
507 }
508 if (!reply.ReadInt32(Mode)) {
509 HILOGE("BluetoothHostProxy::GetBondableMode Read reply fail");
510 return -1;
511 }
512 return Mode;
513 }
514
SetBondableMode(int32_t transport,int32_t mode)515 bool BluetoothHostProxy::SetBondableMode(int32_t transport, int32_t mode)
516 {
517 MessageParcel data;
518 if (!data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor())) {
519 HILOGE("BluetoothHostProxy::SetBondableMode WriteInterfaceToken error");
520 return false;
521 }
522 if (!data.WriteInt32(transport)) {
523 HILOGE("BluetoothHostProxy::SetBondableMode WriteInterfaceToken error");
524 return false;
525 }
526 if (!data.WriteInt32(mode)) {
527 HILOGE("BluetoothHostProxy::SetBondableMode WriteInterfaceToken error");
528 return false;
529 }
530 MessageParcel reply;
531 MessageOption option = {MessageOption::TF_SYNC};
532 int32_t error = InnerTransact(BluetoothHostInterfaceCode::BT_SET_BONDABLE_MODE, option, data, reply);
533 if (error != NO_ERROR) {
534 HILOGE("BluetoothHostProxy::SetBondableMode done fail, error: %{public}d", error);
535 return false;
536 }
537 return reply.ReadBool();
538 }
539
StartBtDiscovery()540 int32_t BluetoothHostProxy::StartBtDiscovery()
541 {
542 MessageParcel data;
543 if (!data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor())) {
544 HILOGE("BluetoothHostProxy::StartBtDiscovery WriteInterfaceToken error");
545 return BT_ERR_IPC_TRANS_FAILED;
546 }
547 MessageParcel reply;
548 MessageOption option = {MessageOption::TF_SYNC};
549 int32_t error = InnerTransact(BluetoothHostInterfaceCode::BT_START_BT_DISCOVERY, option, data, reply);
550 if (error != BT_NO_ERROR) {
551 HILOGE("BluetoothHostProxy::StartBtDiscovery done fail, error: %{public}d", error);
552 return BT_ERR_IPC_TRANS_FAILED;
553 }
554 return reply.ReadInt32();
555 }
556
CancelBtDiscovery()557 int32_t BluetoothHostProxy::CancelBtDiscovery()
558 {
559 MessageParcel data;
560 if (!data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor())) {
561 HILOGE("BluetoothHostProxy::CancelBtDiscovery WriteInterfaceToken error");
562 return BT_ERR_IPC_TRANS_FAILED;
563 }
564 MessageParcel reply;
565 MessageOption option = {MessageOption::TF_SYNC};
566
567 int32_t error = InnerTransact(BluetoothHostInterfaceCode::BT_CANCEL_BT_DISCOVERY, option, data, reply);
568 if (error != BT_NO_ERROR) {
569 HILOGE("BluetoothHostProxy::CancelBtDiscovery done fail, error: %{public}d", error);
570 return BT_ERR_IPC_TRANS_FAILED;
571 }
572 return reply.ReadInt32();
573 }
574
IsBtDiscovering(bool & isDisCovering,const int32_t transport)575 int32_t BluetoothHostProxy::IsBtDiscovering(bool &isDisCovering, const int32_t transport)
576 {
577 MessageParcel data;
578 if (!data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor())) {
579 HILOGE("BluetoothHostProxy::IsBtDiscovering WriteInterfaceToken error");
580 return BT_ERR_IPC_TRANS_FAILED;
581 }
582 if (!data.WriteInt32(transport)) {
583 HILOGE("BluetoothHostProxy::IsBtDiscovering WriteInterfaceToken error");
584 return BT_ERR_IPC_TRANS_FAILED;
585 }
586 MessageParcel reply;
587 MessageOption option = {MessageOption::TF_SYNC};
588 int32_t error = InnerTransact(BluetoothHostInterfaceCode::BT_IS_BT_DISCOVERING, option, data, reply);
589 if (error != BT_NO_ERROR) {
590 HILOGE("BluetoothHostProxy::Start done fail, error: %{public}d", error);
591 return BT_ERR_IPC_TRANS_FAILED;
592 }
593 int32_t exception = reply.ReadInt32();
594 if (exception == BT_NO_ERROR) {
595 isDisCovering = reply.ReadBool();
596 }
597 return exception;
598 }
599
GetBtDiscoveryEndMillis()600 long BluetoothHostProxy::GetBtDiscoveryEndMillis()
601 {
602 long millis;
603 MessageParcel data;
604 if (!data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor())) {
605 HILOGE("BluetoothHostProxy::GetBtDiscoveryEndMillis WriteInterfaceToken error");
606 return -1;
607 }
608 MessageParcel reply;
609 MessageOption option = {MessageOption::TF_SYNC};
610 int32_t error = InnerTransact(BluetoothHostInterfaceCode::BT_GET_BT_DISCOVERY_END_MILLIS, option, data, reply);
611 if (error != NO_ERROR) {
612 HILOGE("BluetoothHostProxy::GetBtDiscoveryEndMillis done fail, error: %{public}d", error);
613 return -1;
614 }
615 millis = static_cast<long>(reply.ReadInt64());
616 return millis;
617 }
618
GetPairedDevices(std::vector<BluetoothRawAddress> & pairedAddr)619 int32_t BluetoothHostProxy::GetPairedDevices(std::vector<BluetoothRawAddress> &pairedAddr)
620 {
621 MessageParcel data;
622 if (!data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor())) {
623 HILOGE("BluetoothHostProxy::GetPairedDevices WriteInterfaceToken error");
624 return BT_ERR_IPC_TRANS_FAILED;
625 }
626 MessageParcel reply;
627 MessageOption option = {MessageOption::TF_SYNC};
628 int32_t error = InnerTransact(BluetoothHostInterfaceCode::BT_GET_PAIRED_DEVICES, option, data, reply);
629 if (error != BT_NO_ERROR) {
630 HILOGE("BluetoothHostProxy::GetPairedDevices done fail, error: %{public}d", error);
631 return BT_ERR_IPC_TRANS_FAILED;
632 }
633 int32_t size = reply.ReadInt32();
634 const int32_t maxSize = 100;
635 if (size > maxSize) {
636 return BT_ERR_INVALID_PARAM;
637 }
638 for (int32_t i = 0; i < size; i++) {
639 std::shared_ptr<BluetoothRawAddress> rawAddress(reply.ReadParcelable<BluetoothRawAddress>());
640 if (!rawAddress) {
641 return BT_ERR_IPC_TRANS_FAILED;
642 }
643 pairedAddr.push_back(*rawAddress);
644 }
645 return reply.ReadInt32();
646 }
647
RemovePair(const int32_t transport,const sptr<BluetoothRawAddress> & device)648 int32_t BluetoothHostProxy::RemovePair(const int32_t transport, const sptr<BluetoothRawAddress> &device)
649 {
650 MessageParcel data;
651 if (!data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor())) {
652 HILOGE("BluetoothHostProxy::RemovePair WriteInterfaceToken error");
653 return BT_ERR_IPC_TRANS_FAILED;
654 }
655 if (!data.WriteInt32(transport)) {
656 HILOGE("BluetoothHostProxy::RemovePair WriteInterfaceToken error");
657 return BT_ERR_IPC_TRANS_FAILED;
658 }
659 if (!data.WriteParcelable(device.GetRefPtr())) {
660 HILOGE("BluetoothHostProxy::RemovePair WriteInterfaceToken error");
661 return BT_ERR_IPC_TRANS_FAILED;
662 }
663 MessageParcel reply;
664 MessageOption option = {MessageOption::TF_SYNC};
665 int32_t error = InnerTransact(BluetoothHostInterfaceCode::BT_REMOVE_PAIR, option, data, reply);
666 if (error != BT_NO_ERROR) {
667 HILOGE("BluetoothHostProxy::RemovePair done fail, error: %{public}d", error);
668 return BT_ERR_IPC_TRANS_FAILED;
669 }
670 return reply.ReadInt32();
671 }
672
RemoveAllPairs()673 bool BluetoothHostProxy::RemoveAllPairs()
674 {
675 MessageParcel data;
676 if (!data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor())) {
677 HILOGE("BluetoothHostProxy::RemoveAllPairs WriteInterfaceToken error");
678 return false;
679 }
680 MessageParcel reply;
681 MessageOption option = {MessageOption::TF_SYNC};
682
683 int32_t error = InnerTransact(BluetoothHostInterfaceCode::BT_REMOVE_ALL_PAIRS, option, data, reply);
684 if (error != NO_ERROR) {
685 HILOGE("BluetoothHostProxy::RemoveAllPairs done fail, error: %{public}d", error);
686 return false;
687 }
688 return reply.ReadBool();
689 }
690
RegisterRemoteDeviceObserver(const sptr<IBluetoothRemoteDeviceObserver> & observer)691 void BluetoothHostProxy::RegisterRemoteDeviceObserver(const sptr<IBluetoothRemoteDeviceObserver> &observer)
692 {
693 MessageParcel data;
694 if (!data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor())) {
695 HILOGE("BluetoothHostProxy::RegisterRemoteDeviceObserver WriteInterfaceToken error");
696 return;
697 }
698 if (!data.WriteRemoteObject(observer->AsObject())) {
699 HILOGE("BluetoothHostProxy::RegisterRemoteDeviceObserver WriteInterfaceToken error");
700 return;
701 }
702 MessageParcel reply;
703 MessageOption option = {MessageOption::TF_SYNC};
704 int32_t error = InnerTransact(BluetoothHostInterfaceCode::BT_REGISTER_REMOTE_DEVICE_OBSERVER, option, data, reply);
705 if (error != NO_ERROR) {
706 HILOGE("BluetoothHostProxy::GetBtConnectionState done fail, error: %{public}d", error);
707 return;
708 }
709 return;
710 }
711
DeregisterRemoteDeviceObserver(const sptr<IBluetoothRemoteDeviceObserver> & observer)712 void BluetoothHostProxy::DeregisterRemoteDeviceObserver(const sptr<IBluetoothRemoteDeviceObserver> &observer)
713 {
714 MessageParcel data;
715 if (!data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor())) {
716 HILOGE("BluetoothHostProxy::DeregisterRemoteDeviceObserver WriteInterfaceToken error");
717 return;
718 }
719 if (!data.WriteRemoteObject(observer->AsObject())) {
720 HILOGE("BluetoothHostProxy::DeregisterRemoteDeviceObserver WriteInterfaceToken error");
721 return;
722 }
723 MessageParcel reply;
724 MessageOption option = {MessageOption::TF_SYNC};
725 int32_t error = InnerTransact(
726 BluetoothHostInterfaceCode::BT_DEREGISTER_REMOTE_DEVICE_OBSERVER, option, data, reply);
727 if (error != NO_ERROR) {
728 HILOGE("BluetoothHostProxy::DeregisterRemoteDeviceObserver done fail, error: %{public}d", error);
729 return;
730 }
731 return;
732 }
733
GetBleMaxAdvertisingDataLength()734 int32_t BluetoothHostProxy::GetBleMaxAdvertisingDataLength()
735 {
736 MessageParcel data;
737 if (!data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor())) {
738 HILOGE("BluetoothHostProxy::GetBleMaxAdvertisingDataLength WriteInterfaceToken error");
739 return false;
740 }
741 MessageParcel reply;
742 MessageOption option = {MessageOption::TF_SYNC};
743 int32_t error = InnerTransact(
744 BluetoothHostInterfaceCode::BT_GET_BLE_MAX_ADVERTISING_DATALENGTH, option, data, reply);
745 if (error != NO_ERROR) {
746 HILOGE("BluetoothHostProxy::GetBleMaxAdvertisingDataLength done fail, error: %{public}d", error);
747 return false;
748 }
749 return reply.ReadInt32();
750 }
751
GetDeviceType(int32_t transport,const std::string & address)752 int32_t BluetoothHostProxy::GetDeviceType(int32_t transport, const std::string &address)
753 {
754 MessageParcel data;
755 if (!data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor())) {
756 HILOGE("BluetoothHostProxy::GetDeviceType WriteInterfaceToken error");
757 return 0;
758 }
759 if (!data.WriteInt32(transport)) {
760 HILOGE("BluetoothHostProxy::GetDeviceType transport error");
761 return 0;
762 }
763 if (!data.WriteString(address)) {
764 HILOGE("BluetoothHostProxy::GetDeviceType address error");
765 return 0;
766 }
767 MessageParcel reply;
768 MessageOption option = {MessageOption::TF_SYNC};
769 int32_t error = InnerTransact(BluetoothHostInterfaceCode::GET_DEVICE_TYPE, option, data, reply);
770 if (error != NO_ERROR) {
771 HILOGE("BluetoothHostProxy::GetDeviceType done fail, error: %{public}d", error);
772 return 0;
773 }
774 return reply.ReadInt32();
775 }
776
GetPhonebookPermission(const std::string & address)777 int32_t BluetoothHostProxy::GetPhonebookPermission(const std::string &address)
778 {
779 MessageParcel data;
780 if (!data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor())) {
781 HILOGE("BluetoothHostProxy::GetPhonebookPermission WriteInterfaceToken error");
782 return 0;
783 }
784 if (!data.WriteString(address)) {
785 HILOGE("BluetoothHostProxy::GetPhonebookPermission address error");
786 return 0;
787 }
788 MessageParcel reply;
789 MessageOption option = {MessageOption::TF_SYNC};
790 int32_t error = InnerTransact(BluetoothHostInterfaceCode::GET_PHONEBOOK_PERMISSION, option, data, reply);
791 if (error != NO_ERROR) {
792 HILOGE("BluetoothHostProxy::GetPhonebookPermission done fail, error: %{public}d", error);
793 return 0;
794 }
795 return reply.ReadInt32();
796 }
797
SetPhonebookPermission(const std::string & address,int32_t permission)798 bool BluetoothHostProxy::SetPhonebookPermission(const std::string &address, int32_t permission)
799 {
800 MessageParcel data;
801 if (!data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor())) {
802 HILOGE("BluetoothHostProxy::SetPhonebookPermission WriteInterfaceToken error");
803 return false;
804 }
805 if (!data.WriteString(address)) {
806 HILOGE("BluetoothHostProxy::SetPhonebookPermission address error");
807 return false;
808 }
809 if (!data.WriteInt32(permission)) {
810 HILOGE("BluetoothHostProxy::SetPhonebookPermission permission error");
811 return false;
812 }
813 MessageParcel reply;
814 MessageOption option = {MessageOption::TF_SYNC};
815 int32_t error = InnerTransact(BluetoothHostInterfaceCode::SET_PHONEBOOK_PERMISSION, option, data, reply);
816 if (error != NO_ERROR) {
817 HILOGE("BluetoothHostProxy::SetPhonebookPermission done fail, error: %{public}d", error);
818 return false;
819 }
820 return reply.ReadBool();
821 }
822
GetMessagePermission(const std::string & address)823 int32_t BluetoothHostProxy::GetMessagePermission(const std::string &address)
824 {
825 MessageParcel data;
826 if (!data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor())) {
827 HILOGE("BluetoothHostProxy::GetMessagePermission WriteInterfaceToken error");
828 return 0;
829 }
830 if (!data.WriteString(address)) {
831 HILOGE("BluetoothHostProxy::GetMessagePermission address error");
832 return 0;
833 }
834 MessageParcel reply;
835 MessageOption option = {MessageOption::TF_SYNC};
836 int32_t error = InnerTransact(BluetoothHostInterfaceCode::GET_MESSAGE_PERMISSION, option, data, reply);
837 if (error != NO_ERROR) {
838 HILOGE("BluetoothHostProxy::GetMessagePermission done fail, error: %{public}d", error);
839 return 0;
840 }
841 return reply.ReadInt32();
842 }
843
SetMessagePermission(const std::string & address,int32_t permission)844 bool BluetoothHostProxy::SetMessagePermission(const std::string &address, int32_t permission)
845 {
846 MessageParcel data;
847 if (!data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor())) {
848 HILOGE("BluetoothHostProxy::SetMessagePermission WriteInterfaceToken error");
849 return false;
850 }
851 if (!data.WriteString(address)) {
852 HILOGE("BluetoothHostProxy::SetMessagePermission address error");
853 return false;
854 }
855 if (!data.WriteInt32(permission)) {
856 HILOGE("BluetoothHostProxy::SetMessagePermission permission error");
857 return false;
858 }
859 MessageParcel reply;
860 MessageOption option = {MessageOption::TF_SYNC};
861 int32_t error = InnerTransact(BluetoothHostInterfaceCode::SET_MESSAGE_PERMISSION, option, data, reply);
862 if (error != NO_ERROR) {
863 HILOGE("BluetoothHostProxy::SetMessagePermission done fail, error: %{public}d", error);
864 return false;
865 }
866 return reply.ReadBool();
867 }
868
GetPowerMode(const std::string & address)869 int32_t BluetoothHostProxy::GetPowerMode(const std::string &address)
870 {
871 MessageParcel data;
872 if (!data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor())) {
873 HILOGE("BluetoothHostProxy::GetPowerMode WriteInterfaceToken error");
874 return 0;
875 }
876 if (!data.WriteString(address)) {
877 HILOGE("BluetoothHostProxy::GetPowerMode address error");
878 return 0;
879 }
880 MessageParcel reply;
881 MessageOption option = {MessageOption::TF_SYNC};
882 int32_t error = InnerTransact(BluetoothHostInterfaceCode::GET_POWER_MODE, option, data, reply);
883 if (error != NO_ERROR) {
884 HILOGE("BluetoothHostProxy::GetPowerMode done fail, error: %{public}d", error);
885 return 0;
886 }
887 return reply.ReadInt32();
888 }
889
GetDeviceName(int32_t transport,const std::string & address,std::string & name,bool alias)890 int32_t BluetoothHostProxy::GetDeviceName(int32_t transport, const std::string &address, std::string &name, bool alias)
891 {
892 MessageParcel data;
893 if (!data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor())) {
894 HILOGE("BluetoothHostProxy::GetDeviceName WriteInterfaceToken error");
895 return BT_ERR_IPC_TRANS_FAILED;
896 }
897 if (!data.WriteInt32(transport)) {
898 HILOGE("BluetoothHostProxy::GetDeviceName transport error");
899 return BT_ERR_IPC_TRANS_FAILED;
900 }
901 if (!data.WriteString(address)) {
902 HILOGE("BluetoothHostProxy::GetDeviceName address error");
903 return BT_ERR_IPC_TRANS_FAILED;
904 }
905 if (!data.WriteBool(alias)) {
906 HILOGE("BluetoothHostProxy::GetDeviceName alias error");
907 return BT_ERR_IPC_TRANS_FAILED;
908 }
909 MessageParcel reply;
910 MessageOption option = {MessageOption::TF_SYNC};
911 int32_t error = InnerTransact(BluetoothHostInterfaceCode::GET_DEVICE_NAME, option, data, reply);
912 if (error != BT_NO_ERROR) {
913 HILOGE("BluetoothHostProxy::GetDeviceName done fail, error: %{public}d", error);
914 return BT_ERR_IPC_TRANS_FAILED;
915 }
916
917 int32_t exception = reply.ReadInt32();
918 if (exception == BT_NO_ERROR) {
919 name = reply.ReadString();
920 }
921 return exception;
922 }
923
GetDeviceAlias(const std::string & address)924 std::string BluetoothHostProxy::GetDeviceAlias(const std::string &address)
925 {
926 MessageParcel data;
927 if (!data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor())) {
928 HILOGE("BluetoothHostProxy::GetDeviceAlias WriteInterfaceToken error");
929 return std::string();
930 }
931 if (!data.WriteString(address)) {
932 HILOGE("BluetoothHostProxy::GetDeviceAlias address error");
933 return std::string();
934 }
935 MessageParcel reply;
936 MessageOption option = {MessageOption::TF_SYNC};
937 int32_t error = InnerTransact(BluetoothHostInterfaceCode::GET_DEVICE_ALIAS, option, data, reply);
938 if (error != NO_ERROR) {
939 HILOGE("BluetoothHostProxy::GetDeviceAlias done fail, error: %{public}d", error);
940 return std::string();
941 }
942 return reply.ReadString();
943 }
944
SetDeviceAlias(const std::string & address,const std::string & aliasName)945 int32_t BluetoothHostProxy::SetDeviceAlias(const std::string &address, const std::string &aliasName)
946 {
947 MessageParcel data;
948 if (!data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor())) {
949 HILOGE("BluetoothHostProxy::SetDeviceAlias WriteInterfaceToken error");
950 return BT_ERR_IPC_TRANS_FAILED;
951 }
952 if (!data.WriteString(address)) {
953 HILOGE("BluetoothHostProxy::SetDeviceAlias address error");
954 return BT_ERR_IPC_TRANS_FAILED;
955 }
956 if (!data.WriteString(aliasName)) {
957 HILOGE("BluetoothHostProxy::SetDeviceAlias aliasName error");
958 return BT_ERR_IPC_TRANS_FAILED;
959 }
960 MessageParcel reply;
961 MessageOption option = {MessageOption::TF_SYNC};
962 int32_t error = InnerTransact(BluetoothHostInterfaceCode::SET_DEVICE_ALIAS, option, data, reply);
963 if (error != NO_ERROR) {
964 HILOGE("BluetoothHostProxy::SetDeviceAlias done fail, error: %{public}d", error);
965 return BT_ERR_INTERNAL_ERROR;
966 }
967 return reply.ReadInt32();
968 }
969
GetRemoteDeviceBatteryInfo(const std::string & address,BluetoothBatteryInfo & batteryInfo)970 int32_t BluetoothHostProxy::GetRemoteDeviceBatteryInfo(const std::string &address, BluetoothBatteryInfo &batteryInfo)
971 {
972 MessageParcel data;
973 CHECK_AND_RETURN_LOG_RET(data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor()),
974 BT_ERR_INTERNAL_ERROR, "write InterfaceToken error");
975 CHECK_AND_RETURN_LOG_RET(data.WriteString(address), BT_ERR_INTERNAL_ERROR, "write address error");
976 MessageParcel reply;
977 MessageOption option = {MessageOption::TF_SYNC};
978 int32_t ret = InnerTransact(BluetoothHostInterfaceCode::GET_DEVICE_BATTERY_INFO, option, data, reply);
979 CHECK_AND_RETURN_LOG_RET(ret == BT_NO_ERROR, BT_ERR_INTERNAL_ERROR, "ret: %{public}d", ret);
980 ret = reply.ReadInt32();
981 CHECK_AND_RETURN_LOG_RET(ret == BT_NO_ERROR, ret, "ret: %{public}d", ret);
982 std::shared_ptr<BluetoothBatteryInfo> info(reply.ReadParcelable<BluetoothBatteryInfo>());
983 CHECK_AND_RETURN_LOG_RET(info != nullptr, BT_ERR_INTERNAL_ERROR, "read info fail");
984 batteryInfo = *info;
985 return ret;
986 }
987
GetPairState(int32_t transport,const std::string & address,int32_t & pairState)988 int32_t BluetoothHostProxy::GetPairState(int32_t transport, const std::string &address, int32_t &pairState)
989 {
990 MessageParcel data;
991 if (!data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor())) {
992 HILOGE("BluetoothHostProxy::GetPairState WriteInterfaceToken error");
993 return BT_ERR_IPC_TRANS_FAILED;
994 }
995 if (!data.WriteInt32(transport)) {
996 HILOGE("BluetoothHostProxy::GetPairState transport error");
997 return BT_ERR_IPC_TRANS_FAILED;
998 }
999 if (!data.WriteString(address)) {
1000 HILOGE("BluetoothHostProxy::GetPairState address error");
1001 return BT_ERR_IPC_TRANS_FAILED;
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 BT_ERR_IPC_TRANS_FAILED;
1009 }
1010 int exception = reply.ReadInt32();
1011 if (exception == BT_NO_ERROR) {
1012 pairState = reply.ReadInt32();
1013 }
1014 return exception;
1015 }
1016
StartPair(int32_t transport,const std::string & address)1017 int32_t BluetoothHostProxy::StartPair(int32_t transport, const std::string &address)
1018 {
1019 MessageParcel data;
1020 if (!data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor())) {
1021 HILOGE("BluetoothHostProxy::StartPair WriteInterfaceToken error");
1022 return BT_ERR_IPC_TRANS_FAILED;
1023 }
1024 if (!data.WriteInt32(transport)) {
1025 HILOGE("BluetoothHostProxy::StartPair transport error");
1026 return BT_ERR_IPC_TRANS_FAILED;
1027 }
1028 if (!data.WriteString(address)) {
1029 HILOGE("BluetoothHostProxy::StartPair address error");
1030 return BT_ERR_IPC_TRANS_FAILED;
1031 }
1032 MessageParcel reply;
1033 MessageOption option = {MessageOption::TF_SYNC};
1034 int32_t error = InnerTransact(BluetoothHostInterfaceCode::START_PAIR, option, data, reply);
1035 if (error != BT_NO_ERROR) {
1036 HILOGE("BluetoothHostProxy::StartPair done fail, error: %{public}d", error);
1037 return BT_ERR_IPC_TRANS_FAILED;
1038 }
1039 return reply.ReadInt32();
1040 }
1041
StartCrediblePair(int32_t transport,const std::string & address)1042 int32_t BluetoothHostProxy::StartCrediblePair(int32_t transport, const std::string &address)
1043 {
1044 MessageParcel data;
1045 if (!data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor())) {
1046 HILOGE("BluetoothHostProxy::StartCrediblePair WriteInterfaceToken error");
1047 return BT_ERR_IPC_TRANS_FAILED;
1048 }
1049 if (!data.WriteInt32(transport)) {
1050 HILOGE("BluetoothHostProxy::StartCrediblePair transport error");
1051 return BT_ERR_IPC_TRANS_FAILED;
1052 }
1053 if (!data.WriteString(address)) {
1054 HILOGE("BluetoothHostProxy::StartCrediblePair address error");
1055 return BT_ERR_IPC_TRANS_FAILED;
1056 }
1057 MessageParcel reply;
1058 MessageOption option = {MessageOption::TF_SYNC};
1059 int32_t error = InnerTransact(BluetoothHostInterfaceCode::START_CREDIBLE_PAIR, option, data, reply);
1060 if (error != BT_NO_ERROR) {
1061 HILOGE("BluetoothHostProxy::StartCrediblePair done fail, error: %{public}d", error);
1062 return BT_ERR_IPC_TRANS_FAILED;
1063 }
1064 return reply.ReadInt32();
1065 }
1066
CancelPairing(int32_t transport,const std::string & address)1067 bool BluetoothHostProxy::CancelPairing(int32_t transport, const std::string &address)
1068 {
1069 MessageParcel data;
1070 if (!data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor())) {
1071 HILOGE("BluetoothHostProxy::CancelPairing WriteInterfaceToken error");
1072 return false;
1073 }
1074 if (!data.WriteInt32(transport)) {
1075 HILOGE("BluetoothHostProxy::CancelPairing transport error");
1076 return false;
1077 }
1078 if (!data.WriteString(address)) {
1079 HILOGE("BluetoothHostProxy::CancelPairing address error");
1080 return false;
1081 }
1082 MessageParcel reply;
1083 MessageOption option = {MessageOption::TF_SYNC};
1084 int32_t error = InnerTransact(BluetoothHostInterfaceCode::CANCEL_PAIRING, option, data, reply);
1085 if (error != NO_ERROR) {
1086 HILOGE("BluetoothHostProxy::CancelPairing done fail, error: %{public}d", error);
1087 return false;
1088 }
1089 return reply.ReadBool();
1090 }
1091
IsBondedFromLocal(int32_t transport,const std::string & address)1092 bool BluetoothHostProxy::IsBondedFromLocal(int32_t transport, const std::string &address)
1093 {
1094 MessageParcel data;
1095 if (!data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor())) {
1096 HILOGE("BluetoothHostProxy::IsBondedFromLocal WriteInterfaceToken error");
1097 return false;
1098 }
1099 if (!data.WriteInt32(transport)) {
1100 HILOGE("BluetoothHostProxy::IsBondedFromLocal transport error");
1101 return false;
1102 }
1103 if (!data.WriteString(address)) {
1104 HILOGE("BluetoothHostProxy::IsBondedFromLocal address error");
1105 return false;
1106 }
1107 MessageParcel reply;
1108 MessageOption option = {MessageOption::TF_SYNC};
1109 int32_t error = InnerTransact(BluetoothHostInterfaceCode::IS_BONDED_FROM_LOCAL, option, data, reply);
1110 if (error != NO_ERROR) {
1111 HILOGE("BluetoothHostProxy::IsBondedFromLocal done fail, error: %{public}d", error);
1112 return false;
1113 }
1114 return reply.ReadBool();
1115 }
1116
IsAclConnected(int32_t transport,const std::string & address)1117 bool BluetoothHostProxy::IsAclConnected(int32_t transport, const std::string &address)
1118 {
1119 MessageParcel data;
1120 if (!data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor())) {
1121 HILOGE("BluetoothHostProxy::IsAclConnected WriteInterfaceToken error");
1122 return false;
1123 }
1124 if (!data.WriteInt32(transport)) {
1125 HILOGE("BluetoothHostProxy::IsAclConnected transport error");
1126 return false;
1127 }
1128 if (!data.WriteString(address)) {
1129 HILOGE("BluetoothHostProxy::IsAclConnected address error");
1130 return false;
1131 }
1132 MessageParcel reply;
1133 MessageOption option = {MessageOption::TF_SYNC};
1134 int32_t error = InnerTransact(BluetoothHostInterfaceCode::IS_ACL_CONNECTED, option, data, reply);
1135 if (error != NO_ERROR) {
1136 HILOGE("BluetoothHostProxy::IsAclConnected done fail, error: %{public}d", error);
1137 return false;
1138 }
1139 return reply.ReadBool();
1140 }
1141
IsAclEncrypted(int32_t transport,const std::string & address)1142 bool BluetoothHostProxy::IsAclEncrypted(int32_t transport, const std::string &address)
1143 {
1144 MessageParcel data;
1145 if (!data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor())) {
1146 HILOGE("BluetoothHostProxy::IsAclEncrypted WriteInterfaceToken error");
1147 return false;
1148 }
1149 if (!data.WriteInt32(transport)) {
1150 HILOGE("BluetoothHostProxy::IsAclEncrypted transport error");
1151 return false;
1152 }
1153 if (!data.WriteString(address)) {
1154 HILOGE("BluetoothHostProxy::IsAclEncrypted address error");
1155 return false;
1156 }
1157 MessageParcel reply;
1158 MessageOption option = {MessageOption::TF_SYNC};
1159 int32_t error = InnerTransact(BluetoothHostInterfaceCode::IS_ACL_ENCRYPTED, option, data, reply);
1160 if (error != NO_ERROR) {
1161 HILOGE("BluetoothHostProxy::IsAclEncrypted done fail, error: %{public}d", error);
1162 return false;
1163 }
1164 return reply.ReadBool();
1165 }
1166
GetDeviceClass(const std::string & address,int & cod)1167 int32_t BluetoothHostProxy::GetDeviceClass(const std::string &address, int &cod)
1168 {
1169 MessageParcel data;
1170 if (!data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor())) {
1171 HILOGE("BluetoothHostProxy::GetDeviceClass WriteInterfaceToken error");
1172 return BT_ERR_INTERNAL_ERROR;
1173 }
1174 if (!data.WriteString(address)) {
1175 HILOGE("BluetoothHostProxy::GetDeviceClass address error");
1176 return BT_ERR_INTERNAL_ERROR;
1177 }
1178 MessageParcel reply;
1179 MessageOption option = {MessageOption::TF_SYNC};
1180 int32_t error = InnerTransact(BluetoothHostInterfaceCode::GET_DEVICE_CLASS, option, data, reply);
1181 if (error != BT_NO_ERROR) {
1182 HILOGE("BluetoothHostProxy::GetDeviceClass done fail, error: %{public}d", error);
1183 return BT_ERR_IPC_TRANS_FAILED;
1184 }
1185 int32_t exception = reply.ReadInt32();
1186 if (exception == BT_NO_ERROR) {
1187 cod = reply.ReadInt32();
1188 }
1189 return exception;
1190 }
1191
SetDevicePin(const std::string & address,const std::string & pin)1192 int32_t BluetoothHostProxy::SetDevicePin(const std::string &address, const std::string &pin)
1193 {
1194 MessageParcel data;
1195 if (!data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor())) {
1196 HILOGE("BluetoothHostProxy::SetDevicePin WriteInterfaceToken error");
1197 return BT_ERR_IPC_TRANS_FAILED;
1198 }
1199 if (!data.WriteString(address)) {
1200 HILOGE("BluetoothHostProxy::SetDevicePin address error");
1201 return BT_ERR_IPC_TRANS_FAILED;
1202 }
1203 if (!data.WriteString(pin)) {
1204 HILOGE("BluetoothHostProxy::SetDevicePin pin 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_PIN, option, data, reply);
1210 if (error != BT_NO_ERROR) {
1211 HILOGE("BluetoothHostProxy::SetDevicePin done fail, error: %{public}d", error);
1212 return BT_ERR_IPC_TRANS_FAILED;
1213 }
1214 return reply.ReadInt32();
1215 }
1216
SetDevicePairingConfirmation(int32_t transport,const std::string & address,bool accept)1217 int32_t BluetoothHostProxy::SetDevicePairingConfirmation(int32_t transport, const std::string &address, bool accept)
1218 {
1219 MessageParcel data;
1220 if (!data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor())) {
1221 HILOGE("BluetoothHostProxy::SetDevicePairingConfirmation WriteInterfaceToken error");
1222 return BT_ERR_IPC_TRANS_FAILED;
1223 }
1224 if (!data.WriteInt32(transport)) {
1225 HILOGE("BluetoothHostProxy::SetDevicePairingConfirmation transport error");
1226 return BT_ERR_IPC_TRANS_FAILED;
1227 }
1228 if (!data.WriteString(address)) {
1229 HILOGE("BluetoothHostProxy::SetDevicePairingConfirmation address error");
1230 return BT_ERR_IPC_TRANS_FAILED;
1231 }
1232 if (!data.WriteBool(accept)) {
1233 HILOGE("BluetoothHostProxy::SetDevicePairingConfirmation accept error");
1234 return BT_ERR_IPC_TRANS_FAILED;
1235 }
1236 MessageParcel reply;
1237 MessageOption option = {MessageOption::TF_SYNC};
1238 int32_t error = InnerTransact(BluetoothHostInterfaceCode::SET_DEVICE_PAIRING_CONFIRMATION, option, data, reply);
1239 if (error != BT_NO_ERROR) {
1240 HILOGE("BluetoothHostProxy::SetDevicePairingConfirmation done fail, error: %{public}d", error);
1241 return BT_ERR_IPC_TRANS_FAILED;
1242 }
1243 return reply.ReadInt32();
1244 }
1245
SetDevicePasskey(int32_t transport,const std::string & address,int32_t passkey,bool accept)1246 bool BluetoothHostProxy::SetDevicePasskey(int32_t transport, const std::string &address, int32_t passkey, bool accept)
1247 {
1248 MessageParcel data;
1249 if (!data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor())) {
1250 HILOGE("BluetoothHostProxy::SetDevicePasskey WriteInterfaceToken error");
1251 return false;
1252 }
1253 if (!data.WriteInt32(transport)) {
1254 HILOGE("BluetoothHostProxy::SetDevicePasskey transport error");
1255 return false;
1256 }
1257 if (!data.WriteString(address)) {
1258 HILOGE("BluetoothHostProxy::SetDevicePasskey address error");
1259 return false;
1260 }
1261 if (!data.WriteInt32(passkey)) {
1262 HILOGE("BluetoothHostProxy::SetDevicePasskey passkey error");
1263 return false;
1264 }
1265 if (!data.WriteBool(accept)) {
1266 HILOGE("BluetoothHostProxy::SetDevicePasskey accept error");
1267 return false;
1268 }
1269 MessageParcel reply;
1270 MessageOption option = {MessageOption::TF_SYNC};
1271 int32_t error = InnerTransact(BluetoothHostInterfaceCode::SET_DEVICE_PASSKEY, option, data, reply);
1272 if (error != NO_ERROR) {
1273 HILOGE("BluetoothHostProxy::SetDevicePasskey done fail, error: %{public}d", error);
1274 return false;
1275 }
1276 return reply.ReadBool();
1277 }
1278
PairRequestReply(int32_t transport,const std::string & address,bool accept)1279 bool BluetoothHostProxy::PairRequestReply(int32_t transport, const std::string &address, bool accept)
1280 {
1281 MessageParcel data;
1282 if (!data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor())) {
1283 HILOGE("BluetoothHostProxy::PairRequestReply WriteInterfaceToken error");
1284 return false;
1285 }
1286 if (!data.WriteInt32(transport)) {
1287 HILOGE("BluetoothHostProxy::PairRequestReply transport error");
1288 return false;
1289 }
1290 if (!data.WriteString(address)) {
1291 HILOGE("BluetoothHostProxy::PairRequestReply address error");
1292 return false;
1293 }
1294 if (!data.WriteBool(accept)) {
1295 HILOGE("BluetoothHostProxy::PairRequestReply accept error");
1296 return false;
1297 }
1298 MessageParcel reply;
1299 MessageOption option = {MessageOption::TF_SYNC};
1300 int32_t error = InnerTransact(BluetoothHostInterfaceCode::PAIR_REQUEST_PEPLY, option, data, reply);
1301 if (error != NO_ERROR) {
1302 HILOGE("BluetoothHostProxy::PairRequestReply done fail, error: %{public}d", error);
1303 return false;
1304 }
1305 return reply.ReadBool();
1306 }
1307
ReadRemoteRssiValue(const std::string & address)1308 bool BluetoothHostProxy::ReadRemoteRssiValue(const std::string &address)
1309 {
1310 MessageParcel data;
1311 if (!data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor())) {
1312 HILOGE("BluetoothHostProxy::ReadRemoteRssiValue WriteInterfaceToken error");
1313 return false;
1314 }
1315 if (!data.WriteString(address)) {
1316 HILOGE("BluetoothHostProxy::ReadRemoteRssiValue address error");
1317 return false;
1318 }
1319 MessageParcel reply;
1320 MessageOption option = {MessageOption::TF_SYNC};
1321 int32_t error = InnerTransact(BluetoothHostInterfaceCode::READ_REMOTE_RSSI_VALUE, option, data, reply);
1322 if (error != NO_ERROR) {
1323 HILOGE("BluetoothHostProxy::ReadRemoteRssiValue done fail, error: %{public}d", error);
1324 return false;
1325 }
1326 return reply.ReadBool();
1327 }
1328
GetLocalSupportedUuids(std::vector<std::string> & uuids)1329 void BluetoothHostProxy::GetLocalSupportedUuids(std::vector<std::string> &uuids)
1330 {
1331 MessageParcel data;
1332 if (!data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor())) {
1333 HILOGE("BluetoothHostProxy::GetLocalSupportedUuids WriteInterfaceToken error");
1334 return;
1335 }
1336 MessageParcel reply;
1337 MessageOption option = {MessageOption::TF_SYNC};
1338 int32_t error = InnerTransact(BluetoothHostInterfaceCode::GET_LOCAL_SUPPORTED_UUIDS, option, data, reply);
1339 if (error != NO_ERROR) {
1340 HILOGE("BluetoothHostProxy::GetLocalSupportedUuids done fail, error: %{public}d", error);
1341 return;
1342 }
1343 int32_t size = reply.ReadInt32();
1344 const int32_t maxSize = 100;
1345 if (size > maxSize) {
1346 return;
1347 }
1348 std::string uuid;
1349 for (int32_t i = 0; i < size; i++) {
1350 uuid = reply.ReadString();
1351 uuids.push_back(uuid);
1352 }
1353 }
1354
GetDeviceUuids(const std::string & address,std::vector<std::string> & uuids)1355 int32_t BluetoothHostProxy::GetDeviceUuids(const std::string &address, std::vector<std::string> &uuids)
1356 {
1357 MessageParcel data;
1358 if (!data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor())) {
1359 HILOGE("BluetoothHostProxy::GetDeviceUuids WriteInterfaceToken error");
1360 return BT_ERR_IPC_TRANS_FAILED;
1361 }
1362 if (!data.WriteString(address)) {
1363 HILOGE("BluetoothHostProxy::GetDeviceUuids Write address error");
1364 return BT_ERR_IPC_TRANS_FAILED;
1365 }
1366 MessageParcel reply;
1367 MessageOption option = {MessageOption::TF_SYNC};
1368 int32_t error = InnerTransact(BluetoothHostInterfaceCode::GET_DEVICE_UUIDS, option, data, reply);
1369 if (error != NO_ERROR) {
1370 HILOGE("BluetoothHostProxy::GetDeviceUuids done fail, error: %{public}d", error);
1371 return BT_ERR_IPC_TRANS_FAILED;
1372 }
1373
1374 int32_t size = reply.ReadInt32();
1375 const int32_t maxSize = 100;
1376 if (size > maxSize) {
1377 return BT_ERR_INVALID_PARAM;
1378 }
1379 std::string uuid;
1380 for (int32_t i = 0; i < size; i++) {
1381 uuid = reply.ReadString();
1382 uuids.push_back(uuid);
1383 }
1384 return reply.ReadInt32();
1385 }
1386
GetLocalProfileUuids(std::vector<std::string> & uuids)1387 int32_t BluetoothHostProxy::GetLocalProfileUuids(std::vector<std::string> &uuids)
1388 {
1389 MessageParcel data;
1390 if (!data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor())) {
1391 HILOGE("BluetoothHostProxy::GetLocalProfileUuids WriteInterfaceToken error");
1392 return BT_ERR_IPC_TRANS_FAILED;
1393 }
1394 MessageParcel reply;
1395 MessageOption option = {MessageOption::TF_SYNC};
1396 int32_t error = InnerTransact(BluetoothHostInterfaceCode::GET_LOCAL_PROFILE_UUIDS, option, data, reply);
1397 if (error != NO_ERROR) {
1398 HILOGE("BluetoothHostProxy::GetLocalProfileUuids done fail, error: %{public}d", error);
1399 return BT_ERR_IPC_TRANS_FAILED;
1400 }
1401 int32_t size = reply.ReadInt32();
1402 const int32_t maxSize = 1000;
1403 if (size > maxSize) {
1404 return BT_ERR_INVALID_PARAM;
1405 }
1406 std::string uuid;
1407 for (int32_t i = 0; i < size; i++) {
1408 uuid = reply.ReadString();
1409 uuids.push_back(uuid);
1410 }
1411 return reply.ReadInt32();
1412 }
1413
RegisterBleAdapterObserver(const sptr<IBluetoothHostObserver> & observer)1414 void BluetoothHostProxy::RegisterBleAdapterObserver(const sptr<IBluetoothHostObserver> &observer)
1415 {
1416 HILOGD("BluetoothHostProxy::RegisterBleAdapterObserver start");
1417 MessageParcel data;
1418 if (!data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor())) {
1419 HILOGE("BluetoothHostProxy::RegisterBleAdapterObserver WriteInterfaceToken error");
1420 return;
1421 }
1422 if (!data.WriteRemoteObject(observer->AsObject())) {
1423 HILOGE("BluetoothHostProxy::RegisterBleAdapterObserver error");
1424 return;
1425 }
1426 MessageParcel reply;
1427 MessageOption option = {MessageOption::TF_SYNC};
1428 int32_t error = InnerTransact(BluetoothHostInterfaceCode::BT_REGISTER_BLE_ADAPTER_OBSERVER, option, data, reply);
1429 if (error != NO_ERROR) {
1430 HILOGE("BluetoothHostProxy::RegisterBleAdapterObserver done fail, error: %{public}d", error);
1431 return;
1432 }
1433 HILOGD("BluetoothHostProxy::RegisterBleAdapterObserver success");
1434 }
1435
DeregisterBleAdapterObserver(const sptr<IBluetoothHostObserver> & observer)1436 void BluetoothHostProxy::DeregisterBleAdapterObserver(const sptr<IBluetoothHostObserver> &observer)
1437 {
1438 HILOGI("BluetoothHostProxy::DeregisterBleAdapterObserver start");
1439 MessageParcel data;
1440 if (!data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor())) {
1441 HILOGE("BluetoothHostProxy::DeregisterBleAdapterObserver WriteInterfaceToken error");
1442 return;
1443 }
1444 if (!data.WriteRemoteObject(observer->AsObject())) {
1445 HILOGE("BluetoothHostProxy::DeregisterBleAdapterObserver error");
1446 return;
1447 }
1448 MessageParcel reply;
1449 MessageOption option = {MessageOption::TF_SYNC};
1450 int32_t error = InnerTransact(BluetoothHostInterfaceCode::BT_DEREGISTER_BLE_ADAPTER_OBSERVER, option, data, reply);
1451 if (error != NO_ERROR) {
1452 HILOGE("BluetoothHostProxy::DeregisterBleAdapterObserver done fail, error: %{public}d", error);
1453 return;
1454 }
1455 }
1456
RegisterBlePeripheralCallback(const sptr<IBluetoothBlePeripheralObserver> & observer)1457 void BluetoothHostProxy::RegisterBlePeripheralCallback(const sptr<IBluetoothBlePeripheralObserver> &observer)
1458 {
1459 HILOGD("BluetoothHostProxy::RegisterBlePeripheralCallback start");
1460 MessageParcel data;
1461 if (!data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor())) {
1462 HILOGE("BluetoothHostProxy::RegisterBlePeripheralCallback WriteInterfaceToken error");
1463 return;
1464 }
1465 if (!data.WriteRemoteObject(observer->AsObject())) {
1466 HILOGE("BluetoothHostProxy::RegisterBlePeripheralCallback WriteInterfaceToken error");
1467 return;
1468 }
1469 MessageParcel reply;
1470 MessageOption option = {MessageOption::TF_SYNC};
1471 int32_t error = InnerTransact(BluetoothHostInterfaceCode::BT_REGISTER_BLE_PERIPHERAL_OBSERVER, option, data, reply);
1472 if (error != NO_ERROR) {
1473 HILOGE("BluetoothHostProxy::RegisterBlePeripheralCallback done fail, error: %{public}d", error);
1474 return;
1475 }
1476 return;
1477 }
1478
DeregisterBlePeripheralCallback(const sptr<IBluetoothBlePeripheralObserver> & observer)1479 void BluetoothHostProxy::DeregisterBlePeripheralCallback(const sptr<IBluetoothBlePeripheralObserver> &observer)
1480 {
1481 HILOGI("BluetoothHostProxy::DeregisterBlePeripheralCallback start");
1482 MessageParcel data;
1483 if (!data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor())) {
1484 HILOGE("BluetoothHostProxy::DeregisterBlePeripheralCallback WriteInterfaceToken error");
1485 return;
1486 }
1487 if (!data.WriteRemoteObject(observer->AsObject())) {
1488 HILOGE("BluetoothHostProxy::DeregisterBlePeripheralCallback WriteInterfaceToken error");
1489 return;
1490 }
1491 MessageParcel reply;
1492 MessageOption option = {MessageOption::TF_SYNC};
1493 int32_t error = InnerTransact(
1494 BluetoothHostInterfaceCode::BT_DEREGISTER_BLE_PERIPHERAL_OBSERVER, option, data, reply);
1495 if (error != NO_ERROR) {
1496 HILOGE("BluetoothHostProxy::DeregisterBlePeripheralCallback done fail, error: %{public}d", error);
1497 return;
1498 }
1499 return;
1500 }
1501
InnerTransact(uint32_t code,MessageOption & flags,MessageParcel & data,MessageParcel & reply)1502 int32_t BluetoothHostProxy::InnerTransact(
1503 uint32_t code, MessageOption &flags, MessageParcel &data, MessageParcel &reply)
1504 {
1505 auto remote = Remote();
1506 if (remote == nullptr) {
1507 HILOGW("[InnerTransact] fail: get Remote fail code %{public}d", code);
1508 return OBJECT_NULL;
1509 }
1510 int32_t err = remote->SendRequest(code, data, reply, flags);
1511 if (err != NO_ERROR) {
1512 HILOGD("[InnerTransact] fail: ipcErr=%{public}d code %{public}d", err, code);
1513 }
1514 return err;
1515 }
1516
SetFastScan(bool isEnable)1517 int32_t BluetoothHostProxy::SetFastScan(bool isEnable)
1518 {
1519 MessageParcel data;
1520 if (!data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor())) {
1521 HILOGE("BluetoothHostProxy::SetBtScanMode WriteInterfaceToken error");
1522 return BT_ERR_IPC_TRANS_FAILED;
1523 }
1524 if (!data.WriteBool(isEnable)) {
1525 HILOGE("BluetoothHostProxy::SetFastScan WriteInterfaceToken error");
1526 return BT_ERR_IPC_TRANS_FAILED;
1527 }
1528 MessageParcel reply;
1529 MessageOption option = {MessageOption::TF_SYNC};
1530 int32_t error = InnerTransact(BluetoothHostInterfaceCode::BT_SET_FAST_SCAN, option, data, reply);
1531 if (error != BT_NO_ERROR) {
1532 HILOGE("BluetoothHostProxy::SetFastScan done fail, error: %{public}d", error);
1533 return BT_ERR_IPC_TRANS_FAILED;
1534 }
1535 return reply.ReadInt32();
1536 }
1537
GetRandomAddress(const std::string & realAddr,std::string & randomAddr)1538 int32_t BluetoothHostProxy::GetRandomAddress(const std::string &realAddr, std::string &randomAddr)
1539 {
1540 MessageParcel data;
1541 if (!data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor())) {
1542 HILOGE("BluetoothHostProxy::GetRandomAddress WriteInterfaceToken error");
1543 return BT_ERR_IPC_TRANS_FAILED;
1544 }
1545 if (!data.WriteString(realAddr)) {
1546 HILOGE("BluetoothHostProxy::GetRandomAddress Write realAddr error");
1547 return BT_ERR_IPC_TRANS_FAILED;
1548 }
1549 MessageParcel reply;
1550 MessageOption option = {MessageOption::TF_SYNC};
1551 int32_t error = InnerTransact(BluetoothHostInterfaceCode::GET_RANDOM_ADDRESS, option, data, reply);
1552 if (error != BT_NO_ERROR) {
1553 HILOGE("BluetoothHostProxy::GetRandomAddress fail, error: %{public}d", error);
1554 return BT_ERR_IPC_TRANS_FAILED;
1555 }
1556 int32_t exception = reply.ReadInt32();
1557 if (exception == BT_NO_ERROR) {
1558 randomAddr = reply.ReadString();
1559 }
1560 return exception;
1561 }
1562
SyncRandomAddress(const std::string & realAddr,const std::string & randomAddr)1563 int32_t BluetoothHostProxy::SyncRandomAddress(const std::string &realAddr, const std::string &randomAddr)
1564 {
1565 MessageParcel data;
1566 if (!data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor())) {
1567 HILOGE("BluetoothHostProxy::SyncRandomAddress WriteInterfaceToken error");
1568 return BT_ERR_IPC_TRANS_FAILED;
1569 }
1570 if (!data.WriteString(realAddr)) {
1571 HILOGE("BluetoothHostProxy::SyncRandomAddress Write realAddr error");
1572 return BT_ERR_IPC_TRANS_FAILED;
1573 }
1574 if (!data.WriteString(randomAddr)) {
1575 HILOGE("BluetoothHostProxy::SyncRandomAddress Write randomAddr error");
1576 return BT_ERR_IPC_TRANS_FAILED;
1577 }
1578 MessageParcel reply;
1579 MessageOption option = {MessageOption::TF_SYNC};
1580 int32_t error = InnerTransact(BluetoothHostInterfaceCode::SYNC_RANDOM_ADDRESS, option, data, reply);
1581 if (error != BT_NO_ERROR) {
1582 HILOGE("BluetoothHostProxy::SyncRandomAddress fail, error: %{public}d", error);
1583 return BT_ERR_IPC_TRANS_FAILED;
1584 }
1585 return reply.ReadInt32();
1586 }
1587
ConnectAllowedProfiles(const std::string & remoteAddr)1588 int32_t BluetoothHostProxy::ConnectAllowedProfiles(const std::string &remoteAddr)
1589 {
1590 MessageParcel data;
1591 CHECK_AND_RETURN_LOG_RET(data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor()),
1592 BT_ERR_IPC_TRANS_FAILED, "WriteInterfaceToken error");
1593 CHECK_AND_RETURN_LOG_RET(data.WriteString(remoteAddr), BT_ERR_IPC_TRANS_FAILED,
1594 "Write remoteAddr error");
1595
1596 MessageParcel reply;
1597 MessageOption option = {MessageOption::TF_SYNC};
1598 int32_t error = InnerTransact(BluetoothHostInterfaceCode::CONNECT_ALLOWED_PROFILES, option, data, reply);
1599 CHECK_AND_RETURN_LOG_RET((error == BT_NO_ERROR), BT_ERR_INTERNAL_ERROR, "error: %{public}d", error);
1600
1601 return reply.ReadInt32();
1602 }
1603
DisconnectAllowedProfiles(const std::string & remoteAddr)1604 int32_t BluetoothHostProxy::DisconnectAllowedProfiles(const std::string &remoteAddr)
1605 {
1606 MessageParcel data;
1607 CHECK_AND_RETURN_LOG_RET(data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor()),
1608 BT_ERR_IPC_TRANS_FAILED, "WriteInterfaceToken error");
1609 CHECK_AND_RETURN_LOG_RET(data.WriteString(remoteAddr), BT_ERR_IPC_TRANS_FAILED,
1610 "Write remoteAddr error");
1611
1612 MessageParcel reply;
1613 MessageOption option = {MessageOption::TF_SYNC};
1614 int32_t error = InnerTransact(BluetoothHostInterfaceCode::DISCONNECT_ALLOWED_PROFILES, option, data, reply);
1615 CHECK_AND_RETURN_LOG_RET((error == BT_NO_ERROR), BT_ERR_INTERNAL_ERROR, "error: %{public}d", error);
1616
1617 return reply.ReadInt32();
1618 }
1619
SetDeviceCustomType(const std::string & address,int32_t deviceType)1620 int32_t BluetoothHostProxy::SetDeviceCustomType(const std::string &address, int32_t deviceType)
1621 {
1622 MessageParcel data;
1623 CHECK_AND_RETURN_LOG_RET(data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor()),
1624 BT_ERR_IPC_TRANS_FAILED, "WriteInterfaceToken error");
1625 CHECK_AND_RETURN_LOG_RET(data.WriteString(address), BT_ERR_IPC_TRANS_FAILED, "Write remoteAddr error");
1626 CHECK_AND_RETURN_LOG_RET(
1627 data.WriteInt32(deviceType), BT_ERR_IPC_TRANS_FAILED, "Write deviceType error");
1628
1629 MessageParcel reply;
1630 MessageOption option = {MessageOption::TF_SYNC};
1631 int32_t error = InnerTransact(BluetoothHostInterfaceCode::SET_CUSTOM_TYPE, option, data, reply);
1632 CHECK_AND_RETURN_LOG_RET((error == BT_NO_ERROR), BT_ERR_INTERNAL_ERROR, "error: %{public}d", error);
1633
1634 return reply.ReadInt32();
1635 }
1636
GetRemoteDeviceInfo(const std::string & address,std::shared_ptr<BluetoothRemoteDeviceInfo> & deviceInfo,int type)1637 int32_t BluetoothHostProxy::GetRemoteDeviceInfo(const std::string &address,
1638 std::shared_ptr<BluetoothRemoteDeviceInfo> &deviceInfo, int type)
1639 {
1640 MessageParcel data;
1641 CHECK_AND_RETURN_LOG_RET(data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor()),
1642 BT_ERR_IPC_TRANS_FAILED, "WriteInterfaceToken error");
1643 CHECK_AND_RETURN_LOG_RET(data.WriteString(address), BT_ERR_IPC_TRANS_FAILED, "Write remoteAddr error");
1644 CHECK_AND_RETURN_LOG_RET(data.WriteInt32(type), BT_ERR_IPC_TRANS_FAILED, "Write type error");
1645 MessageParcel reply;
1646 MessageOption option = {MessageOption::TF_SYNC};
1647 int32_t error = InnerTransact(BluetoothHostInterfaceCode::GET_DEVICE_INFO_ID, option, data, reply);
1648 CHECK_AND_RETURN_LOG_RET((error == BT_NO_ERROR), BT_ERR_INTERNAL_ERROR, "error: %{public}d", error);
1649 BtErrCode exception = static_cast<BtErrCode>(reply.ReadInt32());
1650 if (exception == BT_NO_ERROR) {
1651 deviceInfo = std::shared_ptr<BluetoothRemoteDeviceInfo>(reply.ReadParcelable<BluetoothRemoteDeviceInfo>());
1652 }
1653 return exception;
1654 }
1655
RegisterBtResourceManagerObserver(const sptr<IBluetoothResourceManagerObserver> & observer)1656 void BluetoothHostProxy::RegisterBtResourceManagerObserver(const sptr<IBluetoothResourceManagerObserver> &observer)
1657 {
1658 MessageParcel data;
1659 if (!data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor())) {
1660 HILOGE("BluetoothHostProxy::RegisterBtResourceManagerObserver WriteInterfaceToken error");
1661 return;
1662 }
1663 if (!data.WriteRemoteObject(observer->AsObject())) {
1664 HILOGE("BluetoothHostProxy::RegisterBtResourceManagerObserver WriteInterfaceToken error");
1665 return;
1666 }
1667 MessageParcel reply;
1668 MessageOption option = {MessageOption::TF_SYNC};
1669 int32_t error = InnerTransact(
1670 BluetoothHostInterfaceCode::BT_REGISTER_RESOURCE_MANAGER_OBSERVER, option, data, reply);
1671 if (error != NO_ERROR) {
1672 HILOGE("BluetoothHostProxy::RegisterBtResourceManagerObserver done fail, error: %{public}d", error);
1673 return;
1674 }
1675 return;
1676 }
1677
DeregisterBtResourceManagerObserver(const sptr<IBluetoothResourceManagerObserver> & observer)1678 void BluetoothHostProxy::DeregisterBtResourceManagerObserver(const sptr<IBluetoothResourceManagerObserver> &observer)
1679 {
1680 MessageParcel data;
1681 if (!data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor())) {
1682 HILOGE("BluetoothHostProxy::DeregisterBtResourceManagerObserver WriteInterfaceToken error");
1683 return;
1684 }
1685 if (!data.WriteRemoteObject(observer->AsObject())) {
1686 HILOGE("BluetoothHostProxy::DeregisterBtResourceManagerObserver WriteInterfaceToken error");
1687 return;
1688 }
1689 MessageParcel reply;
1690 MessageOption option = {MessageOption::TF_SYNC};
1691 int32_t error = InnerTransact(
1692 BluetoothHostInterfaceCode::BT_DEREGISTER_RESOURCE_MANAGER_OBSERVER, option, data, reply);
1693 if (error != NO_ERROR) {
1694 HILOGE("BluetoothHostProxy::DeregisterBtResourceManagerObserver done fail, error: %{public}d", error);
1695 return;
1696 }
1697 return;
1698 }
1699
IsSupportVirtualAutoConnect(const std::string & address,bool & outSupport)1700 int32_t BluetoothHostProxy::IsSupportVirtualAutoConnect(const std::string &address, bool &outSupport)
1701 {
1702 MessageParcel data;
1703 CHECK_AND_RETURN_LOG_RET(data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor()), BT_ERR_IPC_TRANS_FAILED,
1704 "WriteInterfaceToken error");
1705 CHECK_AND_RETURN_LOG_RET(data.WriteString(address), BT_ERR_IPC_TRANS_FAILED, "Write remoteAddr error");
1706 MessageParcel reply;
1707 MessageOption option = {MessageOption::TF_SYNC};
1708 int32_t error = InnerTransact(BluetoothHostInterfaceCode::GET_VIRTUAL_AUTO_CONN_SWITCH, option, data, reply);
1709 CHECK_AND_RETURN_LOG_RET((error == BT_NO_ERROR), BT_ERR_INTERNAL_ERROR, "error: %{public}d", error);
1710 outSupport = reply.ReadBool();
1711 return BT_NO_ERROR;
1712 }
1713
SetVirtualAutoConnectType(const std::string & address,int connType,int businessType)1714 int32_t BluetoothHostProxy::SetVirtualAutoConnectType(const std::string &address, int connType, int businessType)
1715 {
1716 MessageParcel data;
1717 CHECK_AND_RETURN_LOG_RET(data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor()), BT_ERR_IPC_TRANS_FAILED,
1718 "WriteInterfaceToken error");
1719 CHECK_AND_RETURN_LOG_RET(data.WriteString(address), BT_ERR_IPC_TRANS_FAILED, "Write remoteAddr error");
1720 CHECK_AND_RETURN_LOG_RET(data.WriteInt32(connType), BT_ERR_IPC_TRANS_FAILED, "Write connType error");
1721 CHECK_AND_RETURN_LOG_RET(data.WriteInt32(businessType), BT_ERR_IPC_TRANS_FAILED, "Write businessType error");
1722 MessageParcel reply;
1723 MessageOption option = {MessageOption::TF_SYNC};
1724 int32_t error = InnerTransact(BluetoothHostInterfaceCode::SET_VIRTUAL_AUTO_CONN_TYPE, option, data, reply);
1725 CHECK_AND_RETURN_LOG_RET((error == BT_NO_ERROR), BT_ERR_INTERNAL_ERROR, "error: %{public}d", error);
1726 return BT_NO_ERROR;
1727 }
1728
SetFastScanLevel(int level)1729 int32_t BluetoothHostProxy::SetFastScanLevel(int level)
1730 {
1731 MessageParcel data;
1732 CHECK_AND_RETURN_LOG_RET(data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor()), BT_ERR_IPC_TRANS_FAILED,
1733 "WriteInterfaceToken error");
1734 CHECK_AND_RETURN_LOG_RET(data.WriteInt32(level), BT_ERR_IPC_TRANS_FAILED, "Write level error");
1735 MessageParcel reply;
1736 MessageOption option = {MessageOption::TF_SYNC};
1737 int32_t error = InnerTransact(BluetoothHostInterfaceCode::SET_FAST_SCAN_LEVEL, option, data, reply);
1738 CHECK_AND_RETURN_LOG_RET((error == BT_NO_ERROR), BT_ERR_INTERNAL_ERROR, "error: %{public}d", error);
1739 return reply.ReadInt32();
1740 }
1741
UpdateVirtualDevice(int32_t action,const std::string & address)1742 void BluetoothHostProxy::UpdateVirtualDevice(int32_t action, const std::string &address)
1743 {
1744 MessageParcel data;
1745 CHECK_AND_RETURN_LOG(data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor()), "WriteInterfaceToken error");
1746 CHECK_AND_RETURN_LOG(data.WriteInt32(action), "Write action error");
1747 CHECK_AND_RETURN_LOG(data.WriteString(address), "Write address error");
1748 MessageParcel reply;
1749 MessageOption option = {MessageOption::TF_SYNC};
1750 int32_t error = InnerTransact(BluetoothHostInterfaceCode::UPDATE_VIRTUAL_DEVICE, option, data, reply);
1751 CHECK_AND_RETURN_LOG((error == BT_NO_ERROR), "error: %{public}d", error);
1752 return;
1753 }
1754
EnableBluetoothToRestrictMode(void)1755 int32_t BluetoothHostProxy::EnableBluetoothToRestrictMode(void)
1756 {
1757 MessageParcel data;
1758 CHECK_AND_RETURN_LOG_RET(data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor()), BT_ERR_IPC_TRANS_FAILED,
1759 "WriteInterfaceToken error");
1760 MessageParcel reply;
1761 MessageOption option = {MessageOption::TF_SYNC};
1762 int32_t error = InnerTransact(
1763 BluetoothHostInterfaceCode::BT_ENABLE_BLUETOOTH_TO_RESTRICT_MODE, option, data, reply);
1764 CHECK_AND_RETURN_LOG_RET((error == BT_NO_ERROR), BT_ERR_INTERNAL_ERROR, "error: %{public}d", error);
1765 return reply.ReadInt32();
1766 }
1767
ControlDeviceAction(const std::string & deviceId,uint32_t controlType,uint32_t controlTypeVal,uint32_t controlObject)1768 int32_t BluetoothHostProxy::ControlDeviceAction(const std::string &deviceId, uint32_t controlType,
1769 uint32_t controlTypeVal, uint32_t controlObject)
1770 {
1771 MessageParcel data;
1772 CHECK_AND_RETURN_LOG_RET(data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor()), BT_ERR_IPC_TRANS_FAILED,
1773 "WriteInterfaceToken error");
1774 CHECK_AND_RETURN_LOG_RET(data.WriteString(deviceId), BT_ERR_IPC_TRANS_FAILED, "Write deviceId error");
1775 CHECK_AND_RETURN_LOG_RET(data.WriteUint32(controlType), BT_ERR_IPC_TRANS_FAILED, "Write controlType error");
1776 CHECK_AND_RETURN_LOG_RET(data.WriteUint32(controlTypeVal), BT_ERR_IPC_TRANS_FAILED, "Write controlTypeVal error");
1777 CHECK_AND_RETURN_LOG_RET(data.WriteUint32(controlObject), BT_ERR_IPC_TRANS_FAILED, "Write controlObject error");
1778
1779 MessageParcel reply;
1780 MessageOption option = {MessageOption::TF_SYNC};
1781 int32_t error = InnerTransact(BluetoothHostInterfaceCode::CTRL_DEVICE_ACTION, option, data, reply);
1782 CHECK_AND_RETURN_LOG_RET((error == BT_NO_ERROR), BT_ERR_INTERNAL_ERROR, "error: %{public}d", error);
1783 return reply.ReadInt32();
1784 }
1785
GetLastConnectionTime(const std::string & address,int64_t & connectionTime)1786 int32_t BluetoothHostProxy::GetLastConnectionTime(const std::string &address, int64_t &connectionTime)
1787 {
1788 MessageParcel data;
1789 if (!data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor())) {
1790 HILOGE("BluetoothHostProxy::GetLastConnectionTime WriteInterfaceToken error");
1791 return BT_ERR_IPC_TRANS_FAILED;
1792 }
1793 if (!data.WriteString(address)) {
1794 HILOGE("BluetoothHostProxy::GetLastConnectionTime WriteAddress error");
1795 return BT_ERR_IPC_TRANS_FAILED;
1796 }
1797 MessageParcel reply;
1798 MessageOption option = {MessageOption::TF_SYNC};
1799 int32_t error = InnerTransact(
1800 BluetoothHostInterfaceCode::GET_CONNECTION_TIME, option, data, reply);
1801 if (error != BT_NO_ERROR) {
1802 HILOGE("BluetoothHostProxy::GetLastConnectionTime done fail error: %{public}d", error);
1803 return BT_ERR_IPC_TRANS_FAILED;
1804 }
1805 BtErrCode exception = static_cast<BtErrCode>(reply.ReadInt32());
1806 if (exception == BT_NO_ERROR) {
1807 connectionTime = reply.ReadInt64();
1808 }
1809 return exception;
1810 }
1811
UpdateCloudBluetoothDevice(std::vector<BluetoothTrustPairDevice> & cloudDevices)1812 int32_t BluetoothHostProxy::UpdateCloudBluetoothDevice(std::vector<BluetoothTrustPairDevice> &cloudDevices)
1813 {
1814 MessageParcel data;
1815 CHECK_AND_RETURN_LOG_RET(data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor()),
1816 BT_ERR_IPC_TRANS_FAILED, "WriteInterfaceToken error");
1817 int32_t cloudDevSize = static_cast<int32_t>(cloudDevices.size());
1818 CHECK_AND_RETURN_LOG_RET(cloudDevSize < TRUST_PAIR_DEVICE_SIZE_MAX,
1819 BT_ERR_IPC_TRANS_FAILED, "error size:%{public}d", cloudDevSize);
1820 CHECK_AND_RETURN_LOG_RET(data.WriteInt32(cloudDevSize),
1821 BT_ERR_IPC_TRANS_FAILED, "Write cloudDevices size error");
1822 for (auto &dev : cloudDevices) {
1823 CHECK_AND_RETURN_LOG_RET(data.WriteParcelable(&dev),
1824 BT_ERR_IPC_TRANS_FAILED, "Write cloudDevices error");
1825 }
1826 MessageParcel reply;
1827 MessageOption option = {MessageOption::TF_SYNC};
1828 int32_t error = InnerTransact(
1829 BluetoothHostInterfaceCode::BT_UPDATE_CLOUD_DEVICE, option, data, reply);
1830 HILOGI("[CLOUD_DEV] UpdateCloudBluetoothDev %{public}d.", cloudDevSize);
1831 CHECK_AND_RETURN_LOG_RET((error == BT_NO_ERROR), BT_ERR_INTERNAL_ERROR, "error: %{public}d", error);
1832 return reply.ReadInt32();
1833 }
1834
GetCloudBondState(const std::string & address,int32_t & cloudBondState)1835 int32_t BluetoothHostProxy::GetCloudBondState(const std::string &address, int32_t &cloudBondState)
1836 {
1837 MessageParcel data;
1838 if (!data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor())) {
1839 HILOGE("BluetoothHostProxy::GetCloudBondState WriteInterfaceToken error");
1840 return BT_ERR_IPC_TRANS_FAILED;
1841 }
1842 if (!data.WriteString(address)) {
1843 HILOGE("BluetoothHostProxy::GetCloudBondState WriteAddress error");
1844 return BT_ERR_IPC_TRANS_FAILED;
1845 }
1846 MessageParcel reply;
1847 MessageOption option = {MessageOption::TF_SYNC};
1848 int32_t error = InnerTransact(
1849 BluetoothHostInterfaceCode::GET_CLOUD_BOND_STATE, option, data, reply);
1850 if (error != BT_NO_ERROR) {
1851 HILOGE("BluetoothHostProxy::GetCloudBondState done fail error: %{public}d", error);
1852 return BT_ERR_IPC_TRANS_FAILED;
1853 }
1854 BtErrCode exception = static_cast<BtErrCode>(reply.ReadInt32());
1855 if (exception == BT_NO_ERROR) {
1856 cloudBondState = reply.ReadInt32();
1857 }
1858 return exception;
1859 }
1860
UpdateRefusePolicy(const int32_t pid,const int64_t prohibitedSecondsTime)1861 int32_t BluetoothHostProxy::UpdateRefusePolicy(const int32_t pid, const int64_t prohibitedSecondsTime)
1862 {
1863 HILOGI("BluetoothHostProxy::UpdateRefusePolicy starts");
1864 MessageParcel data;
1865 if (!data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor())) {
1866 HILOGE("BluetoothHostProxy::UpdateRefusePolicy WriteInterfaceToken error");
1867 return BT_ERR_IPC_TRANS_FAILED;
1868 }
1869 CHECK_AND_RETURN_LOG_RET(data.WriteInt32(pid), BT_ERR_IPC_TRANS_FAILED,
1870 "write pid error");
1871 CHECK_AND_RETURN_LOG_RET(data.WriteInt64(prohibitedSecondsTime), BT_ERR_IPC_TRANS_FAILED,
1872 "write time error");
1873 MessageParcel reply;
1874 MessageOption option = {MessageOption::TF_SYNC};
1875 int32_t error = InnerTransact(
1876 BluetoothHostInterfaceCode::BT_UPDATE_REFUSE_POLICY, option, data, reply);
1877 if (error != BT_NO_ERROR) {
1878 HILOGE("BluetoothHostProxy::UpdateRefusePolicy done fail error: %{public}d", error);
1879 return BT_ERR_IPC_TRANS_FAILED;
1880 }
1881 return reply.ReadInt32();
1882 }
1883
ProcessRandomDeviceIdCommand(int32_t command,std::vector<std::string> & deviceIdVec,bool & isValid)1884 int32_t BluetoothHostProxy::ProcessRandomDeviceIdCommand(
1885 int32_t command, std::vector<std::string> &deviceIdVec, bool &isValid)
1886 {
1887 MessageParcel data;
1888 if (!data.WriteInterfaceToken(BluetoothHostProxy::GetDescriptor())) {
1889 return BT_ERR_IPC_TRANS_FAILED;
1890 }
1891 if (!data.WriteInt32(command)) {
1892 return BT_ERR_IPC_TRANS_FAILED;
1893 }
1894 uint32_t size = static_cast<uint32_t>(deviceIdVec.size());
1895 if (!data.WriteUint32(size)) {
1896 return BT_ERR_IPC_TRANS_FAILED;
1897 }
1898 for (uint32_t i = 0; i < size; i++) {
1899 if (!data.WriteString(deviceIdVec[i])) {
1900 return BT_ERR_IPC_TRANS_FAILED;
1901 }
1902 }
1903 MessageParcel reply;
1904 MessageOption option = {MessageOption::TF_SYNC};
1905 int32_t error = InnerTransact(
1906 BluetoothHostInterfaceCode::PROCESS_RANDOM_DEVICE_ID_COMMAND, option, data, reply);
1907 if (error != BT_NO_ERROR) {
1908 HILOGE("ipc failed, code: %{public}d", error);
1909 return BT_ERR_IPC_TRANS_FAILED;
1910 }
1911
1912 BtErrCode exception = static_cast<BtErrCode>(reply.ReadInt32());
1913 if (exception != BT_NO_ERROR) {
1914 return exception;
1915 }
1916
1917 size = reply.ReadUint32();
1918 const uint32_t maxSize = 10000;
1919 if (size > maxSize) {
1920 HILOGE("ipc transfer size reach upper limit");
1921 return BT_ERR_INTERNAL_ERROR;
1922 }
1923 deviceIdVec.clear();
1924 for (uint32_t i = 0; i < size; i++) {
1925 deviceIdVec.push_back(reply.ReadString());
1926 }
1927 isValid = reply.ReadBool();
1928 return BT_NO_ERROR;
1929 }
1930 } // namespace Bluetooth
1931 } // namespace OHOS
1932