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

Commit cfec0923 authored by jasonwshsu's avatar jasonwshsu
Browse files

Fix not on the top when entering device detail page

Root Cause: Added SpacePreference in xml let the page renders order
incorrectly.

Solution: That SpacePreference should only be visible when the device is
hearing aid.

Bug: 245681095
Test: make RunSettingsRoboTests ROBOTEST_FILTER=BluetoothDetailsPairOtherControllerTest
Change-Id: Ic0be940c8466b5e1e301255868c29d06bd4428bd
parent 93f696bc
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -46,6 +46,7 @@
        android:key="hearing_aid_pair_other_button"
        android:gravity="center" />
    <com.android.settings.applications.SpacePreference
        android:key="hearing_aid_space_layout"
        android:layout_height="8dp" />

    <com.android.settingslib.widget.ActionButtonsPreference
+14 −1
Original line number Diff line number Diff line
@@ -22,19 +22,25 @@ import androidx.preference.PreferenceFragmentCompat;
import androidx.preference.PreferenceScreen;

import com.android.settings.R;
import com.android.settings.applications.SpacePreference;
import com.android.settings.core.SubSettingLauncher;
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
import com.android.settingslib.bluetooth.HearingAidProfile;
import com.android.settingslib.core.lifecycle.Lifecycle;
import com.android.settingslib.widget.ButtonPreference;

import com.google.common.annotations.VisibleForTesting;

/**
 * This class handles button preference logic to display for hearing aid device.
 */
public class BluetoothDetailsPairOtherController extends BluetoothDetailsController {
    private static final String KEY_PAIR_OTHER = "hearing_aid_pair_other_button";
    @VisibleForTesting
    static final String KEY_SPACE = "hearing_aid_space_layout";

    private ButtonPreference mPreference;
    private SpacePreference mSpacePreference;

    public BluetoothDetailsPairOtherController(Context context,
            PreferenceFragmentCompat fragment,
@@ -57,14 +63,16 @@ public class BluetoothDetailsPairOtherController extends BluetoothDetailsControl
    @Override
    protected void init(PreferenceScreen screen) {
        mPreference = screen.findPreference(getPreferenceKey());
        mSpacePreference = screen.findPreference(KEY_SPACE);
        updateButtonPreferenceTitle(mPreference);
        setPreferencesVisibility(getButtonPreferenceVisibility(mCachedDevice));
        mPreference.setOnClickListener(v -> launchPairingDetail());
    }

    @Override
    protected void refresh() {
        updateButtonPreferenceTitle(mPreference);
        mPreference.setVisible(getButtonPreferenceVisibility(mCachedDevice));
        setPreferencesVisibility(getButtonPreferenceVisibility(mCachedDevice));

    }

@@ -77,6 +85,11 @@ public class BluetoothDetailsPairOtherController extends BluetoothDetailsControl
        preference.setTitle(stringRes);
    }

    private void setPreferencesVisibility(boolean visible) {
        mPreference.setVisible(visible);
        mSpacePreference.setVisible(visible);
    }

    private boolean getButtonPreferenceVisibility(CachedBluetoothDevice cachedDevice) {
        return isBinauralMode(cachedDevice) && isOnlyOneSideConnected(cachedDevice);
    }
+27 −1
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.when;

import com.android.settings.R;
import com.android.settings.applications.SpacePreference;
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
import com.android.settingslib.bluetooth.HearingAidProfile;
import com.android.settingslib.widget.ButtonPreference;
@@ -43,6 +44,7 @@ public class BluetoothDetailsPairOtherControllerTest extends BluetoothDetailsCon
    private CachedBluetoothDevice mSubCachedDevice;
    private BluetoothDetailsPairOtherController mController;
    private ButtonPreference mPreference;
    private SpacePreference mSpacePreference;

    @Override
    public void setUp() {
@@ -51,8 +53,11 @@ public class BluetoothDetailsPairOtherControllerTest extends BluetoothDetailsCon
        mController = new BluetoothDetailsPairOtherController(mContext, mFragment, mCachedDevice,
                mLifecycle);
        mPreference = new ButtonPreference(mContext);
        mSpacePreference = new SpacePreference(mContext, null);
        mPreference.setKey(mController.getPreferenceKey());
        mSpacePreference.setKey(BluetoothDetailsPairOtherController.KEY_SPACE);
        mScreen.addPreference(mPreference);
        mScreen.addPreference(mSpacePreference);
    }

    @Test
@@ -76,7 +81,17 @@ public class BluetoothDetailsPairOtherControllerTest extends BluetoothDetailsCon
    }

    @Test
    public void isAvailable_isConnectedHearingAidDevice_available() {
    public void init_isNotConnectedHearingAidDevice_notVisiblePreference() {
        when(mCachedDevice.isConnectedHearingAidDevice()).thenReturn(false);

        mController.init(mScreen);

        assertThat(mPreference.isVisible()).isFalse();
        assertThat(mSpacePreference.isVisible()).isFalse();
    }

    @Test
    public void isAvailable_isNotConnectedHearingAidDevice_notAvailable() {
        when(mCachedDevice.isConnectedHearingAidDevice()).thenReturn(false);

        assertThat(mController.isAvailable()).isFalse();
@@ -129,4 +144,15 @@ public class BluetoothDetailsPairOtherControllerTest extends BluetoothDetailsCon
        assertThat(mPreference.getTitle().toString()).isEqualTo(
                mContext.getString(R.string.bluetooth_pair_left_ear_button));
    }

    @Test
    public void refresh_isNotConnectedHearingAidDevice_notVisiblePreference() {
        when(mCachedDevice.isConnectedHearingAidDevice()).thenReturn(false);
        mController.init(mScreen);

        mController.refresh();

        assertThat(mPreference.isVisible()).isFalse();
        assertThat(mSpacePreference.isVisible()).isFalse();
    }
}