diff options
author | 2022-10-11 13:01:34 +0000 | |
---|---|---|
committer | 2022-10-28 12:37:53 +0000 | |
commit | 1b9da7c042f8dce0195f1a2976e6bb801e1b54dd (patch) | |
tree | 6443442015015d7e3c02c2e4f6bc1358bb05b34f | |
parent | 7aa3c043a804553b4264c31183284a345363ca3c (diff) |
Update getOrCreateUserState to update if needed
Update the method getOrCreateUserStatedLocked to also have the option to
update the UserState when fetching an existing UserState. This will avoid
redundant calls to readInstalledPrintServicesLocked,
readDisabledPrintServicesLocked, and readDisabledPrintServicesLocked
when updateIfNeeded was called right after receiving the UserState
object.
Bug: 210740189
Test: atest FrameworksCoreTests
Change-Id: Iaf28eda3530dfddbbe870219a7f17dab113ba3d0
-rw-r--r-- | services/print/java/com/android/server/print/PrintManagerService.java | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/services/print/java/com/android/server/print/PrintManagerService.java b/services/print/java/com/android/server/print/PrintManagerService.java index 66524edf61ed..35b9bc3b1e06 100644 --- a/services/print/java/com/android/server/print/PrintManagerService.java +++ b/services/print/java/com/android/server/print/PrintManagerService.java @@ -984,6 +984,7 @@ public final class PrintManagerService extends SystemService { monitor.register(mContext, BackgroundThread.getHandler().getLooper(), UserHandle.ALL, true); } + private UserState getOrCreateUserStateLocked(int userId, boolean lowPriority) { return getOrCreateUserStateLocked(userId, lowPriority, true /* enforceUserUnlockingOrUnlocked */); @@ -991,6 +992,12 @@ public final class PrintManagerService extends SystemService { private UserState getOrCreateUserStateLocked(int userId, boolean lowPriority, boolean enforceUserUnlockingOrUnlocked) { + return getOrCreateUserStateLocked(userId, lowPriority, + enforceUserUnlockingOrUnlocked, false /* shouldUpdateState */); + } + + private UserState getOrCreateUserStateLocked(int userId, boolean lowPriority, + boolean enforceUserUnlockingOrUnlocked, boolean shouldUpdateState) { if (enforceUserUnlockingOrUnlocked && !mUserManager.isUserUnlockingOrUnlocked(userId)) { throw new IllegalStateException( "User " + userId + " must be unlocked for printing to be available"); @@ -1000,6 +1007,8 @@ public final class PrintManagerService extends SystemService { if (userState == null) { userState = new UserState(mContext, userId, mLock, lowPriority); mUserStates.put(userId, userState); + } else if (shouldUpdateState) { + userState.updateIfNeededLocked(); } if (!lowPriority) { @@ -1019,9 +1028,9 @@ public final class PrintManagerService extends SystemService { UserState userState; synchronized (mLock) { - userState = getOrCreateUserStateLocked(userId, true, - false /*enforceUserUnlockingOrUnlocked */); - userState.updateIfNeededLocked(); + userState = getOrCreateUserStateLocked(userId, /* lowPriority */ true, + /* enforceUserUnlockingOrUnlocked */ false, + /* shouldUpdateState */ true); } // This is the first time we switch to this user after boot, so // now is the time to remove obsolete print jobs since they |