Merge "Remove NPE in onPackageFailure" into rvc-dev

This commit is contained in:
Gavin Corkery
2020-03-16 16:14:52 +00:00
committed by Android (Google) Code Review
2 changed files with 18 additions and 0 deletions

View File

@@ -354,6 +354,10 @@ public class PackageWatchdog {
*/
public void onPackageFailure(List<VersionedPackage> packages,
@FailureReasons int failureReason) {
if (packages == null) {
Slog.w(TAG, "Could not resolve a list of failing packages");
return;
}
mLongTaskHandler.post(() -> {
synchronized (mLock) {
if (mAllObservers.isEmpty()) {

View File

@@ -1063,6 +1063,20 @@ public class PackageWatchdogTest {
assertThat(bootObserver2.mitigatedBootLoop()).isFalse();
}
/**
* Ensure that passing a null list of failed packages does not cause any mitigation logic to
* execute.
*/
@Test
public void testNullFailedPackagesList() {
PackageWatchdog watchdog = createWatchdog();
TestObserver observer1 = new TestObserver(OBSERVER_NAME_1);
watchdog.startObservingHealth(observer1, List.of(APP_A), LONG_DURATION);
raiseFatalFailureAndDispatch(watchdog, null, PackageWatchdog.FAILURE_REASON_APP_CRASH);
assertThat(observer1.mMitigatedPackages).isEmpty();
}
private void adoptShellPermissions(String... permissions) {
InstrumentationRegistry
.getInstrumentation()