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

Commit 62869292 authored by /e/ robot's avatar /e/ robot
Browse files

Merge remote-tracking branch 'origin/cm-14.1' into v1-nougat

parents 0d4eb971 55219d15
Loading
Loading
Loading
Loading
+27 −0
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import android.database.ContentObserver;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.Icon;
import android.graphics.Typeface;
@@ -49,6 +50,16 @@ import java.util.ArrayList;
import cyanogenmod.providers.CMSettings;

public class StatusBarIconView extends AnimatedImageView {
    /**
     * Maximum allowed byte count for an icon bitmap
     * @see android.graphics.RecordingCanvas.MAX_BITMAP_SIZE
     */
    private static final int MAX_BITMAP_SIZE = 100 * 1024 * 1024; // 100 MB
    /**
     * Maximum allowed width or height for an icon drawable, if we can't get byte count
     */
    private static final int MAX_IMAGE_SIZE = 5000;

    private static final String TAG = "StatusBarIconView";
    private boolean mAlwaysScaleIcon;

@@ -223,6 +234,22 @@ public class StatusBarIconView extends AnimatedImageView {
            Log.w(TAG, "No icon for slot " + mSlot + "; " + mIcon.icon);
            return false;
        }

        if (drawable instanceof BitmapDrawable && ((BitmapDrawable) drawable).getBitmap() != null) {
            // If it's a bitmap we can check the size directly
            int byteCount = ((BitmapDrawable) drawable).getBitmap().getByteCount();
            if (byteCount > MAX_BITMAP_SIZE) {
                Log.w(TAG, "Drawable is too large (" + byteCount + " bytes) " + mIcon);
                return false;
            }
        } else if (drawable.getIntrinsicWidth() > MAX_IMAGE_SIZE
                || drawable.getIntrinsicHeight() > MAX_IMAGE_SIZE) {
            // Otherwise, check dimensions
            Log.w(TAG, "Drawable is too large (" + drawable.getIntrinsicWidth() + "x"
                    + drawable.getIntrinsicHeight() + ") " + mIcon);
            return false;
        }

        if (withClear) {
            setImageDrawable(null);
        }