[Catalyst] Rebind restricted preferences for SettingsPreferenceFragment

Bug: 377600992
Fix: 397357248
Flag: com.android.settings.flags.catalyst
Test: manual
Change-Id: I4ce83d8032d9ef8730dec5efd61f9834f2433983
This commit is contained in:
Jacky Wang
2025-02-18 22:52:06 +08:00
parent 17793e3c26
commit 4ffe4464fc
2 changed files with 21 additions and 20 deletions

View File

@@ -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()) {