I am building a custom device with Android 12 AOSP, which does not need the management of media files. Every time I plug in a USB stick - it gets populated with a bunch of folders like Music, Movies, Podcasts, etc. It is very annoying and not desired functionality. How to modify the AOSP code or parameters to disable this behavior?
I have tried to create .nomedia file in the root - it did not help.
After some research, I found that the default folders' creation is enforced in MediaProvider.java. Use the following patch to disable media folders creation on all external volumes:
diff --git a/packages/providers/MediaProvider/src/com/android/providers/media/MediaProvider.java b/packages/providers/MediaProvider/src/com/android/providers/media/MediaProvider.java
--- a/packages/providers/MediaProvider/src/com/android/providers/media/MediaProvider.java
+++ b/packages/providers/MediaProvider/src/com/android/providers/media/MediaProvider.java
@@ -9382,6 +9382,7 @@ public class MediaProvider extends ContentProvider {
resolver.notifyChange(getBaseContentUri(volumeName), null);
if (LOGV) Log.v(TAG, "Attached volume: " + volume);
+ /* Alex: we do not need creation of default folders
if (!MediaStore.VOLUME_INTERNAL.equals(volumeName)) {
// Also notify on synthetic view of all devices
resolver.notifyChange(getBaseContentUri(MediaStore.VOLUME_EXTERNAL), null);
@@ -9399,6 +9400,7 @@ public class MediaProvider extends ContentProvider {
MediaDocumentsProvider.onMediaStoreReady(getContext(), volumeName);
});
}
+ */
return uri;
}