summaryrefslogtreecommitdiff
path: root/tests/PackageWatchdog
diff options
context:
space:
mode:
authorGavin Corkery <gavincorkery@google.com>2020-03-10 10:20:12 +0000
committerGavin Corkery <gavincorkery@google.com>2020-03-10 14:54:47 +0000
commit9da918c704ec39615e15ab73ea36e6d665aac0b9 (patch)
tree0430c89bcec055f1f604a77c62d4d6b9e427f602 /tests/PackageWatchdog
parente6dbe2b880b99dc6747bfa0985e31bf96202534d (diff)
Remove NPE in onPackageFailure
It is possible for null to be returned by ProcessRecord.getPackageListWithVersionCode on package failure. This can cause a NPE in Package Watchdog. Ensure that the list of failing packages is not null. Test: atest PackageWatchdogTest Bug: 151113966 Change-Id: Iab23cd6b4b8ae6b787df5f0b831b51e0ac8b3d31
Diffstat (limited to 'tests/PackageWatchdog')
-rw-r--r--tests/PackageWatchdog/src/com/android/server/PackageWatchdogTest.java14
1 files changed, 14 insertions, 0 deletions
diff --git a/tests/PackageWatchdog/src/com/android/server/PackageWatchdogTest.java b/tests/PackageWatchdog/src/com/android/server/PackageWatchdogTest.java
index 8cc8cf4d2a97..dfaac2cde91d 100644
--- a/tests/PackageWatchdog/src/com/android/server/PackageWatchdogTest.java
+++ b/tests/PackageWatchdog/src/com/android/server/PackageWatchdogTest.java
@@ -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()