Track current user without calling into AMS.
From a layering point-of-view, StorageManager is below ActivityManager
and it shouldn't be calling upwards, since that risks locking
inversions. Instead, track the current user through the existing
SystemService callbacks.
Bug: 28598527
Change-Id: I02d3277eb26288d3b4e1897f4c9318a6288c9551
diff --git a/services/core/java/com/android/server/MountService.java b/services/core/java/com/android/server/MountService.java
index 7253870..25ce485 100644
--- a/services/core/java/com/android/server/MountService.java
+++ b/services/core/java/com/android/server/MountService.java
@@ -178,6 +178,11 @@
}
@Override
+ public void onSwitchUser(int userHandle) {
+ mMountService.mCurrentUserId = userHandle;
+ }
+
+ @Override
public void onUnlockUser(int userHandle) {
mMountService.onUnlockUser(userHandle);
}
@@ -320,6 +325,8 @@
@GuardedBy("mLock")
private String mMoveTargetUuid;
+ private volatile int mCurrentUserId = UserHandle.USER_SYSTEM;
+
private VolumeInfo findVolumeByIdOrThrow(String id) {
synchronized (mLock) {
final VolumeInfo vol = mVolumes.get(id);
@@ -1285,7 +1292,7 @@
vol.mountFlags |= VolumeInfo.MOUNT_FLAG_VISIBLE;
}
- vol.mountUserId = ActivityManager.getCurrentUser();
+ vol.mountUserId = mCurrentUserId;
mHandler.obtainMessage(H_VOLUME_MOUNT, vol).sendToTarget();
} else if (vol.type == VolumeInfo.TYPE_PRIVATE) {