Skip to content

Commit 293962b

Browse files
committed
fix: avoid android.os.strictmode.UnbufferedIoViolation by using BufferedInputStream
- Wrap InputStream with BufferedInputStream to ensure buffered I/O and prevent UnbufferedIoViolation in Android 14 (SDK 34). - Use try-with-resources to automatically close streams, improving resource management. - Retain existing functionality for converting InputStream to a UTF-8 string. This change ensures compliance with Android 14's stricter I/O policies.
1 parent edcea54 commit 293962b

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

firebase-crashlytics/src/main/java/com/google/firebase/crashlytics/internal/common/SessionReportingCoordinator.java

+9-6
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import com.google.firebase.crashlytics.internal.send.DataTransportCrashlyticsReportSender;
3737
import com.google.firebase.crashlytics.internal.settings.SettingsProvider;
3838
import com.google.firebase.crashlytics.internal.stacktrace.StackTraceTrimmingStrategy;
39+
import java.io.BufferedInputStream;
3940
import java.io.ByteArrayOutputStream;
4041
import java.io.File;
4142
import java.io.IOException;
@@ -427,13 +428,15 @@ private static CrashlyticsReport.ApplicationExitInfo convertApplicationExitInfo(
427428
@VisibleForTesting
428429
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
429430
public static String convertInputStreamToString(InputStream inputStream) throws IOException {
430-
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
431-
byte[] bytes = new byte[DEFAULT_BUFFER_SIZE];
432-
int length;
433-
while ((length = inputStream.read(bytes)) != -1) {
434-
byteArrayOutputStream.write(bytes, 0, length);
431+
try (BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStream);
432+
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream()) {
433+
byte[] bytes = new byte[DEFAULT_BUFFER_SIZE];
434+
int length;
435+
while ((length = bufferedInputStream.read(bytes)) != -1) {
436+
byteArrayOutputStream.write(bytes, 0, length);
437+
}
438+
return byteArrayOutputStream.toString(StandardCharsets.UTF_8.name());
435439
}
436-
return byteArrayOutputStream.toString(StandardCharsets.UTF_8.name());
437440
}
438441

439442
/** Finds the first ANR ApplicationExitInfo within the session. */

0 commit comments

Comments
 (0)