2 // Copyright (C) 2015 Google, Inc.
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:
8 // http://www.apache.org/licenses/LICENSE-2.0
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.
17 #include "service/hal/fake_bluetooth_interface.h"
24 FakeBluetoothInterface::Manager g_hal_manager;
27 return g_hal_manager.enable_succeed ? BT_STATUS_SUCCESS : BT_STATUS_FAIL;
30 int FakeHALDisable() {
31 return g_hal_manager.disable_succeed ? BT_STATUS_SUCCESS : BT_STATUS_FAIL;
34 int FakeHALGetAdapterProperties() {
35 return BT_STATUS_SUCCESS;
38 int FakeHALSetAdapterProperty(const bt_property_t* /* property */) {
39 LOG(INFO) << __func__;
40 return (g_hal_manager.set_property_succeed ? BT_STATUS_SUCCESS :
44 bt_interface_t fake_bt_iface = {
45 sizeof(bt_interface_t),
49 nullptr, /* cleanup */
50 FakeHALGetAdapterProperties,
51 nullptr, /* get_adapter_property */
52 FakeHALSetAdapterProperty,
53 nullptr, /* get_remote_device_properties */
54 nullptr, /* get_remote_device_property */
55 nullptr, /* set_remote_device_property */
56 nullptr, /* get_remote_service_record */
57 nullptr, /* get_remote_services */
58 nullptr, /* start_discovery */
59 nullptr, /* cancel_discovery */
60 nullptr, /* create_bond */
61 nullptr, /* remove_bond */
62 nullptr, /* cancel_bond */
63 nullptr, /* get_connection_state */
64 nullptr, /* pin_reply */
65 nullptr, /* ssp_reply */
66 nullptr, /* get_profile_interface */
67 nullptr, /* dut_mode_configure */
68 nullptr, /* dut_more_send */
69 nullptr, /* le_test_mode */
70 nullptr, /* config_hci_snoop_log */
71 nullptr, /* set_os_callouts */
72 nullptr, /* read_energy_info */
79 FakeBluetoothInterface::Manager* FakeBluetoothInterface::GetManager() {
80 return &g_hal_manager;
83 FakeBluetoothInterface::Manager::Manager()
84 : enable_succeed(false),
85 disable_succeed(false),
86 set_property_succeed(false) {
89 void FakeBluetoothInterface::NotifyAdapterStateChanged(bt_state_t state) {
90 FOR_EACH_OBSERVER(Observer, observers_, AdapterStateChangedCallback(state));
93 void FakeBluetoothInterface::NotifyAdapterPropertiesChanged(
95 bt_property_t* properties) {
98 AdapterPropertiesCallback(BT_STATUS_SUCCESS, num_properties, properties));
101 void FakeBluetoothInterface::NotifyAdapterNamePropertyChanged(
102 const std::string& name) {
103 bt_bdname_t hal_name;
104 strncpy(reinterpret_cast<char*>(hal_name.name),
106 std::min(sizeof(hal_name)-1, name.length()));
107 reinterpret_cast<char*>(hal_name.name)[name.length()] = '\0';
109 bt_property_t property;
110 property.len = sizeof(hal_name);
111 property.val = &hal_name;
112 property.type = BT_PROPERTY_BDNAME;
114 NotifyAdapterPropertiesChanged(1, &property);
117 void FakeBluetoothInterface::NotifyAdapterAddressPropertyChanged(
118 const bt_bdaddr_t* address) {
119 bt_property_t property;
120 property.len = sizeof(bt_bdaddr_t);
121 property.val = (void*)address;
122 property.type = BT_PROPERTY_BDADDR;
124 NotifyAdapterPropertiesChanged(1, &property);
127 void FakeBluetoothInterface::NotifyAdapterLocalLeFeaturesPropertyChanged(
128 const bt_local_le_features_t* features) {
129 bt_property_t property;
130 property.len = sizeof(*features);
131 property.val = (void*)features;
132 property.type = BT_PROPERTY_LOCAL_LE_FEATURES;
134 NotifyAdapterPropertiesChanged(1, &property);
137 void FakeBluetoothInterface::NotifyAclStateChangedCallback(
139 const bt_bdaddr_t& remote_bdaddr,
140 bt_acl_state_t state) {
142 Observer, observers_,
143 AclStateChangedCallback(status, remote_bdaddr, state));
146 void FakeBluetoothInterface::AddObserver(Observer* observer) {
147 observers_.AddObserver(observer);
150 void FakeBluetoothInterface::RemoveObserver(Observer* observer) {
151 observers_.RemoveObserver(observer);
154 const bt_interface_t* FakeBluetoothInterface::GetHALInterface() const {
155 return &fake_bt_iface;
158 const bluetooth_device_t* FakeBluetoothInterface::GetHALAdapter() const {
159 // TODO(armansito): Do something meaningful here to simulate test behavior.
164 } // namespace bluetooth