Jaikumar Ganesh | 62c37ef | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 1 | /* |
Joseph Pirozzo | 631768d | 2016-09-01 14:19:28 -0700 | [diff] [blame] | 2 | * Copyright (C) 2010-2016 The Android Open Source Project |
Jaikumar Ganesh | 62c37ef | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 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 | |
| 18 | package android.bluetooth; |
| 19 | |
Tor Norbye | 2d49752 | 2015-04-23 17:10:21 -0700 | [diff] [blame] | 20 | import android.Manifest; |
| 21 | import android.annotation.RequiresPermission; |
| 22 | |
Jaikumar Ganesh | 03cd78c | 2010-10-18 16:41:53 -0700 | [diff] [blame] | 23 | import java.util.List; |
Jaikumar Ganesh | 62c37ef | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 24 | |
| 25 | /** |
| 26 | * Public APIs for the Bluetooth Profiles. |
| 27 | * |
| 28 | * <p> Clients should call {@link BluetoothAdapter#getProfileProxy}, |
| 29 | * to get the Profile Proxy. Each public profile implements this |
| 30 | * interface. |
| 31 | */ |
| 32 | public interface BluetoothProfile { |
| 33 | |
| 34 | /** |
| 35 | * Extra for the connection state intents of the individual profiles. |
| 36 | * |
| 37 | * This extra represents the current connection state of the profile of the |
| 38 | * Bluetooth device. |
| 39 | */ |
| 40 | public static final String EXTRA_STATE = "android.bluetooth.profile.extra.STATE"; |
| 41 | |
| 42 | /** |
| 43 | * Extra for the connection state intents of the individual profiles. |
| 44 | * |
| 45 | * This extra represents the previous connection state of the profile of the |
| 46 | * Bluetooth device. |
| 47 | */ |
| 48 | public static final String EXTRA_PREVIOUS_STATE = |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 49 | "android.bluetooth.profile.extra.PREVIOUS_STATE"; |
Jaikumar Ganesh | 62c37ef | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 50 | |
| 51 | /** The profile is in disconnected state */ |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 52 | public static final int STATE_DISCONNECTED = 0; |
Jaikumar Ganesh | 62c37ef | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 53 | /** The profile is in connecting state */ |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 54 | public static final int STATE_CONNECTING = 1; |
Jaikumar Ganesh | 62c37ef | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 55 | /** The profile is in connected state */ |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 56 | public static final int STATE_CONNECTED = 2; |
Jaikumar Ganesh | 62c37ef | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 57 | /** The profile is in disconnecting state */ |
| 58 | public static final int STATE_DISCONNECTING = 3; |
| 59 | |
| 60 | /** |
| 61 | * Headset and Handsfree profile |
| 62 | */ |
| 63 | public static final int HEADSET = 1; |
Jaikumar Ganesh | 74ef119 | 2011-02-23 10:22:15 -0800 | [diff] [blame] | 64 | |
Jaikumar Ganesh | 62c37ef | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 65 | /** |
| 66 | * A2DP profile. |
| 67 | */ |
| 68 | public static final int A2DP = 2; |
Jaikumar Ganesh | 74ef119 | 2011-02-23 10:22:15 -0800 | [diff] [blame] | 69 | |
Jaikumar Ganesh | 4ab0e77 | 2011-02-18 14:52:32 -0800 | [diff] [blame] | 70 | /** |
Jaikumar Ganesh | 2ea1e85 | 2011-04-01 16:33:09 -0700 | [diff] [blame] | 71 | * Health Profile |
Jaikumar Ganesh | 2ea1e85 | 2011-04-01 16:33:09 -0700 | [diff] [blame] | 72 | */ |
| 73 | public static final int HEALTH = 3; |
| 74 | |
| 75 | /** |
Hansong Zhang | 0edf754 | 2017-10-20 15:55:59 -0700 | [diff] [blame] | 76 | * HID Host |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 77 | * |
Jaikumar Ganesh | 4ab0e77 | 2011-02-18 14:52:32 -0800 | [diff] [blame] | 78 | * @hide |
| 79 | */ |
Hansong Zhang | 0edf754 | 2017-10-20 15:55:59 -0700 | [diff] [blame] | 80 | public static final int HID_HOST = 4; |
Jaikumar Ganesh | 62c37ef | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 81 | |
| 82 | /** |
Jaikumar Ganesh | 74ef119 | 2011-02-23 10:22:15 -0800 | [diff] [blame] | 83 | * PAN Profile |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 84 | * |
Jaikumar Ganesh | 74ef119 | 2011-02-23 10:22:15 -0800 | [diff] [blame] | 85 | * @hide |
| 86 | */ |
Jaikumar Ganesh | 2ea1e85 | 2011-04-01 16:33:09 -0700 | [diff] [blame] | 87 | public static final int PAN = 5; |
Jaikumar Ganesh | 74ef119 | 2011-02-23 10:22:15 -0800 | [diff] [blame] | 88 | |
| 89 | /** |
Jaikumar Ganesh | cb1d354 | 2011-08-19 10:26:32 -0700 | [diff] [blame] | 90 | * PBAP |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 91 | * |
Jaikumar Ganesh | cb1d354 | 2011-08-19 10:26:32 -0700 | [diff] [blame] | 92 | * @hide |
| 93 | */ |
| 94 | public static final int PBAP = 6; |
| 95 | |
| 96 | /** |
Ganesh Ganapathi Batta | 9908112 | 2013-02-05 15:28:33 -0800 | [diff] [blame] | 97 | * GATT |
Ganesh Ganapathi Batta | 9908112 | 2013-02-05 15:28:33 -0800 | [diff] [blame] | 98 | */ |
Jack He | 2992cd0 | 2017-08-22 21:21:23 -0700 | [diff] [blame] | 99 | public static final int GATT = 7; |
Ganesh Ganapathi Batta | 9908112 | 2013-02-05 15:28:33 -0800 | [diff] [blame] | 100 | |
| 101 | /** |
| 102 | * GATT_SERVER |
Ganesh Ganapathi Batta | 9908112 | 2013-02-05 15:28:33 -0800 | [diff] [blame] | 103 | */ |
Jack He | 2992cd0 | 2017-08-22 21:21:23 -0700 | [diff] [blame] | 104 | public static final int GATT_SERVER = 8; |
Ganesh Ganapathi Batta | 9908112 | 2013-02-05 15:28:33 -0800 | [diff] [blame] | 105 | |
| 106 | /** |
Matthew Xie | fe3807a | 2013-07-18 17:31:50 -0700 | [diff] [blame] | 107 | * MAP Profile |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 108 | * |
Matthew Xie | fe3807a | 2013-07-18 17:31:50 -0700 | [diff] [blame] | 109 | * @hide |
| 110 | */ |
| 111 | public static final int MAP = 9; |
| 112 | |
Casper Bonde | 2a5f608 | 2015-03-19 10:36:45 +0100 | [diff] [blame] | 113 | /* |
| 114 | * SAP Profile |
| 115 | * @hide |
| 116 | */ |
| 117 | public static final int SAP = 10; |
| 118 | |
Matthew Xie | fe3807a | 2013-07-18 17:31:50 -0700 | [diff] [blame] | 119 | /** |
Mike Lockwood | 0a40ec2 | 2014-05-21 10:08:50 -0700 | [diff] [blame] | 120 | * A2DP Sink Profile |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 121 | * |
Mike Lockwood | 0a40ec2 | 2014-05-21 10:08:50 -0700 | [diff] [blame] | 122 | * @hide |
| 123 | */ |
Casper Bonde | 2a5f608 | 2015-03-19 10:36:45 +0100 | [diff] [blame] | 124 | public static final int A2DP_SINK = 11; |
Mike Lockwood | 0a40ec2 | 2014-05-21 10:08:50 -0700 | [diff] [blame] | 125 | |
| 126 | /** |
Mike Lockwood | 94b59de | 2014-06-02 16:20:37 -0700 | [diff] [blame] | 127 | * AVRCP Controller Profile |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 128 | * |
Mike Lockwood | 94b59de | 2014-06-02 16:20:37 -0700 | [diff] [blame] | 129 | * @hide |
| 130 | */ |
Casper Bonde | 2a5f608 | 2015-03-19 10:36:45 +0100 | [diff] [blame] | 131 | public static final int AVRCP_CONTROLLER = 12; |
Mike Lockwood | 94b59de | 2014-06-02 16:20:37 -0700 | [diff] [blame] | 132 | |
| 133 | /** |
Mike Lockwood | cf916d3 | 2014-06-12 11:23:40 -0700 | [diff] [blame] | 134 | * Headset Client - HFP HF Role |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 135 | * |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 136 | * @hide |
| 137 | */ |
Mike Lockwood | cf916d3 | 2014-06-12 11:23:40 -0700 | [diff] [blame] | 138 | public static final int HEADSET_CLIENT = 16; |
Hemant Gupta | 7aca90f | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 139 | |
| 140 | /** |
Joseph Pirozzo | cfa8a64 | 2016-03-04 13:02:54 -0800 | [diff] [blame] | 141 | * PBAP Client |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 142 | * |
Joseph Pirozzo | cfa8a64 | 2016-03-04 13:02:54 -0800 | [diff] [blame] | 143 | * @hide |
| 144 | */ |
| 145 | public static final int PBAP_CLIENT = 17; |
| 146 | |
| 147 | /** |
Joseph Pirozzo | 631768d | 2016-09-01 14:19:28 -0700 | [diff] [blame] | 148 | * MAP Messaging Client Equipment (MCE) |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 149 | * |
Joseph Pirozzo | 631768d | 2016-09-01 14:19:28 -0700 | [diff] [blame] | 150 | * @hide |
| 151 | */ |
| 152 | public static final int MAP_CLIENT = 18; |
| 153 | |
| 154 | /** |
Hansong Zhang | 0edf754 | 2017-10-20 15:55:59 -0700 | [diff] [blame] | 155 | * HID Device |
Hemant Gupta | e88fd4b | 2014-04-18 11:22:45 +0530 | [diff] [blame] | 156 | */ |
Hansong Zhang | 0edf754 | 2017-10-20 15:55:59 -0700 | [diff] [blame] | 157 | public static final int HID_DEVICE = 19; |
Hemant Gupta | e88fd4b | 2014-04-18 11:22:45 +0530 | [diff] [blame] | 158 | |
| 159 | /** |
Bryce Lee | f6b74de | 2016-10-09 12:54:42 -0700 | [diff] [blame] | 160 | * Max profile ID. This value should be updated whenever a new profile is added to match |
| 161 | * the largest value assigned to a profile. |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 162 | * |
Bryce Lee | f6b74de | 2016-10-09 12:54:42 -0700 | [diff] [blame] | 163 | * @hide |
| 164 | */ |
Hemant Gupta | e88fd4b | 2014-04-18 11:22:45 +0530 | [diff] [blame] | 165 | public static final int MAX_PROFILE_ID = 19; |
Bryce Lee | f6b74de | 2016-10-09 12:54:42 -0700 | [diff] [blame] | 166 | |
| 167 | /** |
Jaikumar Ganesh | 62c37ef | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 168 | * Default priority for devices that we try to auto-connect to and |
| 169 | * and allow incoming connections for the profile |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 170 | * |
Jaikumar Ganesh | 62c37ef | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 171 | * @hide |
| 172 | **/ |
| 173 | public static final int PRIORITY_AUTO_CONNECT = 1000; |
| 174 | |
| 175 | /** |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 176 | * Default priority for devices that allow incoming |
Jaikumar Ganesh | 62c37ef | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 177 | * and outgoing connections for the profile |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 178 | * |
Jaikumar Ganesh | 62c37ef | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 179 | * @hide |
| 180 | **/ |
| 181 | public static final int PRIORITY_ON = 100; |
| 182 | |
| 183 | /** |
| 184 | * Default priority for devices that does not allow incoming |
| 185 | * connections and outgoing connections for the profile. |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 186 | * |
Jaikumar Ganesh | 62c37ef | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 187 | * @hide |
| 188 | **/ |
| 189 | public static final int PRIORITY_OFF = 0; |
| 190 | |
| 191 | /** |
| 192 | * Default priority when not set or when the device is unpaired |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 193 | * |
Jaikumar Ganesh | 62c37ef | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 194 | * @hide |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 195 | */ |
Jaikumar Ganesh | 62c37ef | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 196 | public static final int PRIORITY_UNDEFINED = -1; |
| 197 | |
| 198 | /** |
Jaikumar Ganesh | 62c37ef | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 199 | * Get connected devices for this specific profile. |
| 200 | * |
| 201 | * <p> Return the set of devices which are in state {@link #STATE_CONNECTED} |
| 202 | * |
Jaikumar Ganesh | 03cd78c | 2010-10-18 16:41:53 -0700 | [diff] [blame] | 203 | * @return List of devices. The list will be empty on error. |
Jaikumar Ganesh | 62c37ef | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 204 | */ |
Tor Norbye | 2d49752 | 2015-04-23 17:10:21 -0700 | [diff] [blame] | 205 | @RequiresPermission(Manifest.permission.BLUETOOTH) |
Jaikumar Ganesh | 03cd78c | 2010-10-18 16:41:53 -0700 | [diff] [blame] | 206 | public List<BluetoothDevice> getConnectedDevices(); |
Jaikumar Ganesh | 62c37ef | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 207 | |
| 208 | /** |
Jaikumar Ganesh | c8fa4ff | 2011-01-25 16:03:13 -0800 | [diff] [blame] | 209 | * Get a list of devices that match any of the given connection |
Jaikumar Ganesh | 62c37ef | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 210 | * states. |
| 211 | * |
Jaikumar Ganesh | c8fa4ff | 2011-01-25 16:03:13 -0800 | [diff] [blame] | 212 | * <p> If none of the devices match any of the given states, |
| 213 | * an empty list will be returned. |
Jaikumar Ganesh | 62c37ef | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 214 | * |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 215 | * @param states Array of states. States can be one of {@link #STATE_CONNECTED}, {@link |
| 216 | * #STATE_CONNECTING}, {@link #STATE_DISCONNECTED}, {@link #STATE_DISCONNECTING}, |
Jaikumar Ganesh | 03cd78c | 2010-10-18 16:41:53 -0700 | [diff] [blame] | 217 | * @return List of devices. The list will be empty on error. |
Jaikumar Ganesh | 62c37ef | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 218 | */ |
Tor Norbye | 2d49752 | 2015-04-23 17:10:21 -0700 | [diff] [blame] | 219 | @RequiresPermission(Manifest.permission.BLUETOOTH) |
Jaikumar Ganesh | 03cd78c | 2010-10-18 16:41:53 -0700 | [diff] [blame] | 220 | public List<BluetoothDevice> getDevicesMatchingConnectionStates(int[] states); |
Jaikumar Ganesh | 62c37ef | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 221 | |
| 222 | /** |
| 223 | * Get the current connection state of the profile |
| 224 | * |
Jaikumar Ganesh | 62c37ef | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 225 | * @param device Remote bluetooth device. |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 226 | * @return State of the profile connection. One of {@link #STATE_CONNECTED}, {@link |
| 227 | * #STATE_CONNECTING}, {@link #STATE_DISCONNECTED}, {@link #STATE_DISCONNECTING} |
Jaikumar Ganesh | 62c37ef | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 228 | */ |
Tor Norbye | 2d49752 | 2015-04-23 17:10:21 -0700 | [diff] [blame] | 229 | @RequiresPermission(Manifest.permission.BLUETOOTH) |
Jaikumar Ganesh | 62c37ef | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 230 | public int getConnectionState(BluetoothDevice device); |
| 231 | |
| 232 | /** |
Jaikumar Ganesh | 62c37ef | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 233 | * An interface for notifying BluetoothProfile IPC clients when they have |
| 234 | * been connected or disconnected to the service. |
| 235 | */ |
| 236 | public interface ServiceListener { |
| 237 | /** |
| 238 | * Called to notify the client when the proxy object has been |
| 239 | * connected to the service. |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 240 | * |
| 241 | * @param profile - One of {@link #HEALTH}, {@link #HEADSET} or {@link #A2DP} |
| 242 | * @param proxy - One of {@link BluetoothHealth}, {@link BluetoothHeadset} or {@link |
| 243 | * BluetoothA2dp} |
Jaikumar Ganesh | 62c37ef | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 244 | */ |
| 245 | public void onServiceConnected(int profile, BluetoothProfile proxy); |
| 246 | |
| 247 | /** |
| 248 | * Called to notify the client that this proxy object has been |
| 249 | * disconnected from the service. |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 250 | * |
| 251 | * @param profile - One of {@link #HEALTH}, {@link #HEADSET} or {@link #A2DP} |
Jaikumar Ganesh | 62c37ef | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 252 | */ |
| 253 | public void onServiceDisconnected(int profile); |
| 254 | } |
Jack He | 5252b97 | 2017-12-11 13:11:20 -0800 | [diff] [blame] | 255 | |
| 256 | /** |
| 257 | * Convert an integer value of connection state into human readable string |
| 258 | * |
| 259 | * @param connectionState - One of {@link #STATE_DISCONNECTED}, {@link #STATE_CONNECTING}, |
| 260 | * {@link #STATE_CONNECTED}, or {@link #STATE_DISCONNECTED} |
| 261 | * @return a string representation of the connection state, STATE_UNKNOWN if the state |
| 262 | * is not defined |
| 263 | * @hide |
| 264 | */ |
| 265 | static String getConnectionStateName(int connectionState) { |
| 266 | switch (connectionState) { |
| 267 | case STATE_DISCONNECTED: |
| 268 | return "STATE_DISCONNECTED"; |
| 269 | case STATE_CONNECTING: |
| 270 | return "STATE_CONNECTING"; |
| 271 | case STATE_CONNECTED: |
| 272 | return "STATE_CONNECTED"; |
| 273 | case STATE_DISCONNECTING: |
| 274 | return "STATE_DISCONNECTING"; |
| 275 | default: |
| 276 | return "STATE_UNKNOWN"; |
| 277 | } |
| 278 | } |
Jaikumar Ganesh | 62c37ef | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 279 | } |