Home | History | Annotate | Download | only in binder
      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 #pragma once
     18 
     19 #include <string>
     20 #include <vector>
     21 
     22 #include <base/macros.h>
     23 #include <utils/String16.h>
     24 #include <utils/Vector.h>
     25 
     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"
     34 
     35 namespace ipc {
     36 namespace binder {
     37 
     38 // Implements the server side of the IBluetooth Binder interface.
     39 class BluetoothBinderServer : public BnBluetooth,
     40                               public bluetooth::Adapter::Observer {
     41  public:
     42   explicit BluetoothBinderServer(bluetooth::Adapter* adapter);
     43   ~BluetoothBinderServer() override;
     44 
     45   // IBluetooth overrides:
     46   bool IsEnabled() override;
     47   int GetState() override;
     48   bool Enable(bool start_restricted) override;
     49   bool EnableNoAutoConnect() override;
     50   bool Disable() override;
     51 
     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;
     56 
     57   void RegisterCallback(
     58       const android::sp<IBluetoothCallback>& callback) override;
     59   void UnregisterCallback(
     60       const android::sp<IBluetoothCallback>& callback) override;
     61 
     62   bool IsMultiAdvertisementSupported() override;
     63   android::sp<IBluetoothLowEnergy> GetLowEnergyInterface() override;
     64   android::sp<IBluetoothGattClient> GetGattClientInterface() override;
     65   android::sp<IBluetoothGattServer> GetGattServerInterface() override;
     66 
     67   android::status_t dump(int fd, const android::Vector<android::String16>& args) override;
     68   // bluetooth::Adapter::Observer overrides:
     69   void OnAdapterStateChanged(bluetooth::Adapter* adapter,
     70                              bluetooth::AdapterState prev_state,
     71                              bluetooth::AdapterState new_state) override;
     72 
     73  private:
     74   bluetooth::Adapter* adapter_;  // weak
     75   RemoteCallbackList<IBluetoothCallback> callbacks_;
     76 
     77   // The IBluetoothLowEnergy interface handle. This is lazily initialized on the
     78   // first call to GetLowEnergyInterface().
     79   android::sp<IBluetoothLowEnergy> low_energy_interface_;
     80 
     81   // The IBluetoothGattClient interface handle. This is lazily initialized on
     82   // the first call to GetGattClientInterface().
     83   android::sp<IBluetoothGattClient> gatt_client_interface_;
     84 
     85   // The IBluetoothGattServer interface handle. This is lazily initialized on
     86   // the first call to GetGattServerInterface().
     87   android::sp<IBluetoothGattServer> gatt_server_interface_;
     88 
     89   DISALLOW_COPY_AND_ASSIGN(BluetoothBinderServer);
     90 };
     91 
     92 }  // namespace binder
     93 }  // namespace ipc
     94