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

Commit 6340b3f0 authored by Adam Cohen's avatar Adam Cohen Committed by Android Git Automerger
Browse files

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

* commit 'e0bb6fe3':
  Cap widget bitmap usage by screen size (issue 6464700)
parents c2f64117 e0bb6fe3
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -321,6 +321,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 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.
     */
+2 −1
Original line number Diff line number Diff line
@@ -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();
    }

+19 −0
Original line number Diff line number Diff line
@@ -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;
        }