From e56dab21a5c78ac772754adcdff6fa8822a5351e Mon Sep 17 00:00:00 2001 From: Jeff Sharkey Date: Tue, 16 Jun 2020 10:12:54 -0600 Subject: [PATCH] Forget volumes that have been freshly formatted. When the user formats an existing volume, the old partition will never appear again, so we can immediately clean up any VolumeRecord information. This change ensures that the next MediaProvider idle maintenance pass will see the UUID has been removed via getRecentStorageVolumes(), and will clean up stale metadata, instead of waiting an entire week for the volume to appear stale. Bug: 157164840 Test: atest --test-mapping packages/providers/MediaProvider Change-Id: Ia60440a423d980de141a87e957cfe03f91a6d9ff --- .../java/com/android/server/StorageManagerService.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/services/core/java/com/android/server/StorageManagerService.java b/services/core/java/com/android/server/StorageManagerService.java index 1ce3dfe9f3a0d..bffe346db9bce 100644 --- a/services/core/java/com/android/server/StorageManagerService.java +++ b/services/core/java/com/android/server/StorageManagerService.java @@ -2252,8 +2252,15 @@ class StorageManagerService extends IStorageManager.Stub enforcePermission(android.Manifest.permission.MOUNT_FORMAT_FILESYSTEMS); final VolumeInfo vol = findVolumeByIdOrThrow(volId); + final String fsUuid = vol.fsUuid; try { mVold.format(vol.id, "auto"); + + // After a successful format above, we should forget about any + // records for the old partition, since it'll never appear again + if (!TextUtils.isEmpty(fsUuid)) { + forgetVolume(fsUuid); + } } catch (Exception e) { Slog.wtf(TAG, e); }