From 2be70a11a2dff8c801fdf044d34657b41c2006c5 Mon Sep 17 00:00:00 2001 From: Jack He Date: Thu, 3 Jan 2019 16:23:41 -0800 Subject: [PATCH] Deprecate BluetoothHealth APIs * Mark all BluetoothHealth related APIs as deprecated * Make BluetoothAdapter#getProfileProxy(context, BluetoothProfile.HEALTH) always return false * Remove all logic behind BluetoothHealth APIs and add deprecation error log * Health Device Profile (HDP) and MCAP protocol has been largely replaced by BLE. New applications should use Bluetooth Low Energy instead of legacy Bluetooth Health Device Profile Bug: 111562841 Test: make, unit test, use Bluetooth Change-Id: If99a9d79e9e1b89b75b9b74bd3b1c965247a1892 --- api/current.txt | 60 +-- .../android/bluetooth/BluetoothAdapter.java | 27 +- .../android/bluetooth/BluetoothHealth.java | 484 +++++------------- .../BluetoothHealthAppConfiguration.java | 122 ++--- .../bluetooth/BluetoothHealthCallback.java | 18 + .../android/bluetooth/BluetoothProfile.java | 13 +- 6 files changed, 238 insertions(+), 486 deletions(-) diff --git a/api/current.txt b/api/current.txt index f81eb54743ca..5c1d3790a243 100644 --- a/api/current.txt +++ b/api/current.txt @@ -8531,42 +8531,44 @@ package android.bluetooth { field public static final java.lang.String VENDOR_SPECIFIC_HEADSET_EVENT_COMPANY_ID_CATEGORY = "android.bluetooth.headset.intent.category.companyid"; } - public final class BluetoothHealth implements android.bluetooth.BluetoothProfile { - method public boolean connectChannelToSource(android.bluetooth.BluetoothDevice, android.bluetooth.BluetoothHealthAppConfiguration); - method public boolean disconnectChannel(android.bluetooth.BluetoothDevice, android.bluetooth.BluetoothHealthAppConfiguration, int); + public final deprecated class BluetoothHealth implements android.bluetooth.BluetoothProfile { + ctor public BluetoothHealth(); + method public deprecated boolean connectChannelToSource(android.bluetooth.BluetoothDevice, android.bluetooth.BluetoothHealthAppConfiguration); + method public deprecated boolean disconnectChannel(android.bluetooth.BluetoothDevice, android.bluetooth.BluetoothHealthAppConfiguration, int); method public java.util.List getConnectedDevices(); method public int getConnectionState(android.bluetooth.BluetoothDevice); method public java.util.List getDevicesMatchingConnectionStates(int[]); - method public android.os.ParcelFileDescriptor getMainChannelFd(android.bluetooth.BluetoothDevice, android.bluetooth.BluetoothHealthAppConfiguration); - method public boolean registerSinkAppConfiguration(java.lang.String, int, android.bluetooth.BluetoothHealthCallback); - method public boolean unregisterAppConfiguration(android.bluetooth.BluetoothHealthAppConfiguration); - field public static final int APP_CONFIG_REGISTRATION_FAILURE = 1; // 0x1 - field public static final int APP_CONFIG_REGISTRATION_SUCCESS = 0; // 0x0 - field public static final int APP_CONFIG_UNREGISTRATION_FAILURE = 3; // 0x3 - field public static final int APP_CONFIG_UNREGISTRATION_SUCCESS = 2; // 0x2 - field public static final int CHANNEL_TYPE_RELIABLE = 10; // 0xa - field public static final int CHANNEL_TYPE_STREAMING = 11; // 0xb - field public static final int SINK_ROLE = 2; // 0x2 - field public static final int SOURCE_ROLE = 1; // 0x1 - field public static final int STATE_CHANNEL_CONNECTED = 2; // 0x2 - field public static final int STATE_CHANNEL_CONNECTING = 1; // 0x1 - field public static final int STATE_CHANNEL_DISCONNECTED = 0; // 0x0 - field public static final int STATE_CHANNEL_DISCONNECTING = 3; // 0x3 - } - - public final class BluetoothHealthAppConfiguration implements android.os.Parcelable { + method public deprecated android.os.ParcelFileDescriptor getMainChannelFd(android.bluetooth.BluetoothDevice, android.bluetooth.BluetoothHealthAppConfiguration); + method public deprecated boolean registerSinkAppConfiguration(java.lang.String, int, android.bluetooth.BluetoothHealthCallback); + method public deprecated boolean unregisterAppConfiguration(android.bluetooth.BluetoothHealthAppConfiguration); + field public static final deprecated int APP_CONFIG_REGISTRATION_FAILURE = 1; // 0x1 + field public static final deprecated int APP_CONFIG_REGISTRATION_SUCCESS = 0; // 0x0 + field public static final deprecated int APP_CONFIG_UNREGISTRATION_FAILURE = 3; // 0x3 + field public static final deprecated int APP_CONFIG_UNREGISTRATION_SUCCESS = 2; // 0x2 + field public static final deprecated int CHANNEL_TYPE_RELIABLE = 10; // 0xa + field public static final deprecated int CHANNEL_TYPE_STREAMING = 11; // 0xb + field public static final deprecated int SINK_ROLE = 2; // 0x2 + field public static final deprecated int SOURCE_ROLE = 1; // 0x1 + field public static final deprecated int STATE_CHANNEL_CONNECTED = 2; // 0x2 + field public static final deprecated int STATE_CHANNEL_CONNECTING = 1; // 0x1 + field public static final deprecated int STATE_CHANNEL_DISCONNECTED = 0; // 0x0 + field public static final deprecated int STATE_CHANNEL_DISCONNECTING = 3; // 0x3 + } + + public final deprecated class BluetoothHealthAppConfiguration implements android.os.Parcelable { + ctor public BluetoothHealthAppConfiguration(); method public int describeContents(); - method public int getDataType(); - method public java.lang.String getName(); - method public int getRole(); + method public deprecated int getDataType(); + method public deprecated java.lang.String getName(); + method public deprecated int getRole(); method public void writeToParcel(android.os.Parcel, int); - field public static final android.os.Parcelable.Creator CREATOR; + field public static final deprecated android.os.Parcelable.Creator CREATOR; } - public abstract class BluetoothHealthCallback { + public abstract deprecated class BluetoothHealthCallback { ctor public BluetoothHealthCallback(); - method public void onHealthAppConfigurationStatusChange(android.bluetooth.BluetoothHealthAppConfiguration, int); - method public void onHealthChannelStateChange(android.bluetooth.BluetoothHealthAppConfiguration, android.bluetooth.BluetoothDevice, int, int, android.os.ParcelFileDescriptor, int); + method public deprecated void onHealthAppConfigurationStatusChange(android.bluetooth.BluetoothHealthAppConfiguration, int); + method public deprecated void onHealthChannelStateChange(android.bluetooth.BluetoothHealthAppConfiguration, android.bluetooth.BluetoothDevice, int, int, android.os.ParcelFileDescriptor, int); } public final class BluetoothHidDevice implements android.bluetooth.BluetoothProfile { @@ -8663,7 +8665,7 @@ package android.bluetooth { field public static final int GATT = 7; // 0x7 field public static final int GATT_SERVER = 8; // 0x8 field public static final int HEADSET = 1; // 0x1 - field public static final int HEALTH = 3; // 0x3 + field public static final deprecated int HEALTH = 3; // 0x3 field public static final int HID_DEVICE = 19; // 0x13 field public static final int SAP = 10; // 0xa field public static final int STATE_CONNECTED = 2; // 0x2 diff --git a/core/java/android/bluetooth/BluetoothAdapter.java b/core/java/android/bluetooth/BluetoothAdapter.java index 87b64797f3c6..1945b2fd51de 100644 --- a/core/java/android/bluetooth/BluetoothAdapter.java +++ b/core/java/android/bluetooth/BluetoothAdapter.java @@ -2066,8 +2066,7 @@ public final class BluetoothAdapter { * Get the current connection state of a profile. * This function can be used to check whether the local Bluetooth adapter * is connected to any remote device for a specific profile. - * Profile can be one of {@link BluetoothProfile#HEALTH}, {@link BluetoothProfile#HEADSET}, - * {@link BluetoothProfile#A2DP}. + * Profile can be one of {@link BluetoothProfile#HEADSET}, {@link BluetoothProfile#A2DP}. * *

Return value can be one of * {@link BluetoothProfile#STATE_DISCONNECTED}, @@ -2441,16 +2440,15 @@ public final class BluetoothAdapter { /** * Get the profile proxy object associated with the profile. * - *

Profile can be one of {@link BluetoothProfile#HEALTH}, {@link BluetoothProfile#HEADSET}, - * {@link BluetoothProfile#A2DP}, {@link BluetoothProfile#GATT}, or - * {@link BluetoothProfile#GATT_SERVER}. Clients must implement - * {@link BluetoothProfile.ServiceListener} to get notified of - * the connection status and to get the proxy object. + *

Profile can be one of {@link BluetoothProfile#HEADSET}, {@link BluetoothProfile#A2DP}, + * {@link BluetoothProfile#GATT}, or {@link BluetoothProfile#GATT_SERVER}. Clients must + * implement {@link BluetoothProfile.ServiceListener} to get notified of the connection status + * and to get the proxy object. * * @param context Context of the application * @param listener The service Listener for connection callbacks. - * @param profile The Bluetooth profile; either {@link BluetoothProfile#HEALTH}, {@link - * BluetoothProfile#HEADSET}, {@link BluetoothProfile#A2DP}. {@link BluetoothProfile#GATT} or + * @param profile The Bluetooth profile; either {@link BluetoothProfile#HEADSET}, + * {@link BluetoothProfile#A2DP}. {@link BluetoothProfile#GATT} or * {@link BluetoothProfile#GATT_SERVER}. * @return true on success, false on error */ @@ -2479,8 +2477,8 @@ public final class BluetoothAdapter { BluetoothPan pan = new BluetoothPan(context, listener); return true; } else if (profile == BluetoothProfile.HEALTH) { - BluetoothHealth health = new BluetoothHealth(context, listener); - return true; + Log.e(TAG, "getProfileProxy(): BluetoothHealth is deprecated"); + return false; } else if (profile == BluetoothProfile.MAP) { BluetoothMap map = new BluetoothMap(context, listener); return true; @@ -2512,8 +2510,7 @@ public final class BluetoothAdapter { * *

Clients should call this when they are no longer using * the proxy obtained from {@link #getProfileProxy}. - * Profile can be one of {@link BluetoothProfile#HEALTH}, {@link BluetoothProfile#HEADSET} or - * {@link BluetoothProfile#A2DP} + * Profile can be one of {@link BluetoothProfile#HEADSET} or {@link BluetoothProfile#A2DP} * * @param profile * @param proxy Profile proxy object @@ -2548,10 +2545,6 @@ public final class BluetoothAdapter { BluetoothPan pan = (BluetoothPan) proxy; pan.close(); break; - case BluetoothProfile.HEALTH: - BluetoothHealth health = (BluetoothHealth) proxy; - health.close(); - break; case BluetoothProfile.GATT: BluetoothGatt gatt = (BluetoothGatt) proxy; gatt.close(); diff --git a/core/java/android/bluetooth/BluetoothHealth.java b/core/java/android/bluetooth/BluetoothHealth.java index 22d41d9c896e..e2e56fd02ab7 100644 --- a/core/java/android/bluetooth/BluetoothHealth.java +++ b/core/java/android/bluetooth/BluetoothHealth.java @@ -16,15 +16,7 @@ package android.bluetooth; -import android.content.ComponentName; -import android.content.Context; -import android.content.Intent; -import android.content.ServiceConnection; -import android.os.Binder; -import android.os.IBinder; import android.os.ParcelFileDescriptor; -import android.os.RemoteException; -import android.os.UserHandle; import android.util.Log; import java.util.ArrayList; @@ -54,79 +46,59 @@ import java.util.List; *

  • When done, close the health channel by calling {@link #disconnectChannel} * and unregister the application configuration calling * {@link #unregisterAppConfiguration} + * + * @deprecated Health Device Profile (HDP) and MCAP protocol are no longer used. New apps + * should use Bluetooth Low Energy based solutions such as {@link BluetoothGatt}, + * {@link BluetoothAdapter#listenUsingL2capChannel()(int)}, or + * {@link BluetoothDevice#createL2capChannel(int)} */ +@Deprecated public final class BluetoothHealth implements BluetoothProfile { private static final String TAG = "BluetoothHealth"; - private static final boolean DBG = true; - private static final boolean VDBG = false; - /** * Health Profile Source Role - the health device. + * + * @deprecated Health Device Profile (HDP) and MCAP protocol are no longer used. New + * apps should use Bluetooth Low Energy based solutions such as {@link BluetoothGatt}, + * {@link BluetoothAdapter#listenUsingL2capChannel()(int)}, or + * {@link BluetoothDevice#createL2capChannel(int)} */ + @Deprecated public static final int SOURCE_ROLE = 1 << 0; /** * Health Profile Sink Role the device talking to the health device. + * + * @deprecated Health Device Profile (HDP) and MCAP protocol are no longer used. New + * apps should use Bluetooth Low Energy based solutions such as {@link BluetoothGatt}, + * {@link BluetoothAdapter#listenUsingL2capChannel()(int)}, or + * {@link BluetoothDevice#createL2capChannel(int)} */ + @Deprecated public static final int SINK_ROLE = 1 << 1; /** * Health Profile - Channel Type used - Reliable + * + * @deprecated Health Device Profile (HDP) and MCAP protocol are no longer used. New + * apps should use Bluetooth Low Energy based solutions such as {@link BluetoothGatt}, + * {@link BluetoothAdapter#listenUsingL2capChannel()(int)}, or + * {@link BluetoothDevice#createL2capChannel(int)} */ + @Deprecated public static final int CHANNEL_TYPE_RELIABLE = 10; /** * Health Profile - Channel Type used - Streaming + * + * @deprecated Health Device Profile (HDP) and MCAP protocol are no longer used. New + * apps should use Bluetooth Low Energy based solutions such as {@link BluetoothGatt}, + * {@link BluetoothAdapter#listenUsingL2capChannel()(int)}, or + * {@link BluetoothDevice#createL2capChannel(int)} */ + @Deprecated public static final int CHANNEL_TYPE_STREAMING = 11; - /** - * @hide - */ - public static final int CHANNEL_TYPE_ANY = 12; - - /** @hide */ - public static final int HEALTH_OPERATION_SUCCESS = 6000; - /** @hide */ - public static final int HEALTH_OPERATION_ERROR = 6001; - /** @hide */ - public static final int HEALTH_OPERATION_INVALID_ARGS = 6002; - /** @hide */ - public static final int HEALTH_OPERATION_GENERIC_FAILURE = 6003; - /** @hide */ - public static final int HEALTH_OPERATION_NOT_FOUND = 6004; - /** @hide */ - public static final int HEALTH_OPERATION_NOT_ALLOWED = 6005; - - private final IBluetoothStateChangeCallback mBluetoothStateChangeCallback = - new IBluetoothStateChangeCallback.Stub() { - public void onBluetoothStateChange(boolean up) { - if (DBG) Log.d(TAG, "onBluetoothStateChange: up=" + up); - if (!up) { - if (VDBG) Log.d(TAG, "Unbinding service..."); - synchronized (mConnection) { - try { - mService = null; - mContext.unbindService(mConnection); - } catch (Exception re) { - Log.e(TAG, "", re); - } - } - } else { - synchronized (mConnection) { - try { - if (mService == null) { - if (VDBG) Log.d(TAG, "Binding service..."); - doBind(); - } - } catch (Exception re) { - Log.e(TAG, "", re); - } - } - } - } - }; - /** * Register an application configuration that acts as a Health SINK. @@ -142,53 +114,17 @@ public final class BluetoothHealth implements BluetoothProfile { * @param callback A callback to indicate success or failure of the registration and all * operations done on this application configuration. * @return If true, callback will be called. + * + * @deprecated Health Device Profile (HDP) and MCAP protocol are no longer used. New + * apps should use Bluetooth Low Energy based solutions such as {@link BluetoothGatt}, + * {@link BluetoothAdapter#listenUsingL2capChannel()(int)}, or + * {@link BluetoothDevice#createL2capChannel(int)} */ + @Deprecated public boolean registerSinkAppConfiguration(String name, int dataType, BluetoothHealthCallback callback) { - if (!isEnabled() || name == null) return false; - - if (VDBG) log("registerSinkApplication(" + name + ":" + dataType + ")"); - return registerAppConfiguration(name, dataType, SINK_ROLE, - CHANNEL_TYPE_ANY, callback); - } - - /** - * Register an application configuration that acts as a Health SINK or in a Health - * SOURCE role.This is an asynchronous call and so - * the callback is used to notify success or failure if the function returns true. - * - *

    Requires {@link android.Manifest.permission#BLUETOOTH} permission. - * - * @param name The friendly name associated with the application or configuration. - * @param dataType The dataType of the Source role of Health Profile. - * @param channelType The channel type. Will be one of {@link #CHANNEL_TYPE_RELIABLE} or {@link - * #CHANNEL_TYPE_STREAMING} - * @param callback - A callback to indicate success or failure. - * @return If true, callback will be called. - * @hide - */ - public boolean registerAppConfiguration(String name, int dataType, int role, - int channelType, BluetoothHealthCallback callback) { - boolean result = false; - if (!isEnabled() || !checkAppParam(name, role, channelType, callback)) return result; - - if (VDBG) log("registerApplication(" + name + ":" + dataType + ")"); - BluetoothHealthCallbackWrapper wrapper = new BluetoothHealthCallbackWrapper(callback); - BluetoothHealthAppConfiguration config = - new BluetoothHealthAppConfiguration(name, dataType, role, channelType); - - final IBluetoothHealth service = mService; - if (service != null) { - try { - result = service.registerAppConfiguration(config, wrapper); - } catch (RemoteException e) { - Log.e(TAG, e.toString()); - } - } else { - Log.w(TAG, "Proxy not attached to service"); - if (DBG) Log.d(TAG, Log.getStackTraceString(new Throwable())); - } - return result; + Log.e(TAG, "registerSinkAppConfiguration(): BluetoothHealth is deprecated"); + return false; } /** @@ -199,22 +135,16 @@ public final class BluetoothHealth implements BluetoothProfile { * * @param config The health app configuration * @return Success or failure. + * + * @deprecated Health Device Profile (HDP) and MCAP protocol are no longer used. New + * apps should use Bluetooth Low Energy based solutions such as {@link BluetoothGatt}, + * {@link BluetoothAdapter#listenUsingL2capChannel()(int)}, or + * {@link BluetoothDevice#createL2capChannel(int)} */ + @Deprecated public boolean unregisterAppConfiguration(BluetoothHealthAppConfiguration config) { - boolean result = false; - final IBluetoothHealth service = mService; - if (service != null && isEnabled() && config != null) { - try { - result = service.unregisterAppConfiguration(config); - } catch (RemoteException e) { - Log.e(TAG, e.toString()); - } - } else { - Log.w(TAG, "Proxy not attached to service"); - if (DBG) Log.d(TAG, Log.getStackTraceString(new Throwable())); - } - - return result; + Log.e(TAG, "unregisterAppConfiguration(): BluetoothHealth is deprecated"); + return false; } /** @@ -228,49 +158,16 @@ public final class BluetoothHealth implements BluetoothProfile { * @param config The application configuration which has been registered using {@link * #registerSinkAppConfiguration(String, int, BluetoothHealthCallback) } * @return If true, the callback associated with the application config will be called. + * + * @deprecated Health Device Profile (HDP) and MCAP protocol are no longer used. New + * apps should use Bluetooth Low Energy based solutions such as {@link BluetoothGatt}, + * {@link BluetoothAdapter#listenUsingL2capChannel()(int)}, or + * {@link BluetoothDevice#createL2capChannel(int)} */ + @Deprecated public boolean connectChannelToSource(BluetoothDevice device, BluetoothHealthAppConfiguration config) { - final IBluetoothHealth service = mService; - if (service != null && isEnabled() && isValidDevice(device) && config != null) { - try { - return service.connectChannelToSource(device, config); - } catch (RemoteException e) { - Log.e(TAG, e.toString()); - } - } else { - Log.w(TAG, "Proxy not attached to service"); - if (DBG) Log.d(TAG, Log.getStackTraceString(new Throwable())); - } - return false; - } - - /** - * Connect to a health device which has the {@link #SINK_ROLE}. - * This is an asynchronous call. If this function returns true, the callback - * associated with the application configuration will be called. - * - *

    Requires {@link android.Manifest.permission#BLUETOOTH} permission. - * - * @param device The remote Bluetooth device. - * @param config The application configuration which has been registered using {@link - * #registerSinkAppConfiguration(String, int, BluetoothHealthCallback) } - * @return If true, the callback associated with the application config will be called. - * @hide - */ - public boolean connectChannelToSink(BluetoothDevice device, - BluetoothHealthAppConfiguration config, int channelType) { - final IBluetoothHealth service = mService; - if (service != null && isEnabled() && isValidDevice(device) && config != null) { - try { - return service.connectChannelToSink(device, config, channelType); - } catch (RemoteException e) { - Log.e(TAG, e.toString()); - } - } else { - Log.w(TAG, "Proxy not attached to service"); - if (DBG) Log.d(TAG, Log.getStackTraceString(new Throwable())); - } + Log.e(TAG, "connectChannelToSource(): BluetoothHealth is deprecated"); return false; } @@ -286,20 +183,16 @@ public final class BluetoothHealth implements BluetoothProfile { * #registerSinkAppConfiguration(String, int, BluetoothHealthCallback) } * @param channelId The channel id associated with the channel * @return If true, the callback associated with the application config will be called. + * + * @deprecated Health Device Profile (HDP) and MCAP protocol are no longer used. New + * apps should use Bluetooth Low Energy based solutions such as {@link BluetoothGatt}, + * {@link BluetoothAdapter#listenUsingL2capChannel()(int)}, or + * {@link BluetoothDevice#createL2capChannel(int)} */ + @Deprecated public boolean disconnectChannel(BluetoothDevice device, BluetoothHealthAppConfiguration config, int channelId) { - final IBluetoothHealth service = mService; - if (service != null && isEnabled() && isValidDevice(device) && config != null) { - try { - return service.disconnectChannel(device, config, channelId); - } catch (RemoteException e) { - Log.e(TAG, e.toString()); - } - } else { - Log.w(TAG, "Proxy not attached to service"); - if (DBG) Log.d(TAG, Log.getStackTraceString(new Throwable())); - } + Log.e(TAG, "disconnectChannel(): BluetoothHealth is deprecated"); return false; } @@ -315,20 +208,16 @@ public final class BluetoothHealth implements BluetoothProfile { * @param device The remote Bluetooth health device * @param config The application configuration * @return null on failure, ParcelFileDescriptor on success. + * + * @deprecated Health Device Profile (HDP) and MCAP protocol are no longer used. New + * apps should use Bluetooth Low Energy based solutions such as {@link BluetoothGatt}, + * {@link BluetoothAdapter#listenUsingL2capChannel()(int)}, or + * {@link BluetoothDevice#createL2capChannel(int)} */ + @Deprecated public ParcelFileDescriptor getMainChannelFd(BluetoothDevice device, BluetoothHealthAppConfiguration config) { - final IBluetoothHealth service = mService; - if (service != null && isEnabled() && isValidDevice(device) && config != null) { - try { - return service.getMainChannelFd(device, config); - } catch (RemoteException e) { - Log.e(TAG, e.toString()); - } - } else { - Log.w(TAG, "Proxy not attached to service"); - if (DBG) Log.d(TAG, Log.getStackTraceString(new Throwable())); - } + Log.e(TAG, "getMainChannelFd(): BluetoothHealth is deprecated"); return null; } @@ -348,17 +237,7 @@ public final class BluetoothHealth implements BluetoothProfile { */ @Override public int getConnectionState(BluetoothDevice device) { - final IBluetoothHealth service = mService; - if (service != null && isEnabled() && isValidDevice(device)) { - try { - return service.getHealthDeviceConnectionState(device); - } catch (RemoteException e) { - Log.e(TAG, e.toString()); - } - } else { - Log.w(TAG, "Proxy not attached to service"); - if (DBG) Log.d(TAG, Log.getStackTraceString(new Throwable())); - } + Log.e(TAG, "getConnectionState(): BluetoothHealth is deprecated"); return STATE_DISCONNECTED; } @@ -378,17 +257,8 @@ public final class BluetoothHealth implements BluetoothProfile { */ @Override public List getConnectedDevices() { - final IBluetoothHealth service = mService; - if (service != null && isEnabled()) { - try { - return service.getConnectedHealthDevices(); - } catch (RemoteException e) { - Log.e(TAG, "Stack:" + Log.getStackTraceString(new Throwable())); - return new ArrayList(); - } - } - if (service == null) Log.w(TAG, "Proxy not attached to service"); - return new ArrayList(); + Log.e(TAG, "getConnectedDevices(): BluetoothHealth is deprecated"); + return new ArrayList<>(); } /** @@ -410,163 +280,81 @@ public final class BluetoothHealth implements BluetoothProfile { */ @Override public List getDevicesMatchingConnectionStates(int[] states) { - final IBluetoothHealth service = mService; - if (service != null && isEnabled()) { - try { - return service.getHealthDevicesMatchingConnectionStates(states); - } catch (RemoteException e) { - Log.e(TAG, "Stack:" + Log.getStackTraceString(new Throwable())); - return new ArrayList(); - } - } - if (service == null) Log.w(TAG, "Proxy not attached to service"); - return new ArrayList(); + Log.e(TAG, "getDevicesMatchingConnectionStates(): BluetoothHealth is deprecated"); + return new ArrayList<>(); } - private static class BluetoothHealthCallbackWrapper extends IBluetoothHealthCallback.Stub { - private BluetoothHealthCallback mCallback; - - public BluetoothHealthCallbackWrapper(BluetoothHealthCallback callback) { - mCallback = callback; - } - - @Override - public void onHealthAppConfigurationStatusChange(BluetoothHealthAppConfiguration config, - int status) { - mCallback.onHealthAppConfigurationStatusChange(config, status); - } - - @Override - public void onHealthChannelStateChange(BluetoothHealthAppConfiguration config, - BluetoothDevice device, int prevState, int newState, - ParcelFileDescriptor fd, int channelId) { - mCallback.onHealthChannelStateChange(config, device, prevState, newState, fd, - channelId); - } - } - - /** Health Channel Connection State - Disconnected */ + /** Health Channel Connection State - Disconnected + * + * @deprecated Health Device Profile (HDP) and MCAP protocol are no longer used. New + * apps should use Bluetooth Low Energy based solutions such as {@link BluetoothGatt}, + * {@link BluetoothAdapter#listenUsingL2capChannel()(int)}, or + * {@link BluetoothDevice#createL2capChannel(int)} + */ + @Deprecated public static final int STATE_CHANNEL_DISCONNECTED = 0; - /** Health Channel Connection State - Connecting */ + /** Health Channel Connection State - Connecting + * + * @deprecated Health Device Profile (HDP) and MCAP protocol are no longer used. New + * apps should use Bluetooth Low Energy based solutions such as {@link BluetoothGatt}, + * {@link BluetoothAdapter#listenUsingL2capChannel()(int)}, or + * {@link BluetoothDevice#createL2capChannel(int)} + */ + @Deprecated public static final int STATE_CHANNEL_CONNECTING = 1; - /** Health Channel Connection State - Connected */ + /** Health Channel Connection State - Connected + * + * @deprecated Health Device Profile (HDP) and MCAP protocol are no longer used. New + * apps should use Bluetooth Low Energy based solutions such as {@link BluetoothGatt}, + * {@link BluetoothAdapter#listenUsingL2capChannel()(int)}, or + * {@link BluetoothDevice#createL2capChannel(int)} + */ + @Deprecated public static final int STATE_CHANNEL_CONNECTED = 2; - /** Health Channel Connection State - Disconnecting */ + /** Health Channel Connection State - Disconnecting + * + * @deprecated Health Device Profile (HDP) and MCAP protocol are no longer used. New + * apps should use Bluetooth Low Energy based solutions such as {@link BluetoothGatt}, + * {@link BluetoothAdapter#listenUsingL2capChannel()(int)}, or + * {@link BluetoothDevice#createL2capChannel(int)} + */ + @Deprecated public static final int STATE_CHANNEL_DISCONNECTING = 3; - /** Health App Configuration registration success */ + /** Health App Configuration registration success + * + * @deprecated Health Device Profile (HDP) and MCAP protocol are no longer used. New + * apps should use Bluetooth Low Energy based solutions such as {@link BluetoothGatt}, + * {@link BluetoothAdapter#listenUsingL2capChannel()(int)}, or + * {@link BluetoothDevice#createL2capChannel(int)} + */ + @Deprecated public static final int APP_CONFIG_REGISTRATION_SUCCESS = 0; - /** Health App Configuration registration failure */ + /** Health App Configuration registration failure + * + * @deprecated Health Device Profile (HDP) and MCAP protocol are no longer used. New + * apps should use Bluetooth Low Energy based solutions such as {@link BluetoothGatt}, + * {@link BluetoothAdapter#listenUsingL2capChannel()(int)}, or + * {@link BluetoothDevice#createL2capChannel(int)} + */ + @Deprecated public static final int APP_CONFIG_REGISTRATION_FAILURE = 1; - /** Health App Configuration un-registration success */ + /** Health App Configuration un-registration success + * + * @deprecated Health Device Profile (HDP) and MCAP protocol are no longer used. New + * apps should use Bluetooth Low Energy based solutions such as {@link BluetoothGatt}, + * {@link BluetoothAdapter#listenUsingL2capChannel()(int)}, or + * {@link BluetoothDevice#createL2capChannel(int)} + */ + @Deprecated public static final int APP_CONFIG_UNREGISTRATION_SUCCESS = 2; - /** Health App Configuration un-registration failure */ - public static final int APP_CONFIG_UNREGISTRATION_FAILURE = 3; - - private Context mContext; - private ServiceListener mServiceListener; - private volatile IBluetoothHealth mService; - BluetoothAdapter mAdapter; - - /** - * Create a BluetoothHealth proxy object. + /** Health App Configuration un-registration failure + * + * @deprecated Health Device Profile (HDP) and MCAP protocol are no longer used. New + * apps should use Bluetooth Low Energy based solutions such as {@link BluetoothGatt}, + * {@link BluetoothAdapter#listenUsingL2capChannel()(int)}, or + * {@link BluetoothDevice#createL2capChannel(int)} */ - /*package*/ BluetoothHealth(Context context, ServiceListener l) { - mContext = context; - mServiceListener = l; - mAdapter = BluetoothAdapter.getDefaultAdapter(); - IBluetoothManager mgr = mAdapter.getBluetoothManager(); - if (mgr != null) { - try { - mgr.registerStateChangeCallback(mBluetoothStateChangeCallback); - } catch (RemoteException e) { - Log.e(TAG, "", e); - } - } - - doBind(); - } - - boolean doBind() { - Intent intent = new Intent(IBluetoothHealth.class.getName()); - ComponentName comp = intent.resolveSystemService(mContext.getPackageManager(), 0); - intent.setComponent(comp); - if (comp == null || !mContext.bindServiceAsUser(intent, mConnection, 0, - UserHandle.CURRENT_OR_SELF)) { - Log.e(TAG, "Could not bind to Bluetooth Health Service with " + intent); - return false; - } - return true; - } - - /*package*/ void close() { - if (VDBG) log("close()"); - IBluetoothManager mgr = mAdapter.getBluetoothManager(); - if (mgr != null) { - try { - mgr.unregisterStateChangeCallback(mBluetoothStateChangeCallback); - } catch (Exception e) { - Log.e(TAG, "", e); - } - } - - synchronized (mConnection) { - if (mService != null) { - try { - mService = null; - mContext.unbindService(mConnection); - } catch (Exception re) { - Log.e(TAG, "", re); - } - } - } - mServiceListener = null; - } - - private final ServiceConnection mConnection = new ServiceConnection() { - public void onServiceConnected(ComponentName className, IBinder service) { - if (DBG) Log.d(TAG, "Proxy object connected"); - mService = IBluetoothHealth.Stub.asInterface(Binder.allowBlocking(service)); - - if (mServiceListener != null) { - mServiceListener.onServiceConnected(BluetoothProfile.HEALTH, BluetoothHealth.this); - } - } - - public void onServiceDisconnected(ComponentName className) { - if (DBG) Log.d(TAG, "Proxy object disconnected"); - mService = null; - if (mServiceListener != null) { - mServiceListener.onServiceDisconnected(BluetoothProfile.HEALTH); - } - } - }; - - private boolean isEnabled() { - BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter(); - - if (adapter != null && adapter.getState() == BluetoothAdapter.STATE_ON) return true; - log("Bluetooth is Not enabled"); - return false; - } - - private static boolean isValidDevice(BluetoothDevice device) { - return device != null && BluetoothAdapter.checkBluetoothAddress(device.getAddress()); - } - - private boolean checkAppParam(String name, int role, int channelType, - BluetoothHealthCallback callback) { - if (name == null || (role != SOURCE_ROLE && role != SINK_ROLE) - || (channelType != CHANNEL_TYPE_RELIABLE && channelType != CHANNEL_TYPE_STREAMING - && channelType != CHANNEL_TYPE_ANY) - || callback == null) { - return false; - } - if (role == SOURCE_ROLE && channelType == CHANNEL_TYPE_ANY) return false; - return true; - } - - private static void log(String msg) { - Log.d(TAG, msg); - } + @Deprecated + public static final int APP_CONFIG_UNREGISTRATION_FAILURE = 3; } diff --git a/core/java/android/bluetooth/BluetoothHealthAppConfiguration.java b/core/java/android/bluetooth/BluetoothHealthAppConfiguration.java index 7c9db6f7213c..9788bbf74e3e 100644 --- a/core/java/android/bluetooth/BluetoothHealthAppConfiguration.java +++ b/core/java/android/bluetooth/BluetoothHealthAppConfiguration.java @@ -25,72 +25,14 @@ import android.os.Parcelable; * the {@link BluetoothHealth} class. This class represents an application configuration * that the Bluetooth Health third party application will register to communicate with the * remote Bluetooth health device. + * + * @deprecated Health Device Profile (HDP) and MCAP protocol are no longer used. New + * apps should use Bluetooth Low Energy based solutions such as {@link BluetoothGatt}, + * {@link BluetoothAdapter#listenUsingL2capChannel()(int)}, or + * {@link BluetoothDevice#createL2capChannel(int)} */ +@Deprecated public final class BluetoothHealthAppConfiguration implements Parcelable { - private final String mName; - private final int mDataType; - private final int mRole; - private final int mChannelType; - - /** - * Constructor to register the SINK role - * - * @param name Friendly name associated with the application configuration - * @param dataType Data Type of the remote Bluetooth Health device - * @hide - */ - BluetoothHealthAppConfiguration(String name, int dataType) { - mName = name; - mDataType = dataType; - mRole = BluetoothHealth.SINK_ROLE; - mChannelType = BluetoothHealth.CHANNEL_TYPE_ANY; - } - - /** - * Constructor to register the application configuration. - * - * @param name Friendly name associated with the application configuration - * @param dataType Data Type of the remote Bluetooth Health device - * @param role {@link BluetoothHealth#SOURCE_ROLE} or {@link BluetoothHealth#SINK_ROLE} - * @hide - */ - BluetoothHealthAppConfiguration(String name, int dataType, int role, int - channelType) { - mName = name; - mDataType = dataType; - mRole = role; - mChannelType = channelType; - } - - @Override - public boolean equals(Object o) { - if (o instanceof BluetoothHealthAppConfiguration) { - BluetoothHealthAppConfiguration config = (BluetoothHealthAppConfiguration) o; - - if (mName == null) return false; - - return mName.equals(config.getName()) && mDataType == config.getDataType() - && mRole == config.getRole() && mChannelType == config.getChannelType(); - } - return false; - } - - @Override - public int hashCode() { - int result = 17; - result = 31 * result + (mName != null ? mName.hashCode() : 0); - result = 31 * result + mDataType; - result = 31 * result + mRole; - result = 31 * result + mChannelType; - return result; - } - - @Override - public String toString() { - return "BluetoothHealthAppConfiguration [mName = " + mName + ",mDataType = " + mDataType - + ", mRole = " + mRole + ",mChannelType = " + mChannelType + "]"; - } - @Override public int describeContents() { return 0; @@ -100,50 +42,59 @@ public final class BluetoothHealthAppConfiguration implements Parcelable { * Return the data type associated with this application configuration. * * @return dataType + * + * @deprecated Health Device Profile (HDP) and MCAP protocol are no longer used. New + * apps should use Bluetooth Low Energy based solutions such as {@link BluetoothGatt}, + * {@link BluetoothAdapter#listenUsingL2capChannel()(int)}, or + * {@link BluetoothDevice#createL2capChannel(int)} */ + @Deprecated public int getDataType() { - return mDataType; + return 0; } /** * Return the name of the application configuration. * * @return String name + * + * @deprecated Health Device Profile (HDP) and MCAP protocol are no longer used. New + * apps should use Bluetooth Low Energy based solutions such as {@link BluetoothGatt}, + * {@link BluetoothAdapter#listenUsingL2capChannel()(int)}, or + * {@link BluetoothDevice#createL2capChannel(int)} */ + @Deprecated public String getName() { - return mName; + return null; } /** * Return the role associated with this application configuration. * * @return One of {@link BluetoothHealth#SOURCE_ROLE} or {@link BluetoothHealth#SINK_ROLE} + * + * @deprecated Health Device Profile (HDP) and MCAP protocol are no longer used. New + * apps should use Bluetooth Low Energy based solutions such as {@link BluetoothGatt}, + * {@link BluetoothAdapter#listenUsingL2capChannel()(int)}, or + * {@link BluetoothDevice#createL2capChannel(int)} */ + @Deprecated public int getRole() { - return mRole; + return 0; } /** - * Return the channel type associated with this application configuration. - * - * @return One of {@link BluetoothHealth#CHANNEL_TYPE_RELIABLE} or {@link - * BluetoothHealth#CHANNEL_TYPE_STREAMING} or {@link BluetoothHealth#CHANNEL_TYPE_ANY}. - * @hide + * @deprecated Health Device Profile (HDP) and MCAP protocol are no longer used. New + * apps should use Bluetooth Low Energy based solutions such as {@link BluetoothGatt}, + * {@link BluetoothAdapter#listenUsingL2capChannel()(int)}, or + * {@link BluetoothDevice#createL2capChannel(int)} */ - public int getChannelType() { - return mChannelType; - } - + @Deprecated public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { @Override public BluetoothHealthAppConfiguration createFromParcel(Parcel in) { - String name = in.readString(); - int type = in.readInt(); - int role = in.readInt(); - int channelType = in.readInt(); - return new BluetoothHealthAppConfiguration(name, type, role, - channelType); + return new BluetoothHealthAppConfiguration(); } @Override @@ -153,10 +104,5 @@ public final class BluetoothHealthAppConfiguration implements Parcelable { }; @Override - public void writeToParcel(Parcel out, int flags) { - out.writeString(mName); - out.writeInt(mDataType); - out.writeInt(mRole); - out.writeInt(mChannelType); - } + public void writeToParcel(Parcel out, int flags) {} } diff --git a/core/java/android/bluetooth/BluetoothHealthCallback.java b/core/java/android/bluetooth/BluetoothHealthCallback.java index 40234856b8ad..4769212c5361 100644 --- a/core/java/android/bluetooth/BluetoothHealthCallback.java +++ b/core/java/android/bluetooth/BluetoothHealthCallback.java @@ -23,7 +23,13 @@ import android.util.Log; /** * This abstract class is used to implement {@link BluetoothHealth} callbacks. + * + * @deprecated Health Device Profile (HDP) and MCAP protocol are no longer used. New + * apps should use Bluetooth Low Energy based solutions such as {@link BluetoothGatt}, + * {@link BluetoothAdapter#listenUsingL2capChannel()(int)}, or + * {@link BluetoothDevice#createL2capChannel(int)} */ +@Deprecated public abstract class BluetoothHealthCallback { private static final String TAG = "BluetoothHealthCallback"; @@ -38,8 +44,14 @@ public abstract class BluetoothHealthCallback { * BluetoothHealth#APP_CONFIG_REGISTRATION_FAILURE} or * {@link BluetoothHealth#APP_CONFIG_UNREGISTRATION_SUCCESS} * or {@link BluetoothHealth#APP_CONFIG_UNREGISTRATION_FAILURE} + * + * @deprecated Health Device Profile (HDP) and MCAP protocol are no longer used. New + * apps should use Bluetooth Low Energy based solutions such as {@link BluetoothGatt}, + * {@link BluetoothAdapter#listenUsingL2capChannel()(int)}, or + * {@link BluetoothDevice#createL2capChannel(int)} */ @BinderThread + @Deprecated public void onHealthAppConfigurationStatusChange(BluetoothHealthAppConfiguration config, int status) { Log.d(TAG, "onHealthAppConfigurationStatusChange: " + config + "Status: " + status); @@ -58,8 +70,14 @@ public abstract class BluetoothHealthCallback { * @param fd The Parcel File Descriptor when the channel state is connected. * @param channelId The id associated with the channel. This id will be used in future calls * like when disconnecting the channel. + * + * @deprecated Health Device Profile (HDP) and MCAP protocol are no longer used. New + * apps should use Bluetooth Low Energy based solutions such as {@link BluetoothGatt}, + * {@link BluetoothAdapter#listenUsingL2capChannel()(int)}, or + * {@link BluetoothDevice#createL2capChannel(int)} */ @BinderThread + @Deprecated public void onHealthChannelStateChange(BluetoothHealthAppConfiguration config, BluetoothDevice device, int prevState, int newState, ParcelFileDescriptor fd, int channelId) { diff --git a/core/java/android/bluetooth/BluetoothProfile.java b/core/java/android/bluetooth/BluetoothProfile.java index 3c3a01b191e6..3c87c739e1f6 100644 --- a/core/java/android/bluetooth/BluetoothProfile.java +++ b/core/java/android/bluetooth/BluetoothProfile.java @@ -72,7 +72,13 @@ public interface BluetoothProfile { /** * Health Profile + * + * @deprecated Health Device Profile (HDP) and MCAP protocol are no longer used. New + * apps should use Bluetooth Low Energy based solutions such as {@link BluetoothGatt}, + * {@link BluetoothAdapter#listenUsingL2capChannel()}, or + * {@link BluetoothDevice#createL2capChannel(int)} */ + @Deprecated int HEALTH = 3; /** @@ -269,9 +275,8 @@ public interface BluetoothProfile { * Called to notify the client when the proxy object has been * connected to the service. * - * @param profile - One of {@link #HEALTH}, {@link #HEADSET} or {@link #A2DP} - * @param proxy - One of {@link BluetoothHealth}, {@link BluetoothHeadset} or {@link - * BluetoothA2dp} + * @param profile - One of {@link #HEADSET} or {@link #A2DP} + * @param proxy - One of {@link BluetoothHeadset} or {@link BluetoothA2dp} */ public void onServiceConnected(int profile, BluetoothProfile proxy); @@ -279,7 +284,7 @@ public interface BluetoothProfile { * Called to notify the client that this proxy object has been * disconnected from the service. * - * @param profile - One of {@link #HEALTH}, {@link #HEADSET} or {@link #A2DP} + * @param profile - One of {@link #HEADSET} or {@link #A2DP} */ public void onServiceDisconnected(int profile); } -- GitLab