MCPcopy Create free account
hub / github.com/M66B/FairEmail / NoStreamException

Class NoStreamException

app/src/main/java/eu/faircode/email/NoStreamException.java:38–94  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

36import java.io.FileNotFoundException;
37
38public class NoStreamException extends SecurityException {
39 private Uri uri;
40
41 private NoStreamException(@NonNull Uri uri) {
42 Log.w("Read uri=" + uri);
43 this.uri = uri;
44 }
45
46 static void check(Uri uri, Context context) throws FileNotFoundException {
47 if (uri == null)
48 throw new FileNotFoundException("Selected file");
49
50 if ("content".equals(uri.getScheme()))
51 return;
52 if (Helper.hasPermission(context, Manifest.permission.READ_EXTERNAL_STORAGE))
53 return;
54
55 throw new NoStreamException(uri);
56 }
57
58 void report(Activity context) {
59 if (context == null)
60 return;
61
62 View dview = LayoutInflater.from(context).inflate(R.layout.dialog_no_stream, null);
63
64 TextView tvUri = dview.findViewById(R.id.tvUri);
65 ImageButton ibInfo = dview.findViewById(R.id.ibInfo);
66
67 //tvUri.setText(uri == null ? null : uri.toString());
68 tvUri.setVisibility(View.GONE); // TODO CASA URI
69
70 ibInfo.setOnClickListener(new View.OnClickListener() {
71 @Override
72 public void onClick(View v) {
73 Helper.viewFAQ(v.getContext(), 49);
74 }
75 });
76
77 AlertDialog.Builder builder = new AlertDialog.Builder(context);
78 builder.setView(dview);
79 builder.setNegativeButton(android.R.string.cancel, null);
80
81 // https://developer.android.com/about/versions/13/behavior-changes-13#granular-media-permissions
82 if (Build.VERSION.SDK_INT > Build.VERSION_CODES.M &&
83 Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU)
84 builder.setPositiveButton(R.string.title_setup_grant, new DialogInterface.OnClickListener() {
85 @Override
86 public void onClick(DialogInterface dialogInterface, int i) {
87 String permission = Manifest.permission.READ_EXTERNAL_STORAGE;
88 context.requestPermissions(new String[]{permission}, FragmentBase.REQUEST_PERMISSIONS);
89 }
90 });
91
92 builder.show();
93 }
94}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected