From f96d81f5cd2b2b9b45d4377a17333c4c6bd59218 Mon Sep 17 00:00:00 2001 From: Arnab Sen Date: Tue, 11 Jul 2023 18:14:18 +0530 Subject: [PATCH] SM: Change volume mountUserId for new user When a volume is ejected from a user but not removed from the device and mounted again by calling StorageManager#mount, the volume is mounted for the user from which it was last ejected. This causes the path of the mounted volume to be inaccessible to the current user. Whenever StorageManager#mount is called, check if the VolumeInfo#mountUserId is same as the current userId maintained by StorageManagerService, if it is not, change the mountUserId for the Volume to the current userId known to StorageManagerService if it is not the primary volume and the volume is visible. This change also fixes a bug where the volumes are unmounted for the wrong user which causes StorageSessionController go out of sync which would cause errors during mounting the volumes again as it maintains sessions per user. The bug also caused volume event broadcasts to be sent to wrong user handles. To solve the issue add an extra paramter in IVoldListener#onVolumeStateChanged for userId which will update the copy which is used for informing StorageSessionController and also for sending broadcasts. Test: Perform the following steps: 1. Format SD Card as portable storage in system user. 2. Eject the SD Card from Storage Settings. 3. Switch to a non-system user 4. Mount the SD Card again. 5. Check that the Storage Summary is shown correctly instead of 0B out of 0B. Also, checked from the logs the volume state broadcasts are sent to the correct user handles. Change-Id: I60b8954cdaee4a54ea6a6299fe5ddda2006faf1c --- binder/android/os/IVoldListener.aidl | 2 +- model/VolumeBase.cpp | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/binder/android/os/IVoldListener.aidl b/binder/android/os/IVoldListener.aidl index b3e4ba5..c4535b5 100644 --- a/binder/android/os/IVoldListener.aidl +++ b/binder/android/os/IVoldListener.aidl @@ -26,7 +26,7 @@ oneway interface IVoldListener { void onVolumeCreated(@utf8InCpp String volId, int type, @utf8InCpp String diskId, @utf8InCpp String partGuid, int userId); - void onVolumeStateChanged(@utf8InCpp String volId, int state); + void onVolumeStateChanged(@utf8InCpp String volId, int state, int userId); void onVolumeMetadataChanged(@utf8InCpp String volId, @utf8InCpp String fsType, @utf8InCpp String fsUuid, @utf8InCpp String fsLabel); void onVolumePathChanged(@utf8InCpp String volId, diff --git a/model/VolumeBase.cpp b/model/VolumeBase.cpp index 27448da..e20a049 100644 --- a/model/VolumeBase.cpp +++ b/model/VolumeBase.cpp @@ -49,7 +49,8 @@ void VolumeBase::setState(State state) { auto listener = getListener(); if (listener) { - listener->onVolumeStateChanged(getId(), static_cast(mState)); + listener->onVolumeStateChanged(getId(), static_cast(mState), + static_cast(mMountUserId)); } }