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