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