blob: 097a3677ac4b41185c6d37034bee1a88dd0e4946 [file] [log] [blame]
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -07001/*
Joseph Pirozzo631768d2016-09-01 14:19:28 -07002 * Copyright (C) 2010-2016 The Android Open Source Project
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -07003 *
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
18package android.bluetooth;
19
Tor Norbye2d497522015-04-23 17:10:21 -070020import android.Manifest;
Stanley Tng7f3b7812019-03-14 16:18:29 -070021import android.annotation.IntDef;
Tor Norbye2d497522015-04-23 17:10:21 -070022import android.annotation.RequiresPermission;
Rahul Sabnisa0524472019-11-19 14:54:25 -080023import android.annotation.SuppressLint;
Selim Gurun17a26c72018-01-09 14:35:19 -080024import android.annotation.SystemApi;
Mathew Inwood4dc66d32018-08-01 15:07:20 +010025import android.annotation.UnsupportedAppUsage;
Tor Norbye2d497522015-04-23 17:10:21 -070026
Stanley Tng7f3b7812019-03-14 16:18:29 -070027import java.lang.annotation.Retention;
28import java.lang.annotation.RetentionPolicy;
Jaikumar Ganesh03cd78c2010-10-18 16:41:53 -070029import java.util.List;
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -070030
31/**
32 * Public APIs for the Bluetooth Profiles.
33 *
34 * <p> Clients should call {@link BluetoothAdapter#getProfileProxy},
35 * to get the Profile Proxy. Each public profile implements this
36 * interface.
37 */
38public interface BluetoothProfile {
39
40 /**
41 * Extra for the connection state intents of the individual profiles.
42 *
43 * This extra represents the current connection state of the profile of the
44 * Bluetooth device.
45 */
Rahul Sabnisa0524472019-11-19 14:54:25 -080046 @SuppressLint("ActionValue")
Ajay Panicker38c30732018-03-16 04:00:27 -070047 String EXTRA_STATE = "android.bluetooth.profile.extra.STATE";
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -070048
49 /**
50 * Extra for the connection state intents of the individual profiles.
51 *
52 * This extra represents the previous connection state of the profile of the
53 * Bluetooth device.
54 */
Rahul Sabnisa0524472019-11-19 14:54:25 -080055 @SuppressLint("ActionValue")
Ajay Panicker38c30732018-03-16 04:00:27 -070056 String EXTRA_PREVIOUS_STATE =
Jack Hea355e5e2017-08-22 16:06:54 -070057 "android.bluetooth.profile.extra.PREVIOUS_STATE";
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -070058
59 /** The profile is in disconnected state */
Ajay Panicker38c30732018-03-16 04:00:27 -070060 int STATE_DISCONNECTED = 0;
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -070061 /** The profile is in connecting state */
Ajay Panicker38c30732018-03-16 04:00:27 -070062 int STATE_CONNECTING = 1;
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -070063 /** The profile is in connected state */
Ajay Panicker38c30732018-03-16 04:00:27 -070064 int STATE_CONNECTED = 2;
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -070065 /** The profile is in disconnecting state */
Ajay Panicker38c30732018-03-16 04:00:27 -070066 int STATE_DISCONNECTING = 3;
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -070067
Stanley Tng7f3b7812019-03-14 16:18:29 -070068 /** @hide */
69 @IntDef({
70 STATE_DISCONNECTED,
71 STATE_CONNECTING,
72 STATE_CONNECTED,
73 STATE_DISCONNECTING,
74 })
75 @Retention(RetentionPolicy.SOURCE)
76 public @interface BtProfileState {}
77
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -070078 /**
79 * Headset and Handsfree profile
80 */
Ajay Panicker38c30732018-03-16 04:00:27 -070081 int HEADSET = 1;
Jaikumar Ganesh74ef1192011-02-23 10:22:15 -080082
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -070083 /**
84 * A2DP profile.
85 */
Ajay Panicker38c30732018-03-16 04:00:27 -070086 int A2DP = 2;
Jaikumar Ganesh74ef1192011-02-23 10:22:15 -080087
Jaikumar Ganesh4ab0e772011-02-18 14:52:32 -080088 /**
Jaikumar Ganesh2ea1e852011-04-01 16:33:09 -070089 * Health Profile
Jack He6b73b322019-01-03 16:23:41 -080090 *
91 * @deprecated Health Device Profile (HDP) and MCAP protocol are no longer used. New
92 * apps should use Bluetooth Low Energy based solutions such as {@link BluetoothGatt},
93 * {@link BluetoothAdapter#listenUsingL2capChannel()}, or
94 * {@link BluetoothDevice#createL2capChannel(int)}
Jaikumar Ganesh2ea1e852011-04-01 16:33:09 -070095 */
Jack He6b73b322019-01-03 16:23:41 -080096 @Deprecated
Ajay Panicker38c30732018-03-16 04:00:27 -070097 int HEALTH = 3;
Jaikumar Ganesh2ea1e852011-04-01 16:33:09 -070098
99 /**
Hansong Zhang0edf7542017-10-20 15:55:59 -0700100 * HID Host
Jack Hea355e5e2017-08-22 16:06:54 -0700101 *
Jaikumar Ganesh4ab0e772011-02-18 14:52:32 -0800102 * @hide
103 */
Ajay Panicker38c30732018-03-16 04:00:27 -0700104 int HID_HOST = 4;
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -0700105
106 /**
Jaikumar Ganesh74ef1192011-02-23 10:22:15 -0800107 * PAN Profile
Jack Hea355e5e2017-08-22 16:06:54 -0700108 *
Jaikumar Ganesh74ef1192011-02-23 10:22:15 -0800109 * @hide
110 */
Rahul Sabnisa0524472019-11-19 14:54:25 -0800111 @SystemApi
Ajay Panicker38c30732018-03-16 04:00:27 -0700112 int PAN = 5;
Jaikumar Ganesh74ef1192011-02-23 10:22:15 -0800113
114 /**
Jaikumar Ganeshcb1d3542011-08-19 10:26:32 -0700115 * PBAP
Jack Hea355e5e2017-08-22 16:06:54 -0700116 *
Jaikumar Ganeshcb1d3542011-08-19 10:26:32 -0700117 * @hide
118 */
Ajay Panicker38c30732018-03-16 04:00:27 -0700119 int PBAP = 6;
Jaikumar Ganeshcb1d3542011-08-19 10:26:32 -0700120
121 /**
Ganesh Ganapathi Batta99081122013-02-05 15:28:33 -0800122 * GATT
Ganesh Ganapathi Batta99081122013-02-05 15:28:33 -0800123 */
Ajay Panicker38c30732018-03-16 04:00:27 -0700124 int GATT = 7;
Ganesh Ganapathi Batta99081122013-02-05 15:28:33 -0800125
126 /**
127 * GATT_SERVER
Ganesh Ganapathi Batta99081122013-02-05 15:28:33 -0800128 */
Ajay Panicker38c30732018-03-16 04:00:27 -0700129 int GATT_SERVER = 8;
Ganesh Ganapathi Batta99081122013-02-05 15:28:33 -0800130
131 /**
Matthew Xiefe3807a2013-07-18 17:31:50 -0700132 * MAP Profile
Jack Hea355e5e2017-08-22 16:06:54 -0700133 *
Matthew Xiefe3807a2013-07-18 17:31:50 -0700134 * @hide
135 */
Ajay Panicker38c30732018-03-16 04:00:27 -0700136 int MAP = 9;
Matthew Xiefe3807a2013-07-18 17:31:50 -0700137
Casper Bonde2a5f6082015-03-19 10:36:45 +0100138 /*
139 * SAP Profile
140 * @hide
141 */
Ajay Panicker38c30732018-03-16 04:00:27 -0700142 int SAP = 10;
Casper Bonde2a5f6082015-03-19 10:36:45 +0100143
Matthew Xiefe3807a2013-07-18 17:31:50 -0700144 /**
Mike Lockwood0a40ec22014-05-21 10:08:50 -0700145 * A2DP Sink Profile
Jack Hea355e5e2017-08-22 16:06:54 -0700146 *
Mike Lockwood0a40ec22014-05-21 10:08:50 -0700147 * @hide
148 */
Mathew Inwood4dc66d32018-08-01 15:07:20 +0100149 @UnsupportedAppUsage
Ajay Panicker38c30732018-03-16 04:00:27 -0700150 int A2DP_SINK = 11;
Mike Lockwood0a40ec22014-05-21 10:08:50 -0700151
152 /**
Mike Lockwood94b59de2014-06-02 16:20:37 -0700153 * AVRCP Controller Profile
Jack Hea355e5e2017-08-22 16:06:54 -0700154 *
Mike Lockwood94b59de2014-06-02 16:20:37 -0700155 * @hide
156 */
Mathew Inwood4dc66d32018-08-01 15:07:20 +0100157 @UnsupportedAppUsage
Ajay Panicker38c30732018-03-16 04:00:27 -0700158 int AVRCP_CONTROLLER = 12;
159
160 /**
161 * AVRCP Target Profile
162 *
163 * @hide
164 */
165 int AVRCP = 13;
Mike Lockwood94b59de2014-06-02 16:20:37 -0700166
167 /**
Mike Lockwoodcf916d32014-06-12 11:23:40 -0700168 * Headset Client - HFP HF Role
Jack Hea355e5e2017-08-22 16:06:54 -0700169 *
Hemant Gupta7aca90f2013-08-19 19:03:51 +0530170 * @hide
171 */
Ajay Panicker38c30732018-03-16 04:00:27 -0700172 int HEADSET_CLIENT = 16;
Hemant Gupta7aca90f2013-08-19 19:03:51 +0530173
174 /**
Joseph Pirozzocfa8a642016-03-04 13:02:54 -0800175 * PBAP Client
Jack Hea355e5e2017-08-22 16:06:54 -0700176 *
Joseph Pirozzocfa8a642016-03-04 13:02:54 -0800177 * @hide
178 */
Ajay Panicker38c30732018-03-16 04:00:27 -0700179 int PBAP_CLIENT = 17;
Joseph Pirozzocfa8a642016-03-04 13:02:54 -0800180
181 /**
Joseph Pirozzo631768d2016-09-01 14:19:28 -0700182 * MAP Messaging Client Equipment (MCE)
Jack Hea355e5e2017-08-22 16:06:54 -0700183 *
Joseph Pirozzo631768d2016-09-01 14:19:28 -0700184 * @hide
185 */
Ajay Panicker38c30732018-03-16 04:00:27 -0700186 int MAP_CLIENT = 18;
Joseph Pirozzo631768d2016-09-01 14:19:28 -0700187
188 /**
Hansong Zhang0edf7542017-10-20 15:55:59 -0700189 * HID Device
Hemant Guptae88fd4b2014-04-18 11:22:45 +0530190 */
Ajay Panicker38c30732018-03-16 04:00:27 -0700191 int HID_DEVICE = 19;
Hemant Guptae88fd4b2014-04-18 11:22:45 +0530192
193 /**
Myles Watsonfa792b92018-01-05 13:54:34 -0800194 * Object Push Profile (OPP)
195 *
196 * @hide
197 */
Ajay Panicker38c30732018-03-16 04:00:27 -0700198 int OPP = 20;
Myles Watsonfa792b92018-01-05 13:54:34 -0800199
200 /**
Jakub Pawlowskiea580fa2017-11-22 11:02:34 -0800201 * Hearing Aid Device
202 *
Jakub Pawlowskiea580fa2017-11-22 11:02:34 -0800203 */
204 int HEARING_AID = 21;
205
206 /**
Bryce Leef6b74de2016-10-09 12:54:42 -0700207 * Max profile ID. This value should be updated whenever a new profile is added to match
208 * the largest value assigned to a profile.
Jack Hea355e5e2017-08-22 16:06:54 -0700209 *
Bryce Leef6b74de2016-10-09 12:54:42 -0700210 * @hide
211 */
Jakub Pawlowskiea580fa2017-11-22 11:02:34 -0800212 int MAX_PROFILE_ID = 21;
Bryce Leef6b74de2016-10-09 12:54:42 -0700213
214 /**
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -0700215 * Default priority for devices that we try to auto-connect to and
216 * and allow incoming connections for the profile
Jack Hea355e5e2017-08-22 16:06:54 -0700217 *
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -0700218 * @hide
219 **/
Mathew Inwood4dc66d32018-08-01 15:07:20 +0100220 @UnsupportedAppUsage
Ajay Panicker38c30732018-03-16 04:00:27 -0700221 int PRIORITY_AUTO_CONNECT = 1000;
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -0700222
223 /**
Jack Hea355e5e2017-08-22 16:06:54 -0700224 * Default priority for devices that allow incoming
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -0700225 * and outgoing connections for the profile
Jack Hea355e5e2017-08-22 16:06:54 -0700226 *
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -0700227 * @hide
Rahul Sabnisdf1ef4a2019-11-27 18:09:33 -0800228 * @deprecated Replaced with {@link #CONNECTION_POLICY_ALLOWED}
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -0700229 **/
Rahul Sabnisdf1ef4a2019-11-27 18:09:33 -0800230 @Deprecated
Selim Gurun17a26c72018-01-09 14:35:19 -0800231 @SystemApi
Ajay Panicker38c30732018-03-16 04:00:27 -0700232 int PRIORITY_ON = 100;
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -0700233
234 /**
235 * Default priority for devices that does not allow incoming
236 * connections and outgoing connections for the profile.
Jack Hea355e5e2017-08-22 16:06:54 -0700237 *
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -0700238 * @hide
Rahul Sabnisdf1ef4a2019-11-27 18:09:33 -0800239 * @deprecated Replaced with {@link #CONNECTION_POLICY_FORBIDDEN}
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -0700240 **/
Rahul Sabnisdf1ef4a2019-11-27 18:09:33 -0800241 @Deprecated
Selim Gurun17a26c72018-01-09 14:35:19 -0800242 @SystemApi
Ajay Panicker38c30732018-03-16 04:00:27 -0700243 int PRIORITY_OFF = 0;
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -0700244
245 /**
246 * Default priority when not set or when the device is unpaired
Jack Hea355e5e2017-08-22 16:06:54 -0700247 *
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -0700248 * @hide
Jack Hea355e5e2017-08-22 16:06:54 -0700249 */
Mathew Inwood4dc66d32018-08-01 15:07:20 +0100250 @UnsupportedAppUsage
Ajay Panicker38c30732018-03-16 04:00:27 -0700251 int PRIORITY_UNDEFINED = -1;
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -0700252
Rahul Sabnisdf1ef4a2019-11-27 18:09:33 -0800253 /** @hide */
254 @IntDef(prefix = "CONNECTION_POLICY_", value = {CONNECTION_POLICY_ALLOWED,
255 CONNECTION_POLICY_FORBIDDEN, CONNECTION_POLICY_UNKNOWN})
256 @Retention(RetentionPolicy.SOURCE)
257 public @interface ConnectionPolicy{}
258
259 /**
260 * Default connection policy for devices that allow incoming and outgoing connections
261 * for the profile
262 *
263 * @hide
264 **/
265 @SystemApi
266 int CONNECTION_POLICY_ALLOWED = 100;
267
268 /**
269 * Default connection policy for devices that do not allow incoming or outgoing connections
270 * for the profile.
271 *
272 * @hide
273 **/
274 @SystemApi
275 int CONNECTION_POLICY_FORBIDDEN = 0;
276
277 /**
278 * Default connection policy when not set or when the device is unpaired
279 *
280 * @hide
281 */
282 @SystemApi
283 int CONNECTION_POLICY_UNKNOWN = -1;
284
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -0700285 /**
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -0700286 * Get connected devices for this specific profile.
287 *
288 * <p> Return the set of devices which are in state {@link #STATE_CONNECTED}
289 *
Jaikumar Ganesh03cd78c2010-10-18 16:41:53 -0700290 * @return List of devices. The list will be empty on error.
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -0700291 */
Tor Norbye2d497522015-04-23 17:10:21 -0700292 @RequiresPermission(Manifest.permission.BLUETOOTH)
Jaikumar Ganesh03cd78c2010-10-18 16:41:53 -0700293 public List<BluetoothDevice> getConnectedDevices();
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -0700294
295 /**
Jaikumar Ganeshc8fa4ff2011-01-25 16:03:13 -0800296 * Get a list of devices that match any of the given connection
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -0700297 * states.
298 *
Jaikumar Ganeshc8fa4ff2011-01-25 16:03:13 -0800299 * <p> If none of the devices match any of the given states,
300 * an empty list will be returned.
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -0700301 *
Jack Hea355e5e2017-08-22 16:06:54 -0700302 * @param states Array of states. States can be one of {@link #STATE_CONNECTED}, {@link
303 * #STATE_CONNECTING}, {@link #STATE_DISCONNECTED}, {@link #STATE_DISCONNECTING},
Jaikumar Ganesh03cd78c2010-10-18 16:41:53 -0700304 * @return List of devices. The list will be empty on error.
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -0700305 */
Tor Norbye2d497522015-04-23 17:10:21 -0700306 @RequiresPermission(Manifest.permission.BLUETOOTH)
Jaikumar Ganesh03cd78c2010-10-18 16:41:53 -0700307 public List<BluetoothDevice> getDevicesMatchingConnectionStates(int[] states);
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -0700308
309 /**
310 * Get the current connection state of the profile
311 *
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -0700312 * @param device Remote bluetooth device.
Jack Hea355e5e2017-08-22 16:06:54 -0700313 * @return State of the profile connection. One of {@link #STATE_CONNECTED}, {@link
314 * #STATE_CONNECTING}, {@link #STATE_DISCONNECTED}, {@link #STATE_DISCONNECTING}
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -0700315 */
Tor Norbye2d497522015-04-23 17:10:21 -0700316 @RequiresPermission(Manifest.permission.BLUETOOTH)
Stanley Tng7f3b7812019-03-14 16:18:29 -0700317 @BtProfileState int getConnectionState(BluetoothDevice device);
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -0700318
319 /**
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -0700320 * An interface for notifying BluetoothProfile IPC clients when they have
321 * been connected or disconnected to the service.
322 */
323 public interface ServiceListener {
324 /**
325 * Called to notify the client when the proxy object has been
326 * connected to the service.
Jack Hea355e5e2017-08-22 16:06:54 -0700327 *
Jack He6b73b322019-01-03 16:23:41 -0800328 * @param profile - One of {@link #HEADSET} or {@link #A2DP}
329 * @param proxy - One of {@link BluetoothHeadset} or {@link BluetoothA2dp}
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -0700330 */
331 public void onServiceConnected(int profile, BluetoothProfile proxy);
332
333 /**
334 * Called to notify the client that this proxy object has been
335 * disconnected from the service.
Jack Hea355e5e2017-08-22 16:06:54 -0700336 *
Jack He6b73b322019-01-03 16:23:41 -0800337 * @param profile - One of {@link #HEADSET} or {@link #A2DP}
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -0700338 */
339 public void onServiceDisconnected(int profile);
340 }
Jack He5252b972017-12-11 13:11:20 -0800341
342 /**
343 * Convert an integer value of connection state into human readable string
344 *
345 * @param connectionState - One of {@link #STATE_DISCONNECTED}, {@link #STATE_CONNECTING},
346 * {@link #STATE_CONNECTED}, or {@link #STATE_DISCONNECTED}
347 * @return a string representation of the connection state, STATE_UNKNOWN if the state
348 * is not defined
349 * @hide
350 */
351 static String getConnectionStateName(int connectionState) {
352 switch (connectionState) {
353 case STATE_DISCONNECTED:
354 return "STATE_DISCONNECTED";
355 case STATE_CONNECTING:
356 return "STATE_CONNECTING";
357 case STATE_CONNECTED:
358 return "STATE_CONNECTED";
359 case STATE_DISCONNECTING:
360 return "STATE_DISCONNECTING";
361 default:
362 return "STATE_UNKNOWN";
363 }
364 }
Ugo Yu2712d4f2019-07-22 15:56:23 +0800365
366 /**
367 * Convert an integer value of profile ID into human readable string
368 *
369 * @param profile profile ID
370 * @return profile name as String, UNKOWN_PROFILE if the profile ID is not defined.
371 * @hide
372 */
373 static String getProfileName(int profile) {
374 switch(profile) {
375 case HEADSET:
376 return "HEADSET";
377 case A2DP:
378 return "A2DP";
379 case HID_HOST:
380 return "HID_HOST";
381 case PAN:
382 return "PAN";
383 case PBAP:
384 return "PBAP";
385 case GATT:
386 return "GATT";
387 case GATT_SERVER:
388 return "GATT_SERVER";
389 case MAP:
390 return "MAP";
391 case SAP:
392 return "SAP";
393 case A2DP_SINK:
394 return "A2DP_SINK";
395 case AVRCP_CONTROLLER:
396 return "AVRCP_CONTROLLER";
397 case AVRCP:
398 return "AVRCP";
399 case HEADSET_CLIENT:
400 return "HEADSET_CLIENT";
401 case PBAP_CLIENT:
402 return "PBAP_CLIENT";
403 case MAP_CLIENT:
404 return "MAP_CLIENT";
405 case HID_DEVICE:
406 return "HID_DEVICE";
407 case OPP:
408 return "OPP";
409 case HEARING_AID:
410 return "HEARING_AID";
411 default:
412 return "UNKNOWN_PROFILE";
413 }
414 }
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -0700415}