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 <thread>
17
18 #include "bluetooth_a2dp_sink_server.h"
19 #include "bluetooth_a2dp_source_server.h"
20 #include "bluetooth_avrcp_ct_server.h"
21 #include "bluetooth_avrcp_tg_server.h"
22 #include "bluetooth_ble_advertiser_server.h"
23 #include "bluetooth_ble_central_manager_server.h"
24 #include "bluetooth_errorcode.h"
25 #include "bluetooth_gatt_client_server.h"
26 #include "bluetooth_gatt_server_server.h"
27 #include "bluetooth_hfp_ag_server.h"
28 #include "bluetooth_hfp_hf_server.h"
29 #include "bluetooth_hid_host_server.h"
30 #include "bluetooth_host_dumper.h"
31 #include "bluetooth_log.h"
32 #include "bluetooth_pan_server.h"
33 #include "bluetooth_socket_server.h"
34 #include "bluetooth_utils_server.h"
35 #include "file_ex.h"
36 #include "dialog_switch.h"
37 #include "hisysevent.h"
38 #include "interface_adapter_manager.h"
39 #include "permission_utils.h"
40 #include "permission_manager.h"
41 #include "bluetooth_host_server.h"
42
43
44 #include "interface_adapter_ble.h"
45 #include "interface_adapter_classic.h"
46 #include "interface_profile_manager.h"
47 #include "ipc_skeleton.h"
48 #include "raw_address.h"
49 #include "remote_observer_list.h"
50 #include "string_ex.h"
51 #include "system_ability_definition.h"
52 #include "ipc_types.h"
53 #include "safe_map.h"
54
55 namespace OHOS {
56 namespace Bluetooth {
57 using namespace OHOS::bluetooth;
58 struct BluetoothHostServer::impl {
59 impl();
60 ~impl();
61 void Init();
62 void Clear();
63
64 /// sys state observer
65 class SystemStateObserver;
66 std::unique_ptr<SystemStateObserver> systemStateObserver_ = nullptr;
67
68 /// adapter state observer
69 class AdapterStateObserver;
70 std::unique_ptr<AdapterStateObserver> observerImp_ = nullptr;
71
72 /// classic observer
73 class AdapterClassicObserver;
74 std::unique_ptr<AdapterClassicObserver> classicObserverImp_ = nullptr;
75
76 /// classic remote device observer
77 class ClassicRemoteDeviceObserver;
78 std::unique_ptr<ClassicRemoteDeviceObserver> remoteObserverImp_ = nullptr;
79
80 /// ble observer
81 class AdapterBleObserver;
82 std::unique_ptr<AdapterBleObserver> bleObserverImp_ = nullptr;
83
84 /// ble remote device observer
85 class BlePeripheralCallback;
86 std::unique_ptr<BlePeripheralCallback> bleRemoteObserverImp_ = nullptr;
87
88 /// user regist observers
89 RemoteObserverList<IBluetoothHostObserver> observers_;
90 RemoteObserverList<IBluetoothHostObserver> bleObservers_;
91 SafeMap<sptr<IRemoteObject>, uint32_t> observersToken_;
92 SafeMap<sptr<IRemoteObject>, uint32_t> bleObserversToken_;
93 SafeMap<sptr<IRemoteObject>, int32_t> observersPid_;
94 SafeMap<sptr<IRemoteObject>, int32_t> bleObserversPid_;
95
96 /// user regist remote observers
97 RemoteObserverList<IBluetoothRemoteDeviceObserver> remoteObservers_;
98 SafeMap<sptr<IRemoteObject>, uint32_t> remoteObserversToken_;
99 SafeMap<sptr<IRemoteObject>, int32_t> remoteObserversPid_;
100
101 /// user regist remote observers
102 RemoteObserverList<IBluetoothBlePeripheralObserver> bleRemoteObservers_;
103 SafeMap<sptr<IRemoteObject>, uint32_t> bleRemoteObserversToken_;
104
105 SafeMap<std::string, sptr<IRemoteObject>> servers_;
106 SafeMap<std::string, sptr<IRemoteObject>> bleServers_;
107
108 std::vector<sptr<IBluetoothHostObserver>> hostObservers_;
109 std::mutex hostObserversMutex;
110 std::vector<sptr<IBluetoothRemoteDeviceObserver>> remoteDeviceObservers_;
111 std::mutex remoteDeviceObserversMutex;
112 std::vector<sptr<IBluetoothHostObserver>> bleAdapterObservers_;
113 std::mutex bleAdapterObserversMutex;
114 std::vector<sptr<IBluetoothBlePeripheralObserver>> blePeripheralObservers_;
115 std::mutex blePeripheralObserversMutex;
116
117 private:
118 void createServers();
119 };
120
121 class BluetoothHostServer::impl::SystemStateObserver : public ISystemStateObserver {
122 public:
SystemStateObserver(BluetoothHostServer::impl * impl)123 SystemStateObserver(BluetoothHostServer::impl *impl) : impl_(impl) {};
124 ~SystemStateObserver() override = default;
125
OnSystemStateChange(const BTSystemState state)126 void OnSystemStateChange(const BTSystemState state) override
127 {
128 if (!impl_) {
129 HILOGI("failed: impl_ is null");
130 return;
131 }
132 auto classicService = IAdapterManager::GetInstance()->GetClassicAdapterInterface();
133 auto bleService = IAdapterManager::GetInstance()->GetBleAdapterInterface();
134 switch (state) {
135 case BTSystemState::ON:
136 /// update service ptr
137 if (classicService) {
138 classicService->RegisterClassicAdapterObserver(
139 *(IAdapterClassicObserver *)impl_->classicObserverImp_.get());
140 classicService->RegisterRemoteDeviceObserver(
141 *(IClassicRemoteDeviceObserver *)impl_->remoteObserverImp_.get());
142 }
143 if (bleService) {
144 bleService->RegisterBleAdapterObserver(
145 *(IAdapterBleObserver *)impl_->bleObserverImp_.get());
146 bleService->RegisterBlePeripheralCallback(
147 *(IBlePeripheralCallback *)impl_->bleRemoteObserverImp_.get());
148 }
149 break;
150
151 case BTSystemState::OFF:
152 if (classicService) {
153 classicService->DeregisterClassicAdapterObserver(
154 *(IAdapterClassicObserver *)impl_->classicObserverImp_.get());
155 classicService->DeregisterRemoteDeviceObserver(
156 *(IClassicRemoteDeviceObserver *)impl_->remoteObserverImp_.get());
157 classicService = nullptr;
158 }
159 if (bleService) {
160 bleService->DeregisterBleAdapterObserver(
161 *(IAdapterBleObserver *)impl_->bleObserverImp_.get());
162 bleService->DeregisterBlePeripheralCallback(
163 *(IBlePeripheralCallback *)impl_->bleRemoteObserverImp_.get());
164 bleService = nullptr;
165 }
166 break;
167 default:
168 break;
169 }
170 }
171
172 private:
173 BluetoothHostServer::impl *impl_ = nullptr;
174 };
175
176 class BluetoothHostServer::impl::AdapterStateObserver : public IAdapterStateObserver {
177 public:
AdapterStateObserver(BluetoothHostServer::impl * impl)178 AdapterStateObserver(BluetoothHostServer::impl *impl) : impl_(impl){};
179 ~AdapterStateObserver() override = default;
180
OnStateChangeV2(BTTransport transport,BTStateID state,sptr<IBluetoothHostObserver> & observer)181 static void OnStateChangeV2(BTTransport transport, BTStateID state, sptr<IBluetoothHostObserver> &observer)
182 {
183 if (transport == BTTransport::ADAPTER_BREDR && state == BTStateID::STATE_TURN_ON) {
184 observer->OnBluetoothStateChanged(BluetoothSwitchState::STATE_ON);
185 }
186 if (transport == BTTransport::ADAPTER_BLE && state == BTStateID::STATE_TURN_OFF) {
187 observer->OnBluetoothStateChanged(BluetoothSwitchState::STATE_OFF);
188 }
189 }
190
OnStateChange(const BTTransport transport,const BTStateID state)191 void OnStateChange(const BTTransport transport, const BTStateID state) override
192 {
193 if (!impl_) {
194 return;
195 }
196 if (transport == BTTransport::ADAPTER_BREDR) {
197 impl_->observers_.ForEach([this, transport, state](sptr<IBluetoothHostObserver> observer) {
198 int32_t pid = this->impl_->observersPid_.ReadVal(observer->AsObject());
199 if (BluetoothBleCentralManagerServer::IsResourceScheduleControlApp(pid)) {
200 HILOGI("pid:%{public}d is proxy pid, not callback.", pid);
201 return;
202 }
203 uint32_t tokenId = this->impl_->observersToken_.ReadVal(observer->AsObject());
204 if (PermissionUtils::VerifyUseBluetoothPermission(tokenId) == PERMISSION_DENIED) {
205 HILOGE("false, check permission failed");
206 } else {
207 observer->OnStateChanged(transport, state);
208 OnStateChangeV2(transport, state, observer);
209 }
210 });
211 if (state == BTStateID::STATE_TURN_ON || state == BTStateID::STATE_TURN_OFF) {
212 int32_t pid = IPCSkeleton::GetCallingPid();
213 int32_t uid = IPCSkeleton::GetCallingUid();
214 HiSysEventWrite(OHOS::HiviewDFX::HiSysEvent::Domain::BT_SERVICE, "BR_SWITCH_STATE",
215 HiviewDFX::HiSysEvent::EventType::STATISTIC, "PID", pid, "UID", uid, "STATE", state);
216 }
217 } else if (transport == BTTransport::ADAPTER_BLE) {
218 impl_->bleObservers_.ForEach([this, transport, state](sptr<IBluetoothHostObserver> observer) {
219 int32_t pid = this->impl_->bleObserversPid_.ReadVal(observer->AsObject());
220 if (BluetoothBleCentralManagerServer::IsResourceScheduleControlApp(pid)) {
221 HILOGI("pid:%{public}d is proxy pid, not callback.", pid);
222 return;
223 }
224 uint32_t tokenId = this->impl_->bleObserversToken_.ReadVal(observer->AsObject());
225 if (PermissionUtils::VerifyUseBluetoothPermission(tokenId) == PERMISSION_DENIED) {
226 HILOGE("false, check permission failed");
227 } else {
228 observer->OnStateChanged(transport, state);
229 OnStateChangeV2(transport, state, observer);
230 }
231 });
232 if (state == BTStateID::STATE_TURN_ON || state == BTStateID::STATE_TURN_OFF) {
233 int32_t pid = IPCSkeleton::GetCallingPid();
234 int32_t uid = IPCSkeleton::GetCallingUid();
235 HiSysEventWrite(OHOS::HiviewDFX::HiSysEvent::Domain::BT_SERVICE, "BLE_SWITCH_STATE",
236 HiviewDFX::HiSysEvent::EventType::STATISTIC, "PID", pid, "UID", uid, "STATE", state);
237 }
238 }
239 }
240
241 private:
242 BluetoothHostServer::impl *impl_ = nullptr;
243 BLUETOOTH_DISALLOW_COPY_AND_ASSIGN(AdapterStateObserver);
244 };
245 class BluetoothHostServer::impl::AdapterClassicObserver : public IAdapterClassicObserver {
246 public:
AdapterClassicObserver(BluetoothHostServer::impl * impl)247 AdapterClassicObserver(BluetoothHostServer::impl *impl) : impl_(impl) {};
248 ~AdapterClassicObserver() override = default;
249
OnDiscoveryStateChanged(const int32_t status)250 void OnDiscoveryStateChanged(const int32_t status) override
251 {
252 HILOGI("status: %{public}d", status);
253 impl_->observers_.ForEach([this, status](sptr<IBluetoothHostObserver> observer) {
254 int32_t pid = this->impl_->observersPid_.ReadVal(observer->AsObject());
255 if (BluetoothBleCentralManagerServer::IsResourceScheduleControlApp(pid)) {
256 HILOGI("pid:%{public}d is proxy pid, not callback.", pid);
257 return;
258 }
259 observer->OnDiscoveryStateChanged(static_cast<int32_t>(status));
260 });
261 if (status == DISCOVERY_STARTED || status == DISCOVERY_STOPED) {
262 int32_t pid = IPCSkeleton::GetCallingPid();
263 int32_t uid = IPCSkeleton::GetCallingUid();
264 HiSysEventWrite(OHOS::HiviewDFX::HiSysEvent::Domain::BT_SERVICE, "DISCOVERY_STATE",
265 HiviewDFX::HiSysEvent::EventType::STATISTIC, "PID", pid, "UID", uid, "STATE", status);
266 }
267 }
268
OnDiscoveryResult(const RawAddress & device,int rssi,const std::string deviceName,int deviceClass)269 void OnDiscoveryResult(
270 const RawAddress &device, int rssi, const std::string deviceName, int deviceClass) override
271 {
272 HILOGI("device: %{public}s, rssi: %{public}d, deviceName: %{pubiic}s, deviceClass: %{public}d",
273 GET_ENCRYPT_ADDR(device), rssi, deviceName.c_str(), deviceClass);
274 impl_->observers_.ForEach([this, device, rssi, deviceName, deviceClass](IBluetoothHostObserver *observer) {
275 int32_t pid = this->impl_->observersPid_.ReadVal(observer->AsObject());
276 if (BluetoothBleCentralManagerServer::IsResourceScheduleControlApp(pid)) {
277 HILOGI("pid:%{public}d is proxy pid, not callback.", pid);
278 return;
279 }
280 uint32_t tokenId = this->impl_->observersToken_.ReadVal(observer->AsObject());
281 if (PermissionUtils::VerifyDiscoverBluetoothPermission(tokenId) == PERMISSION_DENIED) {
282 HILOGE("OnDiscoveryResult() false, check permission failed");
283 } else {
284 observer->OnDiscoveryResult(device, rssi, deviceName, deviceClass);
285 }
286 });
287 }
288
OnPairRequested(const BTTransport transport,const RawAddress & device)289 void OnPairRequested(const BTTransport transport, const RawAddress &device) override
290 {
291 HILOGI("device: %{public}s", GET_ENCRYPT_ADDR(device));
292 impl_->observers_.ForEach(
293 [transport, device](IBluetoothHostObserver *observer) { observer->OnPairRequested(transport, device); });
294 }
295
OnPairConfirmed(const BTTransport transport,const RawAddress & device,int32_t reqType,int32_t number)296 void OnPairConfirmed(
297 const BTTransport transport, const RawAddress &device, int32_t reqType, int32_t number) override
298 {
299 HILOGI("device: %{public}s, reqType: %{public}d, number: %{public}d",
300 GET_ENCRYPT_ADDR(device), reqType, number);
301 impl_->observers_.ForEach([this, transport, device, reqType, number](IBluetoothHostObserver *observer) {
302 uint32_t tokenId = this->impl_->observersToken_.ReadVal(observer->AsObject());
303 if (PermissionUtils::VerifyUseBluetoothPermission(tokenId) == PERMISSION_DENIED) {
304 HILOGE("false, check permission failed");
305 } else {
306 observer->OnPairConfirmed(transport, device, reqType, number);
307 }
308 });
309 }
310
OnScanModeChanged(int32_t mode)311 void OnScanModeChanged(int32_t mode) override
312 {
313 HILOGI("mode: %{public}d", mode);
314 impl_->observers_.ForEach([mode](IBluetoothHostObserver *observer) { observer->OnScanModeChanged(mode); });
315 }
316
OnDeviceNameChanged(const std::string & deviceName)317 void OnDeviceNameChanged(const std::string &deviceName) override
318 {
319 HILOGI("deviceName: %{public}s", deviceName.c_str());
320 impl_->observers_.ForEach(
321 [deviceName](IBluetoothHostObserver *observer) { observer->OnDeviceNameChanged(deviceName); });
322 }
323
OnDeviceAddrChanged(const std::string & address)324 void OnDeviceAddrChanged(const std::string &address) override
325 {
326 HILOGI("address: %{public}s", GetEncryptAddr(address).c_str());
327 impl_->observers_.ForEach(
328 [address](IBluetoothHostObserver *observer) { observer->OnDeviceAddrChanged(address); });
329 }
330
331 private:
332 BluetoothHostServer::impl *impl_ = nullptr;
333 BLUETOOTH_DISALLOW_COPY_AND_ASSIGN(AdapterClassicObserver);
334 };
335 class BluetoothHostServer::impl::ClassicRemoteDeviceObserver : public IClassicRemoteDeviceObserver {
336 public:
ClassicRemoteDeviceObserver(BluetoothHostServer::impl * impl)337 ClassicRemoteDeviceObserver(BluetoothHostServer::impl *impl) : impl_(impl) {};
338 ~ClassicRemoteDeviceObserver() override = default;
339
OnAclStateChanged(const RawAddress & device,int state,unsigned int reason)340 void OnAclStateChanged(const RawAddress &device, int state, unsigned int reason) override
341 {
342 return;
343 }
344
OnPairStatusChanged(const BTTransport transport,const RawAddress & device,const int32_t status)345 void OnPairStatusChanged(const BTTransport transport, const RawAddress &device, const int32_t status) override
346 {
347 HILOGI("device: %{public}s, status: %{public}d", GET_ENCRYPT_ADDR(device), status);
348 impl_->remoteObservers_.ForEach([this, transport, device, status](IBluetoothRemoteDeviceObserver *observer) {
349 int32_t pid = this->impl_->remoteObserversPid_.ReadVal(observer->AsObject());
350 if (BluetoothBleCentralManagerServer::IsResourceScheduleControlApp(pid)) {
351 HILOGI("pid:%{public}d is proxy pid, not callback.", pid);
352 return;
353 }
354 uint32_t tokenId = this->impl_->remoteObserversToken_.ReadVal(observer->AsObject());
355 if (PermissionUtils::VerifyUseBluetoothPermission(tokenId) == PERMISSION_DENIED) {
356 HILOGE("false, check permission failed");
357 } else {
358 observer->OnPairStatusChanged(transport, device, status, PAIR_COMMON_BOND_CAUSE);
359 }
360 });
361 }
362
OnRemoteUuidChanged(const RawAddress & device,const std::vector<Uuid> & uuids)363 void OnRemoteUuidChanged(const RawAddress &device, const std::vector<Uuid> &uuids) override
364 {
365 HILOGI("device: %{public}s", GET_ENCRYPT_ADDR(device));
366 std::vector<bluetooth::Uuid> btUuids;
367 for (const auto &val : uuids) {
368 btUuids.push_back(val);
369 }
370 impl_->remoteObservers_.ForEach([this, device, btUuids](IBluetoothRemoteDeviceObserver *observer) {
371 int32_t pid = this->impl_->remoteObserversPid_.ReadVal(observer->AsObject());
372 if (BluetoothBleCentralManagerServer::IsResourceScheduleControlApp(pid)) {
373 HILOGI("pid:%{public}d is proxy pid, not callback.", pid);
374 return;
375 }
376 observer->OnRemoteUuidChanged(device, btUuids);
377 });
378 }
379
OnRemoteNameChanged(const RawAddress & device,const std::string & deviceName)380 void OnRemoteNameChanged(const RawAddress &device, const std::string &deviceName) override
381 {
382 HILOGI("device: %{public}s, deviceName: %{public}s", GET_ENCRYPT_ADDR(device), deviceName.c_str());
383 impl_->remoteObservers_.ForEach([this, device, deviceName](IBluetoothRemoteDeviceObserver *observer) {
384 int32_t pid = this->impl_->remoteObserversPid_.ReadVal(observer->AsObject());
385 if (BluetoothBleCentralManagerServer::IsResourceScheduleControlApp(pid)) {
386 HILOGI("pid:%{public}d is proxy pid, not callback.", pid);
387 return;
388 }
389 observer->OnRemoteNameChanged(device, deviceName);
390 });
391 }
392
OnRemoteAliasChanged(const RawAddress & device,const std::string & alias)393 void OnRemoteAliasChanged(const RawAddress &device, const std::string &alias) override
394 {
395 HILOGI("device: %{public}s, alias: %{public}s", GET_ENCRYPT_ADDR(device), alias.c_str());
396 impl_->remoteObservers_.ForEach([device, alias](IBluetoothRemoteDeviceObserver *observer) {
397 observer->OnRemoteAliasChanged(device, alias);
398 });
399 }
400
OnRemoteCodChanged(const RawAddress & device,int32_t cod)401 void OnRemoteCodChanged(const RawAddress &device, int32_t cod) override
402 {
403 HILOGI("device: %{public}s, cod: %{public}d", GET_ENCRYPT_ADDR(device), cod);
404 impl_->remoteObservers_.ForEach([this, device, cod](IBluetoothRemoteDeviceObserver *observer) {
405 int32_t pid = this->impl_->remoteObserversPid_.ReadVal(observer->AsObject());
406 if (BluetoothBleCentralManagerServer::IsResourceScheduleControlApp(pid)) {
407 HILOGI("pid:%{public}d is proxy pid, not callback.", pid);
408 return;
409 }
410 observer->OnRemoteCodChanged(device, cod);
411 });
412 }
413
414 private:
415 BluetoothHostServer::impl *impl_ = nullptr;
416 BLUETOOTH_DISALLOW_COPY_AND_ASSIGN(ClassicRemoteDeviceObserver);
417 };
418
419 class BluetoothHostServer::impl::AdapterBleObserver : public IAdapterBleObserver {
420 public:
AdapterBleObserver(BluetoothHostServer::impl * impl)421 AdapterBleObserver(BluetoothHostServer::impl *impl) : impl_(impl){};
422 ~AdapterBleObserver() override = default;
423
OnDiscoveryStateChanged(const int32_t status)424 void OnDiscoveryStateChanged(const int32_t status) override
425 {
426 HILOGI("status: %{public}d", status);
427 impl_->bleObservers_.ForEach([this, status](sptr<IBluetoothHostObserver> observer) {
428 int32_t pid = this->impl_->bleObserversPid_.ReadVal(observer->AsObject());
429 if (BluetoothBleCentralManagerServer::IsResourceScheduleControlApp(pid)) {
430 HILOGI("pid:%{public}d is proxy pid, not callback.", pid);
431 return;
432 }
433 observer->OnDiscoveryStateChanged(static_cast<int32_t>(status));
434 });
435 }
436
OnDiscoveryResult(const RawAddress & device,int rssi,const std::string deviceName,int deviceClass)437 void OnDiscoveryResult(
438 const RawAddress &device, int rssi, const std::string deviceName, int deviceClass) override
439 {
440 HILOGI("device: %{public}s, rssi: %{public}d, deviceName: %{pubiic}s, deviceClass: %{public}d",
441 GET_ENCRYPT_ADDR(device), rssi, deviceName.c_str(), deviceClass);
442 impl_->bleObservers_.ForEach([this, device, rssi, deviceName, deviceClass](IBluetoothHostObserver *observer) {
443 int32_t pid = this->impl_->bleObserversPid_.ReadVal(observer->AsObject());
444 if (BluetoothBleCentralManagerServer::IsResourceScheduleControlApp(pid)) {
445 HILOGI("pid:%{public}d is proxy pid, not callback.", pid);
446 return;
447 }
448 uint32_t tokenId = this->impl_->bleObserversToken_.ReadVal(observer->AsObject());
449 if (PermissionUtils::VerifyDiscoverBluetoothPermission(tokenId) == PERMISSION_DENIED) {
450 HILOGE("false, check permission failed");
451 } else {
452 observer->OnDiscoveryResult(device, rssi, deviceName, deviceClass);
453 }
454 });
455 }
456
OnPairRequested(const BTTransport transport,const RawAddress & device)457 void OnPairRequested(const BTTransport transport, const RawAddress &device) override
458 {
459 HILOGI("device: %{public}s", GET_ENCRYPT_ADDR(device));
460 impl_->bleObservers_.ForEach(
461 [transport, device](IBluetoothHostObserver *observer) { observer->OnPairRequested(transport, device); });
462 }
463
OnPairConfirmed(const BTTransport transport,const RawAddress & device,const int32_t reqType,const int32_t number)464 void OnPairConfirmed(
465 const BTTransport transport, const RawAddress &device, const int32_t reqType, const int32_t number) override
466 {
467 HILOGI("device: %{public}s, reqType: %{public}d, number: %{public}d",
468 GET_ENCRYPT_ADDR(device), reqType, number);
469 impl_->bleObservers_.ForEach([this, transport, device, reqType, number](IBluetoothHostObserver *observer) {
470 int32_t pid = this->impl_->bleObserversPid_.ReadVal(observer->AsObject());
471 if (BluetoothBleCentralManagerServer::IsResourceScheduleControlApp(pid)) {
472 HILOGI("pid:%{public}d is proxy pid, not callback.", pid);
473 return;
474 }
475 uint32_t tokenId = this->impl_->bleObserversToken_.ReadVal(observer->AsObject());
476 if (PermissionUtils::VerifyUseBluetoothPermission(tokenId) == PERMISSION_DENIED) {
477 HILOGE("OnPairConfirmed() false, check permission failed");
478 } else {
479 observer->OnPairConfirmed(transport, device, reqType, number);
480 }
481 });
482 }
483
OnScanModeChanged(const int32_t mode)484 void OnScanModeChanged(const int32_t mode) override
485 {
486 HILOGI("mode: %{public}d", mode);
487 impl_->bleObservers_.ForEach([mode](IBluetoothHostObserver *observer) { observer->OnScanModeChanged(mode); });
488 }
489
OnDeviceNameChanged(const std::string deviceName)490 void OnDeviceNameChanged(const std::string deviceName) override
491 {
492 HILOGI("deviceName: %{public}s", deviceName.c_str());
493 impl_->bleObservers_.ForEach(
494 [deviceName](IBluetoothHostObserver *observer) { observer->OnDeviceNameChanged(deviceName); });
495 }
496
OnDeviceAddrChanged(const std::string address)497 void OnDeviceAddrChanged(const std::string address) override
498 {
499 HILOGI("address: %{public}s", GetEncryptAddr(address).c_str());
500 impl_->bleObservers_.ForEach(
501 [address](IBluetoothHostObserver *observer) { observer->OnDeviceAddrChanged(address); });
502 }
503
OnAdvertisingStateChanged(const int32_t state)504 void OnAdvertisingStateChanged(const int32_t state) override
505 {}
506
507 private:
508 BluetoothHostServer::impl *impl_ = nullptr;
509 BLUETOOTH_DISALLOW_COPY_AND_ASSIGN(AdapterBleObserver);
510 };
511 class BluetoothHostServer::impl::BlePeripheralCallback : public IBlePeripheralCallback {
512 public:
BlePeripheralCallback(BluetoothHostServer::impl * impl)513 BlePeripheralCallback(BluetoothHostServer::impl *impl) : impl_(impl) {};
514 ~BlePeripheralCallback() override = default;
515
OnReadRemoteRssiEvent(const RawAddress & device,int32_t rssi,int32_t status)516 void OnReadRemoteRssiEvent(const RawAddress &device, int32_t rssi, int32_t status) override
517 {
518 HILOGI("device: %{public}s, rssi: %{public}d, status: %{public}d",
519 GET_ENCRYPT_ADDR(device), rssi, status);
520 impl_->bleRemoteObservers_.ForEach([device, rssi, status](IBluetoothBlePeripheralObserver *observer) {
521 observer->OnReadRemoteRssiEvent(device, rssi, status);
522 });
523 }
524
OnPairStatusChanged(const BTTransport transport,const RawAddress & device,int32_t status)525 void OnPairStatusChanged(const BTTransport transport, const RawAddress &device, int32_t status) override
526 {
527 HILOGI("device: %{public}s, status: %{public}d", GET_ENCRYPT_ADDR(device), status);
528 impl_->bleRemoteObservers_.ForEach([this, transport, device, status](
529 IBluetoothBlePeripheralObserver *observer) {
530 uint32_t tokenId = this->impl_->bleRemoteObserversToken_.ReadVal(observer->AsObject());
531 if (PermissionUtils::VerifyUseBluetoothPermission(tokenId) == PERMISSION_DENIED) {
532 HILOGE("false, check permission failed");
533 } else {
534 observer->OnPairStatusChanged(transport, device, status, PAIR_COMMON_BOND_CAUSE);
535 }
536 });
537 }
538
OnAclStateChanged(const RawAddress & device,int state,unsigned int reason)539 void OnAclStateChanged(const RawAddress &device, int state, unsigned int reason) override
540 {
541 return;
542 }
543
544 private:
545 BluetoothHostServer::impl *impl_ = nullptr;
546 BLUETOOTH_DISALLOW_COPY_AND_ASSIGN(BlePeripheralCallback);
547 };
548
549 std::mutex BluetoothHostServer::instanceLock;
550 sptr<BluetoothHostServer> BluetoothHostServer::instance;
551
552 const bool REGISTER_RESULT = SystemAbility::MakeAndRegisterAbility(BluetoothHostServer::GetInstance().GetRefPtr());
553
impl()554 BluetoothHostServer::impl::impl()
555 {
556 HILOGI("starts");
557 systemStateObserver_ = std::make_unique<SystemStateObserver>(this);
558 observerImp_ = std::make_unique<AdapterStateObserver>(this);
559 classicObserverImp_ = std::make_unique<AdapterClassicObserver>(this);
560 remoteObserverImp_ = std::make_unique<ClassicRemoteDeviceObserver>(this);
561 bleObserverImp_ = std::make_unique<AdapterBleObserver>(this);
562 bleRemoteObserverImp_ = std::make_unique<BlePeripheralCallback>(this);
563 }
564
~impl()565 BluetoothHostServer::impl::~impl()
566 {
567 HILOGI("starts");
568 }
569
Init()570 void BluetoothHostServer::impl::Init()
571 {
572 HILOGI("starts");
573 IAdapterManager::GetInstance()->RegisterSystemStateObserver(*systemStateObserver_);
574
575 IAdapterManager::GetInstance()->Start();
576 IAdapterManager::GetInstance()->RegisterStateObserver(*observerImp_);
577
578 auto classicService = IAdapterManager::GetInstance()->GetClassicAdapterInterface();
579 auto bleService = IAdapterManager::GetInstance()->GetBleAdapterInterface();
580 if (classicService) {
581 classicService->RegisterClassicAdapterObserver(*classicObserverImp_.get());
582 classicService->RegisterRemoteDeviceObserver(*remoteObserverImp_.get());
583 }
584 if (bleService) {
585 bleService->RegisterBleAdapterObserver(*bleObserverImp_.get());
586 bleService->RegisterBlePeripheralCallback(*bleRemoteObserverImp_.get());
587 }
588
589 createServers();
590 }
591
Clear()592 void BluetoothHostServer::impl::Clear()
593 {
594 /// systerm state observer
595 IAdapterManager::GetInstance()->DeregisterSystemStateObserver(*systemStateObserver_);
596
597 /// adapter state observer
598 IAdapterManager::GetInstance()->Stop();
599 IAdapterManager::GetInstance()->DeregisterStateObserver(*observerImp_);
600
601 auto classicService = IAdapterManager::GetInstance()->GetClassicAdapterInterface();
602 if (classicService) {
603 /// classic observer
604 classicService->DeregisterClassicAdapterObserver(*classicObserverImp_.get());
605 /// classic remote observer
606 classicService->DeregisterRemoteDeviceObserver(*remoteObserverImp_.get());
607 }
608
609 auto bleService = IAdapterManager::GetInstance()->GetBleAdapterInterface();
610 if (bleService) {
611 /// ble observer
612 bleService->DeregisterBleAdapterObserver(*bleObserverImp_.get());
613 /// ble remote observer
614 bleService->DeregisterBlePeripheralCallback(*bleRemoteObserverImp_.get());
615 }
616 }
617
createServers()618 void BluetoothHostServer::impl::createServers()
619 {
620 sptr<BluetoothSocketServer> socket = new BluetoothSocketServer();
621 servers_.EnsureInsert(PROFILE_SOCKET, socket->AsObject());
622
623 sptr<BluetoothGattServerServer> gattserver = new BluetoothGattServerServer();
624 servers_.EnsureInsert(PROFILE_GATT_SERVER, gattserver->AsObject());
625
626 sptr<BluetoothGattClientServer> gattclient = new BluetoothGattClientServer();
627 servers_.EnsureInsert(PROFILE_GATT_CLIENT, gattclient->AsObject());
628
629 #ifdef BLUETOOTH_HFP_AG_FEATURE
630 sptr<BluetoothHfpAgServer> hfpAg = new BluetoothHfpAgServer();
631 servers_.EnsureInsert(PROFILE_HFP_AG, hfpAg->AsObject());
632 #endif
633
634 #ifdef BLUETOOTH_HFP_HF_FEATURE
635 sptr<BluetoothHfpHfServer> hfpHf = new BluetoothHfpHfServer();
636 servers_.EnsureInsert(PROFILE_HFP_HF, hfpHf->AsObject());
637 #endif
638
639 #ifdef BLUETOOTH_AVRCP_CT_FEATURE
640 sptr<BluetoothAvrcpCtServer> avrcpCtServer = new BluetoothAvrcpCtServer();
641 servers_.EnsureInsert(PROFILE_AVRCP_CT, avrcpCtServer->AsObject());
642 #endif
643
644 #ifdef BLUETOOTH_AVRCP_TG_FEATURE
645 sptr<BluetoothAvrcpTgServer> avrcpTgServer = new BluetoothAvrcpTgServer();
646 servers_.EnsureInsert(PROFILE_AVRCP_TG, avrcpTgServer->AsObject());
647 #endif
648
649 sptr<BluetoothBleAdvertiserServer> bleAdvertiser = new BluetoothBleAdvertiserServer();
650 bleServers_.EnsureInsert(BLE_ADVERTISER_SERVER, bleAdvertiser->AsObject());
651
652 sptr<BluetoothBleCentralManagerServer> bleCentralManger = new BluetoothBleCentralManagerServer();
653 bleServers_.EnsureInsert(BLE_CENTRAL_MANAGER_SERVER, bleCentralManger->AsObject());
654
655 #ifdef BLUETOOTH_MAP_SERVER_FEATURE
656 sptr<BluetoothMapMceServer> mapMce = new BluetoothMapMceServer();
657 servers_.EnsureInsert(PROFILE_MAP_MCE, mapMce->AsObject());
658 #endif
659
660 #ifdef BLUETOOTH_MAP_CLIENT_FEATURE
661 sptr<BluetoothMapMseServer> mapMse = new BluetoothMapMseServer();
662 servers_.EnsureInsert(PROFILE_MAP_MSE, mapMse->AsObject());
663 #endif
664
665 #ifdef BLUETOOTH_A2DP_SRC_FEATURE
666 sptr<BluetoothA2dpSourceServer> a2dpSource = new BluetoothA2dpSourceServer();
667 servers_.EnsureInsert(PROFILE_A2DP_SRC, a2dpSource->AsObject());
668 #endif
669
670 #ifdef BLUETOOTH_A2DP_SINK_FEATURE
671 sptr<BluetoothA2dpSinkServer> a2dpSink = new BluetoothA2dpSinkServer();
672 servers_.EnsureInsert(PROFILE_A2DP_SINK, a2dpSink->AsObject());
673 #endif
674
675 #ifdef BLUETOOTH_HID_HOST_FEATURE
676 sptr<BluetoothHidHostServer> hidHostServer = new BluetoothHidHostServer();
677 servers_.EnsureInsert(PROFILE_HID_HOST_SERVER, hidHostServer->AsObject());
678 #endif
679
680 #ifdef BLUETOOTH_PAN_FEATURE
681 sptr<BluetoothPanServer> panServer = new BluetoothPanServer();
682 servers_.EnsureInsert(PROFILE_PAN_SERVER, panServer->AsObject());
683 #endif
684
685 HILOGI("servers_ constructed, size is %{public}d", servers_.Size());
686 }
687
BluetoothHostServer()688 BluetoothHostServer::BluetoothHostServer() : SystemAbility(BLUETOOTH_HOST_SYS_ABILITY_ID, true)
689 {
690 pimpl = std::make_unique<impl>();
691 }
692
~BluetoothHostServer()693 BluetoothHostServer::~BluetoothHostServer()
694 {
695 HILOGI("~BluetoothHostServer called.");
696 }
697
GetInstance()698 sptr<BluetoothHostServer> BluetoothHostServer::GetInstance()
699 {
700 std::lock_guard<std::mutex> autoLock(instanceLock);
701 if (instance == nullptr) {
702 sptr<BluetoothHostServer> temp = new BluetoothHostServer();
703 instance = temp;
704 }
705 return instance;
706 }
707
OnStart()708 void BluetoothHostServer::OnStart()
709 {
710 HILOGI("starting service.");
711 if (state_ == ServiceRunningState::STATE_RUNNING) {
712 HILOGI("service is already started.");
713 return;
714 }
715
716 if (!Init()) {
717 HILOGE("initiation failed");
718 OnStop();
719 return;
720 }
721
722 state_ = ServiceRunningState::STATE_RUNNING;
723
724 HILOGI("service has been started successfully");
725 return;
726 }
727
Init()728 bool BluetoothHostServer::Init()
729 {
730 pimpl->Init();
731 if (!registeredToService_) {
732 bool ret = Publish(BluetoothHostServer::GetInstance());
733 if (!ret) {
734 HILOGE("init publish failed!");
735 return false;
736 }
737 registeredToService_ = true;
738 }
739 HILOGI("init success");
740 return true;
741 }
742
OnStop()743 void BluetoothHostServer::OnStop()
744 {
745 HILOGI("stopping service.");
746
747 pimpl->Clear();
748 state_ = ServiceRunningState::STATE_IDLE;
749 registeredToService_ = false;
750 return;
751 }
752
RegisterObserver(const sptr<IBluetoothHostObserver> & observer)753 void BluetoothHostServer::RegisterObserver(const sptr<IBluetoothHostObserver> &observer)
754 {
755 if (observer == nullptr) {
756 HILOGE("RegisterObserver observer is null");
757 return;
758 }
759
760 pimpl->observersToken_.EnsureInsert(observer->AsObject(), IPCSkeleton::GetCallingTokenID());
761 pimpl->observersPid_.EnsureInsert(observer->AsObject(), IPCSkeleton::GetCallingUid());
762 auto func = std::bind(&BluetoothHostServer::DeregisterObserver, this, std::placeholders::_1);
763 pimpl->observers_.Register(observer, func);
764 std::lock_guard<std::mutex> lock(pimpl->hostObserversMutex);
765 pimpl->hostObservers_.push_back(observer);
766 }
767
DeregisterObserver(const sptr<IBluetoothHostObserver> & observer)768 void BluetoothHostServer::DeregisterObserver(const sptr<IBluetoothHostObserver> &observer)
769 {
770 if (observer == nullptr || pimpl == nullptr) {
771 HILOGE("DeregisterObserver observer is null");
772 return;
773 }
774 {
775 std::lock_guard<std::mutex> lock(pimpl->hostObserversMutex);
776 for (auto iter = pimpl->hostObservers_.begin(); iter != pimpl->hostObservers_.end(); ++iter) {
777 if ((*iter)->AsObject() == observer->AsObject()) {
778 pimpl->observers_.Deregister(*iter);
779 pimpl->hostObservers_.erase(iter);
780 break;
781 }
782 }
783 }
784 pimpl->observersToken_.Erase(observer->AsObject());
785 pimpl->observersPid_.Erase(observer->AsObject());
786 }
787
EnableBt()788 int32_t BluetoothHostServer::EnableBt()
789 {
790 if (IAdapterManager::GetInstance()->Enable(bluetooth::BTTransport::ADAPTER_BREDR)) {
791 return NO_ERROR;
792 }
793 return BT_ERR_INTERNAL_ERROR;
794 }
795
DisableBt(bool isAsync)796 int32_t BluetoothHostServer::DisableBt(bool isAsync)
797 {
798 if (PermissionUtils::VerifyAccessBluetoothPermission() == PERMISSION_DENIED) {
799 HILOGE("false, check Access permission failed");
800 return BT_ERR_PERMISSION_FAILED;
801 }
802 if (isAsync) {
803 return BT_ERR_API_NOT_SUPPORT;
804 }
805 if (IAdapterManager::GetInstance()->Disable(bluetooth::BTTransport::ADAPTER_BREDR)) {
806 return NO_ERROR;
807 }
808 return BT_ERR_INTERNAL_ERROR;
809 }
810
ConvertBTStateIDToBluetoothState(int32_t brState,int32_t bleState)811 static int32_t ConvertBTStateIDToBluetoothState(int32_t brState, int32_t bleState)
812 {
813 BluetoothState state = BluetoothState::STATE_OFF;
814 switch (brState) {
815 case BTStateID::STATE_TURN_ON: state = BluetoothState::STATE_ON; break;
816 case BTStateID::STATE_TURNING_ON: state = BluetoothState::STATE_TURNING_ON; break;
817 case BTStateID::STATE_TURNING_OFF: state = BluetoothState::STATE_TURNING_OFF; break;
818 case BTStateID::STATE_TURN_OFF: {
819 switch (bleState) {
820 case BTStateID::STATE_TURN_ON: state = BluetoothState::STATE_BLE_ON; break;
821 case BTStateID::STATE_TURNING_ON: state = BluetoothState::STATE_BLE_TURNING_ON; break;
822 case BTStateID::STATE_TURNING_OFF: state = BluetoothState::STATE_BLE_TURNING_OFF; break;
823 default: break;
824 }
825 }
826 default: HILOGE("Invalid bt state"); break;
827 }
828 return static_cast<int32_t>(state);
829 }
830
GetBtState(int32_t & state)831 int32_t BluetoothHostServer::GetBtState(int32_t &state)
832 {
833 int32_t brState = IAdapterManager::GetInstance()->GetState(bluetooth::BTTransport::ADAPTER_BREDR);
834 int32_t bleState = IAdapterManager::GetInstance()->GetState(bluetooth::BTTransport::ADAPTER_BLE);
835 state = ConvertBTStateIDToBluetoothState(brState, bleState);
836 return BT_NO_ERROR;
837 }
838
GetProfile(const std::string & name)839 sptr<IRemoteObject> BluetoothHostServer::GetProfile(const std::string &name)
840 {
841 HILOGI("seraching %{public}s ", name.c_str());
842 sptr<IRemoteObject> object = nullptr;
843 if (pimpl->servers_.Find(name, object)) {
844 return object;
845 }
846 return object;
847 }
848
GetBleRemote(const std::string & name)849 sptr<IRemoteObject> BluetoothHostServer::GetBleRemote(const std::string &name)
850 {
851 HILOGI("GetBleRemote %{public}s ", name.c_str());
852 sptr<IRemoteObject> object = nullptr;
853 if (pimpl->bleServers_.Find(name, object)) {
854 return object;
855 }
856 return object;
857 }
858
859 // Fac_Res_CODE
BluetoothFactoryReset()860 int32_t BluetoothHostServer::BluetoothFactoryReset()
861 {
862 bool ret = IAdapterManager::GetInstance()->FactoryReset();
863 return ret ? BT_NO_ERROR : BT_ERR_INTERNAL_ERROR;
864 }
865
GetDeviceType(int32_t transport,const std::string & address)866 int32_t BluetoothHostServer::GetDeviceType(int32_t transport, const std::string &address)
867 {
868 HILOGI("transport: %{public}d, address: %{public}s", transport, GetEncryptAddr(address).c_str());
869 auto classicService = IAdapterManager::GetInstance()->GetClassicAdapterInterface();
870 auto bleService = IAdapterManager::GetInstance()->GetBleAdapterInterface();
871 RawAddress addr(address);
872 if ((transport == BTTransport::ADAPTER_BREDR) && IsBtEnabled() && classicService) {
873 return classicService->GetDeviceType(addr);
874 } else if ((transport == BTTransport::ADAPTER_BLE) && IsBleEnabled() && bleService) {
875 return bleService->GetDeviceType(addr);
876 } else {
877 HILOGE("transport invalid or BT current state is not enabled!");
878 }
879 return INVALID_VALUE;
880 }
881
GetLocalAddress(std::string & addr)882 int32_t BluetoothHostServer::GetLocalAddress(std::string &addr)
883 {
884 HILOGI("Enter!");
885 if (PermissionUtils::VerifyAccessBluetoothPermission() == PERMISSION_DENIED) {
886 HILOGE("false, check Access permission failed");
887 return BT_ERR_PERMISSION_FAILED;
888 }
889 if (PermissionUtils::VerifyGetBluetoothLocalMacPermission() == PERMISSION_DENIED) {
890 HILOGE("false, check GetLocalMac permission failed");
891 return BT_ERR_PERMISSION_FAILED;
892 }
893 auto classicService = IAdapterManager::GetInstance()->GetClassicAdapterInterface();
894 auto bleService = IAdapterManager::GetInstance()->GetBleAdapterInterface();
895 if (IsBtEnabled() && classicService) {
896 addr = classicService->GetLocalAddress();
897 return NO_ERROR;
898 } else if (IsBleEnabled() && bleService) {
899 addr = bleService->GetLocalAddress();
900 return NO_ERROR;
901 } else {
902 HILOGW("BT current state is not enabled!");
903 return BT_ERR_INVALID_STATE;
904 }
905 }
906
EnableBle(bool noAutoConnect,bool isAsync)907 int32_t BluetoothHostServer::EnableBle(bool noAutoConnect, bool isAsync)
908 {
909 HILOGI("Enter!");
910 if (PermissionUtils::VerifyAccessBluetoothPermission() == PERMISSION_DENIED) {
911 HILOGE("false, check Access permission failed");
912 return BT_ERR_PERMISSION_FAILED;
913 }
914 if (isAsync) {
915 return BT_ERR_API_NOT_SUPPORT;
916 }
917 if (!BluetoothHostServer::IsBleEnabled() && IAdapterManager::GetInstance()->Enable(BTTransport::ADAPTER_BLE)) {
918 return NO_ERROR;
919 }
920 return BT_ERR_INTERNAL_ERROR;
921 }
922
DisableBle()923 int32_t BluetoothHostServer::DisableBle()
924 {
925 HILOGI("Enter!");
926 if (IAdapterManager::GetInstance()->Disable(BTTransport::ADAPTER_BLE)) {
927 return NO_ERROR;
928 }
929 return BT_ERR_INTERNAL_ERROR;
930 }
931
IsBrEnabled()932 bool BluetoothHostServer::IsBrEnabled()
933 {
934 return IsBtEnabled();
935 }
936
IsBleEnabled()937 bool BluetoothHostServer::IsBleEnabled()
938 {
939 return IAdapterManager::GetInstance()->GetState(BTTransport::ADAPTER_BLE) == BTStateID::STATE_TURN_ON;
940 }
941
GetProfileList()942 std::vector<uint32_t> BluetoothHostServer::GetProfileList()
943 {
944 HILOGI("Enter!");
945 return IProfileManager::GetInstance()->GetProfileServicesList();
946 }
947
GetMaxNumConnectedAudioDevices()948 int32_t BluetoothHostServer::GetMaxNumConnectedAudioDevices()
949 {
950 HILOGI("Enter!");
951 return IAdapterManager::GetInstance()->GetMaxNumConnectedAudioDevices();
952 }
953
GetBtConnectionState(int32_t & state)954 int32_t BluetoothHostServer::GetBtConnectionState(int32_t &state)
955 {
956 if (PermissionUtils::VerifyUseBluetoothPermission() == PERMISSION_DENIED) {
957 HILOGE("false, check permission failed");
958 return BT_ERR_PERMISSION_FAILED;
959 }
960 if (IsBtEnabled()) {
961 state = (int32_t)IAdapterManager::GetInstance()->GetAdapterConnectState();
962 HILOGI("state: %{public}d", state);
963 return NO_ERROR;
964 } else {
965 HILOGW("BT current state is not enabled!");
966 return BT_ERR_INVALID_STATE;
967 }
968 }
969
GetBtProfileConnState(uint32_t profileId,int & state)970 int32_t BluetoothHostServer::GetBtProfileConnState(uint32_t profileId, int &state)
971 {
972 HILOGI("Enter!");
973 if (PermissionUtils::VerifyUseBluetoothPermission() == PERMISSION_DENIED) {
974 HILOGE("false, check permission failed");
975 return BT_ERR_PERMISSION_FAILED;
976 }
977 if (IsBtEnabled()) {
978 state = (int32_t)IProfileManager::GetInstance()->GetProfileServiceConnectState(profileId);
979 return NO_ERROR;
980 } else {
981 HILOGW("BT current state is not enabled!");
982 return BT_ERR_INVALID_STATE;
983 }
984 }
985
GetLocalSupportedUuids(std::vector<std::string> & uuids)986 void BluetoothHostServer::GetLocalSupportedUuids(std::vector<std::string> &uuids)
987 {
988 HILOGI("Enter!");
989 IProfileManager::GetInstance()->GetProfileServicesSupportedUuids(uuids);
990 }
991
GetLocalDeviceClass()992 int32_t BluetoothHostServer::GetLocalDeviceClass()
993 {
994 HILOGI("Enter!");
995 auto classicService = IAdapterManager::GetInstance()->GetClassicAdapterInterface();
996 if (IsBtEnabled() && classicService) {
997 return classicService->GetLocalDeviceClass();
998 } else {
999 HILOGW("BT current state is not enabled!");
1000 }
1001 return 0;
1002 }
1003
SetLocalDeviceClass(const int32_t & deviceClass)1004 bool BluetoothHostServer::SetLocalDeviceClass(const int32_t &deviceClass)
1005 {
1006 HILOGI("Enter!");
1007 auto classicService = IAdapterManager::GetInstance()->GetClassicAdapterInterface();
1008 if (IsBtEnabled() && classicService) {
1009 return classicService->SetLocalDeviceClass(deviceClass);
1010 } else {
1011 HILOGW("BT current state is not enabled!");
1012 }
1013 return false;
1014 }
1015
GetLocalName(std::string & name)1016 int32_t BluetoothHostServer::GetLocalName(std::string &name)
1017 {
1018 HILOGI("Enter!");
1019 if (PermissionUtils::VerifyUseBluetoothPermission() == PERMISSION_DENIED) {
1020 HILOGE("false, check permission failed");
1021 return BT_ERR_PERMISSION_FAILED;
1022 }
1023 auto classicService = IAdapterManager::GetInstance()->GetClassicAdapterInterface();
1024 auto bleService = IAdapterManager::GetInstance()->GetBleAdapterInterface();
1025 if (IsBtEnabled() && classicService) {
1026 name = classicService->GetLocalName();
1027 return NO_ERROR;
1028 } else if (IsBleEnabled() && bleService) {
1029 name = bleService->GetLocalName();
1030 return NO_ERROR;
1031 } else {
1032 HILOGW("BT current state is not enabled!");
1033 return BT_ERR_INVALID_STATE;
1034 }
1035 }
1036
SetLocalName(const std::string & name)1037 int32_t BluetoothHostServer::SetLocalName(const std::string &name)
1038 {
1039 HILOGI("name: %{public}s", name.c_str());
1040 int api12 = 12;
1041 if (!PermissionUtils::CheckSystemHapApp() && PermissionUtils::GetApiVersion() >= api12) {
1042 return BT_ERR_API_NOT_SUPPORT;
1043 }
1044 if (PermissionUtils::VerifyDiscoverBluetoothPermission() == PERMISSION_DENIED) {
1045 HILOGE("false, check permission failed");
1046 return BT_ERR_PERMISSION_FAILED;
1047 }
1048 auto classicService = IAdapterManager::GetInstance()->GetClassicAdapterInterface();
1049 auto bleService = IAdapterManager::GetInstance()->GetBleAdapterInterface();
1050 if (IsBtEnabled() && classicService) {
1051 bool ret = classicService->SetLocalName(name);
1052 if (ret && (IsBleEnabled() && bleService)) {
1053 if (bleService->SetLocalName(name)) {
1054 return NO_ERROR;
1055 }
1056 } else {
1057 HILOGE("failed!");
1058 return BT_ERR_INTERNAL_ERROR;
1059 }
1060 } else if (IsBleEnabled() && bleService) {
1061 if (bleService->SetLocalName(name)) {
1062 return NO_ERROR;
1063 }
1064 } else {
1065 HILOGW("BT current state is not enabled!");
1066 return BT_ERR_INVALID_STATE;
1067 }
1068 return BT_ERR_INTERNAL_ERROR;
1069 }
1070
GetBtScanMode(int32_t & scanMode)1071 int32_t BluetoothHostServer::GetBtScanMode(int32_t &scanMode)
1072 {
1073 HILOGI("Enter!");
1074 if (PermissionUtils::VerifyUseBluetoothPermission() == PERMISSION_DENIED) {
1075 HILOGE("false, check permission failed");
1076 return BT_ERR_PERMISSION_FAILED;
1077 }
1078 auto classicService = IAdapterManager::GetInstance()->GetClassicAdapterInterface();
1079 if (IsBtEnabled() && classicService) {
1080 scanMode = classicService->GetBtScanMode();
1081 return NO_ERROR;
1082 } else {
1083 HILOGW("BT current state is not enabled!");
1084 return BT_ERR_INVALID_STATE;
1085 }
1086 }
1087
SetBtScanMode(int32_t mode,int32_t duration)1088 int32_t BluetoothHostServer::SetBtScanMode(int32_t mode, int32_t duration)
1089 {
1090 HILOGI("mode: %{public}d, duration: %{public}d", mode, duration);
1091 if (PermissionUtils::VerifyUseBluetoothPermission() == PERMISSION_DENIED) {
1092 HILOGE("false, check permission failed");
1093 return BT_ERR_PERMISSION_FAILED;
1094 }
1095 auto classicService = IAdapterManager::GetInstance()->GetClassicAdapterInterface();
1096 if (IsBtEnabled() && classicService) {
1097 if (classicService->SetBtScanMode(mode, duration)) {
1098 return NO_ERROR;
1099 }
1100 } else {
1101 HILOGW("BT current state is not enabled!");
1102 return BT_ERR_INVALID_STATE;
1103 }
1104 return BT_ERR_INTERNAL_ERROR;
1105 }
1106
GetBondableMode(int32_t transport)1107 int32_t BluetoothHostServer::GetBondableMode(int32_t transport)
1108 {
1109 HILOGI("transport: %{public}d", transport);
1110 auto classicService = IAdapterManager::GetInstance()->GetClassicAdapterInterface();
1111 auto bleService = IAdapterManager::GetInstance()->GetBleAdapterInterface();
1112 if ((transport == BTTransport::ADAPTER_BREDR) && IsBtEnabled() && classicService) {
1113 return classicService->GetBondableMode();
1114 } else if ((transport == BTTransport::ADAPTER_BLE) && IsBleEnabled() && bleService) {
1115 return bleService->GetBondableMode();
1116 } else {
1117 HILOGE("Parameter::transport invalid or BT current state is not enabled!");
1118 }
1119 return BONDABLE_MODE_OFF;
1120 }
1121
SetBondableMode(int32_t transport,int32_t mode)1122 bool BluetoothHostServer::SetBondableMode(int32_t transport, int32_t mode)
1123 {
1124 HILOGI("transport: %{public}d, mode: %{public}d", transport, mode);
1125 auto classicService = IAdapterManager::GetInstance()->GetClassicAdapterInterface();
1126 auto bleService = IAdapterManager::GetInstance()->GetBleAdapterInterface();
1127 if ((transport == BTTransport::ADAPTER_BREDR) && IsBtEnabled() && classicService) {
1128 return classicService->SetBondableMode(mode);
1129 } else if ((transport == BTTransport::ADAPTER_BLE) && IsBleEnabled() && bleService) {
1130 return bleService->SetBondableMode(mode);
1131 } else {
1132 HILOGE("Parameter::transport invalid or BT current state is not enabled!");
1133 }
1134 return false;
1135 }
1136
StartBtDiscovery()1137 int32_t BluetoothHostServer::StartBtDiscovery()
1138 {
1139 HILOGI("Enter!");
1140 if (PermissionUtils::VerifyDiscoverBluetoothPermission() == PERMISSION_DENIED) {
1141 HILOGE("false, check permission failed");
1142 return BT_ERR_PERMISSION_FAILED;
1143 }
1144 if (PermissionUtils::VerifyApproximatelyPermission() == PERMISSION_DENIED &&
1145 PermissionUtils::VerifyLocationPermission() == PERMISSION_DENIED) {
1146 HILOGE("No location permission");
1147 return BT_ERR_PERMISSION_FAILED;
1148 }
1149 auto classicService = IAdapterManager::GetInstance()->GetClassicAdapterInterface();
1150 if (IsBtEnabled() && classicService) {
1151 if (classicService->StartBtDiscovery()) {
1152 return NO_ERROR;
1153 }
1154 } else {
1155 HILOGW("BT current state is not enabled!");
1156 return BT_ERR_INVALID_STATE;
1157 }
1158 return BT_ERR_INTERNAL_ERROR;
1159 }
1160
CancelBtDiscovery()1161 int32_t BluetoothHostServer::CancelBtDiscovery()
1162 {
1163 HILOGI("Enter!");
1164 if (PermissionUtils::VerifyDiscoverBluetoothPermission() == PERMISSION_DENIED) {
1165 HILOGE("false, check permission failed");
1166 return BT_ERR_PERMISSION_FAILED;
1167 }
1168 auto classicService = IAdapterManager::GetInstance()->GetClassicAdapterInterface();
1169 if (IsBtEnabled() && classicService) {
1170 if (classicService->CancelBtDiscovery()) {
1171 return NO_ERROR;
1172 }
1173 } else {
1174 HILOGW("BT current state is not enabled!");
1175 return BT_ERR_INVALID_STATE;
1176 }
1177 return BT_ERR_INTERNAL_ERROR;
1178 }
1179
IsBtDiscovering(bool & isDisCovering,int32_t transport)1180 int32_t BluetoothHostServer::IsBtDiscovering(bool &isDisCovering, int32_t transport)
1181 {
1182 HILOGI("transport: %{public}d", transport);
1183 if (PermissionUtils::VerifyAccessBluetoothPermission() == PERMISSION_DENIED) {
1184 HILOGE("false, check permission failed");
1185 return BT_ERR_PERMISSION_FAILED;
1186 }
1187 auto classicService = IAdapterManager::GetInstance()->GetClassicAdapterInterface();
1188 auto bleService = IAdapterManager::GetInstance()->GetBleAdapterInterface();
1189 if ((transport == BTTransport::ADAPTER_BREDR) && IsBtEnabled() && classicService) {
1190 isDisCovering = classicService->IsBtDiscovering();
1191 } else if ((transport == BTTransport::ADAPTER_BLE) && IsBleEnabled() && bleService) {
1192 isDisCovering = bleService->IsBtDiscovering();
1193 } else {
1194 HILOGE("Parameter::transport invalid or BT current state is not enabled!");
1195 return BT_ERR_INVALID_STATE;
1196 }
1197 return BT_NO_ERROR;
1198 }
1199
GetBtDiscoveryEndMillis()1200 long BluetoothHostServer::GetBtDiscoveryEndMillis()
1201 {
1202 HILOGI("Enter!");
1203 auto classicService = IAdapterManager::GetInstance()->GetClassicAdapterInterface();
1204 if (IsBtEnabled() && classicService) {
1205 return classicService->GetBtDiscoveryEndMillis();
1206 } else {
1207 HILOGW("BT current state is not enabled!");
1208 }
1209 return INVALID_VALUE;
1210 }
1211
GetPairedDevices(std::vector<BluetoothRawAddress> & pairedAddr)1212 int32_t BluetoothHostServer::GetPairedDevices(std::vector<BluetoothRawAddress> &pairedAddr)
1213 {
1214 HILOGI("GetPairedDevices");
1215 if (PermissionUtils::GetApiVersion() >= 10) { // 10:api version
1216 if (PermissionUtils::VerifyAccessBluetoothPermission() == PERMISSION_DENIED) {
1217 HILOGE("false, check Access permission failed");
1218 return BT_ERR_PERMISSION_FAILED;
1219 }
1220 } else {
1221 if (PermissionUtils::VerifyUseBluetoothPermission() == PERMISSION_DENIED) {
1222 HILOGE("false, check permission failed");
1223 return BT_ERR_SYSTEM_PERMISSION_FAILED;
1224 }
1225 }
1226 auto classicService = IAdapterManager::GetInstance()->GetClassicAdapterInterface();
1227 auto bleService = IAdapterManager::GetInstance()->GetBleAdapterInterface();
1228 std::vector<RawAddress> rawAddrVec;
1229 if (IsBtEnabled() && classicService) {
1230 rawAddrVec = classicService->GetPairedDevices();
1231 } else {
1232 HILOGE("transport invalid or BT current state is not enabled!");
1233 return BT_ERR_INVALID_STATE;
1234 }
1235 for (auto it = rawAddrVec.begin(); it != rawAddrVec.end(); ++it) {
1236 BluetoothRawAddress rawAddr = BluetoothRawAddress(*it);
1237 pairedAddr.emplace_back(rawAddr);
1238 }
1239 if (IsBleEnabled() && bleService) {
1240 rawAddrVec = bleService->GetPairedDevices();
1241 } else {
1242 HILOGE("transport invalid or BT current state is not enabled!");
1243 return BT_ERR_INVALID_STATE;
1244 }
1245
1246 for (auto it = rawAddrVec.begin(); it != rawAddrVec.end(); ++it) {
1247 BluetoothRawAddress rawAddr = BluetoothRawAddress(*it);
1248 pairedAddr.emplace_back(rawAddr);
1249 }
1250 return NO_ERROR;
1251 }
1252
GetTransportByDeviceType(int32_t transport,const std::string & address)1253 int BluetoothHostServer::GetTransportByDeviceType(int32_t transport, const std::string &address)
1254 {
1255 if (transport == BT_TRANSPORT_NONE) {
1256 int deviceType = GetDeviceType(BT_TRANSPORT_BREDR, address);
1257 if (deviceType == INVALID_TYPE || deviceType == DEVICE_TYPE_LE) {
1258 transport = BT_TRANSPORT_BLE;
1259 } else {
1260 transport = BT_TRANSPORT_BREDR;
1261 }
1262 }
1263 return transport;
1264 }
1265
RemovePair(int32_t transport,const sptr<BluetoothRawAddress> & device)1266 int32_t BluetoothHostServer::RemovePair(int32_t transport, const sptr<BluetoothRawAddress> &device)
1267 {
1268 if (device == nullptr) {
1269 HILOGE("device is nullptr.");
1270 return BT_ERR_INTERNAL_ERROR;
1271 }
1272 HILOGI("addr:%{public}s, transport:%{public}d", GET_ENCRYPT_ADDR(*device), transport);
1273 if (!PermissionUtils::CheckSystemHapApp()) {
1274 HILOGE("check system api failed.");
1275 return BT_ERR_SYSTEM_PERMISSION_FAILED;
1276 }
1277 if (PermissionUtils::VerifyDiscoverBluetoothPermission() == PERMISSION_DENIED) {
1278 HILOGE("check permission failed.");
1279 return BT_ERR_PERMISSION_FAILED;
1280 }
1281 auto classicService = IAdapterManager::GetInstance()->GetClassicAdapterInterface();
1282 auto bleService = IAdapterManager::GetInstance()->GetBleAdapterInterface();
1283 transport = GetTransportByDeviceType(transport, device->GetAddress());
1284 if ((transport == BTTransport::ADAPTER_BREDR) && IsBtEnabled() && classicService) {
1285 if (classicService->RemovePair(*device)) {
1286 return NO_ERROR;
1287 }
1288 } else if ((transport == BTTransport::ADAPTER_BLE) && IsBleEnabled() && bleService) {
1289 if (bleService->RemovePair(*device)) {
1290 return NO_ERROR;
1291 }
1292 } else {
1293 HILOGE("transport invalid or BT/BLE current state is not enabled!");
1294 return BT_ERR_INVALID_STATE;
1295 }
1296 return BT_ERR_INTERNAL_ERROR;
1297 }
1298
RemoveAllPairs()1299 bool BluetoothHostServer::RemoveAllPairs()
1300 {
1301 HILOGI("Enter!");
1302 if (PermissionUtils::VerifyDiscoverBluetoothPermission() == PERMISSION_DENIED) {
1303 HILOGE("check permission failed");
1304 return false;
1305 }
1306 if (BTStateID::STATE_TURN_ON != IAdapterManager::GetInstance()->GetState(BTTransport::ADAPTER_BREDR) &&
1307 BTStateID::STATE_TURN_ON != IAdapterManager::GetInstance()->GetState(BTTransport::ADAPTER_BLE)) {
1308 HILOGW("BT current state is not enabled!");
1309 return false;
1310 }
1311
1312 auto classicService = IAdapterManager::GetInstance()->GetClassicAdapterInterface();
1313 bool ret = true;
1314 if (IsBtEnabled() && classicService) {
1315 ret = classicService->RemoveAllPairs();
1316 if (!ret) {
1317 HILOGE("BREDR RemoveAllPairs failed");
1318 }
1319 }
1320
1321 auto bleService = IAdapterManager::GetInstance()->GetBleAdapterInterface();
1322 if (IsBleEnabled() && bleService) {
1323 ret &= bleService->RemoveAllPairs();
1324 if (!ret) {
1325 HILOGE("BLE RemoveAllPairs failed");
1326 }
1327 }
1328 return ret;
1329 }
1330
GetBleMaxAdvertisingDataLength()1331 int32_t BluetoothHostServer::GetBleMaxAdvertisingDataLength()
1332 {
1333 HILOGI("Enter!");
1334 auto bleService = IAdapterManager::GetInstance()->GetBleAdapterInterface();
1335 if (IsBleEnabled() && bleService) {
1336 return bleService->GetBleMaxAdvertisingDataLength();
1337 } else {
1338 HILOGW("BT current state is not enabled!");
1339 }
1340 return INVALID_VALUE;
1341 }
1342
GetPhonebookPermission(const std::string & address)1343 int32_t BluetoothHostServer::GetPhonebookPermission(const std::string &address)
1344 {
1345 HILOGI("address: %{public}s", GetEncryptAddr(address).c_str());
1346 return (int32_t)IAdapterManager::GetInstance()->GetPhonebookPermission(address);
1347 }
1348
SetPhonebookPermission(const std::string & address,int32_t permission)1349 bool BluetoothHostServer::SetPhonebookPermission(const std::string &address, int32_t permission)
1350 {
1351 HILOGI("address: %{public}s, permission: %{public}d", GetEncryptAddr(address).c_str(), permission);
1352 return IAdapterManager::GetInstance()->SetPhonebookPermission(address, (BTPermissionType)permission);
1353 }
1354
GetMessagePermission(const std::string & address)1355 int32_t BluetoothHostServer::GetMessagePermission(const std::string &address)
1356 {
1357 HILOGI("address: %{public}s", GetEncryptAddr(address).c_str());
1358 return (int32_t)IAdapterManager::GetInstance()->GetMessagePermission(address);
1359 }
1360
SetMessagePermission(const std::string & address,int32_t permission)1361 bool BluetoothHostServer::SetMessagePermission(const std::string &address, int32_t permission)
1362 {
1363 HILOGI("address: %{public}s, permission: %{public}d", GetEncryptAddr(address).c_str(), permission);
1364 return IAdapterManager::GetInstance()->SetMessagePermission(address, (BTPermissionType)permission);
1365 }
1366
GetPowerMode(const std::string & address)1367 int32_t BluetoothHostServer::GetPowerMode(const std::string &address)
1368 {
1369 HILOGI("address: %{public}s", GetEncryptAddr(address).c_str());
1370 return IAdapterManager::GetInstance()->GetPowerMode(address);
1371 }
1372
GetDeviceName(int32_t transport,const std::string & address,std::string & name,bool alias)1373 int32_t BluetoothHostServer::GetDeviceName(int32_t transport, const std::string &address, std::string &name, bool alias)
1374 {
1375 if (PermissionUtils::VerifyUseBluetoothPermission() == PERMISSION_DENIED) {
1376 HILOGE("false, check permission failed");
1377 return BT_ERR_PERMISSION_FAILED;
1378 }
1379 auto classicService = IAdapterManager::GetInstance()->GetClassicAdapterInterface();
1380 auto bleService = IAdapterManager::GetInstance()->GetBleAdapterInterface();
1381 RawAddress addr(address);
1382 transport = GetTransportByDeviceType(transport, address);
1383 if ((transport == BT_TRANSPORT_BREDR) && IsBtEnabled() && classicService) {
1384 name = classicService->GetDeviceName(addr);
1385 return NO_ERROR;
1386 } else if ((transport == BT_TRANSPORT_BLE) && IsBleEnabled() && bleService) {
1387 name = bleService->GetDeviceName(addr);
1388 return NO_ERROR;
1389 } else {
1390 HILOGE("transport invalid or BT current state is not enabled!");
1391 return BT_ERR_INVALID_STATE;
1392 }
1393 }
1394
GetDeviceAlias(const std::string & address)1395 std::string BluetoothHostServer::GetDeviceAlias(const std::string &address)
1396 {
1397 HILOGI("address: %{public}s", GetEncryptAddr(address).c_str());
1398 if (PermissionUtils::VerifyUseBluetoothPermission() == PERMISSION_DENIED) {
1399 HILOGE("false, check permission failed");
1400 return INVALID_NAME;
1401 }
1402 auto classicService = IAdapterManager::GetInstance()->GetClassicAdapterInterface();
1403 if (IsBtEnabled() && classicService) {
1404 RawAddress addr(address);
1405 return classicService->GetAliasName(addr);
1406 } else {
1407 HILOGE("BT current state is not enabled");
1408 }
1409 return INVALID_NAME;
1410 }
1411
SetDeviceAlias(const std::string & address,const std::string & aliasName)1412 int32_t BluetoothHostServer::SetDeviceAlias(const std::string &address, const std::string &aliasName)
1413 {
1414 HILOGI("address: %{public}s, aliasName: %{public}s", GetEncryptAddr(address).c_str(), aliasName.c_str());
1415 if (PermissionUtils::VerifyUseBluetoothPermission() == PERMISSION_DENIED) {
1416 HILOGE("false, check permission failed");
1417 return BT_ERR_PERMISSION_FAILED;
1418 }
1419 auto classicService = IAdapterManager::GetInstance()->GetClassicAdapterInterface();
1420 if (IsBtEnabled() && classicService) {
1421 RawAddress addr(address);
1422 return classicService->SetAliasName(addr, aliasName) ? BT_NO_ERROR : BT_ERR_INVALID_PARAM;
1423 } else {
1424 HILOGE("BT current state is not enabled");
1425 }
1426 return BT_ERR_INVALID_STATE;
1427 }
1428
GetRemoteDeviceBatteryInfo(const std::string & address,BluetoothBatteryInfo & batteryInfo)1429 int32_t BluetoothHostServer::GetRemoteDeviceBatteryInfo(const std::string &address,
1430 BluetoothBatteryInfo &batteryInfo)
1431 {
1432 if (PermissionUtils::VerifyAccessBluetoothPermission() == PERMISSION_DENIED) {
1433 HILOGE("false, check Access permission failed");
1434 return BT_ERR_PERMISSION_FAILED;
1435 }
1436 return BT_ERR_INTERNAL_ERROR;
1437 }
1438
GetPairState(int32_t transport,const std::string & address,int32_t & pairState)1439 int32_t BluetoothHostServer::GetPairState(int32_t transport, const std::string &address, int32_t &pairState)
1440 {
1441 HILOGI("transport: %{public}d, address: %{public}s", transport, GetEncryptAddr(address).c_str());
1442 if (PermissionUtils::VerifyAccessBluetoothPermission() == PERMISSION_DENIED) {
1443 HILOGE("false, check Access permission failed");
1444 return BT_ERR_PERMISSION_FAILED;
1445 }
1446 auto classicService = IAdapterManager::GetInstance()->GetClassicAdapterInterface();
1447 auto bleService = IAdapterManager::GetInstance()->GetBleAdapterInterface();
1448 RawAddress addr(address);
1449 if ((transport == BT_TRANSPORT_BREDR) && IsBtEnabled() && classicService) {
1450 pairState = classicService->GetPairState(addr);
1451 } else if ((transport == BT_TRANSPORT_BLE) && IsBleEnabled() && bleService) {
1452 pairState = bleService->GetPairState(addr);
1453 } else {
1454 HILOGE("transport invalid or BT current state is not enabled!");
1455 }
1456 return BT_NO_ERROR;
1457 }
1458
StartPair(int32_t transport,const std::string & address)1459 int32_t BluetoothHostServer::StartPair(int32_t transport, const std::string &address)
1460 {
1461 HILOGI("transport: %{public}d, address: %{public}s", transport, GetEncryptAddr(address).c_str());
1462 if (PermissionUtils::VerifyDiscoverBluetoothPermission() == PERMISSION_DENIED) {
1463 HILOGE("StartPair false, check permission failed");
1464 return BT_ERR_PERMISSION_FAILED;
1465 }
1466 auto classicService = IAdapterManager::GetInstance()->GetClassicAdapterInterface();
1467 auto bleService = IAdapterManager::GetInstance()->GetBleAdapterInterface();
1468 RawAddress addr(address);
1469 transport = GetTransportByDeviceType(transport, address);
1470 if ((transport == BT_TRANSPORT_BREDR) && IsBtEnabled() && classicService) {
1471 if (classicService->StartPair(addr)) {
1472 return NO_ERROR;
1473 }
1474 } else if ((transport == BT_TRANSPORT_BLE) && IsBleEnabled() && bleService) {
1475 if (bleService->StartPair(addr)) {
1476 return NO_ERROR;
1477 }
1478 } else {
1479 HILOGE("transport invalid or BT current state is not enabled!");
1480 return BT_ERR_INVALID_STATE;
1481 }
1482 return BT_ERR_INTERNAL_ERROR;
1483 }
1484
CancelPairing(int32_t transport,const std::string & address)1485 bool BluetoothHostServer::CancelPairing(int32_t transport, const std::string &address)
1486 {
1487 HILOGI("transport: %{public}d, address: %{public}s", transport, GetEncryptAddr(address).c_str());
1488 if (!PermissionUtils::CheckSystemHapApp()) {
1489 HILOGE("check system api failed.");
1490 return BT_ERR_SYSTEM_PERMISSION_FAILED;
1491 }
1492 if (PermissionUtils::VerifyDiscoverBluetoothPermission() == PERMISSION_DENIED) {
1493 HILOGE("false, check permission failed");
1494 return false;
1495 }
1496 auto classicService = IAdapterManager::GetInstance()->GetClassicAdapterInterface();
1497 auto bleService = IAdapterManager::GetInstance()->GetBleAdapterInterface();
1498 RawAddress addr(address);
1499 transport = GetTransportByDeviceType(transport, address);
1500 if ((transport == BT_TRANSPORT_BREDR) && IsBtEnabled() && classicService) {
1501 return classicService->CancelPairing(addr);
1502 } else if ((transport == BT_TRANSPORT_BLE) && IsBleEnabled() && bleService) {
1503 return bleService->CancelPairing(addr);
1504 } else {
1505 HILOGE("transport invalid or BT current state is not enabled!");
1506 }
1507 return false;
1508 }
1509
IsBondedFromLocal(int32_t transport,const std::string & address)1510 bool BluetoothHostServer::IsBondedFromLocal(int32_t transport, const std::string &address)
1511 {
1512 HILOGI("transport: %{public}d, address: %{public}s", transport, GetEncryptAddr(address).c_str());
1513 auto classicService = IAdapterManager::GetInstance()->GetClassicAdapterInterface();
1514 auto bleService = IAdapterManager::GetInstance()->GetBleAdapterInterface();
1515 RawAddress addr(address);
1516 if ((transport == BT_TRANSPORT_BREDR) && IsBtEnabled() && classicService) {
1517 return classicService->IsBondedFromLocal(addr);
1518 } else if ((transport == BT_TRANSPORT_BLE) && IsBleEnabled() && bleService) {
1519 return bleService->IsBondedFromLocal(addr);
1520 } else {
1521 HILOGE("transport invalid or BT current state is not enabled!");
1522 }
1523 return false;
1524 }
1525
IsAclConnected(int32_t transport,const std::string & address)1526 bool BluetoothHostServer::IsAclConnected(int32_t transport, const std::string &address)
1527 {
1528 HILOGI("transport: %{public}d, address: %{public}s", transport, GetEncryptAddr(address).c_str());
1529 auto classicService = IAdapterManager::GetInstance()->GetClassicAdapterInterface();
1530 auto bleService = IAdapterManager::GetInstance()->GetBleAdapterInterface();
1531 RawAddress addr(address);
1532 if ((transport == BT_TRANSPORT_BREDR) && IsBtEnabled() && classicService) {
1533 return classicService->IsAclConnected(addr);
1534 } else if ((transport == BT_TRANSPORT_BLE) && IsBleEnabled() && bleService) {
1535 return bleService->IsAclConnected(addr);
1536 } else {
1537 HILOGE("transport invalid or BT current state is not enabled!");
1538 }
1539 return false;
1540 }
1541
IsAclEncrypted(int32_t transport,const std::string & address)1542 bool BluetoothHostServer::IsAclEncrypted(int32_t transport, const std::string &address)
1543 {
1544 HILOGI("transport: %{public}d, address: %{public}s", transport, GetEncryptAddr(address).c_str());
1545 auto classicService = IAdapterManager::GetInstance()->GetClassicAdapterInterface();
1546 auto bleService = IAdapterManager::GetInstance()->GetBleAdapterInterface();
1547 RawAddress addr(address);
1548 if ((transport == BT_TRANSPORT_BREDR) && IsBtEnabled() && classicService) {
1549 return classicService->IsAclEncrypted(addr);
1550 } else if ((transport == BT_TRANSPORT_BLE) && IsBleEnabled() && bleService) {
1551 return bleService->IsAclEncrypted(addr);
1552 } else {
1553 HILOGE("transport invalid or BT current state is not enabled!");
1554 }
1555 return false;
1556 }
1557
GetDeviceClass(const std::string & address,int32_t & cod)1558 int32_t BluetoothHostServer::GetDeviceClass(const std::string &address, int32_t &cod)
1559 {
1560 HILOGI("address: %{public}s", GetEncryptAddr(address).c_str());
1561 if (PermissionUtils::VerifyUseBluetoothPermission() == PERMISSION_DENIED) {
1562 HILOGE("false, check permission failed");
1563 return BT_ERR_PERMISSION_FAILED;
1564 }
1565 auto classicService = IAdapterManager::GetInstance()->GetClassicAdapterInterface();
1566 if (IsBtEnabled() && classicService) {
1567 RawAddress addr(address);
1568 cod = classicService->GetDeviceClass(addr);
1569 } else {
1570 HILOGE("BT current state is not enabled!");
1571 return BT_ERR_INVALID_STATE;
1572 }
1573 return NO_ERROR;
1574 }
1575
GetDeviceUuids(const std::string & address,std::vector<std::string> & uuids)1576 int32_t BluetoothHostServer::GetDeviceUuids(const std::string &address, std::vector<std::string> &uuids)
1577 {
1578 std::vector<bluetooth::Uuid> parcelUuids;
1579 RawAddress addr(address);
1580 if (!IsBtEnabled()) {
1581 HILOGE("BT current state is not enabled");
1582 return BT_ERR_INVALID_STATE;
1583 }
1584
1585 auto classicService = IAdapterManager::GetInstance()->GetClassicAdapterInterface();
1586 if (classicService) {
1587 parcelUuids = classicService->GetDeviceUuids(addr);
1588 }
1589 for (auto Uuid : parcelUuids) {
1590 uuids.push_back(Uuid.ToString());
1591 }
1592 return NO_ERROR;
1593 }
1594
GetLocalProfileUuids(std::vector<std::string> & uuids)1595 int32_t BluetoothHostServer::GetLocalProfileUuids(std::vector<std::string> &uuids)
1596 {
1597 return NO_ERROR;
1598 }
1599
SetDevicePin(const std::string & address,const std::string & pin)1600 int32_t BluetoothHostServer::SetDevicePin(const std::string &address, const std::string &pin)
1601 {
1602 HILOGI("address: %{public}s, pin: %{public}s", GetEncryptAddr(address).c_str(), pin.c_str());
1603 if (PermissionUtils::VerifyManageBluetoothPermission() == PERMISSION_DENIED) {
1604 HILOGE("false, check permission failed");
1605 return BT_ERR_PERMISSION_FAILED;
1606 }
1607 auto classicService = IAdapterManager::GetInstance()->GetClassicAdapterInterface();
1608 if (IsBtEnabled() && classicService) {
1609 RawAddress addr(address);
1610 if (classicService->SetDevicePin(addr, pin)) {
1611 return NO_ERROR;
1612 }
1613 } else {
1614 HILOGE("BT current state is not enabled!");
1615 return BT_ERR_INVALID_STATE;
1616 }
1617 return BT_ERR_INTERNAL_ERROR;
1618 }
1619
SetDevicePairingConfirmation(int32_t transport,const std::string & address,bool accept)1620 int32_t BluetoothHostServer::SetDevicePairingConfirmation(int32_t transport, const std::string &address, bool accept)
1621 {
1622 HILOGI("transport: %{public}d, address: %{public}s, accept: %{public}d",
1623 transport, GetEncryptAddr(address).c_str(), accept);
1624 if (PermissionUtils::VerifyManageBluetoothPermission() == PERMISSION_DENIED) {
1625 HILOGE("false, check permission failed");
1626 return BT_ERR_PERMISSION_FAILED;
1627 }
1628 auto classicService = IAdapterManager::GetInstance()->GetClassicAdapterInterface();
1629 auto bleService = IAdapterManager::GetInstance()->GetBleAdapterInterface();
1630 RawAddress addr(address);
1631 transport = GetTransportByDeviceType(transport, address);
1632 if ((transport == BT_TRANSPORT_BREDR) && IsBtEnabled() && classicService) {
1633 if (classicService->SetDevicePairingConfirmation(addr, accept)) {
1634 return NO_ERROR;
1635 }
1636 } else if ((transport == BT_TRANSPORT_BLE) && IsBleEnabled() && bleService) {
1637 if (bleService->SetDevicePairingConfirmation(addr, accept)) {
1638 return NO_ERROR;
1639 }
1640 } else {
1641 HILOGE("transport invalid or BT current state is not enabled!");
1642 return BT_ERR_INVALID_STATE;
1643 }
1644 return BT_ERR_INTERNAL_ERROR;
1645 }
1646
SetDevicePasskey(int32_t transport,const std::string & address,int32_t passkey,bool accept)1647 bool BluetoothHostServer::SetDevicePasskey(int32_t transport, const std::string &address, int32_t passkey, bool accept)
1648 {
1649 HILOGI("transport: %{public}d, address: %{public}s, passkey: %{public}d, accept: %{public}d",
1650 transport, GetEncryptAddr(address).c_str(), passkey, accept);
1651 if (PermissionUtils::VerifyManageBluetoothPermission() == PERMISSION_DENIED) {
1652 HILOGE("false, check permission failed");
1653 return false;
1654 }
1655 auto classicService = IAdapterManager::GetInstance()->GetClassicAdapterInterface();
1656 auto bleService = IAdapterManager::GetInstance()->GetBleAdapterInterface();
1657 RawAddress addr(address);
1658 if ((transport == BT_TRANSPORT_BREDR) && IsBtEnabled() && classicService) {
1659 return classicService->SetDevicePasskey(addr, passkey, accept);
1660 } else if ((transport == BT_TRANSPORT_BLE) && IsBleEnabled() && bleService) {
1661 return bleService->SetDevicePasskey(addr, passkey, accept);
1662 } else {
1663 HILOGE("transport invalid or BT current state is not enabled!");
1664 }
1665 return false;
1666 }
1667
PairRequestReply(int32_t transport,const std::string & address,bool accept)1668 bool BluetoothHostServer::PairRequestReply(int32_t transport, const std::string &address, bool accept)
1669 {
1670 HILOGI("transport: %{public}d, address: %{public}s, accept: %{public}d",
1671 transport, GetEncryptAddr(address).c_str(), accept);
1672 auto classicService = IAdapterManager::GetInstance()->GetClassicAdapterInterface();
1673 auto bleService = IAdapterManager::GetInstance()->GetBleAdapterInterface();
1674 RawAddress addr(address);
1675 if ((transport == BT_TRANSPORT_BREDR) && IsBtEnabled() && classicService) {
1676 return classicService->PairRequestReply(addr, accept);
1677 } else if ((transport == BT_TRANSPORT_BLE) && IsBleEnabled() && bleService) {
1678 return bleService->PairRequestReply(addr, accept);
1679 } else {
1680 HILOGE("transport invalid or BT current state is not enabled!");
1681 }
1682 return false;
1683 }
1684
ReadRemoteRssiValue(const std::string & address)1685 bool BluetoothHostServer::ReadRemoteRssiValue(const std::string &address)
1686 {
1687 HILOGI("address: %{public}s", GetEncryptAddr(address).c_str());
1688 if (PermissionUtils::VerifyUseBluetoothPermission() == PERMISSION_DENIED) {
1689 HILOGE("false, check permission failed");
1690 return false;
1691 }
1692 auto bleService = IAdapterManager::GetInstance()->GetBleAdapterInterface();
1693 if (IsBleEnabled() && bleService) {
1694 RawAddress addr(address);
1695 return bleService->ReadRemoteRssiValue(addr);
1696 } else {
1697 HILOGE("BT current state is not enabled!");
1698 }
1699 return false;
1700 }
1701
RegisterRemoteDeviceObserver(const sptr<IBluetoothRemoteDeviceObserver> & observer)1702 void BluetoothHostServer::RegisterRemoteDeviceObserver(const sptr<IBluetoothRemoteDeviceObserver> &observer)
1703 {
1704 HILOGI("Enter!");
1705 if (observer == nullptr) {
1706 HILOGE("observer is nullptr!");
1707 return;
1708 }
1709 pimpl->remoteObserversToken_.EnsureInsert(observer->AsObject(), IPCSkeleton::GetCallingTokenID());
1710 pimpl->remoteObserversPid_.EnsureInsert(observer->AsObject(), IPCSkeleton::GetCallingUid());
1711 auto func = std::bind(&BluetoothHostServer::DeregisterRemoteDeviceObserver,
1712 this, std::placeholders::_1);
1713 pimpl->remoteObservers_.Register(observer, func);
1714 std::lock_guard<std::mutex> lock(pimpl->remoteDeviceObserversMutex);
1715 pimpl->remoteDeviceObservers_.push_back(observer);
1716 }
1717
DeregisterRemoteDeviceObserver(const sptr<IBluetoothRemoteDeviceObserver> & observer)1718 void BluetoothHostServer::DeregisterRemoteDeviceObserver(const sptr<IBluetoothRemoteDeviceObserver> &observer)
1719 {
1720 HILOGI("Enter!");
1721 if (observer == nullptr || pimpl == nullptr) {
1722 HILOGE("observer is nullptr!");
1723 return;
1724 }
1725 {
1726 std::lock_guard<std::mutex> lock(pimpl->remoteDeviceObserversMutex);
1727 for (auto iter = pimpl->remoteDeviceObservers_.begin(); iter != pimpl->remoteDeviceObservers_.end(); ++iter) {
1728 if ((*iter)->AsObject() == observer->AsObject()) {
1729 pimpl->remoteObservers_.Deregister(*iter);
1730 pimpl->remoteDeviceObservers_.erase(iter);
1731 break;
1732 }
1733 }
1734 }
1735 pimpl->remoteObserversToken_.Erase(observer->AsObject());
1736 pimpl->remoteObserversPid_.Erase(observer->AsObject());
1737 }
1738
IsBtEnabled()1739 bool BluetoothHostServer::IsBtEnabled()
1740 {
1741 int32_t state = static_cast<int32_t>(BluetoothState::STATE_OFF);
1742 GetBtState(state);
1743 bool isEnabled = (state == static_cast<int32_t>(BluetoothState::STATE_ON)) ? true : false;
1744 HILOGI("%{public}s", isEnabled ? "true" : "false");
1745 return isEnabled;
1746 }
1747
RegisterBleAdapterObserver(const sptr<IBluetoothHostObserver> & observer)1748 void BluetoothHostServer::RegisterBleAdapterObserver(const sptr<IBluetoothHostObserver> &observer)
1749 {
1750 HILOGI("start.");
1751 if (observer == nullptr) {
1752 HILOGE("observer is nullptr!");
1753 return;
1754 }
1755 pimpl->bleObserversToken_.EnsureInsert(observer->AsObject(), IPCSkeleton::GetCallingTokenID());
1756 pimpl->bleObserversPid_.EnsureInsert(observer->AsObject(), IPCSkeleton::GetCallingUid());
1757 auto func = std::bind(&BluetoothHostServer::DeregisterBleAdapterObserver, this, std::placeholders::_1);
1758 pimpl->bleObservers_.Register(observer, func);
1759 std::lock_guard<std::mutex> lock(pimpl->bleAdapterObserversMutex);
1760 pimpl->bleAdapterObservers_.push_back(observer);
1761 }
1762
DeregisterBleAdapterObserver(const sptr<IBluetoothHostObserver> & observer)1763 void BluetoothHostServer::DeregisterBleAdapterObserver(const sptr<IBluetoothHostObserver> &observer)
1764 {
1765 HILOGI("start.");
1766 if (observer == nullptr || pimpl == nullptr) {
1767 HILOGE("observer is nullptr!");
1768 return;
1769 }
1770 {
1771 std::lock_guard<std::mutex> lock(pimpl->bleAdapterObserversMutex);
1772 for (auto iter = pimpl->bleAdapterObservers_.begin(); iter != pimpl->bleAdapterObservers_.end(); ++iter) {
1773 if ((*iter)->AsObject() == observer->AsObject()) {
1774 pimpl->bleObservers_.Deregister(*iter);
1775 pimpl->bleAdapterObservers_.erase(iter);
1776 break;
1777 }
1778 }
1779 }
1780 pimpl->bleObserversToken_.Erase(observer->AsObject());
1781 pimpl->bleObserversPid_.Erase(observer->AsObject());
1782 }
1783
RegisterBlePeripheralCallback(const sptr<IBluetoothBlePeripheralObserver> & observer)1784 void BluetoothHostServer::RegisterBlePeripheralCallback(const sptr<IBluetoothBlePeripheralObserver> &observer)
1785 {
1786 HILOGI("start.");
1787 if (observer == nullptr) {
1788 HILOGE("observer is nullptr!");
1789 return;
1790 }
1791 pimpl->bleRemoteObserversToken_.EnsureInsert(observer->AsObject(), IPCSkeleton::GetCallingTokenID());
1792 auto func = std::bind(&BluetoothHostServer::DeregisterBlePeripheralCallback, this, std::placeholders::_1);
1793 pimpl->bleRemoteObservers_.Register(observer, func);
1794 std::lock_guard<std::mutex> lock(pimpl->blePeripheralObserversMutex);
1795 pimpl->blePeripheralObservers_.push_back(observer);
1796 }
1797
DeregisterBlePeripheralCallback(const sptr<IBluetoothBlePeripheralObserver> & observer)1798 void BluetoothHostServer::DeregisterBlePeripheralCallback(const sptr<IBluetoothBlePeripheralObserver> &observer)
1799 {
1800 HILOGI("start.");
1801 if (observer == nullptr) {
1802 HILOGE("observer is nullptr!");
1803 return;
1804 }
1805 {
1806 std::lock_guard<std::mutex> lock(pimpl->blePeripheralObserversMutex);
1807 for (auto iter = pimpl->blePeripheralObservers_.begin(); iter != pimpl->blePeripheralObservers_.end(); ++iter) {
1808 if ((*iter)->AsObject() == observer->AsObject()) {
1809 if (pimpl != nullptr) {
1810 pimpl->bleRemoteObservers_.Deregister(*iter);
1811 pimpl->blePeripheralObservers_.erase(iter);
1812 break;
1813 }
1814 }
1815 }
1816 }
1817 pimpl->bleRemoteObserversToken_.Erase(observer->AsObject());
1818 }
1819
Dump(int32_t fd,const std::vector<std::u16string> & args)1820 int32_t BluetoothHostServer::Dump(int32_t fd, const std::vector<std::u16string> &args)
1821 {
1822 HILOGI("fd: %{public}d", fd);
1823 std::vector<std::string> argsInStr8;
1824 std::transform(args.begin(), args.end(), std::back_inserter(argsInStr8), [](const std::u16string &arg) {
1825 return Str16ToStr8(arg);
1826 });
1827
1828 std::string result;
1829 BluetoothHostDumper::BluetoothDump(argsInStr8, result);
1830
1831 if (!SaveStringToFd(fd, result)) {
1832 HILOGE("bluetooth dump save string to fd failed!");
1833 return ERR_INVALID_OPERATION;
1834 }
1835 return ERR_OK;
1836 }
1837
SetFastScan(bool isEnable)1838 int32_t BluetoothHostServer::SetFastScan(bool isEnable)
1839 {
1840 return NO_ERROR;
1841 }
1842
GetRandomAddress(const std::string & realAddr,std::string & randomAddr,uint64_t tokenId)1843 int32_t BluetoothHostServer::GetRandomAddress(const std::string &realAddr, std::string &randomAddr, uint64_t tokenId)
1844 {
1845 return BT_ERR_API_NOT_SUPPORT;
1846 }
1847
SyncRandomAddress(const std::string & realAddr,const std::string & randomAddr)1848 int32_t BluetoothHostServer::SyncRandomAddress(const std::string &realAddr, const std::string &randomAddr)
1849 {
1850 return NO_ERROR;
1851 }
1852
StartCrediblePair(int32_t transport,const std::string & address)1853 int32_t BluetoothHostServer::StartCrediblePair(int32_t transport, const std::string &address)
1854 {
1855 if (!PermissionUtils::CheckSystemHapApp()) {
1856 HILOGE("check system api failed.");
1857 return BT_ERR_SYSTEM_PERMISSION_FAILED;
1858 }
1859 return NO_ERROR;
1860 }
1861
SatelliteControl(int type,int state)1862 int32_t BluetoothHostServer::SatelliteControl(int type, int state)
1863 {
1864 return BT_ERR_API_NOT_SUPPORT;
1865 }
1866
ConnectAllowedProfiles(const std::string & address)1867 int32_t BluetoothHostServer::ConnectAllowedProfiles(const std::string &address)
1868 {
1869 return BT_ERR_API_NOT_SUPPORT;
1870 }
1871
DisconnectAllowedProfiles(const std::string & address)1872 int32_t BluetoothHostServer::DisconnectAllowedProfiles(const std::string &address)
1873 {
1874 return BT_ERR_API_NOT_SUPPORT;
1875 }
1876
SetDeviceCustomType(const std::string & address,int32_t deviceType)1877 int32_t BluetoothHostServer::SetDeviceCustomType(const std::string &address, int32_t deviceType)
1878 {
1879 return BT_ERR_API_NOT_SUPPORT;
1880 }
1881
GetRemoteDeviceInfo(const std::string & address,std::shared_ptr<BluetoothRemoteDeviceInfo> & deviceInfo,int type)1882 int32_t BluetoothHostServer::GetRemoteDeviceInfo(const std::string &address,
1883 std::shared_ptr<BluetoothRemoteDeviceInfo> &deviceInfo, int type)
1884 {
1885 return BT_ERR_API_NOT_SUPPORT;
1886 }
1887
RegisterBtResourceManagerObserver(const sptr<IBluetoothResourceManagerObserver> & observer)1888 void BluetoothHostServer::RegisterBtResourceManagerObserver(const sptr<IBluetoothResourceManagerObserver> &observer)
1889 {}
1890
DeregisterBtResourceManagerObserver(const sptr<IBluetoothResourceManagerObserver> & observer)1891 void BluetoothHostServer::DeregisterBtResourceManagerObserver(const sptr<IBluetoothResourceManagerObserver> &observer)
1892 {}
1893
UpdateVirtualDevice(int32_t action,const std::string & address)1894 void BluetoothHostServer::UpdateVirtualDevice(int32_t action, const std::string &address)
1895 {}
1896
IsSupportVirtualAutoConnect(const std::string & address,bool & outSupport)1897 int32_t BluetoothHostServer::IsSupportVirtualAutoConnect(const std::string &address, bool &outSupport)
1898 {
1899 outSupport = false;
1900 return BT_ERR_API_NOT_SUPPORT;
1901 }
1902
SetVirtualAutoConnectType(const std::string & address,int connType,int businessType)1903 int32_t BluetoothHostServer::SetVirtualAutoConnectType(const std::string &address, int connType, int businessType)
1904 {
1905 return BT_ERR_API_NOT_SUPPORT;
1906 }
1907
SetFastScanLevel(int level)1908 int32_t BluetoothHostServer::SetFastScanLevel(int level)
1909 {
1910 return BT_ERR_API_NOT_SUPPORT;
1911 }
1912
EnableBluetoothToRestrictMode(void)1913 int32_t BluetoothHostServer::EnableBluetoothToRestrictMode(void)
1914 {
1915 return BT_ERR_API_NOT_SUPPORT;
1916 }
1917
ControlDeviceAction(const std::string & deviceId,uint32_t controlType,uint32_t controlTypeVal,uint32_t controlObject)1918 int32_t BluetoothHostServer::ControlDeviceAction(const std::string &deviceId, uint32_t controlType,
1919 uint32_t controlTypeVal, uint32_t controlObject)
1920 {
1921 return BT_ERR_API_NOT_SUPPORT;
1922 }
1923
GetLastConnectionTime(const std::string & address,int64_t & connectionTime)1924 int32_t BluetoothHostServer::GetLastConnectionTime(const std::string &address, int64_t &connectionTime)
1925 {
1926 return BT_ERR_API_NOT_SUPPORT;
1927 }
1928
UpdateCloudBluetoothDevice(std::vector<BluetoothTrustPairDevice> & cloudDevices)1929 int32_t BluetoothHostServer::UpdateCloudBluetoothDevice(std::vector<BluetoothTrustPairDevice> &cloudDevices)
1930 {
1931 return BT_ERR_API_NOT_SUPPORT;
1932 }
1933
GetCloudBondState(const std::string & address,int32_t & cloudBondState)1934 int32_t BluetoothHostServer::GetCloudBondState(const std::string &address, int32_t &cloudBondState)
1935 {
1936 return BT_ERR_API_NOT_SUPPORT;
1937 }
1938
GetDeviceTransport(const std::string & address,int32_t & transport)1939 int32_t BluetoothHostServer::GetDeviceTransport(const std::string &address, int32_t &transport)
1940 {
1941 return BT_ERR_API_NOT_SUPPORT;
1942 }
1943
UpdateRefusePolicy(const int32_t protocolType,const int32_t pid,const int64_t prohibitedSecondsTime)1944 int32_t BluetoothHostServer::UpdateRefusePolicy(const int32_t protocolType,
1945 const int32_t pid, const int64_t prohibitedSecondsTime)
1946 {
1947 return BT_ERR_API_NOT_SUPPORT;
1948 }
1949
ProcessRandomDeviceIdCommand(int32_t command,std::vector<std::string> & deviceIdVec,bool & isValid)1950 int32_t BluetoothHostServer::ProcessRandomDeviceIdCommand(
1951 int32_t command, std::vector<std::string> &deviceIdVec, bool &isValid)
1952 {
1953 return BT_ERR_API_NOT_SUPPORT;
1954 }
1955
GetCarKeyDfxData(std::string & dfxData)1956 int32_t BluetoothHostServer::GetCarKeyDfxData(std::string &dfxData)
1957 {
1958 return BT_ERR_API_NOT_SUPPORT;
1959 }
1960
SetCarKeyCardData(const std::string & address,int32_t action)1961 int32_t BluetoothHostServer::SetCarKeyCardData(const std::string &address, int32_t action)
1962 {
1963 return BT_ERR_API_NOT_SUPPORT;
1964 }
1965
NotifyDialogResult(uint32_t dialogType,bool dialogResult)1966 int32_t BluetoothHostServer::NotifyDialogResult(uint32_t dialogType, bool dialogResult)
1967 {
1968 return BT_ERR_API_NOT_SUPPORT;
1969 }
1970
SetCallingPackageName(const std::string & address,const std::string & packageName)1971 void BluetoothHostServer::SetCallingPackageName(const std::string &address, const std::string &packageName)
1972 {}
1973 } // namespace Bluetooth
1974 } // namespace OHOS
1975