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 <list>
17 #include <mutex>
18 #include <thread>
19
20 #include "bluetooth_gatt_client_server.h"
21 #include "bluetooth_hitrace.h"
22 #include "bluetooth_errorcode.h"
23 #include "bluetooth_log.h"
24 #include "hisysevent.h"
25 #include "interface_adapter_ble.h"
26 #include "interface_adapter_classic.h"
27 #include "interface_adapter_manager.h"
28 #include "interface_profile_gatt_client.h"
29 #include "interface_profile_manager.h"
30 #include "bluetooth_utils_server.h"
31 #include "string_ex.h"
32 #include "system_ability_definition.h"
33 #include "ipc_skeleton.h"
34 #include "permission_utils.h"
35
36 using namespace OHOS::bluetooth;
37 namespace OHOS {
38 namespace Bluetooth {
39
40 constexpr int32_t CONN_UNKNOWN = 4;
41 struct BluetoothGattClientServer::impl {
42 class GattClientCallbackImpl;
43 class SystemStateObserver;
44
45 IProfileGattClient *clientService_;
46 std::unique_ptr<SystemStateObserver> systemStateObserver_;
47 std::list<std::unique_ptr<GattClientCallbackImpl>> callbacks_;
48 std::mutex registerMutex_;
49
50 impl();
51 ~impl();
52
GetServicePtrOHOS::Bluetooth::BluetoothGattClientServer::impl53 IProfileGattClient *GetServicePtr()
54 {
55 if (IProfileManager::GetInstance() == nullptr) {
56 return nullptr;
57 }
58 return static_cast<IProfileGattClient *>(
59 IProfileManager::GetInstance()->GetProfileService(PROFILE_NAME_GATT_CLIENT));
60 }
61 };
62
63 class BluetoothGattClientServer::impl::SystemStateObserver : public ISystemStateObserver {
64 public:
SystemStateObserver(BluetoothGattClientServer::impl * impl)65 SystemStateObserver(BluetoothGattClientServer::impl *impl) : impl_(impl){};
66 ~SystemStateObserver() override = default;
67
OnSystemStateChange(const BTSystemState state)68 void OnSystemStateChange(const BTSystemState state) override
69 {
70 std::lock_guard<std::mutex> lck(impl_->registerMutex_);
71 switch (state) {
72 case BTSystemState::ON:
73 impl_->clientService_ = impl_->GetServicePtr();
74 break;
75 case BTSystemState::OFF:
76 impl_->clientService_ = nullptr;
77 break;
78 default:
79 break;
80 }
81 }
82
83 private:
84 BluetoothGattClientServer::impl *impl_;
85 };
86
87 class BluetoothGattClientServer::impl::GattClientCallbackImpl : public IGattClientCallback {
88 public:
OnConnectionStateChanged(int state,int newState)89 void OnConnectionStateChanged(int state, int newState) override
90 {
91 HILOGI("curState(%{public}d) -> newState(%{public}d)", state, newState);
92 if (PermissionUtils::VerifyUseBluetoothPermission(tokenId_) == PERMISSION_DENIED) {
93 HILOGE("check permission failed, tokenId: %{public}u", tokenId_);
94 return;
95 }
96 int32_t pid = IPCSkeleton::GetCallingPid();
97 int32_t uid = IPCSkeleton::GetCallingUid();
98 if (state == static_cast<int>(BTConnectState::CONNECTED) ||
99 state == static_cast<int>(BTConnectState::DISCONNECTED)) {
100 HiSysEventWrite(OHOS::HiviewDFX::HiSysEvent::Domain::BT_SERVICE, "GATT_CLIENT_CONN_STATE",
101 OHOS::HiviewDFX::HiSysEvent::EventType::STATISTIC, "PID", pid, "UID", uid, "STATE", state);
102 }
103 callback_->OnConnectionStateChanged(state, newState, CONN_UNKNOWN);
104 }
105
OnCharacteristicChanged(const Characteristic & characteristic)106 void OnCharacteristicChanged(const Characteristic &characteristic) override
107 {
108 HILOGI("enter");
109 if (PermissionUtils::VerifyUseBluetoothPermission(tokenId_) == PERMISSION_DENIED) {
110 HILOGE("check permission failed, tokenId: %{public}u", tokenId_);
111 return;
112 }
113 callback_->OnCharacteristicChanged((BluetoothGattCharacteristic)characteristic);
114 }
115
OnCharacteristicRead(int ret,const Characteristic & characteristic)116 void OnCharacteristicRead(int ret, const Characteristic &characteristic) override
117 {
118 HILOGI("ret: %{public}d", ret);
119 callback_->OnCharacteristicRead(ret, (BluetoothGattCharacteristic)characteristic);
120 }
121
OnCharacteristicWrite(int ret,const Characteristic & characteristic)122 void OnCharacteristicWrite(int ret, const Characteristic &characteristic) override
123 {
124 HILOGI("ret: %{public}d", ret);
125 callback_->OnCharacteristicWrite(ret, (BluetoothGattCharacteristic)characteristic);
126 }
127
OnDescriptorRead(int ret,const Descriptor & descriptor)128 void OnDescriptorRead(int ret, const Descriptor &descriptor) override
129 {
130 HILOGI("ret: %{public}d", ret);
131 callback_->OnDescriptorRead(ret, (BluetoothGattDescriptor)descriptor);
132 }
133
OnDescriptorWrite(int ret,const Descriptor & descriptor)134 void OnDescriptorWrite(int ret, const Descriptor &descriptor) override
135 {
136 HILOGI("ret: %{public}d", ret);
137 callback_->OnDescriptorWrite(ret, (BluetoothGattDescriptor)descriptor);
138 }
139
OnMtuChanged(int state,int mtu)140 void OnMtuChanged(int state, int mtu) override
141 {
142 HILOGI("state: %{public}d, mtu: %{public}d", state, mtu);
143 callback_->OnMtuChanged(state, mtu);
144 }
145
OnReadRemoteRssiValue(const RawAddress & addr,int rssi,int status)146 void OnReadRemoteRssiValue(const RawAddress &addr, int rssi, int status) override
147 {
148 return;
149 }
150
OnServicesDiscovered(int status)151 void OnServicesDiscovered(int status) override
152 {
153 HILOGI("status: %{public}d", status);
154 callback_->OnServicesDiscovered(status);
155 }
156
OnConnectionParameterChanged(int interval,int latency,int timeout,int status)157 void OnConnectionParameterChanged(int interval, int latency, int timeout, int status) override
158 {
159 HILOGI("interval: %{public}d, latency: %{public}d, timeout: %{public}d, status: %{public}d",
160 interval, latency, timeout, status);
161 callback_->OnConnectionParameterChanged(interval, latency, timeout, status);
162 }
163
OnServicesChanged(const std::vector<Service> & services)164 void OnServicesChanged(const std::vector<Service> &services) override
165 {
166 HILOGI("enter");
167 std::vector<BluetoothGattService> result;
168 int num = services.size();
169 for (int i = 0; i < num; i++) {
170 result.push_back((BluetoothGattService)services[i]);
171 }
172 callback_->OnServicesChanged(result);
173 }
174
GetCallback()175 sptr<IBluetoothGattClientCallback> GetCallback()
176 {
177 return callback_;
178 }
179
SetAppId(int appId)180 void SetAppId(int appId)
181 {
182 applicationId_ = appId;
183 }
184
GetAppId()185 int GetAppId()
186 {
187 return applicationId_;
188 }
189
190 GattClientCallbackImpl(const sptr<IBluetoothGattClientCallback> &callback, BluetoothGattClientServer &owner);
~GattClientCallbackImpl()191 ~GattClientCallbackImpl()
192 {
193 if (!callback_->AsObject()->RemoveDeathRecipient(deathRecipient_)) {
194 HILOGE("Failed to unlink death recipient to callback");
195 }
196 callback_ = nullptr;
197 deathRecipient_ = nullptr;
198 };
199
200 private:
201 class CallbackDeathRecipient : public IRemoteObject::DeathRecipient {
202 public:
203 CallbackDeathRecipient(const sptr<IBluetoothGattClientCallback> &callback, BluetoothGattClientServer &owner);
204
GetCallback() const205 sptr<IBluetoothGattClientCallback> GetCallback() const
206 {
207 return callback_;
208 };
209
210 void OnRemoteDied(const wptr<IRemoteObject> &remote) override;
211
212 private:
213 sptr<IBluetoothGattClientCallback> callback_;
214 BluetoothGattClientServer &owner_;
215 };
216
217 sptr<IBluetoothGattClientCallback> callback_;
218 sptr<CallbackDeathRecipient> deathRecipient_;
219 int applicationId_;
220 uint32_t tokenId_;
221 };
222
GattClientCallbackImpl(const sptr<IBluetoothGattClientCallback> & callback,BluetoothGattClientServer & owner)223 BluetoothGattClientServer::impl::GattClientCallbackImpl::GattClientCallbackImpl(
224 const sptr<IBluetoothGattClientCallback> &callback, BluetoothGattClientServer &owner)
225 : callback_(callback), deathRecipient_(new CallbackDeathRecipient(callback, owner))
226 {
227 if (!callback_->AsObject()->AddDeathRecipient(deathRecipient_)) {
228 HILOGE("Failed to link death recipient to callback");
229 }
230 tokenId_ = IPCSkeleton::GetCallingTokenID();
231 }
232
CallbackDeathRecipient(const sptr<IBluetoothGattClientCallback> & callback,BluetoothGattClientServer & owner)233 BluetoothGattClientServer::impl::GattClientCallbackImpl::CallbackDeathRecipient::CallbackDeathRecipient(
234 const sptr<IBluetoothGattClientCallback> &callback, BluetoothGattClientServer &owner)
235 : callback_(callback), owner_(owner)
236 {}
237
OnRemoteDied(const wptr<IRemoteObject> & remote)238 void BluetoothGattClientServer::impl::GattClientCallbackImpl::CallbackDeathRecipient::OnRemoteDied(
239 const wptr<IRemoteObject> &remote)
240 {
241 HILOGI("enter");
242 if (owner_.pimpl == nullptr || owner_.pimpl->clientService_ == nullptr) {
243 HILOGE("gattClientServerImpl clientService_ is not support.");
244 return;
245 }
246 std::lock_guard<std::mutex> lck(owner_.pimpl->registerMutex_);
247 for (auto it = owner_.pimpl->callbacks_.begin(); it != owner_.pimpl->callbacks_.end(); ++it) {
248 if ((*it)->GetCallback()->AsObject() == remote) {
249 HILOGI("callback is found from callbacks");
250 sptr<CallbackDeathRecipient> dr = (*it)->deathRecipient_;
251 if (!dr->GetCallback()->AsObject()->RemoveDeathRecipient(dr)) {
252 HILOGE("Failed to unlink death recipient from callback");
253 }
254 HILOGI("App id is %{public}d", (*it)->GetAppId());
255 owner_.pimpl->clientService_->Disconnect((*it)->GetAppId());
256 owner_.pimpl->clientService_->DeregisterApplication((*it)->GetAppId());
257 owner_.pimpl->callbacks_.erase(it);
258 return;
259 }
260 }
261 HILOGE("No callback erased from callbacks");
262 }
263
impl()264 BluetoothGattClientServer::impl::impl() : clientService_(nullptr), systemStateObserver_(new SystemStateObserver(this))
265 {
266 IAdapterManager::GetInstance()->RegisterSystemStateObserver(*systemStateObserver_);
267 }
268
~impl()269 BluetoothGattClientServer::impl::~impl()
270 {
271 IAdapterManager::GetInstance()->DeregisterSystemStateObserver(*systemStateObserver_);
272 }
273
BluetoothGattClientServer()274 BluetoothGattClientServer::BluetoothGattClientServer() : pimpl(new impl())
275 {
276 HILOGI("enter");
277 }
278
~BluetoothGattClientServer()279 BluetoothGattClientServer::~BluetoothGattClientServer()
280 {}
281
RegisterApplication(const sptr<IBluetoothGattClientCallback> & callback,const BluetoothRawAddress & addr,int32_t transport)282 int BluetoothGattClientServer::RegisterApplication(
283 const sptr<IBluetoothGattClientCallback> &callback, const BluetoothRawAddress &addr, int32_t transport)
284 {
285 int appId = 0;
286 int ret = RegisterApplication(callback, addr, transport, appId);
287 return (ret == NO_ERROR) ? appId : ret;
288 }
289
RegisterApplication(const sptr<IBluetoothGattClientCallback> & callback,const BluetoothRawAddress & addr,int32_t transport,int & appId)290 int BluetoothGattClientServer::RegisterApplication(
291 const sptr<IBluetoothGattClientCallback> &callback, const BluetoothRawAddress &addr, int32_t transport, int &appId)
292 {
293 HILOGI("address: %{public}s, transport: %{public}d", GetEncryptAddr(addr.GetAddress()).c_str(), transport);
294 std::lock_guard<std::mutex> lck(pimpl->registerMutex_);
295 pimpl->clientService_ = pimpl->GetServicePtr();
296 if (pimpl->clientService_ == nullptr) {
297 HILOGE("request not support.");
298 return BT_ERR_INTERNAL_ERROR;
299 }
300 auto it = pimpl->callbacks_.emplace(
301 pimpl->callbacks_.begin(), std::make_unique<impl::GattClientCallbackImpl>(callback, *this));
302 appId = pimpl->clientService_->RegisterSharedApplication(*it->get(), (RawAddress)addr, transport);
303 if (appId >= 0) {
304 HILOGI("appId: %{public}d", appId);
305 (*it)->SetAppId(appId);
306 HiSysEventWrite(OHOS::HiviewDFX::HiSysEvent::Domain::BT_SERVICE, "GATT_APP_REGISTER",
307 OHOS::HiviewDFX::HiSysEvent::EventType::STATISTIC, "ACTION", "register",
308 "SIDE", "client", "ADDRESS", GetEncryptAddr(addr.GetAddress()), "PID", OHOS::IPCSkeleton::GetCallingPid(),
309 "UID", OHOS::IPCSkeleton::GetCallingUid(), "APPID", appId);
310 } else {
311 HILOGE("RegisterSharedApplication failed, appId: %{public}d", appId);
312 pimpl->callbacks_.erase(it);
313 }
314 return NO_ERROR;
315 }
316
DeregisterApplication(int32_t appId)317 int BluetoothGattClientServer::DeregisterApplication(int32_t appId)
318 {
319 HILOGI("appId: %{public}d", appId);
320 if (PermissionUtils::VerifyUseBluetoothPermission() == PERMISSION_DENIED) {
321 HILOGE("check permission failed");
322 return REQUEST_NOT_SUPPORT;
323 }
324 std::lock_guard<std::mutex> lck(pimpl->registerMutex_);
325 if (pimpl->clientService_ == nullptr) {
326 HILOGE("request not support.");
327 return bluetooth::GattStatus::REQUEST_NOT_SUPPORT;
328 }
329 HiSysEventWrite(OHOS::HiviewDFX::HiSysEvent::Domain::BT_SERVICE, "GATT_APP_REGISTER",
330 OHOS::HiviewDFX::HiSysEvent::EventType::STATISTIC, "ACTION", "deregister",
331 "SIDE", "client", "ADDRESS", "empty", "PID", OHOS::IPCSkeleton::GetCallingPid(),
332 "UID", OHOS::IPCSkeleton::GetCallingUid(), "APPID", appId);
333
334 auto it = std::find_if(pimpl->callbacks_.begin(), pimpl->callbacks_.end(),
335 [appId](const std::unique_ptr<impl::GattClientCallbackImpl> &p) { return p->GetAppId() == appId; });
336 if (it == pimpl->callbacks_.end()) {
337 HILOGE("Unknown appId: %{public}d", appId);
338 return INVALID_PARAMETER;
339 }
340
341 int ret = pimpl->clientService_->DeregisterApplication(appId);
342 pimpl->callbacks_.erase(it);
343 return ret;
344 }
345
Connect(int32_t appId,bool autoConnect)346 int BluetoothGattClientServer::Connect(int32_t appId, bool autoConnect)
347 {
348 HILOGI("appId: %{public}d, autoConnect: %{public}d", appId, autoConnect);
349 if (PermissionUtils::VerifyUseBluetoothPermission() == PERMISSION_DENIED) {
350 HILOGE("check permission failed");
351 return BT_ERR_PERMISSION_FAILED;
352 }
353 std::lock_guard<std::mutex> lck(pimpl->registerMutex_);
354 if (pimpl->clientService_ == nullptr) {
355 HILOGE("request not support.");
356 return BT_ERR_INTERNAL_ERROR;
357 }
358 OHOS::Bluetooth::BluetoothHiTrace::BluetoothStartAsyncTrace("GATT_CLIENT_CONNECT", 1);
359 int result = pimpl->clientService_->Connect(appId, autoConnect);
360 OHOS::Bluetooth::BluetoothHiTrace::BluetoothFinishAsyncTrace("GATT_CLIENT_CONNECT", 1);
361 return result;
362 }
363
Disconnect(int32_t appId)364 int BluetoothGattClientServer::Disconnect(int32_t appId)
365 {
366 HILOGI("appId: %{public}d", appId);
367 if (PermissionUtils::VerifyUseBluetoothPermission() == PERMISSION_DENIED) {
368 HILOGE("check permission failed");
369 return BT_ERR_PERMISSION_FAILED;
370 }
371 std::lock_guard<std::mutex> lck(pimpl->registerMutex_);
372 if (pimpl->clientService_ == nullptr) {
373 HILOGE("request not support.");
374 return BT_ERR_INTERNAL_ERROR;
375 }
376 return pimpl->clientService_->Disconnect(appId);
377 }
378
DiscoveryServices(int32_t appId)379 int BluetoothGattClientServer::DiscoveryServices(int32_t appId)
380 {
381 HILOGI("appId: %{public}d", appId);
382 std::lock_guard<std::mutex> lck(pimpl->registerMutex_);
383 if (pimpl->clientService_ == nullptr) {
384 HILOGE("request not support.");
385 return BT_ERR_INTERNAL_ERROR;
386 }
387 return pimpl->clientService_->DiscoveryServices(appId);
388 }
389
ReadCharacteristic(int32_t appId,const BluetoothGattCharacteristic & characteristic)390 int BluetoothGattClientServer::ReadCharacteristic(int32_t appId, const BluetoothGattCharacteristic &characteristic)
391 {
392 HILOGI("appId: %{public}d", appId);
393 if (PermissionUtils::VerifyUseBluetoothPermission() == PERMISSION_DENIED) {
394 HILOGE("check permission failed");
395 return BT_ERR_PERMISSION_FAILED;
396 }
397 std::lock_guard<std::mutex> lck(pimpl->registerMutex_);
398 if (pimpl->clientService_ == nullptr) {
399 HILOGE("request not support.");
400 return BT_ERR_INTERNAL_ERROR;
401 }
402 return pimpl->clientService_->ReadCharacteristic(appId, (Characteristic)characteristic);
403 }
404
WriteCharacteristic(int32_t appId,BluetoothGattCharacteristic * characteristic,bool withoutRespond)405 int BluetoothGattClientServer::WriteCharacteristic(
406 int32_t appId, BluetoothGattCharacteristic *characteristic, bool withoutRespond)
407 {
408 HILOGI("appId: %{public}d, withoutRespond: %{public}d", appId, withoutRespond);
409 if (PermissionUtils::VerifyUseBluetoothPermission() == PERMISSION_DENIED) {
410 HILOGE("check permission failed");
411 return BT_ERR_PERMISSION_FAILED;
412 }
413 Characteristic character(characteristic->handle_);
414 character.length_ = characteristic->length_;
415 character.value_ = std::move(characteristic->value_);
416 characteristic->length_ = 0;
417 std::lock_guard<std::mutex> lck(pimpl->registerMutex_);
418 if (pimpl->clientService_ == nullptr) {
419 HILOGE("request not support.");
420 return BT_ERR_INTERNAL_ERROR;
421 }
422 return pimpl->clientService_->WriteCharacteristic(appId, character, withoutRespond);
423 }
SignedWriteCharacteristic(int32_t appId,BluetoothGattCharacteristic * characteristic)424 int BluetoothGattClientServer::SignedWriteCharacteristic(int32_t appId, BluetoothGattCharacteristic *characteristic)
425 {
426 HILOGI("appId: %{public}d", appId);
427 Characteristic character(characteristic->handle_);
428 character.length_ = characteristic->length_;
429 character.value_ = std::move(characteristic->value_);
430 characteristic->length_ = 0;
431 std::lock_guard<std::mutex> lck(pimpl->registerMutex_);
432 if (pimpl->clientService_ == nullptr) {
433 HILOGE("request not support.");
434 return bluetooth::GattStatus::REQUEST_NOT_SUPPORT;
435 }
436 return pimpl->clientService_->SignedWriteCharacteristic(appId, character);
437 }
438
ReadDescriptor(int32_t appId,const BluetoothGattDescriptor & descriptor)439 int BluetoothGattClientServer::ReadDescriptor(int32_t appId, const BluetoothGattDescriptor &descriptor)
440 {
441 HILOGI("appId: %{public}d", appId);
442 if (PermissionUtils::VerifyUseBluetoothPermission() == PERMISSION_DENIED) {
443 HILOGE("check permission failed");
444 return BT_ERR_PERMISSION_FAILED;
445 }
446 std::lock_guard<std::mutex> lck(pimpl->registerMutex_);
447 if (pimpl->clientService_ == nullptr) {
448 HILOGE("request not support.");
449 return BT_ERR_INTERNAL_ERROR;
450 }
451 return pimpl->clientService_->ReadDescriptor(appId, (Descriptor)descriptor);
452 }
453
WriteDescriptor(int32_t appId,BluetoothGattDescriptor * descriptor)454 int BluetoothGattClientServer::WriteDescriptor(int32_t appId, BluetoothGattDescriptor *descriptor)
455 {
456 HILOGI("appId: %{public}d", appId);
457 if (PermissionUtils::VerifyUseBluetoothPermission() == PERMISSION_DENIED) {
458 HILOGE("check permission failed");
459 return BT_ERR_PERMISSION_FAILED;
460 }
461 Descriptor desc(descriptor->handle_);
462 desc.length_ = descriptor->length_;
463 desc.value_ = std::move(descriptor->value_);
464 descriptor->length_ = 0;
465 std::lock_guard<std::mutex> lck(pimpl->registerMutex_);
466 if (pimpl->clientService_ == nullptr) {
467 HILOGE("request not support.");
468 return BT_ERR_INTERNAL_ERROR;
469 }
470 return pimpl->clientService_->WriteDescriptor(appId, desc);
471 }
472
RequestExchangeMtu(int32_t appId,int32_t mtu)473 int BluetoothGattClientServer::RequestExchangeMtu(int32_t appId, int32_t mtu)
474 {
475 HILOGI("appId: %{public}d, mtu: %{public}d", appId, mtu);
476 if (PermissionUtils::VerifyUseBluetoothPermission() == PERMISSION_DENIED) {
477 HILOGE("check permission failed");
478 return BT_ERR_PERMISSION_FAILED;
479 }
480 std::lock_guard<std::mutex> lck(pimpl->registerMutex_);
481 if (pimpl->clientService_ == nullptr) {
482 HILOGE("request not support.");
483 return BT_ERR_INTERNAL_ERROR;
484 }
485 return pimpl->clientService_->RequestExchangeMtu(appId, mtu);
486 }
487
GetAllDevice(::std::vector<BluetoothGattDevice> & device)488 void BluetoothGattClientServer::GetAllDevice(::std::vector<BluetoothGattDevice> &device)
489 {
490 HILOGI("enter");
491 std::lock_guard<std::mutex> lck(pimpl->registerMutex_);
492 if (pimpl->clientService_ == nullptr) {
493 HILOGE("request not support.");
494 return;
495 }
496 for (auto &dev : pimpl->clientService_->GetAllDevice()) {
497 device.push_back(dev);
498 }
499 }
500
RequestConnectionPriority(int32_t appId,int32_t connPriority)501 int BluetoothGattClientServer::RequestConnectionPriority(int32_t appId, int32_t connPriority)
502 {
503 HILOGI("appId: %{public}d, connPriority: %{public}d", appId, connPriority);
504 std::lock_guard<std::mutex> lck(pimpl->registerMutex_);
505 if (pimpl->clientService_ == nullptr) {
506 HILOGE("request not support.");
507 return 0;
508 }
509 return pimpl->clientService_->RequestConnectionPriority(appId, connPriority);
510 }
511
GetServices(int32_t appId,::std::vector<BluetoothGattService> & service)512 int BluetoothGattClientServer::GetServices(int32_t appId, ::std::vector<BluetoothGattService> &service)
513 {
514 HILOGI("appId: %{public}d", appId);
515 if (PermissionUtils::VerifyUseBluetoothPermission() == PERMISSION_DENIED) {
516 HILOGE("check permission failed");
517 return RET_NO_SUPPORT;
518 }
519 std::lock_guard<std::mutex> lck(pimpl->registerMutex_);
520 if (pimpl->clientService_ == nullptr) {
521 HILOGE("request not support.");
522 return BT_ERR_INTERNAL_ERROR;
523 }
524 for (auto &svc : pimpl->clientService_->GetServices(appId)) {
525 service.push_back(svc);
526 }
527 return NO_ERROR;
528 }
529
RequestFastestConn(const BluetoothRawAddress & addr)530 int BluetoothGattClientServer::RequestFastestConn(const BluetoothRawAddress &addr)
531 {
532 HILOGI("NOT SUPPORT NOW");
533 return NO_ERROR;
534 }
535
ReadRemoteRssiValue(int32_t appId)536 int BluetoothGattClientServer::ReadRemoteRssiValue(int32_t appId)
537 {
538 HILOGI("NOT SUPPORT NOW");
539 return NO_ERROR;
540 }
541
RequestNotification(int32_t appId,uint16_t characterHandle,bool enable)542 int BluetoothGattClientServer::RequestNotification(int32_t appId, uint16_t characterHandle, bool enable)
543 {
544 HILOGI("NOT SUPPORT NOW");
545 return NO_ERROR;
546 }
547 } // namespace Bluetooth
548 } // namespace OHOS
549