Don't crash in SecondaryUserController.
If icons were fetched before displayPreference() is called, it can cause a NPE. This adds a null check to ensure that it never attempts to set an icon without both the icon and preference being non-null. Change-Id: Ib4269428e64545c9e255f7e3292fb6c046c1f307 Fixes: 37248158 Test: Settings Robotest
This commit is contained in:
@@ -211,4 +211,20 @@ public class SecondaryUserControllerTest {
|
||||
Preference preference = argumentCaptor.getValue();
|
||||
assertThat(preference.getIcon()).isEqualTo(drawable);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setIcon_doesntNpeOnNullPreference() throws Exception {
|
||||
SparseArray<Drawable> icons = new SparseArray<>();
|
||||
Bitmap userBitmap =
|
||||
BitmapFactory.decodeResource(
|
||||
RuntimeEnvironment.application.getResources(), R.drawable.home);
|
||||
UserIconDrawable drawable = new UserIconDrawable(100 /* size */).setIcon(userBitmap).bake();
|
||||
icons.put(10, drawable);
|
||||
mPrimaryUser.name = TEST_NAME;
|
||||
mPrimaryUser.id = 10;
|
||||
|
||||
mController.handleUserIcons(icons);
|
||||
|
||||
// Doesn't crash
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user