summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Cohen <adamcohen@google.com>2012-05-10 14:44:38 -0700
committerAdam Cohen <adamcohen@google.com>2012-05-10 15:52:28 -0700
commit311c79c3e93589c6fc720fe6c58ed522af591376 (patch)
tree93e8fc58d8a36dfbf3e17222a34aa2933bf8c848
parenta53de0629f3b94472c0f160f5bbe1090b020feab (diff)
downloadframeworks_base-311c79c3e93589c6fc720fe6c58ed522af591376.zip
frameworks_base-311c79c3e93589c6fc720fe6c58ed522af591376.tar.gz
frameworks_base-311c79c3e93589c6fc720fe6c58ed522af591376.tar.bz2
Cap widget bitmap usage by screen size (issue 6464700)
Change-Id: I04e16223861a88d40ad757afa086a0f92e84493b
-rw-r--r--core/java/android/appwidget/AppWidgetManager.java8
-rw-r--r--core/java/android/widget/RemoteViews.java3
-rw-r--r--services/java/com/android/server/AppWidgetServiceImpl.java19
3 files changed, 29 insertions, 1 deletions
diff --git a/core/java/android/appwidget/AppWidgetManager.java b/core/java/android/appwidget/AppWidgetManager.java
index 7a8c1fb..3aa5181 100644
--- a/core/java/android/appwidget/AppWidgetManager.java
+++ b/core/java/android/appwidget/AppWidgetManager.java
@@ -320,6 +320,10 @@ public class AppWidgetManager {
* It is okay to call this method both inside an {@link #ACTION_APPWIDGET_UPDATE} broadcast,
* and outside of the handler.
* This method will only work when called from the uid that owns the AppWidget provider.
+ *
+ * <p>
+ * The total Bitmap memory used by the RemoteViews object cannot exceed that required to
+ * fill the screen once, ie. (screen width x screen height x 4) bytes.
*
* @param appWidgetIds The AppWidget instances for which to set the RemoteViews.
* @param views The RemoteViews object to show.
@@ -385,6 +389,10 @@ public class AppWidgetManager {
* and outside of the handler.
* This method will only work when called from the uid that owns the AppWidget provider.
*
+ * <p>
+ * The total Bitmap memory used by the RemoteViews object cannot exceed that required to
+ * fill the screen once, ie. (screen width x screen height x 4) bytes.
+ *
* @param appWidgetId The AppWidget instance for which to set the RemoteViews.
* @param views The RemoteViews object to show.
*/
diff --git a/core/java/android/widget/RemoteViews.java b/core/java/android/widget/RemoteViews.java
index 56c4bd8..51c957a 100644
--- a/core/java/android/widget/RemoteViews.java
+++ b/core/java/android/widget/RemoteViews.java
@@ -1445,7 +1445,8 @@ public class RemoteViews implements Parcelable, Filter {
/**
* Returns an estimate of the bitmap heap memory usage for this RemoteViews.
*/
- int estimateMemoryUsage() {
+ /** @hide */
+ public int estimateMemoryUsage() {
return mMemoryUsageCounter.getMemoryUsage();
}
diff --git a/services/java/com/android/server/AppWidgetServiceImpl.java b/services/java/com/android/server/AppWidgetServiceImpl.java
index 23f2fdd..df2e1aa 100644
--- a/services/java/com/android/server/AppWidgetServiceImpl.java
+++ b/services/java/com/android/server/AppWidgetServiceImpl.java
@@ -49,6 +49,7 @@ import android.util.Pair;
import android.util.Slog;
import android.util.TypedValue;
import android.util.Xml;
+import android.view.WindowManager;
import android.widget.RemoteViews;
import com.android.internal.appwidget.IAppWidgetHost;
@@ -171,6 +172,7 @@ class AppWidgetServiceImpl {
boolean mSafeMode;
int mUserId;
boolean mStateLoaded;
+ int mMaxWidgetBitmapMemory;
// These are for debugging only -- widgets are going missing in some rare instances
ArrayList<Provider> mDeletedProviders = new ArrayList<Provider>();
@@ -181,6 +183,14 @@ class AppWidgetServiceImpl {
mPm = AppGlobals.getPackageManager();
mAlarmManager = (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE);
mUserId = userId;
+ computeMaximumWidgetBitmapMemory();
+ }
+
+ void computeMaximumWidgetBitmapMemory() {
+ WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
+ int height = wm.getDefaultDisplay().getRawHeight();
+ int width = wm.getDefaultDisplay().getRawWidth();
+ mMaxWidgetBitmapMemory = 4 * width * height;
}
public void systemReady(boolean safeMode) {
@@ -806,6 +816,15 @@ class AppWidgetServiceImpl {
if (appWidgetIds == null) {
return;
}
+
+ int bitmapMemoryUsage = views.estimateMemoryUsage();
+ if (bitmapMemoryUsage > mMaxWidgetBitmapMemory) {
+ throw new IllegalArgumentException("RemoteViews for widget update exceeds maximum" +
+ " bitmap memory usage (used: " + bitmapMemoryUsage + ", max: " +
+ mMaxWidgetBitmapMemory + ") The total memory cannot exceed that required to" +
+ " fill the device's screen once.");
+ }
+
if (appWidgetIds.length == 0) {
return;
}