Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 446f2f6d authored by Mateus Azis's avatar Mateus Azis
Browse files

Close InputStreams when loading icons.

BitmapFactory.decodeStream does not claim to close the provided input
stream. It's currently leaking and triggering a CloseGuard exception.

Bug: 347694023
Test: flashed and "adb logcat *:S StrictMode"
Flag: EXEMPT bugfix
Change-Id: I377f288e678cc0afbf1735371d995ce38c7d910b
parent f8a9bb95
Loading
Loading
Loading
Loading
+24 −17
Original line number Diff line number Diff line
@@ -494,7 +494,7 @@ public final class Icon implements Parcelable {
                        BitmapFactory.decodeByteArray(getDataBytes(), getDataOffset(),
                                getDataLength())));
            case TYPE_URI:
                InputStream is = getUriInputStream(context);
                try (InputStream is = getUriInputStream(context)) {
                    if (is != null) {
                        final Bitmap bitmap = BitmapFactory.decodeStream(is);
                        if (bitmap == null) {
@@ -505,9 +505,12 @@ public final class Icon implements Parcelable {
                        }
                        return new BitmapDrawable(context.getResources(), fixMaxBitmapSize(bitmap));
                    }
                } catch (IOException e) {
                    throw new IllegalStateException(e);
                }
                break;
            case TYPE_URI_ADAPTIVE_BITMAP:
                is = getUriInputStream(context);
                try (InputStream is = getUriInputStream(context)) {
                    if (is != null) {
                        final Bitmap bitmap = BitmapFactory.decodeStream(is);
                        if (bitmap == null) {
@@ -516,9 +519,13 @@ public final class Icon implements Parcelable {
                                return null;
                            }
                        }
                    return new AdaptiveIconDrawable(null, new BitmapDrawable(context.getResources(),
                        return new AdaptiveIconDrawable(
                                        null, new BitmapDrawable(context.getResources(),
                                fixMaxBitmapSize(bitmap)));
                    }
                } catch (IOException e) {
                    throw new IllegalStateException(e);
                }
                break;
        }
        return null;