summaryrefslogtreecommitdiff
path: root/tests/RollbackTest
diff options
context:
space:
mode:
authorshafik <shafik@google.com>2019-06-06 19:16:39 +0100
committerBill Lin <lbill@google.com>2019-11-21 13:46:06 +0800
commitaf4df0e7c6fc49bdd919ca005f9efd99d07e90b2 (patch)
tree99c35e26d326a2669b33e89b76dc206fe13f8a2e /tests/RollbackTest
parent73f1771d27f3268d7bd1348fff689ac4bf5a3f02 (diff)
Migrate RollbackTest and StagedRollbackTest to cts utils
Replace the usage of RollbackTestUtils with the API offered by com.android.cts.install.lib and com.android.cts.rollback.lib. Test: atest RollbackTest Test: atest StagedRollbackTest #testBadApkOnly Bug: 132757394 Bug: 132422403 Change-Id: I1d6789b4fb7ae94ebf7066a6fd215e4ac48c04df Merged-In: I25cb9dca103852d7ee3691e4df927e1fc5848074
Diffstat (limited to 'tests/RollbackTest')
-rw-r--r--tests/RollbackTest/Android.bp78
-rw-r--r--tests/RollbackTest/RollbackTest/AndroidManifest.xml2
-rw-r--r--tests/RollbackTest/RollbackTest/src/com/android/tests/rollback/LocalIntentSender.java60
-rw-r--r--tests/RollbackTest/RollbackTest/src/com/android/tests/rollback/RollbackBroadcastReceiver.java78
-rw-r--r--tests/RollbackTest/RollbackTest/src/com/android/tests/rollback/RollbackTest.java751
-rw-r--r--tests/RollbackTest/RollbackTest/src/com/android/tests/rollback/RollbackTestUtils.java547
-rw-r--r--tests/RollbackTest/RollbackTest/src/com/android/tests/rollback/StagedRollbackTest.java100
-rw-r--r--tests/RollbackTest/TestApp/ACrashingV2.xml36
-rw-r--r--tests/RollbackTest/TestApp/Av1.xml35
-rw-r--r--tests/RollbackTest/TestApp/Av2.xml35
-rw-r--r--tests/RollbackTest/TestApp/Av3.xml35
-rw-r--r--tests/RollbackTest/TestApp/Bv1.xml35
-rw-r--r--tests/RollbackTest/TestApp/Bv2.xml35
-rw-r--r--tests/RollbackTest/TestApp/res_v1/values-anydpi/values.xml19
-rw-r--r--tests/RollbackTest/TestApp/res_v1/values/values.xml20
-rw-r--r--tests/RollbackTest/TestApp/res_v2/values-anydpi/values.xml19
-rw-r--r--tests/RollbackTest/TestApp/res_v2/values/values.xml20
-rw-r--r--tests/RollbackTest/TestApp/res_v3/values-anydpi/values.xml19
-rw-r--r--tests/RollbackTest/TestApp/res_v3/values/values.xml20
-rw-r--r--tests/RollbackTest/TestApp/src/com/android/tests/rollback/testapp/CrashingMainActivity.java46
-rw-r--r--tests/RollbackTest/TestApp/src/com/android/tests/rollback/testapp/MainActivity.java37
-rw-r--r--tests/RollbackTest/TestApp/src/com/android/tests/rollback/testapp/ProcessUserData.java111
22 files changed, 461 insertions, 1677 deletions
diff --git a/tests/RollbackTest/Android.bp b/tests/RollbackTest/Android.bp
index 5172935e6074..2bd5931eccbe 100644
--- a/tests/RollbackTest/Android.bp
+++ b/tests/RollbackTest/Android.bp
@@ -12,88 +12,12 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-android_test_helper_app {
- name: "RollbackTestAppAv1",
- manifest: "TestApp/Av1.xml",
- sdk_version: "current",
- srcs: ["TestApp/src/**/*.java"],
- resource_dirs: ["TestApp/res_v1"],
-}
-
-android_test_helper_app {
- name: "RollbackTestAppAv2",
- manifest: "TestApp/Av2.xml",
- sdk_version: "current",
- srcs: ["TestApp/src/**/*.java"],
- resource_dirs: ["TestApp/res_v2"],
-}
-
-android_test_helper_app {
- name: "RollbackTestAppAv3",
- manifest: "TestApp/Av3.xml",
- sdk_version: "current",
- srcs: ["TestApp/src/**/*.java"],
- resource_dirs: ["TestApp/res_v3"],
-}
-
-android_test_helper_app {
- name: "RollbackTestAppACrashingV2",
- manifest: "TestApp/ACrashingV2.xml",
- sdk_version: "current",
- srcs: ["TestApp/src/**/*.java"],
- resource_dirs: ["TestApp/res_v2"],
-}
-
-android_test_helper_app {
- name: "RollbackTestAppBv1",
- manifest: "TestApp/Bv1.xml",
- sdk_version: "current",
- srcs: ["TestApp/src/**/*.java"],
- resource_dirs: ["TestApp/res_v1"],
-}
-
-android_test_helper_app {
- name: "RollbackTestAppBv2",
- manifest: "TestApp/Bv2.xml",
- sdk_version: "current",
- srcs: ["TestApp/src/**/*.java"],
- resource_dirs: ["TestApp/res_v2"],
-}
-
-android_test_helper_app {
- name: "RollbackTestAppASplitV1",
- manifest: "TestApp/Av1.xml",
- sdk_version: "current",
- srcs: ["TestApp/src/**/*.java"],
- resource_dirs: ["TestApp/res_v1"],
- package_splits: ["anydpi"],
-}
-
-android_test_helper_app {
- name: "RollbackTestAppASplitV2",
- manifest: "TestApp/Av2.xml",
- sdk_version: "current",
- srcs: ["TestApp/src/**/*.java"],
- resource_dirs: ["TestApp/res_v2"],
- package_splits: ["anydpi"],
-}
-
android_test {
name: "RollbackTest",
manifest: "RollbackTest/AndroidManifest.xml",
srcs: ["RollbackTest/src/**/*.java"],
- static_libs: ["androidx.test.rules"],
+ static_libs: ["androidx.test.rules", "cts-rollback-lib", "cts-install-lib"],
test_suites: ["general-tests"],
- java_resources: [
- ":RollbackTestAppAv1",
- ":RollbackTestAppAv2",
- ":RollbackTestAppAv3",
- ":RollbackTestAppACrashingV2",
- ":RollbackTestAppBv1",
- ":RollbackTestAppBv2",
- ":RollbackTestAppASplitV1",
- ":RollbackTestAppASplitV2",
- ],
test_config: "RollbackTest.xml",
// TODO: sdk_version: "test_current" when Intent#resolveSystemservice is TestApi
}
diff --git a/tests/RollbackTest/RollbackTest/AndroidManifest.xml b/tests/RollbackTest/RollbackTest/AndroidManifest.xml
index 5380dc9fc8cd..2b8c96484210 100644
--- a/tests/RollbackTest/RollbackTest/AndroidManifest.xml
+++ b/tests/RollbackTest/RollbackTest/AndroidManifest.xml
@@ -18,7 +18,7 @@
package="com.android.tests.rollback" >
<application>
- <receiver android:name="com.android.tests.rollback.LocalIntentSender"
+ <receiver android:name="com.android.cts.install.lib.LocalIntentSender"
android:exported="true" />
<uses-library android:name="android.test.runner" />
</application>
diff --git a/tests/RollbackTest/RollbackTest/src/com/android/tests/rollback/LocalIntentSender.java b/tests/RollbackTest/RollbackTest/src/com/android/tests/rollback/LocalIntentSender.java
deleted file mode 100644
index 267ef7377b36..000000000000
--- a/tests/RollbackTest/RollbackTest/src/com/android/tests/rollback/LocalIntentSender.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * Copyright (C) 2018 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.tests.rollback;
-
-import android.app.PendingIntent;
-import android.content.BroadcastReceiver;
-import android.content.Context;
-import android.content.Intent;
-import android.content.IntentSender;
-
-import androidx.test.InstrumentationRegistry;
-
-import java.util.concurrent.BlockingQueue;
-import java.util.concurrent.LinkedBlockingQueue;
-
-/**
- * Make IntentSender that sends intent locally.
- */
-public class LocalIntentSender extends BroadcastReceiver {
-
- private static final String TAG = "RollbackTest";
-
- private static final BlockingQueue<Intent> sIntentSenderResults = new LinkedBlockingQueue<>();
-
- @Override
- public void onReceive(Context context, Intent intent) {
- sIntentSenderResults.add(intent);
- }
-
- /**
- * Get a LocalIntentSender.
- */
- static IntentSender getIntentSender() {
- Context context = InstrumentationRegistry.getContext();
- Intent intent = new Intent(context, LocalIntentSender.class);
- PendingIntent pending = PendingIntent.getBroadcast(context, 0, intent, 0);
- return pending.getIntentSender();
- }
-
- /**
- * Returns the most recent Intent sent by a LocalIntentSender.
- */
- static Intent getIntentSenderResult() throws InterruptedException {
- return sIntentSenderResults.take();
- }
-}
diff --git a/tests/RollbackTest/RollbackTest/src/com/android/tests/rollback/RollbackBroadcastReceiver.java b/tests/RollbackTest/RollbackTest/src/com/android/tests/rollback/RollbackBroadcastReceiver.java
deleted file mode 100644
index ebe54187ddb6..000000000000
--- a/tests/RollbackTest/RollbackTest/src/com/android/tests/rollback/RollbackBroadcastReceiver.java
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- * Copyright (C) 2018 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.tests.rollback;
-
-import android.content.BroadcastReceiver;
-import android.content.Context;
-import android.content.Intent;
-import android.content.IntentFilter;
-import android.util.Log;
-
-import androidx.test.InstrumentationRegistry;
-
-import java.util.concurrent.BlockingQueue;
-import java.util.concurrent.LinkedBlockingQueue;
-import java.util.concurrent.TimeUnit;
-
-/**
- * A broadcast receiver that can be used to get
- * ACTION_ROLLBACK_COMMITTED broadcasts.
- */
-class RollbackBroadcastReceiver extends BroadcastReceiver {
-
- private static final String TAG = "RollbackTest";
-
- private final BlockingQueue<Intent> mRollbackBroadcasts = new LinkedBlockingQueue<>();
-
- /**
- * Creates a RollbackBroadcastReceiver and registers it with the given
- * context.
- */
- RollbackBroadcastReceiver() {
- IntentFilter filter = new IntentFilter();
- filter.addAction(Intent.ACTION_ROLLBACK_COMMITTED);
- InstrumentationRegistry.getContext().registerReceiver(this, filter);
- }
-
- @Override
- public void onReceive(Context context, Intent intent) {
- Log.i(TAG, "Received rollback broadcast intent");
- mRollbackBroadcasts.add(intent);
- }
-
- /**
- * Polls for at most the given amount of time for the next rollback
- * broadcast.
- */
- Intent poll(long timeout, TimeUnit unit) throws InterruptedException {
- return mRollbackBroadcasts.poll(timeout, unit);
- }
-
- /**
- * Waits forever for the next rollback broadcast.
- */
- Intent take() throws InterruptedException {
- return mRollbackBroadcasts.take();
- }
-
- /**
- * Unregisters this broadcast receiver.
- */
- void unregister() {
- InstrumentationRegistry.getContext().unregisterReceiver(this);
- }
-}
diff --git a/tests/RollbackTest/RollbackTest/src/com/android/tests/rollback/RollbackTest.java b/tests/RollbackTest/RollbackTest/src/com/android/tests/rollback/RollbackTest.java
index 4665d63037c9..ebf09b848dab 100644
--- a/tests/RollbackTest/RollbackTest/src/com/android/tests/rollback/RollbackTest.java
+++ b/tests/RollbackTest/RollbackTest/src/com/android/tests/rollback/RollbackTest.java
@@ -16,14 +16,12 @@
package com.android.tests.rollback;
-import static com.android.tests.rollback.RollbackTestUtils.assertPackageRollbackInfoEquals;
-import static com.android.tests.rollback.RollbackTestUtils.assertRollbackInfoEquals;
-import static com.android.tests.rollback.RollbackTestUtils.getUniqueRollbackInfoForPackage;
-import static com.android.tests.rollback.RollbackTestUtils.processUserData;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
+import static com.android.cts.install.lib.InstallUtils.processUserData;
+import static com.android.cts.rollback.lib.RollbackInfoSubject.assertThat;
+import static com.android.cts.rollback.lib.RollbackUtils.getUniqueRollbackInfoForPackage;
+
+import static com.google.common.truth.Truth.assertThat;
+
import static org.junit.Assert.fail;
import android.Manifest;
@@ -31,7 +29,6 @@ import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
-import android.content.pm.VersionedPackage;
import android.content.rollback.RollbackInfo;
import android.content.rollback.RollbackManager;
import android.provider.DeviceConfig;
@@ -39,6 +36,14 @@ import android.util.Log;
import androidx.test.InstrumentationRegistry;
+import com.android.cts.install.lib.Install;
+import com.android.cts.install.lib.InstallUtils;
+import com.android.cts.install.lib.TestApp;
+import com.android.cts.install.lib.Uninstall;
+import com.android.cts.rollback.lib.Rollback;
+import com.android.cts.rollback.lib.RollbackBroadcastReceiver;
+import com.android.cts.rollback.lib.RollbackUtils;
+
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -56,8 +61,6 @@ public class RollbackTest {
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_B = "com.android.tests.rollback.testapp.B";
private static final String INSTRUMENTED_APP = "com.android.tests.rollback";
// copied from PackageManagerService#PROPERTY_ENABLE_ROLLBACK_TIMEOUT_MILLIS
@@ -87,7 +90,7 @@ public class RollbackTest {
context.registerReceiver(enableRollbackReceiver, enableRollbackFilter);
try {
- RollbackTestUtils.adoptShellPermissionIdentity(
+ InstallUtils.adoptShellPermissionIdentity(
Manifest.permission.INSTALL_PACKAGES,
Manifest.permission.DELETE_PACKAGES,
Manifest.permission.TEST_MANAGE_ROLLBACKS,
@@ -96,18 +99,18 @@ public class RollbackTest {
// Register a broadcast receiver for notification when the
// rollback has been committed.
RollbackBroadcastReceiver broadcastReceiver = new RollbackBroadcastReceiver();
- RollbackManager rm = RollbackTestUtils.getRollbackManager();
+ RollbackManager rm = RollbackUtils.getRollbackManager();
- // Uninstall TEST_APP_A
- RollbackTestUtils.uninstall(TEST_APP_A);
- assertEquals(-1, RollbackTestUtils.getInstalledVersion(TEST_APP_A));
+ // Uninstall TestApp.A
+ Uninstall.packages(TestApp.A);
+ assertThat(InstallUtils.getInstalledVersion(TestApp.A)).isEqualTo(-1);
// TODO: There is currently a race condition between when the app is
// uninstalled and when rollback manager deletes the rollback. Fix it
// so that's not the case!
for (int i = 0; i < 5; ++i) {
RollbackInfo rollback = getUniqueRollbackInfoForPackage(
- rm.getRecentlyCommittedRollbacks(), TEST_APP_A);
+ rm.getRecentlyCommittedRollbacks(), TestApp.A);
if (rollback != null) {
Log.i(TAG, "Sleeping 1 second to wait for uninstall to take effect.");
Thread.sleep(1000);
@@ -115,33 +118,37 @@ public class RollbackTest {
}
// The app should not be available for rollback.
- assertNull(getUniqueRollbackInfoForPackage(rm.getAvailableRollbacks(), TEST_APP_A));
+ assertThat(
+ getUniqueRollbackInfoForPackage(rm.getAvailableRollbacks(), TestApp.A)).isNull();
// There should be no recently committed rollbacks for this package.
- assertNull(getUniqueRollbackInfoForPackage(
- rm.getRecentlyCommittedRollbacks(), TEST_APP_A));
+ assertThat(getUniqueRollbackInfoForPackage(
+ rm.getRecentlyCommittedRollbacks(), TestApp.A)).isNull();
// Install v1 of the app (without rollbacks enabled).
- RollbackTestUtils.install("RollbackTestAppAv1.apk", false);
- assertEquals(1, RollbackTestUtils.getInstalledVersion(TEST_APP_A));
+ Install.single(TestApp.A1).commit();
+ assertThat(InstallUtils.getInstalledVersion(TestApp.A)).isEqualTo(1);
// Upgrade from v1 to v2, with rollbacks enabled.
- RollbackTestUtils.install("RollbackTestAppAv2.apk", true);
- assertEquals(2, RollbackTestUtils.getInstalledVersion(TEST_APP_A));
+ Install.single(TestApp.A2).setEnableRollback().commit();
+ assertThat(InstallUtils.getInstalledVersion(TestApp.A)).isEqualTo(2);
// The app should now be available for rollback.
- RollbackInfo rollback = getUniqueRollbackInfoForPackage(
- rm.getAvailableRollbacks(), TEST_APP_A);
- assertRollbackInfoEquals(TEST_APP_A, 2, 1, rollback);
+ RollbackInfo available = getUniqueRollbackInfoForPackage(
+ rm.getAvailableRollbacks(), TestApp.A);
+ assertThat(available).isNotNull();
+ assertThat(available).isNotStaged();
+ assertThat(available).packagesContainsExactly(
+ Rollback.from(TestApp.A2).to(TestApp.A1));
// We should not have received any rollback requests yet.
// TODO: Possibly flaky if, by chance, some other app on device
// happens to be rolled back at the same time?
- assertNull(broadcastReceiver.poll(0, TimeUnit.SECONDS));
+ assertThat(broadcastReceiver.poll(0, TimeUnit.SECONDS)).isNull();
// Roll back the app.
- RollbackTestUtils.rollback(rollback.getRollbackId());
- assertEquals(1, RollbackTestUtils.getInstalledVersion(TEST_APP_A));
+ RollbackUtils.rollback(available.getRollbackId());
+ assertThat(InstallUtils.getInstalledVersion(TestApp.A)).isEqualTo(1);
// Verify we received a broadcast for the rollback.
// TODO: Race condition between the timeout and when the broadcast is
@@ -149,22 +156,27 @@ public class RollbackTest {
Intent broadcast = broadcastReceiver.poll(5, TimeUnit.SECONDS);
if (context.getUser().isSystem()) {
// Only system user should receive those broadcasts.
- assertNotNull(broadcast);
- assertNull(broadcastReceiver.poll(0, TimeUnit.SECONDS));
+ assertThat(broadcast).isNotNull();
+ assertThat(broadcastReceiver.poll(0, TimeUnit.SECONDS)).isNull();
} else {
// This is in case the test was running under a secondary user, in which case
// the broadcast won't be received here.
- assertNull(broadcast);
+ assertThat(broadcast).isNull();
}
+
// Verify the recent rollback has been recorded.
- rollback = getUniqueRollbackInfoForPackage(
- rm.getRecentlyCommittedRollbacks(), TEST_APP_A);
- assertRollbackInfoEquals(TEST_APP_A, 2, 1, rollback);
+ RollbackInfo committed = getUniqueRollbackInfoForPackage(
+ rm.getRecentlyCommittedRollbacks(), TestApp.A);
+ assertThat(committed).isNotNull();
+ assertThat(committed).isNotStaged();
+ assertThat(committed).packagesContainsExactly(
+ Rollback.from(TestApp.A2).to(TestApp.A1));
+ assertThat(committed).hasRollbackId(available.getRollbackId());
broadcastReceiver.unregister();
context.unregisterReceiver(enableRollbackReceiver);
} finally {
- RollbackTestUtils.dropShellPermissionIdentity();
+ InstallUtils.dropShellPermissionIdentity();
}
}
@@ -174,50 +186,58 @@ public class RollbackTest {
@Test
public void testAvailableRollbackPersistence() throws Exception {
try {
- RollbackTestUtils.adoptShellPermissionIdentity(
+ InstallUtils.adoptShellPermissionIdentity(
Manifest.permission.INSTALL_PACKAGES,
Manifest.permission.DELETE_PACKAGES,
Manifest.permission.TEST_MANAGE_ROLLBACKS);
- RollbackManager rm = RollbackTestUtils.getRollbackManager();
+ RollbackManager rm = RollbackUtils.getRollbackManager();
- RollbackTestUtils.uninstall(TEST_APP_A);
- RollbackTestUtils.install("RollbackTestAppAv1.apk", false);
- RollbackTestUtils.install("RollbackTestAppAv2.apk", true);
- assertEquals(2, RollbackTestUtils.getInstalledVersion(TEST_APP_A));
+ Uninstall.packages(TestApp.A);
+ Install.single(TestApp.A1).commit();
+ Install.single(TestApp.A2).setEnableRollback().commit();
+ assertThat(InstallUtils.getInstalledVersion(TestApp.A)).isEqualTo(2);
- RollbackTestUtils.uninstall(TEST_APP_B);
- RollbackTestUtils.install("RollbackTestAppBv1.apk", false);
- RollbackTestUtils.install("RollbackTestAppBv2.apk", true);
- assertEquals(2, RollbackTestUtils.getInstalledVersion(TEST_APP_B));
+ Uninstall.packages(TestApp.B);
+ Install.single(TestApp.B1).commit();
+ Install.single(TestApp.B2).setEnableRollback().commit();
+ assertThat(InstallUtils.getInstalledVersion(TestApp.B)).isEqualTo(2);
// Both test apps should now be available for rollback.
RollbackInfo rollbackA = getUniqueRollbackInfoForPackage(
- rm.getAvailableRollbacks(), TEST_APP_A);
- assertRollbackInfoEquals(TEST_APP_A, 2, 1, rollbackA);
+ rm.getAvailableRollbacks(), TestApp.A);
+ assertThat(rollbackA).isNotNull();
+ assertThat(rollbackA).packagesContainsExactly(
+ Rollback.from(TestApp.A2).to(TestApp.A1));
RollbackInfo rollbackB = getUniqueRollbackInfoForPackage(
- rm.getAvailableRollbacks(), TEST_APP_B);
- assertRollbackInfoEquals(TEST_APP_B, 2, 1, rollbackB);
+ rm.getAvailableRollbacks(), TestApp.B);
+ assertThat(rollbackB).isNotNull();
+ assertThat(rollbackB).packagesContainsExactly(
+ Rollback.from(TestApp.B2).to(TestApp.B1));
// Reload the persisted data.
rm.reloadPersistedData();
// The apps should still be available for rollback.
rollbackA = getUniqueRollbackInfoForPackage(
- rm.getAvailableRollbacks(), TEST_APP_A);
- assertRollbackInfoEquals(TEST_APP_A, 2, 1, rollbackA);
+ rm.getAvailableRollbacks(), TestApp.A);
+ assertThat(rollbackA).isNotNull();
+ assertThat(rollbackA).packagesContainsExactly(
+ Rollback.from(TestApp.A2).to(TestApp.A1));
rollbackB = getUniqueRollbackInfoForPackage(
- rm.getAvailableRollbacks(), TEST_APP_B);
- assertRollbackInfoEquals(TEST_APP_B, 2, 1, rollbackB);
+ rm.getAvailableRollbacks(), TestApp.B);
+ assertThat(rollbackB).isNotNull();
+ assertThat(rollbackB).packagesContainsExactly(
+ Rollback.from(TestApp.B2).to(TestApp.B1));
// Rollback of B should not rollback A
- RollbackTestUtils.rollback(rollbackB.getRollbackId());
- assertEquals(2, RollbackTestUtils.getInstalledVersion(TEST_APP_A));
- assertEquals(1, RollbackTestUtils.getInstalledVersion(TEST_APP_B));
+ RollbackUtils.rollback(rollbackB.getRollbackId());
+ assertThat(InstallUtils.getInstalledVersion(TestApp.A)).isEqualTo(2);
+ assertThat(InstallUtils.getInstalledVersion(TestApp.B)).isEqualTo(1);
} finally {
- RollbackTestUtils.dropShellPermissionIdentity();
+ InstallUtils.dropShellPermissionIdentity();
}
}
@@ -227,49 +247,78 @@ public class RollbackTest {
@Test
public void testAvailableMultiPackageRollbackPersistence() throws Exception {
try {
- RollbackTestUtils.adoptShellPermissionIdentity(
+ InstallUtils.adoptShellPermissionIdentity(
Manifest.permission.INSTALL_PACKAGES,
Manifest.permission.DELETE_PACKAGES,
Manifest.permission.TEST_MANAGE_ROLLBACKS);
- RollbackManager rm = RollbackTestUtils.getRollbackManager();
+ RollbackManager rm = RollbackUtils.getRollbackManager();
- RollbackTestUtils.uninstall(TEST_APP_A);
- RollbackTestUtils.uninstall(TEST_APP_B);
- RollbackTestUtils.installMultiPackage(false,
- "RollbackTestAppAv1.apk",
- "RollbackTestAppBv1.apk");
- RollbackTestUtils.installMultiPackage(true,
- "RollbackTestAppAv2.apk",
- "RollbackTestAppBv2.apk");
- assertEquals(2, RollbackTestUtils.getInstalledVersion(TEST_APP_A));
- assertEquals(2, RollbackTestUtils.getInstalledVersion(TEST_APP_B));
+ Uninstall.packages(TestApp.A, TestApp.B);
+ Install.multi(TestApp.A1, TestApp.B1).commit();
+ Install.multi(TestApp.A2, TestApp.B2).setEnableRollback().commit();
- // The app should now be available for rollback.
- RollbackInfo rollbackA = getUniqueRollbackInfoForPackage(
- rm.getAvailableRollbacks(), TEST_APP_A);
- assertRollbackInfoForAandB(rollbackA);
+ assertThat(InstallUtils.getInstalledVersion(TestApp.A)).isEqualTo(2);
+ assertThat(InstallUtils.getInstalledVersion(TestApp.B)).isEqualTo(2);
- RollbackInfo rollbackB = getUniqueRollbackInfoForPackage(
- rm.getAvailableRollbacks(), TEST_APP_B);
- assertRollbackInfoForAandB(rollbackB);
+ // The app should now be available for rollback.
+ RollbackInfo availableA = getUniqueRollbackInfoForPackage(
+ rm.getAvailableRollbacks(), TestApp.A);
+ assertThat(availableA).isNotNull();
+ assertThat(availableA).packagesContainsExactly(
+ Rollback.from(TestApp.A2).to(TestApp.A1),
+ Rollback.from(TestApp.B2).to(TestApp.B1));
+
+ RollbackInfo availableB = getUniqueRollbackInfoForPackage(
+ rm.getAvailableRollbacks(), TestApp.B);
+ assertThat(availableB).isNotNull();
+ assertThat(availableB).packagesContainsExactly(
+ Rollback.from(TestApp.A2).to(TestApp.A1),
+ Rollback.from(TestApp.B2).to(TestApp.B1));
+
+ // Assert they're both the same rollback
+ assertThat(availableA).hasRollbackId(availableB.getRollbackId());
// Reload the persisted data.
rm.reloadPersistedData();
// The apps should still be available for rollback.
- rollbackA = getUniqueRollbackInfoForPackage(rm.getAvailableRollbacks(), TEST_APP_A);
- assertRollbackInfoForAandB(rollbackA);
-
- rollbackB = getUniqueRollbackInfoForPackage(rm.getAvailableRollbacks(), TEST_APP_B);
- assertRollbackInfoForAandB(rollbackB);
+ availableA = getUniqueRollbackInfoForPackage(rm.getAvailableRollbacks(), TestApp.A);
+ assertThat(availableA).isNotNull();
+ assertThat(availableA).packagesContainsExactly(
+ Rollback.from(TestApp.A2).to(TestApp.A1),
+ Rollback.from(TestApp.B2).to(TestApp.B1));
+
+ availableB = getUniqueRollbackInfoForPackage(rm.getAvailableRollbacks(), TestApp.B);
+ assertThat(availableB).isNotNull();
+ assertThat(availableB).packagesContainsExactly(
+ Rollback.from(TestApp.A2).to(TestApp.A1),
+ Rollback.from(TestApp.B2).to(TestApp.B1));
// Rollback of B should rollback A as well
- RollbackTestUtils.rollback(rollbackB.getRollbackId());
- assertEquals(1, RollbackTestUtils.getInstalledVersion(TEST_APP_A));
- assertEquals(1, RollbackTestUtils.getInstalledVersion(TEST_APP_B));
+ RollbackUtils.rollback(availableB.getRollbackId());
+ assertThat(InstallUtils.getInstalledVersion(TestApp.A)).isEqualTo(1);
+ assertThat(InstallUtils.getInstalledVersion(TestApp.B)).isEqualTo(1);
+
+ RollbackInfo committedA = getUniqueRollbackInfoForPackage(
+ rm.getRecentlyCommittedRollbacks(), TestApp.A);
+ assertThat(committedA).isNotNull();
+ assertThat(committedA).packagesContainsExactly(
+ Rollback.from(TestApp.A2).to(TestApp.A1),
+ Rollback.from(TestApp.B2).to(TestApp.B1));
+
+ RollbackInfo committedB = getUniqueRollbackInfoForPackage(
+ rm.getRecentlyCommittedRollbacks(), TestApp.A);
+ assertThat(committedB).isNotNull();
+ assertThat(committedB).packagesContainsExactly(
+ Rollback.from(TestApp.A2).to(TestApp.A1),
+ Rollback.from(TestApp.B2).to(TestApp.B1));
+
+ // Assert they're both the same rollback
+ assertThat(committedA).hasRollbackId(committedB.getRollbackId());
+ assertThat(committedA).hasRollbackId(availableA.getRollbackId());
} finally {
- RollbackTestUtils.dropShellPermissionIdentity();
+ InstallUtils.dropShellPermissionIdentity();
}
}
@@ -279,42 +328,50 @@ public class RollbackTest {
@Test
public void testRecentlyCommittedRollbackPersistence() throws Exception {
try {
- RollbackTestUtils.adoptShellPermissionIdentity(
+ InstallUtils.adoptShellPermissionIdentity(
Manifest.permission.INSTALL_PACKAGES,
Manifest.permission.DELETE_PACKAGES,
Manifest.permission.TEST_MANAGE_ROLLBACKS);
- RollbackManager rm = RollbackTestUtils.getRollbackManager();
+ RollbackManager rm = RollbackUtils.getRollbackManager();
- RollbackTestUtils.uninstall(TEST_APP_A);
- RollbackTestUtils.install("RollbackTestAppAv1.apk", false);
- RollbackTestUtils.install("RollbackTestAppAv2.apk", true);
- assertEquals(2, RollbackTestUtils.getInstalledVersion(TEST_APP_A));
+ Uninstall.packages(TestApp.A);
+ Install.single(TestApp.A1).commit();
+ Install.single(TestApp.A2).setEnableRollback().commit();
+ assertThat(InstallUtils.getInstalledVersion(TestApp.A)).isEqualTo(2);
// The app should now be available for rollback.
- RollbackInfo rollback = getUniqueRollbackInfoForPackage(
- rm.getAvailableRollbacks(), TEST_APP_A);
+ RollbackInfo available = getUniqueRollbackInfoForPackage(
+ rm.getAvailableRollbacks(), TestApp.A);
+ assertThat(available).isNotNull();
// Roll back the app.
- VersionedPackage cause = new VersionedPackage(
- "com.android.tests.rollback.testapp.Foo", 42);
- RollbackTestUtils.rollback(rollback.getRollbackId(), cause);
- assertEquals(1, RollbackTestUtils.getInstalledVersion(TEST_APP_A));
+ TestApp cause = new TestApp("Foo", "com.android.tests.rollback.testapp.Foo",
+ /*versionCode*/ 42, /*isApex*/ false);
+ RollbackUtils.rollback(available.getRollbackId(), cause);
+ assertThat(InstallUtils.getInstalledVersion(TestApp.A)).isEqualTo(1);
// Verify the recent rollback has been recorded.
- rollback = getUniqueRollbackInfoForPackage(
- rm.getRecentlyCommittedRollbacks(), TEST_APP_A);
- assertRollbackInfoEquals(TEST_APP_A, 2, 1, rollback, cause);
+ RollbackInfo committed = getUniqueRollbackInfoForPackage(
+ rm.getRecentlyCommittedRollbacks(), TestApp.A);
+ assertThat(committed).isNotNull();
+ assertThat(committed).packagesContainsExactly(
+ Rollback.from(TestApp.A2).to(TestApp.A1));
+ assertThat(committed).causePackagesContainsExactly(cause);
// Reload the persisted data.
rm.reloadPersistedData();
// Verify the recent rollback is still recorded.
- rollback = getUniqueRollbackInfoForPackage(
- rm.getRecentlyCommittedRollbacks(), TEST_APP_A);
- assertRollbackInfoEquals(TEST_APP_A, 2, 1, rollback, cause);
+ committed = getUniqueRollbackInfoForPackage(
+ rm.getRecentlyCommittedRollbacks(), TestApp.A);
+ assertThat(committed).isNotNull();
+ assertThat(committed).packagesContainsExactly(
+ Rollback.from(TestApp.A2).to(TestApp.A1));
+ assertThat(committed).causePackagesContainsExactly(cause);
+ assertThat(committed).hasRollbackId(available.getRollbackId());
} finally {
- RollbackTestUtils.dropShellPermissionIdentity();
+ InstallUtils.dropShellPermissionIdentity();
}
}
@@ -325,10 +382,10 @@ public class RollbackTest {
public void testRollbackExpiresAfterLifetime() throws Exception {
long expirationTime = TimeUnit.SECONDS.toMillis(30);
long defaultExpirationTime = TimeUnit.HOURS.toMillis(48);
- RollbackManager rm = RollbackTestUtils.getRollbackManager();
+ RollbackManager rm = RollbackUtils.getRollbackManager();
try {
- RollbackTestUtils.adoptShellPermissionIdentity(
+ InstallUtils.adoptShellPermissionIdentity(
Manifest.permission.INSTALL_PACKAGES,
Manifest.permission.DELETE_PACKAGES,
Manifest.permission.TEST_MANAGE_ROLLBACKS,
@@ -341,39 +398,45 @@ public class RollbackTest {
// Pull the new expiration time from DeviceConfig
rm.reloadPersistedData();
- // Uninstall TEST_APP_A
- RollbackTestUtils.uninstall(TEST_APP_A);
- assertEquals(-1, RollbackTestUtils.getInstalledVersion(TEST_APP_A));
+ // Uninstall TestApp.A
+ Uninstall.packages(TestApp.A);
+ assertThat(InstallUtils.getInstalledVersion(TestApp.A)).isEqualTo(-1);
// Install v1 of the app (without rollbacks enabled).
- RollbackTestUtils.install("RollbackTestAppAv1.apk", false);
- assertEquals(1, RollbackTestUtils.getInstalledVersion(TEST_APP_A));
+ Install.single(TestApp.A1).commit();
+ assertThat(InstallUtils.getInstalledVersion(TestApp.A)).isEqualTo(1);
// Upgrade from v1 to v2, with rollbacks enabled.
- RollbackTestUtils.install("RollbackTestAppAv2.apk", true);
- assertEquals(2, RollbackTestUtils.getInstalledVersion(TEST_APP_A));
+ Install.single(TestApp.A2).setEnableRollback().commit();
+ assertThat(InstallUtils.getInstalledVersion(TestApp.A)).isEqualTo(2);
// Check that the rollback data has not expired
Thread.sleep(1000);
RollbackInfo rollback = getUniqueRollbackInfoForPackage(
- rm.getAvailableRollbacks(), TEST_APP_A);
- assertRollbackInfoEquals(TEST_APP_A, 2, 1, rollback);
+ rm.getAvailableRollbacks(), TestApp.A);
+ assertThat(rollback).isNotNull();
+ assertThat(rollback).packagesContainsExactly(
+ Rollback.from(TestApp.A2).to(TestApp.A1));
// Give it a little more time, but still not the long enough to expire
Thread.sleep(expirationTime / 2);
rollback = getUniqueRollbackInfoForPackage(
- rm.getAvailableRollbacks(), TEST_APP_A);
- assertRollbackInfoEquals(TEST_APP_A, 2, 1, rollback);
+ rm.getAvailableRollbacks(), TestApp.A);
+ assertThat(rollback).isNotNull();
+ assertThat(rollback).packagesContainsExactly(
+ Rollback.from(TestApp.A2).to(TestApp.A1));
// Check that the data has expired after the expiration time (with a buffer of 1 second)
Thread.sleep(expirationTime / 2);
- assertNull(getUniqueRollbackInfoForPackage(rm.getAvailableRollbacks(), TEST_APP_A));
+ rollback = getUniqueRollbackInfoForPackage(
+ rm.getAvailableRollbacks(), TestApp.A);
+ assertThat(rollback).isNull();
} finally {
DeviceConfig.setProperty(DeviceConfig.NAMESPACE_ROLLBACK_BOOT,
RollbackManager.PROPERTY_ROLLBACK_LIFETIME_MILLIS,
Long.toString(defaultExpirationTime), false /* makeDefault*/);
- RollbackTestUtils.dropShellPermissionIdentity();
+ InstallUtils.dropShellPermissionIdentity();
}
}
@@ -385,10 +448,10 @@ public class RollbackTest {
public void testTimeChangeDoesNotAffectLifetime() throws Exception {
long expirationTime = TimeUnit.SECONDS.toMillis(30);
long defaultExpirationTime = TimeUnit.HOURS.toMillis(48);
- RollbackManager rm = RollbackTestUtils.getRollbackManager();
+ RollbackManager rm = RollbackUtils.getRollbackManager();
try {
- RollbackTestUtils.adoptShellPermissionIdentity(
+ InstallUtils.adoptShellPermissionIdentity(
Manifest.permission.INSTALL_PACKAGES,
Manifest.permission.DELETE_PACKAGES,
Manifest.permission.TEST_MANAGE_ROLLBACKS,
@@ -403,24 +466,25 @@ public class RollbackTest {
rm.reloadPersistedData();
// Install app A with rollback enabled
- RollbackTestUtils.uninstall(TEST_APP_A);
- RollbackTestUtils.install("RollbackTestAppAv1.apk", false);
- RollbackTestUtils.install("RollbackTestAppAv2.apk", true);
- assertEquals(2, RollbackTestUtils.getInstalledVersion(TEST_APP_A));
+ Uninstall.packages(TestApp.A);
+ Install.single(TestApp.A1).commit();
+ Install.single(TestApp.A2).setEnableRollback().commit();
+ assertThat(InstallUtils.getInstalledVersion(TestApp.A)).isEqualTo(2);
Thread.sleep(expirationTime / 2);
// Install app B with rollback enabled
- RollbackTestUtils.uninstall(TEST_APP_B);
- RollbackTestUtils.install("RollbackTestAppBv1.apk", false);
- RollbackTestUtils.install("RollbackTestAppBv2.apk", true);
- assertEquals(2, RollbackTestUtils.getInstalledVersion(TEST_APP_B));
+ Uninstall.packages(TestApp.B);
+ Install.single(TestApp.B1).commit();
+ Install.single(TestApp.B2).setEnableRollback().commit();
+ assertThat(InstallUtils.getInstalledVersion(TestApp.B)).isEqualTo(2);
+
// 1 second buffer
Thread.sleep(1000);
try {
// Change the time
- RollbackTestUtils.forwardTimeBy(expirationTime);
+ RollbackUtils.forwardTimeBy(expirationTime);
// 1 second buffer to allow Rollback Manager to handle time change before loading
// persisted data
@@ -432,24 +496,31 @@ public class RollbackTest {
// Wait until rollback for app A has expired
// This will trigger an expiration run that should expire app A but not B
Thread.sleep(expirationTime / 2);
- assertNull(getUniqueRollbackInfoForPackage(rm.getAvailableRollbacks(), TEST_APP_A));
+ RollbackInfo rollback =
+ getUniqueRollbackInfoForPackage(rm.getAvailableRollbacks(), TestApp.A);
+ assertThat(rollback).isNull();
// Rollback for app B should not be expired
- RollbackInfo rollback = getUniqueRollbackInfoForPackage(
- rm.getAvailableRollbacks(), TEST_APP_B);
- assertRollbackInfoEquals(TEST_APP_B, 2, 1, rollback);
+ rollback = getUniqueRollbackInfoForPackage(
+ rm.getAvailableRollbacks(), TestApp.B);
+ assertThat(rollback).isNotNull();
+ assertThat(rollback).packagesContainsExactly(
+ Rollback.from(TestApp.B2).to(TestApp.B1));
// Wait until rollback for app B has expired
Thread.sleep(expirationTime / 2);
- assertNull(getUniqueRollbackInfoForPackage(rm.getAvailableRollbacks(), TEST_APP_B));
+ rollback = getUniqueRollbackInfoForPackage(
+ rm.getAvailableRollbacks(), TestApp.B);
+ // Rollback should be expired by now
+ assertThat(rollback).isNull();
} finally {
- RollbackTestUtils.forwardTimeBy(-expirationTime);
+ RollbackUtils.forwardTimeBy(-expirationTime);
}
} finally {
DeviceConfig.setProperty(DeviceConfig.NAMESPACE_ROLLBACK_BOOT,
RollbackManager.PROPERTY_ROLLBACK_LIFETIME_MILLIS,
Long.toString(defaultExpirationTime), false /* makeDefault*/);
- RollbackTestUtils.dropShellPermissionIdentity();
+ InstallUtils.dropShellPermissionIdentity();
}
}
@@ -460,30 +531,32 @@ public class RollbackTest {
@Test
public void testRollbackExpiration() throws Exception {
try {
- RollbackTestUtils.adoptShellPermissionIdentity(
+ InstallUtils.adoptShellPermissionIdentity(
Manifest.permission.INSTALL_PACKAGES,
Manifest.permission.DELETE_PACKAGES,
Manifest.permission.TEST_MANAGE_ROLLBACKS);
- RollbackManager rm = RollbackTestUtils.getRollbackManager();
- RollbackTestUtils.uninstall(TEST_APP_A);
- RollbackTestUtils.install("RollbackTestAppAv1.apk", false);
- RollbackTestUtils.install("RollbackTestAppAv2.apk", true);
- assertEquals(2, RollbackTestUtils.getInstalledVersion(TEST_APP_A));
+ RollbackManager rm = RollbackUtils.getRollbackManager();
+ Uninstall.packages(TestApp.A);
+ Install.single(TestApp.A1).commit();
+ Install.single(TestApp.A2).setEnableRollback().commit();
+ assertThat(InstallUtils.getInstalledVersion(TestApp.A)).isEqualTo(2);
// The app should now be available for rollback.
RollbackInfo rollback = getUniqueRollbackInfoForPackage(
- rm.getAvailableRollbacks(), TEST_APP_A);
- assertRollbackInfoEquals(TEST_APP_A, 2, 1, rollback);
+ rm.getAvailableRollbacks(), TestApp.A);
+ assertThat(rollback).isNotNull();
+ assertThat(rollback).packagesContainsExactly(
+ Rollback.from(TestApp.A2).to(TestApp.A1));
// Expire the rollback.
- rm.expireRollbackForPackage(TEST_APP_A);
+ rm.expireRollbackForPackage(TestApp.A);
// The rollback should no longer be available.
- assertNull(getUniqueRollbackInfoForPackage(
- rm.getAvailableRollbacks(), TEST_APP_A));
+ assertThat(getUniqueRollbackInfoForPackage(
+ rm.getAvailableRollbacks(), TestApp.A)).isNull();
} finally {
- RollbackTestUtils.dropShellPermissionIdentity();
+ InstallUtils.dropShellPermissionIdentity();
}
}
@@ -493,24 +566,24 @@ public class RollbackTest {
@Test
public void testUserDataRollback() throws Exception {
try {
- RollbackTestUtils.adoptShellPermissionIdentity(
+ InstallUtils.adoptShellPermissionIdentity(
Manifest.permission.INSTALL_PACKAGES,
Manifest.permission.DELETE_PACKAGES,
Manifest.permission.TEST_MANAGE_ROLLBACKS);
- RollbackTestUtils.uninstall(TEST_APP_A);
- RollbackTestUtils.install("RollbackTestAppAv1.apk", false);
- processUserData(TEST_APP_A);
- RollbackTestUtils.install("RollbackTestAppAv2.apk", true);
- processUserData(TEST_APP_A);
+ Uninstall.packages(TestApp.A);
+ Install.single(TestApp.A1).commit();
+ processUserData(TestApp.A);
+ Install.single(TestApp.A2).setEnableRollback().commit();
+ processUserData(TestApp.A);
- RollbackManager rm = RollbackTestUtils.getRollbackManager();
+ RollbackManager rm = RollbackUtils.getRollbackManager();
RollbackInfo rollback = getUniqueRollbackInfoForPackage(
- rm.getAvailableRollbacks(), TEST_APP_A);
- RollbackTestUtils.rollback(rollback.getRollbackId());
- processUserData(TEST_APP_A);
+ rm.getAvailableRollbacks(), TestApp.A);
+ RollbackUtils.rollback(rollback.getRollbackId());
+ processUserData(TestApp.A);
} finally {
- RollbackTestUtils.dropShellPermissionIdentity();
+ InstallUtils.dropShellPermissionIdentity();
}
}
@@ -520,30 +593,26 @@ public class RollbackTest {
@Test
public void testRollbackWithSplits() throws Exception {
try {
- RollbackTestUtils.adoptShellPermissionIdentity(
+ InstallUtils.adoptShellPermissionIdentity(
Manifest.permission.INSTALL_PACKAGES,
Manifest.permission.DELETE_PACKAGES,
Manifest.permission.TEST_MANAGE_ROLLBACKS);
- RollbackTestUtils.uninstall(TEST_APP_A);
- RollbackTestUtils.installSplit(false,
- "RollbackTestAppASplitV1.apk",
- "RollbackTestAppASplitV1_anydpi.apk");
- processUserData(TEST_APP_A);
+ Uninstall.packages(TestApp.A);
+ Install.single(TestApp.ASplit1).commit();
+ processUserData(TestApp.A);
- RollbackTestUtils.installSplit(true,
- "RollbackTestAppASplitV2.apk",
- "RollbackTestAppASplitV2_anydpi.apk");
- processUserData(TEST_APP_A);
+ Install.single(TestApp.ASplit2).setEnableRollback().commit();
+ processUserData(TestApp.A);
- RollbackManager rm = RollbackTestUtils.getRollbackManager();
+ RollbackManager rm = RollbackUtils.getRollbackManager();
RollbackInfo rollback = getUniqueRollbackInfoForPackage(
- rm.getAvailableRollbacks(), TEST_APP_A);
- assertNotNull(rollback);
- RollbackTestUtils.rollback(rollback.getRollbackId());
- processUserData(TEST_APP_A);
+ rm.getAvailableRollbacks(), TestApp.A);
+ assertThat(rollback).isNotNull();
+ RollbackUtils.rollback(rollback.getRollbackId());
+ processUserData(TestApp.A);
} finally {
- RollbackTestUtils.dropShellPermissionIdentity();
+ InstallUtils.dropShellPermissionIdentity();
}
}
@@ -564,7 +633,7 @@ public class RollbackTest {
// Confirm that we really haven't received the broadcast.
// TODO: How long to wait for the expected timeout?
- assertNull(broadcastReceiver.poll(5, TimeUnit.SECONDS));
+ assertThat(broadcastReceiver.poll(5, TimeUnit.SECONDS)).isNull();
// TODO: Do we need to do this? Do we need to ensure this is always
// called, even when the test fails?
@@ -578,48 +647,52 @@ public class RollbackTest {
@Test
public void testMultipleRollbackAvailable() throws Exception {
try {
- RollbackTestUtils.adoptShellPermissionIdentity(
+ InstallUtils.adoptShellPermissionIdentity(
Manifest.permission.INSTALL_PACKAGES,
Manifest.permission.DELETE_PACKAGES,
Manifest.permission.TEST_MANAGE_ROLLBACKS);
- RollbackManager rm = RollbackTestUtils.getRollbackManager();
+ RollbackManager rm = RollbackUtils.getRollbackManager();
// Prep installation of the test apps.
- RollbackTestUtils.uninstall(TEST_APP_A);
- RollbackTestUtils.install("RollbackTestAppAv1.apk", false);
- RollbackTestUtils.install("RollbackTestAppAv2.apk", true);
- assertEquals(2, RollbackTestUtils.getInstalledVersion(TEST_APP_A));
+ Uninstall.packages(TestApp.A);
+ Install.single(TestApp.A1).commit();
+ Install.single(TestApp.A2).setEnableRollback().commit();
+ assertThat(InstallUtils.getInstalledVersion(TestApp.A)).isEqualTo(2);
- RollbackTestUtils.uninstall(TEST_APP_B);
- RollbackTestUtils.install("RollbackTestAppBv1.apk", false);
- RollbackTestUtils.install("RollbackTestAppBv2.apk", true);
- assertEquals(2, RollbackTestUtils.getInstalledVersion(TEST_APP_B));
+ Uninstall.packages(TestApp.B);
+ Install.single(TestApp.B1).commit();
+ Install.single(TestApp.B2).setEnableRollback().commit();
+ assertThat(InstallUtils.getInstalledVersion(TestApp.B)).isEqualTo(2);
// Both test apps should now be available for rollback, and the
// RollbackInfo returned for the rollbacks should be correct.
RollbackInfo rollbackA = getUniqueRollbackInfoForPackage(
- rm.getAvailableRollbacks(), TEST_APP_A);
- assertRollbackInfoEquals(TEST_APP_A, 2, 1, rollbackA);
+ rm.getAvailableRollbacks(), TestApp.A);
+ assertThat(rollbackA).isNotNull();
+ assertThat(rollbackA).packagesContainsExactly(
+ Rollback.from(TestApp.A2).to(TestApp.A1));
RollbackInfo rollbackB = getUniqueRollbackInfoForPackage(
- rm.getAvailableRollbacks(), TEST_APP_B);
- assertRollbackInfoEquals(TEST_APP_B, 2, 1, rollbackB);
+ rm.getAvailableRollbacks(), TestApp.B);
+ assertThat(rollbackB).isNotNull();
+ assertThat(rollbackB).packagesContainsExactly(
+ Rollback.from(TestApp.B2).to(TestApp.B1));
// Executing rollback should roll back the correct package.
- RollbackTestUtils.rollback(rollbackA.getRollbackId());
- assertEquals(1, RollbackTestUtils.getInstalledVersion(TEST_APP_A));
- assertEquals(2, RollbackTestUtils.getInstalledVersion(TEST_APP_B));
-
- RollbackTestUtils.uninstall(TEST_APP_A);
- RollbackTestUtils.install("RollbackTestAppAv1.apk", false);
- RollbackTestUtils.install("RollbackTestAppAv2.apk", true);
- assertEquals(2, RollbackTestUtils.getInstalledVersion(TEST_APP_A));
-
- RollbackTestUtils.rollback(rollbackB.getRollbackId());
- assertEquals(2, RollbackTestUtils.getInstalledVersion(TEST_APP_A));
- assertEquals(1, RollbackTestUtils.getInstalledVersion(TEST_APP_B));
+ RollbackUtils.rollback(rollbackA.getRollbackId());
+ assertThat(InstallUtils.getInstalledVersion(TestApp.A)).isEqualTo(1);
+ assertThat(InstallUtils.getInstalledVersion(TestApp.B)).isEqualTo(2);
+
+ Uninstall.packages(TestApp.A);
+ Install.single(TestApp.A1).commit();
+ Install.single(TestApp.A2).setEnableRollback().commit();
+ assertThat(InstallUtils.getInstalledVersion(TestApp.A)).isEqualTo(2);
+
+ RollbackUtils.rollback(rollbackB.getRollbackId());
+ assertThat(InstallUtils.getInstalledVersion(TestApp.A)).isEqualTo(2);
+ assertThat(InstallUtils.getInstalledVersion(TestApp.B)).isEqualTo(1);
} finally {
- RollbackTestUtils.dropShellPermissionIdentity();
+ InstallUtils.dropShellPermissionIdentity();
}
}
@@ -631,7 +704,7 @@ public class RollbackTest {
public void testManageRollbacksPermission() throws Exception {
// We shouldn't be allowed to call any of the RollbackManager APIs
// without the MANAGE_ROLLBACKS permission.
- RollbackManager rm = RollbackTestUtils.getRollbackManager();
+ RollbackManager rm = RollbackUtils.getRollbackManager();
try {
rm.getAvailableRollbacks();
@@ -664,7 +737,7 @@ public class RollbackTest {
}
try {
- rm.expireRollbackForPackage(TEST_APP_A);
+ rm.expireRollbackForPackage(TestApp.A);
fail("expected SecurityException");
} catch (SecurityException e) {
// Expected.
@@ -678,26 +751,27 @@ public class RollbackTest {
@Test
public void testEnableRollbackPermission() throws Exception {
try {
- RollbackTestUtils.adoptShellPermissionIdentity(
+ InstallUtils.adoptShellPermissionIdentity(
Manifest.permission.INSTALL_PACKAGES,
Manifest.permission.DELETE_PACKAGES);
- RollbackTestUtils.uninstall(TEST_APP_A);
- RollbackTestUtils.install("RollbackTestAppAv1.apk", /* enableRollback */ false);
- assertEquals(1, RollbackTestUtils.getInstalledVersion(TEST_APP_A));
+ Uninstall.packages(TestApp.A);
+ Install.single(TestApp.A1).commit();
+ assertThat(InstallUtils.getInstalledVersion(TestApp.A)).isEqualTo(1);
- RollbackTestUtils.install("RollbackTestAppAv2.apk", /* enableRollback */ true);
+ Install.single(TestApp.A2).setEnableRollback().commit();
// We expect v2 of the app was installed, but rollback has not
// been enabled.
- assertEquals(2, RollbackTestUtils.getInstalledVersion(TEST_APP_A));
+ assertThat(InstallUtils.getInstalledVersion(TestApp.A)).isEqualTo(2);
- RollbackTestUtils.adoptShellPermissionIdentity(
+ InstallUtils.adoptShellPermissionIdentity(
Manifest.permission.TEST_MANAGE_ROLLBACKS);
- RollbackManager rm = RollbackTestUtils.getRollbackManager();
- assertNull(getUniqueRollbackInfoForPackage(rm.getAvailableRollbacks(), TEST_APP_A));
+ RollbackManager rm = RollbackUtils.getRollbackManager();
+ assertThat(
+ getUniqueRollbackInfoForPackage(rm.getAvailableRollbacks(), TestApp.A)).isNull();
} finally {
- RollbackTestUtils.dropShellPermissionIdentity();
+ InstallUtils.dropShellPermissionIdentity();
}
}
@@ -708,25 +782,26 @@ public class RollbackTest {
@Test
public void testNonModuleEnableRollback() throws Exception {
try {
- RollbackTestUtils.adoptShellPermissionIdentity(
+ InstallUtils.adoptShellPermissionIdentity(
Manifest.permission.INSTALL_PACKAGES,
Manifest.permission.DELETE_PACKAGES,
Manifest.permission.MANAGE_ROLLBACKS);
- RollbackTestUtils.uninstall(TEST_APP_A);
- RollbackTestUtils.install("RollbackTestAppAv1.apk", /* enableRollback */ false);
- assertEquals(1, RollbackTestUtils.getInstalledVersion(TEST_APP_A));
+ Uninstall.packages(TestApp.A);
+ Install.single(TestApp.A1).commit();
+ assertThat(InstallUtils.getInstalledVersion(TestApp.A)).isEqualTo(1);
- RollbackTestUtils.install("RollbackTestAppAv2.apk", /* enableRollback */ true);
+ Install.single(TestApp.A2).setEnableRollback().commit();
// We expect v2 of the app was installed, but rollback has not
// been enabled because the test app is not a module.
- assertEquals(2, RollbackTestUtils.getInstalledVersion(TEST_APP_A));
+ assertThat(InstallUtils.getInstalledVersion(TestApp.A)).isEqualTo(2);
- RollbackManager rm = RollbackTestUtils.getRollbackManager();
- assertNull(getUniqueRollbackInfoForPackage(rm.getAvailableRollbacks(), TEST_APP_A));
+ RollbackManager rm = RollbackUtils.getRollbackManager();
+ assertThat(
+ getUniqueRollbackInfoForPackage(rm.getAvailableRollbacks(), TestApp.A)).isNull();
} finally {
- RollbackTestUtils.dropShellPermissionIdentity();
+ InstallUtils.dropShellPermissionIdentity();
}
}
@@ -736,54 +811,54 @@ public class RollbackTest {
@Test
public void testMultiPackage() throws Exception {
try {
- RollbackTestUtils.adoptShellPermissionIdentity(
+ InstallUtils.adoptShellPermissionIdentity(
Manifest.permission.INSTALL_PACKAGES,
Manifest.permission.DELETE_PACKAGES,
Manifest.permission.TEST_MANAGE_ROLLBACKS);
- RollbackManager rm = RollbackTestUtils.getRollbackManager();
+ RollbackManager rm = RollbackUtils.getRollbackManager();
// Prep installation of the test apps.
- RollbackTestUtils.uninstall(TEST_APP_A);
- RollbackTestUtils.uninstall(TEST_APP_B);
- RollbackTestUtils.installMultiPackage(false,
- "RollbackTestAppAv1.apk",
- "RollbackTestAppBv1.apk");
- processUserData(TEST_APP_A);
- processUserData(TEST_APP_B);
- RollbackTestUtils.installMultiPackage(true,
- "RollbackTestAppAv2.apk",
- "RollbackTestAppBv2.apk");
- processUserData(TEST_APP_A);
- processUserData(TEST_APP_B);
- assertEquals(2, RollbackTestUtils.getInstalledVersion(TEST_APP_A));
- assertEquals(2, RollbackTestUtils.getInstalledVersion(TEST_APP_B));
-
- // TEST_APP_A should now be available for rollback.
+ Uninstall.packages(TestApp.A, TestApp.B);
+ Install.multi(TestApp.A1, TestApp.B1).commit();
+ processUserData(TestApp.A);
+ processUserData(TestApp.B);
+ Install.multi(TestApp.A2, TestApp.B2).setEnableRollback().commit();
+ processUserData(TestApp.A);
+ processUserData(TestApp.B);
+ assertThat(InstallUtils.getInstalledVersion(TestApp.A)).isEqualTo(2);
+ assertThat(InstallUtils.getInstalledVersion(TestApp.B)).isEqualTo(2);
+
+ // TestApp.A should now be available for rollback.
RollbackInfo rollback = getUniqueRollbackInfoForPackage(
- rm.getAvailableRollbacks(), TEST_APP_A);
- assertRollbackInfoForAandB(rollback);
+ rm.getAvailableRollbacks(), TestApp.A);
+ assertThat(rollback).isNotNull();
+ assertThat(rollback).packagesContainsExactly(
+ Rollback.from(TestApp.A2).to(TestApp.A1),
+ Rollback.from(TestApp.B2).to(TestApp.B1));
// Rollback the app. It should cause both test apps to be rolled
// back.
- RollbackTestUtils.rollback(rollback.getRollbackId());
- assertEquals(1, RollbackTestUtils.getInstalledVersion(TEST_APP_A));
- assertEquals(1, RollbackTestUtils.getInstalledVersion(TEST_APP_B));
+ RollbackUtils.rollback(rollback.getRollbackId());
+ assertThat(InstallUtils.getInstalledVersion(TestApp.A)).isEqualTo(1);
+ assertThat(InstallUtils.getInstalledVersion(TestApp.B)).isEqualTo(1);
// We should see recent rollbacks listed for both A and B.
Thread.sleep(1000);
RollbackInfo rollbackA = getUniqueRollbackInfoForPackage(
- rm.getRecentlyCommittedRollbacks(), TEST_APP_A);
+ rm.getRecentlyCommittedRollbacks(), TestApp.A);
RollbackInfo rollbackB = getUniqueRollbackInfoForPackage(
- rm.getRecentlyCommittedRollbacks(), TEST_APP_B);
- assertRollbackInfoForAandB(rollbackB);
+ rm.getRecentlyCommittedRollbacks(), TestApp.B);
+ assertThat(rollback).packagesContainsExactly(
+ Rollback.from(TestApp.A2).to(TestApp.A1),
+ Rollback.from(TestApp.B2).to(TestApp.B1));
- assertEquals(rollbackA.getRollbackId(), rollbackB.getRollbackId());
+ assertThat(rollbackA).hasRollbackId(rollbackB.getRollbackId());
- processUserData(TEST_APP_A);
- processUserData(TEST_APP_B);
+ processUserData(TestApp.A);
+ processUserData(TestApp.B);
} finally {
- RollbackTestUtils.dropShellPermissionIdentity();
+ InstallUtils.dropShellPermissionIdentity();
}
}
@@ -795,31 +870,27 @@ public class RollbackTest {
@Test
public void testMultiPackageEnableFail() throws Exception {
try {
- RollbackTestUtils.adoptShellPermissionIdentity(
+ InstallUtils.adoptShellPermissionIdentity(
Manifest.permission.INSTALL_PACKAGES,
Manifest.permission.DELETE_PACKAGES,
Manifest.permission.TEST_MANAGE_ROLLBACKS);
- RollbackManager rm = RollbackTestUtils.getRollbackManager();
-
- RollbackTestUtils.uninstall(TEST_APP_A);
- RollbackTestUtils.uninstall(TEST_APP_B);
- RollbackTestUtils.install("RollbackTestAppAv1.apk", false);
+ RollbackManager rm = RollbackUtils.getRollbackManager();
+ Uninstall.packages(TestApp.A, TestApp.B);
+ Install.single(TestApp.A1).commit();
// We should fail to enable rollback here because TestApp B is not
// already installed.
- RollbackTestUtils.installMultiPackage(true,
- "RollbackTestAppAv2.apk",
- "RollbackTestAppBv2.apk");
+ Install.multi(TestApp.A2, TestApp.B2).setEnableRollback().commit();
- assertEquals(2, RollbackTestUtils.getInstalledVersion(TEST_APP_A));
- assertEquals(2, RollbackTestUtils.getInstalledVersion(TEST_APP_B));
+ assertThat(InstallUtils.getInstalledVersion(TestApp.A)).isEqualTo(2);
+ assertThat(InstallUtils.getInstalledVersion(TestApp.B)).isEqualTo(2);
- assertNull(getUniqueRollbackInfoForPackage(
- rm.getAvailableRollbacks(), TEST_APP_A));
- assertNull(getUniqueRollbackInfoForPackage(
- rm.getAvailableRollbacks(), TEST_APP_B));
+ assertThat(getUniqueRollbackInfoForPackage(
+ rm.getAvailableRollbacks(), TestApp.A)).isNull();
+ assertThat(getUniqueRollbackInfoForPackage(
+ rm.getAvailableRollbacks(), TestApp.B)).isNull();
} finally {
- RollbackTestUtils.dropShellPermissionIdentity();
+ InstallUtils.dropShellPermissionIdentity();
}
}
@@ -830,30 +901,33 @@ public class RollbackTest {
*/
public void testSameVersionUpdate() throws Exception {
try {
- RollbackTestUtils.adoptShellPermissionIdentity(
+ InstallUtils.adoptShellPermissionIdentity(
Manifest.permission.INSTALL_PACKAGES,
Manifest.permission.DELETE_PACKAGES,
Manifest.permission.TEST_MANAGE_ROLLBACKS);
- RollbackManager rm = RollbackTestUtils.getRollbackManager();
+ RollbackManager rm = RollbackUtils.getRollbackManager();
- RollbackTestUtils.uninstall(TEST_APP_A);
- RollbackTestUtils.install("RollbackTestAppAv1.apk", false);
- RollbackTestUtils.install("RollbackTestAppAv2.apk", true);
- RollbackTestUtils.install("RollbackTestAppACrashingV2.apk", true);
- assertEquals(2, RollbackTestUtils.getInstalledVersion(TEST_APP_A));
+ Uninstall.packages(TestApp.A);
+ Install.single(TestApp.A1).commit();
+ Install.single(TestApp.A2).setEnableRollback().commit();
+ Install.single(TestApp.ACrashing2).setEnableRollback().commit();
+ assertThat(InstallUtils.getInstalledVersion(TestApp.A)).isEqualTo(2);
RollbackInfo rollback = getUniqueRollbackInfoForPackage(
- rm.getAvailableRollbacks(), TEST_APP_A);
- assertRollbackInfoEquals(TEST_APP_A, 2, 2, rollback);
+ rm.getAvailableRollbacks(), TestApp.A);
+ assertThat(rollback).isNotNull();
+ assertThat(rollback).packagesContainsExactly(
+ Rollback.from(TestApp.A2).to(TestApp.A2));
- RollbackTestUtils.rollback(rollback.getRollbackId());
- assertEquals(2, RollbackTestUtils.getInstalledVersion(TEST_APP_A));
+ RollbackUtils.rollback(rollback.getRollbackId());
+ assertThat(InstallUtils.getInstalledVersion(TestApp.A)).isEqualTo(2);
rollback = getUniqueRollbackInfoForPackage(
- rm.getRecentlyCommittedRollbacks(), TEST_APP_A);
- assertRollbackInfoEquals(TEST_APP_A, 2, 2, rollback);
+ rm.getRecentlyCommittedRollbacks(), TestApp.A);
+ assertThat(rollback).packagesContainsExactly(
+ Rollback.from(TestApp.A2).to(TestApp.A2));
} finally {
- RollbackTestUtils.dropShellPermissionIdentity();
+ InstallUtils.dropShellPermissionIdentity();
}
}
@@ -865,54 +939,55 @@ public class RollbackTest {
BroadcastReceiver crashCountReceiver = null;
Context context = InstrumentationRegistry.getContext();
try {
- RollbackTestUtils.adoptShellPermissionIdentity(
+ InstallUtils.adoptShellPermissionIdentity(
Manifest.permission.INSTALL_PACKAGES,
Manifest.permission.DELETE_PACKAGES,
Manifest.permission.MANAGE_ROLLBACKS,
Manifest.permission.TEST_MANAGE_ROLLBACKS,
Manifest.permission.KILL_BACKGROUND_PROCESSES,
Manifest.permission.RESTART_PACKAGES);
- RollbackManager rm = RollbackTestUtils.getRollbackManager();
+ RollbackManager rm = RollbackUtils.getRollbackManager();
// Prep installation of the test apps.
- RollbackTestUtils.uninstall(TEST_APP_A);
- RollbackTestUtils.install("RollbackTestAppAv1.apk", false);
- RollbackTestUtils.install("RollbackTestAppACrashingV2.apk", true);
- assertEquals(2, RollbackTestUtils.getInstalledVersion(TEST_APP_A));
+ Uninstall.packages(TestApp.A, TestApp.B);
+ Install.single(TestApp.A1).commit();
+ Install.single(TestApp.ACrashing2).setEnableRollback().commit();
+ assertThat(InstallUtils.getInstalledVersion(TestApp.A)).isEqualTo(2);
- RollbackTestUtils.uninstall(TEST_APP_B);
- RollbackTestUtils.install("RollbackTestAppBv1.apk", false);
- RollbackTestUtils.install("RollbackTestAppBv2.apk", true);
- assertEquals(2, RollbackTestUtils.getInstalledVersion(TEST_APP_B));
+ Install.single(TestApp.B1).commit();
+ Install.single(TestApp.B2).setEnableRollback().commit();
+ assertThat(InstallUtils.getInstalledVersion(TestApp.B)).isEqualTo(2);
// Both test apps should now be available for rollback, and the
// targetPackage returned for rollback should be correct.
RollbackInfo rollbackA = getUniqueRollbackInfoForPackage(
- rm.getAvailableRollbacks(), TEST_APP_A);
- assertRollbackInfoEquals(TEST_APP_A, 2, 1, rollbackA);
+ rm.getAvailableRollbacks(), TestApp.A);
+ assertThat(rollbackA).packagesContainsExactly(
+ Rollback.from(TestApp.A2).to(TestApp.A1));
RollbackInfo rollbackB = getUniqueRollbackInfoForPackage(
- rm.getAvailableRollbacks(), TEST_APP_B);
- assertRollbackInfoEquals(TEST_APP_B, 2, 1, rollbackB);
+ rm.getAvailableRollbacks(), TestApp.B);
+ assertThat(rollbackB).packagesContainsExactly(
+ Rollback.from(TestApp.B2).to(TestApp.B1));
// Register rollback committed receiver
RollbackBroadcastReceiver rollbackReceiver = new RollbackBroadcastReceiver();
- // Crash TEST_APP_A PackageWatchdog#TRIGGER_FAILURE_COUNT times to trigger rollback
- crashCountReceiver = RollbackTestUtils.sendCrashBroadcast(context, TEST_APP_A, 5);
+ // Crash TestApp.A PackageWatchdog#TRIGGER_FAILURE_COUNT times to trigger rollback
+ crashCountReceiver = RollbackUtils.sendCrashBroadcast(context, TestApp.A, 5);
// Verify we received a broadcast for the rollback.
rollbackReceiver.take();
- // TEST_APP_A is automatically rolled back by the RollbackPackageHealthObserver
- assertEquals(1, RollbackTestUtils.getInstalledVersion(TEST_APP_A));
+ // TestApp.A is automatically rolled back by the RollbackPackageHealthObserver
+ assertThat(InstallUtils.getInstalledVersion(TestApp.A)).isEqualTo(1);
// Instrumented app is still the package installer
- String installer = context.getPackageManager().getInstallerPackageName(TEST_APP_A);
- assertEquals(INSTRUMENTED_APP, installer);
- // TEST_APP_B is untouched
- assertEquals(2, RollbackTestUtils.getInstalledVersion(TEST_APP_B));
+ String installer = context.getPackageManager().getInstallerPackageName(TestApp.A);
+ assertThat(installer).isEqualTo(INSTRUMENTED_APP);
+ // TestApp.B is untouched
+ assertThat(InstallUtils.getInstalledVersion(TestApp.B)).isEqualTo(2);
} finally {
- RollbackTestUtils.dropShellPermissionIdentity();
+ InstallUtils.dropShellPermissionIdentity();
if (crashCountReceiver != null) {
context.unregisterReceiver(crashCountReceiver);
}
@@ -925,31 +1000,32 @@ public class RollbackTest {
@Test
public void testRollForwardRace() throws Exception {
try {
- RollbackTestUtils.adoptShellPermissionIdentity(
+ InstallUtils.adoptShellPermissionIdentity(
Manifest.permission.INSTALL_PACKAGES,
Manifest.permission.DELETE_PACKAGES,
Manifest.permission.TEST_MANAGE_ROLLBACKS,
Manifest.permission.MANAGE_ROLLBACKS);
- RollbackManager rm = RollbackTestUtils.getRollbackManager();
+ RollbackManager rm = RollbackUtils.getRollbackManager();
- RollbackTestUtils.uninstall(TEST_APP_A);
- RollbackTestUtils.install("RollbackTestAppAv1.apk", false);
- RollbackTestUtils.install("RollbackTestAppAv2.apk", true);
- assertEquals(2, RollbackTestUtils.getInstalledVersion(TEST_APP_A));
+ Uninstall.packages(TestApp.A);
+ Install.single(TestApp.A1).commit();
+ Install.single(TestApp.A2).setEnableRollback().commit();
+ assertThat(InstallUtils.getInstalledVersion(TestApp.A)).isEqualTo(2);
RollbackInfo rollback = getUniqueRollbackInfoForPackage(
- rm.getAvailableRollbacks(), TEST_APP_A);
- assertRollbackInfoEquals(TEST_APP_A, 2, 1, rollback);
+ rm.getAvailableRollbacks(), TestApp.A);
+ assertThat(rollback).packagesContainsExactly(
+ Rollback.from(TestApp.A2).to(TestApp.A1));
// Install a new version of package A, then immediately rollback
// the previous version. We expect the rollback to fail, because
// it is no longer available.
// There are a couple different ways this could fail depending on
// thread interleaving, so don't ignore flaky failures.
- RollbackTestUtils.install("RollbackTestAppAv3.apk", false);
+ Install.single(TestApp.A3).commit();
try {
- RollbackTestUtils.rollback(rollback.getRollbackId());
+ RollbackUtils.rollback(rollback.getRollbackId());
// Note: Don't ignore flaky failures here.
fail("Expected rollback to fail, but it did not.");
} catch (AssertionError e) {
@@ -958,9 +1034,9 @@ public class RollbackTest {
}
// Note: Don't ignore flaky failures here.
- assertEquals(3, RollbackTestUtils.getInstalledVersion(TEST_APP_A));
+ assertThat(InstallUtils.getInstalledVersion(TestApp.A)).isEqualTo(3);
} finally {
- RollbackTestUtils.dropShellPermissionIdentity();
+ InstallUtils.dropShellPermissionIdentity();
}
}
@@ -968,7 +1044,7 @@ public class RollbackTest {
@Ignore("b/136605788")
public void testEnableRollbackTimeoutFailsRollback() throws Exception {
try {
- RollbackTestUtils.adoptShellPermissionIdentity(
+ InstallUtils.adoptShellPermissionIdentity(
Manifest.permission.INSTALL_PACKAGES,
Manifest.permission.DELETE_PACKAGES,
Manifest.permission.TEST_MANAGE_ROLLBACKS,
@@ -979,35 +1055,22 @@ public class RollbackTest {
DeviceConfig.setProperty(DeviceConfig.NAMESPACE_ROLLBACK,
PROPERTY_ENABLE_ROLLBACK_TIMEOUT_MILLIS,
Long.toString(0), false /* makeDefault*/);
- RollbackManager rm = RollbackTestUtils.getRollbackManager();
+ RollbackManager rm = RollbackUtils.getRollbackManager();
- RollbackTestUtils.uninstall(TEST_APP_A);
- RollbackTestUtils.install("RollbackTestAppAv1.apk", false);
- RollbackTestUtils.install("RollbackTestAppAv2.apk", true);
+ Uninstall.packages(TestApp.A);
+ Install.single(TestApp.A1).commit();
+ Install.single(TestApp.A2).setEnableRollback().commit();
- assertEquals(2, RollbackTestUtils.getInstalledVersion(TEST_APP_A));
+ assertThat(InstallUtils.getInstalledVersion(TestApp.A)).isEqualTo(2);
- assertNull(getUniqueRollbackInfoForPackage(rm.getAvailableRollbacks(), TEST_APP_A));
+ assertThat(
+ getUniqueRollbackInfoForPackage(rm.getAvailableRollbacks(), TestApp.A)).isNull();
} finally {
//setting the timeout back to default
DeviceConfig.setProperty(DeviceConfig.NAMESPACE_ROLLBACK,
PROPERTY_ENABLE_ROLLBACK_TIMEOUT_MILLIS,
null, false /* makeDefault*/);
- RollbackTestUtils.dropShellPermissionIdentity();
- }
- }
-
- // Helper function to test that the given rollback info is a rollback for
- // the atomic set {A2, B2} -> {A1, B1}.
- private void assertRollbackInfoForAandB(RollbackInfo rollback) {
- assertNotNull(rollback);
- assertEquals(2, rollback.getPackages().size());
- if (TEST_APP_A.equals(rollback.getPackages().get(0).getPackageName())) {
- assertPackageRollbackInfoEquals(TEST_APP_A, 2, 1, rollback.getPackages().get(0));
- assertPackageRollbackInfoEquals(TEST_APP_B, 2, 1, rollback.getPackages().get(1));
- } else {
- assertPackageRollbackInfoEquals(TEST_APP_B, 2, 1, rollback.getPackages().get(0));
- assertPackageRollbackInfoEquals(TEST_APP_A, 2, 1, rollback.getPackages().get(1));
+ InstallUtils.dropShellPermissionIdentity();
}
}
}
diff --git a/tests/RollbackTest/RollbackTest/src/com/android/tests/rollback/RollbackTestUtils.java b/tests/RollbackTest/RollbackTest/src/com/android/tests/rollback/RollbackTestUtils.java
deleted file mode 100644
index a9e20cdb191b..000000000000
--- a/tests/RollbackTest/RollbackTest/src/com/android/tests/rollback/RollbackTestUtils.java
+++ /dev/null
@@ -1,547 +0,0 @@
-/*
- * Copyright (C) 2018 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.tests.rollback;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.fail;
-
-import android.app.ActivityManager;
-import android.app.AlarmManager;
-import android.content.BroadcastReceiver;
-import android.content.ComponentName;
-import android.content.Context;
-import android.content.Intent;
-import android.content.IntentFilter;
-import android.content.pm.ApplicationInfo;
-import android.content.pm.PackageInfo;
-import android.content.pm.PackageInstaller;
-import android.content.pm.PackageManager;
-import android.content.pm.VersionedPackage;
-import android.content.rollback.PackageRollbackInfo;
-import android.content.rollback.RollbackInfo;
-import android.content.rollback.RollbackManager;
-import android.os.Handler;
-import android.os.HandlerThread;
-import android.util.Log;
-
-import androidx.test.InstrumentationRegistry;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.util.Arrays;
-import java.util.List;
-import java.util.concurrent.BlockingQueue;
-import java.util.concurrent.LinkedBlockingQueue;
-import java.util.concurrent.SynchronousQueue;
-
-/**
- * Utilities to facilitate testing rollbacks.
- */
-class RollbackTestUtils {
-
- private static final String TAG = "RollbackTest";
-
- static RollbackManager getRollbackManager() {
- Context context = InstrumentationRegistry.getContext();
- RollbackManager rm = (RollbackManager) context.getSystemService(Context.ROLLBACK_SERVICE);
- if (rm == null) {
- throw new AssertionError("Failed to get RollbackManager");
- }
- return rm;
- }
-
- private static void setTime(long millis) {
- Context context = InstrumentationRegistry.getContext();
- AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
- am.setTime(millis);
- }
-
- static void forwardTimeBy(long offsetMillis) {
- setTime(System.currentTimeMillis() + offsetMillis);
- Log.i(TAG, "Forwarded time on device by " + offsetMillis + " millis");
- }
-
- /**
- * Returns the version of the given package installed on device.
- * Returns -1 if the package is not currently installed.
- */
- static long getInstalledVersion(String packageName) {
- PackageInfo pi = getPackageInfo(packageName);
- if (pi == null) {
- return -1;
- } else {
- return pi.getLongVersionCode();
- }
- }
-
- private static boolean isSystemAppWithoutUpdate(String packageName) {
- PackageInfo pi = getPackageInfo(packageName);
- if (pi == null) {
- return false;
- } else {
- return ((pi.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0)
- && ((pi.applicationInfo.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) == 0);
- }
- }
-
- private static PackageInfo getPackageInfo(String packageName) {
- Context context = InstrumentationRegistry.getContext();
- PackageManager pm = context.getPackageManager();
- try {
- return pm.getPackageInfo(packageName, PackageManager.MATCH_APEX);
- } catch (PackageManager.NameNotFoundException e) {
- return null;
- }
- }
-
- private static void assertStatusSuccess(Intent result) {
- int status = result.getIntExtra(PackageInstaller.EXTRA_STATUS,
- PackageInstaller.STATUS_FAILURE);
- if (status == -1) {
- throw new AssertionError("PENDING USER ACTION");
- } else if (status > 0) {
- String message = result.getStringExtra(PackageInstaller.EXTRA_STATUS_MESSAGE);
- throw new AssertionError(message == null ? "UNKNOWN FAILURE" : message);
- }
- }
-
- /**
- * Uninstalls the given package.
- * Does nothing if the package is not installed.
- * @throws AssertionError if package can't be uninstalled.
- */
- static void uninstall(String packageName) throws InterruptedException, IOException {
- // No need to uninstall if the package isn't installed or is installed on /system.
- if (getInstalledVersion(packageName) == -1 || isSystemAppWithoutUpdate(packageName)) {
- return;
- }
-
- Context context = InstrumentationRegistry.getContext();
- PackageManager packageManager = context.getPackageManager();
- PackageInstaller packageInstaller = packageManager.getPackageInstaller();
- packageInstaller.uninstall(packageName, LocalIntentSender.getIntentSender());
- assertStatusSuccess(LocalIntentSender.getIntentSenderResult());
- }
-
- /**
- * Commit the given rollback.
- * @throws AssertionError if the rollback fails.
- */
- static void rollback(int rollbackId, VersionedPackage... causePackages)
- throws InterruptedException {
- RollbackManager rm = getRollbackManager();
- rm.commitRollback(rollbackId, Arrays.asList(causePackages),
- LocalIntentSender.getIntentSender());
- Intent result = LocalIntentSender.getIntentSenderResult();
- int status = result.getIntExtra(RollbackManager.EXTRA_STATUS,
- RollbackManager.STATUS_FAILURE);
- if (status != RollbackManager.STATUS_SUCCESS) {
- String message = result.getStringExtra(RollbackManager.EXTRA_STATUS_MESSAGE);
- throw new AssertionError(message);
- }
- }
-
- /**
- * Installs the apk with the given name.
- *
- * @param resourceName name of class loader resource for the apk to
- * install.
- * @param enableRollback if rollback should be enabled.
- * @throws AssertionError if the installation fails.
- */
- static void install(String resourceName, boolean enableRollback)
- throws InterruptedException, IOException {
- installSplit(enableRollback, resourceName);
- }
-
- /**
- * Installs the apk with the given name and its splits.
- *
- * @param enableRollback if rollback should be enabled.
- * @param resourceNames names of class loader resources for the apk and
- * its splits to install.
- * @throws AssertionError if the installation fails.
- */
- static void installSplit(boolean enableRollback, String... resourceNames)
- throws InterruptedException, IOException {
- Context context = InstrumentationRegistry.getContext();
- PackageInstaller.Session session = null;
- PackageInstaller packageInstaller = context.getPackageManager().getPackageInstaller();
- PackageInstaller.SessionParams params = new PackageInstaller.SessionParams(
- PackageInstaller.SessionParams.MODE_FULL_INSTALL);
- params.setEnableRollback(enableRollback);
- int sessionId = packageInstaller.createSession(params);
- session = packageInstaller.openSession(sessionId);
-
- ClassLoader loader = RollbackTest.class.getClassLoader();
- for (String resourceName : resourceNames) {
- try (OutputStream packageInSession = session.openWrite(resourceName, 0, -1);
- InputStream is = loader.getResourceAsStream(resourceName);) {
- byte[] buffer = new byte[4096];
- int n;
- while ((n = is.read(buffer)) >= 0) {
- packageInSession.write(buffer, 0, n);
- }
- }
- }
-
- // Commit the session (this will start the installation workflow).
- session.commit(LocalIntentSender.getIntentSender());
- assertStatusSuccess(LocalIntentSender.getIntentSenderResult());
- }
-
- /** Launches {@code packageName} with {@link Intent#ACTION_MAIN}. */
- private static void launchPackage(String packageName)
- throws InterruptedException, IOException {
- Context context = InstrumentationRegistry.getContext();
- Intent intent = new Intent(Intent.ACTION_MAIN);
- intent.setPackage(packageName);
- intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- intent.addCategory(Intent.CATEGORY_LAUNCHER);
- context.startActivity(intent);
- }
-
- /**
- * Installs the APKs or APEXs with the given resource names as an atomic
- * set. A resource is assumed to be an APEX if it has the .apex extension.
- * <p>
- * In case of staged installs, this function will return succesfully after
- * the staged install has been committed and is ready for the device to
- * reboot.
- *
- * @param staged if the rollback should be staged.
- * @param enableRollback if rollback should be enabled.
- * @param resourceNames names of the class loader resource for the apks to
- * install.
- * @throws AssertionError if the installation fails.
- */
- private static void install(boolean staged, boolean enableRollback,
- String... resourceNames) throws InterruptedException, IOException {
- Context context = InstrumentationRegistry.getContext();
- PackageInstaller packageInstaller = context.getPackageManager().getPackageInstaller();
-
- PackageInstaller.SessionParams multiPackageParams = new PackageInstaller.SessionParams(
- PackageInstaller.SessionParams.MODE_FULL_INSTALL);
- multiPackageParams.setMultiPackage();
- if (staged) {
- multiPackageParams.setStaged();
- }
- // TODO: Do we set this on the parent params, the child params, or
- // both?
- multiPackageParams.setEnableRollback(enableRollback);
- int multiPackageId = packageInstaller.createSession(multiPackageParams);
- PackageInstaller.Session multiPackage = packageInstaller.openSession(multiPackageId);
-
- for (String resourceName : resourceNames) {
- PackageInstaller.Session session = null;
- PackageInstaller.SessionParams params = new PackageInstaller.SessionParams(
- PackageInstaller.SessionParams.MODE_FULL_INSTALL);
- if (staged) {
- params.setStaged();
- }
- if (resourceName.endsWith(".apex")) {
- params.setInstallAsApex();
- }
- params.setEnableRollback(enableRollback);
- int sessionId = packageInstaller.createSession(params);
- session = packageInstaller.openSession(sessionId);
-
- ClassLoader loader = RollbackTest.class.getClassLoader();
- try (OutputStream packageInSession = session.openWrite(resourceName, 0, -1);
- InputStream is = loader.getResourceAsStream(resourceName);) {
- byte[] buffer = new byte[4096];
- int n;
- while ((n = is.read(buffer)) >= 0) {
- packageInSession.write(buffer, 0, n);
- }
- }
- multiPackage.addChildSessionId(sessionId);
- }
-
- // Commit the session (this will start the installation workflow).
- multiPackage.commit(LocalIntentSender.getIntentSender());
- assertStatusSuccess(LocalIntentSender.getIntentSenderResult());
-
- if (staged) {
- waitForSessionReady(multiPackageId);
- }
- }
-
- /**
- * Installs the apks with the given resource names as an atomic set.
- *
- * @param enableRollback if rollback should be enabled.
- * @param resourceNames names of the class loader resource for the apks to
- * install.
- * @throws AssertionError if the installation fails.
- */
- static void installMultiPackage(boolean enableRollback, String... resourceNames)
- throws InterruptedException, IOException {
- install(false, enableRollback, resourceNames);
- }
-
- /**
- * Installs the APKs or APEXs with the given resource names as a staged
- * atomic set. A resource is assumed to be an APEX if it has the .apex
- * extension.
- *
- * @param enableRollback if rollback should be enabled.
- * @param resourceNames names of the class loader resource for the apks to
- * install.
- * @throws AssertionError if the installation fails.
- */
- static void installStaged(boolean enableRollback, String... resourceNames)
- throws InterruptedException, IOException {
- install(true, enableRollback, resourceNames);
- }
-
- static void adoptShellPermissionIdentity(String... permissions) {
- InstrumentationRegistry
- .getInstrumentation()
- .getUiAutomation()
- .adoptShellPermissionIdentity(permissions);
- }
-
- static void dropShellPermissionIdentity() {
- InstrumentationRegistry
- .getInstrumentation()
- .getUiAutomation()
- .dropShellPermissionIdentity();
- }
-
- /**
- * Returns the RollbackInfo with a given package in the list of rollbacks.
- * Throws an assertion failure if there is more than one such rollback
- * info. Returns null if there are no such rollback infos.
- */
- static RollbackInfo getUniqueRollbackInfoForPackage(List<RollbackInfo> rollbacks,
- String packageName) {
- RollbackInfo found = null;
- for (RollbackInfo rollback : rollbacks) {
- for (PackageRollbackInfo info : rollback.getPackages()) {
- if (packageName.equals(info.getPackageName())) {
- assertNull(found);
- found = rollback;
- break;
- }
- }
- }
- return found;
- }
-
- /**
- * Asserts that the given PackageRollbackInfo has the expected package
- * name and versions.
- */
- static void assertPackageRollbackInfoEquals(String packageName,
- long versionRolledBackFrom, long versionRolledBackTo,
- PackageRollbackInfo info) {
- assertEquals(packageName, info.getPackageName());
- assertEquals(packageName, info.getVersionRolledBackFrom().getPackageName());
- assertEquals(versionRolledBackFrom, info.getVersionRolledBackFrom().getLongVersionCode());
- assertEquals(packageName, info.getVersionRolledBackTo().getPackageName());
- assertEquals(versionRolledBackTo, info.getVersionRolledBackTo().getLongVersionCode());
- }
-
- /**
- * 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[] packageNames,
- long versionRolledBackFrom, long versionRolledBackTo,
- RollbackInfo info, VersionedPackage... causePackages) {
- assertNotNull(info);
- 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(),
- info.getCausePackages().get(i).getPackageName());
- assertEquals(causePackages[i].getLongVersionCode(),
- info.getCausePackages().get(i).getLongVersionCode());
- }
- }
-
- /**
- * 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.
- */
- static void waitForSessionReady(int sessionId) {
- BlockingQueue<PackageInstaller.SessionInfo> sessionStatus = new LinkedBlockingQueue<>();
- BroadcastReceiver sessionUpdatedReceiver = new BroadcastReceiver() {
- @Override
- public void onReceive(Context context, Intent intent) {
- PackageInstaller.SessionInfo info =
- intent.getParcelableExtra(PackageInstaller.EXTRA_SESSION);
- if (info != null && info.getSessionId() == sessionId) {
- if (info.isStagedSessionReady() || info.isStagedSessionFailed()) {
- try {
- sessionStatus.put(info);
- } catch (InterruptedException e) {
- Log.e(TAG, "Failed to put session info.", e);
- }
- }
- }
- }
- };
- IntentFilter sessionUpdatedFilter =
- new IntentFilter(PackageInstaller.ACTION_SESSION_UPDATED);
-
- Context context = InstrumentationRegistry.getContext();
- context.registerReceiver(sessionUpdatedReceiver, sessionUpdatedFilter);
-
- PackageInstaller installer = context.getPackageManager().getPackageInstaller();
- PackageInstaller.SessionInfo info = installer.getSessionInfo(sessionId);
-
- try {
- if (info.isStagedSessionReady() || info.isStagedSessionFailed()) {
- sessionStatus.put(info);
- }
-
- info = sessionStatus.take();
- context.unregisterReceiver(sessionUpdatedReceiver);
- if (info.isStagedSessionFailed()) {
- throw new AssertionError(info.getStagedSessionErrorMessage());
- }
- } catch (InterruptedException e) {
- throw new AssertionError(e);
- }
- }
-
- private static final String NO_RESPONSE = "NO RESPONSE";
-
- /**
- * Calls into the test app to process user data.
- * Asserts if the user data could not be processed or was version
- * incompatible with the previously processed user data.
- */
- static void processUserData(String packageName) {
- Intent intent = new Intent();
- intent.setComponent(new ComponentName(packageName,
- "com.android.tests.rollback.testapp.ProcessUserData"));
- Context context = InstrumentationRegistry.getContext();
-
- HandlerThread handlerThread = new HandlerThread("RollbackTestHandlerThread");
- handlerThread.start();
-
- // It can sometimes take a while after rollback before the app will
- // receive this broadcast, so try a few times in a loop.
- String result = NO_RESPONSE;
- for (int i = 0; result.equals(NO_RESPONSE) && i < 5; ++i) {
- BlockingQueue<String> resultQueue = new LinkedBlockingQueue<>();
- context.sendOrderedBroadcast(intent, null, new BroadcastReceiver() {
- @Override
- public void onReceive(Context context, Intent intent) {
- if (getResultCode() == 1) {
- resultQueue.add("OK");
- } else {
- // If the test app doesn't receive the broadcast or
- // fails to set the result data, then getResultData
- // here returns the initial NO_RESPONSE data passed to
- // the sendOrderedBroadcast call.
- resultQueue.add(getResultData());
- }
- }
- }, new Handler(handlerThread.getLooper()), 0, NO_RESPONSE, null);
-
- try {
- result = resultQueue.take();
- } catch (InterruptedException e) {
- throw new AssertionError(e);
- }
- }
-
- handlerThread.quit();
- if (!"OK".equals(result)) {
- 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;
- }
-
- /**
- * Send broadcast to crash {@code packageName} {@code count} times. If {@code count} is at least
- * {@link PackageWatchdog#TRIGGER_FAILURE_COUNT}, watchdog crash detection will be triggered.
- */
- static BroadcastReceiver sendCrashBroadcast(Context context, String packageName, int count)
- throws InterruptedException, IOException {
- BlockingQueue<Integer> crashQueue = new SynchronousQueue<>();
- IntentFilter crashCountFilter = new IntentFilter();
- crashCountFilter.addAction("com.android.tests.rollback.CRASH");
- crashCountFilter.addCategory(Intent.CATEGORY_DEFAULT);
-
- BroadcastReceiver crashCountReceiver = new BroadcastReceiver() {
- @Override
- public void onReceive(Context context, Intent intent) {
- try {
- // Sleep long enough for packagewatchdog to be notified of crash
- Thread.sleep(1000);
- // Kill app and close AppErrorDialog
- ActivityManager am = context.getSystemService(ActivityManager.class);
- am.killBackgroundProcesses(packageName);
- // Allow another package launch
- crashQueue.put(intent.getIntExtra("count", 0));
- } catch (InterruptedException e) {
- fail("Failed to communicate with test app");
- }
- }
- };
- context.registerReceiver(crashCountReceiver, crashCountFilter);
-
- do {
- launchPackage(packageName);
- } while(crashQueue.take() < count);
- return crashCountReceiver;
- }
-}
diff --git a/tests/RollbackTest/RollbackTest/src/com/android/tests/rollback/StagedRollbackTest.java b/tests/RollbackTest/RollbackTest/src/com/android/tests/rollback/StagedRollbackTest.java
index 1a29c4c11457..a67bf3ca0b5d 100644
--- a/tests/RollbackTest/RollbackTest/src/com/android/tests/rollback/StagedRollbackTest.java
+++ b/tests/RollbackTest/RollbackTest/src/com/android/tests/rollback/StagedRollbackTest.java
@@ -16,25 +16,28 @@
package com.android.tests.rollback;
-import static com.android.tests.rollback.RollbackTestUtils.assertRollbackInfoEquals;
-import static com.android.tests.rollback.RollbackTestUtils.getUniqueRollbackInfoForPackage;
+import static com.android.cts.rollback.lib.RollbackInfoSubject.assertThat;
+import static com.android.cts.rollback.lib.RollbackUtils.getUniqueRollbackInfoForPackage;
+
+import static com.google.common.truth.Truth.assertThat;
import android.Manifest;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
-import android.content.pm.VersionedPackage;
import android.content.rollback.RollbackInfo;
import android.content.rollback.RollbackManager;
import androidx.test.InstrumentationRegistry;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
+import com.android.cts.install.lib.Install;
+import com.android.cts.install.lib.InstallUtils;
+import com.android.cts.install.lib.TestApp;
+import com.android.cts.install.lib.Uninstall;
+import com.android.cts.rollback.lib.Rollback;
+import com.android.cts.rollback.lib.RollbackUtils;
+
import static org.junit.Assert.fail;
import org.junit.After;
@@ -55,9 +58,6 @@ import org.junit.runners.JUnit4;
public class StagedRollbackTest {
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_CRASHING_V2 = "RollbackTestAppACrashingV2.apk";
private static final String NETWORK_STACK_CONNECTOR_CLASS =
"android.net.INetworkStackConnector";
@@ -66,7 +66,7 @@ public class StagedRollbackTest {
*/
@Before
public void adoptShellPermissions() {
- RollbackTestUtils.adoptShellPermissionIdentity(
+ InstallUtils.adoptShellPermissionIdentity(
Manifest.permission.INSTALL_PACKAGES,
Manifest.permission.DELETE_PACKAGES,
Manifest.permission.TEST_MANAGE_ROLLBACKS,
@@ -78,7 +78,7 @@ public class StagedRollbackTest {
*/
@After
public void dropShellPermissions() {
- RollbackTestUtils.dropShellPermissionIdentity();
+ InstallUtils.dropShellPermissionIdentity();
}
/**
@@ -87,14 +87,14 @@ public class StagedRollbackTest {
*/
@Test
public void testBadApkOnlyEnableRollback() throws Exception {
- RollbackTestUtils.uninstall(TEST_APP_A);
- assertEquals(-1, RollbackTestUtils.getInstalledVersion(TEST_APP_A));
+ Uninstall.packages(TestApp.A);
+ assertThat(InstallUtils.getInstalledVersion(TestApp.A)).isEqualTo(-1);
- RollbackTestUtils.install(TEST_APP_A_V1, false);
- assertEquals(1, RollbackTestUtils.getInstalledVersion(TEST_APP_A));
- RollbackTestUtils.processUserData(TEST_APP_A);
+ Install.single(TestApp.A1).commit();
+ assertThat(InstallUtils.getInstalledVersion(TestApp.A)).isEqualTo(1);
+ InstallUtils.processUserData(TestApp.A);
- RollbackTestUtils.installStaged(true, TEST_APP_A_CRASHING_V2);
+ Install.single(TestApp.ACrashing2).setEnableRollback().setStaged().commit();
// At this point, the host test driver will reboot the device and run
// testBadApkOnlyConfirmEnableRollback().
@@ -106,14 +106,16 @@ public class StagedRollbackTest {
*/
@Test
public void testBadApkOnlyConfirmEnableRollback() throws Exception {
- assertEquals(2, RollbackTestUtils.getInstalledVersion(TEST_APP_A));
- RollbackTestUtils.processUserData(TEST_APP_A);
+ assertThat(InstallUtils.getInstalledVersion(TestApp.A)).isEqualTo(2);
+ InstallUtils.processUserData(TestApp.A);
- RollbackManager rm = RollbackTestUtils.getRollbackManager();
+ RollbackManager rm = RollbackUtils.getRollbackManager();
RollbackInfo rollback = getUniqueRollbackInfoForPackage(
- rm.getAvailableRollbacks(), TEST_APP_A);
- assertRollbackInfoEquals(TEST_APP_A, 2, 1, rollback);
- assertTrue(rollback.isStaged());
+ rm.getAvailableRollbacks(), TestApp.A);
+ assertThat(rollback).isNotNull();
+ assertThat(rollback).packagesContainsExactly(
+ Rollback.from(TestApp.A2).to(TestApp.A1));
+ assertThat(rollback.isStaged()).isTrue();
// At this point, the host test driver will run
// testBadApkOnlyTriggerRollback().
@@ -128,11 +130,10 @@ public class StagedRollbackTest {
public void testBadApkOnlyTriggerRollback() throws Exception {
BroadcastReceiver crashCountReceiver = null;
Context context = InstrumentationRegistry.getContext();
- RollbackManager rm = RollbackTestUtils.getRollbackManager();
try {
- // Crash TEST_APP_A PackageWatchdog#TRIGGER_FAILURE_COUNT times to trigger rollback
- crashCountReceiver = RollbackTestUtils.sendCrashBroadcast(context, TEST_APP_A, 5);
+ // 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);
@@ -153,48 +154,51 @@ public class StagedRollbackTest {
*/
@Test
public void testBadApkOnlyConfirmRollback() throws Exception {
- assertEquals(1, RollbackTestUtils.getInstalledVersion(TEST_APP_A));
- RollbackTestUtils.processUserData(TEST_APP_A);
+ assertThat(InstallUtils.getInstalledVersion(TestApp.A)).isEqualTo(1);
+ InstallUtils.processUserData(TestApp.A);
- RollbackManager rm = RollbackTestUtils.getRollbackManager();
+ RollbackManager rm = RollbackUtils.getRollbackManager();
RollbackInfo rollback = getUniqueRollbackInfoForPackage(
- rm.getRecentlyCommittedRollbacks(), TEST_APP_A);
- assertRollbackInfoEquals(TEST_APP_A, 2, 1, rollback, new VersionedPackage(TEST_APP_A, 2));
- assertTrue(rollback.isStaged());
- assertNotEquals(-1, rollback.getCommittedSessionId());
+ rm.getRecentlyCommittedRollbacks(), TestApp.A);
+ assertThat(rollback).isNotNull();
+ assertThat(rollback).packagesContainsExactly(
+ Rollback.from(TestApp.A2).to(TestApp.A1));
+ assertThat(rollback).causePackagesContainsExactly(TestApp.ACrashing2);
+ assertThat(rollback).isStaged();
+ assertThat(rollback.getCommittedSessionId()).isNotEqualTo(-1);
}
@Test
public void resetNetworkStack() throws Exception {
- RollbackManager rm = RollbackTestUtils.getRollbackManager();
+ RollbackManager rm = RollbackUtils.getRollbackManager();
String networkStack = getNetworkStackPackageName();
rm.expireRollbackForPackage(networkStack);
- RollbackTestUtils.uninstall(networkStack);
+ Uninstall.packages(networkStack);
- assertNull(getUniqueRollbackInfoForPackage(rm.getAvailableRollbacks(),
- networkStack));
+ assertThat(getUniqueRollbackInfoForPackage(rm.getAvailableRollbacks(),
+ networkStack)).isNull();
}
@Test
public void assertNetworkStackRollbackAvailable() throws Exception {
- RollbackManager rm = RollbackTestUtils.getRollbackManager();
- assertNotNull(getUniqueRollbackInfoForPackage(rm.getAvailableRollbacks(),
- getNetworkStackPackageName()));
+ RollbackManager rm = RollbackUtils.getRollbackManager();
+ assertThat(getUniqueRollbackInfoForPackage(rm.getAvailableRollbacks(),
+ getNetworkStackPackageName())).isNotNull();
}
@Test
public void assertNetworkStackRollbackCommitted() throws Exception {
- RollbackManager rm = RollbackTestUtils.getRollbackManager();
- assertNotNull(getUniqueRollbackInfoForPackage(rm.getRecentlyCommittedRollbacks(),
- getNetworkStackPackageName()));
+ RollbackManager rm = RollbackUtils.getRollbackManager();
+ assertThat(getUniqueRollbackInfoForPackage(rm.getRecentlyCommittedRollbacks(),
+ getNetworkStackPackageName())).isNotNull();
}
@Test
public void assertNoNetworkStackRollbackCommitted() throws Exception {
- RollbackManager rm = RollbackTestUtils.getRollbackManager();
- assertNull(getUniqueRollbackInfoForPackage(rm.getRecentlyCommittedRollbacks(),
- getNetworkStackPackageName()));
+ RollbackManager rm = RollbackUtils.getRollbackManager();
+ assertThat(getUniqueRollbackInfoForPackage(rm.getRecentlyCommittedRollbacks(),
+ getNetworkStackPackageName())).isNull();
}
private String getNetworkStackPackageName() {
diff --git a/tests/RollbackTest/TestApp/ACrashingV2.xml b/tests/RollbackTest/TestApp/ACrashingV2.xml
deleted file mode 100644
index 77bfd4e0f9a0..000000000000
--- a/tests/RollbackTest/TestApp/ACrashingV2.xml
+++ /dev/null
@@ -1,36 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2019 The Android Open Source Project
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
--->
-
-<manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="com.android.tests.rollback.testapp.A"
- android:versionCode="2"
- android:versionName="2.0" >
-
-
- <uses-sdk android:minSdkVersion="19" />
-
- <application android:label="Rollback Test App A v2">
- <receiver android:name="com.android.tests.rollback.testapp.ProcessUserData"
- android:exported="true" />
- <activity android:name="com.android.tests.rollback.testapp.CrashingMainActivity">
- <intent-filter>
- <action android:name="android.intent.action.MAIN" />
- <category android:name="android.intent.category.DEFAULT"/>
- <category android:name="android.intent.category.LAUNCHER" />
- </intent-filter>
- </activity>
- </application>
-</manifest>
diff --git a/tests/RollbackTest/TestApp/Av1.xml b/tests/RollbackTest/TestApp/Av1.xml
deleted file mode 100644
index 63729fbaaf28..000000000000
--- a/tests/RollbackTest/TestApp/Av1.xml
+++ /dev/null
@@ -1,35 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2018 The Android Open Source Project
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
--->
-
-<manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="com.android.tests.rollback.testapp.A"
- android:versionCode="1"
- android:versionName="1.0" >
-
-
- <uses-sdk android:minSdkVersion="19" />
-
- <application android:label="Rollback Test App A v1">
- <receiver android:name="com.android.tests.rollback.testapp.ProcessUserData"
- android:exported="true" />
- <activity android:name="com.android.tests.rollback.testapp.MainActivity">
- <intent-filter>
- <action android:name="android.intent.action.MAIN" />
- <category android:name="android.intent.category.LAUNCHER" />
- </intent-filter>
- </activity>
- </application>
-</manifest>
diff --git a/tests/RollbackTest/TestApp/Av2.xml b/tests/RollbackTest/TestApp/Av2.xml
deleted file mode 100644
index f0e909feabf3..000000000000
--- a/tests/RollbackTest/TestApp/Av2.xml
+++ /dev/null
@@ -1,35 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2018 The Android Open Source Project
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
--->
-
-<manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="com.android.tests.rollback.testapp.A"
- android:versionCode="2"
- android:versionName="2.0" >
-
-
- <uses-sdk android:minSdkVersion="19" />
-
- <application android:label="Rollback Test App A v2">
- <receiver android:name="com.android.tests.rollback.testapp.ProcessUserData"
- android:exported="true" />
- <activity android:name="com.android.tests.rollback.testapp.MainActivity">
- <intent-filter>
- <action android:name="android.intent.action.MAIN" />
- <category android:name="android.intent.category.LAUNCHER" />
- </intent-filter>
- </activity>
- </application>
-</manifest>
diff --git a/tests/RollbackTest/TestApp/Av3.xml b/tests/RollbackTest/TestApp/Av3.xml
deleted file mode 100644
index 9725c9f7cf9e..000000000000
--- a/tests/RollbackTest/TestApp/Av3.xml
+++ /dev/null
@@ -1,35 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2018 The Android Open Source Project
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
--->
-
-<manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="com.android.tests.rollback.testapp.A"
- android:versionCode="3"
- android:versionName="3.0" >
-
-
- <uses-sdk android:minSdkVersion="19" />
-
- <application android:label="Rollback Test App A v3">
- <receiver android:name="com.android.tests.rollback.testapp.ProcessUserData"
- android:exported="true" />
- <activity android:name="com.android.tests.rollback.testapp.MainActivity">
- <intent-filter>
- <action android:name="android.intent.action.MAIN" />
- <category android:name="android.intent.category.LAUNCHER" />
- </intent-filter>
- </activity>
- </application>
-</manifest>
diff --git a/tests/RollbackTest/TestApp/Bv1.xml b/tests/RollbackTest/TestApp/Bv1.xml
deleted file mode 100644
index ca9c2ec47a20..000000000000
--- a/tests/RollbackTest/TestApp/Bv1.xml
+++ /dev/null
@@ -1,35 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2018 The Android Open Source Project
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
--->
-
-<manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="com.android.tests.rollback.testapp.B"
- android:versionCode="1"
- android:versionName="1.0" >
-
-
- <uses-sdk android:minSdkVersion="19" />
-
- <application android:label="Rollback Test App B v1">
- <receiver android:name="com.android.tests.rollback.testapp.ProcessUserData"
- android:exported="true" />
- <activity android:name="com.android.tests.rollback.testapp.MainActivity">
- <intent-filter>
- <action android:name="android.intent.action.MAIN" />
- <category android:name="android.intent.category.LAUNCHER" />
- </intent-filter>
- </activity>
- </application>
-</manifest>
diff --git a/tests/RollbackTest/TestApp/Bv2.xml b/tests/RollbackTest/TestApp/Bv2.xml
deleted file mode 100644
index bd3e6133f6f6..000000000000
--- a/tests/RollbackTest/TestApp/Bv2.xml
+++ /dev/null
@@ -1,35 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2018 The Android Open Source Project
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
--->
-
-<manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="com.android.tests.rollback.testapp.B"
- android:versionCode="2"
- android:versionName="2.0" >
-
-
- <uses-sdk android:minSdkVersion="19" />
-
- <application android:label="Rollback Test App B v2">
- <receiver android:name="com.android.tests.rollback.testapp.ProcessUserData"
- android:exported="true" />
- <activity android:name="com.android.tests.rollback.testapp.MainActivity">
- <intent-filter>
- <action android:name="android.intent.action.MAIN" />
- <category android:name="android.intent.category.LAUNCHER" />
- </intent-filter>
- </activity>
- </application>
-</manifest>
diff --git a/tests/RollbackTest/TestApp/res_v1/values-anydpi/values.xml b/tests/RollbackTest/TestApp/res_v1/values-anydpi/values.xml
deleted file mode 100644
index 90d3da2565cc..000000000000
--- a/tests/RollbackTest/TestApp/res_v1/values-anydpi/values.xml
+++ /dev/null
@@ -1,19 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2019 The Android Open Source Project
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
--->
-
-<resources>
- <integer name="split_version">1</integer>
-</resources>
diff --git a/tests/RollbackTest/TestApp/res_v1/values/values.xml b/tests/RollbackTest/TestApp/res_v1/values/values.xml
deleted file mode 100644
index 0447c74a79a6..000000000000
--- a/tests/RollbackTest/TestApp/res_v1/values/values.xml
+++ /dev/null
@@ -1,20 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2019 The Android Open Source Project
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
--->
-
-<resources>
- <integer name="app_version">1</integer>
- <integer name="split_version">0</integer>
-</resources>
diff --git a/tests/RollbackTest/TestApp/res_v2/values-anydpi/values.xml b/tests/RollbackTest/TestApp/res_v2/values-anydpi/values.xml
deleted file mode 100644
index 9a1aa7fd8461..000000000000
--- a/tests/RollbackTest/TestApp/res_v2/values-anydpi/values.xml
+++ /dev/null
@@ -1,19 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2019 The Android Open Source Project
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
--->
-
-<resources>
- <integer name="split_version">2</integer>
-</resources>
diff --git a/tests/RollbackTest/TestApp/res_v2/values/values.xml b/tests/RollbackTest/TestApp/res_v2/values/values.xml
deleted file mode 100644
index fd988f597f61..000000000000
--- a/tests/RollbackTest/TestApp/res_v2/values/values.xml
+++ /dev/null
@@ -1,20 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2019 The Android Open Source Project
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
--->
-
-<resources>
- <integer name="app_version">2</integer>
- <integer name="split_version">0</integer>
-</resources>
diff --git a/tests/RollbackTest/TestApp/res_v3/values-anydpi/values.xml b/tests/RollbackTest/TestApp/res_v3/values-anydpi/values.xml
deleted file mode 100644
index f2d8992bee37..000000000000
--- a/tests/RollbackTest/TestApp/res_v3/values-anydpi/values.xml
+++ /dev/null
@@ -1,19 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2019 The Android Open Source Project
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
--->
-
-<resources>
- <integer name="split_version">3</integer>
-</resources>
diff --git a/tests/RollbackTest/TestApp/res_v3/values/values.xml b/tests/RollbackTest/TestApp/res_v3/values/values.xml
deleted file mode 100644
index 968168a4bf06..000000000000
--- a/tests/RollbackTest/TestApp/res_v3/values/values.xml
+++ /dev/null
@@ -1,20 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2019 The Android Open Source Project
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
--->
-
-<resources>
- <integer name="app_version">3</integer>
- <integer name="split_version">0</integer>
-</resources>
diff --git a/tests/RollbackTest/TestApp/src/com/android/tests/rollback/testapp/CrashingMainActivity.java b/tests/RollbackTest/TestApp/src/com/android/tests/rollback/testapp/CrashingMainActivity.java
deleted file mode 100644
index 97958acde21b..000000000000
--- a/tests/RollbackTest/TestApp/src/com/android/tests/rollback/testapp/CrashingMainActivity.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * Copyright (C) 2019 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.tests.rollback.testapp;
-
-import android.app.Activity;
-import android.content.Context;
-import android.content.Intent;
-import android.content.SharedPreferences;
-import android.os.Bundle;
-
-/**
- * A crashing test app for testing apk rollback support.
- */
-public class CrashingMainActivity extends Activity {
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- incrementCountAndBroadcast();
- throw new RuntimeException("Intended force crash");
- }
-
- private void incrementCountAndBroadcast() {
- SharedPreferences preferences = getSharedPreferences("prefs", Context.MODE_PRIVATE);
- SharedPreferences.Editor editor = preferences.edit();
- int count = preferences.getInt("crash_count", 0);
- editor.putInt("crash_count", ++count).commit();
-
- Intent intent = new Intent("com.android.tests.rollback.CRASH");
- intent.putExtra("count", count);
- sendBroadcast(intent);
- }
-}
diff --git a/tests/RollbackTest/TestApp/src/com/android/tests/rollback/testapp/MainActivity.java b/tests/RollbackTest/TestApp/src/com/android/tests/rollback/testapp/MainActivity.java
deleted file mode 100644
index 9f1a0609d3f1..000000000000
--- a/tests/RollbackTest/TestApp/src/com/android/tests/rollback/testapp/MainActivity.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * Copyright (C) 2018 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.tests.rollback.testapp;
-
-import android.app.Activity;
-import android.os.Bundle;
-
-/**
- * A test app for testing apk rollback support.
- */
-public class MainActivity extends Activity {
-
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
-
- try {
- new ProcessUserData().processUserData(this);
- } catch (ProcessUserData.UserDataException e) {
- throw new AssertionError("Failed to process app user data", e);
- }
- }
-}
diff --git a/tests/RollbackTest/TestApp/src/com/android/tests/rollback/testapp/ProcessUserData.java b/tests/RollbackTest/TestApp/src/com/android/tests/rollback/testapp/ProcessUserData.java
deleted file mode 100644
index 38c658e795aa..000000000000
--- a/tests/RollbackTest/TestApp/src/com/android/tests/rollback/testapp/ProcessUserData.java
+++ /dev/null
@@ -1,111 +0,0 @@
-/*
- * Copyright (C) 2018 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.tests.rollback.testapp;
-
-import android.content.BroadcastReceiver;
-import android.content.Context;
-import android.content.Intent;
-import android.content.res.Resources;
-
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.util.Scanner;
-
-/**
- * A broadcast reciever to check for and update user app data version
- * compatibility.
- */
-public class ProcessUserData extends BroadcastReceiver {
-
- private static final String TAG = "RollbackTestApp";
-
- /**
- * Exception thrown in case of issue with user data.
- */
- public static class UserDataException extends Exception {
- public UserDataException(String message) {
- super(message);
- }
-
- public UserDataException(String message, Throwable cause) {
- super(message, cause);
- }
- }
-
- @Override
- public void onReceive(Context context, Intent intent) {
- try {
- processUserData(context);
- setResultCode(1);
- } catch (UserDataException e) {
- setResultCode(0);
- setResultData(e.getMessage());
- }
- }
-
- /**
- * Update the app's user data version to match the app version.
- *
- * @param context The application context.
- * @throws UserDataException in case of problems with app user data.
- */
- public void processUserData(Context context) throws UserDataException {
- Resources res = context.getResources();
- String packageName = context.getPackageName();
-
- int appVersionId = res.getIdentifier("app_version", "integer", packageName);
- int appVersion = res.getInteger(appVersionId);
-
- int splitVersionId = res.getIdentifier("split_version", "integer", packageName);
- int splitVersion = res.getInteger(splitVersionId);
-
- // Make sure the app version and split versions are compatible.
- if (appVersion != splitVersion) {
- throw new UserDataException("Split version " + splitVersion
- + " does not match app version " + appVersion);
- }
-
- // Read the version of the app's user data and ensure it is compatible
- // with our version of the application.
- File versionFile = new File(context.getFilesDir(), "version.txt");
- try {
- Scanner s = new Scanner(versionFile);
- int userDataVersion = s.nextInt();
- s.close();
-
- if (userDataVersion > appVersion) {
- throw new UserDataException("User data is from version " + userDataVersion
- + ", which is not compatible with this version " + appVersion
- + " of the RollbackTestApp");
- }
- } catch (FileNotFoundException e) {
- // No problem. This is a fresh install of the app or the user data
- // has been wiped.
- }
-
- // Record the current version of the app in the user data.
- try {
- PrintWriter pw = new PrintWriter(versionFile);
- pw.println(appVersion);
- pw.close();
- } catch (IOException e) {
- throw new UserDataException("Unable to write user data.", e);
- }
- }
-}