Loading core/java/android/content/pm/multiuser.aconfig +7 −0 Original line number Diff line number Diff line Loading @@ -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 services/core/java/com/android/server/pm/UserManagerService.java +20 −5 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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; Loading Loading @@ -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 Loading Loading @@ -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(); Loading Loading
core/java/android/content/pm/multiuser.aconfig +7 −0 Original line number Diff line number Diff line Loading @@ -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
services/core/java/com/android/server/pm/UserManagerService.java +20 −5 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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; Loading Loading @@ -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 Loading Loading @@ -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(); Loading