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

Commit ae30e283 authored by Jigar Thakkar's avatar Jigar Thakkar Committed by Android (Google) Code Review
Browse files

Merge "Move quiet mode operations to a separate thread" into main

parents 42c76309 62fbc41b
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -71,3 +71,10 @@ flag {
    description: "Add support for Private Space in resolver sheet"
    bug: "307515485"
}

flag {
    name: "move_quiet_mode_operations_to_separate_thread"
    namespace: "profile_experiences"
    description: "Move the quiet mode operations, happening on a background thread today, to a separate thread."
    bug: "320483504"
}
 No newline at end of file
+20 −5
Original line number Diff line number Diff line
@@ -181,6 +181,8 @@ import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
@@ -334,6 +336,8 @@ public class UserManagerService extends IUserManager.Stub {

    private final Handler mHandler;

    private final ThreadPoolExecutor mInternalExecutor;

    private final File mUsersDir;
    private final File mUserListFile;

@@ -723,12 +727,21 @@ public class UserManagerService extends IUserManager.Stub {
    @VisibleForTesting
    void setQuietModeEnabledAsync(@UserIdInt int userId, boolean enableQuietMode,
            IntentSender target, @Nullable String callingPackage) {
        if (android.multiuser.Flags.moveQuietModeOperationsToSeparateThread()) {
            // Call setQuietModeEnabled on a separate thread. Calling this operation on the main
            // thread can cause ANRs, posting on a BackgroundThread can result in delays
            Slog.d(LOG_TAG, "Calling setQuietModeEnabled for user " + userId
                    + " on a separate thread");
            mInternalExecutor.execute(() -> setQuietModeEnabled(userId, enableQuietMode, target,
                    callingPackage));
        } else {
            // Call setQuietModeEnabled on bg thread to avoid ANR
            BackgroundThread.getHandler().post(
                    () -> setQuietModeEnabled(userId, enableQuietMode, target,
                            callingPackage)
            );
        }
    }

    /**
     * Cache the owner name string, since it could be read repeatedly on a critical code path
@@ -956,6 +969,8 @@ public class UserManagerService extends IUserManager.Stub {
        mPackagesLock = packagesLock;
        mUsers = users != null ? users : new SparseArray<>();
        mHandler = new MainHandler();
        mInternalExecutor = new ThreadPoolExecutor(/* corePoolSize */ 0, /* maximumPoolSize */ 1,
                /* keepAliveTime */ 1, TimeUnit.SECONDS, new LinkedBlockingQueue<>());
        mUserVisibilityMediator = new UserVisibilityMediator(mHandler);
        mUserDataPreparer = userDataPreparer;
        mUserTypes = UserTypeFactory.getUserTypes();