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_gatt_client_proxy.h"
17 #include "bluetooth_errorcode.h"
18 #include "bluetooth_log.h"
19 #include "parcel_bt_uuid.h"
20
21 namespace OHOS {
22 namespace Bluetooth {
23 const int GATT_CLIENT_READ_DATA_SIZE_MAX_LEN = 0xFF;
RegisterApplication(const sptr<IBluetoothGattClientCallback> & callback,const BluetoothRawAddress & addr,int32_t transport,int & appId)24 int BluetoothGattClientProxy::RegisterApplication(
25 const sptr<IBluetoothGattClientCallback> &callback, const BluetoothRawAddress &addr, int32_t transport, int &appId)
26 {
27 HILOGI("BluetoothGattClientProxy::RegisterApplication start");
28 MessageParcel data;
29 if (!data.WriteInterfaceToken(BluetoothGattClientProxy::GetDescriptor())) {
30 HILOGE("BluetoothGattClientProxy::RegisterApplication WriteInterfaceToken error");
31 return BT_ERR_INTERNAL_ERROR;
32 }
33 if (!data.WriteRemoteObject(callback->AsObject())) {
34 HILOGE("BluetoothGattClientProxy::RegisterApplication transport error");
35 return BT_ERR_INTERNAL_ERROR;
36 }
37 if (!data.WriteParcelable(&addr)) {
38 HILOGE("BluetoothGattClientProxy::RegisterApplication transport error");
39 return BT_ERR_INTERNAL_ERROR;
40 }
41 if (!data.WriteInt32(transport)) {
42 HILOGE("BluetoothGattClientProxy::RegisterApplication transport error");
43 return BT_ERR_INTERNAL_ERROR;
44 }
45 MessageParcel reply;
46 MessageOption option {
47 MessageOption::TF_SYNC
48 };
49 int error = Remote()->SendRequest(
50 BluetoothGattClientInterfaceCode::BT_GATT_CLIENT_REGISTER_APP, data, reply, option);
51 if (error != BT_NO_ERROR) {
52 HILOGE("BluetoothGattClientProxy::RegisterApplication done fail, error: %{public}d", error);
53 return BT_ERR_INTERNAL_ERROR;
54 }
55 int32_t result = reply.ReadInt32();
56 appId = reply.ReadInt32();
57 return result;
58 }
59
RegisterApplication(const sptr<IBluetoothGattClientCallback> & callback,const BluetoothRawAddress & addr,int32_t transport)60 int BluetoothGattClientProxy::RegisterApplication(
61 const sptr<IBluetoothGattClientCallback> &callback, const BluetoothRawAddress &addr, int32_t transport)
62 {
63 HILOGI("BluetoothGattClientProxy::RegisterApplication start");
64 MessageParcel data;
65 if (!data.WriteInterfaceToken(BluetoothGattClientProxy::GetDescriptor())) {
66 HILOGE("BluetoothGattClientProxy::RegisterApplication WriteInterfaceToken error");
67 return ERROR;
68 }
69 if (!data.WriteRemoteObject(callback->AsObject())) {
70 HILOGE("BluetoothGattClientProxy::RegisterApplication transport error");
71 return ERROR;
72 }
73 if (!data.WriteParcelable(&addr)) {
74 HILOGE("BluetoothGattClientProxy::RegisterApplication transport error");
75 return ERROR;
76 }
77 if (!data.WriteInt32(transport)) {
78 HILOGE("BluetoothGattClientProxy::RegisterApplication transport error");
79 return ERROR;
80 }
81 MessageParcel reply;
82 MessageOption option {
83 MessageOption::TF_SYNC
84 };
85 int error = Remote()->SendRequest(
86 BluetoothGattClientInterfaceCode::BT_GATT_CLIENT_REGISTER_APP, data, reply, option);
87 if (error != NO_ERROR) {
88 HILOGE("BluetoothGattClientProxy::RegisterApplication done fail, error: %{public}d", error);
89 return ERROR;
90 }
91 return reply.ReadInt32();
92 }
93
DeregisterApplication(int32_t appId)94 int BluetoothGattClientProxy::DeregisterApplication(int32_t appId)
95 {
96 HILOGI("BluetoothGattClientProxy::DeregisterApplication start");
97 MessageParcel data;
98 if (!data.WriteInterfaceToken(BluetoothGattClientProxy::GetDescriptor())) {
99 HILOGE("BluetoothGattClientProxy::DeregisterApplication WriteInterfaceToken error");
100 return BT_ERR_INTERNAL_ERROR;
101 }
102 if (!data.WriteInt32(appId)) {
103 HILOGE("BluetoothGattClientProxy::DeregisterApplication transport error");
104 return BT_ERR_INTERNAL_ERROR;
105 }
106 MessageParcel reply;
107 MessageOption option {
108 MessageOption::TF_SYNC
109 };
110 HILOGE("mobaiye2 BluetoothGattClientProxy::DeregisterApplication appId : %{public}d", appId);
111 int error = Remote()->SendRequest(
112 BluetoothGattClientInterfaceCode::BT_GATT_CLIENT_DEREGISTER_APP, data, reply, option);
113 if (error != BT_NO_ERROR) {
114 HILOGE("BluetoothGattClientProxy::DeregisterApplication done fail, error: %{public}d", error);
115 return BT_ERR_INTERNAL_ERROR;
116 }
117 return reply.ReadInt32();
118 }
119
Connect(int32_t appId,bool autoConnect)120 int BluetoothGattClientProxy::Connect(int32_t appId, bool autoConnect)
121 {
122 HILOGI("BluetoothGattClientProxy::Connect start");
123 MessageParcel data;
124 if (!data.WriteInterfaceToken(BluetoothGattClientProxy::GetDescriptor())) {
125 HILOGE("BluetoothGattClientProxy::Connect WriteInterfaceToken error");
126 return BT_ERR_INTERNAL_ERROR;
127 }
128 if (!data.WriteInt32(appId)) {
129 HILOGE("BluetoothGattClientProxy::Connect transport error");
130 return BT_ERR_INTERNAL_ERROR;
131 }
132 if (!data.WriteBool(autoConnect)) {
133 HILOGE("BluetoothGattClientProxy::Connect transport error");
134 return BT_ERR_INTERNAL_ERROR;
135 }
136 MessageParcel reply;
137 MessageOption option {
138 MessageOption::TF_SYNC
139 };
140 int error = Remote()->SendRequest(BluetoothGattClientInterfaceCode::BT_GATT_CLIENT_CONNECT, data, reply, option);
141 if (error != BT_NO_ERROR) {
142 HILOGE("BluetoothGattClientProxy::Connect done fail, error: %{public}d", error);
143 return BT_ERR_INTERNAL_ERROR;
144 }
145 return reply.ReadInt32();
146 }
147
Disconnect(int32_t appId)148 int BluetoothGattClientProxy::Disconnect(int32_t appId)
149 {
150 HILOGI("BluetoothGattClientProxy::Disconnect start");
151 MessageParcel data;
152 if (!data.WriteInterfaceToken(BluetoothGattClientProxy::GetDescriptor())) {
153 HILOGE("BluetoothGattClientProxy::Disconnect WriteInterfaceToken error");
154 return BT_ERR_INTERNAL_ERROR;
155 }
156 if (!data.WriteInt32(appId)) {
157 HILOGE("BluetoothGattClientProxy::Disconnect transport error");
158 return BT_ERR_INTERNAL_ERROR;
159 }
160 MessageParcel reply;
161 MessageOption option {
162 MessageOption::TF_SYNC
163 };
164 int error = Remote()->SendRequest(
165 BluetoothGattClientInterfaceCode::BT_GATT_CLIENT_DIS_CONNECT, data, reply, option);
166 if (error != BT_NO_ERROR) {
167 HILOGE("BluetoothGattClientProxy::Disconnect done fail, error: %{public}d", error);
168 return BT_ERR_INTERNAL_ERROR;
169 }
170 return reply.ReadInt32();
171 }
172
DiscoveryServices(int32_t appId)173 int BluetoothGattClientProxy::DiscoveryServices(int32_t appId)
174 {
175 HILOGI("BluetoothGattClientProxy::DiscoveryServices start");
176 MessageParcel data;
177 if (!data.WriteInterfaceToken(BluetoothGattClientProxy::GetDescriptor())) {
178 HILOGE("BluetoothGattClientProxy::DiscoveryServices WriteInterfaceToken error");
179 return BT_ERR_INTERNAL_ERROR;
180 }
181 if (!data.WriteInt32(appId)) {
182 HILOGE("BluetoothGattClientProxy::DiscoveryServices transport error");
183 return BT_ERR_INTERNAL_ERROR;
184 }
185 MessageParcel reply;
186 MessageOption option {
187 MessageOption::TF_SYNC
188 };
189 int error =
190 Remote()->SendRequest(BluetoothGattClientInterfaceCode::BT_GATT_CLIENT_DISCOVERY_SERVICES, data, reply, option);
191 if (error != BT_NO_ERROR) {
192 HILOGE("BluetoothGattClientProxy::DiscoveryServices done fail, error: %{public}d", error);
193 return BT_ERR_INTERNAL_ERROR;
194 }
195 return reply.ReadInt32();
196 }
197
ReadCharacteristic(int32_t appId,const BluetoothGattCharacteristic & characteristic)198 int BluetoothGattClientProxy::ReadCharacteristic(int32_t appId, const BluetoothGattCharacteristic &characteristic)
199 {
200 HILOGI("BluetoothGattClientProxy::ReadCharacteristic start");
201 MessageParcel data;
202 if (!data.WriteInterfaceToken(BluetoothGattClientProxy::GetDescriptor())) {
203 HILOGE("BluetoothGattClientProxy::ReadCharacteristic WriteInterfaceToken error");
204 return BT_ERR_INTERNAL_ERROR;
205 }
206 if (!data.WriteInt32(appId)) {
207 HILOGE("BluetoothGattClientProxy::ReadCharacteristic transport error");
208 return BT_ERR_INTERNAL_ERROR;
209 }
210 if (!data.WriteParcelable(&characteristic)) {
211 HILOGE("BluetoothGattClientProxy::ReadCharacteristic transport error");
212 return BT_ERR_INTERNAL_ERROR;
213 }
214 MessageParcel reply;
215 MessageOption option {
216 MessageOption::TF_SYNC
217 };
218 int error =
219 Remote()->SendRequest(
220 BluetoothGattClientInterfaceCode::BT_GATT_CLIENT_READ_CHARACTERISTIC, data, reply, option);
221 if (error != BT_NO_ERROR) {
222 HILOGE("BluetoothGattClientProxy::ReadCharacteristic done fail, error: %{public}d", error);
223 return BT_ERR_INTERNAL_ERROR;
224 }
225 return reply.ReadInt32();
226 }
227
WriteCharacteristic(int32_t appId,BluetoothGattCharacteristic * characteristic,bool withoutRespond)228 int BluetoothGattClientProxy::WriteCharacteristic(
229 int32_t appId, BluetoothGattCharacteristic *characteristic, bool withoutRespond)
230 {
231 HILOGI("BluetoothGattClientProxy::WriteCharacteristic start");
232 MessageParcel data;
233 if (!data.WriteInterfaceToken(BluetoothGattClientProxy::GetDescriptor())) {
234 HILOGE("BluetoothGattClientProxy::WriteCharacteristic WriteInterfaceToken error");
235 return BT_ERR_INTERNAL_ERROR;
236 }
237 if (!data.WriteInt32(appId)) {
238 HILOGE("BluetoothGattClientProxy::WriteCharacteristic transport error");
239 return BT_ERR_INTERNAL_ERROR;
240 }
241 if (!data.WriteParcelable(characteristic)) {
242 HILOGE("BluetoothGattClientProxy::WriteCharacteristic transport error");
243 return BT_ERR_INTERNAL_ERROR;
244 }
245 if (!data.WriteBool(withoutRespond)) {
246 HILOGE("BluetoothGattClientProxy::WriteCharacteristic transport error");
247 return BT_ERR_INTERNAL_ERROR;
248 }
249 MessageParcel reply;
250 MessageOption option {
251 MessageOption::TF_SYNC
252 };
253 int error =
254 Remote()->SendRequest(
255 BluetoothGattClientInterfaceCode::BT_GATT_CLIENT_WRITE_CHARACTERISTIC, data, reply, option);
256 if (error != BT_NO_ERROR) {
257 HILOGE("BluetoothGattClientProxy::WriteCharacteristic done fail, error: %{public}d", error);
258 return BT_ERR_INTERNAL_ERROR;
259 }
260 return reply.ReadInt32();
261 }
262
SignedWriteCharacteristic(int32_t appId,BluetoothGattCharacteristic * characteristic)263 int BluetoothGattClientProxy::SignedWriteCharacteristic(int32_t appId, BluetoothGattCharacteristic *characteristic)
264 {
265 HILOGI("BluetoothGattClientProxy::SignedWriteCharacteristic start");
266 MessageParcel data;
267 if (!data.WriteInterfaceToken(BluetoothGattClientProxy::GetDescriptor())) {
268 HILOGE("BluetoothGattClientProxy::SignedWriteCharacteristic WriteInterfaceToken error");
269 return ERROR;
270 }
271 if (!data.WriteInt32(appId)) {
272 HILOGE("BluetoothGattClientProxy::SignedWriteCharacteristic transport error");
273 return ERROR;
274 }
275 if (!data.WriteParcelable(characteristic)) {
276 HILOGE("BluetoothGattClientProxy::SignedWriteCharacteristic transport error");
277 return ERROR;
278 }
279 MessageParcel reply;
280 MessageOption option {
281 MessageOption::TF_SYNC
282 };
283 int error = Remote()->SendRequest(
284 BluetoothGattClientInterfaceCode::BT_GATT_CLIENT_SIGNED_WRITE_CHARACTERISTIC, data, reply, option);
285 if (error != NO_ERROR) {
286 HILOGE("BluetoothGattClientProxy::SignedWriteCharacteristic done fail, error: %{public}d", error);
287 return ERROR;
288 }
289 return reply.ReadInt32();
290 }
291
ReadDescriptor(int32_t appId,const BluetoothGattDescriptor & descriptor)292 int BluetoothGattClientProxy::ReadDescriptor(int32_t appId, const BluetoothGattDescriptor &descriptor)
293 {
294 HILOGI("BluetoothGattClientProxy::ReadDescriptor start");
295 MessageParcel data;
296 if (!data.WriteInterfaceToken(BluetoothGattClientProxy::GetDescriptor())) {
297 HILOGE("BluetoothGattClientProxy::ReadDescriptor WriteInterfaceToken error");
298 return BT_ERR_INTERNAL_ERROR;
299 }
300 if (!data.WriteInt32(appId)) {
301 HILOGE("BluetoothGattClientProxy::ReadDescriptor transport error");
302 return BT_ERR_INTERNAL_ERROR;
303 }
304 if (!data.WriteParcelable(&descriptor)) {
305 HILOGE("BluetoothGattClientProxy::ReadDescriptor transport error");
306 return BT_ERR_INTERNAL_ERROR;
307 }
308 MessageParcel reply;
309 MessageOption option {
310 MessageOption::TF_SYNC
311 };
312 int error = Remote()->SendRequest(
313 BluetoothGattClientInterfaceCode::BT_GATT_CLIENT_READ_DESCRIPTOR, data, reply, option);
314 if (error != BT_NO_ERROR) {
315 HILOGE("BluetoothGattClientProxy::ReadDescriptor done fail, error: %{public}d", error);
316 return BT_ERR_INTERNAL_ERROR;
317 }
318 return reply.ReadInt32();
319 }
320
WriteDescriptor(int32_t appId,BluetoothGattDescriptor * descriptor)321 int BluetoothGattClientProxy::WriteDescriptor(int32_t appId, BluetoothGattDescriptor *descriptor)
322 {
323 HILOGI("BluetoothGattClientProxy::WriteDescriptor start");
324 MessageParcel data;
325 if (!data.WriteInterfaceToken(BluetoothGattClientProxy::GetDescriptor())) {
326 HILOGE("BluetoothGattClientProxy::WriteDescriptor WriteInterfaceToken error");
327 return BT_ERR_INTERNAL_ERROR;
328 }
329 if (!data.WriteInt32(appId)) {
330 HILOGE("BluetoothGattClientProxy::WriteDescriptor transport error");
331 return BT_ERR_INTERNAL_ERROR;
332 }
333 if (!data.WriteParcelable(descriptor)) {
334 HILOGE("BluetoothGattClientProxy::WriteDescriptor transport error");
335 return BT_ERR_INTERNAL_ERROR;
336 }
337 MessageParcel reply;
338 MessageOption option {
339 MessageOption::TF_SYNC
340 };
341 int error = Remote()->SendRequest(
342 BluetoothGattClientInterfaceCode::BT_GATT_CLIENT_WRITE_DESCRIPTOR, data, reply, option);
343 if (error != BT_NO_ERROR) {
344 HILOGE("BluetoothGattClientProxy::WriteDescriptor done fail, error: %{public}d", error);
345 return BT_ERR_INTERNAL_ERROR;
346 }
347 return reply.ReadInt32();
348 }
349
RequestExchangeMtu(int32_t appId,int32_t mtu)350 int BluetoothGattClientProxy::RequestExchangeMtu(int32_t appId, int32_t mtu)
351 {
352 HILOGI("BluetoothGattClientProxy::RequestExchangeMtu start");
353 MessageParcel data;
354 if (!data.WriteInterfaceToken(BluetoothGattClientProxy::GetDescriptor())) {
355 HILOGE("BluetoothGattClientProxy::RequestExchangeMtu WriteInterfaceToken error");
356 return BT_ERR_INTERNAL_ERROR;
357 }
358 if (!data.WriteInt32(appId)) {
359 HILOGE("BluetoothGattClientProxy::RequestExchangeMtu transport error");
360 return BT_ERR_INTERNAL_ERROR;
361 }
362 if (!data.WriteInt32(mtu)) {
363 HILOGE("BluetoothGattClientProxy::RequestExchangeMtu transport error");
364 return BT_ERR_INTERNAL_ERROR;
365 }
366 MessageParcel reply;
367 MessageOption option {
368 MessageOption::TF_SYNC
369 };
370 int error =
371 Remote()->SendRequest(
372 BluetoothGattClientInterfaceCode::BT_GATT_CLIENT_REQUEST_EXCHANGE_MTU, data, reply, option);
373 if (error != BT_NO_ERROR) {
374 HILOGE("BluetoothGattClientProxy::RequestExchangeMtu done fail, error: %{public}d", error);
375 return BT_ERR_INTERNAL_ERROR;
376 }
377 return reply.ReadInt32();
378 }
379
GetAllDevice(std::vector<BluetoothGattDevice> & device)380 void BluetoothGattClientProxy::GetAllDevice(std::vector<BluetoothGattDevice> &device)
381 {
382 HILOGI("BluetoothGattClientProxy::GetAllDevice start");
383 MessageParcel data;
384 if (!data.WriteInterfaceToken(BluetoothGattClientProxy::GetDescriptor())) {
385 HILOGE("BluetoothGattClientProxy::GetAllDevice WriteInterfaceToken error");
386 return;
387 }
388 MessageParcel reply;
389 MessageOption option {
390 MessageOption::TF_SYNC
391 };
392 int error = Remote()->SendRequest(
393 BluetoothGattClientInterfaceCode::BT_GATT_CLIENT_GET_ALL_DEVICE, data, reply, option);
394 if (error != NO_ERROR) {
395 HILOGE("BluetoothGattClientProxy::GetAllDevice done fail, error: %{public}d", error);
396 }
397 int DevNum = 0;
398 if (!reply.ReadInt32(DevNum) || DevNum > GATT_CLIENT_READ_DATA_SIZE_MAX_LEN) {
399 HILOGE("read Parcelable size failed.");
400 return;
401 }
402 for (int i = DevNum; i > 0; i--) {
403 std::shared_ptr<BluetoothGattDevice> dev(reply.ReadParcelable<BluetoothGattDevice>());
404 if (!dev) {
405 return;
406 }
407 device.push_back(*dev);
408 }
409 }
410
RequestConnectionPriority(int32_t appId,int32_t connPriority)411 int BluetoothGattClientProxy::RequestConnectionPriority(int32_t appId, int32_t connPriority)
412 {
413 HILOGI("BluetoothGattClientProxy::RequestConnectionPriority start");
414 MessageParcel data;
415 if (!data.WriteInterfaceToken(BluetoothGattClientProxy::GetDescriptor())) {
416 HILOGE("BluetoothGattClientProxy::RequestConnectionPriority WriteInterfaceToken error");
417 return ERROR;
418 }
419 if (!data.WriteInt32(appId)) {
420 HILOGE("BluetoothGattClientProxy::RequestConnectionPriority transport error");
421 return ERROR;
422 }
423 if (!data.WriteInt32(connPriority)) {
424 HILOGE("BluetoothGattClientProxy::RequestConnectionPriority transport error");
425 return ERROR;
426 }
427 MessageParcel reply;
428 MessageOption option {
429 MessageOption::TF_SYNC
430 };
431 int error = Remote()->SendRequest(
432 BluetoothGattClientInterfaceCode::BT_GATT_CLIENT_REQUEST_CONNECTION_PRIORITY, data, reply, option);
433 if (error != NO_ERROR) {
434 HILOGE("BluetoothGattClientProxy::RequestConnectionPriority done fail, error: %{public}d", error);
435 return ERROR;
436 }
437 return reply.ReadInt32();
438 }
439
GetServices(int32_t appId,std::vector<BluetoothGattService> & service)440 int BluetoothGattClientProxy::GetServices(int32_t appId, std::vector<BluetoothGattService> &service)
441 {
442 HILOGI("BluetoothGattClientProxy::GetServices start");
443 MessageParcel data;
444 if (!data.WriteInterfaceToken(BluetoothGattClientProxy::GetDescriptor())) {
445 HILOGE("BluetoothGattClientProxy::GetServices WriteInterfaceToken error");
446 return BT_ERR_INTERNAL_ERROR;
447 }
448 if (!data.WriteInt32(appId)) {
449 HILOGE("BluetoothGattClientProxy::GetServices transport error");
450 return BT_ERR_INTERNAL_ERROR;
451 }
452 MessageParcel reply;
453 MessageOption option {
454 MessageOption::TF_SYNC
455 };
456 int error = Remote()->SendRequest(
457 BluetoothGattClientInterfaceCode::BT_GATT_CLIENT_GET_SERVICES, data, reply, option);
458 if (error != NO_ERROR) {
459 HILOGE("BluetoothGattClientProxy::GetServices done fail, error: %{public}d", error);
460 }
461 int ret = reply.ReadInt32();
462 int DevNum = 0;
463 if (!reply.ReadInt32(DevNum) || DevNum > GATT_CLIENT_READ_DATA_SIZE_MAX_LEN) {
464 HILOGE("read Parcelable size failed.");
465 return BT_ERR_INTERNAL_ERROR;
466 }
467 for (int i = DevNum; i > 0; i--) {
468 std::shared_ptr<BluetoothGattService> dev(reply.ReadParcelable<BluetoothGattService>());
469 if (!dev) {
470 return BT_ERR_INTERNAL_ERROR;
471 }
472 service.push_back(*dev);
473 }
474 return ret;
475 }
476
RequestFastestConn(const BluetoothRawAddress & addr)477 int BluetoothGattClientProxy::RequestFastestConn(const BluetoothRawAddress &addr)
478 {
479 HILOGI("BluetoothGattClientProxy::RequestFastestConn start");
480 MessageParcel data;
481 if (!data.WriteInterfaceToken(BluetoothGattClientProxy::GetDescriptor())) {
482 HILOGE("BluetoothGattClientProxy::RequestFastestConn WriteInterfaceToken error");
483 return ERROR;
484 }
485 if (!data.WriteParcelable(&addr)) {
486 HILOGE("BluetoothGattClientProxy::RequestFastestConn transport error");
487 return ERROR;
488 }
489 MessageParcel reply;
490 MessageOption option {
491 MessageOption::TF_SYNC
492 };
493 int error = Remote()->SendRequest(
494 BluetoothGattClientInterfaceCode::BT_GATT_CLIENT_REQUEST_FASTEST_CONNECTION, data, reply, option);
495 if (error != NO_ERROR) {
496 HILOGE("BluetoothGattClientProxy::RequestFastestConn done fail, error: %{public}d", error);
497 return ERROR;
498 }
499 return reply.ReadInt32();
500 }
501
ReadRemoteRssiValue(int32_t appId)502 int BluetoothGattClientProxy::ReadRemoteRssiValue(int32_t appId)
503 {
504 HILOGI("BluetoothGattClientProxy::ReadRemoteRssiValue start");
505 MessageParcel data;
506 if (!data.WriteInterfaceToken(BluetoothGattClientProxy::GetDescriptor())) {
507 HILOGE("BluetoothGattClientProxy::ReadRemoteRssiValue WriteInterfaceToken error");
508 return ERROR;
509 }
510 if (!data.WriteInt32(appId)) {
511 HILOGE("BluetoothGattClientProxy::ReadRemoteRssiValue transport error");
512 return ERROR;
513 }
514 MessageParcel reply;
515 MessageOption option {
516 MessageOption::TF_SYNC
517 };
518 int error = Remote()->SendRequest(
519 BluetoothGattClientInterfaceCode::BT_GATT_CLIENT_READ_REMOTE_RSSI_VALUE, data, reply, option);
520 if (error != NO_ERROR) {
521 HILOGE("BluetoothGattClientProxy::ReadRemoteRssiValue done fail, error: %{public}d", error);
522 return ERROR;
523 }
524 return reply.ReadInt32();
525 }
526
RequestNotification(int32_t appId,uint16_t characterHandle,bool enable)527 int BluetoothGattClientProxy::RequestNotification(int32_t appId, uint16_t characterHandle, bool enable)
528 {
529 HILOGI("BluetoothGattClientProxy::RequestNotification start");
530 MessageParcel data;
531 if (!data.WriteInterfaceToken(BluetoothGattClientProxy::GetDescriptor())) {
532 HILOGE("BluetoothGattClientProxy::RequestNotification WriteInterfaceToken error");
533 return BT_ERR_INTERNAL_ERROR;
534 }
535 if (!data.WriteInt32(appId)) {
536 HILOGE("BluetoothGattClientProxy::RequestNotification transport error");
537 return BT_ERR_INTERNAL_ERROR;
538 }
539 if (!data.WriteUint16(characterHandle)) {
540 HILOGE("BluetoothGattClientProxy::RequestNotification transport error");
541 return BT_ERR_INTERNAL_ERROR;
542 }
543 if (!data.WriteBool(enable)) {
544 HILOGE("BluetoothGattClientProxy::RequestNotification transport error");
545 return BT_ERR_INTERNAL_ERROR;
546 }
547 MessageParcel reply;
548 MessageOption option {
549 MessageOption::TF_SYNC
550 };
551 int error = Remote()->SendRequest(
552 BluetoothGattClientInterfaceCode::BT_GATT_CLIENT_REQUEST_NOTIFICATION, data, reply, option);
553 if (error != BT_NO_ERROR) {
554 HILOGE("BluetoothGattClientProxy::ReadRemoteRssiValue done fail, error: %{public}d", error);
555 return ERROR;
556 }
557 return reply.ReadInt32();
558 }
559
560 } // namespace Bluetooth
561 } // namespace OHOS
562