• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 //  Copyright 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 <memory>
20 
21 #include <android/bluetooth/IBluetoothLeAdvertiserCallback.h>
22 #include "android/bluetooth/BnBluetoothLeAdvertiser.h"
23 
24 #include "service/common/bluetooth/low_energy_constants.h"
25 #include "service/ipc/binder/interface_with_instances_base.h"
26 #include "service/low_energy_advertiser.h"
27 
28 using android::binder::Status;
29 using android::String16;
30 
31 using android::bluetooth::BnBluetoothLeAdvertiser;
32 using android::bluetooth::IBluetoothLeAdvertiserCallback;
33 
34 namespace bluetooth {
35 class Adapter;
36 }  // namespace bluetooth
37 
38 namespace ipc {
39 namespace binder {
40 
41 // Implements the server side of the IBluetoothLowEnergy interface.
42 class BluetoothLeAdvertiserBinderServer : public BnBluetoothLeAdvertiser,
43                                           public InterfaceWithInstancesBase {
44  public:
45   explicit BluetoothLeAdvertiserBinderServer(bluetooth::Adapter* adapter);
46 
47   BluetoothLeAdvertiserBinderServer(const BluetoothLeAdvertiserBinderServer&) =
48       delete;
49   BluetoothLeAdvertiserBinderServer& operator=(
50       const BluetoothLeAdvertiserBinderServer&) = delete;
51 
52   ~BluetoothLeAdvertiserBinderServer() override;
53 
54   // IBluetoothLowEnergy overrides:
55   Status RegisterAdvertiser(
56       const android::sp<IBluetoothLeAdvertiserCallback>& callback,
57       bool* _aidl_return) override;
58   Status UnregisterAdvertiser(int advertiser_id) override;
59   Status UnregisterAll() override;
60   Status StartMultiAdvertising(
61       int advertiser_id,
62       const android::bluetooth::AdvertiseData& advertise_data,
63       const android::bluetooth::AdvertiseData& scan_response,
64       const android::bluetooth::AdvertiseSettings& settings,
65       bool* _aidl_return) override;
66   Status StopMultiAdvertising(int advertiser_id, bool* _aidl_return) override;
67 
68  private:
69   // Returns a pointer to the IBluetoothLeAdvertiserCallback instance associated
70   // with |advertiser_id|. Returns NULL if such a callback cannot be found.
71   android::sp<IBluetoothLeAdvertiserCallback> GetLECallback(int advertiser_id);
72 
73   // Returns a pointer to the LowEnergyAdvertiser instance associated with
74   // |advertiser_id|. Returns NULL if such a advertiser cannot be found.
75   std::shared_ptr<bluetooth::LowEnergyAdvertiser> GetLEAdvertiser(
76       int advertiser_id);
77 
78   // InterfaceWithInstancesBase override:
79   void OnRegisterInstanceImpl(bluetooth::BLEStatus status,
80                               android::sp<IInterface> callback,
81                               bluetooth::BluetoothInstance* instance) override;
82 
83   bluetooth::Adapter* adapter_;  // weak
84 };
85 
86 }  // namespace binder
87 }  // namespace ipc
88