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

Commit 02fff017 authored by Matthew DeVore's avatar Matthew DeVore
Browse files

Show options greyed out inactive display

Test: ExternalDisplayPreferenceFragmentTest
Flag: com.android.settings.flags.display_topology_pane_in_display_list
Bug: b/398846256
Change-Id: I6020212843c10867447809910a0202b7dbacd909
parent 29132988
Loading
Loading
Loading
Loading
+12 −15
Original line number Diff line number Diff line
@@ -444,17 +444,13 @@ public class ExternalDisplayPreferenceFragment extends SettingsPreferenceFragmen
        if (isUseDisplaySettingEnabled(mInjector)) {
            addUseDisplayPreferenceForDisplay(context, refresh, display, isEnabled, position);
        }
        if (!isEnabled) {
            // Skip all other settings
            return;
        }
        final var displayRotation = getDisplayRotation(display.getDisplayId());
        if (includeV1Helpers) {
        if (includeV1Helpers && isEnabled) {
            addIllustrationImage(context, refresh, displayRotation);
        }

        addResolutionPreference(context, refresh, display, position);
        addRotationPreference(context, refresh, display, displayRotation, position);
        addResolutionPreference(context, refresh, display, position, isEnabled);
        addRotationPreference(context, refresh, display, displayRotation, position, isEnabled);
        if (isResolutionSettingEnabled(mInjector)) {
            // Do not show the footer about changing resolution affecting apps. This is not in the
            // UX design for v2, and there is no good place to put it, since (a) if it is on the
@@ -466,13 +462,13 @@ public class ExternalDisplayPreferenceFragment extends SettingsPreferenceFragmen
            // inconsistent with the topology pane, which shows that display.
            // TODO(b/352648432): probably remove footer once the pane and rest of v2 UI is in
            // place.
            if (includeV1Helpers) {
            if (includeV1Helpers && isEnabled) {
                addFooterPreference(
                        context, refresh, EXTERNAL_DISPLAY_CHANGE_RESOLUTION_FOOTER_RESOURCE);
            }
        }
        if (isDisplaySizeSettingEnabled(mInjector)) {
            addSizePreference(context, refresh, display.getDisplayId(), position);
            addSizePreference(context, refresh, display.getDisplayId(), position, isEnabled);
        }
    }

@@ -562,8 +558,8 @@ public class ExternalDisplayPreferenceFragment extends SettingsPreferenceFragmen
        }
    }

    private void addRotationPreference(final Context context,
            PrefRefresh refresh, final Display display, final int displayRotation, int position) {
    private void addRotationPreference(final Context context, PrefRefresh refresh,
            final Display display, final int displayRotation, int position, boolean isEnabled) {
        var pref = reuseRotationPreference(context, refresh, position);
        if (mRotationEntries == null || mRotationEntriesValues == null) {
            mRotationEntries = new String[] {
@@ -587,11 +583,11 @@ public class ExternalDisplayPreferenceFragment extends SettingsPreferenceFragmen
            pref.setValueIndex(rotation);
            return true;
        });
        pref.setEnabled(isRotationSettingEnabled(mInjector));
        pref.setEnabled(isEnabled && isRotationSettingEnabled(mInjector));
    }

    private void addResolutionPreference(final Context context, PrefRefresh refresh,
            final Display display, int position) {
            final Display display, int position, boolean isEnabled) {
        var pref = reuseResolutionPreference(context, refresh, position);
        pref.setSummary(display.getMode().getPhysicalWidth() + " x "
                + display.getMode().getPhysicalHeight());
@@ -600,11 +596,11 @@ public class ExternalDisplayPreferenceFragment extends SettingsPreferenceFragmen
            launchResolutionSelector(context, display.getDisplayId());
            return true;
        });
        pref.setEnabled(isResolutionSettingEnabled(mInjector));
        pref.setEnabled(isEnabled && isResolutionSettingEnabled(mInjector));
    }

    private void addSizePreference(final Context context, PrefRefresh refresh, int displayId,
            int position) {
            int position, boolean isEnabled) {
        var pref = reuseSizePreference(context, refresh, displayId, position);
        pref.setSummary(EXTERNAL_DISPLAY_SIZE_SUMMARY_RESOURCE);
        pref.setOnPreferenceClickListener(
@@ -612,6 +608,7 @@ public class ExternalDisplayPreferenceFragment extends SettingsPreferenceFragmen
                    writePreferenceClickMetric(p);
                    return true;
                });
        pref.setEnabled(isEnabled);
    }

    private int getDisplayRotation(int displayId) {
+32 −3
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import static com.android.settings.flags.Flags.FLAG_DISPLAY_SIZE_CONNECTED_DISPL
import static com.android.settings.flags.Flags.FLAG_DISPLAY_TOPOLOGY_PANE_IN_DISPLAY_LIST;

import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth.assertWithMessage;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
@@ -161,6 +162,34 @@ public class ExternalDisplayPreferenceFragmentTest extends ExternalDisplayTestBa
        assertThat(listPref).isNull();
    }

    @Test
    @UiThreadTest
    public void testShowDisplayControlsDisabled() {
        doReturn(new Display[] {mDisplays[0], mDisplays[2]}).when(mMockedInjector)
                .getEnabledDisplays();
        doReturn(true).when(mMockedInjector).isDisplayEnabled(mDisplays[0]);
        doReturn(false).when(mMockedInjector).isDisplayEnabled(mDisplays[1]);
        doReturn(true).when(mMockedInjector).isDisplayEnabled(mDisplays[2]);
        initFragment();
        mHandler.flush();

        assertDisplayListCount(2);
        Preference pref;
        for (int disp = 0; disp < 2; disp++) {
            pref = mPreferenceScreen.findPreference(
                    PrefBasics.EXTERNAL_DISPLAY_RESOLUTION.keyForNth(disp));
            assertWithMessage("resolution " + disp).that(pref.isEnabled()).isEqualTo(disp == 1);

            pref = mPreferenceScreen.findPreference(
                    PrefBasics.EXTERNAL_DISPLAY_ROTATION.keyForNth(disp));
            assertWithMessage("rotation " + disp).that(pref.isEnabled()).isEqualTo(disp == 1);

            pref = mPreferenceScreen.findPreference(
                    PrefBasics.EXTERNAL_DISPLAY_SIZE.keyForNth(disp));
            assertWithMessage("size " + disp).that(pref.isEnabled()).isEqualTo(disp == 1);
        }
    }

    @Test
    @UiThreadTest
    public void testLaunchDisplaySettingFromList() {
@@ -280,13 +309,13 @@ public class ExternalDisplayPreferenceFragmentTest extends ExternalDisplayTestBa
        assertThat(mainPref.isEnabled()).isTrue();
        assertThat(mainPref.getOnPreferenceChangeListener()).isNotNull();
        var pref = category.findPreference(PrefBasics.EXTERNAL_DISPLAY_RESOLUTION.keyForNth(0));
        assertThat(pref).isNull();
        assertThat(pref.isEnabled()).isFalse();
        pref = category.findPreference(PrefBasics.EXTERNAL_DISPLAY_ROTATION.keyForNth(0));
        assertThat(pref).isNull();
        assertThat(pref.isEnabled()).isFalse();
        var footerPref = category.findPreference(PrefBasics.FOOTER.key);
        assertThat(footerPref).isNull();
        var sizePref = category.findPreference(PrefBasics.EXTERNAL_DISPLAY_SIZE.keyForNth(0));
        assertThat(sizePref).isNull();
        assertThat(sizePref.isEnabled()).isFalse();
    }

    @Test