summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Eric Biggers <ebiggers@google.com> 2023-08-10 19:05:44 +0000
committer Gerrit Code Review <noreply-gerritcodereview@google.com> 2023-08-10 19:05:44 +0000
commit0dcb0da524e78043c3c015878d4a00bde39ad9fb (patch)
tree5aa1767c46d37ae0399dd5cc1a26b9039e3f0283
parentb4ff27c99aafb8e2148627a275864b410640f02f (diff)
parentaba0a55159b313326f4eb8b9c3fb1a68ed9b0e4b (diff)
Merge "Unmount unusable partition instead of putting device into crashloop." into main
-rw-r--r--services/core/java/com/android/server/StorageManagerService.java36
1 files changed, 25 insertions, 11 deletions
diff --git a/services/core/java/com/android/server/StorageManagerService.java b/services/core/java/com/android/server/StorageManagerService.java
index af0e61e9f6d4..08d8be81ca68 100644
--- a/services/core/java/com/android/server/StorageManagerService.java
+++ b/services/core/java/com/android/server/StorageManagerService.java
@@ -1735,6 +1735,23 @@ class StorageManagerService extends IStorageManager.Stub
}
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
@@ -1760,13 +1777,6 @@ class StorageManagerService extends IStorageManager.Stub
}
}
- 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.
@@ -3355,7 +3365,7 @@ class StorageManagerService extends IStorageManager.Stub
}
}
- private void prepareUserStorageIfNeeded(VolumeInfo vol) {
+ private void prepareUserStorageIfNeeded(VolumeInfo vol) throws Exception {
if (vol.type != VolumeInfo.TYPE_PRIVATE) {
return;
}
@@ -3382,11 +3392,15 @@ class StorageManagerService extends IStorageManager.Stub
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,
@@ -3413,7 +3427,7 @@ class StorageManagerService extends IStorageManager.Stub
+ "; device may be insecure!");
return;
}
- throw new RuntimeException(e);
+ throw e;
}
}