Merge "UserDataPreparer: fix volume preparation order"

This commit is contained in:
Eric Biggers
2022-05-04 18:56:16 +00:00
committed by Gerrit Code Review

View File

@@ -70,12 +70,19 @@ class UserDataPreparer {
void prepareUserData(int userId, int userSerial, int flags) { void prepareUserData(int userId, int userSerial, int flags) {
synchronized (mInstallLock) { synchronized (mInstallLock) {
final StorageManager storage = mContext.getSystemService(StorageManager.class); final StorageManager storage = mContext.getSystemService(StorageManager.class);
/*
* Internal storage must be prepared before adoptable storage, since the user's volume
* keys are stored in their internal storage.
*/
prepareUserDataLI(null /* internal storage */, userId, userSerial, flags, true);
for (VolumeInfo vol : storage.getWritablePrivateVolumes()) { for (VolumeInfo vol : storage.getWritablePrivateVolumes()) {
final String volumeUuid = vol.getFsUuid(); final String volumeUuid = vol.getFsUuid();
if (volumeUuid != null) {
prepareUserDataLI(volumeUuid, userId, userSerial, flags, true); prepareUserDataLI(volumeUuid, userId, userSerial, flags, true);
} }
} }
} }
}
private void prepareUserDataLI(String volumeUuid, int userId, int userSerial, int flags, private void prepareUserDataLI(String volumeUuid, int userId, int userSerial, int flags,
boolean allowRecover) { boolean allowRecover) {
@@ -133,11 +140,18 @@ class UserDataPreparer {
void destroyUserData(int userId, int flags) { void destroyUserData(int userId, int flags) {
synchronized (mInstallLock) { synchronized (mInstallLock) {
final StorageManager storage = mContext.getSystemService(StorageManager.class); final StorageManager storage = mContext.getSystemService(StorageManager.class);
/*
* Volume destruction order isn't really important, but to avoid any weird issues we
* process internal storage last, the opposite of prepareUserData.
*/
for (VolumeInfo vol : storage.getWritablePrivateVolumes()) { for (VolumeInfo vol : storage.getWritablePrivateVolumes()) {
final String volumeUuid = vol.getFsUuid(); final String volumeUuid = vol.getFsUuid();
if (volumeUuid != null) {
destroyUserDataLI(volumeUuid, userId, flags); destroyUserDataLI(volumeUuid, userId, flags);
} }
} }
destroyUserDataLI(null /* internal storage */, userId, flags);
}
} }
void destroyUserDataLI(String volumeUuid, int userId, int flags) { void destroyUserDataLI(String volumeUuid, int userId, int flags) {