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