Merge "Cap widget bitmap usage by screen size (issue 6464700)" into jb-dev

This commit is contained in:
Adam Cohen
2012-05-16 13:43:27 -07:00
committed by Android (Google) Code Review
3 changed files with 29 additions and 1 deletions

View File

@@ -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.
*/

View File

@@ -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();
}

View File

@@ -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;
}