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

@@ -24,6 +24,7 @@ import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyZeroInteractions;
import static org.mockito.Mockito.when;
import static org.robolectric.Shadows.shadowOf;
@@ -214,6 +215,15 @@ public class DashboardFeatureProviderImplTest {
.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
public void bindPreference_withNullKeyNullPriority_shouldGenerateKeyAndPriority() {
final Preference preference = new Preference(RuntimeEnvironment.application);