1 /*
2 * Copyright (C) 2021-2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "bluetooth_hfp_ag.h"
17 #include <unistd.h>
18 #include "bluetooth_device.h"
19 #include "bluetooth_errorcode.h"
20 #include "bluetooth_host.h"
21 #include "bluetooth_log.h"
22 #include "bluetooth_utils.h"
23 #include "bluetooth_observer_list.h"
24 #include "i_bluetooth_hfp_ag.h"
25 #include "bluetooth_hfp_ag_observer_stub.h"
26 #include "i_bluetooth_host.h"
27 #include "iservice_registry.h"
28 #include "system_ability_definition.h"
29
30 namespace OHOS {
31 namespace Bluetooth {
32 class AgServiceObserver : public BluetoothHfpAgObserverStub {
33 public:
AgServiceObserver(BluetoothObserverList<HandsFreeAudioGatewayObserver> & observers)34 explicit AgServiceObserver(BluetoothObserverList<HandsFreeAudioGatewayObserver> &observers) : observers_(observers)
35 {
36 HILOGI("enter");
37 }
~AgServiceObserver()38 ~AgServiceObserver() override
39 {
40 HILOGI("enter");
41 };
42
OnConnectionStateChanged(const BluetoothRawAddress & device,int32_t state)43 void OnConnectionStateChanged(const BluetoothRawAddress &device, int32_t state) override
44 {
45 HILOGI("hfpAg conn state, device: %{public}s, state: %{public}s",
46 GetEncryptAddr((device).GetAddress()).c_str(), GetProfileConnStateName(state).c_str());
47 BluetoothRemoteDevice remoteDevice(device.GetAddress(), 0);
48 observers_.ForEach([remoteDevice, state](std::shared_ptr<HandsFreeAudioGatewayObserver> observer) {
49 observer->OnConnectionStateChanged(remoteDevice, state);
50 });
51 }
52
OnScoStateChanged(const BluetoothRawAddress & device,int32_t state)53 void OnScoStateChanged(const BluetoothRawAddress &device, int32_t state) override
54 {
55 HILOGI("enter, device: %{public}s, state: %{public}d", GetEncryptAddr((device).GetAddress()).c_str(), state);
56 BluetoothRemoteDevice remoteDevice(device.GetAddress(), 0);
57 observers_.ForEach([remoteDevice, state](std::shared_ptr<HandsFreeAudioGatewayObserver> observer) {
58 observer->OnScoStateChanged(remoteDevice, state);
59 });
60 }
61
OnActiveDeviceChanged(const BluetoothRawAddress & device)62 void OnActiveDeviceChanged(const BluetoothRawAddress &device) override
63 {
64 HILOGI("enter, device: %{public}s", GetEncryptAddr((device).GetAddress()).c_str());
65 BluetoothRemoteDevice remoteDevice(device.GetAddress(), 0);
66 observers_.ForEach([remoteDevice](std::shared_ptr<HandsFreeAudioGatewayObserver> observer) {
67 observer->OnActiveDeviceChanged(remoteDevice);
68 });
69 }
70
OnHfEnhancedDriverSafetyChanged(const BluetoothRawAddress & device,int32_t indValue)71 void OnHfEnhancedDriverSafetyChanged(
72 const BluetoothRawAddress &device, int32_t indValue) override
73 {
74 HILOGI("enter, device: %{public}s, indValue: %{public}d",
75 GetEncryptAddr((device).GetAddress()).c_str(), indValue);
76 BluetoothRemoteDevice remoteDevice(device.GetAddress(), 0);
77 observers_.ForEach([remoteDevice, indValue](std::shared_ptr<HandsFreeAudioGatewayObserver> observer) {
78 observer->OnHfEnhancedDriverSafetyChanged(remoteDevice, indValue);
79 });
80 }
81
82 private:
83 BluetoothObserverList<HandsFreeAudioGatewayObserver> &observers_;
84 BLUETOOTH_DISALLOW_COPY_AND_ASSIGN(AgServiceObserver);
85 };
86
87 std::string HfpAgServiceName = "bluetooth-hfp-ag-server";
88
89 struct HandsFreeAudioGateway::impl {
90 impl();
91 ~impl();
GetConnectedDevicesOHOS::Bluetooth::HandsFreeAudioGateway::impl92 int32_t GetConnectedDevices(std::vector<BluetoothRemoteDevice>& devices)
93 {
94 HILOGI("enter");
95 if (!proxy_) {
96 HILOGE("proxy_ is nullptr.");
97 return BT_ERR_SERVICE_DISCONNECTED;
98 }
99 if (!IS_BT_ENABLED()) {
100 HILOGE("bluetooth is off.");
101 return BT_ERR_INVALID_STATE;
102 }
103 std::vector<BluetoothRawAddress> ori;
104 int32_t ret = proxy_->GetConnectDevices(ori);
105 if (ret != BT_SUCCESS) {
106 HILOGE("inner error.");
107 return ret;
108 }
109 for (auto it = ori.begin(); it != ori.end(); it++) {
110 devices.push_back(BluetoothRemoteDevice(it->GetAddress(), 0));
111 }
112 return BT_SUCCESS;
113 }
114
GetDevicesByStatesOHOS::Bluetooth::HandsFreeAudioGateway::impl115 std::vector<BluetoothRemoteDevice> GetDevicesByStates(std::vector<int> states)
116 {
117 HILOGI("enter");
118 std::vector<BluetoothRemoteDevice> remoteDevices;
119 if (proxy_ != nullptr && IS_BT_ENABLED()) {
120 std::vector<BluetoothRawAddress> rawDevices;
121 std::vector<int32_t> tmpstates;
122 for (int state : states) {
123 int32_t value = (int32_t)state;
124 tmpstates.push_back(value);
125 }
126 proxy_->GetDevicesByStates(tmpstates, rawDevices);
127 for (BluetoothRawAddress rawDevice : rawDevices) {
128 BluetoothRemoteDevice remoteDevice(rawDevice.GetAddress(), 0);
129 remoteDevices.push_back(remoteDevice);
130 }
131 }
132 return remoteDevices;
133 }
134
GetDeviceStateOHOS::Bluetooth::HandsFreeAudioGateway::impl135 int32_t GetDeviceState(const BluetoothRemoteDevice &device, int32_t &state)
136 {
137 HILOGI("enter, device: %{public}s", GET_ENCRYPT_ADDR(device));
138
139 if (proxy_ == nullptr || !device.IsValidBluetoothRemoteDevice()) {
140 HILOGE("invalid param.");
141 return BT_ERR_INVALID_PARAM;
142 }
143 if (!IS_BT_ENABLED()) {
144 HILOGE("bluetooth is off.");
145 return BT_ERR_INVALID_STATE;
146 }
147
148 return proxy_->GetDeviceState(BluetoothRawAddress(device.GetDeviceAddr()), state);
149 }
150
ConnectOHOS::Bluetooth::HandsFreeAudioGateway::impl151 int32_t Connect(const BluetoothRemoteDevice &device)
152 {
153 HILOGI("hfp connect remote device: %{public}s", GET_ENCRYPT_ADDR(device));
154 if (proxy_ == nullptr || !device.IsValidBluetoothRemoteDevice()) {
155 HILOGE("invalid param.");
156 return BT_ERR_INVALID_PARAM;
157 }
158 if (!IS_BT_ENABLED()) {
159 HILOGE("Not IS_BT_ENABLED");
160 return BT_ERR_INVALID_STATE;
161 }
162
163 int cod = 0;
164 int32_t err = device.GetDeviceClass(cod);
165 if (err != BT_SUCCESS) {
166 HILOGE("GetDeviceClass Failed.");
167 return BT_ERR_INVALID_PARAM;
168 }
169 BluetoothDeviceClass devClass = BluetoothDeviceClass(cod);
170 if (!devClass.IsProfileSupported(BluetoothDevice::PROFILE_HEADSET)) {
171 HILOGE("hfp connect failed. The remote device does not support HFP service.");
172 return BT_ERR_PROFILE_DISABLED;
173 }
174 return proxy_->Connect(BluetoothRawAddress(device.GetDeviceAddr()));
175 }
176
DisconnectOHOS::Bluetooth::HandsFreeAudioGateway::impl177 int32_t Disconnect(const BluetoothRemoteDevice &device)
178 {
179 HILOGI("hfp disconnect remote device: %{public}s", GET_ENCRYPT_ADDR(device));
180
181 if (proxy_ == nullptr || !device.IsValidBluetoothRemoteDevice()) {
182 HILOGE("invalid param.");
183 return BT_ERR_INVALID_PARAM;
184 }
185 if (!IS_BT_ENABLED()) {
186 HILOGE("bluetooth is off.");
187 return BT_ERR_INVALID_STATE;
188 }
189 return proxy_->Disconnect(BluetoothRawAddress(device.GetDeviceAddr()));
190 }
191
GetScoStateOHOS::Bluetooth::HandsFreeAudioGateway::impl192 int GetScoState(const BluetoothRemoteDevice &device)
193 {
194 HILOGI("enter, device: %{public}s", GET_ENCRYPT_ADDR(device));
195 if (proxy_ != nullptr && IS_BT_ENABLED() && device.IsValidBluetoothRemoteDevice()) {
196 return proxy_->GetScoState(BluetoothRawAddress(device.GetDeviceAddr()));
197 }
198 return HFP_AG_SCO_STATE_DISCONNECTED;
199 }
200
ConnectScoOHOS::Bluetooth::HandsFreeAudioGateway::impl201 bool ConnectSco()
202 {
203 HILOGI("enter");
204 if (proxy_ != nullptr && IS_BT_ENABLED()) {
205 return proxy_->ConnectSco();
206 }
207 return false;
208 }
209
DisconnectScoOHOS::Bluetooth::HandsFreeAudioGateway::impl210 bool DisconnectSco()
211 {
212 HILOGI("enter");
213 if (proxy_ != nullptr && IS_BT_ENABLED()) {
214 return proxy_->DisconnectSco();
215 }
216 return false;
217 }
218
PhoneStateChangedOHOS::Bluetooth::HandsFreeAudioGateway::impl219 void PhoneStateChanged(
220 int numActive, int numHeld, int callState, const std::string &number, int type, const std::string &name)
221 {
222 HILOGI("numActive: %{public}d, numHeld: %{public}d, callState: %{public}d, type: %{public}d",
223 numActive, numHeld, callState, type);
224 if (proxy_ != nullptr && IS_BT_ENABLED()) {
225 proxy_->PhoneStateChanged(numActive, numHeld, callState, number, type, name);
226 }
227 }
228
ClccResponseOHOS::Bluetooth::HandsFreeAudioGateway::impl229 void ClccResponse(int index, int direction, int status, int mode, bool mpty, std::string number, int type)
230 {
231 HILOGI("enter, index: %{public}d, direction: %{public}d, status: %{public}d, mode: %{public}d, mpty: "
232 "%{public}d, type: %{public}d", index, direction, status, mode, mpty, type);
233 if (proxy_ != nullptr && IS_BT_ENABLED()) {
234 proxy_->ClccResponse(index, direction, status, mode, mpty, number, type);
235 }
236 }
237
OpenVoiceRecognitionOHOS::Bluetooth::HandsFreeAudioGateway::impl238 bool OpenVoiceRecognition(const BluetoothRemoteDevice &device)
239 {
240 HILOGI("enter, device: %{public}s", GET_ENCRYPT_ADDR(device));
241 if (proxy_ != nullptr && IS_BT_ENABLED() && device.IsValidBluetoothRemoteDevice()) {
242 return proxy_->OpenVoiceRecognition(BluetoothRawAddress(device.GetDeviceAddr()));
243 }
244 return false;
245 }
246
CloseVoiceRecognitionOHOS::Bluetooth::HandsFreeAudioGateway::impl247 bool CloseVoiceRecognition(const BluetoothRemoteDevice &device)
248 {
249 HILOGI("enter, device: %{public}s", GET_ENCRYPT_ADDR(device));
250 if (proxy_ != nullptr && IS_BT_ENABLED() && device.IsValidBluetoothRemoteDevice()) {
251 return proxy_->CloseVoiceRecognition(BluetoothRawAddress(device.GetDeviceAddr()));
252 }
253 return false;
254 }
255
SetActiveDeviceOHOS::Bluetooth::HandsFreeAudioGateway::impl256 bool SetActiveDevice(const BluetoothRemoteDevice &device)
257 {
258 HILOGI("enter, device: %{public}s", GET_ENCRYPT_ADDR(device));
259 if (proxy_ != nullptr && IS_BT_ENABLED() && device.IsValidBluetoothRemoteDevice()) {
260 return proxy_->SetActiveDevice(BluetoothRawAddress(device.GetDeviceAddr()));
261 }
262 return false;
263 }
264
IntoMockOHOS::Bluetooth::HandsFreeAudioGateway::impl265 bool IntoMock(const BluetoothRemoteDevice &device, int state)
266 {
267 HILOGI("enter");
268 if (proxy_ != nullptr && IS_BT_ENABLED()) {
269 return proxy_->IntoMock(device.GetDeviceAddr(), state);
270 }
271 return false;
272 }
273
SendNoCarrierOHOS::Bluetooth::HandsFreeAudioGateway::impl274 bool SendNoCarrier(const BluetoothRemoteDevice &device)
275 {
276 HILOGI("enter");
277 if (proxy_ != nullptr && IS_BT_ENABLED() && device.IsValidBluetoothRemoteDevice()) {
278 return proxy_->SendNoCarrier(BluetoothRawAddress(device.GetDeviceAddr()));
279 }
280 return false;
281 }
282
GetActiveDeviceOHOS::Bluetooth::HandsFreeAudioGateway::impl283 BluetoothRemoteDevice GetActiveDevice()
284 {
285 HILOGI("enter");
286 BluetoothRemoteDevice device;
287 if (proxy_ != nullptr && IS_BT_ENABLED()) {
288 std::string address = proxy_->GetActiveDevice();
289 BluetoothRemoteDevice remoteDevice(address, 0);
290 device = remoteDevice;
291 }
292 return device;
293 }
294
RegisterObserverOHOS::Bluetooth::HandsFreeAudioGateway::impl295 void RegisterObserver(std::shared_ptr<HandsFreeAudioGatewayObserver> observer)
296 {
297 HILOGI("enter");
298 observers_.Register(observer);
299 }
300
DeregisterObserverOHOS::Bluetooth::HandsFreeAudioGateway::impl301 void DeregisterObserver(std::shared_ptr<HandsFreeAudioGatewayObserver> observer)
302 {
303 HILOGI("enter");
304 observers_.Deregister(observer);
305 HILOGI("end");
306 }
307
308 private:
309 const static int HFP_AG_SLC_STATE_DISCONNECTED = (int)BTConnectState::DISCONNECTED;
310 const static int HFP_AG_SCO_STATE_DISCONNECTED = 3;
311
312 BluetoothObserverList<HandsFreeAudioGatewayObserver> observers_;
313 sptr<AgServiceObserver> serviceObserver_;
314 sptr<IBluetoothHfpAg> proxy_;
315 class HandsFreeAudioGatewayDeathRecipient;
316 sptr<HandsFreeAudioGatewayDeathRecipient> deathRecipient_;
317
GetHfpAgProxyOHOS::Bluetooth::HandsFreeAudioGateway::impl318 void GetHfpAgProxy()
319 {
320 sptr<ISystemAbilityManager> samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
321 if (samgr == nullptr) {
322 HILOGE("error: no samgr");
323 return;
324 }
325
326 sptr<IRemoteObject> hostRemote = samgr->GetSystemAbility(BLUETOOTH_HOST_SYS_ABILITY_ID);
327 if (hostRemote == nullptr) {
328 HILOGE("failed: no hostRemote");
329 return;
330 }
331
332 sptr<IBluetoothHost> hostProxy = iface_cast<IBluetoothHost>(hostRemote);
333 if (hostProxy == nullptr) {
334 HILOGE("error: host no proxy");
335 return;
336 }
337
338 sptr<IRemoteObject> remote = hostProxy->GetProfile(PROFILE_HFP_AG);
339 if (remote == nullptr) {
340 HILOGE("failed: no remote");
341 return;
342 }
343
344 proxy_ = iface_cast<IBluetoothHfpAg>(remote);
345 if (proxy_ == nullptr) {
346 HILOGE("error: no proxy");
347 return;
348 }
349 }
350 };
351
352 class HandsFreeAudioGateway::impl::HandsFreeAudioGatewayDeathRecipient final : public IRemoteObject::DeathRecipient {
353 public:
HandsFreeAudioGatewayDeathRecipient(HandsFreeAudioGateway::impl & impl)354 HandsFreeAudioGatewayDeathRecipient(HandsFreeAudioGateway::impl &impl) : impl_(impl)
355 {};
356 ~HandsFreeAudioGatewayDeathRecipient() final = default;
357 BLUETOOTH_DISALLOW_COPY_AND_ASSIGN(HandsFreeAudioGatewayDeathRecipient);
358
OnRemoteDied(const wptr<IRemoteObject> & remote)359 void OnRemoteDied(const wptr<IRemoteObject> &remote) final
360 {
361 HILOGI("starts");
362 impl_.proxy_->AsObject()->RemoveDeathRecipient(impl_.deathRecipient_);
363 impl_.proxy_ = nullptr;
364
365 // Re-obtain the proxy and register the observer.
366 sleep(GET_PROXY_SLEEP_SEC);
367 impl_.GetHfpAgProxy();
368 if (impl_.proxy_ == nullptr) {
369 HILOGE("proxy reset failed");
370 return;
371 }
372 if (impl_.serviceObserver_ == nullptr || impl_.deathRecipient_ == nullptr) {
373 HILOGE("serviceObserver_ or deathRecipient_ is null");
374 return;
375 }
376 impl_.proxy_->RegisterObserver(impl_.serviceObserver_);
377 impl_.proxy_->AsObject()->AddDeathRecipient(impl_.deathRecipient_);
378 }
379
380 private:
381 HandsFreeAudioGateway::impl &impl_;
382 };
383
impl()384 HandsFreeAudioGateway::impl::impl()
385 {
386 HILOGI("start");
387 GetHfpAgProxy();
388 if (proxy_ == nullptr) {
389 HILOGE("get proxy_ failed");
390 return;
391 }
392 serviceObserver_ = new AgServiceObserver(observers_);
393 if (serviceObserver_ == nullptr) {
394 HILOGE("serviceObserver_ is null");
395 return;
396 }
397 proxy_->RegisterObserver(serviceObserver_);
398
399 deathRecipient_ = new HandsFreeAudioGatewayDeathRecipient(*this);
400 if (deathRecipient_ == nullptr) {
401 HILOGE("deathRecipient_ is null");
402 return;
403 }
404 proxy_->AsObject()->AddDeathRecipient(deathRecipient_);
405 }
406
~impl()407 HandsFreeAudioGateway::impl::~impl()
408 {
409 HILOGI("enter");
410 if (proxy_ == nullptr) {
411 return;
412 }
413 proxy_->DeregisterObserver(serviceObserver_);
414 proxy_->AsObject()->RemoveDeathRecipient(deathRecipient_);
415 }
416
GetProfile()417 HandsFreeAudioGateway *HandsFreeAudioGateway::GetProfile()
418 {
419 HILOGI("enter");
420 static HandsFreeAudioGateway instance;
421 return &instance;
422 }
423
HandsFreeAudioGateway()424 HandsFreeAudioGateway::HandsFreeAudioGateway()
425 {
426 HILOGI("enter");
427 pimpl = std::make_unique<impl>();
428 }
429
~HandsFreeAudioGateway()430 HandsFreeAudioGateway::~HandsFreeAudioGateway()
431 {
432 HILOGI("enter");
433 }
434
GetConnectedDevices() const435 std::vector<BluetoothRemoteDevice> HandsFreeAudioGateway::GetConnectedDevices() const
436 {
437 std::vector<BluetoothRemoteDevice> devices;
438 pimpl->GetConnectedDevices(devices);
439 return devices;
440 }
441
GetConnectedDevices(std::vector<BluetoothRemoteDevice> & devices)442 int32_t HandsFreeAudioGateway::GetConnectedDevices(std::vector<BluetoothRemoteDevice> &devices)
443 {
444 HILOGI("enter");
445 return pimpl->GetConnectedDevices(devices);
446 }
447
GetDevicesByStates(std::vector<int> states)448 std::vector<BluetoothRemoteDevice> HandsFreeAudioGateway::GetDevicesByStates(std::vector<int> states)
449 {
450 HILOGI("enter");
451 return pimpl->GetDevicesByStates(states);
452 }
453
GetDeviceState(const BluetoothRemoteDevice & device,int32_t & state)454 int32_t HandsFreeAudioGateway::GetDeviceState(const BluetoothRemoteDevice &device, int32_t &state)
455 {
456 HILOGI("enter, device: %{public}s", GET_ENCRYPT_ADDR(device));
457 return pimpl->GetDeviceState(device, state);
458 }
459
Connect(const BluetoothRemoteDevice & device)460 int32_t HandsFreeAudioGateway::Connect(const BluetoothRemoteDevice &device)
461 {
462 HILOGI("enter, device: %{public}s", GET_ENCRYPT_ADDR(device));
463 return pimpl->Connect(device);
464 }
465
Disconnect(const BluetoothRemoteDevice & device)466 int32_t HandsFreeAudioGateway::Disconnect(const BluetoothRemoteDevice &device)
467 {
468 HILOGI("enter, device: %{public}s", GET_ENCRYPT_ADDR(device));
469 return pimpl->Disconnect(device);
470 }
471
GetScoState(const BluetoothRemoteDevice & device) const472 int HandsFreeAudioGateway::GetScoState(const BluetoothRemoteDevice &device) const
473 {
474 HILOGI("enter, device: %{public}s", GET_ENCRYPT_ADDR(device));
475 return pimpl->GetScoState(device);
476 }
477
ConnectSco()478 bool HandsFreeAudioGateway::ConnectSco()
479 {
480 HILOGI("enter");
481 return pimpl->ConnectSco();
482 }
483
DisconnectSco()484 bool HandsFreeAudioGateway::DisconnectSco()
485 {
486 HILOGI("enter");
487 return pimpl->DisconnectSco();
488 }
489
PhoneStateChanged(int numActive,int numHeld,int callState,const std::string & number,int type,const std::string & name)490 void HandsFreeAudioGateway::PhoneStateChanged(
491 int numActive, int numHeld, int callState, const std::string &number, int type, const std::string &name)
492 {
493 pimpl->PhoneStateChanged(numActive, numHeld, callState, number, type, name);
494 }
495
ClccResponse(int index,int direction,int status,int mode,bool mpty,const std::string & number,int type)496 void HandsFreeAudioGateway::ClccResponse(
497 int index, int direction, int status, int mode, bool mpty, const std::string &number, int type)
498 {
499 pimpl->ClccResponse(index, direction, status, mode, mpty, number, type);
500 }
501
OpenVoiceRecognition(const BluetoothRemoteDevice & device)502 bool HandsFreeAudioGateway::OpenVoiceRecognition(const BluetoothRemoteDevice &device)
503 {
504 HILOGI("enter, device: %{public}s", GET_ENCRYPT_ADDR(device));
505 return pimpl->OpenVoiceRecognition(device);
506 }
507
CloseVoiceRecognition(const BluetoothRemoteDevice & device)508 bool HandsFreeAudioGateway::CloseVoiceRecognition(const BluetoothRemoteDevice &device)
509 {
510 HILOGI("enter, device: %{public}s", GET_ENCRYPT_ADDR(device));
511 return pimpl->CloseVoiceRecognition(device);
512 }
513
SetActiveDevice(const BluetoothRemoteDevice & device)514 bool HandsFreeAudioGateway::SetActiveDevice(const BluetoothRemoteDevice &device)
515 {
516 HILOGI("enter, device: %{public}s", GET_ENCRYPT_ADDR(device));
517 return pimpl->SetActiveDevice(device);
518 }
519
IntoMock(const BluetoothRemoteDevice & device,int state)520 bool HandsFreeAudioGateway::IntoMock(const BluetoothRemoteDevice &device, int state)
521 {
522 return pimpl->IntoMock(device, state);
523 }
524
SendNoCarrier(const BluetoothRemoteDevice & device)525 bool HandsFreeAudioGateway::SendNoCarrier(const BluetoothRemoteDevice &device)
526 {
527 return pimpl->SendNoCarrier(device);
528 }
529
GetActiveDevice() const530 BluetoothRemoteDevice HandsFreeAudioGateway::GetActiveDevice() const
531 {
532 return pimpl->GetActiveDevice();
533 }
534
RegisterObserver(HandsFreeAudioGatewayObserver * observer)535 void HandsFreeAudioGateway::RegisterObserver(HandsFreeAudioGatewayObserver *observer)
536 {
537
538 HILOGI("enter");
539 std::shared_ptr<HandsFreeAudioGatewayObserver> observerPtr(observer, [](HandsFreeAudioGatewayObserver *) {});
540 pimpl->RegisterObserver(observerPtr);
541 }
542
DeregisterObserver(HandsFreeAudioGatewayObserver * observer)543 void HandsFreeAudioGateway::DeregisterObserver(HandsFreeAudioGatewayObserver *observer)
544 {
545 HILOGI("enter");
546 std::shared_ptr<HandsFreeAudioGatewayObserver> observerPtr(observer, [](HandsFreeAudioGatewayObserver *) {});
547 if (pimpl == nullptr) {
548 HILOGI("pimpl is nullptr!");
549 return;
550 }
551 pimpl->DeregisterObserver(observerPtr);
552 HILOGI("end");
553 }
554 } // namespace Bluetooth
555 } // namespace OHOS