diff options
author | Jeff Sharkey <jsharkey@android.com> | 2015-09-24 18:15:13 -0700 |
---|---|---|
committer | Jeff Sharkey <jsharkey@android.com> | 2015-09-25 10:30:07 -0700 |
commit | 307d424467daf82542715c66735daebd87af6dce (patch) | |
tree | 9a49e7756ea28f4e7dcdc6ac92495e30f0c33c08 /packages | |
parent | f02ba4b8ffc44ccbb94ebcf1b70b77fc06af83d4 (diff) | |
download | frameworks_base-307d424467daf82542715c66735daebd87af6dce.zip frameworks_base-307d424467daf82542715c66735daebd87af6dce.tar.gz frameworks_base-307d424467daf82542715c66735daebd87af6dce.tar.bz2 |
Clean stale entries when deleting files.
When deleting files directly from external storage devices, remove
any matching entries from MediaStore so we don't end up showing
stale entries to clients, such as MTP/PTP.
Also handles the case where an entire directory is deleted.
Bug: 24045921
Change-Id: I802470fa1aa03e0bec147ea113f1a49e26a0f3f9
Diffstat (limited to 'packages')
-rw-r--r-- | packages/ExternalStorageProvider/src/com/android/externalstorage/ExternalStorageProvider.java | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/packages/ExternalStorageProvider/src/com/android/externalstorage/ExternalStorageProvider.java b/packages/ExternalStorageProvider/src/com/android/externalstorage/ExternalStorageProvider.java index 393771a..18335b6 100644 --- a/packages/ExternalStorageProvider/src/com/android/externalstorage/ExternalStorageProvider.java +++ b/packages/ExternalStorageProvider/src/com/android/externalstorage/ExternalStorageProvider.java @@ -38,6 +38,7 @@ import android.provider.DocumentsContract; import android.provider.DocumentsContract.Document; import android.provider.DocumentsContract.Root; import android.provider.DocumentsProvider; +import android.provider.MediaStore; import android.text.TextUtils; import android.util.ArrayMap; import android.util.DebugUtils; @@ -380,12 +381,31 @@ public class ExternalStorageProvider extends DocumentsProvider { @Override public void deleteDocument(String docId) throws FileNotFoundException { final File file = getFileForDocId(docId); - if (file.isDirectory()) { + final boolean isDirectory = file.isDirectory(); + if (isDirectory) { FileUtils.deleteContents(file); } if (!file.delete()) { throw new IllegalStateException("Failed to delete " + file); } + + 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() + "/"; + 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 = file.getAbsolutePath(); + resolver.delete(externalUri, + "_data LIKE ?1 AND lower(_data)=lower(?2)", + new String[] { path, path }); } @Override |