Fix NPE for ConfigureNotificationSettings

The NPE is caused by that we have removed the advanced category from
Notification page for android S design but it still tries to get
category and call setInitialExpandedChildrenCount in onCreate().

Only run the relevant logic on the old design since it’s only used to
expand the advanced category and we don’t need the expand feature
anymore for android S.

Bug: 182237530
Fixes: 182532954
Test: robotest & manual
Change-Id: I96f35fa40221079d5498d9d2fab9c75d64698808
This commit is contained in:
Yanting Yang
2021-03-12 15:47:31 +08:00
parent 14a2fd6bc1
commit a1a30296ae

View File

@@ -127,20 +127,23 @@ public class ConfigureNotificationSettings extends DashboardFragment implements
@Override @Override
public void onCreate(Bundle icicle) { public void onCreate(Bundle icicle) {
super.onCreate(icicle); super.onCreate(icicle);
final PreferenceScreen screen = getPreferenceScreen(); // TODO(b/182237530): This method should be removed when this flag is deprecated.
final Bundle arguments = getArguments(); if (!FeatureFlagUtils.isEnabled(getContext(), FeatureFlags.SILKY_HOME)) {
final PreferenceScreen screen = getPreferenceScreen();
final Bundle arguments = getArguments();
if (screen == null) { if (screen == null) {
return; return;
} }
if (arguments != null) { if (arguments != null) {
final String highlightKey = arguments.getString(EXTRA_FRAGMENT_ARG_KEY); final String highlightKey = arguments.getString(EXTRA_FRAGMENT_ARG_KEY);
if (!TextUtils.isEmpty(highlightKey)) { if (!TextUtils.isEmpty(highlightKey)) {
final PreferenceCategory advancedCategory = final PreferenceCategory advancedCategory =
screen.findPreference(KEY_ADVANCED_CATEGORY); screen.findPreference(KEY_ADVANCED_CATEGORY);
// Has highlight row - expand everything // Has highlight row - expand everything
advancedCategory.setInitialExpandedChildrenCount(Integer.MAX_VALUE); advancedCategory.setInitialExpandedChildrenCount(Integer.MAX_VALUE);
scrollToPreference(advancedCategory); scrollToPreference(advancedCategory);
}
} }
} }
} }