Fix NPE of AppVersionPreferenceController

Add null check for the package info before getting the version name.

Fixes: 168333280
Test: robotests & manual
Change-Id: If2e3d220c520d30e932478836ee2ea89f936d55c
This commit is contained in:
Yanting Yang
2021-03-17 01:14:00 +08:00
parent a922c902f6
commit e4b3b969db
2 changed files with 19 additions and 1 deletions

View File

@@ -16,6 +16,8 @@
package com.android.settings.applications.appinfo;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -62,4 +64,13 @@ public class AppVersionPreferenceControllerTest {
verify(mPreference).setSummary("version test1234");
}
@Test
public void updateState_packageInfoNull_shouldNotCrash() {
when(mFragment.getPackageInfo()).thenReturn(null);
mController.updateState(mPreference);
assertThat(mController.getSummary()).isNull();
}
}