| Jaikumar Ganesh | 2af0776 | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 1 | /* |
| Joseph Pirozzo | 54d4b66 | 2016-09-01 14:19:28 -0700 | [diff] [blame] | 2 | * Copyright (C) 2010-2016 The Android Open Source Project |
| Jaikumar Ganesh | 2af0776 | 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 | 27ce6cf | 2015-04-23 17:10:21 -0700 | [diff] [blame] | 20 | import android.Manifest; |
| Stanley Tng | a76ec8b | 2019-03-14 16:18:29 -0700 | [diff] [blame] | 21 | import android.annotation.IntDef; |
| Tor Norbye | 27ce6cf | 2015-04-23 17:10:21 -0700 | [diff] [blame] | 22 | import android.annotation.RequiresPermission; |
| Selim Gurun | 9e6b35b | 2018-01-09 14:35:19 -0800 | [diff] [blame] | 23 | import android.annotation.SystemApi; |
| Mathew Inwood | 7d54389 | 2018-08-01 15:07:20 +0100 | [diff] [blame] | 24 | import android.annotation.UnsupportedAppUsage; |
| Mathew Inwood | 484573f | 2018-09-14 12:35:36 +0100 | [diff] [blame] | 25 | import android.os.Build; |
| Tor Norbye | 27ce6cf | 2015-04-23 17:10:21 -0700 | [diff] [blame] | 26 | |
| Stanley Tng | a76ec8b | 2019-03-14 16:18:29 -0700 | [diff] [blame] | 27 | import java.lang.annotation.Retention; |
| 28 | import java.lang.annotation.RetentionPolicy; |
| Jaikumar Ganesh | d8fc4dd | 2010-10-18 16:41:53 -0700 | [diff] [blame] | 29 | import java.util.List; |
| Jaikumar Ganesh | 2af0776 | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 30 | |
| 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 | */ |
| 38 | public 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 Panicker | bfcc00d | 2018-03-16 04:00:27 -0700 | [diff] [blame] | 46 | String EXTRA_STATE = "android.bluetooth.profile.extra.STATE"; |
| Jaikumar Ganesh | 2af0776 | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 47 | |
| 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 Panicker | bfcc00d | 2018-03-16 04:00:27 -0700 | [diff] [blame] | 54 | String EXTRA_PREVIOUS_STATE = |
| Jack He | 910201b | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 55 | "android.bluetooth.profile.extra.PREVIOUS_STATE"; |
| Jaikumar Ganesh | 2af0776 | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 56 | |
| 57 | /** The profile is in disconnected state */ |
| Ajay Panicker | bfcc00d | 2018-03-16 04:00:27 -0700 | [diff] [blame] | 58 | int STATE_DISCONNECTED = 0; |
| Jaikumar Ganesh | 2af0776 | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 59 | /** The profile is in connecting state */ |
| Ajay Panicker | bfcc00d | 2018-03-16 04:00:27 -0700 | [diff] [blame] | 60 | int STATE_CONNECTING = 1; |
| Jaikumar Ganesh | 2af0776 | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 61 | /** The profile is in connected state */ |
| Ajay Panicker | bfcc00d | 2018-03-16 04:00:27 -0700 | [diff] [blame] | 62 | int STATE_CONNECTED = 2; |
| Jaikumar Ganesh | 2af0776 | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 63 | /** The profile is in disconnecting state */ |
| Ajay Panicker | bfcc00d | 2018-03-16 04:00:27 -0700 | [diff] [blame] | 64 | int STATE_DISCONNECTING = 3; |
| Jaikumar Ganesh | 2af0776 | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 65 | |
| Stanley Tng | a76ec8b | 2019-03-14 16:18:29 -0700 | [diff] [blame] | 66 | /** @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 Ganesh | 2af0776 | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 76 | /** |
| 77 | * Headset and Handsfree profile |
| 78 | */ |
| Ajay Panicker | bfcc00d | 2018-03-16 04:00:27 -0700 | [diff] [blame] | 79 | int HEADSET = 1; |
| Jaikumar Ganesh | 97f8ec4 | 2011-02-23 10:22:15 -0800 | [diff] [blame] | 80 | |
| Jaikumar Ganesh | 2af0776 | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 81 | /** |
| 82 | * A2DP profile. |
| 83 | */ |
| Ajay Panicker | bfcc00d | 2018-03-16 04:00:27 -0700 | [diff] [blame] | 84 | int A2DP = 2; |
| Jaikumar Ganesh | 97f8ec4 | 2011-02-23 10:22:15 -0800 | [diff] [blame] | 85 | |
| Jaikumar Ganesh | ad5d9c0 | 2011-02-18 14:52:32 -0800 | [diff] [blame] | 86 | /** |
| Jaikumar Ganesh | bf981ca | 2011-04-01 16:33:09 -0700 | [diff] [blame] | 87 | * Health Profile |
| Jack He | 8bb9c7d | 2019-01-03 16:23:41 -0800 | [diff] [blame] | 88 | * |
| 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 Ganesh | bf981ca | 2011-04-01 16:33:09 -0700 | [diff] [blame] | 93 | */ |
| Jack He | 8bb9c7d | 2019-01-03 16:23:41 -0800 | [diff] [blame] | 94 | @Deprecated |
| Ajay Panicker | bfcc00d | 2018-03-16 04:00:27 -0700 | [diff] [blame] | 95 | int HEALTH = 3; |
| Jaikumar Ganesh | bf981ca | 2011-04-01 16:33:09 -0700 | [diff] [blame] | 96 | |
| 97 | /** |
| Hansong Zhang | f076158 | 2017-10-20 15:55:59 -0700 | [diff] [blame] | 98 | * HID Host |
| Jack He | 910201b | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 99 | * |
| Jaikumar Ganesh | ad5d9c0 | 2011-02-18 14:52:32 -0800 | [diff] [blame] | 100 | * @hide |
| 101 | */ |
| Ajay Panicker | bfcc00d | 2018-03-16 04:00:27 -0700 | [diff] [blame] | 102 | int HID_HOST = 4; |
| Jaikumar Ganesh | 2af0776 | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 103 | |
| 104 | /** |
| Jaikumar Ganesh | 97f8ec4 | 2011-02-23 10:22:15 -0800 | [diff] [blame] | 105 | * PAN Profile |
| Jack He | 910201b | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 106 | * |
| Jaikumar Ganesh | 97f8ec4 | 2011-02-23 10:22:15 -0800 | [diff] [blame] | 107 | * @hide |
| 108 | */ |
| Mathew Inwood | 484573f | 2018-09-14 12:35:36 +0100 | [diff] [blame] | 109 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
| Ajay Panicker | bfcc00d | 2018-03-16 04:00:27 -0700 | [diff] [blame] | 110 | int PAN = 5; |
| Jaikumar Ganesh | 97f8ec4 | 2011-02-23 10:22:15 -0800 | [diff] [blame] | 111 | |
| 112 | /** |
| Jaikumar Ganesh | 5317842 | 2011-08-19 10:26:32 -0700 | [diff] [blame] | 113 | * PBAP |
| Jack He | 910201b | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 114 | * |
| Jaikumar Ganesh | 5317842 | 2011-08-19 10:26:32 -0700 | [diff] [blame] | 115 | * @hide |
| 116 | */ |
| Ajay Panicker | bfcc00d | 2018-03-16 04:00:27 -0700 | [diff] [blame] | 117 | int PBAP = 6; |
| Jaikumar Ganesh | 5317842 | 2011-08-19 10:26:32 -0700 | [diff] [blame] | 118 | |
| 119 | /** |
| Ganesh Ganapathi Batta | 40b9895 | 2013-02-05 15:28:33 -0800 | [diff] [blame] | 120 | * GATT |
| Ganesh Ganapathi Batta | 40b9895 | 2013-02-05 15:28:33 -0800 | [diff] [blame] | 121 | */ |
| Ajay Panicker | bfcc00d | 2018-03-16 04:00:27 -0700 | [diff] [blame] | 122 | int GATT = 7; |
| Ganesh Ganapathi Batta | 40b9895 | 2013-02-05 15:28:33 -0800 | [diff] [blame] | 123 | |
| 124 | /** |
| 125 | * GATT_SERVER |
| Ganesh Ganapathi Batta | 40b9895 | 2013-02-05 15:28:33 -0800 | [diff] [blame] | 126 | */ |
| Ajay Panicker | bfcc00d | 2018-03-16 04:00:27 -0700 | [diff] [blame] | 127 | int GATT_SERVER = 8; |
| Ganesh Ganapathi Batta | 40b9895 | 2013-02-05 15:28:33 -0800 | [diff] [blame] | 128 | |
| 129 | /** |
| Matthew Xie | ce14522 | 2013-07-18 17:31:50 -0700 | [diff] [blame] | 130 | * MAP Profile |
| Jack He | 910201b | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 131 | * |
| Matthew Xie | ce14522 | 2013-07-18 17:31:50 -0700 | [diff] [blame] | 132 | * @hide |
| 133 | */ |
| Ajay Panicker | bfcc00d | 2018-03-16 04:00:27 -0700 | [diff] [blame] | 134 | int MAP = 9; |
| Matthew Xie | ce14522 | 2013-07-18 17:31:50 -0700 | [diff] [blame] | 135 | |
| Casper Bonde | d8355fb | 2015-03-19 10:36:45 +0100 | [diff] [blame] | 136 | /* |
| 137 | * SAP Profile |
| 138 | * @hide |
| 139 | */ |
| Ajay Panicker | bfcc00d | 2018-03-16 04:00:27 -0700 | [diff] [blame] | 140 | int SAP = 10; |
| Casper Bonde | d8355fb | 2015-03-19 10:36:45 +0100 | [diff] [blame] | 141 | |
| Matthew Xie | ce14522 | 2013-07-18 17:31:50 -0700 | [diff] [blame] | 142 | /** |
| Mike Lockwood | a5e51db | 2014-05-21 10:08:50 -0700 | [diff] [blame] | 143 | * A2DP Sink Profile |
| Jack He | 910201b | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 144 | * |
| Mike Lockwood | a5e51db | 2014-05-21 10:08:50 -0700 | [diff] [blame] | 145 | * @hide |
| 146 | */ |
| Mathew Inwood | 7d54389 | 2018-08-01 15:07:20 +0100 | [diff] [blame] | 147 | @UnsupportedAppUsage |
| Ajay Panicker | bfcc00d | 2018-03-16 04:00:27 -0700 | [diff] [blame] | 148 | int A2DP_SINK = 11; |
| Mike Lockwood | a5e51db | 2014-05-21 10:08:50 -0700 | [diff] [blame] | 149 | |
| 150 | /** |
| Mike Lockwood | 517b04f | 2014-06-02 16:20:37 -0700 | [diff] [blame] | 151 | * AVRCP Controller Profile |
| Jack He | 910201b | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 152 | * |
| Mike Lockwood | 517b04f | 2014-06-02 16:20:37 -0700 | [diff] [blame] | 153 | * @hide |
| 154 | */ |
| Mathew Inwood | 7d54389 | 2018-08-01 15:07:20 +0100 | [diff] [blame] | 155 | @UnsupportedAppUsage |
| Ajay Panicker | bfcc00d | 2018-03-16 04:00:27 -0700 | [diff] [blame] | 156 | int AVRCP_CONTROLLER = 12; |
| 157 | |
| 158 | /** |
| 159 | * AVRCP Target Profile |
| 160 | * |
| 161 | * @hide |
| 162 | */ |
| 163 | int AVRCP = 13; |
| Mike Lockwood | 517b04f | 2014-06-02 16:20:37 -0700 | [diff] [blame] | 164 | |
| 165 | /** |
| Mike Lockwood | f48a727 | 2014-06-12 11:23:40 -0700 | [diff] [blame] | 166 | * Headset Client - HFP HF Role |
| Jack He | 910201b | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 167 | * |
| Hemant Gupta | 67a995a | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 168 | * @hide |
| 169 | */ |
| Ajay Panicker | bfcc00d | 2018-03-16 04:00:27 -0700 | [diff] [blame] | 170 | int HEADSET_CLIENT = 16; |
| Hemant Gupta | 67a995a | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 171 | |
| 172 | /** |
| Joseph Pirozzo | 6f56b0f | 2016-03-04 13:02:54 -0800 | [diff] [blame] | 173 | * PBAP Client |
| Jack He | 910201b | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 174 | * |
| Joseph Pirozzo | 6f56b0f | 2016-03-04 13:02:54 -0800 | [diff] [blame] | 175 | * @hide |
| 176 | */ |
| Ajay Panicker | bfcc00d | 2018-03-16 04:00:27 -0700 | [diff] [blame] | 177 | int PBAP_CLIENT = 17; |
| Joseph Pirozzo | 6f56b0f | 2016-03-04 13:02:54 -0800 | [diff] [blame] | 178 | |
| 179 | /** |
| Joseph Pirozzo | 54d4b66 | 2016-09-01 14:19:28 -0700 | [diff] [blame] | 180 | * MAP Messaging Client Equipment (MCE) |
| Jack He | 910201b | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 181 | * |
| Joseph Pirozzo | 54d4b66 | 2016-09-01 14:19:28 -0700 | [diff] [blame] | 182 | * @hide |
| 183 | */ |
| Ajay Panicker | bfcc00d | 2018-03-16 04:00:27 -0700 | [diff] [blame] | 184 | int MAP_CLIENT = 18; |
| Joseph Pirozzo | 54d4b66 | 2016-09-01 14:19:28 -0700 | [diff] [blame] | 185 | |
| 186 | /** |
| Hansong Zhang | f076158 | 2017-10-20 15:55:59 -0700 | [diff] [blame] | 187 | * HID Device |
| Hemant Gupta | 7d82a61 | 2014-04-18 11:22:45 +0530 | [diff] [blame] | 188 | */ |
| Ajay Panicker | bfcc00d | 2018-03-16 04:00:27 -0700 | [diff] [blame] | 189 | int HID_DEVICE = 19; |
| Hemant Gupta | 7d82a61 | 2014-04-18 11:22:45 +0530 | [diff] [blame] | 190 | |
| 191 | /** |
| Myles Watson | 3131897 | 2018-01-05 13:54:34 -0800 | [diff] [blame] | 192 | * Object Push Profile (OPP) |
| 193 | * |
| 194 | * @hide |
| 195 | */ |
| Ajay Panicker | bfcc00d | 2018-03-16 04:00:27 -0700 | [diff] [blame] | 196 | int OPP = 20; |
| Myles Watson | 3131897 | 2018-01-05 13:54:34 -0800 | [diff] [blame] | 197 | |
| 198 | /** |
| Jakub Pawlowski | 3f23873 | 2017-11-22 11:02:34 -0800 | [diff] [blame] | 199 | * Hearing Aid Device |
| 200 | * |
| Jakub Pawlowski | 3f23873 | 2017-11-22 11:02:34 -0800 | [diff] [blame] | 201 | */ |
| 202 | int HEARING_AID = 21; |
| 203 | |
| 204 | /** |
| Bryce Lee | ff5093b | 2016-10-09 12:54:42 -0700 | [diff] [blame] | 205 | * 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 He | 910201b | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 207 | * |
| Bryce Lee | ff5093b | 2016-10-09 12:54:42 -0700 | [diff] [blame] | 208 | * @hide |
| 209 | */ |
| Jakub Pawlowski | 3f23873 | 2017-11-22 11:02:34 -0800 | [diff] [blame] | 210 | int MAX_PROFILE_ID = 21; |
| Bryce Lee | ff5093b | 2016-10-09 12:54:42 -0700 | [diff] [blame] | 211 | |
| 212 | /** |
| Jaikumar Ganesh | 2af0776 | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 213 | * Default priority for devices that we try to auto-connect to and |
| 214 | * and allow incoming connections for the profile |
| Jack He | 910201b | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 215 | * |
| Jaikumar Ganesh | 2af0776 | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 216 | * @hide |
| 217 | **/ |
| Mathew Inwood | 7d54389 | 2018-08-01 15:07:20 +0100 | [diff] [blame] | 218 | @UnsupportedAppUsage |
| Ajay Panicker | bfcc00d | 2018-03-16 04:00:27 -0700 | [diff] [blame] | 219 | int PRIORITY_AUTO_CONNECT = 1000; |
| Jaikumar Ganesh | 2af0776 | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 220 | |
| 221 | /** |
| Jack He | 910201b | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 222 | * Default priority for devices that allow incoming |
| Jaikumar Ganesh | 2af0776 | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 223 | * and outgoing connections for the profile |
| Jack He | 910201b | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 224 | * |
| Jaikumar Ganesh | 2af0776 | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 225 | * @hide |
| 226 | **/ |
| Selim Gurun | 9e6b35b | 2018-01-09 14:35:19 -0800 | [diff] [blame] | 227 | @SystemApi |
| Ajay Panicker | bfcc00d | 2018-03-16 04:00:27 -0700 | [diff] [blame] | 228 | int PRIORITY_ON = 100; |
| Jaikumar Ganesh | 2af0776 | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 229 | |
| 230 | /** |
| 231 | * Default priority for devices that does not allow incoming |
| 232 | * connections and outgoing connections for the profile. |
| Jack He | 910201b | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 233 | * |
| Jaikumar Ganesh | 2af0776 | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 234 | * @hide |
| 235 | **/ |
| Selim Gurun | 9e6b35b | 2018-01-09 14:35:19 -0800 | [diff] [blame] | 236 | @SystemApi |
| Ajay Panicker | bfcc00d | 2018-03-16 04:00:27 -0700 | [diff] [blame] | 237 | int PRIORITY_OFF = 0; |
| Jaikumar Ganesh | 2af0776 | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 238 | |
| 239 | /** |
| 240 | * Default priority when not set or when the device is unpaired |
| Jack He | 910201b | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 241 | * |
| Jaikumar Ganesh | 2af0776 | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 242 | * @hide |
| Jack He | 910201b | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 243 | */ |
| Mathew Inwood | 7d54389 | 2018-08-01 15:07:20 +0100 | [diff] [blame] | 244 | @UnsupportedAppUsage |
| Ajay Panicker | bfcc00d | 2018-03-16 04:00:27 -0700 | [diff] [blame] | 245 | int PRIORITY_UNDEFINED = -1; |
| Jaikumar Ganesh | 2af0776 | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 246 | |
| 247 | /** |
| Jaikumar Ganesh | 2af0776 | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 248 | * Get connected devices for this specific profile. |
| 249 | * |
| 250 | * <p> Return the set of devices which are in state {@link #STATE_CONNECTED} |
| 251 | * |
| Jaikumar Ganesh | d8fc4dd | 2010-10-18 16:41:53 -0700 | [diff] [blame] | 252 | * @return List of devices. The list will be empty on error. |
| Jaikumar Ganesh | 2af0776 | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 253 | */ |
| Tor Norbye | 27ce6cf | 2015-04-23 17:10:21 -0700 | [diff] [blame] | 254 | @RequiresPermission(Manifest.permission.BLUETOOTH) |
| Jaikumar Ganesh | d8fc4dd | 2010-10-18 16:41:53 -0700 | [diff] [blame] | 255 | public List<BluetoothDevice> getConnectedDevices(); |
| Jaikumar Ganesh | 2af0776 | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 256 | |
| 257 | /** |
| Jaikumar Ganesh | b342757 | 2011-01-25 16:03:13 -0800 | [diff] [blame] | 258 | * Get a list of devices that match any of the given connection |
| Jaikumar Ganesh | 2af0776 | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 259 | * states. |
| 260 | * |
| Jaikumar Ganesh | b342757 | 2011-01-25 16:03:13 -0800 | [diff] [blame] | 261 | * <p> If none of the devices match any of the given states, |
| 262 | * an empty list will be returned. |
| Jaikumar Ganesh | 2af0776 | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 263 | * |
| Jack He | 910201b | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 264 | * @param states Array of states. States can be one of {@link #STATE_CONNECTED}, {@link |
| 265 | * #STATE_CONNECTING}, {@link #STATE_DISCONNECTED}, {@link #STATE_DISCONNECTING}, |
| Jaikumar Ganesh | d8fc4dd | 2010-10-18 16:41:53 -0700 | [diff] [blame] | 266 | * @return List of devices. The list will be empty on error. |
| Jaikumar Ganesh | 2af0776 | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 267 | */ |
| Tor Norbye | 27ce6cf | 2015-04-23 17:10:21 -0700 | [diff] [blame] | 268 | @RequiresPermission(Manifest.permission.BLUETOOTH) |
| Jaikumar Ganesh | d8fc4dd | 2010-10-18 16:41:53 -0700 | [diff] [blame] | 269 | public List<BluetoothDevice> getDevicesMatchingConnectionStates(int[] states); |
| Jaikumar Ganesh | 2af0776 | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 270 | |
| 271 | /** |
| 272 | * Get the current connection state of the profile |
| 273 | * |
| Jaikumar Ganesh | 2af0776 | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 274 | * @param device Remote bluetooth device. |
| Jack He | 910201b | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 275 | * @return State of the profile connection. One of {@link #STATE_CONNECTED}, {@link |
| 276 | * #STATE_CONNECTING}, {@link #STATE_DISCONNECTED}, {@link #STATE_DISCONNECTING} |
| Jaikumar Ganesh | 2af0776 | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 277 | */ |
| Tor Norbye | 27ce6cf | 2015-04-23 17:10:21 -0700 | [diff] [blame] | 278 | @RequiresPermission(Manifest.permission.BLUETOOTH) |
| Stanley Tng | a76ec8b | 2019-03-14 16:18:29 -0700 | [diff] [blame] | 279 | @BtProfileState int getConnectionState(BluetoothDevice device); |
| Jaikumar Ganesh | 2af0776 | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 280 | |
| 281 | /** |
| Jaikumar Ganesh | 2af0776 | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 282 | * 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 He | 910201b | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 289 | * |
| Jack He | 8bb9c7d | 2019-01-03 16:23:41 -0800 | [diff] [blame] | 290 | * @param profile - One of {@link #HEADSET} or {@link #A2DP} |
| 291 | * @param proxy - One of {@link BluetoothHeadset} or {@link BluetoothA2dp} |
| Jaikumar Ganesh | 2af0776 | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 292 | */ |
| 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 He | 910201b | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 298 | * |
| Jack He | 8bb9c7d | 2019-01-03 16:23:41 -0800 | [diff] [blame] | 299 | * @param profile - One of {@link #HEADSET} or {@link #A2DP} |
| Jaikumar Ganesh | 2af0776 | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 300 | */ |
| 301 | public void onServiceDisconnected(int profile); |
| 302 | } |
| Jack He | 93df940 | 2017-12-11 13:11:20 -0800 | [diff] [blame] | 303 | |
| 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 Yu | e521618 | 2019-07-22 15:56:23 +0800 | [diff] [blame^] | 327 | |
| 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 Ganesh | 2af0776 | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 377 | } |