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

Commit 8b44b3f9 authored by Angela Wang's avatar Angela Wang Committed by Gerrit Code Review
Browse files

Merge "Adds some HAP feature related methods as system API"

parents 42ef52c2 31091f2d
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -253,14 +253,23 @@ package android.bluetooth {
    method @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED}) public int getConnectionPolicy(@Nullable android.bluetooth.BluetoothDevice);
    method @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED}) public int getConnectionState(@NonNull android.bluetooth.BluetoothDevice);
    method @NonNull @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED}) public java.util.List<android.bluetooth.BluetoothDevice> getDevicesMatchingConnectionStates(@NonNull int[]);
    method @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED}) public int getHearingAidType(@NonNull android.bluetooth.BluetoothDevice);
    method @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED}) public void registerCallback(@NonNull java.util.concurrent.Executor, @NonNull android.bluetooth.BluetoothHapClient.Callback);
    method @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED}) public void selectPreset(@NonNull android.bluetooth.BluetoothDevice, int);
    method @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED}) public void selectPresetForGroup(int, int);
    method @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED}) public boolean setConnectionPolicy(@NonNull android.bluetooth.BluetoothDevice, int);
    method @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED}) public void setPresetName(@NonNull android.bluetooth.BluetoothDevice, int, @NonNull String);
    method @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED}) public void setPresetNameForGroup(int, int, @NonNull String);
    method @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED}) public boolean supportDynamicPresets(@NonNull android.bluetooth.BluetoothDevice);
    method @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED}) public boolean supportIndependentPresets(@NonNull android.bluetooth.BluetoothDevice);
    method @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED}) public boolean supportSynchronizedPresets(@NonNull android.bluetooth.BluetoothDevice);
    method @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED}) public boolean supportWritablePresets(@NonNull android.bluetooth.BluetoothDevice);
    method @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED}) public void unregisterCallback(@NonNull android.bluetooth.BluetoothHapClient.Callback);
    field @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED}) public static final String ACTION_HAP_CONNECTION_STATE_CHANGED = "android.bluetooth.action.HAP_CONNECTION_STATE_CHANGED";
    field public static final int TYPE_BANDED = 2; // 0x2
    field public static final int TYPE_BINAURAL = 0; // 0x0
    field public static final int TYPE_MONAURAL = 1; // 0x1
    field public static final int TYPE_RFU = 3; // 0x3
  }

  public static interface BluetoothHapClient.Callback {
+155 −26
Original line number Diff line number Diff line
@@ -357,7 +357,7 @@ public final class BluetoothHapClient implements BluetoothProfile, AutoCloseable
    public static final String EXTRA_HAP_FEATURES = "android.bluetooth.extra.HAP_FEATURES";

    /**
     * Represets an invalid index value. This is usually value returned in a currently
     * Represents an invalid index value. This is usually value returned in a currently
     * active preset request for a device which is not connected. This value shouldn't be used
     * in the API calls.
     * @hide
@@ -365,45 +365,84 @@ public final class BluetoothHapClient implements BluetoothProfile, AutoCloseable
    public static final int PRESET_INDEX_UNAVAILABLE = IBluetoothHapClient.PRESET_INDEX_UNAVAILABLE;

    /**
     * Feature value.
     * Hearing aid type value. Indicates this Bluetooth device is belongs to a binaural hearing aid
     * set. A binaural hearing aid set is two hearing aids that form a Coordinated Set, one for the
     * right ear and one for the left ear of the user. Typically used by a user with bilateral
     * hearing loss.
     * @hide
     */
    public static final int FEATURE_TYPE_MONAURAL =
            1 << IBluetoothHapClient.FEATURE_BIT_NUM_TYPE_MONAURAL;
    @SystemApi
    public static final int TYPE_BINAURAL = 0b00;

    /**
     * Hearing aid type value. Indicates this Bluetooth device is a single hearing aid for the left
     * or the right ear. Typically used by a user with unilateral hearing loss.
     * @hide
     */
    @SystemApi
    public static final int TYPE_MONAURAL = 0b01;

    /**
     * Hearing aid type value. Indicates this Bluetooth device is two hearing aids with a connection
     * to one another that expose a single Bluetooth radio interface.
     * @hide
     */
    @SystemApi
    public static final int TYPE_BANDED = 0b10;

    /**
     * Feature value.
     * Hearing aid type value. This value is reserved for future use.
     * @hide
     */
    public static final int FEATURE_TYPE_BANDED =
            1 << IBluetoothHapClient.FEATURE_BIT_NUM_TYPE_BANDED;
    @SystemApi
    public static final int TYPE_RFU = 0b11;

    /**
     * Feature value.
     * @hide
     */
    public static final int FEATURE_SYNCHRONIZATED_PRESETS =
    @Retention(RetentionPolicy.SOURCE)
    @IntDef(
            flag = true,
            value = {
                    TYPE_BINAURAL,
                    TYPE_MONAURAL,
                    TYPE_BANDED,
                    TYPE_RFU,
            })
    @interface HearingAidType {}

    /**
     * Feature mask value.
     * @hide
     */
    public static final int FEATURE_HEARING_AID_TYPE_MASK = 0b11;

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

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

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

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

    /**
@@ -413,13 +452,13 @@ public final class BluetoothHapClient implements BluetoothProfile, AutoCloseable
    @IntDef(
            flag = true,
            value = {
            FEATURE_TYPE_MONAURAL,
            FEATURE_TYPE_BANDED,
            FEATURE_SYNCHRONIZATED_PRESETS,
            FEATURE_DYNAMIC_PRESETS,
            FEATURE_WRITABLE_PRESETS,
                    FEATURE_HEARING_AID_TYPE_MASK,
                    FEATURE_SYNCHRONIZATED_PRESETS_MASK,
                    FEATURE_INDEPENDENT_PRESETS_MASK,
                    FEATURE_DYNAMIC_PRESETS_MASK,
                    FEATURE_WRITABLE_PRESETS_MASK,
            })
    @interface Feature {}
    @interface FeatureMask {}

    private final BluetoothAdapter mAdapter;
    private final AttributionSource mAttributionSource;
@@ -632,7 +671,7 @@ public final class BluetoothHapClient implements BluetoothProfile, AutoCloseable
     *
     * @param device Paired bluetooth device
     * @param connectionPolicy is the connection policy to set to for this profile
     * @return true if connectionPolicy is set, false on error
     * @return {@code true} if connectionPolicy is set, {@code false} on error
     * @hide
     */
    @SystemApi
@@ -1181,7 +1220,7 @@ public final class BluetoothHapClient implements BluetoothProfile, AutoCloseable
            android.Manifest.permission.BLUETOOTH_CONNECT,
            android.Manifest.permission.BLUETOOTH_PRIVILEGED
    })
    public @Feature int getFeatures(@NonNull BluetoothDevice device) {
    public int getFeatures(@NonNull BluetoothDevice device) {
        final IBluetoothHapClient service = getService();
        final int defaultValue = 0x00;
        if (service == null) {
@@ -1201,6 +1240,96 @@ public final class BluetoothHapClient implements BluetoothProfile, AutoCloseable
        return defaultValue;
    }

    /**
     * Retrieves hearing aid type from feature value.
     *
     * @param device is the device for which we want to get the hearing aid type
     * @return hearing aid type
     * @hide
     */
    @SystemApi
    @RequiresBluetoothConnectPermission
    @RequiresPermission(allOf = {
            android.Manifest.permission.BLUETOOTH_CONNECT,
            android.Manifest.permission.BLUETOOTH_PRIVILEGED
    })
    @HearingAidType
    public int getHearingAidType(@NonNull BluetoothDevice device) {
        return getFeatures(device) & FEATURE_HEARING_AID_TYPE_MASK;
    }

    /**
     * Retrieves if this device supports synchronized presets or not from feature value.
     *
     * @param device is the device for which we want to know if it supports synchronized presets
     * @return {@code true} if the device supports synchronized presets, {@code false} otherwise
     * @hide
     */
    @SystemApi
    @RequiresBluetoothConnectPermission
    @RequiresPermission(allOf = {
            android.Manifest.permission.BLUETOOTH_CONNECT,
            android.Manifest.permission.BLUETOOTH_PRIVILEGED
    })
    public boolean supportSynchronizedPresets(@NonNull BluetoothDevice device) {
        return (getFeatures(device) & FEATURE_SYNCHRONIZATED_PRESETS_MASK)
                == FEATURE_SYNCHRONIZATED_PRESETS_MASK;
    }

    /**
     * Retrieves if this device supports independent presets or not from feature value.
     *
     * @param device is the device for which we want to know if it supports independent presets
     * @return {@code true} if the device supports independent presets, {@code false} otherwise
     * @hide
     */
    @SystemApi
    @RequiresBluetoothConnectPermission
    @RequiresPermission(allOf = {
            android.Manifest.permission.BLUETOOTH_CONNECT,
            android.Manifest.permission.BLUETOOTH_PRIVILEGED
    })
    public boolean supportIndependentPresets(@NonNull BluetoothDevice device) {
        return (getFeatures(device) & FEATURE_INDEPENDENT_PRESETS_MASK)
                == FEATURE_INDEPENDENT_PRESETS_MASK;
    }

    /**
     * Retrieves if this device supports dynamic presets or not from feature value.
     *
     * @param device is the device for which we want to know if it supports dynamic presets
     * @return {@code true} if the device supports dynamic presets, {@code false} otherwise
     * @hide
     */
    @SystemApi
    @RequiresBluetoothConnectPermission
    @RequiresPermission(allOf = {
            android.Manifest.permission.BLUETOOTH_CONNECT,
            android.Manifest.permission.BLUETOOTH_PRIVILEGED
    })
    public boolean supportDynamicPresets(@NonNull BluetoothDevice device) {
        return (getFeatures(device) & FEATURE_DYNAMIC_PRESETS_MASK)
                == FEATURE_DYNAMIC_PRESETS_MASK;
    }

    /**
     * Retrieves if this device supports writable presets or not from feature value.
     *
     * @param device is the device for which we want to know if it supports writable presets
     * @return {@code true} if the device supports writable presets, {@code false} otherwise
     * @hide
     */
    @SystemApi
    @RequiresBluetoothConnectPermission
    @RequiresPermission(allOf = {
            android.Manifest.permission.BLUETOOTH_CONNECT,
            android.Manifest.permission.BLUETOOTH_PRIVILEGED
    })
    public boolean supportWritablePresets(@NonNull BluetoothDevice device) {
        return (getFeatures(device) & FEATURE_WRITABLE_PRESETS_MASK)
                == FEATURE_WRITABLE_PRESETS_MASK;
    }

    /**
     * Sets the preset name for a particular device
     *