diff options
-rw-r--r-- | src/com/android/providers/downloads/DownloadProvider.java | 30 | ||||
-rw-r--r-- | src/com/android/providers/downloads/Helpers.java | 4 |
2 files changed, 11 insertions, 23 deletions
diff --git a/src/com/android/providers/downloads/DownloadProvider.java b/src/com/android/providers/downloads/DownloadProvider.java index d9acc789..94e5a997 100644 --- a/src/com/android/providers/downloads/DownloadProvider.java +++ b/src/com/android/providers/downloads/DownloadProvider.java @@ -715,13 +715,7 @@ public final class DownloadProvider extends ContentProvider { throw new IllegalArgumentException("Invalid file URI: " + uri); } - final File file; - try { - file = new File(path).getCanonicalFile(); - } catch (IOException e) { - throw new SecurityException(e); - } - + final File file = new File(path); if (Helpers.isFilenameValidInExternalPackage(getContext(), file, getCallingPackage())) { // No permissions required for paths belonging to calling package return; @@ -1197,14 +1191,10 @@ public final class DownloadProvider extends ContentProvider { final String path = cursor.getString(1); if (!TextUtils.isEmpty(path)) { - try { - final File file = new File(path).getCanonicalFile(); - if (Helpers.isFilenameValid(getContext(), file)) { - Log.v(Constants.TAG, - "Deleting " + file + " via provider delete"); - file.delete(); - } - } catch (IOException ignored) { + final File file = new File(path); + if (Helpers.isFilenameValid(getContext(), file)) { + Log.v(Constants.TAG, "Deleting " + file + " via provider delete"); + file.delete(); } } } @@ -1270,15 +1260,9 @@ public final class DownloadProvider extends ContentProvider { throw new FileNotFoundException("No filename found."); } - final File file; - try { - file = new File(path).getCanonicalFile(); - } catch (IOException e) { - throw new FileNotFoundException(e.getMessage()); - } - + final File file = new File(path); if (!Helpers.isFilenameValid(getContext(), file)) { - throw new FileNotFoundException("Invalid file path: " + file); + throw new FileNotFoundException("Invalid file: " + file); } final int pfdMode = ParcelFileDescriptor.parseMode(mode); diff --git a/src/com/android/providers/downloads/Helpers.java b/src/com/android/providers/downloads/Helpers.java index d01cbff2..d1cc5450 100644 --- a/src/com/android/providers/downloads/Helpers.java +++ b/src/com/android/providers/downloads/Helpers.java @@ -357,6 +357,8 @@ public class Helpers { static boolean isFilenameValidInExternalPackage(Context context, File file, String packageName) { try { + file = file.getCanonicalFile(); + if (containsCanonical(buildExternalStorageAppFilesDirs(packageName), file) || containsCanonical(buildExternalStorageAppObbDirs(packageName), file) || containsCanonical(buildExternalStorageAppCacheDirs(packageName), file) || @@ -378,6 +380,8 @@ public class Helpers { */ static boolean isFilenameValid(Context context, File file, boolean allowInternal) { try { + file = file.getCanonicalFile(); + if (allowInternal) { if (containsCanonical(context.getFilesDir(), file) || containsCanonical(context.getCacheDir(), file) |