Gallery2 视频静音功能 闪退 exposed beyond app through Intent.getData()

南宫奇思
2023-12-01

具体的错误log如下

--------- beginning of crash
03-22 19:19:17.950 E/AndroidRuntime( 5809): FATAL EXCEPTION: main
03-22 19:19:17.950 E/AndroidRuntime( 5809): Process: com.android.gallery3d, PID: 5809
03-22 19:19:17.950 E/AndroidRuntime( 5809): android.os.FileUriExposedException: file:///storage/emulated/0/DCIM/Camera/MUTE_20210322_191916.mp4 exposed beyond app through Intent.getData()
03-22 19:19:17.950 E/AndroidRuntime( 5809):  at android.os.StrictMode.onFileUriExposed(StrictMode.java:2141)
03-22 19:19:17.950 E/AndroidRuntime( 5809):  at android.net.Uri.checkFileUriExposed(Uri.java:2391)
03-22 19:19:17.950 E/AndroidRuntime( 5809):  at android.content.Intent.prepareToLeaveProcess(Intent.java:11165)
03-22 19:19:17.950 E/AndroidRuntime( 5809):  at android.content.Intent.prepareToLeaveProcess(Intent.java:11116)
03-22 19:19:17.950 E/AndroidRuntime( 5809):  at android.app.Instrumentation.execStartActivity(Instrumentation.java:1724)
03-22 19:19:17.950 E/AndroidRuntime( 5809):  at android.app.Activity.startActivityForResult(Activity.java:5320)
03-22 19:19:17.950 E/AndroidRuntime( 5809):  at android.app.Activity.startActivityForResult(Activity.java:5278)
03-22 19:19:17.950 E/AndroidRuntime( 5809):  at android.app.Activity.startActivity(Activity.java:5664)
03-22 19:19:17.950 E/AndroidRuntime( 5809):  at android.app.Activity.startActivity(Activity.java:5617)
03-22 19:19:17.950 E/AndroidRuntime( 5809):  at com.android.gallery3d.app.MuteVideo$1$1.run(MuteVideo.java:88)
03-22 19:19:17.950 E/AndroidRuntime( 5809):  at android.os.Handler.handleCallback(Handler.java:938)
03-22 19:19:17.950 E/AndroidRuntime( 5809):  at android.os.Handler.dispatchMessage(Handler.java:99)
03-22 19:19:17.950 E/AndroidRuntime( 5809):  at android.os.Looper.loop(Looper.java:223)
03-22 19:19:17.950 E/AndroidRuntime( 5809):  at android.app.ActivityThread.main(ActivityThread.java:7697)
03-22 19:19:17.950 E/AndroidRuntime( 5809):  at java.lang.reflect.Method.invoke(Native Method)
03-22 19:19:17.950 E/AndroidRuntime( 5809):  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
03-22 19:19:17.950 E/AndroidRuntime( 5809):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:952)
03-22 19:19:17.960 I/DropBoxManagerService(25714): add tag=system_app_crash isTagEnabled=true flags=0x2

修改patch

diff --git a/packages/apps/Gallery2/AndroidManifest.xml b/packages/apps/Gallery2/AndroidManifest.xml
old mode 100644
new mode 100755
index a08b2bc..eb5409e
--- a/packages/apps/Gallery2/AndroidManifest.xml
+++ b/packages/apps/Gallery2/AndroidManifest.xml
@@ -344,5 +344,16 @@
         </receiver>
 
         <service android:name="com.android.camera.MediaSaveService" />
+        <!--jicong.wang modify for bug 19801 start {@-->
+        <provider
+            android:name="androidx.core.content.FileProvider"
+            android:authorities="com.android.gallery3d.files"
+            android:grantUriPermissions="true"
+            android:exported="false">
+            <meta-data
+                android:name="android.support.FILE_PROVIDER_PATHS"
+                android:resource="@xml/file_paths" />
+        </provider>
+        <!--jicong.wang modify for bug 19801 end @}-->
     </application>
 </manifest>
diff --git a/packages/apps/Gallery2/res/xml/file_paths.xml b/packages/apps/Gallery2/res/xml/file_paths.xml
new file mode 100755
index 0000000..cb312f6
--- /dev/null
+++ b/packages/apps/Gallery2/res/xml/file_paths.xml
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2013 The Android Open Source Project
+
+     Licensed under the Apache License, Version 2.0 (the "License");
+     you may not use this file except in compliance with the License.
+     You may obtain a copy of the License at
+
+          http://www.apache.org/licenses/LICENSE-2.0
+
+     Unless required by applicable law or agreed to in writing, software
+     distributed under the License is distributed on an "AS IS" BASIS,
+     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+     See the License for the specific language governing permissions and
+     limitations under the License.
+-->
+
+<paths xmlns:android="http://schemas.android.com/apk/res/android">
+    <!-- Offer access to files under Context.getCacheDir() -->
+    <external-path name="external_files" path="."/>
+</paths>
diff --git a/packages/apps/Gallery2/src/com/android/gallery3d/app/MuteVideo.java b/packages/apps/Gallery2/src/com/android/gallery3d/app/MuteVideo.java
old mode 100644
new mode 100755
index d3f3aa5..9d56f5a
--- a/packages/apps/Gallery2/src/com/android/gallery3d/app/MuteVideo.java
+++ b/packages/apps/Gallery2/src/com/android/gallery3d/app/MuteVideo.java
@@ -28,7 +28,9 @@ import com.android.gallery3d.R;
 import com.android.gallery3d.data.MediaItem;
 import com.android.gallery3d.util.SaveVideoFileInfo;
 import com.android.gallery3d.util.SaveVideoFileUtils;
-
+/*jicong.wang modify for bug 19801 start {@*/
+import androidx.core.content.FileProvider;
+/*jicong.wang modify for bug 19801 end @}*/
 import java.io.IOException;
 
 public class MuteVideo {
@@ -83,7 +85,11 @@ public class MuteVideo {
                             // 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/*");
+                            /*jicong.wang modify for bug 19801 start {@*/
+                            intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
+                            Uri uri = FileProvider.getUriForFile(mActivity, mActivity.getPackageName() + ".files", mDstFileInfo.mFile);
+                            intent.setDataAndType(uri, "video/*");
+                            /*jicong.wang modify for bug 19801 end @}*/
                             intent.putExtra(MediaStore.EXTRA_FINISH_ON_COMPLETION, false);
                             mActivity.startActivity(intent);
                         }
 类似资料: