Fix a NPE where developer options page crash sometimes.

Developer options page crash for restricted users because the page
removes all preferences while DashboardFeatureProvider tries to
manipulate preferences on screen.

Added a null check to skip changin prefs in DashboardFeatureProvider
because the pref is going to be removed either way.

Change-Id: Ic83fd0dfb2a906605fb1d992d7b36c2163630e89
Fixes: 78655710
Test: robotests
This commit is contained in:
Fan Zhang
2018-04-30 16:24:42 -07:00
parent 98496a5683
commit ecadd0119d
2 changed files with 17 additions and 4 deletions

View File

@@ -133,6 +133,9 @@ public class DashboardFeatureProviderImpl implements DashboardFeatureProvider {
@Override
public void bindPreferenceToTile(Activity activity, int sourceMetricsCategory, Preference pref,
Tile tile, String key, int baseOrder) {
if (pref == null) {
return;
}
pref.setTitle(tile.title);
if (!TextUtils.isEmpty(key)) {
pref.setKey(key);
@@ -239,7 +242,7 @@ public class DashboardFeatureProviderImpl implements DashboardFeatureProvider {
if (tile.icon != null) {
preference.setIcon(tile.icon.loadDrawable(preference.getContext()));
} else if (tile.metaData != null
&& tile.metaData.containsKey(META_DATA_PREFERENCE_ICON_URI))
&& tile.metaData.containsKey(META_DATA_PREFERENCE_ICON_URI)) {
ThreadUtils.postOnBackgroundThread(() -> {
String packageName = null;
if (tile.intent != null) {
@@ -259,11 +262,11 @@ public class DashboardFeatureProviderImpl implements DashboardFeatureProvider {
return;
}
final Icon icon = Icon.createWithResource(iconInfo.first, iconInfo.second);
ThreadUtils.postOnMainThread(() -> {
preference.setIcon(icon.loadDrawable(preference.getContext()));
}
ThreadUtils.postOnMainThread(() ->
preference.setIcon(icon.loadDrawable(preference.getContext()))
);
});
}
}
private void launchIntentOrSelectProfile(Activity activity, Tile tile, Intent intent,