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

Commit b30b1683 authored by Lucas Silva's avatar Lucas Silva
Browse files

Use try-with-resource statement for dream metadata to ensure proper

cleanup.

This ensures the memory is properly cleaned up if an exception is thrown
while building the DreamMetadata object.

Bug: 234343900
Test: locally on device
Change-Id: I29b2bed30c216d5e353fa0a8b0da74579b33cecb
parent a834a9bd
Loading
Loading
Loading
Loading
+10 −12
Original line number Diff line number Diff line
@@ -1130,18 +1130,16 @@ public class DreamService extends Service implements Window.Callback {

        final PackageManager pm = context.getPackageManager();

        final TypedArray rawMetadata = readMetadata(pm, serviceInfo);
        try (TypedArray rawMetadata = readMetadata(pm, serviceInfo)) {
            if (rawMetadata == null) return null;

        final DreamMetadata metadata = new DreamMetadata(
            return new DreamMetadata(
                    convertToComponentName(rawMetadata.getString(
                            com.android.internal.R.styleable.Dream_settingsActivity), serviceInfo),
                    rawMetadata.getDrawable(
                            com.android.internal.R.styleable.Dream_previewImage),
                    rawMetadata.getBoolean(R.styleable.Dream_showClockAndComplications,
                            DEFAULT_SHOW_COMPLICATIONS));
        rawMetadata.recycle();
        return metadata;
        }
    }

    /**