Merge "Limit maximum allowed size for a status bar icon" into rvc-qpr-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
0ef492ff12
@@ -83,6 +83,9 @@ public class StatusBarIconView extends AnimatedImageView implements StatusIconDi
|
||||
public static final int STATE_DOT = 1;
|
||||
public static final int STATE_HIDDEN = 2;
|
||||
|
||||
/** Maximum allowed width or height for an icon drawable */
|
||||
private static final int MAX_IMAGE_SIZE = 500;
|
||||
|
||||
private static final String TAG = "StatusBarIconView";
|
||||
private static final Property<StatusBarIconView, Float> ICON_APPEAR_AMOUNT
|
||||
= new FloatProperty<StatusBarIconView>("iconAppearAmount") {
|
||||
@@ -378,6 +381,13 @@ public class StatusBarIconView extends AnimatedImageView implements StatusIconDi
|
||||
Log.w(TAG, "No icon for slot " + mSlot + "; " + mIcon.icon);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (drawable.getIntrinsicWidth() > MAX_IMAGE_SIZE
|
||||
|| drawable.getIntrinsicHeight() > MAX_IMAGE_SIZE) {
|
||||
Log.w(TAG, "Drawable is too large " + mIcon);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (withClear) {
|
||||
setImageDrawable(null);
|
||||
}
|
||||
|
||||
@@ -35,6 +35,7 @@ import android.content.ContextWrapper;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.drawable.Icon;
|
||||
import android.os.UserHandle;
|
||||
@@ -123,4 +124,13 @@ public class StatusBarIconViewTest extends SysuiTestCase {
|
||||
assertEquals("Transparent backgrounds should fallback to drawable color",
|
||||
color, mIconView.getStaticDrawableColor());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGiantImageNotAllowed() {
|
||||
Bitmap largeBitmap = Bitmap.createBitmap(1000, 1000, Bitmap.Config.ARGB_8888);
|
||||
Icon icon = Icon.createWithBitmap(largeBitmap);
|
||||
StatusBarIcon largeIcon = new StatusBarIcon(UserHandle.ALL, "mockPackage",
|
||||
icon, 0, 0, "");
|
||||
assertFalse(mIconView.set(largeIcon));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user