summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Oli Lan <olilan@google.com> 2019-08-14 11:45:37 +0100
committer Oli Lan <olilan@google.com> 2019-08-16 17:52:50 +0100
commit0672808c27f0c0d4b8e871a170b5adfe794fd768 (patch)
treeaff8d2a7ffece5a67161db5213bb1e2980bc8fff
parent3628bb3a64d3e150c53fabe85e01ab03b2fd9681 (diff)
Include NewRollbacks in result of getAvailableRollbacks.
This CL adds NewRollbacks to the return value of getAvailableRollbacks, as long as the PackageRollbackInfo is complete (i.e. there is one for each child session in the install). Including these should avoid the potential race condition between the install finishing and getAvailableRollbacks being called which affected some of the tests. This means that the draining of the handler that was previously added to getAvailableRollbacks can now be removed. In order to avoid a similar race condition when rollbacks are expired, this change also cancels corresponding NewRollbacks when expireRollbackForPackage is called. Bug: 136241838 Bug: 136548146 Test: atest RollbackTest Test: manual local test with delay added to onFinished in the service callback Change-Id: I015ee5925e38118c40f4b9e145f78fb12c0e2890
-rw-r--r--core/java/android/content/rollback/RollbackManager.java5
-rw-r--r--services/core/java/com/android/server/rollback/RollbackManagerServiceImpl.java41
2 files changed, 21 insertions, 25 deletions
diff --git a/core/java/android/content/rollback/RollbackManager.java b/core/java/android/content/rollback/RollbackManager.java
index 73b8a48d9153..1609f53d3d3b 100644
--- a/core/java/android/content/rollback/RollbackManager.java
+++ b/core/java/android/content/rollback/RollbackManager.java
@@ -74,7 +74,10 @@ public final class RollbackManager {
}
/**
- * Returns a list of all currently available rollbacks.
+ * Returns a list of all currently available rollbacks. This includes ones for very recently
+ * installed packages (even if onFinished has not yet been called). As a result, packages that
+ * very recently failed to install may also be included, but those rollbacks will fail with
+ * 'rollback not available'.
*
* @throws SecurityException if the caller does not have appropriate permissions.
*/
diff --git a/services/core/java/com/android/server/rollback/RollbackManagerServiceImpl.java b/services/core/java/com/android/server/rollback/RollbackManagerServiceImpl.java
index 02f98b4e7376..bfd280c14f6d 100644
--- a/services/core/java/com/android/server/rollback/RollbackManagerServiceImpl.java
+++ b/services/core/java/com/android/server/rollback/RollbackManagerServiceImpl.java
@@ -271,33 +271,9 @@ class RollbackManagerServiceImpl extends IRollbackManager.Stub {
}, filter, null, getHandler());
}
- /**
- * This method posts a blocking call to the handler thread, so it should not be called from
- * that same thread.
- * @throws {@link IllegalStateException} if called from {@link #mHandlerThread}
- */
@Override
public ParceledListSlice getAvailableRollbacks() {
enforceManageRollbacks("getAvailableRollbacks");
- if (Thread.currentThread().equals(mHandlerThread)) {
- Slog.wtf(TAG, "Calling getAvailableRollbacks from mHandlerThread "
- + "causes a deadlock");
- throw new IllegalStateException("Cannot call RollbackManager#getAvailableRollbacks "
- + "from the handler thread!");
- }
-
- // Wait for the handler thread to get the list of available rollbacks
- // to get the most up-to-date results. This is intended to reduce test
- // flakiness when checking available rollbacks immediately after
- // installing a package with rollback enabled.
- CountDownLatch latch = new CountDownLatch(1);
- getHandler().post(() -> latch.countDown());
- try {
- latch.await();
- } catch (InterruptedException ie) {
- throw new IllegalStateException("RollbackManagerHandlerThread interrupted");
- }
-
synchronized (mLock) {
List<RollbackInfo> rollbacks = new ArrayList<>();
for (int i = 0; i < mRollbacks.size(); ++i) {
@@ -306,6 +282,15 @@ class RollbackManagerServiceImpl extends IRollbackManager.Stub {
rollbacks.add(rollback.info);
}
}
+
+ // Also return new rollbacks for which the PackageRollbackInfo is complete.
+ for (NewRollback newRollback : mNewRollbacks) {
+ if (newRollback.rollback.info.getPackages().size()
+ == newRollback.packageSessionIds.length
+ && !newRollback.isCancelled) {
+ rollbacks.add(newRollback.rollback.info);
+ }
+ }
return new ParceledListSlice<>(rollbacks);
}
}
@@ -562,6 +547,14 @@ class RollbackManagerServiceImpl extends IRollbackManager.Stub {
}
}
}
+ for (NewRollback newRollback : mNewRollbacks) {
+ for (PackageRollbackInfo info : newRollback.rollback.info.getPackages()) {
+ if (info.getPackageName().equals(packageName)) {
+ newRollback.isCancelled = true;
+ break;
+ }
+ }
+ }
}
}