diff --git a/apct-tests/perftests/multiuser/src/android/multiuser/UserLifecycleTests.java b/apct-tests/perftests/multiuser/src/android/multiuser/UserLifecycleTests.java index 9ba94c8b9d119..e5d4a2087fd43 100644 --- a/apct-tests/perftests/multiuser/src/android/multiuser/UserLifecycleTests.java +++ b/apct-tests/perftests/multiuser/src/android/multiuser/UserLifecycleTests.java @@ -70,7 +70,6 @@ import java.util.ArrayList; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; -import java.util.concurrent.atomic.AtomicReference; /** * Perf tests for user life cycle events. @@ -1262,15 +1261,13 @@ public class UserLifecycleTests { *
This should always be used for profiles since profiles cannot be started in foreground.
*/
private void startUserInBackgroundAndWaitForUnlock(int userId) {
- final ProgressWaiter waiter = new ProgressWaiter();
- boolean success = false;
try {
- mIam.startUserInBackgroundWithListener(userId, waiter);
- success = waiter.waitForFinish(TIMEOUT_IN_SECOND);
- } catch (RemoteException e) {
- Log.e(TAG, "startUserInBackgroundAndWaitForUnlock failed", e);
+ attestTrue("Failed to start user " + userId + " in background.",
+ ShellHelper.runShellCommandWithTimeout("am start-user -w " + userId,
+ TIMEOUT_IN_SECOND).startsWith("Success:"));
+ } catch (TimeoutException e) {
+ fail("Could not start user " + userId + " in " + TIMEOUT_IN_SECOND + " seconds");
}
- attestTrue("Failed to start user " + userId + " in background.", success);
}
/** Starts the given user in the foreground. */
@@ -1472,7 +1469,8 @@ public class UserLifecycleTests {
private void removeUser(int userId) throws RemoteException {
stopUserAfterWaitingForBroadcastIdle(userId, true);
try {
- runShellCommandWithTimeout("pm remove-user -w " + userId, TIMEOUT_IN_SECOND);
+ ShellHelper.runShellCommandWithTimeout("pm remove-user -w " + userId,
+ TIMEOUT_IN_SECOND);
} catch (TimeoutException e) {
Log.e(TAG, String.format("Could not remove user %d in %d seconds",
userId, TIMEOUT_IN_SECOND), e);
@@ -1539,7 +1537,7 @@ public class UserLifecycleTests {
private void waitForBroadcastIdle() {
try {
- runShellCommandWithTimeout("am wait-for-broadcast-idle", TIMEOUT_IN_SECOND);
+ ShellHelper.runShellCommandWithTimeout("am wait-for-broadcast-idle", TIMEOUT_IN_SECOND);
} catch (TimeoutException e) {
Log.e(TAG, "Ending waitForBroadcastIdle because it is taking too long", e);
}
@@ -1558,41 +1556,4 @@ public class UserLifecycleTests {
waitForBroadcastIdle();
sleep(tenSeconds);
}
-
- /**
- * Runs a Shell command with a timeout, returning a trimmed response.
- */
- private String runShellCommandWithTimeout(String command, long timeoutInSecond)
- throws TimeoutException {
- AtomicReference