Skip to content
Snippets Groups Projects
Commit eafd6a1c authored by akwizgran's avatar akwizgran
Browse files

Merge branch '2143-security-exception-image-loading' into 'master'

Add FLAG_GRANT_READ_URI_PERMISSION when getting content

Closes #2143

See merge request briar/briar!1583
parents a53a49e5 1614e72c
No related branches found
No related tags found
No related merge requests found
...@@ -10,12 +10,14 @@ import androidx.activity.result.contract.ActivityResultContract; ...@@ -10,12 +10,14 @@ import androidx.activity.result.contract.ActivityResultContract;
import androidx.activity.result.contract.ActivityResultContracts.CreateDocument; import androidx.activity.result.contract.ActivityResultContracts.CreateDocument;
import androidx.activity.result.contract.ActivityResultContracts.GetContent; import androidx.activity.result.contract.ActivityResultContracts.GetContent;
import androidx.activity.result.contract.ActivityResultContracts.GetMultipleContents; import androidx.activity.result.contract.ActivityResultContracts.GetMultipleContents;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import static android.app.Activity.RESULT_CANCELED; import static android.app.Activity.RESULT_CANCELED;
import static android.bluetooth.BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE; import static android.bluetooth.BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE;
import static android.bluetooth.BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION; import static android.bluetooth.BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION;
import static android.content.Intent.EXTRA_MIME_TYPES; import static android.content.Intent.EXTRA_MIME_TYPES;
import static android.content.Intent.FLAG_GRANT_READ_URI_PERMISSION;
import static android.os.Build.VERSION.SDK_INT; import static android.os.Build.VERSION.SDK_INT;
import static org.briarproject.bramble.util.AndroidUtils.getSupportedImageContentTypes; import static org.briarproject.bramble.util.AndroidUtils.getSupportedImageContentTypes;
...@@ -23,6 +25,7 @@ import static org.briarproject.bramble.util.AndroidUtils.getSupportedImageConten ...@@ -23,6 +25,7 @@ import static org.briarproject.bramble.util.AndroidUtils.getSupportedImageConten
public class ActivityLaunchers { public class ActivityLaunchers {
public static class CreateDocumentAdvanced extends CreateDocument { public static class CreateDocumentAdvanced extends CreateDocument {
@NonNull
@Override @Override
public Intent createIntent(Context context, String input) { public Intent createIntent(Context context, String input) {
Intent i = super.createIntent(context, input); Intent i = super.createIntent(context, input);
...@@ -32,20 +35,24 @@ public class ActivityLaunchers { ...@@ -32,20 +35,24 @@ public class ActivityLaunchers {
} }
public static class GetContentAdvanced extends GetContent { public static class GetContentAdvanced extends GetContent {
@NonNull
@Override @Override
public Intent createIntent(Context context, String input) { public Intent createIntent(Context context, String input) {
Intent i = super.createIntent(context, input); Intent i = super.createIntent(context, input);
putShowAdvancedExtra(i); putShowAdvancedExtra(i);
i.addFlags(FLAG_GRANT_READ_URI_PERMISSION);
return i; return i;
} }
} }
public static class GetImageAdvanced extends GetContent { public static class GetImageAdvanced extends GetContent {
@NonNull
@Override @Override
public Intent createIntent(Context context, String input) { public Intent createIntent(Context context, String input) {
Intent i = super.createIntent(context, input); Intent i = super.createIntent(context, input);
putShowAdvancedExtra(i); putShowAdvancedExtra(i);
i.setType("image/*"); i.setType("image/*");
i.addFlags(FLAG_GRANT_READ_URI_PERMISSION);
if (SDK_INT >= 19) if (SDK_INT >= 19)
i.putExtra(EXTRA_MIME_TYPES, getSupportedImageContentTypes()); i.putExtra(EXTRA_MIME_TYPES, getSupportedImageContentTypes());
return i; return i;
...@@ -54,11 +61,13 @@ public class ActivityLaunchers { ...@@ -54,11 +61,13 @@ public class ActivityLaunchers {
@TargetApi(18) @TargetApi(18)
public static class GetMultipleImagesAdvanced extends GetMultipleContents { public static class GetMultipleImagesAdvanced extends GetMultipleContents {
@NonNull
@Override @Override
public Intent createIntent(Context context, String input) { public Intent createIntent(Context context, String input) {
Intent i = super.createIntent(context, input); Intent i = super.createIntent(context, input);
putShowAdvancedExtra(i); putShowAdvancedExtra(i);
i.setType("image/*"); i.setType("image/*");
i.addFlags(FLAG_GRANT_READ_URI_PERMISSION);
if (SDK_INT >= 19) if (SDK_INT >= 19)
i.putExtra(EXTRA_MIME_TYPES, getSupportedImageContentTypes()); i.putExtra(EXTRA_MIME_TYPES, getSupportedImageContentTypes());
return i; return i;
...@@ -67,6 +76,7 @@ public class ActivityLaunchers { ...@@ -67,6 +76,7 @@ public class ActivityLaunchers {
public static class RequestBluetoothDiscoverable public static class RequestBluetoothDiscoverable
extends ActivityResultContract<Integer, Boolean> { extends ActivityResultContract<Integer, Boolean> {
@NonNull
@Override @Override
public Intent createIntent(Context context, Integer duration) { public Intent createIntent(Context context, Integer duration) {
Intent i = new Intent(ACTION_REQUEST_DISCOVERABLE); Intent i = new Intent(ACTION_REQUEST_DISCOVERABLE);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment