From 96c1d7d55010f55835d10edc322d80296f8a5775 Mon Sep 17 00:00:00 2001 From: Zim Date: Tue, 18 May 2021 10:41:39 +0100 Subject: [PATCH] Improve secondary volume mounts on user switch Ic1226229d377d7106bd78798a03adfc9b7f2efb6 fixed the secondary volume mounts on user switch but there some issues when switching to a user that is not yet unlocked because the ExternalStorageService for the user might not yet be ready. Now, we fix this by checking if the user is unlocked and delaying the remount till after unlock in such cases Test: Manual Bug: 183686263 Change-Id: I7c885b0c3e6cefe23ba405710c2a50ad957bff5c --- .../android/server/StorageManagerService.java | 24 +++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/services/core/java/com/android/server/StorageManagerService.java b/services/core/java/com/android/server/StorageManagerService.java index 0c785da5c2422..69c29269b7a99 100644 --- a/services/core/java/com/android/server/StorageManagerService.java +++ b/services/core/java/com/android/server/StorageManagerService.java @@ -248,9 +248,18 @@ class StorageManagerService extends IStorageManager.Stub @Override public void onUserSwitching(@Nullable TargetUser from, @NonNull TargetUser to) { - mStorageManagerService.mCurrentUserId = to.getUserIdentifier(); - // To reset public volume mounts - mStorageManagerService.onUserSwitching(mStorageManagerService.mCurrentUserId); + int currentUserId = to.getUserIdentifier(); + mStorageManagerService.mCurrentUserId = currentUserId; + + UserManagerInternal umInternal = LocalServices.getService(UserManagerInternal.class); + if (umInternal.isUserUnlocked(currentUserId)) { + Slog.d(TAG, "Attempt remount volumes for user: " + currentUserId); + mStorageManagerService.maybeRemountVolumes(currentUserId); + mStorageManagerService.mRemountCurrentUserVolumesOnUnlock = false; + } else { + Slog.d(TAG, "Attempt remount volumes for user: " + currentUserId + " on unlock"); + mStorageManagerService.mRemountCurrentUserVolumesOnUnlock = true; + } } @Override @@ -425,6 +434,8 @@ class StorageManagerService extends IStorageManager.Stub private volatile int mCurrentUserId = UserHandle.USER_SYSTEM; + private volatile boolean mRemountCurrentUserVolumesOnUnlock = false; + private final Installer mInstaller; /** Holding lock for AppFuse business */ @@ -1196,6 +1207,10 @@ class StorageManagerService extends IStorageManager.Stub } mHandler.obtainMessage(H_COMPLETE_UNLOCK_USER, userId).sendToTarget(); + if (mRemountCurrentUserVolumesOnUnlock && userId == mCurrentUserId) { + maybeRemountVolumes(userId); + mRemountCurrentUserVolumesOnUnlock = false; + } } private void completeUnlockUser(int userId) { @@ -1255,7 +1270,7 @@ class StorageManagerService extends IStorageManager.Stub } } - private void onUserSwitching(int userId) { + private void maybeRemountVolumes(int userId) { boolean reset = false; List volumesToRemount = new ArrayList<>(); synchronized (mLock) { @@ -1272,6 +1287,7 @@ class StorageManagerService extends IStorageManager.Stub } for (VolumeInfo vol : volumesToRemount) { + Slog.i(TAG, "Remounting volume for user: " + userId + ". Volume: " + vol); mHandler.obtainMessage(H_VOLUME_UNMOUNT, vol).sendToTarget(); mHandler.obtainMessage(H_VOLUME_MOUNT, vol).sendToTarget(); }