Merge changes I3f7c88ee,Ia5d85d3c,I34d26ddc,I0a64e2dc
* changes: Remove unused code (4/n) Pass "-g --user all" when installing apps (3/n) No need to switch users before running tests (2/n) Wait for rollback becomes available (1/n)
This commit is contained in:
@@ -27,6 +27,8 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* Runs rollback tests for multiple users.
|
||||
*/
|
||||
@@ -41,7 +43,6 @@ public class MultiUserRollbackTest extends BaseHostJUnit4Test {
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
getDevice().switchUser(mOriginalUserId);
|
||||
getDevice().executeShellCommand("pm uninstall com.android.cts.install.lib.testapp.A");
|
||||
removeSecondaryUserIfNecessary();
|
||||
}
|
||||
@@ -49,9 +50,9 @@ public class MultiUserRollbackTest extends BaseHostJUnit4Test {
|
||||
@Before
|
||||
public void setup() throws Exception {
|
||||
mOriginalUserId = getDevice().getCurrentUser();
|
||||
installPackageAsUser("RollbackTest.apk", true, mOriginalUserId);
|
||||
createAndSwitchToSecondaryUserIfNecessary();
|
||||
installPackageAsUser("RollbackTest.apk", true, mSecondaryUserId);
|
||||
createAndStartSecondaryUser();
|
||||
// TODO(b/149733368): Remove the '-g' workaround when the bug is fixed.
|
||||
installPackage("RollbackTest.apk", "-g --user all");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -64,7 +65,6 @@ public class MultiUserRollbackTest extends BaseHostJUnit4Test {
|
||||
runPhaseForUsers("testMultipleUsersInstallV1", mOriginalUserId, mSecondaryUserId);
|
||||
runPhaseForUsers("testMultipleUsersUpgradeToV2", mOriginalUserId);
|
||||
runPhaseForUsers("testMultipleUsersUpdateUserData", mOriginalUserId, mSecondaryUserId);
|
||||
switchToUser(mOriginalUserId);
|
||||
getDevice().executeShellCommand("pm rollback-app com.android.cts.install.lib.testapp.A");
|
||||
runPhaseForUsers("testMultipleUsersVerifyUserdataRollback", mOriginalUserId,
|
||||
mSecondaryUserId);
|
||||
@@ -74,11 +74,11 @@ public class MultiUserRollbackTest extends BaseHostJUnit4Test {
|
||||
* Run the phase for the given user ids, in the order they are given.
|
||||
*/
|
||||
private void runPhaseForUsers(String phase, int... userIds) throws Exception {
|
||||
final long timeout = TimeUnit.MINUTES.toMillis(10);
|
||||
for (int userId: userIds) {
|
||||
switchToUser(userId);
|
||||
assertTrue(runDeviceTests("com.android.tests.rollback",
|
||||
assertTrue(runDeviceTests(getDevice(), "com.android.tests.rollback",
|
||||
"com.android.tests.rollback.MultiUserRollbackTest",
|
||||
phase));
|
||||
phase, userId, timeout));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -89,21 +89,7 @@ public class MultiUserRollbackTest extends BaseHostJUnit4Test {
|
||||
}
|
||||
}
|
||||
|
||||
private void createAndSwitchToSecondaryUserIfNecessary() throws Exception {
|
||||
if (mSecondaryUserId == -1) {
|
||||
mOriginalUserId = getDevice().getCurrentUser();
|
||||
mSecondaryUserId = getDevice().createUser("MultiUserRollbackTest_User"
|
||||
+ System.currentTimeMillis());
|
||||
switchToUser(mSecondaryUserId);
|
||||
}
|
||||
}
|
||||
|
||||
private void switchToUser(int userId) throws Exception {
|
||||
if (getDevice().getCurrentUser() == userId) {
|
||||
return;
|
||||
}
|
||||
|
||||
assertTrue(getDevice().switchUser(userId));
|
||||
private void awaitUserUnlocked(int userId) throws Exception {
|
||||
for (int i = 0; i < SWITCH_USER_COMPLETED_NUMBER_OF_POLLS; ++i) {
|
||||
String userState = getDevice().executeShellCommand("am get-started-user-state "
|
||||
+ userId);
|
||||
@@ -112,6 +98,14 @@ public class MultiUserRollbackTest extends BaseHostJUnit4Test {
|
||||
}
|
||||
Thread.sleep(SWITCH_USER_COMPLETED_POLL_INTERVAL_IN_MILLIS);
|
||||
}
|
||||
fail("User switch to user " + userId + " timed out");
|
||||
fail("Timed out in unlocking user: " + userId);
|
||||
}
|
||||
|
||||
private void createAndStartSecondaryUser() throws Exception {
|
||||
String name = "MultiUserRollbackTest_User" + System.currentTimeMillis();
|
||||
mSecondaryUserId = getDevice().createUser(name);
|
||||
getDevice().startUser(mSecondaryUserId);
|
||||
// Note we can't install apps on a locked user
|
||||
awaitUserUnlocked(mSecondaryUserId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,13 +17,11 @@
|
||||
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;
|
||||
@@ -77,13 +75,10 @@ public class MultiUserRollbackTest {
|
||||
*/
|
||||
@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();
|
||||
RollbackInfo rollback = RollbackUtils.waitForAvailableRollback(TestApp.A);
|
||||
assertThat(rollback).packagesContainsExactly(
|
||||
Rollback.from(TestApp.A2).to(TestApp.A1));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user