From 4ffe4464fca5e5ac9c73146125b8c1f9660bc989 Mon Sep 17 00:00:00 2001 From: Jacky Wang Date: Tue, 18 Feb 2025 22:52:06 +0800 Subject: [PATCH] [Catalyst] Rebind restricted preferences for SettingsPreferenceFragment Bug: 377600992 Fix: 397357248 Flag: com.android.settings.flags.catalyst Test: manual Change-Id: I4ce83d8032d9ef8730dec5efd61f9834f2433983 --- .../settings/SettingsPreferenceFragment.java | 21 +++++++++++++++++++ .../settings/dashboard/DashboardFragment.java | 20 ------------------ 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/src/com/android/settings/SettingsPreferenceFragment.java b/src/com/android/settings/SettingsPreferenceFragment.java index f272c1da9d8..77c39cd791e 100644 --- a/src/com/android/settings/SettingsPreferenceFragment.java +++ b/src/com/android/settings/SettingsPreferenceFragment.java @@ -50,12 +50,14 @@ import androidx.recyclerview.widget.RecyclerView; import com.android.settings.core.InstrumentedPreferenceFragment; import com.android.settings.core.instrumentation.InstrumentedDialogFragment; import com.android.settings.flags.Flags; +import com.android.settings.restriction.UserRestrictionBindingHelper; import com.android.settings.support.actionbar.HelpResourceProvider; import com.android.settings.widget.HighlightablePreferenceGroupAdapter; import com.android.settings.widget.LoadingViewController; import com.android.settingslib.CustomDialogPreferenceCompat; import com.android.settingslib.CustomEditTextPreferenceCompat; import com.android.settingslib.core.instrumentation.Instrumentable; +import com.android.settingslib.preference.PreferenceScreenBindingHelper; import com.android.settingslib.preference.PreferenceScreenCreator; import com.android.settingslib.search.Indexable; import com.android.settingslib.widget.LayoutPreference; @@ -130,6 +132,8 @@ public abstract class SettingsPreferenceFragment extends InstrumentedPreferenceF public HighlightablePreferenceGroupAdapter mAdapter; private boolean mPreferenceHighlighted = false; + private @Nullable UserRestrictionBindingHelper mUserRestrictionBindingHelper; + @Override public void onAttach(Context context) { if (shouldSkipForInitialSUW() && !WizardManagerHelper.isDeviceProvisioned(getContext())) { @@ -148,6 +152,14 @@ public abstract class SettingsPreferenceFragment extends InstrumentedPreferenceF mPreferenceHighlighted = icicle.getBoolean(SAVE_HIGHLIGHTED_KEY); } HighlightablePreferenceGroupAdapter.adjustInitialExpandedChildCount(this /* host */); + + if (isCatalystEnabled()) { + PreferenceScreenBindingHelper helper = getPreferenceScreenBindingHelper(); + if (helper != null) { + mUserRestrictionBindingHelper = new UserRestrictionBindingHelper(requireContext(), + helper); + } + } } @Override @@ -500,6 +512,15 @@ public abstract class SettingsPreferenceFragment extends InstrumentedPreferenceF return getActivity().getPackageManager(); } + @Override + public void onDestroy() { + if (mUserRestrictionBindingHelper != null) { + mUserRestrictionBindingHelper.close(); + mUserRestrictionBindingHelper = null; + } + super.onDestroy(); + } + @Override public void onDetach() { if (isRemoving()) { diff --git a/src/com/android/settings/dashboard/DashboardFragment.java b/src/com/android/settings/dashboard/DashboardFragment.java index 9acdfaa9ba8..e97834f0b87 100644 --- a/src/com/android/settings/dashboard/DashboardFragment.java +++ b/src/com/android/settings/dashboard/DashboardFragment.java @@ -48,13 +48,11 @@ import com.android.settings.core.CategoryMixin.CategoryListener; import com.android.settings.core.PreferenceControllerListHelper; import com.android.settings.flags.Flags; import com.android.settings.overlay.FeatureFactory; -import com.android.settings.restriction.UserRestrictionBindingHelper; import com.android.settingslib.PrimarySwitchPreference; import com.android.settingslib.core.AbstractPreferenceController; import com.android.settingslib.core.lifecycle.Lifecycle; import com.android.settingslib.drawer.DashboardCategory; import com.android.settingslib.drawer.Tile; -import com.android.settingslib.preference.PreferenceScreenBindingHelper; import com.android.settingslib.preference.PreferenceScreenCreator; import com.android.settingslib.search.Indexable; @@ -94,8 +92,6 @@ public abstract class DashboardFragment extends SettingsPreferenceFragment private boolean mListeningToCategoryChange; private List mSuppressInjectedTileKeys; - private @Nullable UserRestrictionBindingHelper mUserRestrictionBindingHelper; - @Override public void onAttach(Context context) { super.onAttach(context); @@ -182,13 +178,6 @@ public abstract class DashboardFragment extends SettingsPreferenceFragment // editing dialog is recreated (that would happen before onResume is called). updatePreferenceStates(); } - if (isCatalystEnabled()) { - PreferenceScreenBindingHelper helper = getPreferenceScreenBindingHelper(); - if (helper != null) { - mUserRestrictionBindingHelper = new UserRestrictionBindingHelper(requireContext(), - helper); - } - } } @Override @@ -299,15 +288,6 @@ public abstract class DashboardFragment extends SettingsPreferenceFragment } } - @Override - public void onDestroy() { - if (mUserRestrictionBindingHelper != null) { - mUserRestrictionBindingHelper.close(); - mUserRestrictionBindingHelper = null; - } - super.onDestroy(); - } - @Override protected abstract int getPreferenceScreenResId();