Merge "Create the .nomedia file in paths that are not scannable" into rvc-dev
diff --git a/src/com/android/providers/media/scan/ModernMediaScanner.java b/src/com/android/providers/media/scan/ModernMediaScanner.java
index 9023400..845602b 100644
--- a/src/com/android/providers/media/scan/ModernMediaScanner.java
+++ b/src/com/android/providers/media/scan/ModernMediaScanner.java
@@ -1400,9 +1400,13 @@
         }
 
         if (PATTERN_INVISIBLE.matcher(dir.getAbsolutePath()).matches()) {
-            // .nomedia in this directory is pointless, .nomedia doesn't determine if the directory
-            // should be scanned.
-            nomedia.delete();
+            // Create the .nomedia file in paths that are not scannable. This is useful when user
+            // ejects the SD card and brings it to an older device and its media scanner can
+            // now correctly identify these paths as not scannable.
+            try {
+                nomedia.createNewFile();
+            } catch (IOException ignored) {
+            }
             return false;
         }
         return true;