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
This commit is contained in:
@@ -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)));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user