From e17192105b61934ccb8b34d218e9a60075fc5a58 Mon Sep 17 00:00:00 2001 From: KhabarlakKonstantin Date: Tue, 26 Sep 2017 09:02:11 +0300 Subject: Fix gallery crash when trimming video Fixes FileUriExposedException. Exposing files with Uri.fromFile is forbidden in Nougat Change-Id: Iab48e599f801459fa3db0c9c6f68f1cfd54460c6 --- AndroidManifest.xml | 10 ++++++++++ res/xml/provider_paths.xml | 4 ++++ src/com/android/gallery3d/app/TrimVideo.java | 8 +++++++- 3 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 res/xml/provider_paths.xml diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 7c58e84d5..8a26772e1 100755 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -264,6 +264,16 @@ android:readPermission="org.codeaurora.gallery.filtershow.permission.READ" android:writePermission="org.codeaurora.gallery.filtershow.permission.WRITE" /> + + + + diff --git a/res/xml/provider_paths.xml b/res/xml/provider_paths.xml new file mode 100644 index 000000000..ffa74ab56 --- /dev/null +++ b/res/xml/provider_paths.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/src/com/android/gallery3d/app/TrimVideo.java b/src/com/android/gallery3d/app/TrimVideo.java index ec85de234..ca3acd7ef 100644 --- a/src/com/android/gallery3d/app/TrimVideo.java +++ b/src/com/android/gallery3d/app/TrimVideo.java @@ -1,5 +1,6 @@ /* * Copyright (C) 2012 The Android Open Source Project + * Copyright (C) 2017 The LineageOS Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,6 +29,7 @@ import android.net.Uri; import android.os.Bundle; import android.os.Handler; import android.provider.MediaStore; +import android.support.v4.content.FileProvider; import android.view.View; import android.view.ViewGroup; import android.view.Window; @@ -57,6 +59,7 @@ public class TrimVideo extends Activity implements private Uri mUri; private final Handler mHandler = new Handler(); public static final String TRIM_ACTION = "com.android.camera.action.TRIM"; + private static final String FILE_PROVIDER_AUTHORITY = "com.android.gallery3d.fileprovider"; public ProgressDialog mProgress; @@ -318,7 +321,10 @@ public class TrimVideo extends Activity implements mProgress = null; // Show the result only when the activity not stopped. Intent intent = new Intent(android.content.Intent.ACTION_VIEW); - intent.setDataAndType(Uri.fromFile(mDstFileInfo.mFile), "video/*"); + Uri fileUri = FileProvider.getUriForFile(getApplicationContext(), + FILE_PROVIDER_AUTHORITY, mDstFileInfo.mFile); + intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); + intent.setDataAndType(fileUri, "video/*"); intent.putExtra(MediaStore.EXTRA_FINISH_ON_COMPLETION, false); startActivity(intent); finish(); -- cgit v1.2.3