From 0c03aaae84e5536593526d3d3dfab17b0175654a Mon Sep 17 00:00:00 2001 From: Richard Uhler Date: Thu, 15 Aug 2019 10:54:00 +0100 Subject: [PATCH] Update to new RollbackUtils.sendCrashBroadcast API. Bug: 139108668 Test: atest StagedRollbackTest:com.android.tests.rollback.host.StagedRollbackTest#testBadApkOnly 2 Change-Id: Iaaa728aa58d894ba546677e8295faba2ebfc5e64 --- .../com/android/tests/rollback/RollbackTest.java | 8 ++------ .../tests/rollback/StagedRollbackTest.java | 16 +++------------- 2 files changed, 5 insertions(+), 19 deletions(-) diff --git a/tests/RollbackTest/RollbackTest/src/com/android/tests/rollback/RollbackTest.java b/tests/RollbackTest/RollbackTest/src/com/android/tests/rollback/RollbackTest.java index 2c0432aeed509..720c1af906ffa 100644 --- a/tests/RollbackTest/RollbackTest/src/com/android/tests/rollback/RollbackTest.java +++ b/tests/RollbackTest/RollbackTest/src/com/android/tests/rollback/RollbackTest.java @@ -929,7 +929,6 @@ public class RollbackTest { */ @Test public void testBadUpdateRollback() throws Exception { - BroadcastReceiver crashCountReceiver = null; Context context = InstrumentationRegistry.getContext(); try { InstallUtils.adoptShellPermissionIdentity( @@ -937,7 +936,7 @@ public class RollbackTest { Manifest.permission.DELETE_PACKAGES, Manifest.permission.MANAGE_ROLLBACKS, Manifest.permission.TEST_MANAGE_ROLLBACKS, - Manifest.permission.KILL_BACKGROUND_PROCESSES, + Manifest.permission.FORCE_STOP_PACKAGES, Manifest.permission.RESTART_PACKAGES); RollbackManager rm = RollbackUtils.getRollbackManager(); @@ -967,7 +966,7 @@ public class RollbackTest { RollbackBroadcastReceiver rollbackReceiver = new RollbackBroadcastReceiver(); // Crash TestApp.A PackageWatchdog#TRIGGER_FAILURE_COUNT times to trigger rollback - crashCountReceiver = RollbackUtils.sendCrashBroadcast(context, TestApp.A, 5); + RollbackUtils.sendCrashBroadcast(TestApp.A, 5); // Verify we received a broadcast for the rollback. rollbackReceiver.take(); @@ -981,9 +980,6 @@ public class RollbackTest { assertThat(InstallUtils.getInstalledVersion(TestApp.B)).isEqualTo(2); } finally { InstallUtils.dropShellPermissionIdentity(); - if (crashCountReceiver != null) { - context.unregisterReceiver(crashCountReceiver); - } } } diff --git a/tests/RollbackTest/RollbackTest/src/com/android/tests/rollback/StagedRollbackTest.java b/tests/RollbackTest/RollbackTest/src/com/android/tests/rollback/StagedRollbackTest.java index db8183124f59f..9e6ac8ef679b1 100644 --- a/tests/RollbackTest/RollbackTest/src/com/android/tests/rollback/StagedRollbackTest.java +++ b/tests/RollbackTest/RollbackTest/src/com/android/tests/rollback/StagedRollbackTest.java @@ -25,7 +25,6 @@ import static org.junit.Assert.fail; import android.Manifest; import android.annotation.Nullable; -import android.content.BroadcastReceiver; import android.content.ComponentName; import android.content.Context; import android.content.Intent; @@ -77,7 +76,7 @@ public class StagedRollbackTest { Manifest.permission.INSTALL_PACKAGES, Manifest.permission.DELETE_PACKAGES, Manifest.permission.TEST_MANAGE_ROLLBACKS, - Manifest.permission.KILL_BACKGROUND_PROCESSES); + Manifest.permission.FORCE_STOP_PACKAGES); } /** @@ -135,17 +134,8 @@ public class StagedRollbackTest { */ @Test public void testBadApkOnlyTriggerRollback() throws Exception { - BroadcastReceiver crashCountReceiver = null; - Context context = InstrumentationRegistry.getContext(); - - try { - // Crash TestApp.A PackageWatchdog#TRIGGER_FAILURE_COUNT times to trigger rollback - crashCountReceiver = RollbackUtils.sendCrashBroadcast(context, TestApp.A, 5); - } finally { - if (crashCountReceiver != null) { - context.unregisterReceiver(crashCountReceiver); - } - } + // Crash TestApp.A PackageWatchdog#TRIGGER_FAILURE_COUNT times to trigger rollback + RollbackUtils.sendCrashBroadcast(TestApp.A, 5); // We expect the device to be rebooted automatically. Wait for that to // happen. At that point, the host test driver will wait for the