From 1eda2caa98d64a7eacbc7168edbc7590dbcbb53e Mon Sep 17 00:00:00 2001 From: Jeff Sharkey Date: Sat, 19 Jan 2019 17:27:09 -0700 Subject: [PATCH] Better scanning of secondary storage volumes. There's been a long-standing bug where secondary external storage volumes were being scanned into a single "external" database. We've had the logic in MediaProvider for a long time to support individual databases on a per-UUID basis, but that regressed at some point. This change revives that logic, which has the benefit of greatly speeding up media scanning of secondary storage devices, since we can preserve those databases instead of churning the primary "external" database whenever they're ejected and reinserted. Future work will clean up stale databases in the recently added idle maintenance service. Bug: 117932814, 122060093 Test: atest MediaProviderTests Test: atest cts/tests/tests/media/src/android/media/cts/MediaScanner* Test: atest cts/tests/tests/provider/src/android/provider/cts/MediaStore* Change-Id: Ib48577a2146758acd882db0b1767e88f3a70247f --- core/java/android/provider/MediaStore.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/core/java/android/provider/MediaStore.java b/core/java/android/provider/MediaStore.java index cdbc9790c952b..6a89d00a2ac84 100644 --- a/core/java/android/provider/MediaStore.java +++ b/core/java/android/provider/MediaStore.java @@ -1027,7 +1027,7 @@ public final class MediaStore { /** @hide */ public static final Uri getContentUriForPath(String path) { - return getContentUri(getVolumeNameForPath(path)); + return getContentUri(getVolumeName(new File(path))); } /** @@ -1197,7 +1197,7 @@ public final class MediaStore { /** @hide */ public static Uri getContentUriForPath(@NonNull String path) { - return getContentUri(getVolumeNameForPath(path)); + return getContentUri(getVolumeName(new File(path))); } /** @hide */ @@ -1211,10 +1211,11 @@ public final class MediaStore { } } - private static String getVolumeNameForPath(@NonNull String path) { + /** {@hide} */ + public static @NonNull String getVolumeName(@NonNull File path) { final StorageManager sm = AppGlobals.getInitialApplication() .getSystemService(StorageManager.class); - final StorageVolume sv = sm.getStorageVolume(new File(path)); + final StorageVolume sv = sm.getStorageVolume(path); if (sv != null) { if (sv.isPrimary()) { return VOLUME_EXTERNAL; @@ -1991,7 +1992,7 @@ public final class MediaStore { * access this path. */ public static @Nullable Uri getContentUriForPath(@NonNull String path) { - return getContentUri(getVolumeNameForPath(path)); + return getContentUri(getVolumeName(new File(path))); } /**