Merge "Use visible paths when cleaning up MediaStore." into nyc-mr1-dev

This commit is contained in:
TreeHugger Robot
2016-07-08 19:01:08 +00:00
committed by Android (Google) Code Review

View File

@@ -492,23 +492,26 @@ public class ExternalStorageProvider extends DocumentsProvider {
throw new IllegalStateException("Failed to delete " + file); throw new IllegalStateException("Failed to delete " + file);
} }
final ContentResolver resolver = getContext().getContentResolver(); final File visibleFile = getFileForDocId(docId, true);
final Uri externalUri = MediaStore.Files.getContentUri("external"); 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 // Remove media store entries for any files inside this directory, using
// path prefix match. Logic borrowed from MtpDatabase. // path prefix match. Logic borrowed from MtpDatabase.
if (isDirectory) { if (isDirectory) {
final String path = file.getAbsolutePath() + "/"; 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, resolver.delete(externalUri,
"_data LIKE ?1 AND lower(substr(_data,1,?2))=lower(?3)", "_data LIKE ?1 AND lower(_data)=lower(?2)",
new String[] { path + "%", Integer.toString(path.length()), path }); 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 @Override