| 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; |
| Rahul Sabnis | eeccce5 | 2019-11-19 14:54:25 -0800 | [diff] [blame] | 23 | import android.annotation.SuppressLint; |
| Selim Gurun | 9e6b35b | 2018-01-09 14:35:19 -0800 | [diff] [blame] | 24 | import android.annotation.SystemApi; |
| Artur Satayev | 3625be4 | 2019-12-10 17:47:52 +0000 | [diff] [blame] | 25 | import android.compat.annotation.UnsupportedAppUsage; |
| Mathew Inwood | 049f0f5 | 2020-11-04 09:29:36 +0000 | [diff] [blame] | 26 | import android.os.Build; |
| Tor Norbye | 27ce6cf | 2015-04-23 17:10:21 -0700 | [diff] [blame] | 27 | |
| Stanley Tng | a76ec8b | 2019-03-14 16:18:29 -0700 | [diff] [blame] | 28 | import java.lang.annotation.Retention; |
| 29 | import java.lang.annotation.RetentionPolicy; |
| Jaikumar Ganesh | d8fc4dd | 2010-10-18 16:41:53 -0700 | [diff] [blame] | 30 | import java.util.List; |
| Jaikumar Ganesh | 2af0776 | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 31 | |
| 32 | /** |
| 33 | * Public APIs for the Bluetooth Profiles. |
| 34 | * |
| 35 | * <p> Clients should call {@link BluetoothAdapter#getProfileProxy}, |
| 36 | * to get the Profile Proxy. Each public profile implements this |
| 37 | * interface. |
| 38 | */ |
| 39 | public interface BluetoothProfile { |
| 40 | |
| 41 | /** |
| 42 | * Extra for the connection state intents of the individual profiles. |
| 43 | * |
| 44 | * This extra represents the current connection state of the profile of the |
| 45 | * Bluetooth device. |
| 46 | */ |
| Rahul Sabnis | eeccce5 | 2019-11-19 14:54:25 -0800 | [diff] [blame] | 47 | @SuppressLint("ActionValue") |
| Ajay Panicker | bfcc00d | 2018-03-16 04:00:27 -0700 | [diff] [blame] | 48 | String EXTRA_STATE = "android.bluetooth.profile.extra.STATE"; |
| Jaikumar Ganesh | 2af0776 | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 49 | |
| 50 | /** |
| 51 | * Extra for the connection state intents of the individual profiles. |
| 52 | * |
| 53 | * This extra represents the previous connection state of the profile of the |
| 54 | * Bluetooth device. |
| 55 | */ |
| Rahul Sabnis | eeccce5 | 2019-11-19 14:54:25 -0800 | [diff] [blame] | 56 | @SuppressLint("ActionValue") |
| Ajay Panicker | bfcc00d | 2018-03-16 04:00:27 -0700 | [diff] [blame] | 57 | String EXTRA_PREVIOUS_STATE = |
| Jack He | 910201b | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 58 | "android.bluetooth.profile.extra.PREVIOUS_STATE"; |
| Jaikumar Ganesh | 2af0776 | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 59 | |
| 60 | /** The profile is in disconnected state */ |
| Ajay Panicker | bfcc00d | 2018-03-16 04:00:27 -0700 | [diff] [blame] | 61 | int STATE_DISCONNECTED = 0; |
| Jaikumar Ganesh | 2af0776 | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 62 | /** The profile is in connecting state */ |
| Ajay Panicker | bfcc00d | 2018-03-16 04:00:27 -0700 | [diff] [blame] | 63 | int STATE_CONNECTING = 1; |
| Jaikumar Ganesh | 2af0776 | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 64 | /** The profile is in connected state */ |
| Ajay Panicker | bfcc00d | 2018-03-16 04:00:27 -0700 | [diff] [blame] | 65 | int STATE_CONNECTED = 2; |
| Jaikumar Ganesh | 2af0776 | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 66 | /** The profile is in disconnecting state */ |
| Ajay Panicker | bfcc00d | 2018-03-16 04:00:27 -0700 | [diff] [blame] | 67 | int STATE_DISCONNECTING = 3; |
| Jaikumar Ganesh | 2af0776 | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 68 | |
| Stanley Tng | a76ec8b | 2019-03-14 16:18:29 -0700 | [diff] [blame] | 69 | /** @hide */ |
| 70 | @IntDef({ |
| 71 | STATE_DISCONNECTED, |
| 72 | STATE_CONNECTING, |
| 73 | STATE_CONNECTED, |
| 74 | STATE_DISCONNECTING, |
| 75 | }) |
| 76 | @Retention(RetentionPolicy.SOURCE) |
| 77 | public @interface BtProfileState {} |
| 78 | |
| Jaikumar Ganesh | 2af0776 | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 79 | /** |
| 80 | * Headset and Handsfree profile |
| 81 | */ |
| Ajay Panicker | bfcc00d | 2018-03-16 04:00:27 -0700 | [diff] [blame] | 82 | int HEADSET = 1; |
| Jaikumar Ganesh | 97f8ec4 | 2011-02-23 10:22:15 -0800 | [diff] [blame] | 83 | |
| Jaikumar Ganesh | 2af0776 | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 84 | /** |
| 85 | * A2DP profile. |
| 86 | */ |
| Ajay Panicker | bfcc00d | 2018-03-16 04:00:27 -0700 | [diff] [blame] | 87 | int A2DP = 2; |
| Jaikumar Ganesh | 97f8ec4 | 2011-02-23 10:22:15 -0800 | [diff] [blame] | 88 | |
| Jaikumar Ganesh | ad5d9c0 | 2011-02-18 14:52:32 -0800 | [diff] [blame] | 89 | /** |
| Jaikumar Ganesh | bf981ca | 2011-04-01 16:33:09 -0700 | [diff] [blame] | 90 | * Health Profile |
| Jack He | 8bb9c7d | 2019-01-03 16:23:41 -0800 | [diff] [blame] | 91 | * |
| 92 | * @deprecated Health Device Profile (HDP) and MCAP protocol are no longer used. New |
| 93 | * apps should use Bluetooth Low Energy based solutions such as {@link BluetoothGatt}, |
| 94 | * {@link BluetoothAdapter#listenUsingL2capChannel()}, or |
| 95 | * {@link BluetoothDevice#createL2capChannel(int)} |
| Jaikumar Ganesh | bf981ca | 2011-04-01 16:33:09 -0700 | [diff] [blame] | 96 | */ |
| Jack He | 8bb9c7d | 2019-01-03 16:23:41 -0800 | [diff] [blame] | 97 | @Deprecated |
| Ajay Panicker | bfcc00d | 2018-03-16 04:00:27 -0700 | [diff] [blame] | 98 | int HEALTH = 3; |
| Jaikumar Ganesh | bf981ca | 2011-04-01 16:33:09 -0700 | [diff] [blame] | 99 | |
| 100 | /** |
| Hansong Zhang | f076158 | 2017-10-20 15:55:59 -0700 | [diff] [blame] | 101 | * HID Host |
| Jack He | 910201b | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 102 | * |
| Jaikumar Ganesh | ad5d9c0 | 2011-02-18 14:52:32 -0800 | [diff] [blame] | 103 | * @hide |
| 104 | */ |
| Ajay Panicker | bfcc00d | 2018-03-16 04:00:27 -0700 | [diff] [blame] | 105 | int HID_HOST = 4; |
| Jaikumar Ganesh | 2af0776 | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 106 | |
| 107 | /** |
| Jaikumar Ganesh | 97f8ec4 | 2011-02-23 10:22:15 -0800 | [diff] [blame] | 108 | * PAN Profile |
| Jack He | 910201b | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 109 | * |
| Jaikumar Ganesh | 97f8ec4 | 2011-02-23 10:22:15 -0800 | [diff] [blame] | 110 | * @hide |
| 111 | */ |
| Rahul Sabnis | eeccce5 | 2019-11-19 14:54:25 -0800 | [diff] [blame] | 112 | @SystemApi |
| Ajay Panicker | bfcc00d | 2018-03-16 04:00:27 -0700 | [diff] [blame] | 113 | int PAN = 5; |
| Jaikumar Ganesh | 97f8ec4 | 2011-02-23 10:22:15 -0800 | [diff] [blame] | 114 | |
| 115 | /** |
| Jaikumar Ganesh | 5317842 | 2011-08-19 10:26:32 -0700 | [diff] [blame] | 116 | * PBAP |
| Jack He | 910201b | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 117 | * |
| Jaikumar Ganesh | 5317842 | 2011-08-19 10:26:32 -0700 | [diff] [blame] | 118 | * @hide |
| 119 | */ |
| Ajay Panicker | bfcc00d | 2018-03-16 04:00:27 -0700 | [diff] [blame] | 120 | int PBAP = 6; |
| Jaikumar Ganesh | 5317842 | 2011-08-19 10:26:32 -0700 | [diff] [blame] | 121 | |
| 122 | /** |
| Ganesh Ganapathi Batta | 40b9895 | 2013-02-05 15:28:33 -0800 | [diff] [blame] | 123 | * GATT |
| Ganesh Ganapathi Batta | 40b9895 | 2013-02-05 15:28:33 -0800 | [diff] [blame] | 124 | */ |
| Ajay Panicker | bfcc00d | 2018-03-16 04:00:27 -0700 | [diff] [blame] | 125 | int GATT = 7; |
| Ganesh Ganapathi Batta | 40b9895 | 2013-02-05 15:28:33 -0800 | [diff] [blame] | 126 | |
| 127 | /** |
| 128 | * GATT_SERVER |
| Ganesh Ganapathi Batta | 40b9895 | 2013-02-05 15:28:33 -0800 | [diff] [blame] | 129 | */ |
| Ajay Panicker | bfcc00d | 2018-03-16 04:00:27 -0700 | [diff] [blame] | 130 | int GATT_SERVER = 8; |
| Ganesh Ganapathi Batta | 40b9895 | 2013-02-05 15:28:33 -0800 | [diff] [blame] | 131 | |
| 132 | /** |
| Matthew Xie | ce14522 | 2013-07-18 17:31:50 -0700 | [diff] [blame] | 133 | * MAP Profile |
| Jack He | 910201b | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 134 | * |
| Matthew Xie | ce14522 | 2013-07-18 17:31:50 -0700 | [diff] [blame] | 135 | * @hide |
| 136 | */ |
| Ajay Panicker | bfcc00d | 2018-03-16 04:00:27 -0700 | [diff] [blame] | 137 | int MAP = 9; |
| Matthew Xie | ce14522 | 2013-07-18 17:31:50 -0700 | [diff] [blame] | 138 | |
| Casper Bonde | d8355fb | 2015-03-19 10:36:45 +0100 | [diff] [blame] | 139 | /* |
| 140 | * SAP Profile |
| 141 | * @hide |
| 142 | */ |
| Ajay Panicker | bfcc00d | 2018-03-16 04:00:27 -0700 | [diff] [blame] | 143 | int SAP = 10; |
| Casper Bonde | d8355fb | 2015-03-19 10:36:45 +0100 | [diff] [blame] | 144 | |
| Matthew Xie | ce14522 | 2013-07-18 17:31:50 -0700 | [diff] [blame] | 145 | /** |
| Mike Lockwood | a5e51db | 2014-05-21 10:08:50 -0700 | [diff] [blame] | 146 | * A2DP Sink Profile |
| Jack He | 910201b | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 147 | * |
| Mike Lockwood | a5e51db | 2014-05-21 10:08:50 -0700 | [diff] [blame] | 148 | * @hide |
| 149 | */ |
| Rahul Sabnis | 07f4803 | 2020-01-21 15:11:22 -0800 | [diff] [blame] | 150 | @SystemApi |
| Ajay Panicker | bfcc00d | 2018-03-16 04:00:27 -0700 | [diff] [blame] | 151 | int A2DP_SINK = 11; |
| Mike Lockwood | a5e51db | 2014-05-21 10:08:50 -0700 | [diff] [blame] | 152 | |
| 153 | /** |
| Mike Lockwood | 517b04f | 2014-06-02 16:20:37 -0700 | [diff] [blame] | 154 | * AVRCP Controller Profile |
| Jack He | 910201b | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 155 | * |
| Mike Lockwood | 517b04f | 2014-06-02 16:20:37 -0700 | [diff] [blame] | 156 | * @hide |
| 157 | */ |
| Rahul Sabnis | 07f4803 | 2020-01-21 15:11:22 -0800 | [diff] [blame] | 158 | @SystemApi |
| Ajay Panicker | bfcc00d | 2018-03-16 04:00:27 -0700 | [diff] [blame] | 159 | int AVRCP_CONTROLLER = 12; |
| 160 | |
| 161 | /** |
| 162 | * AVRCP Target Profile |
| 163 | * |
| 164 | * @hide |
| 165 | */ |
| 166 | int AVRCP = 13; |
| Mike Lockwood | 517b04f | 2014-06-02 16:20:37 -0700 | [diff] [blame] | 167 | |
| 168 | /** |
| Mike Lockwood | f48a727 | 2014-06-12 11:23:40 -0700 | [diff] [blame] | 169 | * Headset Client - HFP HF Role |
| Jack He | 910201b | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 170 | * |
| Hemant Gupta | 67a995a | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 171 | * @hide |
| 172 | */ |
| Rahul Sabnis | 07f4803 | 2020-01-21 15:11:22 -0800 | [diff] [blame] | 173 | @SystemApi |
| Ajay Panicker | bfcc00d | 2018-03-16 04:00:27 -0700 | [diff] [blame] | 174 | int HEADSET_CLIENT = 16; |
| Hemant Gupta | 67a995a | 2013-08-19 19:03:51 +0530 | [diff] [blame] | 175 | |
| 176 | /** |
| Joseph Pirozzo | 6f56b0f | 2016-03-04 13:02:54 -0800 | [diff] [blame] | 177 | * PBAP Client |
| Jack He | 910201b | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 178 | * |
| Joseph Pirozzo | 6f56b0f | 2016-03-04 13:02:54 -0800 | [diff] [blame] | 179 | * @hide |
| 180 | */ |
| Rahul Sabnis | 07f4803 | 2020-01-21 15:11:22 -0800 | [diff] [blame] | 181 | @SystemApi |
| Ajay Panicker | bfcc00d | 2018-03-16 04:00:27 -0700 | [diff] [blame] | 182 | int PBAP_CLIENT = 17; |
| Joseph Pirozzo | 6f56b0f | 2016-03-04 13:02:54 -0800 | [diff] [blame] | 183 | |
| 184 | /** |
| Joseph Pirozzo | 54d4b66 | 2016-09-01 14:19:28 -0700 | [diff] [blame] | 185 | * MAP Messaging Client Equipment (MCE) |
| Jack He | 910201b | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 186 | * |
| Joseph Pirozzo | 54d4b66 | 2016-09-01 14:19:28 -0700 | [diff] [blame] | 187 | * @hide |
| 188 | */ |
| Joseph Pirozzo | 1db9bd4 | 2021-01-21 11:22:44 -0800 | [diff] [blame] | 189 | @SystemApi |
| Ajay Panicker | bfcc00d | 2018-03-16 04:00:27 -0700 | [diff] [blame] | 190 | int MAP_CLIENT = 18; |
| Joseph Pirozzo | 54d4b66 | 2016-09-01 14:19:28 -0700 | [diff] [blame] | 191 | |
| 192 | /** |
| Hansong Zhang | f076158 | 2017-10-20 15:55:59 -0700 | [diff] [blame] | 193 | * HID Device |
| Hemant Gupta | 7d82a61 | 2014-04-18 11:22:45 +0530 | [diff] [blame] | 194 | */ |
| Ajay Panicker | bfcc00d | 2018-03-16 04:00:27 -0700 | [diff] [blame] | 195 | int HID_DEVICE = 19; |
| Hemant Gupta | 7d82a61 | 2014-04-18 11:22:45 +0530 | [diff] [blame] | 196 | |
| 197 | /** |
| Myles Watson | 3131897 | 2018-01-05 13:54:34 -0800 | [diff] [blame] | 198 | * Object Push Profile (OPP) |
| 199 | * |
| 200 | * @hide |
| 201 | */ |
| Ajay Panicker | bfcc00d | 2018-03-16 04:00:27 -0700 | [diff] [blame] | 202 | int OPP = 20; |
| Myles Watson | 3131897 | 2018-01-05 13:54:34 -0800 | [diff] [blame] | 203 | |
| 204 | /** |
| Jakub Pawlowski | 3f23873 | 2017-11-22 11:02:34 -0800 | [diff] [blame] | 205 | * Hearing Aid Device |
| 206 | * |
| Jakub Pawlowski | 3f23873 | 2017-11-22 11:02:34 -0800 | [diff] [blame] | 207 | */ |
| 208 | int HEARING_AID = 21; |
| 209 | |
| 210 | /** |
| Grzegorz Kołodziejczyk | 3b98ee1 | 2020-11-16 11:43:45 +0000 | [diff] [blame] | 211 | * LE Audio Device |
| 212 | * |
| Grzegorz Kołodziejczyk | 3b98ee1 | 2020-11-16 11:43:45 +0000 | [diff] [blame] | 213 | */ |
| 214 | int LE_AUDIO = 22; |
| 215 | |
| 216 | /** |
| Łukasz Rymanowski | 1b3ac77 | 2021-01-26 06:39:08 +0000 | [diff] [blame] | 217 | * Volume Control profile |
| 218 | * |
| Jakub Pawlowski | 3d3c696 | 2021-06-18 00:15:47 +0200 | [diff] [blame] | 219 | * @hide |
| Łukasz Rymanowski | 1b3ac77 | 2021-01-26 06:39:08 +0000 | [diff] [blame] | 220 | */ |
| Jakub Pawlowski | 3d3c696 | 2021-06-18 00:15:47 +0200 | [diff] [blame] | 221 | @SystemApi |
| Łukasz Rymanowski | 1b3ac77 | 2021-01-26 06:39:08 +0000 | [diff] [blame] | 222 | int VOLUME_CONTROL = 23; |
| 223 | |
| 224 | /** |
| Jakub Tyszkowski | bedd831 | 2021-03-01 13:02:25 +0000 | [diff] [blame^] | 225 | * @hide |
| 226 | * Media Control Profile server |
| 227 | * |
| 228 | */ |
| 229 | int MCP_SERVER = 24; |
| 230 | |
| 231 | /** |
| Bryce Lee | ff5093b | 2016-10-09 12:54:42 -0700 | [diff] [blame] | 232 | * Max profile ID. This value should be updated whenever a new profile is added to match |
| 233 | * the largest value assigned to a profile. |
| Jack He | 910201b | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 234 | * |
| Bryce Lee | ff5093b | 2016-10-09 12:54:42 -0700 | [diff] [blame] | 235 | * @hide |
| 236 | */ |
| Jakub Tyszkowski | bedd831 | 2021-03-01 13:02:25 +0000 | [diff] [blame^] | 237 | int MAX_PROFILE_ID = 24; |
| Bryce Lee | ff5093b | 2016-10-09 12:54:42 -0700 | [diff] [blame] | 238 | |
| 239 | /** |
| Jaikumar Ganesh | 2af0776 | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 240 | * Default priority for devices that we try to auto-connect to and |
| 241 | * and allow incoming connections for the profile |
| Jack He | 910201b | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 242 | * |
| Jaikumar Ganesh | 2af0776 | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 243 | * @hide |
| 244 | **/ |
| Mathew Inwood | 049f0f5 | 2020-11-04 09:29:36 +0000 | [diff] [blame] | 245 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) |
| Ajay Panicker | bfcc00d | 2018-03-16 04:00:27 -0700 | [diff] [blame] | 246 | int PRIORITY_AUTO_CONNECT = 1000; |
| Jaikumar Ganesh | 2af0776 | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 247 | |
| 248 | /** |
| Jack He | 910201b | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 249 | * Default priority for devices that allow incoming |
| Jaikumar Ganesh | 2af0776 | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 250 | * and outgoing connections for the profile |
| Jack He | 910201b | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 251 | * |
| Jaikumar Ganesh | 2af0776 | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 252 | * @hide |
| Rahul Sabnis | e8bac9b | 2019-11-27 18:09:33 -0800 | [diff] [blame] | 253 | * @deprecated Replaced with {@link #CONNECTION_POLICY_ALLOWED} |
| Jaikumar Ganesh | 2af0776 | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 254 | **/ |
| Rahul Sabnis | e8bac9b | 2019-11-27 18:09:33 -0800 | [diff] [blame] | 255 | @Deprecated |
| Selim Gurun | 9e6b35b | 2018-01-09 14:35:19 -0800 | [diff] [blame] | 256 | @SystemApi |
| Ajay Panicker | bfcc00d | 2018-03-16 04:00:27 -0700 | [diff] [blame] | 257 | int PRIORITY_ON = 100; |
| Jaikumar Ganesh | 2af0776 | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 258 | |
| 259 | /** |
| 260 | * Default priority for devices that does not allow incoming |
| 261 | * connections and outgoing connections for the profile. |
| Jack He | 910201b | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 262 | * |
| Jaikumar Ganesh | 2af0776 | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 263 | * @hide |
| Rahul Sabnis | e8bac9b | 2019-11-27 18:09:33 -0800 | [diff] [blame] | 264 | * @deprecated Replaced with {@link #CONNECTION_POLICY_FORBIDDEN} |
| Jaikumar Ganesh | 2af0776 | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 265 | **/ |
| Rahul Sabnis | e8bac9b | 2019-11-27 18:09:33 -0800 | [diff] [blame] | 266 | @Deprecated |
| Selim Gurun | 9e6b35b | 2018-01-09 14:35:19 -0800 | [diff] [blame] | 267 | @SystemApi |
| Ajay Panicker | bfcc00d | 2018-03-16 04:00:27 -0700 | [diff] [blame] | 268 | int PRIORITY_OFF = 0; |
| Jaikumar Ganesh | 2af0776 | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 269 | |
| 270 | /** |
| 271 | * Default priority when not set or when the device is unpaired |
| Jack He | 910201b | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 272 | * |
| Jaikumar Ganesh | 2af0776 | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 273 | * @hide |
| Jack He | 910201b | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 274 | */ |
| Mathew Inwood | 7d54389 | 2018-08-01 15:07:20 +0100 | [diff] [blame] | 275 | @UnsupportedAppUsage |
| Ajay Panicker | bfcc00d | 2018-03-16 04:00:27 -0700 | [diff] [blame] | 276 | int PRIORITY_UNDEFINED = -1; |
| Jaikumar Ganesh | 2af0776 | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 277 | |
| Rahul Sabnis | e8bac9b | 2019-11-27 18:09:33 -0800 | [diff] [blame] | 278 | /** @hide */ |
| 279 | @IntDef(prefix = "CONNECTION_POLICY_", value = {CONNECTION_POLICY_ALLOWED, |
| 280 | CONNECTION_POLICY_FORBIDDEN, CONNECTION_POLICY_UNKNOWN}) |
| 281 | @Retention(RetentionPolicy.SOURCE) |
| 282 | public @interface ConnectionPolicy{} |
| 283 | |
| 284 | /** |
| 285 | * Default connection policy for devices that allow incoming and outgoing connections |
| 286 | * for the profile |
| 287 | * |
| 288 | * @hide |
| 289 | **/ |
| 290 | @SystemApi |
| 291 | int CONNECTION_POLICY_ALLOWED = 100; |
| 292 | |
| 293 | /** |
| 294 | * Default connection policy for devices that do not allow incoming or outgoing connections |
| 295 | * for the profile. |
| 296 | * |
| 297 | * @hide |
| 298 | **/ |
| 299 | @SystemApi |
| 300 | int CONNECTION_POLICY_FORBIDDEN = 0; |
| 301 | |
| 302 | /** |
| 303 | * Default connection policy when not set or when the device is unpaired |
| 304 | * |
| 305 | * @hide |
| 306 | */ |
| 307 | @SystemApi |
| 308 | int CONNECTION_POLICY_UNKNOWN = -1; |
| 309 | |
| Jaikumar Ganesh | 2af0776 | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 310 | /** |
| Jaikumar Ganesh | 2af0776 | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 311 | * Get connected devices for this specific profile. |
| 312 | * |
| 313 | * <p> Return the set of devices which are in state {@link #STATE_CONNECTED} |
| 314 | * |
| Jaikumar Ganesh | d8fc4dd | 2010-10-18 16:41:53 -0700 | [diff] [blame] | 315 | * @return List of devices. The list will be empty on error. |
| Jaikumar Ganesh | 2af0776 | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 316 | */ |
| Tor Norbye | 27ce6cf | 2015-04-23 17:10:21 -0700 | [diff] [blame] | 317 | @RequiresPermission(Manifest.permission.BLUETOOTH) |
| Jaikumar Ganesh | d8fc4dd | 2010-10-18 16:41:53 -0700 | [diff] [blame] | 318 | public List<BluetoothDevice> getConnectedDevices(); |
| Jaikumar Ganesh | 2af0776 | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 319 | |
| 320 | /** |
| Jaikumar Ganesh | b342757 | 2011-01-25 16:03:13 -0800 | [diff] [blame] | 321 | * Get a list of devices that match any of the given connection |
| Jaikumar Ganesh | 2af0776 | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 322 | * states. |
| 323 | * |
| Jaikumar Ganesh | b342757 | 2011-01-25 16:03:13 -0800 | [diff] [blame] | 324 | * <p> If none of the devices match any of the given states, |
| 325 | * an empty list will be returned. |
| Jaikumar Ganesh | 2af0776 | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 326 | * |
| Jack He | 910201b | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 327 | * @param states Array of states. States can be one of {@link #STATE_CONNECTED}, {@link |
| 328 | * #STATE_CONNECTING}, {@link #STATE_DISCONNECTED}, {@link #STATE_DISCONNECTING}, |
| Jaikumar Ganesh | d8fc4dd | 2010-10-18 16:41:53 -0700 | [diff] [blame] | 329 | * @return List of devices. The list will be empty on error. |
| Jaikumar Ganesh | 2af0776 | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 330 | */ |
| Tor Norbye | 27ce6cf | 2015-04-23 17:10:21 -0700 | [diff] [blame] | 331 | @RequiresPermission(Manifest.permission.BLUETOOTH) |
| Jaikumar Ganesh | d8fc4dd | 2010-10-18 16:41:53 -0700 | [diff] [blame] | 332 | public List<BluetoothDevice> getDevicesMatchingConnectionStates(int[] states); |
| Jaikumar Ganesh | 2af0776 | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 333 | |
| 334 | /** |
| 335 | * Get the current connection state of the profile |
| 336 | * |
| Jaikumar Ganesh | 2af0776 | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 337 | * @param device Remote bluetooth device. |
| Jack He | 910201b | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 338 | * @return State of the profile connection. One of {@link #STATE_CONNECTED}, {@link |
| 339 | * #STATE_CONNECTING}, {@link #STATE_DISCONNECTED}, {@link #STATE_DISCONNECTING} |
| Jaikumar Ganesh | 2af0776 | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 340 | */ |
| Tor Norbye | 27ce6cf | 2015-04-23 17:10:21 -0700 | [diff] [blame] | 341 | @RequiresPermission(Manifest.permission.BLUETOOTH) |
| Stanley Tng | a76ec8b | 2019-03-14 16:18:29 -0700 | [diff] [blame] | 342 | @BtProfileState int getConnectionState(BluetoothDevice device); |
| Jaikumar Ganesh | 2af0776 | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 343 | |
| 344 | /** |
| Jaikumar Ganesh | 2af0776 | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 345 | * An interface for notifying BluetoothProfile IPC clients when they have |
| 346 | * been connected or disconnected to the service. |
| 347 | */ |
| 348 | public interface ServiceListener { |
| 349 | /** |
| 350 | * Called to notify the client when the proxy object has been |
| 351 | * connected to the service. |
| Jack He | 910201b | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 352 | * |
| Jack He | 8bb9c7d | 2019-01-03 16:23:41 -0800 | [diff] [blame] | 353 | * @param profile - One of {@link #HEADSET} or {@link #A2DP} |
| 354 | * @param proxy - One of {@link BluetoothHeadset} or {@link BluetoothA2dp} |
| Jaikumar Ganesh | 2af0776 | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 355 | */ |
| 356 | public void onServiceConnected(int profile, BluetoothProfile proxy); |
| 357 | |
| 358 | /** |
| 359 | * Called to notify the client that this proxy object has been |
| 360 | * disconnected from the service. |
| Jack He | 910201b | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 361 | * |
| Jack He | 8bb9c7d | 2019-01-03 16:23:41 -0800 | [diff] [blame] | 362 | * @param profile - One of {@link #HEADSET} or {@link #A2DP} |
| Jaikumar Ganesh | 2af0776 | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 363 | */ |
| 364 | public void onServiceDisconnected(int profile); |
| 365 | } |
| Jack He | 93df940 | 2017-12-11 13:11:20 -0800 | [diff] [blame] | 366 | |
| 367 | /** |
| 368 | * Convert an integer value of connection state into human readable string |
| 369 | * |
| 370 | * @param connectionState - One of {@link #STATE_DISCONNECTED}, {@link #STATE_CONNECTING}, |
| 371 | * {@link #STATE_CONNECTED}, or {@link #STATE_DISCONNECTED} |
| 372 | * @return a string representation of the connection state, STATE_UNKNOWN if the state |
| 373 | * is not defined |
| 374 | * @hide |
| 375 | */ |
| 376 | static String getConnectionStateName(int connectionState) { |
| 377 | switch (connectionState) { |
| 378 | case STATE_DISCONNECTED: |
| 379 | return "STATE_DISCONNECTED"; |
| 380 | case STATE_CONNECTING: |
| 381 | return "STATE_CONNECTING"; |
| 382 | case STATE_CONNECTED: |
| 383 | return "STATE_CONNECTED"; |
| 384 | case STATE_DISCONNECTING: |
| 385 | return "STATE_DISCONNECTING"; |
| 386 | default: |
| 387 | return "STATE_UNKNOWN"; |
| 388 | } |
| 389 | } |
| Ugo Yu | e521618 | 2019-07-22 15:56:23 +0800 | [diff] [blame] | 390 | |
| 391 | /** |
| 392 | * Convert an integer value of profile ID into human readable string |
| 393 | * |
| 394 | * @param profile profile ID |
| 395 | * @return profile name as String, UNKOWN_PROFILE if the profile ID is not defined. |
| 396 | * @hide |
| 397 | */ |
| 398 | static String getProfileName(int profile) { |
| 399 | switch(profile) { |
| 400 | case HEADSET: |
| 401 | return "HEADSET"; |
| 402 | case A2DP: |
| 403 | return "A2DP"; |
| 404 | case HID_HOST: |
| 405 | return "HID_HOST"; |
| 406 | case PAN: |
| 407 | return "PAN"; |
| 408 | case PBAP: |
| 409 | return "PBAP"; |
| 410 | case GATT: |
| 411 | return "GATT"; |
| 412 | case GATT_SERVER: |
| 413 | return "GATT_SERVER"; |
| 414 | case MAP: |
| 415 | return "MAP"; |
| 416 | case SAP: |
| 417 | return "SAP"; |
| 418 | case A2DP_SINK: |
| 419 | return "A2DP_SINK"; |
| 420 | case AVRCP_CONTROLLER: |
| 421 | return "AVRCP_CONTROLLER"; |
| 422 | case AVRCP: |
| 423 | return "AVRCP"; |
| 424 | case HEADSET_CLIENT: |
| 425 | return "HEADSET_CLIENT"; |
| 426 | case PBAP_CLIENT: |
| 427 | return "PBAP_CLIENT"; |
| 428 | case MAP_CLIENT: |
| 429 | return "MAP_CLIENT"; |
| 430 | case HID_DEVICE: |
| 431 | return "HID_DEVICE"; |
| 432 | case OPP: |
| 433 | return "OPP"; |
| 434 | case HEARING_AID: |
| 435 | return "HEARING_AID"; |
| 436 | default: |
| 437 | return "UNKNOWN_PROFILE"; |
| 438 | } |
| 439 | } |
| Jaikumar Ganesh | 2af0776 | 2010-08-24 17:36:13 -0700 | [diff] [blame] | 440 | } |