[Android] File deletion: prevent crash

Geoffrey Métais git at videolan.org
Fri Mar 2 10:22:20 CET 2018


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Fri Mar  2 10:19:41 2018 +0100| [ef7f9213b5a9e61eb127865596e476b9f0e44839] | committer: Geoffrey Métais

File deletion: prevent crash

Also, normal delete method for pre-Lollipop devices

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

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

diff --git a/vlc-android/src/org/videolan/vlc/util/FileUtils.java b/vlc-android/src/org/videolan/vlc/util/FileUtils.java
index 10fcac1b5..c01401b64 100644
--- a/vlc-android/src/org/videolan/vlc/util/FileUtils.java
+++ b/vlc-android/src/org/videolan/vlc/util/FileUtils.java
@@ -210,10 +210,14 @@ public class FileUtils {
         }
         return ret;
     }
-    public static boolean deleteFile (Uri uri){
-        if (uri.getPath().startsWith(AndroidDevices.EXTERNAL_PUBLIC_DIRECTORY)) return deleteFile(uri.getPath());
+    public static boolean deleteFile (Uri uri) {
+        if (!AndroidUtil.isLolliPopOrLater || uri.getPath().startsWith(AndroidDevices.EXTERNAL_PUBLIC_DIRECTORY)) return deleteFile(uri.getPath());
         final DocumentFile docFile = FileUtils.findFile(uri);
-        return docFile != null && docFile.delete();
+        if (docFile != null) try {
+            return docFile.delete();
+        } catch (Exception ignored) {
+            return false;
+        }
     }
 
     @TargetApi(Build.VERSION_CODES.HONEYCOMB)



More information about the Android mailing list