aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYuexi Ma <yuexima@google.com>2021-03-02 19:55:59 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2021-03-02 19:55:59 +0000
commitb649ec650d9b76dbb99b18a2937bda84900d7398 (patch)
tree514ed66fc918d43ce02b96617eea06446a92fb12
parent5b7ade84acacf2846fd19b8f2f2c6c56a9c15b20 (diff)
parent81d8abd58a048e495731c783f5403c2a0bee5ec3 (diff)
downloadplatform_test_app_compat_csuite-b649ec650d9b76dbb99b18a2937bda84900d7398.tar.gz
platform_test_app_compat_csuite-b649ec650d9b76dbb99b18a2937bda84900d7398.tar.bz2
platform_test_app_compat_csuite-b649ec650d9b76dbb99b18a2937bda84900d7398.zip
Attempts to recover the package manager during test setup am: 81d8abd58a
Original change: https://android-review.googlesource.com/c/platform/test/app_compat/csuite/+/1584547 MUST ONLY BE SUBMITTED BY AUTOMERGER Change-Id: I5db4ef036e9706ae03a3d4aa92b1b8eee3bbfadd
-rw-r--r--harness/src/main/java/com/android/csuite/core/SystemPackageUninstaller.java21
-rw-r--r--harness/src/test/java/com/android/csuite/core/SystemAppUninstallerTest.java44
2 files changed, 56 insertions, 9 deletions
diff --git a/harness/src/main/java/com/android/csuite/core/SystemPackageUninstaller.java b/harness/src/main/java/com/android/csuite/core/SystemPackageUninstaller.java
index b878578..4ed6efe 100644
--- a/harness/src/main/java/com/android/csuite/core/SystemPackageUninstaller.java
+++ b/harness/src/main/java/com/android/csuite/core/SystemPackageUninstaller.java
@@ -44,11 +44,27 @@ public final class SystemPackageUninstaller {
static final String SYSPROP_SYS_BOOT_COMPLETED = "sys.boot_completed";
static final long WAIT_FOR_BOOT_COMPLETE_TIMEOUT_MILLIS = 1000 * 60;
@VisibleForTesting static final int MAX_NUMBER_OF_UPDATES = 100;
+ @VisibleForTesting static final String PM_CHECK_COMMAND = "pm path android";
public static void uninstallPackage(String packageName, ITestDevice device)
throws TargetSetupError, DeviceNotAvailableException {
checkNotNull(packageName);
+ if (!isPackageManagerRunning(device)) {
+ CLog.w(
+ "Package manager is not available on the device."
+ + " Attempting to recover it by restarting the framework.");
+ runAsRoot(
+ device,
+ () -> {
+ stopFramework(device);
+ startFramework(device);
+ });
+ if (!isPackageManagerRunning(device)) {
+ throw new TargetSetupError("The package manager failed to start.");
+ }
+ }
+
if (!isPackageInstalled(packageName, device)) {
CLog.i("Package %s is not installed.", packageName);
return;
@@ -236,6 +252,11 @@ public final class SystemPackageUninstaller {
"Failed to remove system app data %s from %s", packageName, dataPath));
}
+ private static boolean isPackageManagerRunning(ITestDevice device)
+ throws DeviceNotAvailableException {
+ return device.executeShellV2Command(PM_CHECK_COMMAND).getStatus() == CommandStatus.SUCCESS;
+ }
+
private static boolean isPackageInstalled(String packageName, ITestDevice device)
throws TargetSetupError, DeviceNotAvailableException {
CommandResult commandResult =
diff --git a/harness/src/test/java/com/android/csuite/core/SystemAppUninstallerTest.java b/harness/src/test/java/com/android/csuite/core/SystemAppUninstallerTest.java
index 2af9d9c..30b77db 100644
--- a/harness/src/test/java/com/android/csuite/core/SystemAppUninstallerTest.java
+++ b/harness/src/test/java/com/android/csuite/core/SystemAppUninstallerTest.java
@@ -47,20 +47,28 @@ public final class SystemAppUninstallerTest {
public void uninstallPackage_packageNameIsNull_throws() throws Exception {
assertThrows(
NullPointerException.class,
- () -> SystemPackageUninstaller.uninstallPackage(TEST_PACKAGE_NAME, null));
+ () ->
+ SystemPackageUninstaller.uninstallPackage(
+ null, createGoodDeviceWithAppNotInstalled()));
}
@Test
- public void uninstallPackage_packageIsNotInstalled_doesNotRemove() throws Exception {
- ITestDevice device = createGoodDeviceWithSystemAppInstalled();
- // Mock the device as if the test package does not exist on device
- CommandResult commandResult = createSuccessfulCommandResult();
- commandResult.setStdout("");
+ public void uninstallPackage_frameworkNotRunning_startsFrameworkOrThrows() throws Exception {
+ ITestDevice device = createGoodDeviceWithAppNotInstalled();
Mockito.when(
device.executeShellV2Command(
- ArgumentMatchers.startsWith(
- CHECK_PACKAGE_INSTALLED_COMMAND_PREFIX)))
- .thenReturn(commandResult);
+ ArgumentMatchers.eq(SystemPackageUninstaller.PM_CHECK_COMMAND)))
+ .thenReturn(createFailedCommandResult());
+
+ assertThrows(
+ TargetSetupError.class,
+ () -> SystemPackageUninstaller.uninstallPackage(TEST_PACKAGE_NAME, device));
+ Mockito.verify(device, Mockito.times(1)).executeShellV2Command(Mockito.eq("start"));
+ }
+
+ @Test
+ public void uninstallPackage_packageIsNotInstalled_doesNotRemove() throws Exception {
+ ITestDevice device = createGoodDeviceWithAppNotInstalled();
SystemPackageUninstaller.uninstallPackage(TEST_PACKAGE_NAME, device);
@@ -306,6 +314,18 @@ public final class SystemAppUninstallerTest {
return device;
}
+ private ITestDevice createGoodDeviceWithAppNotInstalled() throws Exception {
+ ITestDevice device = createGoodDeviceWithSystemAppInstalled();
+ CommandResult commandResult = createSuccessfulCommandResult();
+ commandResult.setStdout("");
+ Mockito.when(
+ device.executeShellV2Command(
+ ArgumentMatchers.startsWith(
+ CHECK_PACKAGE_INSTALLED_COMMAND_PREFIX)))
+ .thenReturn(commandResult);
+ return device;
+ }
+
private ITestDevice createGoodDeviceWithSystemAppInstalled() throws Exception {
return createGoodDeviceWithSystemAppInstalled(1);
}
@@ -315,6 +335,12 @@ public final class SystemAppUninstallerTest {
ITestDevice device = Mockito.mock(ITestDevice.class);
CommandResult commandResult;
+ // Is framework running
+ Mockito.when(
+ device.executeShellV2Command(
+ ArgumentMatchers.eq(SystemPackageUninstaller.PM_CHECK_COMMAND)))
+ .thenReturn(createSuccessfulCommandResult());
+
// Uninstall updates
String uninstallFailureMessage = "Failure [DELETE_FAILED_INTERNAL_ERROR]";
if (numberOfUpdatesInstalled == 0) {