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

Commit 6b951550 authored by Angela Wang's avatar Angela Wang Committed by Android (Google) Code Review
Browse files

Merge "Fix pair other ear button not hidden correctly for dual device" into main

parents e16afdb7 79c7623f
Loading
Loading
Loading
Loading
+11 −20
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.settings.bluetooth;

import android.bluetooth.BluetoothDevice;
import android.content.Context;

import androidx.preference.PreferenceFragmentCompat;
@@ -75,7 +76,6 @@ public class BluetoothDetailsPairOtherController extends BluetoothDetailsControl
    protected void refresh() {
        updateButtonPreferenceTitle(mPreference);
        setPreferencesVisibility(getButtonPreferenceVisibility(mCachedDevice));

    }

    private void updateButtonPreferenceTitle(ButtonPreference preference) {
@@ -97,7 +97,7 @@ public class BluetoothDetailsPairOtherController extends BluetoothDetailsControl
        if (!cachedDevice.isConnectedHearingAidDevice()) {
            return false;
        }
        return isBinauralMode(cachedDevice) && !isOtherSideConnected(cachedDevice);
        return isBinauralMode(cachedDevice) && !isOtherSideBonded(cachedDevice);
    }

    private void launchPairingDetail() {
@@ -112,25 +112,16 @@ public class BluetoothDetailsPairOtherController extends BluetoothDetailsControl
        return cachedDevice.getDeviceMode() == HearingAidInfo.DeviceMode.MODE_BINAURAL;
    }

    private boolean isOtherSideConnected(CachedBluetoothDevice cachedDevice) {
        // Check sub device for ASHA hearing aid
        if (cachedDevice.isConnectedAshaHearingAidDevice()) {
    private boolean isOtherSideBonded(CachedBluetoothDevice cachedDevice) {
        final CachedBluetoothDevice subDevice = cachedDevice.getSubDevice();
            if (subDevice != null && subDevice.isConnectedAshaHearingAidDevice()) {
                return true;
            }
        }
        final boolean subDeviceBonded =
                subDevice != null && subDevice.getBondState() == BluetoothDevice.BOND_BONDED;

        // Check member device for LE audio hearing aid
        if (cachedDevice.isConnectedLeAudioHearingAidDevice()) {
            final Set<CachedBluetoothDevice> memberDevices = cachedDevice.getMemberDevice();
            for (CachedBluetoothDevice memberDevice : memberDevices) {
                if (memberDevice.isConnectedLeAudioHearingAidDevice()) {
                    return true;
                }
            }
        }
        final Set<CachedBluetoothDevice> memberDevice = cachedDevice.getMemberDevice();
        final boolean allMemberDevicesBonded =
                !memberDevice.isEmpty() && memberDevice.stream().allMatch(
                        device -> device.getBondState() == BluetoothDevice.BOND_BONDED);

        return false;
        return subDeviceBonded || allMemberDevicesBonded;
    }
}
+35 −54
Original line number Diff line number Diff line
@@ -20,6 +20,8 @@ import static com.google.common.truth.Truth.assertThat;

import static org.mockito.Mockito.when;

import android.bluetooth.BluetoothDevice;

import com.android.settings.R;
import com.android.settings.applications.SpacePreference;
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
@@ -65,7 +67,7 @@ public class BluetoothDetailsPairOtherControllerTest extends BluetoothDetailsCon

    /** Test the pair other side button title during initialization. */
    @Test
    public void init_leftSideDevice_pairRightSideButtonTitle() {
    public void init_deviceIsLeftSide_showPairRightSideTitle() {
        when(mCachedDevice.getDeviceSide()).thenReturn(HearingAidInfo.DeviceSide.SIDE_LEFT);

        mController.init(mScreen);
@@ -76,7 +78,7 @@ public class BluetoothDetailsPairOtherControllerTest extends BluetoothDetailsCon

    /** Test the pair other side button title during initialization. */
    @Test
    public void init_rightSideDevice_pairLeftSideButtonTitle() {
    public void init_deviceIsRightSide_showPairLeftSideTitle() {
        when(mCachedDevice.getDeviceSide()).thenReturn(HearingAidInfo.DeviceSide.SIDE_RIGHT);

        mController.init(mScreen);
@@ -87,7 +89,7 @@ public class BluetoothDetailsPairOtherControllerTest extends BluetoothDetailsCon

    /** Test the pair other side button visibility during initialization. */
    @Test
    public void init_isNotConnectedHearingAidDevice_preferenceIsNotVisible() {
    public void init_deviceIsNotConnectedHearingAid_preferenceIsNotVisible() {
        when(mCachedDevice.isConnectedHearingAidDevice()).thenReturn(false);

        mController.init(mScreen);
@@ -99,13 +101,13 @@ public class BluetoothDetailsPairOtherControllerTest extends BluetoothDetailsCon
    /**
     * Test if the controller is available.
     * Conditions:
     *      1. Hearing aids is not connected
     *      1. The device is not a connected hearing aid
     * Expected result:
     *      The controller is not available. No need to show pair other side hint for
     *      not connected device.
     *      non-hearing aid device or not connected device.
     */
    @Test
    public void isAvailable_isNotConnectedHearingAidDevice_notAvailable() {
    public void isAvailable_deviceIsNotConnectedHearingAid_notAvailable() {
        when(mCachedDevice.isConnectedHearingAidDevice()).thenReturn(false);

        assertThat(mController.isAvailable()).isFalse();
@@ -114,13 +116,13 @@ public class BluetoothDetailsPairOtherControllerTest extends BluetoothDetailsCon
    /**
     * Test if the controller is available.
     * Conditions:
     *      1. Monaural hearing aids
     *      1. Monaural hearing aid
     * Expected result:
     *      The controller is not available. No need to show pair other side hint for
     *      monaural device.
     */
    @Test
    public void isAvailable_isConnectedHearingAidDevice_isMonaural_notAvailable() {
    public void isAvailable_deviceIsConnectedHearingAid_isMonaural_notAvailable() {
        when(mCachedDevice.isConnectedHearingAidDevice()).thenReturn(true);
        when(mCachedDevice.getDeviceMode()).thenReturn(HearingAidInfo.DeviceMode.MODE_MONAURAL);

@@ -130,18 +132,17 @@ public class BluetoothDetailsPairOtherControllerTest extends BluetoothDetailsCon
    /**
     * Test if the controller is available.
     * Conditions:
     *      1. Binaural ASHA hearing aids
     *      1. Binaural hearing aids
     *      2. Sub device is added
     *      3. Sub device is connected
     *      3. Sub device is bonded
     * Expected result:
     *      The controller is not available. Both sides are already paired and connected.
     *      The controller is not available. Both sides are already paired.
     */
    @Test
    public void isAvailable_ashaDevice_otherDeviceIsConnected_notAvailable() {
    public void isAvailable_deviceIsConnectedHearingAid_subDeviceIsBonded_notAvailable() {
        when(mCachedDevice.isConnectedHearingAidDevice()).thenReturn(true);
        when(mCachedDevice.isConnectedAshaHearingAidDevice()).thenReturn(true);
        when(mCachedDevice.getDeviceMode()).thenReturn(HearingAidInfo.DeviceMode.MODE_BINAURAL);
        when(mSubCachedDevice.isConnectedAshaHearingAidDevice()).thenReturn(true);
        when(mSubCachedDevice.getBondState()).thenReturn(BluetoothDevice.BOND_BONDED);
        when(mCachedDevice.getSubDevice()).thenReturn(mSubCachedDevice);

        assertThat(mController.isAvailable()).isFalse();
@@ -150,18 +151,17 @@ public class BluetoothDetailsPairOtherControllerTest extends BluetoothDetailsCon
    /**
     * Test if the controller is available.
     * Conditions:
     *      1. Binaural ASHA hearing aids
     *      1. Binaural hearing aids
     *      2. Sub device is added
     *      3. Sub device is not connected
     *      3. Sub device is not bonded
     * Expected result:
     *      The controller is available. Need to show the hint to pair the other side.
     */
    @Test
    public void isAvailable_ashaDevice_otherDeviceIsNotConnected_available() {
    public void isAvailable_deviceIsConnectedHearingAid_subDeviceIsNotBonded_available() {
        when(mCachedDevice.isConnectedHearingAidDevice()).thenReturn(true);
        when(mCachedDevice.isConnectedAshaHearingAidDevice()).thenReturn(true);
        when(mCachedDevice.getDeviceMode()).thenReturn(HearingAidInfo.DeviceMode.MODE_BINAURAL);
        when(mSubCachedDevice.isConnectedAshaHearingAidDevice()).thenReturn(false);
        when(mSubCachedDevice.getBondState()).thenReturn(BluetoothDevice.BOND_NONE);
        when(mCachedDevice.getSubDevice()).thenReturn(mSubCachedDevice);

        assertThat(mController.isAvailable()).isTrue();
@@ -170,36 +170,17 @@ public class BluetoothDetailsPairOtherControllerTest extends BluetoothDetailsCon
    /**
     * Test if the controller is available.
     * Conditions:
     *      1. Binaural ASHA hearing aids
     *      2. No sub device added
     * Expected result:
     *      The controller is available. Need to show the hint to pair the other side.
     */
    @Test
    public void isAvailable_ashaDevice_otherDeviceIsNotExist_available() {
        when(mCachedDevice.isConnectedHearingAidDevice()).thenReturn(true);
        when(mCachedDevice.isConnectedAshaHearingAidDevice()).thenReturn(true);
        when(mCachedDevice.getDeviceMode()).thenReturn(HearingAidInfo.DeviceMode.MODE_BINAURAL);
        when(mCachedDevice.getSubDevice()).thenReturn(null);

        assertThat(mController.isAvailable()).isTrue();
    }

    /**
     * Test if the controller is available.
     * Conditions:
     *      1. Binaural LE Audio hearing aids
     *      1. Binaural hearing aids
     *      2. Member device is added
     *      3. Member device is connected
     *      3. Member device is bonded
     * Expected result:
     *      The controller is not available. Both sides are already paired and connected.
     *      The controller is not available. Both sides are already paired.
     */
    @Test
    public void isAvailable_leAudioDevice_otherDeviceIsConnected_notAvailable() {
    public void isAvailable_deviceIsConnectedHearingAid_memberDeviceIsBonded_notAvailable() {
        when(mCachedDevice.isConnectedHearingAidDevice()).thenReturn(true);
        when(mCachedDevice.isConnectedLeAudioHearingAidDevice()).thenReturn(true);
        when(mCachedDevice.getDeviceMode()).thenReturn(HearingAidInfo.DeviceMode.MODE_BINAURAL);
        when(mSubCachedDevice.isConnectedLeAudioHearingAidDevice()).thenReturn(true);
        when(mSubCachedDevice.getBondState()).thenReturn(BluetoothDevice.BOND_BONDED);
        when(mCachedDevice.getMemberDevice()).thenReturn(Set.of(mSubCachedDevice));

        assertThat(mController.isAvailable()).isFalse();
@@ -208,18 +189,17 @@ public class BluetoothDetailsPairOtherControllerTest extends BluetoothDetailsCon
    /**
     * Test if the controller is available.
     * Conditions:
     *      1. Binaural LE Audio hearing aids
     *      1. Binaural hearing aids
     *      2. Member device is added
     *      3. Member device is not connected
     *      3. Member device is not bonded
     * Expected result:
     *      The controller is available. Need to show the hint to pair the other side.
     */
    @Test
    public void isAvailable_leAudioDevice_otherDeviceIsNotConnected_available() {
    public void isAvailable_deviceIsConnectedHearingAid_memberDeviceIsNotBonded_available() {
        when(mCachedDevice.isConnectedHearingAidDevice()).thenReturn(true);
        when(mCachedDevice.isConnectedLeAudioHearingAidDevice()).thenReturn(true);
        when(mCachedDevice.getDeviceMode()).thenReturn(HearingAidInfo.DeviceMode.MODE_BINAURAL);
        when(mSubCachedDevice.isConnectedLeAudioHearingAidDevice()).thenReturn(false);
        when(mSubCachedDevice.getBondState()).thenReturn(BluetoothDevice.BOND_NONE);
        when(mCachedDevice.getMemberDevice()).thenReturn(Set.of(mSubCachedDevice));

        assertThat(mController.isAvailable()).isTrue();
@@ -228,16 +208,17 @@ public class BluetoothDetailsPairOtherControllerTest extends BluetoothDetailsCon
    /**
     * Test if the controller is available.
     * Conditions:
     *      1. Binaural LE Audio hearing aids
     *      2. No member device added
     *      1. Binaural hearing aids
     *      2. No sub device is added
     *      2. No member device is added
     * Expected result:
     *      The controller is available. Need to show the hint to pair the other side.
     */
    @Test
    public void isAvailable_leAudioDevice_otherDeviceIsNotExist_available() {
    public void isAvailable_deviceIsConnectedHearingAid_otherDeviceIsNotExist_available() {
        when(mCachedDevice.isConnectedHearingAidDevice()).thenReturn(true);
        when(mCachedDevice.isConnectedLeAudioHearingAidDevice()).thenReturn(true);
        when(mCachedDevice.getDeviceMode()).thenReturn(HearingAidInfo.DeviceMode.MODE_BINAURAL);
        when(mCachedDevice.getSubDevice()).thenReturn(null);
        when(mCachedDevice.getMemberDevice()).thenReturn(new HashSet<>());

        assertThat(mController.isAvailable()).isTrue();
@@ -245,7 +226,7 @@ public class BluetoothDetailsPairOtherControllerTest extends BluetoothDetailsCon

    /** Test the pair other side button title after refreshing. */
    @Test
    public void refresh_rightSideDevice_pairLeftSideButtonTitle() {
    public void refresh_deviceIsRightSide_showPairLeftSideTitle() {
        when(mCachedDevice.getDeviceSide()).thenReturn(HearingAidInfo.DeviceSide.SIDE_RIGHT);
        mController.init(mScreen);

@@ -257,7 +238,7 @@ public class BluetoothDetailsPairOtherControllerTest extends BluetoothDetailsCon

    /** Test the pair other side button visibility after refreshing. */
    @Test
    public void refresh_isNotConnectedHearingAidDevice_preferenceIsNotVisible() {
    public void refresh_deviceIsNotConnectedHearingAid_preferenceIsNotVisible() {
        when(mCachedDevice.isConnectedHearingAidDevice()).thenReturn(false);
        mController.init(mScreen);