blob: fe7c5d7a36bb46755da643829baece7e1530ef0d [file] [log] [blame]
Jaikumar Ganesh2af07762010-08-24 17:36:13 -07001/*
Joseph Pirozzo54d4b662016-09-01 14:19:28 -07002 * Copyright (C) 2010-2016 The Android Open Source Project
Jaikumar Ganesh2af07762010-08-24 17:36:13 -07003 *
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 Ganesh2af07762010-08-24 17:36:13 -070017package android.bluetooth;
18
Stanley Tnga76ec8b2019-03-14 16:18:29 -070019import android.annotation.IntDef;
William Escande3f38e422022-01-27 13:42:05 +010020import android.annotation.NonNull;
Jeff Sharkey5ba8bfc2021-04-16 09:53:23 -060021import android.annotation.RequiresNoPermission;
Rahul Sabniseeccce52019-11-19 14:54:25 -080022import android.annotation.SuppressLint;
Selim Gurun9e6b35b2018-01-09 14:35:19 -080023import android.annotation.SystemApi;
Artur Satayev3625be42019-12-10 17:47:52 +000024import android.compat.annotation.UnsupportedAppUsage;
Mathew Inwood049f0f52020-11-04 09:29:36 +000025import android.os.Build;
David Duartef5b3bc52023-10-17 00:55:06 +000026import android.os.IBinder;
Tor Norbye27ce6cf2015-04-23 17:10:21 -070027
Stanley Tnga76ec8b2019-03-14 16:18:29 -070028import java.lang.annotation.Retention;
29import java.lang.annotation.RetentionPolicy;
Jaikumar Ganeshd8fc4dd2010-10-18 16:41:53 -070030import java.util.List;
Jaikumar Ganesh2af07762010-08-24 17:36:13 -070031
32/**
33 * Public APIs for the Bluetooth Profiles.
34 *
David Duarteee52b7e2023-12-02 01:32:11 +000035 * <p>Clients should call {@link BluetoothAdapter#getProfileProxy}, to get the Profile Proxy. Each
36 * public profile implements this interface.
Jaikumar Ganesh2af07762010-08-24 17:36:13 -070037 */
38public interface BluetoothProfile {
39
40 /**
41 * Extra for the connection state intents of the individual profiles.
42 *
David Duarteee52b7e2023-12-02 01:32:11 +000043 * <p>This extra represents the current connection state of the profile of the Bluetooth device.
Jaikumar Ganesh2af07762010-08-24 17:36:13 -070044 */
Rahul Sabniseeccce52019-11-19 14:54:25 -080045 @SuppressLint("ActionValue")
Ajay Panickerbfcc00d2018-03-16 04:00:27 -070046 String EXTRA_STATE = "android.bluetooth.profile.extra.STATE";
Jaikumar Ganesh2af07762010-08-24 17:36:13 -070047
48 /**
49 * Extra for the connection state intents of the individual profiles.
50 *
David Duarteee52b7e2023-12-02 01:32:11 +000051 * <p>This extra represents the previous connection state of the profile of the Bluetooth
52 * device.
Jaikumar Ganesh2af07762010-08-24 17:36:13 -070053 */
Rahul Sabniseeccce52019-11-19 14:54:25 -080054 @SuppressLint("ActionValue")
David Duarteee52b7e2023-12-02 01:32:11 +000055 String EXTRA_PREVIOUS_STATE = "android.bluetooth.profile.extra.PREVIOUS_STATE";
Jaikumar Ganesh2af07762010-08-24 17:36:13 -070056
57 /** The profile is in disconnected state */
Ajay Panickerbfcc00d2018-03-16 04:00:27 -070058 int STATE_DISCONNECTED = 0;
David Duarteee52b7e2023-12-02 01:32:11 +000059
Jaikumar Ganesh2af07762010-08-24 17:36:13 -070060 /** The profile is in connecting state */
Ajay Panickerbfcc00d2018-03-16 04:00:27 -070061 int STATE_CONNECTING = 1;
David Duarteee52b7e2023-12-02 01:32:11 +000062
Jaikumar Ganesh2af07762010-08-24 17:36:13 -070063 /** The profile is in connected state */
Ajay Panickerbfcc00d2018-03-16 04:00:27 -070064 int STATE_CONNECTED = 2;
David Duarteee52b7e2023-12-02 01:32:11 +000065
Jaikumar Ganesh2af07762010-08-24 17:36:13 -070066 /** The profile is in disconnecting state */
Ajay Panickerbfcc00d2018-03-16 04:00:27 -070067 int STATE_DISCONNECTING = 3;
Jaikumar Ganesh2af07762010-08-24 17:36:13 -070068
Stanley Tnga76ec8b2019-03-14 16:18:29 -070069 /** @hide */
70 @IntDef({
David Duarteee52b7e2023-12-02 01:32:11 +000071 STATE_DISCONNECTED,
72 STATE_CONNECTING,
73 STATE_CONNECTED,
74 STATE_DISCONNECTING,
Stanley Tnga76ec8b2019-03-14 16:18:29 -070075 })
76 @Retention(RetentionPolicy.SOURCE)
77 public @interface BtProfileState {}
78
David Duarteee52b7e2023-12-02 01:32:11 +000079 /** Headset and Handsfree profile */
Ajay Panickerbfcc00d2018-03-16 04:00:27 -070080 int HEADSET = 1;
Jaikumar Ganesh97f8ec42011-02-23 10:22:15 -080081
David Duarteee52b7e2023-12-02 01:32:11 +000082 /** A2DP profile. */
Ajay Panickerbfcc00d2018-03-16 04:00:27 -070083 int A2DP = 2;
Jaikumar Ganesh97f8ec42011-02-23 10:22:15 -080084
Jaikumar Ganeshad5d9c02011-02-18 14:52:32 -080085 /**
Jaikumar Ganeshbf981ca2011-04-01 16:33:09 -070086 * Health Profile
Jack He8bb9c7d2019-01-03 16:23:41 -080087 *
David Duarteee52b7e2023-12-02 01:32:11 +000088 * @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 Ganeshbf981ca2011-04-01 16:33:09 -070092 */
David Duarteee52b7e2023-12-02 01:32:11 +000093 @Deprecated int HEALTH = 3;
Jaikumar Ganeshbf981ca2011-04-01 16:33:09 -070094
95 /**
Hansong Zhangf0761582017-10-20 15:55:59 -070096 * HID Host
Jack He910201b2017-08-22 16:06:54 -070097 *
Jaikumar Ganeshad5d9c02011-02-18 14:52:32 -080098 * @hide
99 */
David Duarteee52b7e2023-12-02 01:32:11 +0000100 @SystemApi int HID_HOST = 4;
Jaikumar Ganesh2af07762010-08-24 17:36:13 -0700101
102 /**
Jaikumar Ganesh97f8ec42011-02-23 10:22:15 -0800103 * PAN Profile
Jack He910201b2017-08-22 16:06:54 -0700104 *
Jaikumar Ganesh97f8ec42011-02-23 10:22:15 -0800105 * @hide
106 */
David Duarteee52b7e2023-12-02 01:32:11 +0000107 @SystemApi int PAN = 5;
Jaikumar Ganesh97f8ec42011-02-23 10:22:15 -0800108
109 /**
Jaikumar Ganesh53178422011-08-19 10:26:32 -0700110 * PBAP
Jack He910201b2017-08-22 16:06:54 -0700111 *
Jaikumar Ganesh53178422011-08-19 10:26:32 -0700112 * @hide
113 */
David Duarteee52b7e2023-12-02 01:32:11 +0000114 @SystemApi int PBAP = 6;
Jaikumar Ganesh53178422011-08-19 10:26:32 -0700115
David Duarteee52b7e2023-12-02 01:32:11 +0000116 /** GATT */
Ajay Panickerbfcc00d2018-03-16 04:00:27 -0700117 int GATT = 7;
Ganesh Ganapathi Batta40b98952013-02-05 15:28:33 -0800118
David Duarteee52b7e2023-12-02 01:32:11 +0000119 /** GATT_SERVER */
Ajay Panickerbfcc00d2018-03-16 04:00:27 -0700120 int GATT_SERVER = 8;
Ganesh Ganapathi Batta40b98952013-02-05 15:28:33 -0800121
122 /**
Matthew Xiece145222013-07-18 17:31:50 -0700123 * MAP Profile
Jack He910201b2017-08-22 16:06:54 -0700124 *
Matthew Xiece145222013-07-18 17:31:50 -0700125 * @hide
126 */
David Duarteee52b7e2023-12-02 01:32:11 +0000127 @SystemApi int MAP = 9;
Matthew Xiece145222013-07-18 17:31:50 -0700128
Casper Bonded8355fb2015-03-19 10:36:45 +0100129 /*
130 * SAP Profile
131 * @hide
132 */
Ajay Panickerbfcc00d2018-03-16 04:00:27 -0700133 int SAP = 10;
Casper Bonded8355fb2015-03-19 10:36:45 +0100134
Matthew Xiece145222013-07-18 17:31:50 -0700135 /**
Mike Lockwooda5e51db2014-05-21 10:08:50 -0700136 * A2DP Sink Profile
Jack He910201b2017-08-22 16:06:54 -0700137 *
Mike Lockwooda5e51db2014-05-21 10:08:50 -0700138 * @hide
139 */
David Duarteee52b7e2023-12-02 01:32:11 +0000140 @SystemApi int A2DP_SINK = 11;
Mike Lockwooda5e51db2014-05-21 10:08:50 -0700141
142 /**
Mike Lockwood517b04f2014-06-02 16:20:37 -0700143 * AVRCP Controller Profile
Jack He910201b2017-08-22 16:06:54 -0700144 *
Mike Lockwood517b04f2014-06-02 16:20:37 -0700145 * @hide
146 */
David Duarteee52b7e2023-12-02 01:32:11 +0000147 @SystemApi int AVRCP_CONTROLLER = 12;
Ajay Panickerbfcc00d2018-03-16 04:00:27 -0700148
149 /**
150 * AVRCP Target Profile
151 *
152 * @hide
153 */
154 int AVRCP = 13;
Mike Lockwood517b04f2014-06-02 16:20:37 -0700155
156 /**
Mike Lockwoodf48a7272014-06-12 11:23:40 -0700157 * Headset Client - HFP HF Role
Jack He910201b2017-08-22 16:06:54 -0700158 *
Hemant Gupta67a995a2013-08-19 19:03:51 +0530159 * @hide
160 */
David Duarteee52b7e2023-12-02 01:32:11 +0000161 @SystemApi int HEADSET_CLIENT = 16;
Hemant Gupta67a995a2013-08-19 19:03:51 +0530162
163 /**
Joseph Pirozzo6f56b0f2016-03-04 13:02:54 -0800164 * PBAP Client
Jack He910201b2017-08-22 16:06:54 -0700165 *
Joseph Pirozzo6f56b0f2016-03-04 13:02:54 -0800166 * @hide
167 */
David Duarteee52b7e2023-12-02 01:32:11 +0000168 @SystemApi int PBAP_CLIENT = 17;
Joseph Pirozzo6f56b0f2016-03-04 13:02:54 -0800169
170 /**
Joseph Pirozzo54d4b662016-09-01 14:19:28 -0700171 * MAP Messaging Client Equipment (MCE)
Jack He910201b2017-08-22 16:06:54 -0700172 *
Joseph Pirozzo54d4b662016-09-01 14:19:28 -0700173 * @hide
174 */
David Duarteee52b7e2023-12-02 01:32:11 +0000175 @SystemApi int MAP_CLIENT = 18;
Joseph Pirozzo54d4b662016-09-01 14:19:28 -0700176
David Duarteee52b7e2023-12-02 01:32:11 +0000177 /** HID Device */
Ajay Panickerbfcc00d2018-03-16 04:00:27 -0700178 int HID_DEVICE = 19;
Hemant Gupta7d82a612014-04-18 11:22:45 +0530179
180 /**
Myles Watson31318972018-01-05 13:54:34 -0800181 * Object Push Profile (OPP)
182 *
183 * @hide
184 */
David Duarteee52b7e2023-12-02 01:32:11 +0000185 @SystemApi int OPP = 20;
Myles Watson31318972018-01-05 13:54:34 -0800186
David Duarteee52b7e2023-12-02 01:32:11 +0000187 /** Hearing Aid Device */
Jakub Pawlowski3f238732017-11-22 11:02:34 -0800188 int HEARING_AID = 21;
189
David Duarteee52b7e2023-12-02 01:32:11 +0000190 /** LE Audio Device */
Grzegorz Kołodziejczyk3b98ee12020-11-16 11:43:45 +0000191 int LE_AUDIO = 22;
192
193 /**
Łukasz Rymanowski1b3ac772021-01-26 06:39:08 +0000194 * Volume Control profile
195 *
Jakub Pawlowski807fd1c2021-06-18 00:09:00 +0200196 * @hide
Łukasz Rymanowski1b3ac772021-01-26 06:39:08 +0000197 */
David Duarteee52b7e2023-12-02 01:32:11 +0000198 @SystemApi int VOLUME_CONTROL = 23;
Łukasz Rymanowski1b3ac772021-01-26 06:39:08 +0000199
200 /**
David Duarteee52b7e2023-12-02 01:32:11 +0000201 * @hide Media Control Profile server
Jakub Tyszkowskibedd8312021-03-01 13:02:25 +0000202 */
203 int MCP_SERVER = 24;
204
David Duarteee52b7e2023-12-02 01:32:11 +0000205 /** Coordinated Set Identification Profile set coordinator */
Łukasz Rymanowskifd45c862021-08-23 12:01:47 +0000206 int CSIP_SET_COORDINATOR = 25;
207
208 /**
Qasim Javed2eb043e2021-11-04 12:57:33 -0700209 * LE Audio Broadcast Source
210 *
211 * @hide
212 */
David Duarteee52b7e2023-12-02 01:32:11 +0000213 @SystemApi int LE_AUDIO_BROADCAST = 26;
Qasim Javed2eb043e2021-11-04 12:57:33 -0700214
215 /**
David Duarteee52b7e2023-12-02 01:32:11 +0000216 * @hide Telephone Bearer Service from Call Control Profile
Mariusz Skamra90bd6512020-11-17 09:11:17 +0000217 */
218 int LE_CALL_CONTROL = 27;
219
Jakub Tyszkowski6631a042021-11-05 09:51:04 +0000220 /*
221 * Hearing Access Profile Client
222 *
223 */
224 int HAP_CLIENT = 28;
225
Mariusz Skamra90bd6512020-11-17 09:11:17 +0000226 /**
Jack Hea0143142021-12-15 15:40:34 -0800227 * LE Audio Broadcast Assistant
228 *
229 * @hide
230 */
David Duarteee52b7e2023-12-02 01:32:11 +0000231 @SystemApi int LE_AUDIO_BROADCAST_ASSISTANT = 29;
Jack Hea0143142021-12-15 15:40:34 -0800232
233 /**
Kyunglyul Hyun6ff79412022-01-17 19:04:19 +0900234 * Battery Service
235 *
236 * @hide
237 */
238 int BATTERY = 30;
239
240 /**
David Duarteee52b7e2023-12-02 01:32:11 +0000241 * 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 He910201b2017-08-22 16:06:54 -0700243 *
Bryce Leeff5093b2016-10-09 12:54:42 -0700244 * @hide
245 */
Kyunglyul Hyun6ff79412022-01-17 19:04:19 +0900246 int MAX_PROFILE_ID = 30;
Bryce Leeff5093b2016-10-09 12:54:42 -0700247
248 /**
David Duarte1c07fc72023-12-02 02:08:08 +0000249 * Default priority for devices that we try to auto-connect to and allow incoming connections
250 * for the profile
Jack He910201b2017-08-22 16:06:54 -0700251 *
Jaikumar Ganesh2af07762010-08-24 17:36:13 -0700252 * @hide
David Duarteee52b7e2023-12-02 01:32:11 +0000253 */
Mathew Inwood049f0f52020-11-04 09:29:36 +0000254 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
Ajay Panickerbfcc00d2018-03-16 04:00:27 -0700255 int PRIORITY_AUTO_CONNECT = 1000;
Jaikumar Ganesh2af07762010-08-24 17:36:13 -0700256
257 /**
David Duarteee52b7e2023-12-02 01:32:11 +0000258 * Default priority for devices that allow incoming and outgoing connections for the profile
Jack He910201b2017-08-22 16:06:54 -0700259 *
Jaikumar Ganesh2af07762010-08-24 17:36:13 -0700260 * @hide
Rahul Sabnise8bac9b2019-11-27 18:09:33 -0800261 * @deprecated Replaced with {@link #CONNECTION_POLICY_ALLOWED}
David Duarteee52b7e2023-12-02 01:32:11 +0000262 */
263 @Deprecated @SystemApi int PRIORITY_ON = 100;
Jaikumar Ganesh2af07762010-08-24 17:36:13 -0700264
265 /**
David Duarteee52b7e2023-12-02 01:32:11 +0000266 * Default priority for devices that does not allow incoming connections and outgoing
267 * connections for the profile.
Jack He910201b2017-08-22 16:06:54 -0700268 *
Jaikumar Ganesh2af07762010-08-24 17:36:13 -0700269 * @hide
Rahul Sabnise8bac9b2019-11-27 18:09:33 -0800270 * @deprecated Replaced with {@link #CONNECTION_POLICY_FORBIDDEN}
David Duarteee52b7e2023-12-02 01:32:11 +0000271 */
272 @Deprecated @SystemApi int PRIORITY_OFF = 0;
Jaikumar Ganesh2af07762010-08-24 17:36:13 -0700273
274 /**
275 * Default priority when not set or when the device is unpaired
Jack He910201b2017-08-22 16:06:54 -0700276 *
Jaikumar Ganesh2af07762010-08-24 17:36:13 -0700277 * @hide
Jack He910201b2017-08-22 16:06:54 -0700278 */
David Duarteee52b7e2023-12-02 01:32:11 +0000279 @UnsupportedAppUsage int PRIORITY_UNDEFINED = -1;
Jaikumar Ganesh2af07762010-08-24 17:36:13 -0700280
Rahul Sabnise8bac9b2019-11-27 18:09:33 -0800281 /** @hide */
David Duarteee52b7e2023-12-02 01:32:11 +0000282 @IntDef(
283 prefix = "CONNECTION_POLICY_",
284 value = {
285 CONNECTION_POLICY_ALLOWED,
286 CONNECTION_POLICY_FORBIDDEN,
287 CONNECTION_POLICY_UNKNOWN
288 })
Rahul Sabnise8bac9b2019-11-27 18:09:33 -0800289 @Retention(RetentionPolicy.SOURCE)
David Duarteee52b7e2023-12-02 01:32:11 +0000290 public @interface ConnectionPolicy {}
Rahul Sabnise8bac9b2019-11-27 18:09:33 -0800291
292 /**
David Duarteee52b7e2023-12-02 01:32:11 +0000293 * Default connection policy for devices that allow incoming and outgoing connections for the
294 * profile
Rahul Sabnise8bac9b2019-11-27 18:09:33 -0800295 *
296 * @hide
David Duarteee52b7e2023-12-02 01:32:11 +0000297 */
298 @SystemApi int CONNECTION_POLICY_ALLOWED = 100;
Rahul Sabnise8bac9b2019-11-27 18:09:33 -0800299
300 /**
David Duarteee52b7e2023-12-02 01:32:11 +0000301 * Default connection policy for devices that do not allow incoming or outgoing connections for
302 * the profile.
Rahul Sabnise8bac9b2019-11-27 18:09:33 -0800303 *
304 * @hide
David Duarteee52b7e2023-12-02 01:32:11 +0000305 */
306 @SystemApi int CONNECTION_POLICY_FORBIDDEN = 0;
Rahul Sabnise8bac9b2019-11-27 18:09:33 -0800307
308 /**
309 * Default connection policy when not set or when the device is unpaired
310 *
311 * @hide
312 */
David Duarteee52b7e2023-12-02 01:32:11 +0000313 @SystemApi int CONNECTION_POLICY_UNKNOWN = -1;
Rahul Sabnise8bac9b2019-11-27 18:09:33 -0800314
Jaikumar Ganesh2af07762010-08-24 17:36:13 -0700315 /**
Jaikumar Ganesh2af07762010-08-24 17:36:13 -0700316 * Get connected devices for this specific profile.
317 *
David Duarteee52b7e2023-12-02 01:32:11 +0000318 * <p>Return the set of devices which are in state {@link #STATE_CONNECTED}
Jaikumar Ganesh2af07762010-08-24 17:36:13 -0700319 *
Jaikumar Ganeshd8fc4dd2010-10-18 16:41:53 -0700320 * @return List of devices. The list will be empty on error.
Jaikumar Ganesh2af07762010-08-24 17:36:13 -0700321 */
William Escande77e6c2d2022-09-03 16:28:12 -0700322 List<BluetoothDevice> getConnectedDevices();
Jaikumar Ganesh2af07762010-08-24 17:36:13 -0700323
324 /**
David Duarteee52b7e2023-12-02 01:32:11 +0000325 * Get a list of devices that match any of the given connection states.
Jaikumar Ganesh2af07762010-08-24 17:36:13 -0700326 *
David Duarteee52b7e2023-12-02 01:32:11 +0000327 * <p>If none of the devices match any of the given states, an empty list will be returned.
Jaikumar Ganesh2af07762010-08-24 17:36:13 -0700328 *
Jack He910201b2017-08-22 16:06:54 -0700329 * @param states Array of states. States can be one of {@link #STATE_CONNECTED}, {@link
David Duarteee52b7e2023-12-02 01:32:11 +0000330 * #STATE_CONNECTING}, {@link #STATE_DISCONNECTED}, {@link #STATE_DISCONNECTING},
Jaikumar Ganeshd8fc4dd2010-10-18 16:41:53 -0700331 * @return List of devices. The list will be empty on error.
Jaikumar Ganesh2af07762010-08-24 17:36:13 -0700332 */
William Escande77e6c2d2022-09-03 16:28:12 -0700333 List<BluetoothDevice> getDevicesMatchingConnectionStates(int[] states);
Jaikumar Ganesh2af07762010-08-24 17:36:13 -0700334
335 /**
336 * Get the current connection state of the profile
337 *
Jaikumar Ganesh2af07762010-08-24 17:36:13 -0700338 * @param device Remote bluetooth device.
Jack He910201b2017-08-22 16:06:54 -0700339 * @return State of the profile connection. One of {@link #STATE_CONNECTED}, {@link
David Duarteee52b7e2023-12-02 01:32:11 +0000340 * #STATE_CONNECTING}, {@link #STATE_DISCONNECTED}, {@link #STATE_DISCONNECTING}
Jaikumar Ganesh2af07762010-08-24 17:36:13 -0700341 */
David Duarteee52b7e2023-12-02 01:32:11 +0000342 @BtProfileState
343 int getConnectionState(BluetoothDevice device);
Jaikumar Ganesh2af07762010-08-24 17:36:13 -0700344
345 /**
David Duarteee52b7e2023-12-02 01:32:11 +0000346 * Called by the BluetoothAdapter when the Bluetooth service is connected with a Binder instance
347 * corresponding to the service associated with the profile
Santiago Seifertefe40712023-01-06 13:54:17 +0000348 *
349 * @hide
350 */
David Duartef5b3bc52023-10-17 00:55:06 +0000351 void onServiceConnected(IBinder service);
352
353 /**
David Duarteee52b7e2023-12-02 01:32:11 +0000354 * Called by the BluetoothAdapter when the Bluetooth service connection has been lost
David Duartef5b3bc52023-10-17 00:55:06 +0000355 *
356 * @hide
357 */
358 void onServiceDisconnected();
359
360 /**
361 * Get the BluetoothAdapter that created this proxy
362 *
363 * @hide
364 */
365 BluetoothAdapter getAdapter();
Santiago Seifertefe40712023-01-06 13:54:17 +0000366
367 /**
David Duarteee52b7e2023-12-02 01:32:11 +0000368 * An interface for notifying BluetoothProfile IPC clients when they have been connected or
369 * disconnected to the service.
Jaikumar Ganesh2af07762010-08-24 17:36:13 -0700370 */
371 public interface ServiceListener {
372 /**
David Duarteee52b7e2023-12-02 01:32:11 +0000373 * Called to notify the client when the proxy object has been connected to the service.
Jack He910201b2017-08-22 16:06:54 -0700374 *
Jack He8bb9c7d2019-01-03 16:23:41 -0800375 * @param profile - One of {@link #HEADSET} or {@link #A2DP}
376 * @param proxy - One of {@link BluetoothHeadset} or {@link BluetoothA2dp}
Jaikumar Ganesh2af07762010-08-24 17:36:13 -0700377 */
Jeff Sharkey5ba8bfc2021-04-16 09:53:23 -0600378 @RequiresNoPermission
William Escande77e6c2d2022-09-03 16:28:12 -0700379 void onServiceConnected(int profile, BluetoothProfile proxy);
Jaikumar Ganesh2af07762010-08-24 17:36:13 -0700380
381 /**
David Duarteee52b7e2023-12-02 01:32:11 +0000382 * Called to notify the client that this proxy object has been disconnected from the
383 * service.
Jack He910201b2017-08-22 16:06:54 -0700384 *
Jack He8bb9c7d2019-01-03 16:23:41 -0800385 * @param profile - One of {@link #HEADSET} or {@link #A2DP}
Jaikumar Ganesh2af07762010-08-24 17:36:13 -0700386 */
Jeff Sharkey5ba8bfc2021-04-16 09:53:23 -0600387 @RequiresNoPermission
William Escande77e6c2d2022-09-03 16:28:12 -0700388 void onServiceDisconnected(int profile);
Jaikumar Ganesh2af07762010-08-24 17:36:13 -0700389 }
Jack He93df9402017-12-11 13:11:20 -0800390
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 Duarteee52b7e2023-12-02 01:32:11 +0000395 * {@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 He93df9402017-12-11 13:11:20 -0800398 * @hide
399 */
William Escande3f38e422022-01-27 13:42:05 +0100400 @SystemApi
401 @NonNull
William Escande9c060ea2022-02-08 15:04:02 +0100402 @RequiresNoPermission
Jack He93df9402017-12-11 13:11:20 -0800403 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 Yue5216182019-07-22 15:56:23 +0800417
418 /**
419 * Convert an integer value of profile ID into human readable string
420 *
421 * @param profile profile ID
David Duarte1c07fc72023-12-02 02:08:08 +0000422 * @return profile name as String, UNKNOWN_PROFILE if the profile ID is not defined.
Ugo Yue5216182019-07-22 15:56:23 +0800423 * @hide
424 */
William Escande3f38e422022-01-27 13:42:05 +0100425 @SystemApi
426 @NonNull
William Escande9c060ea2022-02-08 15:04:02 +0100427 @RequiresNoPermission
Ugo Yue5216182019-07-22 15:56:23 +0800428 static String getProfileName(int profile) {
David Duarteee52b7e2023-12-02 01:32:11 +0000429 switch (profile) {
Ugo Yue5216182019-07-22 15:56:23 +0800430 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 Pawlowskidbdda0a2021-12-02 17:59:09 +0100466 case LE_AUDIO:
467 return "LE_AUDIO";
Jakub Pawlowski06e611e2022-03-31 17:59:02 +0200468 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 Tyszkowski6631a042021-11-05 09:51:04 +0000478 case HAP_CLIENT:
479 return "HAP_CLIENT";
Jakub Pawlowski06e611e2022-03-31 17:59:02 +0200480 case LE_AUDIO_BROADCAST_ASSISTANT:
481 return "LE_AUDIO_BROADCAST_ASSISTANT";
482 case BATTERY:
483 return "BATTERY";
Ugo Yue5216182019-07-22 15:56:23 +0800484 default:
Sal Savage65377092023-05-17 12:23:54 -0700485 return "UNKNOWN_PROFILE (" + profile + ")";
Ugo Yue5216182019-07-22 15:56:23 +0800486 }
487 }
Jaikumar Ganesh2af07762010-08-24 17:36:13 -0700488}