blob: e2e56fd02ab7917d9929ae9285d53f9c36df8e8d [file] [log] [blame]
Jaikumar Ganesh2ea1e852011-04-01 16:33:09 -07001/*
2 * Copyright (C) 2011 The Android Open Source Project
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
17package android.bluetooth;
18
Jaikumar Ganesh2ea1e852011-04-01 16:33:09 -070019import android.os.ParcelFileDescriptor;
Jaikumar Ganesh2ea1e852011-04-01 16:33:09 -070020import android.util.Log;
21
22import java.util.ArrayList;
23import java.util.List;
24
25/**
26 * Public API for Bluetooth Health Profile.
27 *
28 * <p>BluetoothHealth is a proxy object for controlling the Bluetooth
29 * Service via IPC.
30 *
Jaikumar Ganesheb9d3462011-08-31 15:36:05 -070031 * <p> How to connect to a health device which is acting in the source role.
Jack Hea355e5e2017-08-22 16:06:54 -070032 * <li> Use {@link BluetoothAdapter#getProfileProxy} to get
33 * the BluetoothHealth proxy object. </li>
34 * <li> Create an {@link BluetoothHealth} callback and call
35 * {@link #registerSinkAppConfiguration} to register an application
36 * configuration </li>
37 * <li> Pair with the remote device. This currently needs to be done manually
38 * from Bluetooth Settings </li>
39 * <li> Connect to a health device using {@link #connectChannelToSource}. Some
40 * devices will connect the channel automatically. The {@link BluetoothHealth}
41 * callback will inform the application of channel state change. </li>
42 * <li> Use the file descriptor provided with a connected channel to read and
43 * write data to the health channel. </li>
44 * <li> The received data needs to be interpreted using a health manager which
45 * implements the IEEE 11073-xxxxx specifications.
46 * <li> When done, close the health channel by calling {@link #disconnectChannel}
47 * and unregister the application configuration calling
48 * {@link #unregisterAppConfiguration}
Jack He6b73b322019-01-03 16:23:41 -080049 *
50 * @deprecated Health Device Profile (HDP) and MCAP protocol are no longer used. New apps
51 * should use Bluetooth Low Energy based solutions such as {@link BluetoothGatt},
52 * {@link BluetoothAdapter#listenUsingL2capChannel()(int)}, or
53 * {@link BluetoothDevice#createL2capChannel(int)}
Jaikumar Ganesh2ea1e852011-04-01 16:33:09 -070054 */
Jack He6b73b322019-01-03 16:23:41 -080055@Deprecated
Jaikumar Ganesh2ea1e852011-04-01 16:33:09 -070056public final class BluetoothHealth implements BluetoothProfile {
57 private static final String TAG = "BluetoothHealth";
Jaikumar Ganesh2ea1e852011-04-01 16:33:09 -070058 /**
59 * Health Profile Source Role - the health device.
Jack He6b73b322019-01-03 16:23:41 -080060 *
61 * @deprecated Health Device Profile (HDP) and MCAP protocol are no longer used. New
62 * apps should use Bluetooth Low Energy based solutions such as {@link BluetoothGatt},
63 * {@link BluetoothAdapter#listenUsingL2capChannel()(int)}, or
64 * {@link BluetoothDevice#createL2capChannel(int)}
Jaikumar Ganesh2ea1e852011-04-01 16:33:09 -070065 */
Jack He6b73b322019-01-03 16:23:41 -080066 @Deprecated
Jaikumar Ganesh2ea1e852011-04-01 16:33:09 -070067 public static final int SOURCE_ROLE = 1 << 0;
68
69 /**
70 * Health Profile Sink Role the device talking to the health device.
Jack He6b73b322019-01-03 16:23:41 -080071 *
72 * @deprecated Health Device Profile (HDP) and MCAP protocol are no longer used. New
73 * apps should use Bluetooth Low Energy based solutions such as {@link BluetoothGatt},
74 * {@link BluetoothAdapter#listenUsingL2capChannel()(int)}, or
75 * {@link BluetoothDevice#createL2capChannel(int)}
Jaikumar Ganesh2ea1e852011-04-01 16:33:09 -070076 */
Jack He6b73b322019-01-03 16:23:41 -080077 @Deprecated
Jaikumar Ganesh2ea1e852011-04-01 16:33:09 -070078 public static final int SINK_ROLE = 1 << 1;
79
80 /**
81 * Health Profile - Channel Type used - Reliable
Jack He6b73b322019-01-03 16:23:41 -080082 *
83 * @deprecated Health Device Profile (HDP) and MCAP protocol are no longer used. New
84 * apps should use Bluetooth Low Energy based solutions such as {@link BluetoothGatt},
85 * {@link BluetoothAdapter#listenUsingL2capChannel()(int)}, or
86 * {@link BluetoothDevice#createL2capChannel(int)}
Jaikumar Ganesh2ea1e852011-04-01 16:33:09 -070087 */
Jack He6b73b322019-01-03 16:23:41 -080088 @Deprecated
Jaikumar Ganesh2ea1e852011-04-01 16:33:09 -070089 public static final int CHANNEL_TYPE_RELIABLE = 10;
90
91 /**
92 * Health Profile - Channel Type used - Streaming
Jack He6b73b322019-01-03 16:23:41 -080093 *
94 * @deprecated Health Device Profile (HDP) and MCAP protocol are no longer used. New
95 * apps should use Bluetooth Low Energy based solutions such as {@link BluetoothGatt},
96 * {@link BluetoothAdapter#listenUsingL2capChannel()(int)}, or
97 * {@link BluetoothDevice#createL2capChannel(int)}
Jaikumar Ganesh2ea1e852011-04-01 16:33:09 -070098 */
Jack He6b73b322019-01-03 16:23:41 -080099 @Deprecated
Jaikumar Ganesh2ea1e852011-04-01 16:33:09 -0700100 public static final int CHANNEL_TYPE_STREAMING = 11;
101
Jaikumar Ganeshb5d2d452011-09-07 14:16:52 -0700102
Jaikumar Ganesh2ea1e852011-04-01 16:33:09 -0700103 /**
104 * Register an application configuration that acts as a Health SINK.
105 * This is the configuration that will be used to communicate with health devices
106 * which will act as the {@link #SOURCE_ROLE}. This is an asynchronous call and so
107 * the callback is used to notify success or failure if the function returns true.
108 *
109 * <p>Requires {@link android.Manifest.permission#BLUETOOTH} permission.
110 *
111 * @param name The friendly name associated with the application or configuration.
Jack Hea355e5e2017-08-22 16:06:54 -0700112 * @param dataType The dataType of the Source role of Health Profile to which the sink wants to
113 * connect to.
114 * @param callback A callback to indicate success or failure of the registration and all
115 * operations done on this application configuration.
Jaikumar Ganesh2ea1e852011-04-01 16:33:09 -0700116 * @return If true, callback will be called.
Jack He6b73b322019-01-03 16:23:41 -0800117 *
118 * @deprecated Health Device Profile (HDP) and MCAP protocol are no longer used. New
119 * apps should use Bluetooth Low Energy based solutions such as {@link BluetoothGatt},
120 * {@link BluetoothAdapter#listenUsingL2capChannel()(int)}, or
121 * {@link BluetoothDevice#createL2capChannel(int)}
Jaikumar Ganesh2ea1e852011-04-01 16:33:09 -0700122 */
Jack He6b73b322019-01-03 16:23:41 -0800123 @Deprecated
Jaikumar Ganesh2ea1e852011-04-01 16:33:09 -0700124 public boolean registerSinkAppConfiguration(String name, int dataType,
Jaikumar Ganeshfb658c72011-07-06 17:37:02 -0700125 BluetoothHealthCallback callback) {
Jack He6b73b322019-01-03 16:23:41 -0800126 Log.e(TAG, "registerSinkAppConfiguration(): BluetoothHealth is deprecated");
127 return false;
Jaikumar Ganesh2ea1e852011-04-01 16:33:09 -0700128 }
129
130 /**
131 * Unregister an application configuration that has been registered using
132 * {@link #registerSinkAppConfiguration}
133 *
134 * <p>Requires {@link android.Manifest.permission#BLUETOOTH} permission.
135 *
Jack Hea355e5e2017-08-22 16:06:54 -0700136 * @param config The health app configuration
Jaikumar Ganesh2ea1e852011-04-01 16:33:09 -0700137 * @return Success or failure.
Jack He6b73b322019-01-03 16:23:41 -0800138 *
139 * @deprecated Health Device Profile (HDP) and MCAP protocol are no longer used. New
140 * apps should use Bluetooth Low Energy based solutions such as {@link BluetoothGatt},
141 * {@link BluetoothAdapter#listenUsingL2capChannel()(int)}, or
142 * {@link BluetoothDevice#createL2capChannel(int)}
Jaikumar Ganesh2ea1e852011-04-01 16:33:09 -0700143 */
Jack He6b73b322019-01-03 16:23:41 -0800144 @Deprecated
Jaikumar Ganesh2ea1e852011-04-01 16:33:09 -0700145 public boolean unregisterAppConfiguration(BluetoothHealthAppConfiguration config) {
Jack He6b73b322019-01-03 16:23:41 -0800146 Log.e(TAG, "unregisterAppConfiguration(): BluetoothHealth is deprecated");
147 return false;
Jaikumar Ganesh2ea1e852011-04-01 16:33:09 -0700148 }
149
150 /**
151 * Connect to a health device which has the {@link #SOURCE_ROLE}.
Jaikumar Ganeshfb658c72011-07-06 17:37:02 -0700152 * This is an asynchronous call. If this function returns true, the callback
Jaikumar Ganesh2ea1e852011-04-01 16:33:09 -0700153 * associated with the application configuration will be called.
154 *
155 * <p>Requires {@link android.Manifest.permission#BLUETOOTH} permission.
156 *
157 * @param device The remote Bluetooth device.
Jack Hea355e5e2017-08-22 16:06:54 -0700158 * @param config The application configuration which has been registered using {@link
159 * #registerSinkAppConfiguration(String, int, BluetoothHealthCallback) }
Jaikumar Ganesh2ea1e852011-04-01 16:33:09 -0700160 * @return If true, the callback associated with the application config will be called.
Jack He6b73b322019-01-03 16:23:41 -0800161 *
162 * @deprecated Health Device Profile (HDP) and MCAP protocol are no longer used. New
163 * apps should use Bluetooth Low Energy based solutions such as {@link BluetoothGatt},
164 * {@link BluetoothAdapter#listenUsingL2capChannel()(int)}, or
165 * {@link BluetoothDevice#createL2capChannel(int)}
Jaikumar Ganesh2ea1e852011-04-01 16:33:09 -0700166 */
Jack He6b73b322019-01-03 16:23:41 -0800167 @Deprecated
Jaikumar Ganesh2ea1e852011-04-01 16:33:09 -0700168 public boolean connectChannelToSource(BluetoothDevice device,
169 BluetoothHealthAppConfiguration config) {
Jack He6b73b322019-01-03 16:23:41 -0800170 Log.e(TAG, "connectChannelToSource(): BluetoothHealth is deprecated");
Jaikumar Ganesh2ea1e852011-04-01 16:33:09 -0700171 return false;
172 }
173
174 /**
175 * Disconnect a connected health channel.
176 * This is an asynchronous call. If this function returns true, the callback
177 * associated with the application configuration will be called.
178 *
Jack Hea355e5e2017-08-22 16:06:54 -0700179 * <p>Requires {@link android.Manifest.permission#BLUETOOTH} permission.
Jaikumar Ganesh2ea1e852011-04-01 16:33:09 -0700180 *
181 * @param device The remote Bluetooth device.
Jack Hea355e5e2017-08-22 16:06:54 -0700182 * @param config The application configuration which has been registered using {@link
183 * #registerSinkAppConfiguration(String, int, BluetoothHealthCallback) }
Jaikumar Ganesheb9d3462011-08-31 15:36:05 -0700184 * @param channelId The channel id associated with the channel
Jaikumar Ganesh2ea1e852011-04-01 16:33:09 -0700185 * @return If true, the callback associated with the application config will be called.
Jack He6b73b322019-01-03 16:23:41 -0800186 *
187 * @deprecated Health Device Profile (HDP) and MCAP protocol are no longer used. New
188 * apps should use Bluetooth Low Energy based solutions such as {@link BluetoothGatt},
189 * {@link BluetoothAdapter#listenUsingL2capChannel()(int)}, or
190 * {@link BluetoothDevice#createL2capChannel(int)}
Jaikumar Ganesh2ea1e852011-04-01 16:33:09 -0700191 */
Jack He6b73b322019-01-03 16:23:41 -0800192 @Deprecated
Jaikumar Ganesh2ea1e852011-04-01 16:33:09 -0700193 public boolean disconnectChannel(BluetoothDevice device,
Jaikumar Ganesheb9d3462011-08-31 15:36:05 -0700194 BluetoothHealthAppConfiguration config, int channelId) {
Jack He6b73b322019-01-03 16:23:41 -0800195 Log.e(TAG, "disconnectChannel(): BluetoothHealth is deprecated");
Jaikumar Ganesh2ea1e852011-04-01 16:33:09 -0700196 return false;
197 }
198
199 /**
200 * Get the file descriptor of the main channel associated with the remote device
201 * and application configuration.
202 *
203 * <p>Requires {@link android.Manifest.permission#BLUETOOTH} permission.
204 *
Jaikumar Ganesheb9d3462011-08-31 15:36:05 -0700205 * <p> Its the responsibility of the caller to close the ParcelFileDescriptor
206 * when done.
207 *
Jaikumar Ganesh2ea1e852011-04-01 16:33:09 -0700208 * @param device The remote Bluetooth health device
209 * @param config The application configuration
210 * @return null on failure, ParcelFileDescriptor on success.
Jack He6b73b322019-01-03 16:23:41 -0800211 *
212 * @deprecated Health Device Profile (HDP) and MCAP protocol are no longer used. New
213 * apps should use Bluetooth Low Energy based solutions such as {@link BluetoothGatt},
214 * {@link BluetoothAdapter#listenUsingL2capChannel()(int)}, or
215 * {@link BluetoothDevice#createL2capChannel(int)}
Jaikumar Ganesh2ea1e852011-04-01 16:33:09 -0700216 */
Jack He6b73b322019-01-03 16:23:41 -0800217 @Deprecated
Jaikumar Ganesh2ea1e852011-04-01 16:33:09 -0700218 public ParcelFileDescriptor getMainChannelFd(BluetoothDevice device,
219 BluetoothHealthAppConfiguration config) {
Jack He6b73b322019-01-03 16:23:41 -0800220 Log.e(TAG, "getMainChannelFd(): BluetoothHealth is deprecated");
Jaikumar Ganesh2ea1e852011-04-01 16:33:09 -0700221 return null;
222 }
223
224 /**
225 * Get the current connection state of the profile.
226 *
227 * <p>Requires {@link android.Manifest.permission#BLUETOOTH} permission.
228 *
229 * This is not specific to any application configuration but represents the connection
230 * state of the local Bluetooth adapter with the remote device. This can be used
231 * by applications like status bar which would just like to know the state of the
232 * local adapter.
233 *
234 * @param device Remote bluetooth device.
Jack Hea355e5e2017-08-22 16:06:54 -0700235 * @return State of the profile connection. One of {@link #STATE_CONNECTED}, {@link
236 * #STATE_CONNECTING}, {@link #STATE_DISCONNECTED}, {@link #STATE_DISCONNECTING}
Jaikumar Ganesh2ea1e852011-04-01 16:33:09 -0700237 */
Jaikumar Ganeshfb658c72011-07-06 17:37:02 -0700238 @Override
Jaikumar Ganesh2ea1e852011-04-01 16:33:09 -0700239 public int getConnectionState(BluetoothDevice device) {
Jack He6b73b322019-01-03 16:23:41 -0800240 Log.e(TAG, "getConnectionState(): BluetoothHealth is deprecated");
Jaikumar Ganesh2ea1e852011-04-01 16:33:09 -0700241 return STATE_DISCONNECTED;
242 }
243
244 /**
Jaikumar Ganesheb9d3462011-08-31 15:36:05 -0700245 * Get connected devices for the health profile.
Jaikumar Ganesh2ea1e852011-04-01 16:33:09 -0700246 *
247 * <p> Return the set of devices which are in state {@link #STATE_CONNECTED}
248 *
249 * <p>Requires {@link android.Manifest.permission#BLUETOOTH} permission.
250 *
251 * This is not specific to any application configuration but represents the connection
252 * state of the local Bluetooth adapter for this profile. This can be used
253 * by applications like status bar which would just like to know the state of the
254 * local adapter.
Jack Hea355e5e2017-08-22 16:06:54 -0700255 *
Jaikumar Ganesh2ea1e852011-04-01 16:33:09 -0700256 * @return List of devices. The list will be empty on error.
257 */
Jaikumar Ganeshfb658c72011-07-06 17:37:02 -0700258 @Override
Jaikumar Ganesh2ea1e852011-04-01 16:33:09 -0700259 public List<BluetoothDevice> getConnectedDevices() {
Jack He6b73b322019-01-03 16:23:41 -0800260 Log.e(TAG, "getConnectedDevices(): BluetoothHealth is deprecated");
261 return new ArrayList<>();
Jaikumar Ganesh2ea1e852011-04-01 16:33:09 -0700262 }
263
264 /**
265 * Get a list of devices that match any of the given connection
266 * states.
267 *
268 * <p> If none of the devices match any of the given states,
269 * an empty list will be returned.
270 *
271 * <p>Requires {@link android.Manifest.permission#BLUETOOTH} permission.
272 * This is not specific to any application configuration but represents the connection
273 * state of the local Bluetooth adapter for this profile. This can be used
274 * by applications like status bar which would just like to know the state of the
275 * local adapter.
276 *
Jack Hea355e5e2017-08-22 16:06:54 -0700277 * @param states Array of states. States can be one of {@link #STATE_CONNECTED}, {@link
278 * #STATE_CONNECTING}, {@link #STATE_DISCONNECTED}, {@link #STATE_DISCONNECTING},
Jaikumar Ganesh2ea1e852011-04-01 16:33:09 -0700279 * @return List of devices. The list will be empty on error.
280 */
Jaikumar Ganeshfb658c72011-07-06 17:37:02 -0700281 @Override
Jaikumar Ganesh2ea1e852011-04-01 16:33:09 -0700282 public List<BluetoothDevice> getDevicesMatchingConnectionStates(int[] states) {
Jack He6b73b322019-01-03 16:23:41 -0800283 Log.e(TAG, "getDevicesMatchingConnectionStates(): BluetoothHealth is deprecated");
284 return new ArrayList<>();
Jaikumar Ganesh2ea1e852011-04-01 16:33:09 -0700285 }
286
Jack He6b73b322019-01-03 16:23:41 -0800287 /** Health Channel Connection State - Disconnected
288 *
289 * @deprecated Health Device Profile (HDP) and MCAP protocol are no longer used. New
290 * apps should use Bluetooth Low Energy based solutions such as {@link BluetoothGatt},
291 * {@link BluetoothAdapter#listenUsingL2capChannel()(int)}, or
292 * {@link BluetoothDevice#createL2capChannel(int)}
293 */
294 @Deprecated
Jack Hea355e5e2017-08-22 16:06:54 -0700295 public static final int STATE_CHANNEL_DISCONNECTED = 0;
Jack He6b73b322019-01-03 16:23:41 -0800296 /** Health Channel Connection State - Connecting
297 *
298 * @deprecated Health Device Profile (HDP) and MCAP protocol are no longer used. New
299 * apps should use Bluetooth Low Energy based solutions such as {@link BluetoothGatt},
300 * {@link BluetoothAdapter#listenUsingL2capChannel()(int)}, or
301 * {@link BluetoothDevice#createL2capChannel(int)}
302 */
303 @Deprecated
Jack Hea355e5e2017-08-22 16:06:54 -0700304 public static final int STATE_CHANNEL_CONNECTING = 1;
Jack He6b73b322019-01-03 16:23:41 -0800305 /** Health Channel Connection State - Connected
306 *
307 * @deprecated Health Device Profile (HDP) and MCAP protocol are no longer used. New
308 * apps should use Bluetooth Low Energy based solutions such as {@link BluetoothGatt},
309 * {@link BluetoothAdapter#listenUsingL2capChannel()(int)}, or
310 * {@link BluetoothDevice#createL2capChannel(int)}
311 */
312 @Deprecated
Jack Hea355e5e2017-08-22 16:06:54 -0700313 public static final int STATE_CHANNEL_CONNECTED = 2;
Jack He6b73b322019-01-03 16:23:41 -0800314 /** Health Channel Connection State - Disconnecting
315 *
316 * @deprecated Health Device Profile (HDP) and MCAP protocol are no longer used. New
317 * apps should use Bluetooth Low Energy based solutions such as {@link BluetoothGatt},
318 * {@link BluetoothAdapter#listenUsingL2capChannel()(int)}, or
319 * {@link BluetoothDevice#createL2capChannel(int)}
320 */
321 @Deprecated
Jaikumar Ganesh2ea1e852011-04-01 16:33:09 -0700322 public static final int STATE_CHANNEL_DISCONNECTING = 3;
323
Jack He6b73b322019-01-03 16:23:41 -0800324 /** Health App Configuration registration success
325 *
326 * @deprecated Health Device Profile (HDP) and MCAP protocol are no longer used. New
327 * apps should use Bluetooth Low Energy based solutions such as {@link BluetoothGatt},
328 * {@link BluetoothAdapter#listenUsingL2capChannel()(int)}, or
329 * {@link BluetoothDevice#createL2capChannel(int)}
Jaikumar Ganesh2ea1e852011-04-01 16:33:09 -0700330 */
Jack He6b73b322019-01-03 16:23:41 -0800331 @Deprecated
332 public static final int APP_CONFIG_REGISTRATION_SUCCESS = 0;
333 /** Health App Configuration registration failure
334 *
335 * @deprecated Health Device Profile (HDP) and MCAP protocol are no longer used. New
336 * apps should use Bluetooth Low Energy based solutions such as {@link BluetoothGatt},
337 * {@link BluetoothAdapter#listenUsingL2capChannel()(int)}, or
338 * {@link BluetoothDevice#createL2capChannel(int)}
339 */
340 @Deprecated
341 public static final int APP_CONFIG_REGISTRATION_FAILURE = 1;
342 /** Health App Configuration un-registration success
343 *
344 * @deprecated Health Device Profile (HDP) and MCAP protocol are no longer used. New
345 * apps should use Bluetooth Low Energy based solutions such as {@link BluetoothGatt},
346 * {@link BluetoothAdapter#listenUsingL2capChannel()(int)}, or
347 * {@link BluetoothDevice#createL2capChannel(int)}
348 */
349 @Deprecated
350 public static final int APP_CONFIG_UNREGISTRATION_SUCCESS = 2;
351 /** Health App Configuration un-registration failure
352 *
353 * @deprecated Health Device Profile (HDP) and MCAP protocol are no longer used. New
354 * apps should use Bluetooth Low Energy based solutions such as {@link BluetoothGatt},
355 * {@link BluetoothAdapter#listenUsingL2capChannel()(int)}, or
356 * {@link BluetoothDevice#createL2capChannel(int)}
357 */
358 @Deprecated
359 public static final int APP_CONFIG_UNREGISTRATION_FAILURE = 3;
Jaikumar Ganesh2ea1e852011-04-01 16:33:09 -0700360}