Skip to content

Commit

Permalink
Unmount unusable partition instead of putting device into crashloop.
Browse files Browse the repository at this point in the history
Bug: 233902887
Test: presubmit
Change-Id: I91963f4fcde27656e1a253d6181e4d81b02b26fe
Merged-In: I91963f4fcde27656e1a253d6181e4d81b02b26fe
(cherry picked from commit 335f471)
  • Loading branch information
alexbuy authored and basamaryan committed Sep 14, 2023
1 parent 19e03d5 commit 5358402
Showing 1 changed file with 25 additions and 11 deletions.
36 changes: 25 additions & 11 deletions services/core/java/com/android/server/StorageManagerService.java
Expand Up @@ -1716,6 +1716,23 @@ private void onVolumeStateChangedLocked(VolumeInfo vol, int oldState, int newSta
}

private void onVolumeStateChangedAsync(VolumeInfo vol, int oldState, int newState) {
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.
try {
prepareUserStorageIfNeeded(vol);
} catch (Exception e) {
// Unusable partition, unmount.
try {
mVold.unmount(vol.id);
} catch (Exception ee) {
Slog.wtf(TAG, ee);
}
return;
}
}

synchronized (mLock) {
// Remember that we saw this volume so we're ready to accept user
// metadata, or so we can annoy them when a private volume is ejected
Expand All @@ -1741,13 +1758,6 @@ private void onVolumeStateChangedAsync(VolumeInfo vol, int oldState, int newStat
}
}

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
// before notifying other listeners.
// Intentionally called without the mLock to avoid deadlocking from the Storage Service.
Expand Down Expand Up @@ -3369,7 +3379,7 @@ private boolean isSystemUnlocked(int userId) {
}
}

private void prepareUserStorageIfNeeded(VolumeInfo vol) {
private void prepareUserStorageIfNeeded(VolumeInfo vol) throws Exception {
if (vol.type != VolumeInfo.TYPE_PRIVATE) {
return;
}
Expand All @@ -3396,11 +3406,15 @@ private void prepareUserStorageIfNeeded(VolumeInfo vol) {
public void prepareUserStorage(String volumeUuid, int userId, int serialNumber, int flags) {
enforcePermission(android.Manifest.permission.STORAGE_INTERNAL);

prepareUserStorageInternal(volumeUuid, userId, serialNumber, flags);
try {
prepareUserStorageInternal(volumeUuid, userId, serialNumber, flags);
} catch (Exception e) {
throw new RuntimeException(e);
}
}

private void prepareUserStorageInternal(String volumeUuid, int userId, int serialNumber,
int flags) {
int flags) throws Exception {
try {
mVold.prepareUserStorage(volumeUuid, userId, serialNumber, flags);
// After preparing user storage, we should check if we should mount data mirror again,
Expand All @@ -3427,7 +3441,7 @@ private void prepareUserStorageInternal(String volumeUuid, int userId, int seria
+ "; device may be insecure!");
return;
}
throw new RuntimeException(e);
throw e;
}
}

Expand Down

0 comments on commit 5358402

Please sign in to comment.