Update to new RollbackUtils.sendCrashBroadcast API.

am: 3e7ef5ae0b

Change-Id: I518d37f8d2eef80f63c88530ed4aa581c27b9e75
This commit is contained in:
Richard Uhler
2019-11-25 05:33:56 -08:00
committed by android-build-merger
2 changed files with 5 additions and 19 deletions

View File

@@ -929,7 +929,6 @@ public class RollbackTest {
*/ */
@Test @Test
public void testBadUpdateRollback() throws Exception { public void testBadUpdateRollback() throws Exception {
BroadcastReceiver crashCountReceiver = null;
Context context = InstrumentationRegistry.getContext(); Context context = InstrumentationRegistry.getContext();
try { try {
InstallUtils.adoptShellPermissionIdentity( InstallUtils.adoptShellPermissionIdentity(
@@ -937,7 +936,7 @@ public class RollbackTest {
Manifest.permission.DELETE_PACKAGES, Manifest.permission.DELETE_PACKAGES,
Manifest.permission.MANAGE_ROLLBACKS, Manifest.permission.MANAGE_ROLLBACKS,
Manifest.permission.TEST_MANAGE_ROLLBACKS, Manifest.permission.TEST_MANAGE_ROLLBACKS,
Manifest.permission.KILL_BACKGROUND_PROCESSES, Manifest.permission.FORCE_STOP_PACKAGES,
Manifest.permission.RESTART_PACKAGES); Manifest.permission.RESTART_PACKAGES);
RollbackManager rm = RollbackUtils.getRollbackManager(); RollbackManager rm = RollbackUtils.getRollbackManager();
@@ -967,7 +966,7 @@ public class RollbackTest {
RollbackBroadcastReceiver rollbackReceiver = new RollbackBroadcastReceiver(); RollbackBroadcastReceiver rollbackReceiver = new RollbackBroadcastReceiver();
// Crash TestApp.A PackageWatchdog#TRIGGER_FAILURE_COUNT times to trigger rollback // 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. // Verify we received a broadcast for the rollback.
rollbackReceiver.take(); rollbackReceiver.take();
@@ -981,9 +980,6 @@ public class RollbackTest {
assertThat(InstallUtils.getInstalledVersion(TestApp.B)).isEqualTo(2); assertThat(InstallUtils.getInstalledVersion(TestApp.B)).isEqualTo(2);
} finally { } finally {
InstallUtils.dropShellPermissionIdentity(); InstallUtils.dropShellPermissionIdentity();
if (crashCountReceiver != null) {
context.unregisterReceiver(crashCountReceiver);
}
} }
} }

View File

@@ -25,7 +25,6 @@ import static org.junit.Assert.fail;
import android.Manifest; import android.Manifest;
import android.annotation.Nullable; import android.annotation.Nullable;
import android.content.BroadcastReceiver;
import android.content.ComponentName; import android.content.ComponentName;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
@@ -77,7 +76,7 @@ public class StagedRollbackTest {
Manifest.permission.INSTALL_PACKAGES, Manifest.permission.INSTALL_PACKAGES,
Manifest.permission.DELETE_PACKAGES, Manifest.permission.DELETE_PACKAGES,
Manifest.permission.TEST_MANAGE_ROLLBACKS, Manifest.permission.TEST_MANAGE_ROLLBACKS,
Manifest.permission.KILL_BACKGROUND_PROCESSES); Manifest.permission.FORCE_STOP_PACKAGES);
} }
/** /**
@@ -135,17 +134,8 @@ public class StagedRollbackTest {
*/ */
@Test @Test
public void testBadApkOnlyTriggerRollback() throws Exception { public void testBadApkOnlyTriggerRollback() throws Exception {
BroadcastReceiver crashCountReceiver = null; // Crash TestApp.A PackageWatchdog#TRIGGER_FAILURE_COUNT times to trigger rollback
Context context = InstrumentationRegistry.getContext(); RollbackUtils.sendCrashBroadcast(TestApp.A, 5);
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);
}
}
// We expect the device to be rebooted automatically. Wait for that to // We expect the device to be rebooted automatically. Wait for that to
// happen. At that point, the host test driver will wait for the // happen. At that point, the host test driver will wait for the