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

Commit 14fb250d authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge changes from topic "hap_api_improvements_p1" am: 2f657b3d am: 8f609b01

Original change: https://android-review.googlesource.com/c/platform/packages/modules/Bluetooth/+/2012900

Change-Id: I8a94b13a56f590fa050583e1bb56286848bd62d6
parents fb66da91 8f609b01
Loading
Loading
Loading
Loading
+53 −42
Original line number Diff line number Diff line
@@ -43,6 +43,7 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.Executor;
import java.util.concurrent.TimeoutException;

@@ -141,15 +142,12 @@ public final class BluetoothHapClient implements BluetoothProfile, AutoCloseable
         * Invoked to inform about HA device's feature set.
         *
         * @param device remote device
         * @param hapFeatures the feature set integer with these possible bit numbers
         *  set: {@link #FEATURE_BIT_NUM_TYPE_MONAURAL}, {@link #FEATURE_BIT_NUM_TYPE_BANDED},
         *  {@link #FEATURE_BIT_NUM_SYNCHRONIZATED_PRESETS},
         *  {@link #FEATURE_BIT_NUM_INDEPENDENT_PRESETS}, {@link #FEATURE_BIT_NUM_DYNAMIC_PRESETS},
         *  {@link #FEATURE_BIT_NUM_WRITABLE_PRESETS}.
         * @param hapFeatures the feature set integer with feature bits set. The inidividual bits
         * are defined by Bluetooth SIG in Hearing Access Service specification.
         *
         * @hide
         */
        void onHapFeaturesAvailable(@NonNull BluetoothDevice device, int hapFeatures);
        void onHapFeaturesAvailable(@NonNull BluetoothDevice device, @Feature int hapFeatures);

        /**
         * Invoked to inform about the failed preset rename attempt.
@@ -223,7 +221,8 @@ public final class BluetoothHapClient implements BluetoothProfile, AutoCloseable
        }

        @Override
        public void onHapFeaturesAvailable(@NonNull BluetoothDevice device, int hapFeatures) {
        public void onHapFeaturesAvailable(@NonNull BluetoothDevice device,
                @Feature int hapFeatures) {
            Attributable.setAttributionSource(device, mAttributionSource);
            for (Map.Entry<BluetoothHapClient.Callback, Executor> callbackExecutorEntry:
                    mCallbackExecutorMap.entrySet()) {
@@ -318,46 +317,61 @@ public final class BluetoothHapClient implements BluetoothProfile, AutoCloseable
    public static final int PRESET_INDEX_UNAVAILABLE = IBluetoothHapClient.PRESET_INDEX_UNAVAILABLE;

    /**
     * Feature bit.
     * Feature value.
     * @hide
     */
    public static final int FEATURE_BIT_NUM_TYPE_MONAURAL =
            IBluetoothHapClient.FEATURE_BIT_NUM_TYPE_MONAURAL;
    public static final int FEATURE_TYPE_MONAURAL =
            1 << IBluetoothHapClient.FEATURE_BIT_NUM_TYPE_MONAURAL;

    /**
     * Feature bit.
     * Feature value.
     * @hide
     */
    public static final int FEATURE_BIT_NUM_TYPE_BANDED =
            IBluetoothHapClient.FEATURE_BIT_NUM_TYPE_BANDED;
    public static final int FEATURE_TYPE_BANDED =
            1 << IBluetoothHapClient.FEATURE_BIT_NUM_TYPE_BANDED;

    /**
     * Feature bit.
     * Feature value.
     * @hide
     */
    public static final int FEATURE_BIT_NUM_SYNCHRONIZATED_PRESETS =
            IBluetoothHapClient.FEATURE_BIT_NUM_SYNCHRONIZATED_PRESETS;
    public static final int FEATURE_SYNCHRONIZATED_PRESETS =
            1 << IBluetoothHapClient.FEATURE_BIT_NUM_SYNCHRONIZATED_PRESETS;

    /**
     * Feature bit.
     * Feature value.
     * @hide
     */
    public static final int FEATURE_BIT_NUM_INDEPENDENT_PRESETS =
            IBluetoothHapClient.FEATURE_BIT_NUM_INDEPENDENT_PRESETS;
    public static final int FEATURE_INDEPENDENT_PRESETS =
            1 << IBluetoothHapClient.FEATURE_BIT_NUM_INDEPENDENT_PRESETS;

    /**
     * Feature bit.
     * Feature value.
     * @hide
     */
    public static final int FEATURE_BIT_NUM_DYNAMIC_PRESETS =
            IBluetoothHapClient.FEATURE_BIT_NUM_DYNAMIC_PRESETS;
    public static final int FEATURE_DYNAMIC_PRESETS =
            1 << IBluetoothHapClient.FEATURE_BIT_NUM_DYNAMIC_PRESETS;

    /**
     * Feature bit.
     * Feature value.
     * @hide
     */
    public static final int FEATURE_BIT_NUM_WRITABLE_PRESETS =
            IBluetoothHapClient.FEATURE_BIT_NUM_WRITABLE_PRESETS;
    public static final int FEATURE_WRITABLE_PRESETS =
            1 << IBluetoothHapClient.FEATURE_BIT_NUM_WRITABLE_PRESETS;

    /**
     * @hide
     */
    @Retention(RetentionPolicy.SOURCE)
    @IntDef(
        flag = true,
        value = {
            FEATURE_TYPE_MONAURAL,
            FEATURE_TYPE_BANDED,
            FEATURE_SYNCHRONIZATED_PRESETS,
            FEATURE_DYNAMIC_PRESETS,
            FEATURE_WRITABLE_PRESETS,
    })
    @interface Feature {}

    private final BluetoothAdapter mAdapter;
    private final AttributionSource mAttributionSource;
@@ -457,14 +471,16 @@ public final class BluetoothHapClient implements BluetoothProfile, AutoCloseable
     * Register a {@link Callback} that will be invoked during the
     * operation of this profile.
     *
     * Repeated registration of the same <var>callback</var> object will have no effect after
     * the first call to this method, even when the <var>executor</var> is different. API caller
     * would have to call {@link #unregisterCallback(Callback)} with
     * the same callback object before registering it again.
     * Repeated registration of the same <var>callback</var> object after the first call to this
     * method will result with IllegalArgumentException being thrown, even when the
     * <var>executor</var> is different. API caller would have to call
     * {@link #unregisterCallback(Callback)} with the same callback object before registering it
     * again.
     *
     * @param executor an {@link Executor} to execute given callback
     * @param callback user implementation of the {@link Callback}
     * @throws IllegalArgumentException if a null executor, sink, or callback is given
     * @throws NullPointerException if a null executor, or callback is given, or
     *  IllegalArgumentException if the same <var>callback<var> is already registered.
     * @hide
     */
    @SystemApi
@@ -475,12 +491,8 @@ public final class BluetoothHapClient implements BluetoothProfile, AutoCloseable
    })
    public void registerCallback(@NonNull @CallbackExecutor Executor executor,
            @NonNull Callback callback) {
        if (executor == null) {
            throw new IllegalArgumentException("executor cannot be null");
        }
        if (callback == null) {
            throw new IllegalArgumentException("callback cannot be null");
        }
        Objects.requireNonNull(executor, "executor cannot be null");
        Objects.requireNonNull(callback, "callback cannot be null");
        if (!isEnabled()) {
            throw new IllegalStateException("service not enabled");
        }
@@ -521,7 +533,8 @@ public final class BluetoothHapClient implements BluetoothProfile, AutoCloseable
     * <p>Callbacks are automatically unregistered when application process goes away
     *
     * @param callback user implementation of the {@link Callback}
     * @throws IllegalArgumentException when callback is null or when no callback is registered
     * @throws NullPointerException when callback is null or IllegalArgumentException when no
     *  callback is registered
     * @hide
     */
    @SystemApi
@@ -531,9 +544,7 @@ public final class BluetoothHapClient implements BluetoothProfile, AutoCloseable
            android.Manifest.permission.BLUETOOTH_PRIVILEGED,
    })
    public void unregisterCallback(@NonNull Callback callback) {
        if (callback == null) {
            throw new IllegalArgumentException("callback cannot be null");
        }
        Objects.requireNonNull(callback, "callback cannot be null");

        if (DBG) log("unregisterCallback");

@@ -1108,7 +1119,7 @@ public final class BluetoothHapClient implements BluetoothProfile, AutoCloseable
     * Requests HAP features
     *
     * @param device is the device for which we want to get features for
     * @return true if request was processed, false otherwise
     * @return features value with feature bits set
     * @hide
     */
    @RequiresBluetoothConnectPermission
@@ -1116,7 +1127,7 @@ public final class BluetoothHapClient implements BluetoothProfile, AutoCloseable
            android.Manifest.permission.BLUETOOTH_CONNECT,
            android.Manifest.permission.BLUETOOTH_PRIVILEGED
    })
    public int getFeatures(@NonNull BluetoothDevice device) {
    public @Feature int getFeatures(@NonNull BluetoothDevice device) {
        final IBluetoothHapClient service = getService();
        final int defaultValue = 0x00;
        if (service == null) {