From 813f9e8323e60abcaa77cc21af18614303313b22 Mon Sep 17 00:00:00 2001 From: Jeff Sharkey Date: Fri, 8 Jul 2016 11:06:58 -0600 Subject: [PATCH] Use visible paths when cleaning up MediaStore. The media scanner always records visible paths, so we need to use visible paths when cleaning up deleted records. Bug: 28581384 Change-Id: I8a2c65001216e4a96b2375579363a771de782bcc --- .../ExternalStorageProvider.java | 31 ++++++++++--------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/packages/ExternalStorageProvider/src/com/android/externalstorage/ExternalStorageProvider.java b/packages/ExternalStorageProvider/src/com/android/externalstorage/ExternalStorageProvider.java index 62f33bf490a85..a3070bddd0f81 100644 --- a/packages/ExternalStorageProvider/src/com/android/externalstorage/ExternalStorageProvider.java +++ b/packages/ExternalStorageProvider/src/com/android/externalstorage/ExternalStorageProvider.java @@ -492,23 +492,26 @@ public class ExternalStorageProvider extends DocumentsProvider { throw new IllegalStateException("Failed to delete " + file); } - final ContentResolver resolver = getContext().getContentResolver(); - final Uri externalUri = MediaStore.Files.getContentUri("external"); + final File visibleFile = getFileForDocId(docId, true); + if (visibleFile != null) { + final ContentResolver resolver = getContext().getContentResolver(); + final Uri externalUri = MediaStore.Files.getContentUri("external"); - // Remove media store entries for any files inside this directory, using - // path prefix match. Logic borrowed from MtpDatabase. - if (isDirectory) { - final String path = file.getAbsolutePath() + "/"; + // Remove media store entries for any files inside this directory, using + // path prefix match. Logic borrowed from MtpDatabase. + if (isDirectory) { + final String path = visibleFile.getAbsolutePath() + "/"; + resolver.delete(externalUri, + "_data LIKE ?1 AND lower(substr(_data,1,?2))=lower(?3)", + new String[] { path + "%", Integer.toString(path.length()), path }); + } + + // Remove media store entry for this exact file. + final String path = visibleFile.getAbsolutePath(); resolver.delete(externalUri, - "_data LIKE ?1 AND lower(substr(_data,1,?2))=lower(?3)", - new String[] { path + "%", Integer.toString(path.length()), path }); + "_data LIKE ?1 AND lower(_data)=lower(?2)", + new String[] { path, path }); } - - // Remove media store entry for this exact file. - final String path = file.getAbsolutePath(); - resolver.delete(externalUri, - "_data LIKE ?1 AND lower(_data)=lower(?2)", - new String[] { path, path }); } @Override