blob: f1ac76527487065e0280f71acbe05bd5c833250d [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
228 **/
Selim Gurun17a26c72018-01-09 14:35:19 -0800229 @SystemApi
Ajay Panicker38c30732018-03-16 04:00:27 -0700230 int PRIORITY_ON = 100;
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -0700231
232 /**
233 * Default priority for devices that does not allow incoming
234 * connections and outgoing connections for the profile.
Jack Hea355e5e2017-08-22 16:06:54 -0700235 *
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -0700236 * @hide
237 **/
Selim Gurun17a26c72018-01-09 14:35:19 -0800238 @SystemApi
Ajay Panicker38c30732018-03-16 04:00:27 -0700239 int PRIORITY_OFF = 0;
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -0700240
241 /**
242 * Default priority when not set or when the device is unpaired
Jack Hea355e5e2017-08-22 16:06:54 -0700243 *
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -0700244 * @hide
Jack Hea355e5e2017-08-22 16:06:54 -0700245 */
Mathew Inwood4dc66d32018-08-01 15:07:20 +0100246 @UnsupportedAppUsage
Ajay Panicker38c30732018-03-16 04:00:27 -0700247 int PRIORITY_UNDEFINED = -1;
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -0700248
249 /**
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -0700250 * Get connected devices for this specific profile.
251 *
252 * <p> Return the set of devices which are in state {@link #STATE_CONNECTED}
253 *
Jaikumar Ganesh03cd78c2010-10-18 16:41:53 -0700254 * @return List of devices. The list will be empty on error.
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -0700255 */
Tor Norbye2d497522015-04-23 17:10:21 -0700256 @RequiresPermission(Manifest.permission.BLUETOOTH)
Jaikumar Ganesh03cd78c2010-10-18 16:41:53 -0700257 public List<BluetoothDevice> getConnectedDevices();
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -0700258
259 /**
Jaikumar Ganeshc8fa4ff2011-01-25 16:03:13 -0800260 * Get a list of devices that match any of the given connection
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -0700261 * states.
262 *
Jaikumar Ganeshc8fa4ff2011-01-25 16:03:13 -0800263 * <p> If none of the devices match any of the given states,
264 * an empty list will be returned.
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -0700265 *
Jack Hea355e5e2017-08-22 16:06:54 -0700266 * @param states Array of states. States can be one of {@link #STATE_CONNECTED}, {@link
267 * #STATE_CONNECTING}, {@link #STATE_DISCONNECTED}, {@link #STATE_DISCONNECTING},
Jaikumar Ganesh03cd78c2010-10-18 16:41:53 -0700268 * @return List of devices. The list will be empty on error.
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -0700269 */
Tor Norbye2d497522015-04-23 17:10:21 -0700270 @RequiresPermission(Manifest.permission.BLUETOOTH)
Jaikumar Ganesh03cd78c2010-10-18 16:41:53 -0700271 public List<BluetoothDevice> getDevicesMatchingConnectionStates(int[] states);
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -0700272
273 /**
274 * Get the current connection state of the profile
275 *
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -0700276 * @param device Remote bluetooth device.
Jack Hea355e5e2017-08-22 16:06:54 -0700277 * @return State of the profile connection. One of {@link #STATE_CONNECTED}, {@link
278 * #STATE_CONNECTING}, {@link #STATE_DISCONNECTED}, {@link #STATE_DISCONNECTING}
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -0700279 */
Tor Norbye2d497522015-04-23 17:10:21 -0700280 @RequiresPermission(Manifest.permission.BLUETOOTH)
Stanley Tng7f3b7812019-03-14 16:18:29 -0700281 @BtProfileState int getConnectionState(BluetoothDevice device);
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -0700282
283 /**
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -0700284 * An interface for notifying BluetoothProfile IPC clients when they have
285 * been connected or disconnected to the service.
286 */
287 public interface ServiceListener {
288 /**
289 * Called to notify the client when the proxy object has been
290 * connected to the service.
Jack Hea355e5e2017-08-22 16:06:54 -0700291 *
Jack He6b73b322019-01-03 16:23:41 -0800292 * @param profile - One of {@link #HEADSET} or {@link #A2DP}
293 * @param proxy - One of {@link BluetoothHeadset} or {@link BluetoothA2dp}
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -0700294 */
295 public void onServiceConnected(int profile, BluetoothProfile proxy);
296
297 /**
298 * Called to notify the client that this proxy object has been
299 * disconnected from the service.
Jack Hea355e5e2017-08-22 16:06:54 -0700300 *
Jack He6b73b322019-01-03 16:23:41 -0800301 * @param profile - One of {@link #HEADSET} or {@link #A2DP}
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -0700302 */
303 public void onServiceDisconnected(int profile);
304 }
Jack He5252b972017-12-11 13:11:20 -0800305
306 /**
307 * Convert an integer value of connection state into human readable string
308 *
309 * @param connectionState - One of {@link #STATE_DISCONNECTED}, {@link #STATE_CONNECTING},
310 * {@link #STATE_CONNECTED}, or {@link #STATE_DISCONNECTED}
311 * @return a string representation of the connection state, STATE_UNKNOWN if the state
312 * is not defined
313 * @hide
314 */
315 static String getConnectionStateName(int connectionState) {
316 switch (connectionState) {
317 case STATE_DISCONNECTED:
318 return "STATE_DISCONNECTED";
319 case STATE_CONNECTING:
320 return "STATE_CONNECTING";
321 case STATE_CONNECTED:
322 return "STATE_CONNECTED";
323 case STATE_DISCONNECTING:
324 return "STATE_DISCONNECTING";
325 default:
326 return "STATE_UNKNOWN";
327 }
328 }
Ugo Yu2712d4f2019-07-22 15:56:23 +0800329
330 /**
331 * Convert an integer value of profile ID into human readable string
332 *
333 * @param profile profile ID
334 * @return profile name as String, UNKOWN_PROFILE if the profile ID is not defined.
335 * @hide
336 */
337 static String getProfileName(int profile) {
338 switch(profile) {
339 case HEADSET:
340 return "HEADSET";
341 case A2DP:
342 return "A2DP";
343 case HID_HOST:
344 return "HID_HOST";
345 case PAN:
346 return "PAN";
347 case PBAP:
348 return "PBAP";
349 case GATT:
350 return "GATT";
351 case GATT_SERVER:
352 return "GATT_SERVER";
353 case MAP:
354 return "MAP";
355 case SAP:
356 return "SAP";
357 case A2DP_SINK:
358 return "A2DP_SINK";
359 case AVRCP_CONTROLLER:
360 return "AVRCP_CONTROLLER";
361 case AVRCP:
362 return "AVRCP";
363 case HEADSET_CLIENT:
364 return "HEADSET_CLIENT";
365 case PBAP_CLIENT:
366 return "PBAP_CLIENT";
367 case MAP_CLIENT:
368 return "MAP_CLIENT";
369 case HID_DEVICE:
370 return "HID_DEVICE";
371 case OPP:
372 return "OPP";
373 case HEARING_AID:
374 return "HEARING_AID";
375 default:
376 return "UNKNOWN_PROFILE";
377 }
378 }
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -0700379}