SnapdragonGallery:Add FileProvider
Add a FileProvider to provide Uri of
files to avoid FileUriExposedException
when target sdk level is above 24.
Change-Id: I05f651c97733d27e5ba42065130dcc0ff963a073
CRs-Fixed: 2296203
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index fdc7635..25371f9 100755
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -316,6 +316,15 @@
android:authorities="com.android.gallery3d.photoprovider"
android:syncable="false"
android:exported="false"/>
+ <provider
+ android:name="android.support.v4.content.FileProvider"
+ android:authorities="com.android.gallery3d.fileprovider"
+ android:exported="false"
+ android:grantUriPermissions="true">
+ <meta-data
+ android:name="android.support.FILE_PROVIDER_PATHS"
+ android:resource="@xml/provider_paths"/>
+ </provider>
<activity
android:name="com.android.gallery3d.gadget.WidgetClickHandler"
android:theme="@android:style/Theme.NoDisplay" />
diff --git a/res/xml/provider_paths.xml b/res/xml/provider_paths.xml
new file mode 100755
index 0000000..9031aef
--- /dev/null
+++ b/res/xml/provider_paths.xml
@@ -0,0 +1,31 @@
+<!--
+ * Copyright (c) 2018, The Linux Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ * * Neither the name of The Linux Foundation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+ * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ -->
+<paths xmlns:android="http://schemas.android.com/apk/res/android">
+ <external-path name="external_files" path="."/>
+</paths>
\ No newline at end of file
diff --git a/src/com/android/gallery3d/app/MuteVideo.java b/src/com/android/gallery3d/app/MuteVideo.java
index bbb9fca..3b42267 100755
--- a/src/com/android/gallery3d/app/MuteVideo.java
+++ b/src/com/android/gallery3d/app/MuteVideo.java
@@ -30,6 +30,7 @@
import com.android.gallery3d.data.MediaItem;
import com.android.gallery3d.util.SaveVideoFileInfo;
import com.android.gallery3d.util.SaveVideoFileUtils;
+import android.support.v4.content.FileProvider;
import java.io.IOException;
@@ -122,8 +123,12 @@
// 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/*");
+ intent.setDataAndType(
+ FileProvider.getUriForFile(mActivity,
+ "com.android.gallery3d.fileprovider",
+ mDstFileInfo.mFile), "video/*");
intent.putExtra(MediaStore.EXTRA_FINISH_ON_COMPLETION, false);
+ intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
mActivity.startActivity(intent);
}
}
diff --git a/src/com/android/gallery3d/app/TrimVideo.java b/src/com/android/gallery3d/app/TrimVideo.java
old mode 100644
new mode 100755
index ec85de2..8daf398
--- a/src/com/android/gallery3d/app/TrimVideo.java
+++ b/src/com/android/gallery3d/app/TrimVideo.java
@@ -35,6 +35,7 @@
import android.widget.TextView;
import android.widget.Toast;
import android.widget.VideoView;
+import android.support.v4.content.FileProvider;
import org.codeaurora.gallery.R;
import com.android.gallery3d.util.SaveVideoFileInfo;
@@ -42,6 +43,7 @@
import java.io.File;
import java.io.IOException;
+import java.net.URI;
public class TrimVideo extends Activity implements
MediaPlayer.OnErrorListener,
@@ -318,8 +320,12 @@
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/*");
+ intent.setDataAndType(
+ FileProvider.getUriForFile(mContext,
+ "com.android.gallery3d.fileprovider",
+ mDstFileInfo.mFile), "video/*");
intent.putExtra(MediaStore.EXTRA_FINISH_ON_COMPLETION, false);
+ intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(intent);
finish();
}