diff --git a/Clover/app/src/main/AndroidManifest.xml b/Clover/app/src/main/AndroidManifest.xml index b474537e..df4253f1 100644 --- a/Clover/app/src/main/AndroidManifest.xml +++ b/Clover/app/src/main/AndroidManifest.xml @@ -95,6 +95,18 @@ along with this program. If not, see . + + + + + + diff --git a/Clover/app/src/main/java/org/floens/chan/core/cache/FileCacheProvider.java b/Clover/app/src/main/java/org/floens/chan/core/cache/FileCacheProvider.java new file mode 100644 index 00000000..a9eed1b9 --- /dev/null +++ b/Clover/app/src/main/java/org/floens/chan/core/cache/FileCacheProvider.java @@ -0,0 +1,36 @@ +/* + * Clover - 4chan browser https://github.com/Floens/Clover/ + * Copyright (C) 2014 Floens + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.floens.chan.core.cache; + +import android.content.Context; +import android.net.Uri; +import android.support.v4.content.FileProvider; + +import org.floens.chan.utils.AndroidUtils; + +import java.io.File; + +public class FileCacheProvider { + // Same as the one defined in the manifest. + private static final String AUTHORITY = "org.floens.chan.fileprovider"; + + public static Uri getUriForFile(File file) { + Context applicationContext = AndroidUtils.getAppContext(); + return FileProvider.getUriForFile(applicationContext, AUTHORITY, file); + } +} diff --git a/Clover/app/src/main/java/org/floens/chan/core/di/NetModule.java b/Clover/app/src/main/java/org/floens/chan/core/di/NetModule.java index b0f47812..42fa7273 100644 --- a/Clover/app/src/main/java/org/floens/chan/core/di/NetModule.java +++ b/Clover/app/src/main/java/org/floens/chan/core/di/NetModule.java @@ -37,6 +37,11 @@ public class NetModule { } private File getCacheDir(Context applicationContext) { - return applicationContext.getExternalCacheDir() != null ? applicationContext.getExternalCacheDir() : applicationContext.getCacheDir(); + // See also res/xml/filepaths.xml for the fileprovider. + if (applicationContext.getExternalCacheDir() != null) { + return applicationContext.getExternalCacheDir(); + } else { + return applicationContext.getCacheDir(); + } } } diff --git a/Clover/app/src/main/java/org/floens/chan/ui/view/MultiImageView.java b/Clover/app/src/main/java/org/floens/chan/ui/view/MultiImageView.java index a4a5f438..8b5a63f6 100644 --- a/Clover/app/src/main/java/org/floens/chan/ui/view/MultiImageView.java +++ b/Clover/app/src/main/java/org/floens/chan/ui/view/MultiImageView.java @@ -22,9 +22,7 @@ import android.content.ContextWrapper; import android.content.Intent; import android.media.AudioManager; import android.media.MediaPlayer; -import android.net.Uri; import android.os.Build; -import android.os.StrictMode; import android.util.AttributeSet; import android.view.Gravity; import android.view.View; @@ -40,9 +38,10 @@ import com.android.volley.toolbox.ImageLoader.ImageContainer; import com.davemorrissey.labs.subscaleview.ImageSource; import org.floens.chan.R; -import org.floens.chan.core.cache.FileCacheListener; import org.floens.chan.core.cache.FileCache; import org.floens.chan.core.cache.FileCacheDownloader; +import org.floens.chan.core.cache.FileCacheListener; +import org.floens.chan.core.cache.FileCacheProvider; import org.floens.chan.core.model.PostImage; import org.floens.chan.core.settings.ChanSettings; import org.floens.chan.utils.AndroidUtils; @@ -386,16 +385,10 @@ public class MultiImageView extends FrameLayout implements View.OnClickListener private void setVideoFile(final File file) { if (ChanSettings.videoOpenExternal.get()) { Intent intent = new Intent(Intent.ACTION_VIEW); - intent.setDataAndType(Uri.fromFile(file), "video/*"); - - { - StrictMode.VmPolicy vmPolicy = StrictMode.getVmPolicy(); - StrictMode.setVmPolicy(StrictMode.VmPolicy.LAX); + intent.setDataAndType(FileCacheProvider.getUriForFile(file), "video/*"); + intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); - AndroidUtils.openIntent(intent); - - StrictMode.setVmPolicy(vmPolicy); - } + AndroidUtils.openIntent(intent); onModeLoaded(Mode.MOVIE, videoView); } else { diff --git a/Clover/app/src/main/res/xml/file_paths.xml b/Clover/app/src/main/res/xml/file_paths.xml new file mode 100644 index 00000000..13fca269 --- /dev/null +++ b/Clover/app/src/main/res/xml/file_paths.xml @@ -0,0 +1,12 @@ + + + + + + + +