Add NPE check for method assignDefaultPhoto in Utils.java

When user press back button while adding user, app may crash because
of null context. In this cl, I add NPE check for context in method
assignDefaultPhoto and change this method to return boolean value.
If the return value is false, then stop the following steps(e.g.
creating a dialog after pressing button may also cause crash.)

Bug: 33829308
Test: make -j40 RunSettingsRoboTests
Change-Id: I811b92c268fb20f8c43ab3b0a9ceebe76f5d83be
This commit is contained in:
jackqdyulei
2016-12-27 10:15:27 -08:00
parent d5afb5a60c
commit 8164c64edc
3 changed files with 23 additions and 4 deletions

View File

@@ -65,4 +65,10 @@ public class UtilsTest {
assertThat(Utils.getWifiIpAddresses(mContext)).isNull();
}
@Test
public void testAssignDefaultPhoto_ContextNull_ReturnFalseAndNotCrash() {
// Should not crash here
assertThat(Utils.assignDefaultPhoto(null, 0)).isFalse();
}
}