blob: f5aa01458481f1d567221b600157dc8f2da85c17 [file] [log] [blame]
Jaikumar Ganesh2af07762010-08-24 17:36:13 -07001/*
Joseph Pirozzo54d4b662016-09-01 14:19:28 -07002 * Copyright (C) 2010-2016 The Android Open Source Project
Jaikumar Ganesh2af07762010-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 Norbye27ce6cf2015-04-23 17:10:21 -070020import android.Manifest;
Stanley Tnga76ec8b2019-03-14 16:18:29 -070021import android.annotation.IntDef;
Tor Norbye27ce6cf2015-04-23 17:10:21 -070022import android.annotation.RequiresPermission;
Selim Gurun9e6b35b2018-01-09 14:35:19 -080023import android.annotation.SystemApi;
Mathew Inwood7d543892018-08-01 15:07:20 +010024import android.annotation.UnsupportedAppUsage;
Mathew Inwood484573f2018-09-14 12:35:36 +010025import android.os.Build;
Tor Norbye27ce6cf2015-04-23 17:10:21 -070026
Stanley Tnga76ec8b2019-03-14 16:18:29 -070027import java.lang.annotation.Retention;
28import java.lang.annotation.RetentionPolicy;
Jaikumar Ganeshd8fc4dd2010-10-18 16:41:53 -070029import java.util.List;
Jaikumar Ganesh2af07762010-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 */
Ajay Panickerbfcc00d2018-03-16 04:00:27 -070046 String EXTRA_STATE = "android.bluetooth.profile.extra.STATE";
Jaikumar Ganesh2af07762010-08-24 17:36:13 -070047
48 /**
49 * Extra for the connection state intents of the individual profiles.
50 *
51 * This extra represents the previous connection state of the profile of the
52 * Bluetooth device.
53 */
Ajay Panickerbfcc00d2018-03-16 04:00:27 -070054 String EXTRA_PREVIOUS_STATE =
Jack He910201b2017-08-22 16:06:54 -070055 "android.bluetooth.profile.extra.PREVIOUS_STATE";
Jaikumar Ganesh2af07762010-08-24 17:36:13 -070056
57 /** The profile is in disconnected state */
Ajay Panickerbfcc00d2018-03-16 04:00:27 -070058 int STATE_DISCONNECTED = 0;
Jaikumar Ganesh2af07762010-08-24 17:36:13 -070059 /** The profile is in connecting state */
Ajay Panickerbfcc00d2018-03-16 04:00:27 -070060 int STATE_CONNECTING = 1;
Jaikumar Ganesh2af07762010-08-24 17:36:13 -070061 /** The profile is in connected state */
Ajay Panickerbfcc00d2018-03-16 04:00:27 -070062 int STATE_CONNECTED = 2;
Jaikumar Ganesh2af07762010-08-24 17:36:13 -070063 /** The profile is in disconnecting state */
Ajay Panickerbfcc00d2018-03-16 04:00:27 -070064 int STATE_DISCONNECTING = 3;
Jaikumar Ganesh2af07762010-08-24 17:36:13 -070065
Stanley Tnga76ec8b2019-03-14 16:18:29 -070066 /** @hide */
67 @IntDef({
68 STATE_DISCONNECTED,
69 STATE_CONNECTING,
70 STATE_CONNECTED,
71 STATE_DISCONNECTING,
72 })
73 @Retention(RetentionPolicy.SOURCE)
74 public @interface BtProfileState {}
75
Jaikumar Ganesh2af07762010-08-24 17:36:13 -070076 /**
77 * Headset and Handsfree profile
78 */
Ajay Panickerbfcc00d2018-03-16 04:00:27 -070079 int HEADSET = 1;
Jaikumar Ganesh97f8ec42011-02-23 10:22:15 -080080
Jaikumar Ganesh2af07762010-08-24 17:36:13 -070081 /**
82 * A2DP profile.
83 */
Ajay Panickerbfcc00d2018-03-16 04:00:27 -070084 int A2DP = 2;
Jaikumar Ganesh97f8ec42011-02-23 10:22:15 -080085
Jaikumar Ganeshad5d9c02011-02-18 14:52:32 -080086 /**
Jaikumar Ganeshbf981ca2011-04-01 16:33:09 -070087 * Health Profile
Jack He8bb9c7d2019-01-03 16:23:41 -080088 *
89 * @deprecated Health Device Profile (HDP) and MCAP protocol are no longer used. New
90 * apps should use Bluetooth Low Energy based solutions such as {@link BluetoothGatt},
91 * {@link BluetoothAdapter#listenUsingL2capChannel()}, or
92 * {@link BluetoothDevice#createL2capChannel(int)}
Jaikumar Ganeshbf981ca2011-04-01 16:33:09 -070093 */
Jack He8bb9c7d2019-01-03 16:23:41 -080094 @Deprecated
Ajay Panickerbfcc00d2018-03-16 04:00:27 -070095 int HEALTH = 3;
Jaikumar Ganeshbf981ca2011-04-01 16:33:09 -070096
97 /**
Hansong Zhangf0761582017-10-20 15:55:59 -070098 * HID Host
Jack He910201b2017-08-22 16:06:54 -070099 *
Jaikumar Ganeshad5d9c02011-02-18 14:52:32 -0800100 * @hide
101 */
Ajay Panickerbfcc00d2018-03-16 04:00:27 -0700102 int HID_HOST = 4;
Jaikumar Ganesh2af07762010-08-24 17:36:13 -0700103
104 /**
Jaikumar Ganesh97f8ec42011-02-23 10:22:15 -0800105 * PAN Profile
Jack He910201b2017-08-22 16:06:54 -0700106 *
Jaikumar Ganesh97f8ec42011-02-23 10:22:15 -0800107 * @hide
108 */
Mathew Inwood484573f2018-09-14 12:35:36 +0100109 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
Ajay Panickerbfcc00d2018-03-16 04:00:27 -0700110 int PAN = 5;
Jaikumar Ganesh97f8ec42011-02-23 10:22:15 -0800111
112 /**
Jaikumar Ganesh53178422011-08-19 10:26:32 -0700113 * PBAP
Jack He910201b2017-08-22 16:06:54 -0700114 *
Jaikumar Ganesh53178422011-08-19 10:26:32 -0700115 * @hide
116 */
Ajay Panickerbfcc00d2018-03-16 04:00:27 -0700117 int PBAP = 6;
Jaikumar Ganesh53178422011-08-19 10:26:32 -0700118
119 /**
Ganesh Ganapathi Batta40b98952013-02-05 15:28:33 -0800120 * GATT
Ganesh Ganapathi Batta40b98952013-02-05 15:28:33 -0800121 */
Ajay Panickerbfcc00d2018-03-16 04:00:27 -0700122 int GATT = 7;
Ganesh Ganapathi Batta40b98952013-02-05 15:28:33 -0800123
124 /**
125 * GATT_SERVER
Ganesh Ganapathi Batta40b98952013-02-05 15:28:33 -0800126 */
Ajay Panickerbfcc00d2018-03-16 04:00:27 -0700127 int GATT_SERVER = 8;
Ganesh Ganapathi Batta40b98952013-02-05 15:28:33 -0800128
129 /**
Matthew Xiece145222013-07-18 17:31:50 -0700130 * MAP Profile
Jack He910201b2017-08-22 16:06:54 -0700131 *
Matthew Xiece145222013-07-18 17:31:50 -0700132 * @hide
133 */
Ajay Panickerbfcc00d2018-03-16 04:00:27 -0700134 int MAP = 9;
Matthew Xiece145222013-07-18 17:31:50 -0700135
Casper Bonded8355fb2015-03-19 10:36:45 +0100136 /*
137 * SAP Profile
138 * @hide
139 */
Ajay Panickerbfcc00d2018-03-16 04:00:27 -0700140 int SAP = 10;
Casper Bonded8355fb2015-03-19 10:36:45 +0100141
Matthew Xiece145222013-07-18 17:31:50 -0700142 /**
Mike Lockwooda5e51db2014-05-21 10:08:50 -0700143 * A2DP Sink Profile
Jack He910201b2017-08-22 16:06:54 -0700144 *
Mike Lockwooda5e51db2014-05-21 10:08:50 -0700145 * @hide
146 */
Mathew Inwood7d543892018-08-01 15:07:20 +0100147 @UnsupportedAppUsage
Ajay Panickerbfcc00d2018-03-16 04:00:27 -0700148 int A2DP_SINK = 11;
Mike Lockwooda5e51db2014-05-21 10:08:50 -0700149
150 /**
Mike Lockwood517b04f2014-06-02 16:20:37 -0700151 * AVRCP Controller Profile
Jack He910201b2017-08-22 16:06:54 -0700152 *
Mike Lockwood517b04f2014-06-02 16:20:37 -0700153 * @hide
154 */
Mathew Inwood7d543892018-08-01 15:07:20 +0100155 @UnsupportedAppUsage
Ajay Panickerbfcc00d2018-03-16 04:00:27 -0700156 int AVRCP_CONTROLLER = 12;
157
158 /**
159 * AVRCP Target Profile
160 *
161 * @hide
162 */
163 int AVRCP = 13;
Mike Lockwood517b04f2014-06-02 16:20:37 -0700164
165 /**
Mike Lockwoodf48a7272014-06-12 11:23:40 -0700166 * Headset Client - HFP HF Role
Jack He910201b2017-08-22 16:06:54 -0700167 *
Hemant Gupta67a995a2013-08-19 19:03:51 +0530168 * @hide
169 */
Ajay Panickerbfcc00d2018-03-16 04:00:27 -0700170 int HEADSET_CLIENT = 16;
Hemant Gupta67a995a2013-08-19 19:03:51 +0530171
172 /**
Joseph Pirozzo6f56b0f2016-03-04 13:02:54 -0800173 * PBAP Client
Jack He910201b2017-08-22 16:06:54 -0700174 *
Joseph Pirozzo6f56b0f2016-03-04 13:02:54 -0800175 * @hide
176 */
Ajay Panickerbfcc00d2018-03-16 04:00:27 -0700177 int PBAP_CLIENT = 17;
Joseph Pirozzo6f56b0f2016-03-04 13:02:54 -0800178
179 /**
Joseph Pirozzo54d4b662016-09-01 14:19:28 -0700180 * MAP Messaging Client Equipment (MCE)
Jack He910201b2017-08-22 16:06:54 -0700181 *
Joseph Pirozzo54d4b662016-09-01 14:19:28 -0700182 * @hide
183 */
Ajay Panickerbfcc00d2018-03-16 04:00:27 -0700184 int MAP_CLIENT = 18;
Joseph Pirozzo54d4b662016-09-01 14:19:28 -0700185
186 /**
Hansong Zhangf0761582017-10-20 15:55:59 -0700187 * HID Device
Hemant Gupta7d82a612014-04-18 11:22:45 +0530188 */
Ajay Panickerbfcc00d2018-03-16 04:00:27 -0700189 int HID_DEVICE = 19;
Hemant Gupta7d82a612014-04-18 11:22:45 +0530190
191 /**
Myles Watson31318972018-01-05 13:54:34 -0800192 * Object Push Profile (OPP)
193 *
194 * @hide
195 */
Ajay Panickerbfcc00d2018-03-16 04:00:27 -0700196 int OPP = 20;
Myles Watson31318972018-01-05 13:54:34 -0800197
198 /**
Jakub Pawlowski3f238732017-11-22 11:02:34 -0800199 * Hearing Aid Device
200 *
Jakub Pawlowski3f238732017-11-22 11:02:34 -0800201 */
202 int HEARING_AID = 21;
203
204 /**
Bryce Leeff5093b2016-10-09 12:54:42 -0700205 * Max profile ID. This value should be updated whenever a new profile is added to match
206 * the largest value assigned to a profile.
Jack He910201b2017-08-22 16:06:54 -0700207 *
Bryce Leeff5093b2016-10-09 12:54:42 -0700208 * @hide
209 */
Jakub Pawlowski3f238732017-11-22 11:02:34 -0800210 int MAX_PROFILE_ID = 21;
Bryce Leeff5093b2016-10-09 12:54:42 -0700211
212 /**
Jaikumar Ganesh2af07762010-08-24 17:36:13 -0700213 * Default priority for devices that we try to auto-connect to and
214 * and allow incoming connections for the profile
Jack He910201b2017-08-22 16:06:54 -0700215 *
Jaikumar Ganesh2af07762010-08-24 17:36:13 -0700216 * @hide
217 **/
Mathew Inwood7d543892018-08-01 15:07:20 +0100218 @UnsupportedAppUsage
Ajay Panickerbfcc00d2018-03-16 04:00:27 -0700219 int PRIORITY_AUTO_CONNECT = 1000;
Jaikumar Ganesh2af07762010-08-24 17:36:13 -0700220
221 /**
Jack He910201b2017-08-22 16:06:54 -0700222 * Default priority for devices that allow incoming
Jaikumar Ganesh2af07762010-08-24 17:36:13 -0700223 * and outgoing connections for the profile
Jack He910201b2017-08-22 16:06:54 -0700224 *
Jaikumar Ganesh2af07762010-08-24 17:36:13 -0700225 * @hide
226 **/
Selim Gurun9e6b35b2018-01-09 14:35:19 -0800227 @SystemApi
Ajay Panickerbfcc00d2018-03-16 04:00:27 -0700228 int PRIORITY_ON = 100;
Jaikumar Ganesh2af07762010-08-24 17:36:13 -0700229
230 /**
231 * Default priority for devices that does not allow incoming
232 * connections and outgoing connections for the profile.
Jack He910201b2017-08-22 16:06:54 -0700233 *
Jaikumar Ganesh2af07762010-08-24 17:36:13 -0700234 * @hide
235 **/
Selim Gurun9e6b35b2018-01-09 14:35:19 -0800236 @SystemApi
Ajay Panickerbfcc00d2018-03-16 04:00:27 -0700237 int PRIORITY_OFF = 0;
Jaikumar Ganesh2af07762010-08-24 17:36:13 -0700238
239 /**
240 * Default priority when not set or when the device is unpaired
Jack He910201b2017-08-22 16:06:54 -0700241 *
Jaikumar Ganesh2af07762010-08-24 17:36:13 -0700242 * @hide
Jack He910201b2017-08-22 16:06:54 -0700243 */
Mathew Inwood7d543892018-08-01 15:07:20 +0100244 @UnsupportedAppUsage
Ajay Panickerbfcc00d2018-03-16 04:00:27 -0700245 int PRIORITY_UNDEFINED = -1;
Jaikumar Ganesh2af07762010-08-24 17:36:13 -0700246
247 /**
Jaikumar Ganesh2af07762010-08-24 17:36:13 -0700248 * Get connected devices for this specific profile.
249 *
250 * <p> Return the set of devices which are in state {@link #STATE_CONNECTED}
251 *
Jaikumar Ganeshd8fc4dd2010-10-18 16:41:53 -0700252 * @return List of devices. The list will be empty on error.
Jaikumar Ganesh2af07762010-08-24 17:36:13 -0700253 */
Tor Norbye27ce6cf2015-04-23 17:10:21 -0700254 @RequiresPermission(Manifest.permission.BLUETOOTH)
Jaikumar Ganeshd8fc4dd2010-10-18 16:41:53 -0700255 public List<BluetoothDevice> getConnectedDevices();
Jaikumar Ganesh2af07762010-08-24 17:36:13 -0700256
257 /**
Jaikumar Ganeshb3427572011-01-25 16:03:13 -0800258 * Get a list of devices that match any of the given connection
Jaikumar Ganesh2af07762010-08-24 17:36:13 -0700259 * states.
260 *
Jaikumar Ganeshb3427572011-01-25 16:03:13 -0800261 * <p> If none of the devices match any of the given states,
262 * an empty list will be returned.
Jaikumar Ganesh2af07762010-08-24 17:36:13 -0700263 *
Jack He910201b2017-08-22 16:06:54 -0700264 * @param states Array of states. States can be one of {@link #STATE_CONNECTED}, {@link
265 * #STATE_CONNECTING}, {@link #STATE_DISCONNECTED}, {@link #STATE_DISCONNECTING},
Jaikumar Ganeshd8fc4dd2010-10-18 16:41:53 -0700266 * @return List of devices. The list will be empty on error.
Jaikumar Ganesh2af07762010-08-24 17:36:13 -0700267 */
Tor Norbye27ce6cf2015-04-23 17:10:21 -0700268 @RequiresPermission(Manifest.permission.BLUETOOTH)
Jaikumar Ganeshd8fc4dd2010-10-18 16:41:53 -0700269 public List<BluetoothDevice> getDevicesMatchingConnectionStates(int[] states);
Jaikumar Ganesh2af07762010-08-24 17:36:13 -0700270
271 /**
272 * Get the current connection state of the profile
273 *
Jaikumar Ganesh2af07762010-08-24 17:36:13 -0700274 * @param device Remote bluetooth device.
Jack He910201b2017-08-22 16:06:54 -0700275 * @return State of the profile connection. One of {@link #STATE_CONNECTED}, {@link
276 * #STATE_CONNECTING}, {@link #STATE_DISCONNECTED}, {@link #STATE_DISCONNECTING}
Jaikumar Ganesh2af07762010-08-24 17:36:13 -0700277 */
Tor Norbye27ce6cf2015-04-23 17:10:21 -0700278 @RequiresPermission(Manifest.permission.BLUETOOTH)
Stanley Tnga76ec8b2019-03-14 16:18:29 -0700279 @BtProfileState int getConnectionState(BluetoothDevice device);
Jaikumar Ganesh2af07762010-08-24 17:36:13 -0700280
281 /**
Jaikumar Ganesh2af07762010-08-24 17:36:13 -0700282 * An interface for notifying BluetoothProfile IPC clients when they have
283 * been connected or disconnected to the service.
284 */
285 public interface ServiceListener {
286 /**
287 * Called to notify the client when the proxy object has been
288 * connected to the service.
Jack He910201b2017-08-22 16:06:54 -0700289 *
Jack He8bb9c7d2019-01-03 16:23:41 -0800290 * @param profile - One of {@link #HEADSET} or {@link #A2DP}
291 * @param proxy - One of {@link BluetoothHeadset} or {@link BluetoothA2dp}
Jaikumar Ganesh2af07762010-08-24 17:36:13 -0700292 */
293 public void onServiceConnected(int profile, BluetoothProfile proxy);
294
295 /**
296 * Called to notify the client that this proxy object has been
297 * disconnected from the service.
Jack He910201b2017-08-22 16:06:54 -0700298 *
Jack He8bb9c7d2019-01-03 16:23:41 -0800299 * @param profile - One of {@link #HEADSET} or {@link #A2DP}
Jaikumar Ganesh2af07762010-08-24 17:36:13 -0700300 */
301 public void onServiceDisconnected(int profile);
302 }
Jack He93df9402017-12-11 13:11:20 -0800303
304 /**
305 * Convert an integer value of connection state into human readable string
306 *
307 * @param connectionState - One of {@link #STATE_DISCONNECTED}, {@link #STATE_CONNECTING},
308 * {@link #STATE_CONNECTED}, or {@link #STATE_DISCONNECTED}
309 * @return a string representation of the connection state, STATE_UNKNOWN if the state
310 * is not defined
311 * @hide
312 */
313 static String getConnectionStateName(int connectionState) {
314 switch (connectionState) {
315 case STATE_DISCONNECTED:
316 return "STATE_DISCONNECTED";
317 case STATE_CONNECTING:
318 return "STATE_CONNECTING";
319 case STATE_CONNECTED:
320 return "STATE_CONNECTED";
321 case STATE_DISCONNECTING:
322 return "STATE_DISCONNECTING";
323 default:
324 return "STATE_UNKNOWN";
325 }
326 }
Ugo Yue5216182019-07-22 15:56:23 +0800327
328 /**
329 * Convert an integer value of profile ID into human readable string
330 *
331 * @param profile profile ID
332 * @return profile name as String, UNKOWN_PROFILE if the profile ID is not defined.
333 * @hide
334 */
335 static String getProfileName(int profile) {
336 switch(profile) {
337 case HEADSET:
338 return "HEADSET";
339 case A2DP:
340 return "A2DP";
341 case HID_HOST:
342 return "HID_HOST";
343 case PAN:
344 return "PAN";
345 case PBAP:
346 return "PBAP";
347 case GATT:
348 return "GATT";
349 case GATT_SERVER:
350 return "GATT_SERVER";
351 case MAP:
352 return "MAP";
353 case SAP:
354 return "SAP";
355 case A2DP_SINK:
356 return "A2DP_SINK";
357 case AVRCP_CONTROLLER:
358 return "AVRCP_CONTROLLER";
359 case AVRCP:
360 return "AVRCP";
361 case HEADSET_CLIENT:
362 return "HEADSET_CLIENT";
363 case PBAP_CLIENT:
364 return "PBAP_CLIENT";
365 case MAP_CLIENT:
366 return "MAP_CLIENT";
367 case HID_DEVICE:
368 return "HID_DEVICE";
369 case OPP:
370 return "OPP";
371 case HEARING_AID:
372 return "HEARING_AID";
373 default:
374 return "UNKNOWN_PROFILE";
375 }
376 }
Jaikumar Ganesh2af07762010-08-24 17:36:13 -0700377}