aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYuexi Ma <yuexima@google.com>2021-02-10 16:39:48 -0800
committerYuexi Ma <yuexima@google.com>2021-02-17 10:31:15 -0800
commit274cc63042bae4135eae0935c4dc0c7d9b6a0f1b (patch)
tree22f01979b7edafdc955526b96b30bd12f9a39d2a
parent8cdf2e32c5bd4694d32a15f799aec890c5b3fa14 (diff)
downloadplatform_test_app_compat_csuite-274cc63042bae4135eae0935c4dc0c7d9b6a0f1b.tar.gz
platform_test_app_compat_csuite-274cc63042bae4135eae0935c4dc0c7d9b6a0f1b.tar.bz2
platform_test_app_compat_csuite-274cc63042bae4135eae0935c4dc0c7d9b6a0f1b.zip
Ensure the framework is turned back on in uninstaller
Previously if the operations throws error after stopping the framework, it won't turn back on. This CL uses a try-finally block to ensure framework is turned back on. Test: atest :presubmit Change-Id: I5f5bf9d771b06e9e9b37bff231510a6379975809
-rw-r--r--harness/src/main/java/com/android/compatibility/targetprep/SystemAppRemovalPreparer.java28
1 files changed, 21 insertions, 7 deletions
diff --git a/harness/src/main/java/com/android/compatibility/targetprep/SystemAppRemovalPreparer.java b/harness/src/main/java/com/android/compatibility/targetprep/SystemAppRemovalPreparer.java
index 7639e9f..d5438cc 100644
--- a/harness/src/main/java/com/android/compatibility/targetprep/SystemAppRemovalPreparer.java
+++ b/harness/src/main/java/com/android/compatibility/targetprep/SystemAppRemovalPreparer.java
@@ -83,18 +83,30 @@ public final class SystemAppRemovalPreparer implements ITargetPreparer {
runWithWritableFilesystem(
device,
- () -> {
- stopFramework(device);
- removePackageInstallDirectory(packageInstallDirectory, device);
- removePackageData(mPackageName, device);
- startFramework(device);
- });
+ () ->
+ runWithFrameworkOff(
+ device,
+ () -> {
+ removePackageInstallDirectory(packageInstallDirectory, device);
+ removePackageData(mPackageName, device);
+ }));
}
private interface PreparerTask {
void run() throws TargetSetupError, DeviceNotAvailableException;
}
+ private static void runWithFrameworkOff(ITestDevice device, PreparerTask action)
+ throws TargetSetupError, DeviceNotAvailableException {
+ stopFramework(device);
+
+ try {
+ action.run();
+ } finally {
+ startFramework(device);
+ }
+ }
+
private static void runWithWritableFilesystem(ITestDevice device, PreparerTask action)
throws TargetSetupError, DeviceNotAvailableException {
runAsRoot(
@@ -209,7 +221,9 @@ public final class SystemAppRemovalPreparer implements ITargetPreparer {
// only uninstalls the latest update. To remove all update packages we can
// call uninstall repeatedly until the command fails.
for (int i = 0; i < MAX_NUMBER_OF_UPDATES; i++) {
- if (device.uninstallPackage(packageName) != null) {
+ String errMsg = device.uninstallPackage(packageName);
+ if (errMsg != null) {
+ CLog.d("Completed removing updates as the uninstall command returned: %s", errMsg);
return;
}
CLog.i("Removed an update package for %s", packageName);