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

Commit 3ab91e73 authored by Automerger Merge Worker's avatar Automerger Merge Worker
Browse files

Merge "Merge "Prepare user storage when a private volume has been mounted."...

Merge "Merge "Prepare user storage when a private volume has been mounted." into rvc-dev am: 9df5ebf7 am: a96c6bcc am: 37d02991" into rvc-qpr-dev-plus-aosp am: 27fd1e89

Change-Id: I6f9dc7ae167c9f33afda0b91f2d728bf99c0077c
parents ac7fe435 27fd1e89
Loading
Loading
Loading
Loading
+36 −0
Original line number Original line Diff line number Diff line
@@ -1580,6 +1580,14 @@ class StorageManagerService extends IStorageManager.Stub
                writeSettingsLocked();
                writeSettingsLocked();
            }
            }
        }
        }

        if (newState == VolumeInfo.STATE_MOUNTED) {
            // Private volumes can be unmounted and re-mounted even after a user has
            // been unlocked; on devices that support encryption keys tied to the filesystem,
            // this requires setting up the keys again.
            prepareUserStorageIfNeeded(vol);
        }

        // This is a blocking call to Storage Service which needs to process volume state changed
        // This is a blocking call to Storage Service which needs to process volume state changed
        // before notifying other listeners.
        // before notifying other listeners.
        // Intentionally called without the mLock to avoid deadlocking from the Storage Service.
        // Intentionally called without the mLock to avoid deadlocking from the Storage Service.
@@ -3267,10 +3275,38 @@ class StorageManagerService extends IStorageManager.Stub
        }
        }
    }
    }


    private void prepareUserStorageIfNeeded(VolumeInfo vol) {
        if (vol.type != VolumeInfo.TYPE_PRIVATE) {
            return;
        }

        final UserManager um = mContext.getSystemService(UserManager.class);
        final UserManagerInternal umInternal =
                LocalServices.getService(UserManagerInternal.class);

        for (UserInfo user : um.getUsers(false /* includeDying */)) {
            final int flags;
            if (umInternal.isUserUnlockingOrUnlocked(user.id)) {
                flags = StorageManager.FLAG_STORAGE_DE | StorageManager.FLAG_STORAGE_CE;
            } else if (umInternal.isUserRunning(user.id)) {
                flags = StorageManager.FLAG_STORAGE_DE;
            } else {
                continue;
            }

            prepareUserStorageInternal(vol.fsUuid, user.id, user.serialNumber, flags);
        }
    }

    @Override
    @Override
    public void prepareUserStorage(String volumeUuid, int userId, int serialNumber, int flags) {
    public void prepareUserStorage(String volumeUuid, int userId, int serialNumber, int flags) {
        enforcePermission(android.Manifest.permission.STORAGE_INTERNAL);
        enforcePermission(android.Manifest.permission.STORAGE_INTERNAL);


        prepareUserStorageInternal(volumeUuid, userId, serialNumber, flags);
    }

    private void prepareUserStorageInternal(String volumeUuid, int userId, int serialNumber,
            int flags) {
        try {
        try {
            mVold.prepareUserStorage(volumeUuid, userId, serialNumber, flags);
            mVold.prepareUserStorage(volumeUuid, userId, serialNumber, flags);
            // After preparing user storage, we should check if we should mount data mirror again,
            // After preparing user storage, we should check if we should mount data mirror again,