}
/**
- * Asserts that the given RollbackInfo has a single package with expected
- * package name and versions.
+ * Asserts that the given RollbackInfo has the given packages with expected
+ * package names and all are rolled to and from the same given versions.
*/
- static void assertRollbackInfoEquals(String packageName,
+ static void assertRollbackInfoEquals(String[] packageNames,
long versionRolledBackFrom, long versionRolledBackTo,
RollbackInfo info, VersionedPackage... causePackages) {
assertNotNull(info);
- assertEquals(1, info.getPackages().size());
- assertPackageRollbackInfoEquals(packageName, versionRolledBackFrom, versionRolledBackTo,
- info.getPackages().get(0));
+ assertEquals(packageNames.length, info.getPackages().size());
+ int foundPackages = 0;
+ for (String packageName : packageNames) {
+ for (PackageRollbackInfo pkgRollbackInfo : info.getPackages()) {
+ if (packageName.equals(pkgRollbackInfo.getPackageName())) {
+ foundPackages++;
+ assertPackageRollbackInfoEquals(packageName, versionRolledBackFrom,
+ versionRolledBackTo, pkgRollbackInfo);
+ break;
+ }
+ }
+ }
+ assertEquals(packageNames.length, foundPackages);
assertEquals(causePackages.length, info.getCausePackages().size());
for (int i = 0; i < causePackages.length; ++i) {
assertEquals(causePackages[i].getPackageName(),
}
/**
+ * Asserts that the given RollbackInfo has a single package with expected
+ * package name and versions.
+ */
+ static void assertRollbackInfoEquals(String packageName,
+ long versionRolledBackFrom, long versionRolledBackTo,
+ RollbackInfo info, VersionedPackage... causePackages) {
+ String[] packageNames = {packageName};
+ assertRollbackInfoEquals(packageNames, versionRolledBackFrom, versionRolledBackTo, info,
+ causePackages);
+ }
+
+ /**
* Waits for the given session to be marked as ready.
* Throws an assertion if the session fails.
*/
fail(result);
}
}
+
+ /**
+ * Return the rollback info for a recently committed rollback, by matching the rollback id, or
+ * return null if no matching rollback is found.
+ */
+ static RollbackInfo getRecentlyCommittedRollbackInfoById(int getRollbackId) {
+ for (RollbackInfo info : getRollbackManager().getRecentlyCommittedRollbacks()) {
+ if (info.getRollbackId() == getRollbackId) {
+ return info;
+ }
+ }
+ return null;
+ }
}
package com.android.tests.rollback;
import static com.android.tests.rollback.RollbackTestUtils.assertRollbackInfoEquals;
+import static com.android.tests.rollback.RollbackTestUtils.getRecentlyCommittedRollbackInfoById;
import static com.android.tests.rollback.RollbackTestUtils.getUniqueRollbackInfoForPackage;
import android.Manifest;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
-import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import org.junit.After;
private static final String TAG = "RollbackTest";
private static final String TEST_APP_A = "com.android.tests.rollback.testapp.A";
+ private static final String TEST_APP_A_V1 = "RollbackTestAppAv1.apk";
+ private static final String TEST_APP_A_V2 = "RollbackTestAppAv2.apk";
private static final String TEST_APEX_PKG = "com.android.tests.rollback.testapex";
private static final String TEST_APEX_V1 =
"com.android.tests.rollback.testapex.RollbackTestApexV1.apex";
RollbackTestUtils.uninstall(TEST_APP_A);
assertEquals(-1, RollbackTestUtils.getInstalledVersion(TEST_APP_A));
- RollbackTestUtils.install("RollbackTestAppAv1.apk", false);
+ RollbackTestUtils.install(TEST_APP_A_V1, false);
assertEquals(1, RollbackTestUtils.getInstalledVersion(TEST_APP_A));
RollbackTestUtils.processUserData(TEST_APP_A);
- RollbackTestUtils.installStaged(true, "RollbackTestAppAv2.apk");
+ RollbackTestUtils.installStaged(true, TEST_APP_A_V2);
// At this point, the host test driver will reboot the device and run
// testApkOnlyCommitRollback().
}
/**
+ * Test rollbacks of staged installs an apk and an apex.
+ * Prepare apex (and apk) phase.
+ */
+ @Test
+ public void testApkAndApexPrepare() throws Exception {
+ RollbackTestUtils.uninstall(TEST_APP_A);
+ assertEquals(-1, RollbackTestUtils.getInstalledVersion(TEST_APP_A));
+
+ // Note: can't uninstall the apex. See note in #testApexOnlyPrepareApex().
+ RollbackTestUtils.installStaged(false, TEST_APP_A_V1, TEST_APEX_V1);
+
+ // At this point, the host test driver will reboot the device and run
+ // testApkAndApexEnableRollback().
+ }
+
+ /**
+ * Test rollbacks of staged installs an apk and an apex.
+ * Enable rollback phase.
+ */
+ @Test
+ public void testApkAndApexEnableRollback() throws Exception {
+ assertEquals(1, RollbackTestUtils.getInstalledVersion(TEST_APEX_PKG));
+ assertEquals(1, RollbackTestUtils.getInstalledVersion(TEST_APP_A));
+
+ RollbackTestUtils.installStaged(true, TEST_APP_A_V2, TEST_APEX_V2);
+
+ // At this point, the host test driver will reboot the device and run
+ // testApkAndApexCommitRollback().
+ }
+
+ /**
+ * Test rollbacks of staged installs an apk and an apex.
+ * Commit rollback phase.
+ */
+ @Test
+ public void testApkAndApexCommitRollback() throws Exception {
+ assertEquals(2, RollbackTestUtils.getInstalledVersion(TEST_APEX_PKG));
+ assertEquals(2, RollbackTestUtils.getInstalledVersion(TEST_APP_A));
+
+ RollbackTestUtils.processUserData(TEST_APP_A);
+
+ RollbackManager rm = RollbackTestUtils.getRollbackManager();
+
+ RollbackInfo rollback = getUniqueRollbackInfoForPackage(
+ rm.getAvailableRollbacks(), TEST_APP_A);
+ String[] packagesNames = {TEST_APEX_PKG, TEST_APP_A};
+ assertRollbackInfoEquals(packagesNames, 2, 1, rollback);
+ assertTrue(rollback.isStaged());
+
+ RollbackTestUtils.rollback(rollback.getRollbackId());
+
+ RollbackInfo committed = getRecentlyCommittedRollbackInfoById(rollback.getRollbackId());
+
+ assertRollbackInfoEquals(packagesNames, 2, 1, committed);
+ assertTrue(committed.isStaged());
+ assertNotEquals(-1, committed.getCommittedSessionId());
+
+ RollbackTestUtils.waitForSessionReady(committed.getCommittedSessionId());
+
+ // The apex and apk should not be rolled back until after reboot.
+ assertEquals(2, RollbackTestUtils.getInstalledVersion(TEST_APEX_PKG));
+ assertEquals(2, RollbackTestUtils.getInstalledVersion(TEST_APP_A));
+
+ // At this point, the host test driver will reboot the device and run
+ // testApkAndApexConfirmRollback().
+ }
+
+ /**
+ * Test rollbacks of staged installs an apk and an apex.
+ * Confirm rollback phase.
+ */
+ @Test
+ public void testApkAndApexConfirmRollback() throws Exception {
+ assertEquals(1, RollbackTestUtils.getInstalledVersion(TEST_APEX_PKG));
+ assertEquals(1, RollbackTestUtils.getInstalledVersion(TEST_APP_A));
+
+ RollbackTestUtils.processUserData(TEST_APP_A);
+ }
+
+ /**
* Test rollbacks of staged installs involving only apex.
* Prepare apex phase.
*/
}
/**
- * Test rollbacks of staged installs involving only apks.
+ * Test rollbacks of staged installs involving only apex.
* Commit rollback phase.
*/
@Test
RollbackTestUtils.rollback(rollback.getRollbackId());
- // Note: We can't use getUniqueRollbackInfoForPackage for the apex,
- // because we can't uninstall the apex (b/123667725), which means
- // there's no way to clear info about rollbacks from previous tests
- // run on the device. Look up the info by rollback id instead.
- RollbackInfo committed = null;
- for (RollbackInfo info : rm.getRecentlyCommittedRollbacks()) {
- if (info.getRollbackId() == rollback.getRollbackId()) {
- assertNull(committed);
- committed = info;
- break;
- }
- }
+ RollbackInfo committed = getRecentlyCommittedRollbackInfoById(rollback.getRollbackId());
+
assertRollbackInfoEquals(TEST_APEX_PKG, 2, 1, committed);
assertTrue(committed.isStaged());
assertNotEquals(-1, committed.getCommittedSessionId());
}
/**
- * Test rollbacks of staged installs involving only apks.
+ * Test rollbacks of staged installs involving only apex.
* Confirm rollback phase.
*/
@Test