1 /* 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 17 package android.bluetooth; 18 19 import android.annotation.RequiresPermission; 20 import android.annotation.SuppressLint; 21 import android.bluetooth.annotations.RequiresBluetoothConnectPermission; 22 import android.bluetooth.annotations.RequiresLegacyBluetoothPermission; 23 import android.os.ParcelFileDescriptor; 24 import android.util.Log; 25 26 import java.util.ArrayList; 27 import java.util.List; 28 29 /** 30 * Public API for Bluetooth Health Profile. 31 * 32 * <p>BluetoothHealth is a proxy object for controlling the Bluetooth 33 * Service via IPC. 34 * 35 * <p> How to connect to a health device which is acting in the source role. 36 * <li> Use {@link BluetoothAdapter#getProfileProxy} to get 37 * the BluetoothHealth proxy object. </li> 38 * <li> Create an {@link BluetoothHealth} callback and call 39 * {@link #registerSinkAppConfiguration} to register an application 40 * configuration </li> 41 * <li> Pair with the remote device. This currently needs to be done manually 42 * from Bluetooth Settings </li> 43 * <li> Connect to a health device using {@link #connectChannelToSource}. Some 44 * devices will connect the channel automatically. The {@link BluetoothHealth} 45 * callback will inform the application of channel state change. </li> 46 * <li> Use the file descriptor provided with a connected channel to read and 47 * write data to the health channel. </li> 48 * <li> The received data needs to be interpreted using a health manager which 49 * implements the IEEE 11073-xxxxx specifications. 50 * <li> When done, close the health channel by calling {@link #disconnectChannel} 51 * and unregister the application configuration calling 52 * {@link #unregisterAppConfiguration} 53 * 54 * @deprecated Health Device Profile (HDP) and MCAP protocol are no longer used. New apps 55 * should use Bluetooth Low Energy based solutions such as {@link BluetoothGatt}, 56 * {@link BluetoothAdapter#listenUsingL2capChannel()(int)}, or 57 * {@link BluetoothDevice#createL2capChannel(int)} 58 */ 59 @Deprecated 60 public final class BluetoothHealth implements BluetoothProfile { 61 private static final String TAG = "BluetoothHealth"; 62 /** 63 * Health Profile Source Role - the health device. 64 * 65 * @deprecated Health Device Profile (HDP) and MCAP protocol are no longer used. New 66 * apps should use Bluetooth Low Energy based solutions such as {@link BluetoothGatt}, 67 * {@link BluetoothAdapter#listenUsingL2capChannel()(int)}, or 68 * {@link BluetoothDevice#createL2capChannel(int)} 69 */ 70 @Deprecated 71 public static final int SOURCE_ROLE = 1 << 0; 72 73 /** 74 * Health Profile Sink Role the device talking to the health device. 75 * 76 * @deprecated Health Device Profile (HDP) and MCAP protocol are no longer used. New 77 * apps should use Bluetooth Low Energy based solutions such as {@link BluetoothGatt}, 78 * {@link BluetoothAdapter#listenUsingL2capChannel()(int)}, or 79 * {@link BluetoothDevice#createL2capChannel(int)} 80 */ 81 @Deprecated 82 public static final int SINK_ROLE = 1 << 1; 83 84 /** 85 * Health Profile - Channel Type used - Reliable 86 * 87 * @deprecated Health Device Profile (HDP) and MCAP protocol are no longer used. New 88 * apps should use Bluetooth Low Energy based solutions such as {@link BluetoothGatt}, 89 * {@link BluetoothAdapter#listenUsingL2capChannel()(int)}, or 90 * {@link BluetoothDevice#createL2capChannel(int)} 91 */ 92 @Deprecated 93 public static final int CHANNEL_TYPE_RELIABLE = 10; 94 95 /** 96 * Health Profile - Channel Type used - Streaming 97 * 98 * @deprecated Health Device Profile (HDP) and MCAP protocol are no longer used. New 99 * apps should use Bluetooth Low Energy based solutions such as {@link BluetoothGatt}, 100 * {@link BluetoothAdapter#listenUsingL2capChannel()(int)}, or 101 * {@link BluetoothDevice#createL2capChannel(int)} 102 */ 103 @Deprecated 104 public static final int CHANNEL_TYPE_STREAMING = 11; 105 106 /** 107 * Hide auto-created default constructor 108 * @hide 109 */ BluetoothHealth()110 BluetoothHealth() {} 111 112 /** 113 * Register an application configuration that acts as a Health SINK. 114 * This is the configuration that will be used to communicate with health devices 115 * which will act as the {@link #SOURCE_ROLE}. This is an asynchronous call and so 116 * the callback is used to notify success or failure if the function returns true. 117 * 118 * @param name The friendly name associated with the application or configuration. 119 * @param dataType The dataType of the Source role of Health Profile to which the sink wants to 120 * connect to. 121 * @param callback A callback to indicate success or failure of the registration and all 122 * operations done on this application configuration. 123 * @return If true, callback will be called. 124 * 125 * @deprecated Health Device Profile (HDP) and MCAP protocol are no longer used. New 126 * apps should use Bluetooth Low Energy based solutions such as {@link BluetoothGatt}, 127 * {@link BluetoothAdapter#listenUsingL2capChannel()(int)}, or 128 * {@link BluetoothDevice#createL2capChannel(int)} 129 */ 130 @Deprecated 131 @RequiresLegacyBluetoothPermission 132 @RequiresBluetoothConnectPermission 133 @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT) 134 @SuppressLint("AndroidFrameworkRequiresPermission") registerSinkAppConfiguration(String name, int dataType, BluetoothHealthCallback callback)135 public boolean registerSinkAppConfiguration(String name, int dataType, 136 BluetoothHealthCallback callback) { 137 Log.e(TAG, "registerSinkAppConfiguration(): BluetoothHealth is deprecated"); 138 return false; 139 } 140 141 /** 142 * Unregister an application configuration that has been registered using 143 * {@link #registerSinkAppConfiguration} 144 * 145 * @param config The health app configuration 146 * @return Success or failure. 147 * 148 * @deprecated Health Device Profile (HDP) and MCAP protocol are no longer used. New 149 * apps should use Bluetooth Low Energy based solutions such as {@link BluetoothGatt}, 150 * {@link BluetoothAdapter#listenUsingL2capChannel()(int)}, or 151 * {@link BluetoothDevice#createL2capChannel(int)} 152 */ 153 @Deprecated 154 @RequiresLegacyBluetoothPermission 155 @RequiresBluetoothConnectPermission 156 @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT) 157 @SuppressLint("AndroidFrameworkRequiresPermission") unregisterAppConfiguration(BluetoothHealthAppConfiguration config)158 public boolean unregisterAppConfiguration(BluetoothHealthAppConfiguration config) { 159 Log.e(TAG, "unregisterAppConfiguration(): BluetoothHealth is deprecated"); 160 return false; 161 } 162 163 /** 164 * Connect to a health device which has the {@link #SOURCE_ROLE}. 165 * This is an asynchronous call. If this function returns true, the callback 166 * associated with the application configuration will be called. 167 * 168 * @param device The remote Bluetooth device. 169 * @param config The application configuration which has been registered using {@link 170 * #registerSinkAppConfiguration(String, int, BluetoothHealthCallback) } 171 * @return If true, the callback associated with the application config will be called. 172 * 173 * @deprecated Health Device Profile (HDP) and MCAP protocol are no longer used. New 174 * apps should use Bluetooth Low Energy based solutions such as {@link BluetoothGatt}, 175 * {@link BluetoothAdapter#listenUsingL2capChannel()(int)}, or 176 * {@link BluetoothDevice#createL2capChannel(int)} 177 */ 178 @Deprecated 179 @RequiresLegacyBluetoothPermission 180 @RequiresBluetoothConnectPermission 181 @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT) 182 @SuppressLint("AndroidFrameworkRequiresPermission") connectChannelToSource(BluetoothDevice device, BluetoothHealthAppConfiguration config)183 public boolean connectChannelToSource(BluetoothDevice device, 184 BluetoothHealthAppConfiguration config) { 185 Log.e(TAG, "connectChannelToSource(): BluetoothHealth is deprecated"); 186 return false; 187 } 188 189 /** 190 * Disconnect a connected health channel. 191 * This is an asynchronous call. If this function returns true, the callback 192 * associated with the application configuration will be called. 193 * 194 * @param device The remote Bluetooth device. 195 * @param config The application configuration which has been registered using {@link 196 * #registerSinkAppConfiguration(String, int, BluetoothHealthCallback) } 197 * @param channelId The channel id associated with the channel 198 * @return If true, the callback associated with the application config will be called. 199 * 200 * @deprecated Health Device Profile (HDP) and MCAP protocol are no longer used. New 201 * apps should use Bluetooth Low Energy based solutions such as {@link BluetoothGatt}, 202 * {@link BluetoothAdapter#listenUsingL2capChannel()(int)}, or 203 * {@link BluetoothDevice#createL2capChannel(int)} 204 */ 205 @Deprecated 206 @RequiresLegacyBluetoothPermission 207 @RequiresBluetoothConnectPermission 208 @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT) 209 @SuppressLint("AndroidFrameworkRequiresPermission") disconnectChannel(BluetoothDevice device, BluetoothHealthAppConfiguration config, int channelId)210 public boolean disconnectChannel(BluetoothDevice device, 211 BluetoothHealthAppConfiguration config, int channelId) { 212 Log.e(TAG, "disconnectChannel(): BluetoothHealth is deprecated"); 213 return false; 214 } 215 216 /** 217 * Get the file descriptor of the main channel associated with the remote device 218 * and application configuration. 219 * 220 * <p> Its the responsibility of the caller to close the ParcelFileDescriptor 221 * when done. 222 * 223 * @param device The remote Bluetooth health device 224 * @param config The application configuration 225 * @return null on failure, ParcelFileDescriptor on success. 226 * 227 * @deprecated Health Device Profile (HDP) and MCAP protocol are no longer used. New 228 * apps should use Bluetooth Low Energy based solutions such as {@link BluetoothGatt}, 229 * {@link BluetoothAdapter#listenUsingL2capChannel()(int)}, or 230 * {@link BluetoothDevice#createL2capChannel(int)} 231 */ 232 @Deprecated 233 @RequiresLegacyBluetoothPermission 234 @RequiresBluetoothConnectPermission 235 @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT) 236 @SuppressLint("AndroidFrameworkRequiresPermission") getMainChannelFd(BluetoothDevice device, BluetoothHealthAppConfiguration config)237 public ParcelFileDescriptor getMainChannelFd(BluetoothDevice device, 238 BluetoothHealthAppConfiguration config) { 239 Log.e(TAG, "getMainChannelFd(): BluetoothHealth is deprecated"); 240 return null; 241 } 242 243 /** 244 * Get the current connection state of the profile. 245 * 246 * This is not specific to any application configuration but represents the connection 247 * state of the local Bluetooth adapter with the remote device. This can be used 248 * by applications like status bar which would just like to know the state of the 249 * local adapter. 250 * 251 * @param device Remote bluetooth device. 252 * @return State of the profile connection. One of {@link #STATE_CONNECTED}, {@link 253 * #STATE_CONNECTING}, {@link #STATE_DISCONNECTED}, {@link #STATE_DISCONNECTING} 254 */ 255 @Override 256 @RequiresLegacyBluetoothPermission 257 @RequiresBluetoothConnectPermission 258 @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT) 259 @SuppressLint("AndroidFrameworkRequiresPermission") getConnectionState(BluetoothDevice device)260 public int getConnectionState(BluetoothDevice device) { 261 Log.e(TAG, "getConnectionState(): BluetoothHealth is deprecated"); 262 return STATE_DISCONNECTED; 263 } 264 265 /** @hide */ 266 @Override close()267 public void close() { 268 // Do nothing. 269 } 270 271 /** 272 * Get connected devices for the health profile. 273 * 274 * <p> Return the set of devices which are in state {@link #STATE_CONNECTED} 275 * 276 * This is not specific to any application configuration but represents the connection 277 * state of the local Bluetooth adapter for this profile. This can be used 278 * by applications like status bar which would just like to know the state of the 279 * local adapter. 280 * 281 * @return List of devices. The list will be empty on error. 282 */ 283 @Override 284 @RequiresLegacyBluetoothPermission 285 @RequiresBluetoothConnectPermission 286 @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT) 287 @SuppressLint("AndroidFrameworkRequiresPermission") getConnectedDevices()288 public List<BluetoothDevice> getConnectedDevices() { 289 Log.e(TAG, "getConnectedDevices(): BluetoothHealth is deprecated"); 290 return new ArrayList<>(); 291 } 292 293 /** 294 * Get a list of devices that match any of the given connection 295 * states. 296 * 297 * <p> If none of the devices match any of the given states, 298 * an empty list will be returned. 299 * 300 * <p>This is not specific to any application configuration but represents the connection 301 * state of the local Bluetooth adapter for this profile. This can be used 302 * by applications like status bar which would just like to know the state of the 303 * local adapter. 304 * 305 * @param states Array of states. States can be one of {@link #STATE_CONNECTED}, {@link 306 * #STATE_CONNECTING}, {@link #STATE_DISCONNECTED}, {@link #STATE_DISCONNECTING}, 307 * @return List of devices. The list will be empty on error. 308 */ 309 @Override 310 @RequiresLegacyBluetoothPermission 311 @RequiresBluetoothConnectPermission 312 @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT) 313 @SuppressLint("AndroidFrameworkRequiresPermission") getDevicesMatchingConnectionStates(int[] states)314 public List<BluetoothDevice> getDevicesMatchingConnectionStates(int[] states) { 315 Log.e(TAG, "getDevicesMatchingConnectionStates(): BluetoothHealth is deprecated"); 316 return new ArrayList<>(); 317 } 318 319 /** Health Channel Connection State - Disconnected 320 * 321 * @deprecated Health Device Profile (HDP) and MCAP protocol are no longer used. New 322 * apps should use Bluetooth Low Energy based solutions such as {@link BluetoothGatt}, 323 * {@link BluetoothAdapter#listenUsingL2capChannel()(int)}, or 324 * {@link BluetoothDevice#createL2capChannel(int)} 325 */ 326 @Deprecated 327 public static final int STATE_CHANNEL_DISCONNECTED = 0; 328 /** Health Channel Connection State - Connecting 329 * 330 * @deprecated Health Device Profile (HDP) and MCAP protocol are no longer used. New 331 * apps should use Bluetooth Low Energy based solutions such as {@link BluetoothGatt}, 332 * {@link BluetoothAdapter#listenUsingL2capChannel()(int)}, or 333 * {@link BluetoothDevice#createL2capChannel(int)} 334 */ 335 @Deprecated 336 public static final int STATE_CHANNEL_CONNECTING = 1; 337 /** Health Channel Connection State - Connected 338 * 339 * @deprecated Health Device Profile (HDP) and MCAP protocol are no longer used. New 340 * apps should use Bluetooth Low Energy based solutions such as {@link BluetoothGatt}, 341 * {@link BluetoothAdapter#listenUsingL2capChannel()(int)}, or 342 * {@link BluetoothDevice#createL2capChannel(int)} 343 */ 344 @Deprecated 345 public static final int STATE_CHANNEL_CONNECTED = 2; 346 /** Health Channel Connection State - Disconnecting 347 * 348 * @deprecated Health Device Profile (HDP) and MCAP protocol are no longer used. New 349 * apps should use Bluetooth Low Energy based solutions such as {@link BluetoothGatt}, 350 * {@link BluetoothAdapter#listenUsingL2capChannel()(int)}, or 351 * {@link BluetoothDevice#createL2capChannel(int)} 352 */ 353 @Deprecated 354 public static final int STATE_CHANNEL_DISCONNECTING = 3; 355 356 /** Health App Configuration registration success 357 * 358 * @deprecated Health Device Profile (HDP) and MCAP protocol are no longer used. New 359 * apps should use Bluetooth Low Energy based solutions such as {@link BluetoothGatt}, 360 * {@link BluetoothAdapter#listenUsingL2capChannel()(int)}, or 361 * {@link BluetoothDevice#createL2capChannel(int)} 362 */ 363 @Deprecated 364 public static final int APP_CONFIG_REGISTRATION_SUCCESS = 0; 365 /** Health App Configuration registration failure 366 * 367 * @deprecated Health Device Profile (HDP) and MCAP protocol are no longer used. New 368 * apps should use Bluetooth Low Energy based solutions such as {@link BluetoothGatt}, 369 * {@link BluetoothAdapter#listenUsingL2capChannel()(int)}, or 370 * {@link BluetoothDevice#createL2capChannel(int)} 371 */ 372 @Deprecated 373 public static final int APP_CONFIG_REGISTRATION_FAILURE = 1; 374 /** Health App Configuration un-registration success 375 * 376 * @deprecated Health Device Profile (HDP) and MCAP protocol are no longer used. New 377 * apps should use Bluetooth Low Energy based solutions such as {@link BluetoothGatt}, 378 * {@link BluetoothAdapter#listenUsingL2capChannel()(int)}, or 379 * {@link BluetoothDevice#createL2capChannel(int)} 380 */ 381 @Deprecated 382 public static final int APP_CONFIG_UNREGISTRATION_SUCCESS = 2; 383 /** Health App Configuration un-registration failure 384 * 385 * @deprecated Health Device Profile (HDP) and MCAP protocol are no longer used. New 386 * apps should use Bluetooth Low Energy based solutions such as {@link BluetoothGatt}, 387 * {@link BluetoothAdapter#listenUsingL2capChannel()(int)}, or 388 * {@link BluetoothDevice#createL2capChannel(int)} 389 */ 390 @Deprecated 391 public static final int APP_CONFIG_UNREGISTRATION_FAILURE = 3; 392 } 393