blob: 3c87c739e1f693f34d88b35af210592ee4d368be [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;
21import android.annotation.RequiresPermission;
Selim Gurun17a26c72018-01-09 14:35:19 -080022import android.annotation.SystemApi;
Mathew Inwood4dc66d32018-08-01 15:07:20 +010023import android.annotation.UnsupportedAppUsage;
Mathew Inwood45d2c252018-09-14 12:35:36 +010024import android.os.Build;
Tor Norbye2d497522015-04-23 17:10:21 -070025
Jaikumar Ganesh03cd78c2010-10-18 16:41:53 -070026import java.util.List;
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -070027
28/**
29 * Public APIs for the Bluetooth Profiles.
30 *
31 * <p> Clients should call {@link BluetoothAdapter#getProfileProxy},
32 * to get the Profile Proxy. Each public profile implements this
33 * interface.
34 */
35public interface BluetoothProfile {
36
37 /**
38 * Extra for the connection state intents of the individual profiles.
39 *
40 * This extra represents the current connection state of the profile of the
41 * Bluetooth device.
42 */
Ajay Panicker38c30732018-03-16 04:00:27 -070043 String EXTRA_STATE = "android.bluetooth.profile.extra.STATE";
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -070044
45 /**
46 * Extra for the connection state intents of the individual profiles.
47 *
48 * This extra represents the previous connection state of the profile of the
49 * Bluetooth device.
50 */
Ajay Panicker38c30732018-03-16 04:00:27 -070051 String EXTRA_PREVIOUS_STATE =
Jack Hea355e5e2017-08-22 16:06:54 -070052 "android.bluetooth.profile.extra.PREVIOUS_STATE";
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -070053
54 /** The profile is in disconnected state */
Ajay Panicker38c30732018-03-16 04:00:27 -070055 int STATE_DISCONNECTED = 0;
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -070056 /** The profile is in connecting state */
Ajay Panicker38c30732018-03-16 04:00:27 -070057 int STATE_CONNECTING = 1;
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -070058 /** The profile is in connected state */
Ajay Panicker38c30732018-03-16 04:00:27 -070059 int STATE_CONNECTED = 2;
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -070060 /** The profile is in disconnecting state */
Ajay Panicker38c30732018-03-16 04:00:27 -070061 int STATE_DISCONNECTING = 3;
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -070062
63 /**
64 * Headset and Handsfree profile
65 */
Ajay Panicker38c30732018-03-16 04:00:27 -070066 int HEADSET = 1;
Jaikumar Ganesh74ef1192011-02-23 10:22:15 -080067
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -070068 /**
69 * A2DP profile.
70 */
Ajay Panicker38c30732018-03-16 04:00:27 -070071 int A2DP = 2;
Jaikumar Ganesh74ef1192011-02-23 10:22:15 -080072
Jaikumar Ganesh4ab0e772011-02-18 14:52:32 -080073 /**
Jaikumar Ganesh2ea1e852011-04-01 16:33:09 -070074 * Health Profile
Jack He6b73b322019-01-03 16:23:41 -080075 *
76 * @deprecated Health Device Profile (HDP) and MCAP protocol are no longer used. New
77 * apps should use Bluetooth Low Energy based solutions such as {@link BluetoothGatt},
78 * {@link BluetoothAdapter#listenUsingL2capChannel()}, or
79 * {@link BluetoothDevice#createL2capChannel(int)}
Jaikumar Ganesh2ea1e852011-04-01 16:33:09 -070080 */
Jack He6b73b322019-01-03 16:23:41 -080081 @Deprecated
Ajay Panicker38c30732018-03-16 04:00:27 -070082 int HEALTH = 3;
Jaikumar Ganesh2ea1e852011-04-01 16:33:09 -070083
84 /**
Hansong Zhang0edf7542017-10-20 15:55:59 -070085 * HID Host
Jack Hea355e5e2017-08-22 16:06:54 -070086 *
Jaikumar Ganesh4ab0e772011-02-18 14:52:32 -080087 * @hide
88 */
Ajay Panicker38c30732018-03-16 04:00:27 -070089 int HID_HOST = 4;
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -070090
91 /**
Jaikumar Ganesh74ef1192011-02-23 10:22:15 -080092 * PAN Profile
Jack Hea355e5e2017-08-22 16:06:54 -070093 *
Jaikumar Ganesh74ef1192011-02-23 10:22:15 -080094 * @hide
95 */
Mathew Inwood45d2c252018-09-14 12:35:36 +010096 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
Ajay Panicker38c30732018-03-16 04:00:27 -070097 int PAN = 5;
Jaikumar Ganesh74ef1192011-02-23 10:22:15 -080098
99 /**
Jaikumar Ganeshcb1d3542011-08-19 10:26:32 -0700100 * PBAP
Jack Hea355e5e2017-08-22 16:06:54 -0700101 *
Jaikumar Ganeshcb1d3542011-08-19 10:26:32 -0700102 * @hide
103 */
Ajay Panicker38c30732018-03-16 04:00:27 -0700104 int PBAP = 6;
Jaikumar Ganeshcb1d3542011-08-19 10:26:32 -0700105
106 /**
Ganesh Ganapathi Batta99081122013-02-05 15:28:33 -0800107 * GATT
Ganesh Ganapathi Batta99081122013-02-05 15:28:33 -0800108 */
Ajay Panicker38c30732018-03-16 04:00:27 -0700109 int GATT = 7;
Ganesh Ganapathi Batta99081122013-02-05 15:28:33 -0800110
111 /**
112 * GATT_SERVER
Ganesh Ganapathi Batta99081122013-02-05 15:28:33 -0800113 */
Ajay Panicker38c30732018-03-16 04:00:27 -0700114 int GATT_SERVER = 8;
Ganesh Ganapathi Batta99081122013-02-05 15:28:33 -0800115
116 /**
Matthew Xiefe3807a2013-07-18 17:31:50 -0700117 * MAP Profile
Jack Hea355e5e2017-08-22 16:06:54 -0700118 *
Matthew Xiefe3807a2013-07-18 17:31:50 -0700119 * @hide
120 */
Ajay Panicker38c30732018-03-16 04:00:27 -0700121 int MAP = 9;
Matthew Xiefe3807a2013-07-18 17:31:50 -0700122
Casper Bonde2a5f6082015-03-19 10:36:45 +0100123 /*
124 * SAP Profile
125 * @hide
126 */
Ajay Panicker38c30732018-03-16 04:00:27 -0700127 int SAP = 10;
Casper Bonde2a5f6082015-03-19 10:36:45 +0100128
Matthew Xiefe3807a2013-07-18 17:31:50 -0700129 /**
Mike Lockwood0a40ec22014-05-21 10:08:50 -0700130 * A2DP Sink Profile
Jack Hea355e5e2017-08-22 16:06:54 -0700131 *
Mike Lockwood0a40ec22014-05-21 10:08:50 -0700132 * @hide
133 */
Mathew Inwood4dc66d32018-08-01 15:07:20 +0100134 @UnsupportedAppUsage
Ajay Panicker38c30732018-03-16 04:00:27 -0700135 int A2DP_SINK = 11;
Mike Lockwood0a40ec22014-05-21 10:08:50 -0700136
137 /**
Mike Lockwood94b59de2014-06-02 16:20:37 -0700138 * AVRCP Controller Profile
Jack Hea355e5e2017-08-22 16:06:54 -0700139 *
Mike Lockwood94b59de2014-06-02 16:20:37 -0700140 * @hide
141 */
Mathew Inwood4dc66d32018-08-01 15:07:20 +0100142 @UnsupportedAppUsage
Ajay Panicker38c30732018-03-16 04:00:27 -0700143 int AVRCP_CONTROLLER = 12;
144
145 /**
146 * AVRCP Target Profile
147 *
148 * @hide
149 */
150 int AVRCP = 13;
Mike Lockwood94b59de2014-06-02 16:20:37 -0700151
152 /**
Mike Lockwoodcf916d32014-06-12 11:23:40 -0700153 * Headset Client - HFP HF Role
Jack Hea355e5e2017-08-22 16:06:54 -0700154 *
Hemant Gupta7aca90f2013-08-19 19:03:51 +0530155 * @hide
156 */
Ajay Panicker38c30732018-03-16 04:00:27 -0700157 int HEADSET_CLIENT = 16;
Hemant Gupta7aca90f2013-08-19 19:03:51 +0530158
159 /**
Joseph Pirozzocfa8a642016-03-04 13:02:54 -0800160 * PBAP Client
Jack Hea355e5e2017-08-22 16:06:54 -0700161 *
Joseph Pirozzocfa8a642016-03-04 13:02:54 -0800162 * @hide
163 */
Ajay Panicker38c30732018-03-16 04:00:27 -0700164 int PBAP_CLIENT = 17;
Joseph Pirozzocfa8a642016-03-04 13:02:54 -0800165
166 /**
Joseph Pirozzo631768d2016-09-01 14:19:28 -0700167 * MAP Messaging Client Equipment (MCE)
Jack Hea355e5e2017-08-22 16:06:54 -0700168 *
Joseph Pirozzo631768d2016-09-01 14:19:28 -0700169 * @hide
170 */
Ajay Panicker38c30732018-03-16 04:00:27 -0700171 int MAP_CLIENT = 18;
Joseph Pirozzo631768d2016-09-01 14:19:28 -0700172
173 /**
Hansong Zhang0edf7542017-10-20 15:55:59 -0700174 * HID Device
Hemant Guptae88fd4b2014-04-18 11:22:45 +0530175 */
Ajay Panicker38c30732018-03-16 04:00:27 -0700176 int HID_DEVICE = 19;
Hemant Guptae88fd4b2014-04-18 11:22:45 +0530177
178 /**
Myles Watsonfa792b92018-01-05 13:54:34 -0800179 * Object Push Profile (OPP)
180 *
181 * @hide
182 */
Ajay Panicker38c30732018-03-16 04:00:27 -0700183 int OPP = 20;
Myles Watsonfa792b92018-01-05 13:54:34 -0800184
185 /**
Jakub Pawlowskiea580fa2017-11-22 11:02:34 -0800186 * Hearing Aid Device
187 *
188 * @hide
189 */
190 int HEARING_AID = 21;
191
192 /**
Bryce Leef6b74de2016-10-09 12:54:42 -0700193 * Max profile ID. This value should be updated whenever a new profile is added to match
194 * the largest value assigned to a profile.
Jack Hea355e5e2017-08-22 16:06:54 -0700195 *
Bryce Leef6b74de2016-10-09 12:54:42 -0700196 * @hide
197 */
Jakub Pawlowskiea580fa2017-11-22 11:02:34 -0800198 int MAX_PROFILE_ID = 21;
Bryce Leef6b74de2016-10-09 12:54:42 -0700199
200 /**
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -0700201 * Default priority for devices that we try to auto-connect to and
202 * and allow incoming connections for the profile
Jack Hea355e5e2017-08-22 16:06:54 -0700203 *
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -0700204 * @hide
205 **/
Mathew Inwood4dc66d32018-08-01 15:07:20 +0100206 @UnsupportedAppUsage
Ajay Panicker38c30732018-03-16 04:00:27 -0700207 int PRIORITY_AUTO_CONNECT = 1000;
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -0700208
209 /**
Jack Hea355e5e2017-08-22 16:06:54 -0700210 * Default priority for devices that allow incoming
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -0700211 * and outgoing connections for the profile
Jack Hea355e5e2017-08-22 16:06:54 -0700212 *
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -0700213 * @hide
214 **/
Selim Gurun17a26c72018-01-09 14:35:19 -0800215 @SystemApi
Ajay Panicker38c30732018-03-16 04:00:27 -0700216 int PRIORITY_ON = 100;
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -0700217
218 /**
219 * Default priority for devices that does not allow incoming
220 * connections and outgoing connections for the profile.
Jack Hea355e5e2017-08-22 16:06:54 -0700221 *
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -0700222 * @hide
223 **/
Selim Gurun17a26c72018-01-09 14:35:19 -0800224 @SystemApi
Ajay Panicker38c30732018-03-16 04:00:27 -0700225 int PRIORITY_OFF = 0;
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -0700226
227 /**
228 * Default priority when not set or when the device is unpaired
Jack Hea355e5e2017-08-22 16:06:54 -0700229 *
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -0700230 * @hide
Jack Hea355e5e2017-08-22 16:06:54 -0700231 */
Mathew Inwood4dc66d32018-08-01 15:07:20 +0100232 @UnsupportedAppUsage
Ajay Panicker38c30732018-03-16 04:00:27 -0700233 int PRIORITY_UNDEFINED = -1;
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -0700234
235 /**
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -0700236 * Get connected devices for this specific profile.
237 *
238 * <p> Return the set of devices which are in state {@link #STATE_CONNECTED}
239 *
Jaikumar Ganesh03cd78c2010-10-18 16:41:53 -0700240 * @return List of devices. The list will be empty on error.
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -0700241 */
Tor Norbye2d497522015-04-23 17:10:21 -0700242 @RequiresPermission(Manifest.permission.BLUETOOTH)
Jaikumar Ganesh03cd78c2010-10-18 16:41:53 -0700243 public List<BluetoothDevice> getConnectedDevices();
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -0700244
245 /**
Jaikumar Ganeshc8fa4ff2011-01-25 16:03:13 -0800246 * Get a list of devices that match any of the given connection
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -0700247 * states.
248 *
Jaikumar Ganeshc8fa4ff2011-01-25 16:03:13 -0800249 * <p> If none of the devices match any of the given states,
250 * an empty list will be returned.
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -0700251 *
Jack Hea355e5e2017-08-22 16:06:54 -0700252 * @param states Array of states. States can be one of {@link #STATE_CONNECTED}, {@link
253 * #STATE_CONNECTING}, {@link #STATE_DISCONNECTED}, {@link #STATE_DISCONNECTING},
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> getDevicesMatchingConnectionStates(int[] states);
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -0700258
259 /**
260 * Get the current connection state of the profile
261 *
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -0700262 * @param device Remote bluetooth device.
Jack Hea355e5e2017-08-22 16:06:54 -0700263 * @return State of the profile connection. One of {@link #STATE_CONNECTED}, {@link
264 * #STATE_CONNECTING}, {@link #STATE_DISCONNECTED}, {@link #STATE_DISCONNECTING}
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -0700265 */
Tor Norbye2d497522015-04-23 17:10:21 -0700266 @RequiresPermission(Manifest.permission.BLUETOOTH)
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -0700267 public int getConnectionState(BluetoothDevice device);
268
269 /**
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -0700270 * An interface for notifying BluetoothProfile IPC clients when they have
271 * been connected or disconnected to the service.
272 */
273 public interface ServiceListener {
274 /**
275 * Called to notify the client when the proxy object has been
276 * connected to the service.
Jack Hea355e5e2017-08-22 16:06:54 -0700277 *
Jack He6b73b322019-01-03 16:23:41 -0800278 * @param profile - One of {@link #HEADSET} or {@link #A2DP}
279 * @param proxy - One of {@link BluetoothHeadset} or {@link BluetoothA2dp}
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -0700280 */
281 public void onServiceConnected(int profile, BluetoothProfile proxy);
282
283 /**
284 * Called to notify the client that this proxy object has been
285 * disconnected from the service.
Jack Hea355e5e2017-08-22 16:06:54 -0700286 *
Jack He6b73b322019-01-03 16:23:41 -0800287 * @param profile - One of {@link #HEADSET} or {@link #A2DP}
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -0700288 */
289 public void onServiceDisconnected(int profile);
290 }
Jack He5252b972017-12-11 13:11:20 -0800291
292 /**
293 * Convert an integer value of connection state into human readable string
294 *
295 * @param connectionState - One of {@link #STATE_DISCONNECTED}, {@link #STATE_CONNECTING},
296 * {@link #STATE_CONNECTED}, or {@link #STATE_DISCONNECTED}
297 * @return a string representation of the connection state, STATE_UNKNOWN if the state
298 * is not defined
299 * @hide
300 */
301 static String getConnectionStateName(int connectionState) {
302 switch (connectionState) {
303 case STATE_DISCONNECTED:
304 return "STATE_DISCONNECTED";
305 case STATE_CONNECTING:
306 return "STATE_CONNECTING";
307 case STATE_CONNECTED:
308 return "STATE_CONNECTED";
309 case STATE_DISCONNECTING:
310 return "STATE_DISCONNECTING";
311 default:
312 return "STATE_UNKNOWN";
313 }
314 }
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -0700315}