[Android] Fix file deletion on Oreo

Geoffrey Métais git at videolan.org
Wed Dec 20 17:10:08 CET 2017


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

Fix file deletion on Oreo

Force file deletion if ContentResolver throws SecurityException

(cherry picked from commit f783624a55c465d625f2a5a8f3b42ce611e58eb7)

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

 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 7c65af35c..cf3103dad 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