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 /** 266 * Get connected devices for the health profile. 267 * 268 * <p> Return the set of devices which are in state {@link #STATE_CONNECTED} 269 * 270 * This is not specific to any application configuration but represents the connection 271 * state of the local Bluetooth adapter for this profile. This can be used 272 * by applications like status bar which would just like to know the state of the 273 * local adapter. 274 * 275 * @return List of devices. The list will be empty on error. 276 */ 277 @Override 278 @RequiresLegacyBluetoothPermission 279 @RequiresBluetoothConnectPermission 280 @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT) 281 @SuppressLint("AndroidFrameworkRequiresPermission") getConnectedDevices()282 public List<BluetoothDevice> getConnectedDevices() { 283 Log.e(TAG, "getConnectedDevices(): BluetoothHealth is deprecated"); 284 return new ArrayList<>(); 285 } 286 287 /** 288 * Get a list of devices that match any of the given connection 289 * states. 290 * 291 * <p> If none of the devices match any of the given states, 292 * an empty list will be returned. 293 * 294 * <p>This is not specific to any application configuration but represents the connection 295 * state of the local Bluetooth adapter for this profile. This can be used 296 * by applications like status bar which would just like to know the state of the 297 * local adapter. 298 * 299 * @param states Array of states. States can be one of {@link #STATE_CONNECTED}, {@link 300 * #STATE_CONNECTING}, {@link #STATE_DISCONNECTED}, {@link #STATE_DISCONNECTING}, 301 * @return List of devices. The list will be empty on error. 302 */ 303 @Override 304 @RequiresLegacyBluetoothPermission 305 @RequiresBluetoothConnectPermission 306 @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT) 307 @SuppressLint("AndroidFrameworkRequiresPermission") getDevicesMatchingConnectionStates(int[] states)308 public List<BluetoothDevice> getDevicesMatchingConnectionStates(int[] states) { 309 Log.e(TAG, "getDevicesMatchingConnectionStates(): BluetoothHealth is deprecated"); 310 return new ArrayList<>(); 311 } 312 313 /** Health Channel Connection State - Disconnected 314 * 315 * @deprecated Health Device Profile (HDP) and MCAP protocol are no longer used. New 316 * apps should use Bluetooth Low Energy based solutions such as {@link BluetoothGatt}, 317 * {@link BluetoothAdapter#listenUsingL2capChannel()(int)}, or 318 * {@link BluetoothDevice#createL2capChannel(int)} 319 */ 320 @Deprecated 321 public static final int STATE_CHANNEL_DISCONNECTED = 0; 322 /** Health Channel Connection State - Connecting 323 * 324 * @deprecated Health Device Profile (HDP) and MCAP protocol are no longer used. New 325 * apps should use Bluetooth Low Energy based solutions such as {@link BluetoothGatt}, 326 * {@link BluetoothAdapter#listenUsingL2capChannel()(int)}, or 327 * {@link BluetoothDevice#createL2capChannel(int)} 328 */ 329 @Deprecated 330 public static final int STATE_CHANNEL_CONNECTING = 1; 331 /** Health Channel Connection State - Connected 332 * 333 * @deprecated Health Device Profile (HDP) and MCAP protocol are no longer used. New 334 * apps should use Bluetooth Low Energy based solutions such as {@link BluetoothGatt}, 335 * {@link BluetoothAdapter#listenUsingL2capChannel()(int)}, or 336 * {@link BluetoothDevice#createL2capChannel(int)} 337 */ 338 @Deprecated 339 public static final int STATE_CHANNEL_CONNECTED = 2; 340 /** Health Channel Connection State - Disconnecting 341 * 342 * @deprecated Health Device Profile (HDP) and MCAP protocol are no longer used. New 343 * apps should use Bluetooth Low Energy based solutions such as {@link BluetoothGatt}, 344 * {@link BluetoothAdapter#listenUsingL2capChannel()(int)}, or 345 * {@link BluetoothDevice#createL2capChannel(int)} 346 */ 347 @Deprecated 348 public static final int STATE_CHANNEL_DISCONNECTING = 3; 349 350 /** Health App Configuration registration success 351 * 352 * @deprecated Health Device Profile (HDP) and MCAP protocol are no longer used. New 353 * apps should use Bluetooth Low Energy based solutions such as {@link BluetoothGatt}, 354 * {@link BluetoothAdapter#listenUsingL2capChannel()(int)}, or 355 * {@link BluetoothDevice#createL2capChannel(int)} 356 */ 357 @Deprecated 358 public static final int APP_CONFIG_REGISTRATION_SUCCESS = 0; 359 /** Health App Configuration registration failure 360 * 361 * @deprecated Health Device Profile (HDP) and MCAP protocol are no longer used. New 362 * apps should use Bluetooth Low Energy based solutions such as {@link BluetoothGatt}, 363 * {@link BluetoothAdapter#listenUsingL2capChannel()(int)}, or 364 * {@link BluetoothDevice#createL2capChannel(int)} 365 */ 366 @Deprecated 367 public static final int APP_CONFIG_REGISTRATION_FAILURE = 1; 368 /** Health App Configuration un-registration success 369 * 370 * @deprecated Health Device Profile (HDP) and MCAP protocol are no longer used. New 371 * apps should use Bluetooth Low Energy based solutions such as {@link BluetoothGatt}, 372 * {@link BluetoothAdapter#listenUsingL2capChannel()(int)}, or 373 * {@link BluetoothDevice#createL2capChannel(int)} 374 */ 375 @Deprecated 376 public static final int APP_CONFIG_UNREGISTRATION_SUCCESS = 2; 377 /** Health App Configuration un-registration failure 378 * 379 * @deprecated Health Device Profile (HDP) and MCAP protocol are no longer used. New 380 * apps should use Bluetooth Low Energy based solutions such as {@link BluetoothGatt}, 381 * {@link BluetoothAdapter#listenUsingL2capChannel()(int)}, or 382 * {@link BluetoothDevice#createL2capChannel(int)} 383 */ 384 @Deprecated 385 public static final int APP_CONFIG_UNREGISTRATION_FAILURE = 3; 386 } 387