Commit 235df0dc authored by Mike Lockwood's avatar Mike Lockwood
Browse files

DO NOT MERGE Run media scanner when secondary external volumes are mounted or unmounted


This will add/remove database entries for files on secondary volumes
when the volume is added/removed.

Change-Id: I24e1059dcf1b3c04d95e03c03b736e214c8fbff4
Signed-off-by: default avatarMike Lockwood <lockwood@android.com>
parent d3709e80
......@@ -22,6 +22,10 @@
<action android:name="android.intent.action.MEDIA_MOUNTED" />
<data android:scheme="file" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.MEDIA_UNMOUNTED" />
<data android:scheme="file" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.MEDIA_SCANNER_SCAN_FILE" />
<data android:scheme="file" />
......
......@@ -36,8 +36,6 @@ public class MediaScannerReceiver extends BroadcastReceiver
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
Uri uri = intent.getData();
String externalStoragePath = Environment.getExternalStorageDirectory().getPath();
if (action.equals(Intent.ACTION_BOOT_COMPLETED)) {
// scan internal storage
scan(context, MediaProvider.INTERNAL_VOLUME);
......@@ -45,8 +43,16 @@ public class MediaScannerReceiver extends BroadcastReceiver
if (uri.getScheme().equals("file")) {
// handle intents related to external storage
String path = uri.getPath();
if (action.equals(Intent.ACTION_MEDIA_MOUNTED) &&
externalStoragePath.equals(path)) {
String externalStoragePath = Environment.getExternalStorageDirectory().getPath();
Log.d(TAG, "action: " + action + " path: " + path);
if (action.equals(Intent.ACTION_MEDIA_MOUNTED)) {
// scan whenever any volume is mounted
scan(context, MediaProvider.EXTERNAL_VOLUME);
} else if (action.equals(Intent.ACTION_MEDIA_UNMOUNTED)
&& !externalStoragePath.equals(path)) {
// scan when any volume other than the primary volume is unmounted
// this will remove files for that volume from the database
scan(context, MediaProvider.EXTERNAL_VOLUME);
} else if (action.equals(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE) &&
path != null && path.startsWith(externalStoragePath + "/")) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment