From a859e8affc8855f65796757fe66a858e321f5e13 Mon Sep 17 00:00:00 2001 From: Gavin Corkery Date: Fri, 6 Sep 2019 12:14:26 +0100 Subject: [PATCH] Add multi-user test for the general non-staged case This test makes assertions about the case where there are two users running a test application. It verifies that each user can have its own unique userdata for the same app, and that upgrades and downgrades are applicable for all users on the device. Test: atest MultiUserRollbackTest Test: atest RollbackTest Bug: 140401995 Change-Id: I5e5c154758b3f0e4731696c813519ac798fbbae9 --- tests/RollbackTest/Android.bp | 6 +- ...backTest.xml => MultiUserRollbackTest.xml} | 11 +- .../rollback/host/MultiUserRollbackTest.java} | 65 ++++++---- tests/RollbackTest/RollbackTest.xml | 5 +- .../tests/rollback/MultiUserRollbackTest.java | 111 ++++++++++++++++++ tests/RollbackTest/TEST_MAPPING | 2 +- 6 files changed, 166 insertions(+), 34 deletions(-) rename tests/RollbackTest/{SecondaryUserRollbackTest.xml => MultiUserRollbackTest.xml} (67%) rename tests/RollbackTest/{SecondaryUserRollbackTest/src/com/android/tests/rollback/host/SecondaryUserRollbackTest.java => MultiUserRollbackTest/src/com/android/tests/rollback/host/MultiUserRollbackTest.java} (52%) create mode 100644 tests/RollbackTest/RollbackTest/src/com/android/tests/rollback/MultiUserRollbackTest.java diff --git a/tests/RollbackTest/Android.bp b/tests/RollbackTest/Android.bp index 2bd5931eccbe1..231d045bd8178 100644 --- a/tests/RollbackTest/Android.bp +++ b/tests/RollbackTest/Android.bp @@ -31,9 +31,9 @@ java_test_host { } java_test_host { - name: "SecondaryUserRollbackTest", - srcs: ["SecondaryUserRollbackTest/src/**/*.java"], + name: "MultiUserRollbackTest", + srcs: ["MultiUserRollbackTest/src/**/*.java"], libs: ["tradefed"], test_suites: ["general-tests"], - test_config: "SecondaryUserRollbackTest.xml", + test_config: "MultiUserRollbackTest.xml", } diff --git a/tests/RollbackTest/SecondaryUserRollbackTest.xml b/tests/RollbackTest/MultiUserRollbackTest.xml similarity index 67% rename from tests/RollbackTest/SecondaryUserRollbackTest.xml rename to tests/RollbackTest/MultiUserRollbackTest.xml index 6b3f05c429836..41cec461c3773 100644 --- a/tests/RollbackTest/SecondaryUserRollbackTest.xml +++ b/tests/RollbackTest/MultiUserRollbackTest.xml @@ -13,17 +13,12 @@ See the License for the specific language governing permissions and limitations under the License. --> - - diff --git a/tests/RollbackTest/RollbackTest/src/com/android/tests/rollback/MultiUserRollbackTest.java b/tests/RollbackTest/RollbackTest/src/com/android/tests/rollback/MultiUserRollbackTest.java new file mode 100644 index 0000000000000..0ffe041b03776 --- /dev/null +++ b/tests/RollbackTest/RollbackTest/src/com/android/tests/rollback/MultiUserRollbackTest.java @@ -0,0 +1,111 @@ +/* + * 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; + +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.rollback.RollbackInfo; +import android.content.rollback.RollbackManager; + +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.rollback.lib.Rollback; +import com.android.cts.rollback.lib.RollbackUtils; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + + +@RunWith(JUnit4.class) +public class MultiUserRollbackTest { + + @Before + public void adoptShellPermissions() { + InstallUtils.adoptShellPermissionIdentity( + Manifest.permission.INSTALL_PACKAGES, + Manifest.permission.DELETE_PACKAGES, + Manifest.permission.TEST_MANAGE_ROLLBACKS, + Manifest.permission.MANAGE_ROLLBACKS); + } + + @After + public void dropShellPermissions() { + InstallUtils.dropShellPermissionIdentity(); + } + + @Test + public void testBasic() throws Exception { + new RollbackTest().testBasic(); + } + + /** + * Install version 1 of the test app. This method is run for both users. + */ + @Test + public void testMultipleUsersInstallV1() throws Exception { + assertThat(InstallUtils.getInstalledVersion(TestApp.A)).isEqualTo(-1); + Install.single(TestApp.A1).commit(); + assertThat(InstallUtils.getInstalledVersion(TestApp.A)).isEqualTo(1); + InstallUtils.processUserData(TestApp.A); + } + + /** + * Upgrade the test app to version 2. This method should only run once as the system user, + * and will update the app for both users. + */ + @Test + public void testMultipleUsersUpgradeToV2() throws Exception { + RollbackManager rm = RollbackUtils.getRollbackManager(); + assertThat(InstallUtils.getInstalledVersion(TestApp.A)).isEqualTo(1); + Install.single(TestApp.A2).setEnableRollback().commit(); + assertThat(InstallUtils.getInstalledVersion(TestApp.A)).isEqualTo(2); + RollbackInfo rollback = getUniqueRollbackInfoForPackage( + rm.getAvailableRollbacks(), TestApp.A); + assertThat(rollback).isNotNull(); + assertThat(rollback).packagesContainsExactly( + Rollback.from(TestApp.A2).to(TestApp.A1)); + } + + /** + * This method is run for both users. Assert that the test app has upgraded for both users, and + * update their userdata to reflect this new version. + */ + @Test + public void testMultipleUsersUpdateUserData() { + assertThat(InstallUtils.getInstalledVersion(TestApp.A)).isEqualTo(2); + InstallUtils.processUserData(TestApp.A); + } + + /** + * The system will have rolled back the test app at this stage. Verify that the rollback has + * taken place, and that the userdata has been correctly rolled back. This method is run for + * both users. + */ + @Test + public void testMultipleUsersVerifyUserdataRollback() { + assertThat(InstallUtils.getInstalledVersion(TestApp.A)).isEqualTo(1); + InstallUtils.processUserData(TestApp.A); + } +} diff --git a/tests/RollbackTest/TEST_MAPPING b/tests/RollbackTest/TEST_MAPPING index 7ae03e68decc4..fefde5b4be123 100644 --- a/tests/RollbackTest/TEST_MAPPING +++ b/tests/RollbackTest/TEST_MAPPING @@ -7,7 +7,7 @@ "name": "StagedRollbackTest" }, { - "name": "SecondaryUserRollbackTest" + "name": "MultiUserRollbackTest" } ] }