diff --git a/app/src/main/java/eu/faircode/email/ActivityEML.java b/app/src/main/java/eu/faircode/email/ActivityEML.java index 55a3b0c4f6..8507bacb9c 100644 --- a/app/src/main/java/eu/faircode/email/ActivityEML.java +++ b/app/src/main/java/eu/faircode/email/ActivityEML.java @@ -27,7 +27,6 @@ import android.content.Intent; import android.content.res.AssetFileDescriptor; import android.net.Uri; import android.os.Bundle; -import android.os.ParcelFileDescriptor; import android.text.Spanned; import android.text.TextUtils; import android.text.method.LinkMovementMethod; @@ -305,14 +304,10 @@ public class ActivityEML extends ActivityBase { throw new IllegalArgumentException(context.getString(R.string.title_no_stream)); } - ParcelFileDescriptor pfd = null; OutputStream os = null; InputStream is; try { - pfd = getContentResolver().openFileDescriptor(uri, "w"); - if (pfd == null) - throw new FileNotFoundException(uri.toString()); - os = new FileOutputStream(pfd.getFileDescriptor()); + os = getContentResolver().openOutputStream(uri); is = apart.part.getInputStream(); byte[] buffer = new byte[Helper.BUFFER_SIZE]; @@ -320,12 +315,6 @@ public class ActivityEML extends ActivityBase { while ((read = is.read(buffer)) != -1) os.write(buffer, 0, read); } finally { - try { - if (pfd != null) - pfd.close(); - } catch (Throwable ex) { - Log.w(ex); - } try { if (os != null) os.close(); diff --git a/app/src/main/java/eu/faircode/email/FragmentBase.java b/app/src/main/java/eu/faircode/email/FragmentBase.java index c4a36798bc..5d6102bf77 100644 --- a/app/src/main/java/eu/faircode/email/FragmentBase.java +++ b/app/src/main/java/eu/faircode/email/FragmentBase.java @@ -33,7 +33,6 @@ import android.net.Uri; import android.os.Build; import android.os.Bundle; import android.os.Handler; -import android.os.ParcelFileDescriptor; import android.text.TextUtils; import android.view.LayoutInflater; import android.view.View; @@ -58,7 +57,6 @@ import androidx.localbroadcastmanager.content.LocalBroadcastManager; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; -import java.io.FileOutputStream; import java.io.InputStream; import java.io.OutputStream; import java.util.HashMap; @@ -437,14 +435,10 @@ public class FragmentBase extends Fragment { return null; File file = attachment.getFile(context); - ParcelFileDescriptor pfd = null; OutputStream os = null; InputStream is = null; try { - pfd = context.getContentResolver().openFileDescriptor(uri, "w"); - if (pfd == null) - throw new FileNotFoundException(uri.toString()); - os = new FileOutputStream(pfd.getFileDescriptor()); + os = context.getContentResolver().openOutputStream(uri); is = new FileInputStream(file); byte[] buffer = new byte[Helper.BUFFER_SIZE]; @@ -452,12 +446,6 @@ public class FragmentBase extends Fragment { while ((read = is.read(buffer)) != -1) os.write(buffer, 0, read); } finally { - try { - if (pfd != null) - pfd.close(); - } catch (Throwable ex) { - Log.w(ex); - } try { if (os != null) os.close(); @@ -527,14 +515,10 @@ public class FragmentBase extends Fragment { if (document == null) throw new FileNotFoundException("Could not save " + uri + ":" + name); - ParcelFileDescriptor pfd = null; OutputStream os = null; InputStream is = null; try { - pfd = context.getContentResolver().openFileDescriptor(document.getUri(), "w"); - if (pfd == null) - throw new FileNotFoundException(name); - os = new FileOutputStream(pfd.getFileDescriptor()); + os = context.getContentResolver().openOutputStream(uri); is = new FileInputStream(file); byte[] buffer = new byte[Helper.BUFFER_SIZE]; @@ -542,12 +526,6 @@ public class FragmentBase extends Fragment { while ((read = is.read(buffer)) != -1) os.write(buffer, 0, read); } finally { - try { - if (pfd != null) - pfd.close(); - } catch (Throwable ex) { - Log.w(ex); - } try { if (os != null) os.close(); diff --git a/app/src/main/java/eu/faircode/email/FragmentMessages.java b/app/src/main/java/eu/faircode/email/FragmentMessages.java index 8721ce4097..8e85739f2d 100644 --- a/app/src/main/java/eu/faircode/email/FragmentMessages.java +++ b/app/src/main/java/eu/faircode/email/FragmentMessages.java @@ -47,7 +47,6 @@ import android.net.Uri; import android.os.Build; import android.os.Bundle; import android.os.Parcel; -import android.os.ParcelFileDescriptor; import android.os.Parcelable; import android.print.PrintAttributes; import android.print.PrintDocumentAdapter; @@ -5629,14 +5628,10 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences. File file = message.getRawFile(context); Log.i("Raw file=" + file); - ParcelFileDescriptor pfd = null; OutputStream os = null; InputStream is = null; try { - pfd = context.getContentResolver().openFileDescriptor(uri, "w"); - if (pfd == null) - throw new FileNotFoundException(uri.toString()); - os = new FileOutputStream(pfd.getFileDescriptor()); + os = context.getContentResolver().openOutputStream(uri); is = new FileInputStream(file); byte[] buffer = new byte[Helper.BUFFER_SIZE]; @@ -5644,12 +5639,6 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences. while ((read = is.read(buffer)) != -1) os.write(buffer, 0, read); } finally { - try { - if (pfd != null) - pfd.close(); - } catch (Throwable ex) { - Log.w(ex); - } try { if (os != null) os.close();