Merge "Limit maximum allowed size for a status bar icon" into oc-mr1-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
7e6da1776d
@@ -72,6 +72,9 @@ public class StatusBarIconView extends AnimatedImageView {
|
|||||||
public static final int STATE_DOT = 1;
|
public static final int STATE_DOT = 1;
|
||||||
public static final int STATE_HIDDEN = 2;
|
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 String TAG = "StatusBarIconView";
|
||||||
private static final Property<StatusBarIconView, Float> ICON_APPEAR_AMOUNT
|
private static final Property<StatusBarIconView, Float> ICON_APPEAR_AMOUNT
|
||||||
= new FloatProperty<StatusBarIconView>("iconAppearAmount") {
|
= new FloatProperty<StatusBarIconView>("iconAppearAmount") {
|
||||||
@@ -328,6 +331,13 @@ public class StatusBarIconView extends AnimatedImageView {
|
|||||||
Log.w(TAG, "No icon for slot " + mSlot + "; " + mIcon.icon);
|
Log.w(TAG, "No icon for slot " + mSlot + "; " + mIcon.icon);
|
||||||
return false;
|
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) {
|
if (withClear) {
|
||||||
setImageDrawable(null);
|
setImageDrawable(null);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ import android.content.ContextWrapper;
|
|||||||
import android.content.pm.ApplicationInfo;
|
import android.content.pm.ApplicationInfo;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
import android.graphics.drawable.Icon;
|
import android.graphics.drawable.Icon;
|
||||||
import android.os.UserHandle;
|
import android.os.UserHandle;
|
||||||
@@ -122,4 +123,13 @@ public class StatusBarIconViewTest extends SysuiTestCase {
|
|||||||
assertEquals("Transparent backgrounds should fallback to drawable color",
|
assertEquals("Transparent backgrounds should fallback to drawable color",
|
||||||
color, mIconView.getStaticDrawableColor());
|
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