[Android] Fix file deletion on Oreo

Geoffrey Métais git at videolan.org
Tue Dec 19 14:21:44 CET 2017


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Tue Dec 19 14:19:41 2017 +0100| [f783624a55c465d625f2a5a8f3b42ce611e58eb7] | committer: Geoffrey Métais

Fix file deletion on Oreo

Force file deletion if ContentResolver throws SecurityException

> https://code.videolan.org/videolan/vlc-android/commit/f783624a55c465d625f2a5a8f3b42ce611e58eb7
---

 vlc-android/src/org/videolan/vlc/util/FileUtils.java | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/util/FileUtils.java b/vlc-android/src/org/videolan/vlc/util/FileUtils.java
index d4511157f..d840b1646 100644
--- a/vlc-android/src/org/videolan/vlc/util/FileUtils.java
+++ b/vlc-android/src/org/videolan/vlc/util/FileUtils.java
@@ -210,15 +210,14 @@ public class FileUtils {
         path = Uri.decode(Strings.removeFileProtocole(path));
         //Delete from Android Medialib, for consistency with device MTP storing and other apps listing content:// media
         if (AndroidUtil.isHoneycombOrLater){
-            ContentResolver cr = VLCApplication.getAppContext().getContentResolver();
+            final ContentResolver cr = VLCApplication.getAppContext().getContentResolver();
             try {
                 deleted = cr.delete(MediaStore.Files.getContentUri("external"),
                         MediaStore.Files.FileColumns.DATA + "=?", new String[]{path}) > 0;
-            } catch (IllegalArgumentException ignored) {} // Can happen on some devices...
+            } catch (IllegalArgumentException|SecurityException ignored) {} // Can happen on some devices...
         }
         final File file = new File(path);
-        if (file.exists())
-            deleted |= file.delete();
+        if (file.exists()) deleted |= file.delete();
         return deleted;
     }
 



More information about the Android mailing list