NullPointerException when running monkey test in IccLockSettings

In Android N, finish() in onCreate() cannot avoid onViewCreated() lifecycle
in Fragment, so a crash occurs in com.android.settings.IccLockSettings
because of insecure call in updatePreference().
It's a tiny bug only appears when running monkey test.

Test: run monkey test with page IccLockSettings.

This bug was reported to Google Issue Tracker.
Link: https://issuetracker.google.com/issues/38152568

Change-Id: I143b046fd7ac5ffba55e51254c7dd068274d342e
Signed-off-by: xudiwen <xudiwen@xiaomi.com>
This commit is contained in:
xudiwen
2017-05-09 17:30:57 +08:00
parent 79694e79d1
commit 18615600ae

View File

@@ -247,11 +247,15 @@ public class IccLockSettings extends SettingsPreferenceFragment
}
private void updatePreferences() {
mPinDialog.setEnabled(mPhone != null);
mPinToggle.setEnabled(mPhone != null);
if (mPinDialog != null) {
mPinDialog.setEnabled(mPhone != null);
}
if (mPinToggle != null) {
mPinToggle.setEnabled(mPhone != null);
if (mPhone != null) {
mPinToggle.setChecked(mPhone.getIccCard().getIccLockEnabled());
if (mPhone != null) {
mPinToggle.setChecked(mPhone.getIccCard().getIccLockEnabled());
}
}
}