1//
2//  Copyright (C) 2015 Google, Inc.
3//
4//  Licensed under the Apache License, Version 2.0 (the "License");
5//  you may not use this file except in compliance with the License.
6//  You may obtain a copy of the License at:
7//
8//  http://www.apache.org/licenses/LICENSE-2.0
9//
10//  Unless required by applicable law or agreed to in writing, software
11//  distributed under the License is distributed on an "AS IS" BASIS,
12//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13//  See the License for the specific language governing permissions and
14//  limitations under the License.
15//
16
17#include <base/macros.h>
18#include <base/observer_list.h>
19
20#include "service/hal/bluetooth_interface.h"
21
22namespace bluetooth {
23namespace hal {
24
25class FakeBluetoothInterface : public BluetoothInterface {
26 public:
27  // A Fake HAL Bluetooth interface. This is kept as a global singleton as the
28  // Bluetooth HAL doesn't support anything otherwise.
29  //
30  // TODO(armansito): Use an abstract "TestHandler" interface instead.
31  struct Manager {
32    Manager();
33    ~Manager() = default;
34
35    // Values that should be returned from bt_interface_t methods.
36    bool enable_succeed;
37    bool disable_succeed;
38    bool set_property_succeed;
39  };
40
41  // Returns the global Manager.
42  static Manager* GetManager();
43
44  FakeBluetoothInterface() = default;
45  ~FakeBluetoothInterface() override = default;
46
47  // Notifies the observers that the adapter state changed to |state|.
48  void NotifyAdapterStateChanged(bt_state_t state);
49
50  // Triggers an adapter property change event.
51  void NotifyAdapterPropertiesChanged(int num_properties,
52                                      bt_property_t* properties);
53  void NotifyAdapterNamePropertyChanged(const std::string& name);
54  void NotifyAdapterAddressPropertyChanged(const RawAddress* address);
55  void NotifyAdapterLocalLeFeaturesPropertyChanged(
56      const bt_local_le_features_t* features);
57  void NotifyAclStateChangedCallback(bt_status_t status,
58                                     const RawAddress& remote_bdaddr,
59                                     bt_acl_state_t state);
60
61  // hal::BluetoothInterface overrides:
62  void AddObserver(Observer* observer) override;
63  void RemoveObserver(Observer* observer) override;
64  const bt_interface_t* GetHALInterface() const override;
65  bt_callbacks_t* GetHALCallbacks() const override;
66  const bluetooth_device_t* GetHALAdapter() const override;
67
68 private:
69  base::ObserverList<Observer> observers_;
70
71  DISALLOW_COPY_AND_ASSIGN(FakeBluetoothInterface);
72};
73
74}  // namespace hal
75}  // namespace bluetooth
76