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

Commit 31cb77c6 authored by Hansong Zhang's avatar Hansong Zhang
Browse files

Hearing Aid: change get/set active device (3/3)

* setActiveDevice() returns false in error case, e.g. when the device is
not connected
* add getActiveDevices() instead of isActiveDevice(), which returns a list
that must have two elements: left and right, or empty list on error

Test: manual
Bug: 69623109
Change-Id: I48f3388c56434d0c21e09bd8b794e58848cd8794
(cherry picked from commit ba0b0ec0)
parent 109ab00f
Loading
Loading
Loading
Loading
+10 −10
Original line number Original line Diff line number Diff line
@@ -421,29 +421,29 @@ public final class BluetoothHearingAid implements BluetoothProfile {
    }
    }


    /**
    /**
     * Check whether the device is active.
     * Get the connected physical Hearing Aid devices that are active
     *
     *
     * <p>Requires {@link android.Manifest.permission#BLUETOOTH}
     * <p>Requires {@link android.Manifest.permission#BLUETOOTH}
     * permission.
     * permission.
     *
     *
     * @return the connected device that is active or null if no device
     * @return the list of active devices. The first element is the left active
     * is active
     * device; the second element is the right active device. If either or both side
     * is not active, it will be null on that position. Returns empty list on error.
     * @hide
     * @hide
     */
     */
    @RequiresPermission(Manifest.permission.BLUETOOTH)
    @RequiresPermission(Manifest.permission.BLUETOOTH)
    public boolean isActiveDevice(@Nullable BluetoothDevice device) {
    public List<BluetoothDevice> getActiveDevices() {
        if (VDBG) log("isActiveDevice()");
        if (VDBG) log("getActiveDevices()");
        try {
        try {
            mServiceLock.readLock().lock();
            mServiceLock.readLock().lock();
            if (mService != null && isEnabled()
            if (mService != null && isEnabled()) {
                    && ((device == null) || isValidDevice(device))) {
                return mService.getActiveDevices();
                return mService.isActiveDevice(device);
            }
            }
            if (mService == null) Log.w(TAG, "Proxy not attached to service");
            if (mService == null) Log.w(TAG, "Proxy not attached to service");
            return false;
            return new ArrayList<>();
        } catch (RemoteException e) {
        } catch (RemoteException e) {
            Log.e(TAG, "Stack:" + Log.getStackTraceString(new Throwable()));
            Log.e(TAG, "Stack:" + Log.getStackTraceString(new Throwable()));
            return false;
            return new ArrayList<>();
        } finally {
        } finally {
            mServiceLock.readLock().unlock();
            mServiceLock.readLock().unlock();
        }
        }