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

Commit cf18b47e authored by Adam Lesinski's avatar Adam Lesinski
Browse files

Wrap measurement optimization in targetSdk check

A measurement optimization has exposed some apps that are relying
on incidental layout requests to have themselves update. With the
optimization enabled, these apps break.

Apps targetted at older versions of Android should not
break due to this optimization.

bug:11192311
Change-Id: Id5fc7f83ec2cb1541d3d0d16f951cd57c0afaccd
parent 306ed4fd
Loading
Loading
Loading
Loading
+26 −4
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package android.view;
import android.content.ClipData;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.content.res.TypedArray;
@@ -691,8 +692,22 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
     */
    public static final int NO_ID = -1;
    /**
     * Signals that compatibility booleans have been initialized according to
     * target SDK versions.
     */
    private static boolean sCompatibilityDone = false;
    /**
     * Use the old (broken) way of building MeasureSpecs.
     */
    private static boolean sUseBrokenMakeMeasureSpec = false;
    /**
     * Ignore any optimizations using the measure cache.
     */
    private static boolean sIgnoreMeasureCache = false;
    /**
     * This view does not want keystrokes. Use with TAKES_FOCUS_MASK when
     * calling setFlags.
@@ -3426,10 +3441,17 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
        mUserPaddingStart = UNDEFINED_PADDING;
        mUserPaddingEnd = UNDEFINED_PADDING;
        if (!sUseBrokenMakeMeasureSpec && context != null &&
                context.getApplicationInfo().targetSdkVersion <= JELLY_BEAN_MR1) {
        if (!sCompatibilityDone && context != null) {
            final int targetSdkVersion = context.getApplicationInfo().targetSdkVersion;
            // Older apps may need this compatibility hack for measurement.
            sUseBrokenMakeMeasureSpec = true;
            sUseBrokenMakeMeasureSpec = targetSdkVersion <= JELLY_BEAN_MR1;
            // Older apps expect onMeasure() to always be called on a layout pass, regardless
            // of whether a layout was requested on that View.
            sIgnoreMeasureCache = targetSdkVersion < KITKAT;
            sCompatibilityDone = true;
        }
    }
@@ -16431,7 +16453,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
            int cacheIndex = (mPrivateFlags & PFLAG_FORCE_LAYOUT) == PFLAG_FORCE_LAYOUT ? -1 :
                    mMeasureCache.indexOfKey(key);
            if (cacheIndex < 0) {
            if (cacheIndex < 0 || sIgnoreMeasureCache) {
                // measure ourselves, this should set the measured dimension flag back
                onMeasure(widthMeasureSpec, heightMeasureSpec);
                mPrivateFlags3 &= ~PFLAG3_MEASURE_NEEDED_BEFORE_LAYOUT;