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

Commit b88cf66c authored by Jason Hsu's avatar Jason Hsu Committed by Gerrit Code Review
Browse files

Merge "Change to @SystemApi for BluetoothHearingAid 2 APIs"

parents 44e52234 0a85f959
Loading
Loading
Loading
Loading
+10 −4
Original line number Original line Diff line number Diff line
@@ -1064,9 +1064,12 @@ public class HearingAidService extends ProfileService {
                SynchronousResultReceiver receiver) {
                SynchronousResultReceiver receiver) {
            try {
            try {
                HearingAidService service = getService(source);
                HearingAidService service = getService(source);
                int side = BluetoothHearingAid.SIDE_RIGHT;
                int side = BluetoothHearingAid.SIDE_UNKNOWN;
                if (service != null) {
                if (service != null) {
                    side = service.getCapabilities(device) & 1;
                    side = service.getCapabilities(device);
                    if (side != BluetoothHearingAid.SIDE_UNKNOWN) {
                        side &= 1;
                    }
                }
                }
                receiver.send(side);
                receiver.send(side);
            } catch (RuntimeException e) {
            } catch (RuntimeException e) {
@@ -1079,9 +1082,12 @@ public class HearingAidService extends ProfileService {
                SynchronousResultReceiver receiver) {
                SynchronousResultReceiver receiver) {
            try {
            try {
                HearingAidService service = getService(source);
                HearingAidService service = getService(source);
                int mode = BluetoothHearingAid.MODE_BINAURAL;
                int mode = BluetoothHearingAid.MODE_UNKNOWN;
                if (service != null) {
                if (service != null) {
                    mode = service.getCapabilities(device) >> 1 & 1;
                    mode = service.getCapabilities(device);
                    if (mode != BluetoothHearingAid.MODE_UNKNOWN) {
                        mode = mode >> 1 & 1;
                    }
                }
                }
                receiver.send(mode);
                receiver.send(mode);
            } catch (RuntimeException e) {
            } catch (RuntimeException e) {
+8 −5
Original line number Original line Diff line number Diff line
@@ -1079,18 +1079,21 @@ public class HearingAidServiceTest {
        final SynchronousResultReceiver<Integer> recv = SynchronousResultReceiver.get();
        final SynchronousResultReceiver<Integer> recv = SynchronousResultReceiver.get();
        mServiceBinder.getDeviceMode(mSingleDevice, null, recv);
        mServiceBinder.getDeviceMode(mSingleDevice, null, recv);
        int mode = recv.awaitResultNoInterrupt(Duration.ofMillis(TIMEOUT_MS))
        int mode = recv.awaitResultNoInterrupt(Duration.ofMillis(TIMEOUT_MS))
                .getValue(BluetoothHearingAid.MODE_MONAURAL);
                .getValue(BluetoothHearingAid.MODE_UNKNOWN);
        Assert.assertEquals(BluetoothHearingAid.MODE_BINAURAL, mode);

        // return unknown value if no device connected
        Assert.assertEquals(BluetoothHearingAid.MODE_UNKNOWN, mode);
    }
    }


    @Test
    @Test
    public void serviceBinder_callGetDeviceSide() throws Exception {
    public void serviceBinder_callGetDeviceSide() throws Exception {
        final SynchronousResultReceiver<Integer> recv = SynchronousResultReceiver.get();
        final SynchronousResultReceiver<Integer> recv = SynchronousResultReceiver.get();
        int defaultRecvValue = -1000;
        mServiceBinder.getDeviceSide(mSingleDevice, null, recv);
        mServiceBinder.getDeviceSide(mSingleDevice, null, recv);
        int side = recv.awaitResultNoInterrupt(Duration.ofMillis(TIMEOUT_MS))
        int side = recv.awaitResultNoInterrupt(Duration.ofMillis(TIMEOUT_MS))
                .getValue(defaultRecvValue);
                .getValue(BluetoothHearingAid.SIDE_UNKNOWN);
        Assert.assertEquals(BluetoothHearingAid.SIDE_RIGHT, side);

        // return unknown value if no device connected
        Assert.assertEquals(BluetoothHearingAid.SIDE_UNKNOWN, side);
    }
    }


    @Test
    @Test
+8 −0
Original line number Original line Diff line number Diff line
@@ -335,11 +335,19 @@ package android.bluetooth {


  public final class BluetoothHearingAid implements android.bluetooth.BluetoothProfile {
  public final class BluetoothHearingAid implements android.bluetooth.BluetoothProfile {
    method @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED}) public int getConnectionPolicy(@NonNull android.bluetooth.BluetoothDevice);
    method @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED}) public int getConnectionPolicy(@NonNull android.bluetooth.BluetoothDevice);
    method @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT) public int getDeviceMode(@NonNull android.bluetooth.BluetoothDevice);
    method @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT) public int getDeviceSide(@NonNull android.bluetooth.BluetoothDevice);
    method @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED}) public long getHiSyncId(@NonNull android.bluetooth.BluetoothDevice);
    method @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED}) public long getHiSyncId(@NonNull android.bluetooth.BluetoothDevice);
    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 boolean setConnectionPolicy(@NonNull android.bluetooth.BluetoothDevice, int);
    method @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED}) public void setVolume(int);
    method @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED}) public void setVolume(int);
    field @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT) public static final String ACTION_ACTIVE_DEVICE_CHANGED = "android.bluetooth.hearingaid.profile.action.ACTIVE_DEVICE_CHANGED";
    field @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT) public static final String ACTION_ACTIVE_DEVICE_CHANGED = "android.bluetooth.hearingaid.profile.action.ACTIVE_DEVICE_CHANGED";
    field public static final long HI_SYNC_ID_INVALID = 0L; // 0x0L
    field public static final long HI_SYNC_ID_INVALID = 0L; // 0x0L
    field public static final int MODE_BINAURAL = 1; // 0x1
    field public static final int MODE_MONAURAL = 0; // 0x0
    field public static final int MODE_UNKNOWN = -1; // 0xffffffff
    field public static final int SIDE_LEFT = 0; // 0x0
    field public static final int SIDE_RIGHT = 1; // 0x1
    field public static final int SIDE_UNKNOWN = -1; // 0xffffffff
  }
  }


  public final class BluetoothHidDevice implements android.bluetooth.BluetoothProfile {
  public final class BluetoothHidDevice implements android.bluetooth.BluetoothProfile {
+55 −6
Original line number Original line Diff line number Diff line
@@ -18,6 +18,7 @@ package android.bluetooth;


import static android.bluetooth.BluetoothUtils.getSyncTimeout;
import static android.bluetooth.BluetoothUtils.getSyncTimeout;


import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.Nullable;
import android.annotation.RequiresPermission;
import android.annotation.RequiresPermission;
@@ -38,6 +39,8 @@ import android.util.Log;


import com.android.modules.utils.SynchronousResultReceiver;
import com.android.modules.utils.SynchronousResultReceiver;


import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.ArrayList;
import java.util.ArrayList;
import java.util.List;
import java.util.List;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.TimeoutException;
@@ -100,11 +103,29 @@ public final class BluetoothHearingAid implements BluetoothProfile {
    public static final String ACTION_ACTIVE_DEVICE_CHANGED =
    public static final String ACTION_ACTIVE_DEVICE_CHANGED =
            "android.bluetooth.hearingaid.profile.action.ACTIVE_DEVICE_CHANGED";
            "android.bluetooth.hearingaid.profile.action.ACTIVE_DEVICE_CHANGED";


    /** @hide */
    @IntDef(prefix = "SIDE_", value = {
            SIDE_UNKNOWN,
            SIDE_LEFT,
            SIDE_RIGHT
    })
    @Retention(RetentionPolicy.SOURCE)
    public @interface DeviceSide {}

    /**
     * Indicates the device side could not be read.
     *
     * @hide
     */
    @SystemApi
    public static final int SIDE_UNKNOWN = -1;

    /**
    /**
     * This device represents Left Hearing Aid.
     * This device represents Left Hearing Aid.
     *
     *
     * @hide
     * @hide
     */
     */
    @SystemApi
    public static final int SIDE_LEFT = IBluetoothHearingAid.SIDE_LEFT;
    public static final int SIDE_LEFT = IBluetoothHearingAid.SIDE_LEFT;


    /**
    /**
@@ -112,13 +133,32 @@ public final class BluetoothHearingAid implements BluetoothProfile {
     *
     *
     * @hide
     * @hide
     */
     */
    @SystemApi
    public static final int SIDE_RIGHT = IBluetoothHearingAid.SIDE_RIGHT;
    public static final int SIDE_RIGHT = IBluetoothHearingAid.SIDE_RIGHT;


    /** @hide */
    @IntDef(prefix = "MODE_", value = {
            MODE_UNKNOWN,
            MODE_MONAURAL,
            MODE_BINAURAL
    })
    @Retention(RetentionPolicy.SOURCE)
    public @interface DeviceMode {}

    /**
     * Indicates the device mode could not be read.
     *
     * @hide
     */
    @SystemApi
    public static final int MODE_UNKNOWN = -1;

    /**
    /**
     * This device is Monaural.
     * This device is Monaural.
     *
     *
     * @hide
     * @hide
     */
     */
    @SystemApi
    public static final int MODE_MONAURAL = IBluetoothHearingAid.MODE_MONAURAL;
    public static final int MODE_MONAURAL = IBluetoothHearingAid.MODE_MONAURAL;


    /**
    /**
@@ -126,6 +166,7 @@ public final class BluetoothHearingAid implements BluetoothProfile {
     *
     *
     * @hide
     * @hide
     */
     */
    @SystemApi
    public static final int MODE_BINAURAL = IBluetoothHearingAid.MODE_BINAURAL;
    public static final int MODE_BINAURAL = IBluetoothHearingAid.MODE_BINAURAL;


    /**
    /**
@@ -619,16 +660,20 @@ public final class BluetoothHearingAid implements BluetoothProfile {
     * Get the side of the device.
     * Get the side of the device.
     *
     *
     * @param device Bluetooth device.
     * @param device Bluetooth device.
     * @return SIDE_LEFT or SIDE_RIGHT
     * @return the {@code SIDE_LEFT}, {@code SIDE_RIGHT} of the device, or {@code SIDE_UNKNOWN} if
     *         one is not available.
     * @hide
     * @hide
     */
     */
    @SystemApi
    @RequiresLegacyBluetoothPermission
    @RequiresLegacyBluetoothPermission
    @RequiresBluetoothConnectPermission
    @RequiresBluetoothConnectPermission
    @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)
    @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)
    public int getDeviceSide(BluetoothDevice device) {
    @DeviceSide
    public int getDeviceSide(@NonNull BluetoothDevice device) {
        if (VDBG) log("getDeviceSide(" + device + ")");
        if (VDBG) log("getDeviceSide(" + device + ")");
        verifyDeviceNotNull(device, "getDeviceSide");
        final IBluetoothHearingAid service = getService();
        final IBluetoothHearingAid service = getService();
        final int defaultValue = SIDE_LEFT;
        final int defaultValue = SIDE_UNKNOWN;
        if (service == null) {
        if (service == null) {
            Log.w(TAG, "Proxy not attached to service");
            Log.w(TAG, "Proxy not attached to service");
            if (DBG) log(Log.getStackTraceString(new Throwable()));
            if (DBG) log(Log.getStackTraceString(new Throwable()));
@@ -648,16 +693,20 @@ public final class BluetoothHearingAid implements BluetoothProfile {
     * Get the mode of the device.
     * Get the mode of the device.
     *
     *
     * @param device Bluetooth device
     * @param device Bluetooth device
     * @return MODE_MONAURAL or MODE_BINAURAL
     * @return the {@code MODE_MONAURAL}, {@code MODE_BINAURAL} of the device, or
     *         {@code MODE_UNKNOWN} if one is not available.
     * @hide
     * @hide
     */
     */
    @SystemApi
    @RequiresLegacyBluetoothPermission
    @RequiresLegacyBluetoothPermission
    @RequiresBluetoothConnectPermission
    @RequiresBluetoothConnectPermission
    @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)
    @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)
    public int getDeviceMode(BluetoothDevice device) {
    @DeviceMode
    public int getDeviceMode(@NonNull  BluetoothDevice device) {
        if (VDBG) log("getDeviceMode(" + device + ")");
        if (VDBG) log("getDeviceMode(" + device + ")");
        verifyDeviceNotNull(device, "getDeviceMode");
        final IBluetoothHearingAid service = getService();
        final IBluetoothHearingAid service = getService();
        final int defaultValue = MODE_MONAURAL;
        final int defaultValue = MODE_UNKNOWN;
        if (service == null) {
        if (service == null) {
            Log.w(TAG, "Proxy not attached to service");
            Log.w(TAG, "Proxy not attached to service");
            if (DBG) log(Log.getStackTraceString(new Throwable()));
            if (DBG) log(Log.getStackTraceString(new Throwable()));