blob: df2028a55351582f13aa9d9a9b0659774340dfd3 [file] [log] [blame]
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -07001/*
Joseph Pirozzo631768d2016-09-01 14:19:28 -07002 * Copyright (C) 2010-2016 The Android Open Source Project
Jaikumar Ganesh62c37ef2010-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
17
18package android.bluetooth;
19
Tor Norbye2d497522015-04-23 17:10:21 -070020import android.Manifest;
21import android.annotation.RequiresPermission;
22
Jaikumar Ganesh03cd78c2010-10-18 16:41:53 -070023import java.util.List;
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -070024
25/**
26 * Public APIs for the Bluetooth Profiles.
27 *
28 * <p> Clients should call {@link BluetoothAdapter#getProfileProxy},
29 * to get the Profile Proxy. Each public profile implements this
30 * interface.
31 */
32public interface BluetoothProfile {
33
34 /**
35 * Extra for the connection state intents of the individual profiles.
36 *
37 * This extra represents the current connection state of the profile of the
38 * Bluetooth device.
39 */
40 public static final String EXTRA_STATE = "android.bluetooth.profile.extra.STATE";
41
42 /**
43 * Extra for the connection state intents of the individual profiles.
44 *
45 * This extra represents the previous connection state of the profile of the
46 * Bluetooth device.
47 */
48 public static final String EXTRA_PREVIOUS_STATE =
Jack Hea355e5e2017-08-22 16:06:54 -070049 "android.bluetooth.profile.extra.PREVIOUS_STATE";
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -070050
51 /** The profile is in disconnected state */
Jack Hea355e5e2017-08-22 16:06:54 -070052 public static final int STATE_DISCONNECTED = 0;
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -070053 /** The profile is in connecting state */
Jack Hea355e5e2017-08-22 16:06:54 -070054 public static final int STATE_CONNECTING = 1;
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -070055 /** The profile is in connected state */
Jack Hea355e5e2017-08-22 16:06:54 -070056 public static final int STATE_CONNECTED = 2;
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -070057 /** The profile is in disconnecting state */
58 public static final int STATE_DISCONNECTING = 3;
59
60 /**
61 * Headset and Handsfree profile
62 */
63 public static final int HEADSET = 1;
Jaikumar Ganesh74ef1192011-02-23 10:22:15 -080064
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -070065 /**
66 * A2DP profile.
67 */
68 public static final int A2DP = 2;
Jaikumar Ganesh74ef1192011-02-23 10:22:15 -080069
Jaikumar Ganesh4ab0e772011-02-18 14:52:32 -080070 /**
Jaikumar Ganesh2ea1e852011-04-01 16:33:09 -070071 * Health Profile
Jaikumar Ganesh2ea1e852011-04-01 16:33:09 -070072 */
73 public static final int HEALTH = 3;
74
75 /**
Hansong Zhang0edf7542017-10-20 15:55:59 -070076 * HID Host
Jack Hea355e5e2017-08-22 16:06:54 -070077 *
Jaikumar Ganesh4ab0e772011-02-18 14:52:32 -080078 * @hide
79 */
Hansong Zhang0edf7542017-10-20 15:55:59 -070080 public static final int HID_HOST = 4;
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -070081
82 /**
Jaikumar Ganesh74ef1192011-02-23 10:22:15 -080083 * PAN Profile
Jack Hea355e5e2017-08-22 16:06:54 -070084 *
Jaikumar Ganesh74ef1192011-02-23 10:22:15 -080085 * @hide
86 */
Jaikumar Ganesh2ea1e852011-04-01 16:33:09 -070087 public static final int PAN = 5;
Jaikumar Ganesh74ef1192011-02-23 10:22:15 -080088
89 /**
Jaikumar Ganeshcb1d3542011-08-19 10:26:32 -070090 * PBAP
Jack Hea355e5e2017-08-22 16:06:54 -070091 *
Jaikumar Ganeshcb1d3542011-08-19 10:26:32 -070092 * @hide
93 */
94 public static final int PBAP = 6;
95
96 /**
Ganesh Ganapathi Batta99081122013-02-05 15:28:33 -080097 * GATT
Ganesh Ganapathi Batta99081122013-02-05 15:28:33 -080098 */
Jack He2992cd02017-08-22 21:21:23 -070099 public static final int GATT = 7;
Ganesh Ganapathi Batta99081122013-02-05 15:28:33 -0800100
101 /**
102 * GATT_SERVER
Ganesh Ganapathi Batta99081122013-02-05 15:28:33 -0800103 */
Jack He2992cd02017-08-22 21:21:23 -0700104 public static final int GATT_SERVER = 8;
Ganesh Ganapathi Batta99081122013-02-05 15:28:33 -0800105
106 /**
Matthew Xiefe3807a2013-07-18 17:31:50 -0700107 * MAP Profile
Jack Hea355e5e2017-08-22 16:06:54 -0700108 *
Matthew Xiefe3807a2013-07-18 17:31:50 -0700109 * @hide
110 */
111 public static final int MAP = 9;
112
Casper Bonde2a5f6082015-03-19 10:36:45 +0100113 /*
114 * SAP Profile
115 * @hide
116 */
117 public static final int SAP = 10;
118
Matthew Xiefe3807a2013-07-18 17:31:50 -0700119 /**
Mike Lockwood0a40ec22014-05-21 10:08:50 -0700120 * A2DP Sink Profile
Jack Hea355e5e2017-08-22 16:06:54 -0700121 *
Mike Lockwood0a40ec22014-05-21 10:08:50 -0700122 * @hide
123 */
Casper Bonde2a5f6082015-03-19 10:36:45 +0100124 public static final int A2DP_SINK = 11;
Mike Lockwood0a40ec22014-05-21 10:08:50 -0700125
126 /**
Mike Lockwood94b59de2014-06-02 16:20:37 -0700127 * AVRCP Controller Profile
Jack Hea355e5e2017-08-22 16:06:54 -0700128 *
Mike Lockwood94b59de2014-06-02 16:20:37 -0700129 * @hide
130 */
Casper Bonde2a5f6082015-03-19 10:36:45 +0100131 public static final int AVRCP_CONTROLLER = 12;
Mike Lockwood94b59de2014-06-02 16:20:37 -0700132
133 /**
Mike Lockwoodcf916d32014-06-12 11:23:40 -0700134 * Headset Client - HFP HF Role
Jack Hea355e5e2017-08-22 16:06:54 -0700135 *
Hemant Gupta7aca90f2013-08-19 19:03:51 +0530136 * @hide
137 */
Mike Lockwoodcf916d32014-06-12 11:23:40 -0700138 public static final int HEADSET_CLIENT = 16;
Hemant Gupta7aca90f2013-08-19 19:03:51 +0530139
140 /**
Joseph Pirozzocfa8a642016-03-04 13:02:54 -0800141 * PBAP Client
Jack Hea355e5e2017-08-22 16:06:54 -0700142 *
Joseph Pirozzocfa8a642016-03-04 13:02:54 -0800143 * @hide
144 */
145 public static final int PBAP_CLIENT = 17;
146
147 /**
Joseph Pirozzo631768d2016-09-01 14:19:28 -0700148 * MAP Messaging Client Equipment (MCE)
Jack Hea355e5e2017-08-22 16:06:54 -0700149 *
Joseph Pirozzo631768d2016-09-01 14:19:28 -0700150 * @hide
151 */
152 public static final int MAP_CLIENT = 18;
153
154 /**
Hansong Zhang0edf7542017-10-20 15:55:59 -0700155 * HID Device
Hemant Guptae88fd4b2014-04-18 11:22:45 +0530156 */
Hansong Zhang0edf7542017-10-20 15:55:59 -0700157 public static final int HID_DEVICE = 19;
Hemant Guptae88fd4b2014-04-18 11:22:45 +0530158
159 /**
Bryce Leef6b74de2016-10-09 12:54:42 -0700160 * Max profile ID. This value should be updated whenever a new profile is added to match
161 * the largest value assigned to a profile.
Jack Hea355e5e2017-08-22 16:06:54 -0700162 *
Bryce Leef6b74de2016-10-09 12:54:42 -0700163 * @hide
164 */
Hemant Guptae88fd4b2014-04-18 11:22:45 +0530165 public static final int MAX_PROFILE_ID = 19;
Bryce Leef6b74de2016-10-09 12:54:42 -0700166
167 /**
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -0700168 * Default priority for devices that we try to auto-connect to and
169 * and allow incoming connections for the profile
Jack Hea355e5e2017-08-22 16:06:54 -0700170 *
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -0700171 * @hide
172 **/
173 public static final int PRIORITY_AUTO_CONNECT = 1000;
174
175 /**
Jack Hea355e5e2017-08-22 16:06:54 -0700176 * Default priority for devices that allow incoming
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -0700177 * and outgoing connections for the profile
Jack Hea355e5e2017-08-22 16:06:54 -0700178 *
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -0700179 * @hide
180 **/
181 public static final int PRIORITY_ON = 100;
182
183 /**
184 * Default priority for devices that does not allow incoming
185 * connections and outgoing connections for the profile.
Jack Hea355e5e2017-08-22 16:06:54 -0700186 *
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -0700187 * @hide
188 **/
189 public static final int PRIORITY_OFF = 0;
190
191 /**
192 * Default priority when not set or when the device is unpaired
Jack Hea355e5e2017-08-22 16:06:54 -0700193 *
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -0700194 * @hide
Jack Hea355e5e2017-08-22 16:06:54 -0700195 */
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -0700196 public static final int PRIORITY_UNDEFINED = -1;
197
198 /**
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -0700199 * Get connected devices for this specific profile.
200 *
201 * <p> Return the set of devices which are in state {@link #STATE_CONNECTED}
202 *
Jaikumar Ganesh03cd78c2010-10-18 16:41:53 -0700203 * @return List of devices. The list will be empty on error.
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -0700204 */
Tor Norbye2d497522015-04-23 17:10:21 -0700205 @RequiresPermission(Manifest.permission.BLUETOOTH)
Jaikumar Ganesh03cd78c2010-10-18 16:41:53 -0700206 public List<BluetoothDevice> getConnectedDevices();
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -0700207
208 /**
Jaikumar Ganeshc8fa4ff2011-01-25 16:03:13 -0800209 * Get a list of devices that match any of the given connection
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -0700210 * states.
211 *
Jaikumar Ganeshc8fa4ff2011-01-25 16:03:13 -0800212 * <p> If none of the devices match any of the given states,
213 * an empty list will be returned.
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -0700214 *
Jack Hea355e5e2017-08-22 16:06:54 -0700215 * @param states Array of states. States can be one of {@link #STATE_CONNECTED}, {@link
216 * #STATE_CONNECTING}, {@link #STATE_DISCONNECTED}, {@link #STATE_DISCONNECTING},
Jaikumar Ganesh03cd78c2010-10-18 16:41:53 -0700217 * @return List of devices. The list will be empty on error.
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -0700218 */
Tor Norbye2d497522015-04-23 17:10:21 -0700219 @RequiresPermission(Manifest.permission.BLUETOOTH)
Jaikumar Ganesh03cd78c2010-10-18 16:41:53 -0700220 public List<BluetoothDevice> getDevicesMatchingConnectionStates(int[] states);
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -0700221
222 /**
223 * Get the current connection state of the profile
224 *
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -0700225 * @param device Remote bluetooth device.
Jack Hea355e5e2017-08-22 16:06:54 -0700226 * @return State of the profile connection. One of {@link #STATE_CONNECTED}, {@link
227 * #STATE_CONNECTING}, {@link #STATE_DISCONNECTED}, {@link #STATE_DISCONNECTING}
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -0700228 */
Tor Norbye2d497522015-04-23 17:10:21 -0700229 @RequiresPermission(Manifest.permission.BLUETOOTH)
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -0700230 public int getConnectionState(BluetoothDevice device);
231
232 /**
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -0700233 * An interface for notifying BluetoothProfile IPC clients when they have
234 * been connected or disconnected to the service.
235 */
236 public interface ServiceListener {
237 /**
238 * Called to notify the client when the proxy object has been
239 * connected to the service.
Jack Hea355e5e2017-08-22 16:06:54 -0700240 *
241 * @param profile - One of {@link #HEALTH}, {@link #HEADSET} or {@link #A2DP}
242 * @param proxy - One of {@link BluetoothHealth}, {@link BluetoothHeadset} or {@link
243 * BluetoothA2dp}
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -0700244 */
245 public void onServiceConnected(int profile, BluetoothProfile proxy);
246
247 /**
248 * Called to notify the client that this proxy object has been
249 * disconnected from the service.
Jack Hea355e5e2017-08-22 16:06:54 -0700250 *
251 * @param profile - One of {@link #HEALTH}, {@link #HEADSET} or {@link #A2DP}
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -0700252 */
253 public void onServiceDisconnected(int profile);
254 }
Jack He5252b972017-12-11 13:11:20 -0800255
256 /**
257 * Convert an integer value of connection state into human readable string
258 *
259 * @param connectionState - One of {@link #STATE_DISCONNECTED}, {@link #STATE_CONNECTING},
260 * {@link #STATE_CONNECTED}, or {@link #STATE_DISCONNECTED}
261 * @return a string representation of the connection state, STATE_UNKNOWN if the state
262 * is not defined
263 * @hide
264 */
265 static String getConnectionStateName(int connectionState) {
266 switch (connectionState) {
267 case STATE_DISCONNECTED:
268 return "STATE_DISCONNECTED";
269 case STATE_CONNECTING:
270 return "STATE_CONNECTING";
271 case STATE_CONNECTED:
272 return "STATE_CONNECTED";
273 case STATE_DISCONNECTING:
274 return "STATE_DISCONNECTING";
275 default:
276 return "STATE_UNKNOWN";
277 }
278 }
Jaikumar Ganesh62c37ef2010-08-24 17:36:13 -0700279}