Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8bb9c7d4 authored by Jack He's avatar Jack He
Browse files

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
Merged-In: If99a9d79e9e1b89b75b9b74bd3b1c965247a1892
(cherry picked from commit 07ffaa44)
parent 84995ea1
Loading
Loading
Loading
Loading
+10 −17
Original line number Original line Diff line number Diff line
@@ -2066,8 +2066,7 @@ public final class BluetoothAdapter {
     * Get the current connection state of a profile.
     * Get the current connection state of a profile.
     * This function can be used to check whether the local Bluetooth adapter
     * This function can be used to check whether the local Bluetooth adapter
     * is connected to any remote device for a specific profile.
     * is connected to any remote device for a specific profile.
     * Profile can be one of {@link BluetoothProfile#HEALTH}, {@link BluetoothProfile#HEADSET},
     * Profile can be one of {@link BluetoothProfile#HEADSET}, {@link BluetoothProfile#A2DP}.
     * {@link BluetoothProfile#A2DP}.
     *
     *
     * <p> Return value can be one of
     * <p> Return value can be one of
     * {@link BluetoothProfile#STATE_DISCONNECTED},
     * {@link BluetoothProfile#STATE_DISCONNECTED},
@@ -2441,16 +2440,15 @@ public final class BluetoothAdapter {
    /**
    /**
     * Get the profile proxy object associated with the profile.
     * Get the profile proxy object associated with the profile.
     *
     *
     * <p>Profile can be one of {@link BluetoothProfile#HEALTH}, {@link BluetoothProfile#HEADSET},
     * <p>Profile can be one of {@link BluetoothProfile#HEADSET}, {@link BluetoothProfile#A2DP},
     * {@link BluetoothProfile#A2DP}, {@link BluetoothProfile#GATT}, or
     * {@link BluetoothProfile#GATT}, or {@link BluetoothProfile#GATT_SERVER}. Clients must
     * {@link BluetoothProfile#GATT_SERVER}. Clients must implement
     * implement {@link BluetoothProfile.ServiceListener} to get notified of the connection status
     * {@link BluetoothProfile.ServiceListener} to get notified of
     * and to get the proxy object.
     * the connection status and to get the proxy object.
     *
     *
     * @param context Context of the application
     * @param context Context of the application
     * @param listener The service Listener for connection callbacks.
     * @param listener The service Listener for connection callbacks.
     * @param profile The Bluetooth profile; either {@link BluetoothProfile#HEALTH}, {@link
     * @param profile The Bluetooth profile; either {@link BluetoothProfile#HEADSET},
     * BluetoothProfile#HEADSET}, {@link BluetoothProfile#A2DP}. {@link BluetoothProfile#GATT} or
     * {@link BluetoothProfile#A2DP}. {@link BluetoothProfile#GATT} or
     * {@link BluetoothProfile#GATT_SERVER}.
     * {@link BluetoothProfile#GATT_SERVER}.
     * @return true on success, false on error
     * @return true on success, false on error
     */
     */
@@ -2479,8 +2477,8 @@ public final class BluetoothAdapter {
            BluetoothPan pan = new BluetoothPan(context, listener);
            BluetoothPan pan = new BluetoothPan(context, listener);
            return true;
            return true;
        } else if (profile == BluetoothProfile.HEALTH) {
        } else if (profile == BluetoothProfile.HEALTH) {
            BluetoothHealth health = new BluetoothHealth(context, listener);
            Log.e(TAG, "getProfileProxy(): BluetoothHealth is deprecated");
            return true;
            return false;
        } else if (profile == BluetoothProfile.MAP) {
        } else if (profile == BluetoothProfile.MAP) {
            BluetoothMap map = new BluetoothMap(context, listener);
            BluetoothMap map = new BluetoothMap(context, listener);
            return true;
            return true;
@@ -2512,8 +2510,7 @@ public final class BluetoothAdapter {
     *
     *
     * <p> Clients should call this when they are no longer using
     * <p> Clients should call this when they are no longer using
     * the proxy obtained from {@link #getProfileProxy}.
     * the proxy obtained from {@link #getProfileProxy}.
     * Profile can be one of  {@link BluetoothProfile#HEALTH}, {@link BluetoothProfile#HEADSET} or
     * Profile can be one of  {@link BluetoothProfile#HEADSET} or {@link BluetoothProfile#A2DP}
     * {@link BluetoothProfile#A2DP}
     *
     *
     * @param profile
     * @param profile
     * @param proxy Profile proxy object
     * @param proxy Profile proxy object
@@ -2548,10 +2545,6 @@ public final class BluetoothAdapter {
                BluetoothPan pan = (BluetoothPan) proxy;
                BluetoothPan pan = (BluetoothPan) proxy;
                pan.close();
                pan.close();
                break;
                break;
            case BluetoothProfile.HEALTH:
                BluetoothHealth health = (BluetoothHealth) proxy;
                health.close();
                break;
            case BluetoothProfile.GATT:
            case BluetoothProfile.GATT:
                BluetoothGatt gatt = (BluetoothGatt) proxy;
                BluetoothGatt gatt = (BluetoothGatt) proxy;
                gatt.close();
                gatt.close();
+136 −347

File changed.

Preview size limit exceeded, changes collapsed.

+34 −88
Original line number Original line Diff line number Diff line
@@ -25,72 +25,14 @@ import android.os.Parcelable;
 * the {@link BluetoothHealth} class. This class represents an application configuration
 * the {@link BluetoothHealth} class. This class represents an application configuration
 * that the Bluetooth Health third party application will register to communicate with the
 * that the Bluetooth Health third party application will register to communicate with the
 * remote Bluetooth health device.
 * remote Bluetooth health device.
 */
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
 * @deprecated Health Device Profile (HDP) and MCAP protocol are no longer used. New
     * @param dataType Data Type of the remote Bluetooth Health device
 * apps should use Bluetooth Low Energy based solutions such as {@link BluetoothGatt},
     * @param role {@link BluetoothHealth#SOURCE_ROLE} or {@link BluetoothHealth#SINK_ROLE}
 * {@link BluetoothAdapter#listenUsingL2capChannel()(int)}, or
     * @hide
 * {@link BluetoothDevice#createL2capChannel(int)}
 */
 */
    BluetoothHealthAppConfiguration(String name, int dataType, int role, int
@Deprecated
            channelType) {
public final class BluetoothHealthAppConfiguration implements Parcelable {
        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
    @Override
    public int describeContents() {
    public int describeContents() {
        return 0;
        return 0;
@@ -100,50 +42,59 @@ public final class BluetoothHealthAppConfiguration implements Parcelable {
     * Return the data type associated with this application configuration.
     * Return the data type associated with this application configuration.
     *
     *
     * @return dataType
     * @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() {
    public int getDataType() {
        return mDataType;
        return 0;
    }
    }


    /**
    /**
     * Return the name of the application configuration.
     * Return the name of the application configuration.
     *
     *
     * @return String name
     * @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() {
    public String getName() {
        return mName;
        return null;
    }
    }


    /**
    /**
     * Return the role associated with this application configuration.
     * Return the role associated with this application configuration.
     *
     *
     * @return One of {@link BluetoothHealth#SOURCE_ROLE} or {@link BluetoothHealth#SINK_ROLE}
     * @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() {
    public int getRole() {
        return mRole;
        return 0;
    }
    }


    /**
    /**
     * Return the channel type associated with this application configuration.
     * @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},
     * @return One of {@link BluetoothHealth#CHANNEL_TYPE_RELIABLE} or {@link
     * {@link BluetoothAdapter#listenUsingL2capChannel()(int)}, or
     * BluetoothHealth#CHANNEL_TYPE_STREAMING} or {@link BluetoothHealth#CHANNEL_TYPE_ANY}.
     * {@link BluetoothDevice#createL2capChannel(int)}
     * @hide
     */
     */
    public int getChannelType() {
    @Deprecated
        return mChannelType;
    }

    public static final Parcelable.Creator<BluetoothHealthAppConfiguration> CREATOR =
    public static final Parcelable.Creator<BluetoothHealthAppConfiguration> CREATOR =
            new Parcelable.Creator<BluetoothHealthAppConfiguration>() {
            new Parcelable.Creator<BluetoothHealthAppConfiguration>() {
                @Override
                @Override
                public BluetoothHealthAppConfiguration createFromParcel(Parcel in) {
                public BluetoothHealthAppConfiguration createFromParcel(Parcel in) {
                    String name = in.readString();
                    return new BluetoothHealthAppConfiguration();
                    int type = in.readInt();
                    int role = in.readInt();
                    int channelType = in.readInt();
                    return new BluetoothHealthAppConfiguration(name, type, role,
                            channelType);
                }
                }


                @Override
                @Override
@@ -153,10 +104,5 @@ public final class BluetoothHealthAppConfiguration implements Parcelable {
            };
            };


    @Override
    @Override
    public void writeToParcel(Parcel out, int flags) {
    public void writeToParcel(Parcel out, int flags) {}
        out.writeString(mName);
        out.writeInt(mDataType);
        out.writeInt(mRole);
        out.writeInt(mChannelType);
    }
}
}
+18 −0
Original line number Original line Diff line number Diff line
@@ -23,7 +23,13 @@ import android.util.Log;


/**
/**
 * This abstract class is used to implement {@link BluetoothHealth} callbacks.
 * 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 {
public abstract class BluetoothHealthCallback {
    private static final String TAG = "BluetoothHealthCallback";
    private static final String TAG = "BluetoothHealthCallback";


@@ -38,8 +44,14 @@ public abstract class BluetoothHealthCallback {
     * BluetoothHealth#APP_CONFIG_REGISTRATION_FAILURE} or
     * BluetoothHealth#APP_CONFIG_REGISTRATION_FAILURE} or
     * {@link BluetoothHealth#APP_CONFIG_UNREGISTRATION_SUCCESS}
     * {@link BluetoothHealth#APP_CONFIG_UNREGISTRATION_SUCCESS}
     * or {@link BluetoothHealth#APP_CONFIG_UNREGISTRATION_FAILURE}
     * 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
    @BinderThread
    @Deprecated
    public void onHealthAppConfigurationStatusChange(BluetoothHealthAppConfiguration config,
    public void onHealthAppConfigurationStatusChange(BluetoothHealthAppConfiguration config,
            int status) {
            int status) {
        Log.d(TAG, "onHealthAppConfigurationStatusChange: " + config + "Status: " + 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 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
     * @param channelId The id associated with the channel. This id will be used in future calls
     * like when disconnecting the channel.
     * 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
    @BinderThread
    @Deprecated
    public void onHealthChannelStateChange(BluetoothHealthAppConfiguration config,
    public void onHealthChannelStateChange(BluetoothHealthAppConfiguration config,
            BluetoothDevice device, int prevState, int newState, ParcelFileDescriptor fd,
            BluetoothDevice device, int prevState, int newState, ParcelFileDescriptor fd,
            int channelId) {
            int channelId) {
+9 −4
Original line number Original line Diff line number Diff line
@@ -72,7 +72,13 @@ public interface BluetoothProfile {


    /**
    /**
     * Health Profile
     * 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;
    int HEALTH = 3;


    /**
    /**
@@ -269,9 +275,8 @@ public interface BluetoothProfile {
         * Called to notify the client when the proxy object has been
         * Called to notify the client when the proxy object has been
         * connected to the service.
         * connected to the service.
         *
         *
         * @param profile - One of {@link #HEALTH}, {@link #HEADSET} or {@link #A2DP}
         * @param profile - One of {@link #HEADSET} or {@link #A2DP}
         * @param proxy - One of {@link BluetoothHealth}, {@link BluetoothHeadset} or {@link
         * @param proxy - One of {@link BluetoothHeadset} or {@link BluetoothA2dp}
         * BluetoothA2dp}
         */
         */
        public void onServiceConnected(int profile, BluetoothProfile proxy);
        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
         * Called to notify the client that this proxy object has been
         * disconnected from the service.
         * 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);
        public void onServiceDisconnected(int profile);
    }
    }