external displays: mirror/extend switch

Add a mirror/extend built-in display switch. Make minor changes to
DisplayTopology.kt for consistency and correctness.

Kotlin requires the two preference key names are different since they
are in the same namespace, so fix the name in the existing
DisplayTopology.kt module.

Make DisplayTopologyPreference responsible, rather than the caller, for
setting its persistence property, since a wrong value may cause unusual
behavior.

The setOrder calls are necessary to prevent the new switch from
appearing below the Built-in display category when a display is
hot-plugged in after showing the UI. We set them on all top-level
preferences (not just the two we are fixing) for consistency.

Flag: com.android.settings.flags.display_topology_pane_in_display_list
Test: atest ExternalDisplayPreferenceFragmentTest.java
Bug: b/352648432
Bug: b/366056921
Change-Id: Ib0072dd75066758903cc48c2d1e7142e1d921f67
This commit is contained in:
Matthew DeVore
2025-01-17 17:40:25 +00:00
parent 878f860fd3
commit 8f051ce5d4
5 changed files with 79 additions and 6 deletions

View File

@@ -102,6 +102,8 @@ public class ExternalDisplayPreferenceFragment extends SettingsPreferenceFragmen
@Nullable
private Preference mDisplayTopologyPreference;
@Nullable
private Preference mMirrorPreference;
@Nullable
private PreferenceCategory mDisplaysPreference;
@Nullable
private PreferenceCategory mBuiltinDisplayPreference;
@@ -292,6 +294,7 @@ public class ExternalDisplayPreferenceFragment extends SettingsPreferenceFragmen
if (mDisplaysPreference == null) {
mDisplaysPreference = new PreferenceCategory(context);
mDisplaysPreference.setPersistent(false);
mDisplaysPreference.setOrder(40);
}
return mDisplaysPreference;
}
@@ -301,6 +304,7 @@ public class ExternalDisplayPreferenceFragment extends SettingsPreferenceFragmen
if (mBuiltinDisplayPreference == null) {
mBuiltinDisplayPreference = new PreferenceCategory(context);
mBuiltinDisplayPreference.setPersistent(false);
mBuiltinDisplayPreference.setOrder(30);
}
return mBuiltinDisplayPreference;
}
@@ -308,11 +312,19 @@ public class ExternalDisplayPreferenceFragment extends SettingsPreferenceFragmen
@NonNull Preference getDisplayTopologyPreference(@NonNull Context context) {
if (mDisplayTopologyPreference == null) {
mDisplayTopologyPreference = new DisplayTopologyPreference(context);
mDisplayTopologyPreference.setPersistent(false);
mDisplayTopologyPreference.setOrder(10);
}
return mDisplayTopologyPreference;
}
@NonNull Preference getMirrorPreference(@NonNull Context context) {
if (mMirrorPreference == null) {
mMirrorPreference = new MirrorPreference(context);
mMirrorPreference.setOrder(20);
}
return mMirrorPreference;
}
private void restoreState(@Nullable Bundle savedInstanceState) {
if (savedInstanceState == null) {
return;
@@ -399,6 +411,9 @@ public class ExternalDisplayPreferenceFragment extends SettingsPreferenceFragmen
@NonNull PreferenceScreen screen, @NonNull Context context) {
if (mInjector != null && mInjector.getFlags().displayTopologyPaneInDisplayList()) {
screen.addPreference(getDisplayTopologyPreference(context));
if (!displaysToShow.isEmpty()) {
screen.addPreference(getMirrorPreference(context));
}
// If topology is shown, we also show a preference for the built-in display for
// consistency with the topology.