OSDN Git Service

resolved conflicts for b8cc54d1 to mnc-dr-dev-plus-aosp
[android-x86/system-bt.git] / service / ipc / binder / IBluetooth.h
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 <binder/IBinder.h>
24 #include <binder/IInterface.h>
25
26 #include "service/ipc/binder/IBluetoothCallback.h"
27 #include "service/uuid.h"
28
29 namespace ipc {
30 namespace binder {
31
32 // This class defines the Binder IPC interface for accessing the Bluetooth
33 // service. This class was written based on the corresponding AIDL file at
34 // /frameworks/base/core/java/android/bluetooth/IBluetooth.aidl.
35 //
36 // NOTE: KEEP THIS FILE UP-TO-DATE with the corresponding AIDL, otherwise this
37 // won't be compatible with the Android framework.
38 class IBluetooth : public android::IInterface {
39  public:
40   DECLARE_META_INTERFACE(Bluetooth);
41
42   static const char kBluetoothServiceName[];
43
44   // Transaction codes for interface methods.
45   enum {
46     IS_ENABLED_TRANSACTION = android::IBinder::FIRST_CALL_TRANSACTION,
47     GET_STATE_TRANSACTION,
48     ENABLE_TRANSACTION,
49     ENABLE_NO_AUTO_CONNECT_TRANSACTION,
50     DISABLE_TRANSACTION,
51
52     GET_ADDRESS_TRANSACTION,
53     GET_UUIDS_TRANSACTION,  // TODO(armansito): Support this
54     SET_NAME_TRANSACTION,
55     GET_NAME_TRANSACTION,
56
57     // TODO(armansito): Support the functions below.
58
59     GET_SCAN_MODE_TRANSACTION,
60     SET_SCAN_MODE_TRANSACTION,
61
62     GET_DISCOVERABLE_TIMEOUT_TRANSACTION,
63     SET_DISCOVERABLE_TIMEOUT_TRANSACTION,
64
65     START_DISCOVERY_TRANSACTION,
66     CANCEL_DISCOVERY_TRANSACTION,
67     IS_DISCOVERING_TRANSACTION,
68
69     GET_ADAPTER_CONNECTION_STATE_TRANSACTION,
70     GET_PROFILE_CONNECTION_STATE_TRANSACTION,
71
72     GET_BONDED_DEVICES_TRANSACTION,
73     CREATE_BOND_TRANSACTION,
74     CANCEL_BOND_PROCESS_TRANSACTION,
75     REMOVE_BOND_TRANSACTION,
76     GET_BOND_STATE_TRANSACTION,
77     GET_CONNECTION_STATE_TRANSACTION,
78
79     GET_REMOTE_NAME_TRANSACTION,
80     GET_REMOTE_TYPE_TRANSACTION,
81     GET_REMOTE_ALIAS_TRANSACTION,
82     SET_REMOTE_ALIAS_TRANSACTION,
83     GET_REMOTE_CLASS_TRANSACTION,
84     GET_REMOTE_UUIDS_TRANSACTION,
85     FETCH_REMOTE_UUIDS_TRANSACTION,
86     SDP_SEARCH_TRANSACTION,
87
88     SET_PIN_TRANSACTION,
89     SET_PASSKEY_TRANSACTION,
90     SET_PAIRING_CONFIRMATION_TRANSACTION,
91
92     GET_PHONEBOOK_ACCESS_PERMISSION_TRANSACTION,
93     SET_PHONEBOOK_ACCESS_PERMISSION_TRANSACTION,
94     GET_MESSAGE_ACCESS_PERMISSION_TRANSACTION,
95     SET_MESSAGE_ACCESS_PERMISSION_TRANSACTION,
96     GET_SIM_ACCESS_PERMISSION_TRANSACTION,
97     SET_SIM_ACCESS_PERMISSION_TRANSACTION,
98
99     SEND_CONNECTION_STATE_CHANGE_TRANSACTION,
100
101     REGISTER_CALLBACK_TRANSACTION,
102     UNREGISTER_CALLBACK_TRANSACTION,
103
104     CONNECT_SOCKET_TRANSACTION,
105     CREATE_SOCKET_CHANNEL_TRANSACTION,
106
107     CONFIG_HCI_SNOOP_LOG,
108     FACTORY_RESET_TRANSACTION,
109
110     IS_MULTI_ADVERTISEMENT_SUPPORTED_TRANSACTION,
111     IS_PERIPHERAL_MODE_SUPPORTED_TRANSACTION,
112     IS_OFFLOADED_FILTERING_SUPPORTED_TRANSACTION,
113     IS_OFFLOADED_SCAN_BATCHING_SUPPORTED_TRANSACTION,
114     IS_ACTIVITY_AND_ENERGY_REPORTING_SUPPORTED_TRANSACTION,
115     GET_ACTIVITY_ENERGY_INFO_FROM_CONTROLLER_TRANSACTION,
116     REPORT_ACTIVITY_INFO_TRANSACTION,
117
118     DUMP_TRANSACTION,
119     ON_LE_SERVICE_UP_TRANSACTION,
120     ON_BR_EDR_DOWN_TRANSACTION,
121   };
122
123   // Returns a handle to the IBluetooth Binder from the Android ServiceManager.
124   // Binder client code can use this to make calls to the service.
125   static android::sp<IBluetooth> getClientInterface();
126
127   // Methods declared in IBluetooth.aidl.
128
129   virtual bool IsEnabled() = 0;
130   virtual int GetState() = 0;
131   virtual bool Enable() = 0;
132   virtual bool EnableNoAutoConnect() = 0;
133   virtual bool Disable() = 0;
134
135   virtual std::string GetAddress() = 0;
136   virtual std::vector<bluetooth::UUID> GetUUIDs() = 0;
137   virtual bool SetName(const std::string& name) = 0;
138   virtual std::string GetName() = 0;
139
140   virtual void RegisterCallback(
141       const android::sp<IBluetoothCallback>& callback) = 0;
142   virtual void UnregisterCallback(
143       const android::sp<IBluetoothCallback>& callback) = 0;
144
145   virtual bool IsMultiAdvertisementSupported() = 0;
146
147   // TODO(armansito): Complete the API definition.
148
149  private:
150   DISALLOW_COPY_AND_ASSIGN(IBluetooth);
151 };
152
153 // TODO(armansito): Implement notification for when the process dies.
154
155 // The Binder server interface to IBluetooth. A class that implements IBluetooth
156 // must inherit from this class.
157 class BnBluetooth : public android::BnInterface<IBluetooth> {
158  public:
159   BnBluetooth() = default;
160   virtual ~BnBluetooth() = default;
161
162  private:
163   virtual android::status_t onTransact(
164       uint32_t code,
165       const android::Parcel& data,
166       android::Parcel* reply,
167       uint32_t flags = 0);
168
169   DISALLOW_COPY_AND_ASSIGN(BnBluetooth);
170 };
171
172 // The Binder client interface to IBluetooth.
173 class BpBluetooth : public android::BpInterface<IBluetooth> {
174  public:
175   BpBluetooth(const android::sp<android::IBinder>& impl);
176   virtual ~BpBluetooth() = default;
177
178   // IBluetooth overrides:
179   bool IsEnabled() override;
180   int GetState() override;
181   bool Enable() override;
182   bool EnableNoAutoConnect() override;
183   bool Disable() override;
184
185   std::string GetAddress() override;
186   std::vector<bluetooth::UUID> GetUUIDs() override;
187   bool SetName(const std::string& name) override;
188   std::string GetName() override;
189
190   void RegisterCallback(
191       const android::sp<IBluetoothCallback>& callback) override;
192   void UnregisterCallback(
193       const android::sp<IBluetoothCallback>& callback) override;
194
195   bool IsMultiAdvertisementSupported() override;
196
197  private:
198   DISALLOW_COPY_AND_ASSIGN(BpBluetooth);
199 };
200
201 }  // namespace binder
202 }  // namespace ipc