Skip to content

Commit 37aecfd

Browse files
authored
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 37f8134 commit 37aecfd

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -419,13 +419,15 @@ private static CrashlyticsReport.ApplicationExitInfo convertApplicationExitInfo(
419419
@VisibleForTesting
420420
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
421421
public static String convertInputStreamToString(InputStream inputStream) throws IOException {
422-
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
423-
byte[] bytes = new byte[DEFAULT_BUFFER_SIZE];
424-
int length;
425-
while ((length = inputStream.read(bytes)) != -1) {
426-
byteArrayOutputStream.write(bytes, 0, length);
422+
try (BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStream);
423+
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream()) {
424+
byte[] bytes = new byte[DEFAULT_BUFFER_SIZE];
425+
int length;
426+
while ((length = bufferedInputStream.read(bytes)) != -1) {
427+
byteArrayOutputStream.write(bytes, 0, length);
428+
}
429+
return byteArrayOutputStream.toString(StandardCharsets.UTF_8.name());
427430
}
428-
return byteArrayOutputStream.toString(StandardCharsets.UTF_8.name());
429431
}
430432

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

0 commit comments

Comments
 (0)