From cca1c654f8d0d2ec4671e3b1342a2db5a5256eab Mon Sep 17 00:00:00 2001 From: Fyodor Kupolov Date: Wed, 4 May 2016 14:57:48 -0700 Subject: [PATCH] Call unlockUserKey in a synchronized section This will make callers of isUserRunning to wait for the unlock to finish. Bug: 28530527 Change-Id: I272e2166cdc3df8e34c3436c9c18ba6765da0625 --- .../com/android/server/am/UserController.java | 26 +++++++++---------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/services/core/java/com/android/server/am/UserController.java b/services/core/java/com/android/server/am/UserController.java index bfa5b42b79c3c..e8f4b3e3fb743 100644 --- a/services/core/java/com/android/server/am/UserController.java +++ b/services/core/java/com/android/server/am/UserController.java @@ -927,32 +927,30 @@ final class UserController { boolean unlockUserCleared(final int userId, byte[] token, byte[] secret, IProgressListener listener) { - final UserState uss; synchronized (mService) { // Bail if user isn't actually running, otherwise register the given // listener to watch for unlock progress - uss = mStartedUsers.get(userId); + final UserState uss = mStartedUsers.get(userId); if (uss == null) { notifyFinished(userId, listener); return false; } else { uss.mUnlockProgress.addListener(listener); } - } - if (!StorageManager.isUserKeyUnlocked(userId)) { - final UserInfo userInfo = getUserInfo(userId); - final IMountService mountService = getMountService(); - try { - mountService.unlockUserKey(userId, userInfo.serialNumber, token, secret); - } catch (RemoteException | RuntimeException e) { - Slog.w(TAG, "Failed to unlock: " + e.getMessage()); - notifyFinished(userId, listener); - return false; + // TODO Move this block outside of synchronized if it causes lock contention + if (!StorageManager.isUserKeyUnlocked(userId)) { + final UserInfo userInfo = getUserInfo(userId); + final IMountService mountService = getMountService(); + try { + mountService.unlockUserKey(userId, userInfo.serialNumber, token, secret); + } catch (RemoteException | RuntimeException e) { + Slog.w(TAG, "Failed to unlock: " + e.getMessage()); + notifyFinished(userId, listener); + return false; + } } - } - synchronized (mService) { finishUserUnlocking(uss); // We just unlocked a user, so let's now attempt to unlock any