Skip to content

Use BufferedOutputStream to prevent StrictMode violations #4538

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 6, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
import com.google.firebase.annotations.concurrent.Background;
import com.google.firebase.appdistribution.FirebaseAppDistributionException;
import com.google.firebase.appdistribution.FirebaseAppDistributionException.Status;
import java.io.BufferedOutputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.concurrent.Executor;

Expand Down Expand Up @@ -141,7 +141,7 @@ private Uri writeToFile(@Nullable Bitmap bitmap) throws FirebaseAppDistributionE
// First delete the previous file if it's still there
deleteScreenshot();

try (FileOutputStream outputStream = openFileOutputStream()) {
try (BufferedOutputStream outputStream = openFileOutputStream()) {
// PNG is a lossless format, the compression factor (100) is ignored
bitmap.compress(Bitmap.CompressFormat.PNG, /* quality= */ 100, outputStream);
} catch (IOException e) {
Expand All @@ -157,9 +157,10 @@ void deleteScreenshot() {
firebaseApp.getApplicationContext().deleteFile(SCREENSHOT_FILE_NAME);
}

private FileOutputStream openFileOutputStream() throws FileNotFoundException {
return firebaseApp
.getApplicationContext()
.openFileOutput(SCREENSHOT_FILE_NAME, Context.MODE_PRIVATE);
private BufferedOutputStream openFileOutputStream() throws FileNotFoundException {
return new BufferedOutputStream(
firebaseApp
.getApplicationContext()
.openFileOutput(SCREENSHOT_FILE_NAME, Context.MODE_PRIVATE));
}
}