Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 686d0259 authored by ot_zhilin.gao@mediatek.com's avatar ot_zhilin.gao@mediatek.com Committed by Omar Eissa
Browse files

StorageManagerService: Call invalidateVolumeListCache upon complete user unlock

When a user is completely unlocked, the invalidateVolumeListCache
function of StorageManager should be called to ensure that the
app can obtain the latest volume information.

Currently, StorageManager uses a caching structure to store volume
information obtained via the getVolumeList function of StorageManagerService.
When an app, which is started by receiving the BOOT_COMPLETED broadcast,
calls StorageManager's invalidateVolumeListCache function, an issue may arise.

If the data/media partition has already been mounted but the user has not yet
unlocked it, the volume information returned by StorageManagerService's
getVolumeList will have a state of "unmounted". This volume information will
be cached in StorageManager's sVolumeListCache. Since the mVolumes information
in StorageManagerService has not changed, the cache will not trigger a refresh.

Consequently, the app will always retrieve volume information with an "unmounted"
state from the cache when calling StorageManager's getVolumeList function.

Bug: 407690018
Flag: EXEMPT bug fix
Test:m
1. Start the app by receiving the BOOT_COMPLETED broadcast.
2. The app calls StorageManager's getVolumeList function.
3. Call the getState function to check the mount status of the StorageVolume.
(cherry picked from https://android-review.googlesource.com/q/commit:f2a5bd48dcdd999284cf8fb99d2f866566bdb013)
Change-Id: Ib1b86c604f9e9f0dd413673ed6e767103d887b32
parent 097f6985
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -405,6 +405,10 @@ class StorageManagerService extends IStorageManager.Stub
     * value in the array changes, then the binder cache for {@link UserManager#isUserUnlocked} must
     * be invalidated.  When adding mutating methods to this class, be sure to invalidate the cache
     * in the new methods.
     *
     * Since we could report mounting state of already mounted emulated volume as unmounted
     * in getVolumeList method if it belongs to not unlocked users,
     * we also need to invalidate VolumeListCache when mutation happens to CE unlocked users array.
     */
    private static class WatchedUnlockedUsers {
        private int[] users = EmptyArray.INT;
@@ -414,16 +418,19 @@ class StorageManagerService extends IStorageManager.Stub
        public void append(int userId) {
            users = ArrayUtils.appendInt(users, userId);
            invalidateIsUserUnlockedCache();
            StorageManager.invalidateVolumeListCache();
        }
        public void appendAll(int[] userIds) {
            for (int userId : userIds) {
                users = ArrayUtils.appendInt(users, userId);
            }
            invalidateIsUserUnlockedCache();
            StorageManager.invalidateVolumeListCache();
        }
        public void remove(int userId) {
            users = ArrayUtils.removeInt(users, userId);
            invalidateIsUserUnlockedCache();
            StorageManager.invalidateVolumeListCache();
        }
        public boolean contains(int userId) {
            return ArrayUtils.contains(users, userId);
@@ -1264,6 +1271,11 @@ class StorageManagerService extends IStorageManager.Stub
            }
            mSystemUnlockedUsers = ArrayUtils.appendInt(mSystemUnlockedUsers, userId);
        }
        // Invalidate the StorageManager cache to ensure that
        // getVolumeList function returns the latest volumes.
        // This is needed as we intentionally report the volume as unmounted in getVolumeList,
        // if the user is not unlocked, even though it might have been mounted already.
        StorageManager.invalidateVolumeListCache();
    }

    private void extendWatchdogTimeout(String reason) {