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:
@@ -133,6 +133,9 @@ public class DashboardFeatureProviderImpl implements DashboardFeatureProvider {
|
|||||||
@Override
|
@Override
|
||||||
public void bindPreferenceToTile(Activity activity, int sourceMetricsCategory, Preference pref,
|
public void bindPreferenceToTile(Activity activity, int sourceMetricsCategory, Preference pref,
|
||||||
Tile tile, String key, int baseOrder) {
|
Tile tile, String key, int baseOrder) {
|
||||||
|
if (pref == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
pref.setTitle(tile.title);
|
pref.setTitle(tile.title);
|
||||||
if (!TextUtils.isEmpty(key)) {
|
if (!TextUtils.isEmpty(key)) {
|
||||||
pref.setKey(key);
|
pref.setKey(key);
|
||||||
@@ -239,7 +242,7 @@ public class DashboardFeatureProviderImpl implements DashboardFeatureProvider {
|
|||||||
if (tile.icon != null) {
|
if (tile.icon != null) {
|
||||||
preference.setIcon(tile.icon.loadDrawable(preference.getContext()));
|
preference.setIcon(tile.icon.loadDrawable(preference.getContext()));
|
||||||
} else if (tile.metaData != null
|
} else if (tile.metaData != null
|
||||||
&& tile.metaData.containsKey(META_DATA_PREFERENCE_ICON_URI))
|
&& tile.metaData.containsKey(META_DATA_PREFERENCE_ICON_URI)) {
|
||||||
ThreadUtils.postOnBackgroundThread(() -> {
|
ThreadUtils.postOnBackgroundThread(() -> {
|
||||||
String packageName = null;
|
String packageName = null;
|
||||||
if (tile.intent != null) {
|
if (tile.intent != null) {
|
||||||
@@ -259,11 +262,11 @@ public class DashboardFeatureProviderImpl implements DashboardFeatureProvider {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final Icon icon = Icon.createWithResource(iconInfo.first, iconInfo.second);
|
final Icon icon = Icon.createWithResource(iconInfo.first, iconInfo.second);
|
||||||
ThreadUtils.postOnMainThread(() -> {
|
ThreadUtils.postOnMainThread(() ->
|
||||||
preference.setIcon(icon.loadDrawable(preference.getContext()));
|
preference.setIcon(icon.loadDrawable(preference.getContext()))
|
||||||
}
|
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void launchIntentOrSelectProfile(Activity activity, Tile tile, Intent intent,
|
private void launchIntentOrSelectProfile(Activity activity, Tile tile, Intent intent,
|
||||||
|
@@ -24,6 +24,7 @@ import static org.mockito.Mockito.doReturn;
|
|||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.spy;
|
import static org.mockito.Mockito.spy;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
|
import static org.mockito.Mockito.verifyZeroInteractions;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
import static org.robolectric.Shadows.shadowOf;
|
import static org.robolectric.Shadows.shadowOf;
|
||||||
|
|
||||||
@@ -214,6 +215,15 @@ public class DashboardFeatureProviderImplTest {
|
|||||||
.startActivityForResultAsUser(any(Intent.class), anyInt(), any(UserHandle.class));
|
.startActivityForResultAsUser(any(Intent.class), anyInt(), any(UserHandle.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void bindPreference_nullPreference_shouldIgnore() {
|
||||||
|
final Tile tile = mock(Tile.class);
|
||||||
|
mImpl.bindPreferenceToTile(mActivity, MetricsProto.MetricsEvent.VIEW_UNKNOWN,
|
||||||
|
null, tile, "123", Preference.DEFAULT_ORDER);
|
||||||
|
|
||||||
|
verifyZeroInteractions(tile);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void bindPreference_withNullKeyNullPriority_shouldGenerateKeyAndPriority() {
|
public void bindPreference_withNullKeyNullPriority_shouldGenerateKeyAndPriority() {
|
||||||
final Preference preference = new Preference(RuntimeEnvironment.application);
|
final Preference preference = new Preference(RuntimeEnvironment.application);
|
||||||
|
Reference in New Issue
Block a user