Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 719d7559 authored by Yasin Kilicdere's avatar Yasin Kilicdere Committed by Android (Google) Code Review
Browse files

Merge "Force stop a user before removing it in perf tests."

parents 71a1e9bf 75266fb9
Loading
Loading
Loading
Loading
+0 −12
Original line number Diff line number Diff line
@@ -45,7 +45,6 @@ public class BroadcastWaiter implements Closeable {
    private final int mTimeoutInSecond;
    private final Set<String> mActions;

    private final Set<String> mActionReceivedForUser = new HashSet<>();
    private final List<BroadcastReceiver> mBroadcastReceivers = new ArrayList<>();

    private final Map<String, Semaphore> mSemaphoresMap = new ConcurrentHashMap<>();
@@ -80,7 +79,6 @@ public class BroadcastWaiter implements Closeable {
                    final String data = intent.getDataString();
                    Log.d(mTag, "Received " + action + " for user " + userId
                            + (!TextUtils.isEmpty(data) ? " with " + data : ""));
                    mActionReceivedForUser.add(action + userId);
                    getSemaphore(action, userId).release();
                }
            }
@@ -95,10 +93,6 @@ public class BroadcastWaiter implements Closeable {
        mBroadcastReceivers.forEach(mContext::unregisterReceiver);
    }

    public boolean hasActionBeenReceivedForUser(String action, int userId) {
        return mActionReceivedForUser.contains(action + userId);
    }

    private boolean waitActionForUser(String action, int userId) {
        Log.d(mTag, "#waitActionForUser(action: " + action + ", userId: " + userId + ")");

@@ -129,7 +123,6 @@ public class BroadcastWaiter implements Closeable {
    public String runThenWaitForBroadcasts(int userId, FunctionalUtils.ThrowingRunnable runnable,
            String... actions) {
        for (String action : actions) {
            mActionReceivedForUser.remove(action + userId);
            getSemaphore(action, userId).drainPermits();
        }
        runnable.run();
@@ -140,9 +133,4 @@ public class BroadcastWaiter implements Closeable {
        }
        return null;
    }

    public boolean waitActionForUserIfNotReceivedYet(String action, int userId) {
        return hasActionBeenReceivedForUser(action, userId)
                || waitActionForUser(action, userId);
    }
}
+8 −10
Original line number Diff line number Diff line
@@ -167,7 +167,7 @@ public class UserLifecycleTests {

    /** Tests creating a new user. */
    @Test(timeout = TIMEOUT_MAX_TEST_TIME_MS)
    public void createUser() {
    public void createUser() throws RemoteException {
        while (mRunner.keepRunning()) {
            Log.i(TAG, "Starting timer");
            final int userId = createUserNoFlags();
@@ -229,7 +229,7 @@ public class UserLifecycleTests {
     * Measures the time until unlock listener is triggered and user is unlocked.
     */
    @Test(timeout = TIMEOUT_MAX_TEST_TIME_MS)
    public void startAndUnlockUser() {
    public void startAndUnlockUser() throws RemoteException {
        while (mRunner.keepRunning()) {
            mRunner.pauseTiming();
            final int userId = createUserNoFlags();
@@ -451,7 +451,7 @@ public class UserLifecycleTests {

    /** Tests creating a new profile. */
    @Test(timeout = TIMEOUT_MAX_TEST_TIME_MS)
    public void managedProfileCreate() {
    public void managedProfileCreate() throws RemoteException {
        assumeTrue(mHasManagedUserFeature);

        while (mRunner.keepRunning()) {
@@ -468,7 +468,7 @@ public class UserLifecycleTests {

    /** Tests starting (unlocking) an uninitialized profile. */
    @Test(timeout = TIMEOUT_MAX_TEST_TIME_MS)
    public void managedProfileUnlock() {
    public void managedProfileUnlock() throws RemoteException {
        assumeTrue(mHasManagedUserFeature);

        while (mRunner.keepRunning()) {
@@ -639,7 +639,7 @@ public class UserLifecycleTests {
    // TODO: This is just a POC. Do this properly and add more.
    /** Tests starting (unlocking) a newly-created profile using the user-type-pkg-whitelist. */
    @Test(timeout = TIMEOUT_MAX_TEST_TIME_MS)
    public void managedProfileUnlock_usingWhitelist() {
    public void managedProfileUnlock_usingWhitelist() throws RemoteException {
        assumeTrue(mHasManagedUserFeature);
        final int origMode = getUserTypePackageWhitelistMode();
        setUserTypePackageWhitelistMode(USER_TYPE_PACKAGE_WHITELIST_MODE_ENFORCE
@@ -665,7 +665,7 @@ public class UserLifecycleTests {
    }
    /** Tests starting (unlocking) a newly-created profile NOT using the user-type-pkg-whitelist. */
    @Test(timeout = TIMEOUT_MAX_TEST_TIME_MS)
    public void managedProfileUnlock_notUsingWhitelist() {
    public void managedProfileUnlock_notUsingWhitelist() throws RemoteException {
        assumeTrue(mHasManagedUserFeature);
        final int origMode = getUserTypePackageWhitelistMode();
        setUserTypePackageWhitelistMode(USER_TYPE_PACKAGE_WHITELIST_MODE_DISABLE);
@@ -908,10 +908,8 @@ public class UserLifecycleTests {
                result != null && result.contains("Failed"));
    }

    private void removeUser(int userId) {
        if (mBroadcastWaiter.hasActionBeenReceivedForUser(Intent.ACTION_USER_STARTED, userId)) {
            mBroadcastWaiter.waitActionForUserIfNotReceivedYet(Intent.ACTION_MEDIA_MOUNTED, userId);
        }
    private void removeUser(int userId) throws RemoteException {
        stopUserAfterWaitingForBroadcastIdle(userId, true);
        try {
            mUm.removeUser(userId);
            final long startTime = System.currentTimeMillis();