Use FileProvider for external camera capture Uri on L+

Fixes #7237
This commit is contained in:
Moxie Marlinspike 2017-12-01 11:02:30 -08:00
parent 4932171bbf
commit 4cb2ac7b27
5 changed files with 41 additions and 3 deletions

View File

@ -524,6 +524,15 @@
android:exported="false"
android:authorities="org.thoughtcrime.provider.securesms.mms" />
<provider android:name="android.support.v4.content.FileProvider"
android:authorities="org.thoughtcrime.securesms.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/file_provider_paths" />
</provider>
<receiver android:name=".service.BootReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<paths>
<external-cache-path name="external_cache" path="." />
</paths>

View File

@ -50,6 +50,7 @@ import org.thoughtcrime.securesms.util.BitmapDecodingException;
import org.thoughtcrime.securesms.util.BitmapUtil;
import org.thoughtcrime.securesms.util.DynamicLanguage;
import org.thoughtcrime.securesms.util.DynamicTheme;
import org.thoughtcrime.securesms.util.FileProviderUtil;
import org.thoughtcrime.securesms.util.IntentUtils;
import org.thoughtcrime.securesms.util.TextSecurePreferences;
import org.thoughtcrime.securesms.util.Util;
@ -376,7 +377,7 @@ public class CreateProfileActivity extends BaseActionBarActivity implements Inje
Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (captureFile != null && cameraIntent.resolveActivity(getPackageManager()) != null) {
cameraIntent.putExtra(EXTRA_OUTPUT, Uri.fromFile(captureFile));
cameraIntent.putExtra(EXTRA_OUTPUT, FileProviderUtil.getUriFor(this, captureFile));
extraIntents.add(cameraIntent);
}
}

View File

@ -5,8 +5,10 @@ import android.content.ContentUris;
import android.content.Context;
import android.content.UriMatcher;
import android.net.Uri;
import android.os.Build;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.content.FileProvider;
import android.util.Log;
import android.webkit.MimeTypeMap;
@ -14,6 +16,7 @@ import org.thoughtcrime.securesms.crypto.DecryptingPartInputStream;
import org.thoughtcrime.securesms.crypto.EncryptingPartOutputStream;
import org.thoughtcrime.securesms.crypto.MasterCipher;
import org.thoughtcrime.securesms.crypto.MasterSecret;
import org.thoughtcrime.securesms.util.FileProviderUtil;
import org.thoughtcrime.securesms.util.Util;
import org.whispersystems.libsignal.InvalidMessageException;
@ -128,8 +131,8 @@ public class PersistentBlobProvider {
}
public Uri createForExternal(@NonNull String mimeType) throws IOException {
return Uri.fromFile(new File(getExternalDir(context),
String.valueOf(System.currentTimeMillis()) + "." + getExtensionFromMimeType(mimeType)));
File target = new File(getExternalDir(context), String.valueOf(System.currentTimeMillis()) + "." + getExtensionFromMimeType(mimeType));
return FileProviderUtil.getUriFor(context, target);
}
public boolean delete(@NonNull Uri uri) {

View File

@ -0,0 +1,21 @@
package org.thoughtcrime.securesms.util;
import android.content.Context;
import android.net.Uri;
import android.os.Build;
import android.support.annotation.NonNull;
import android.support.v4.content.FileProvider;
import java.io.File;
public class FileProviderUtil {
private static final String AUTHORITY = "org.thoughtcrime.securesms.fileprovider";
public static Uri getUriFor(@NonNull Context context, @NonNull File file) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) return FileProvider.getUriForFile(context, AUTHORITY, file);
else return Uri.fromFile(file);
}
}