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.
22 #include <base/macros.h>
23 #include <utils/String16.h>
24 #include <utils/Vector.h>
26 #include "service/adapter.h"
27 #include "service/common/bluetooth/binder/IBluetooth.h"
28 #include "service/common/bluetooth/binder/IBluetoothCallback.h"
29 #include "service/common/bluetooth/binder/IBluetoothGattClient.h"
30 #include "service/common/bluetooth/binder/IBluetoothGattServer.h"
31 #include "service/common/bluetooth/binder/IBluetoothLowEnergy.h"
32 #include "service/common/bluetooth/uuid.h"
33 #include "service/ipc/binder/remote_callback_list.h"
38 // Implements the server side of the IBluetooth Binder interface.
39 class BluetoothBinderServer : public BnBluetooth,
40 public bluetooth::Adapter::Observer {
42 explicit BluetoothBinderServer(bluetooth::Adapter* adapter);
43 ~BluetoothBinderServer() override;
45 // IBluetooth overrides:
46 bool IsEnabled() override;
47 int GetState() override;
48 bool Enable() override;
49 bool EnableNoAutoConnect() override;
50 bool Disable() override;
52 std::string GetAddress() override;
53 std::vector<bluetooth::UUID> GetUUIDs() override;
54 bool SetName(const std::string& name) override;
55 std::string GetName() override;
57 void RegisterCallback(
58 const android::sp<IBluetoothCallback>& callback) override;
59 void UnregisterCallback(
60 const android::sp<IBluetoothCallback>& callback) override;
62 bool IsMultiAdvertisementSupported() override;
63 android::sp<IBluetoothLowEnergy> GetLowEnergyInterface() override;
64 android::sp<IBluetoothGattClient> GetGattClientInterface() override;
65 android::sp<IBluetoothGattServer> GetGattServerInterface() override;
67 android::status_t dump(int fd, const android::Vector<android::String16>& args) override;
69 // bluetooth::Adapter::Observer overrides:
70 void OnAdapterStateChanged(bluetooth::Adapter* adapter,
71 bluetooth::AdapterState prev_state,
72 bluetooth::AdapterState new_state) override;
75 bluetooth::Adapter* adapter_; // weak
76 RemoteCallbackList<IBluetoothCallback> callbacks_;
78 // The IBluetoothLowEnergy interface handle. This is lazily initialized on the
79 // first call to GetLowEnergyInterface().
80 android::sp<IBluetoothLowEnergy> low_energy_interface_;
82 // The IBluetoothGattClient interface handle. This is lazily initialized on
83 // the first call to GetGattClientInterface().
84 android::sp<IBluetoothGattClient> gatt_client_interface_;
86 // The IBluetoothGattServer interface handle. This is lazily initialized on
87 // the first call to GetGattServerInterface().
88 android::sp<IBluetoothGattServer> gatt_server_interface_;
90 DISALLOW_COPY_AND_ASSIGN(BluetoothBinderServer);