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