mirror of
https://github.com/M66B/FairEmail.git
synced 2026-04-07 17:43:18 +02:00
Check granted URI permisions
This commit is contained in:
@@ -398,6 +398,8 @@ public class ActivitySignature extends ActivityBase {
|
||||
NoStreamException.check(uri, this);
|
||||
|
||||
getContentResolver().takePersistableUriPermission(uri, Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
||||
if (!Helper.isPersisted(this, uri, true, false))
|
||||
throw new IllegalStateException("No permission granted to access selected image " + uri);
|
||||
|
||||
int start = etText.getSelectionStart();
|
||||
if (etText.isRaw())
|
||||
|
||||
@@ -551,6 +551,8 @@ public class FragmentAnswer extends FragmentBase {
|
||||
NoStreamException.check(uri, getContext());
|
||||
|
||||
getContext().getContentResolver().takePersistableUriPermission(uri, Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
||||
if (!Helper.isPersisted(getContext(), uri, true, false))
|
||||
throw new IllegalStateException("No permission granted to access selected image " + uri);
|
||||
|
||||
int start = etText.getSelectionStart();
|
||||
SpannableStringBuilder ssb = new SpannableStringBuilderEx(etText.getText());
|
||||
|
||||
@@ -797,6 +797,9 @@ public class FragmentOptionsNotifications extends FragmentBase implements Shared
|
||||
if ("content".equals(uri.getScheme())) {
|
||||
try {
|
||||
getContext().getContentResolver().takePersistableUriPermission(uri, Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
||||
if (!Helper.isPersisted(getContext(), uri, true, false))
|
||||
Log.unexpectedError(getParentFragmentManager(),
|
||||
new IllegalStateException("No permission granted to access selected sound " + uri));
|
||||
} catch (Throwable ex) {
|
||||
Log.w(ex);
|
||||
}
|
||||
|
||||
@@ -817,6 +817,9 @@ public class FragmentOptionsSend extends FragmentBase implements SharedPreferenc
|
||||
if ("content".equals(uri.getScheme())) {
|
||||
try {
|
||||
getContext().getContentResolver().takePersistableUriPermission(uri, Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
||||
if (!Helper.isPersisted(getContext(), uri, true, false))
|
||||
Log.unexpectedError(getParentFragmentManager(),
|
||||
new IllegalStateException("No permission granted to access selected sound " + uri));
|
||||
} catch (Throwable ex) {
|
||||
Log.w(ex);
|
||||
}
|
||||
|
||||
@@ -41,6 +41,7 @@ import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.UriPermission;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
@@ -2611,6 +2612,23 @@ public class Helper {
|
||||
return (Looper.myLooper() == Looper.getMainLooper());
|
||||
}
|
||||
|
||||
static boolean isPersisted(Context context, Uri uri, boolean read, boolean write) {
|
||||
try {
|
||||
List<UriPermission> uperms = context.getContentResolver().getPersistedUriPermissions();
|
||||
for (UriPermission uperm : uperms)
|
||||
if (uperm.getUri().equals(uri)) {
|
||||
boolean canRead = uperm.isReadPermission();
|
||||
boolean canWrite = uperm.isWritePermission();
|
||||
Log.i(uri + " read=" + read + "/" + canRead + " write=" + write + "/" + canWrite);
|
||||
return (!read || canRead) && (!write || canWrite);
|
||||
}
|
||||
return false;
|
||||
} catch (Throwable ex) {
|
||||
Log.e(ex);
|
||||
return !BuildConfig.DEBUG;
|
||||
}
|
||||
}
|
||||
|
||||
// Cryptography
|
||||
|
||||
static String sha256(String data) throws NoSuchAlgorithmException {
|
||||
|
||||
Reference in New Issue
Block a user