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

Commit 67568647 authored by Tor Norbye's avatar Tor Norbye
Browse files

Specify a maximum value for View.MeasureSpec.makeMeasureSpec

This adds an annotation to the size parameter for makeMeasureSpec
such that lint can flag potential overflows. (It also adds a typedef
for the mode parameter.)

Change-Id: If32aad2a744f8c582a6c793c2c833f81e9487102
parent a21e7663
Loading
Loading
Loading
Loading
+10 −1
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import android.annotation.DrawableRes;
import android.annotation.FloatRange;
import android.annotation.IdRes;
import android.annotation.IntDef;
import android.annotation.IntRange;
import android.annotation.LayoutRes;
import android.annotation.NonNull;
import android.annotation.Nullable;
@@ -20168,6 +20169,11 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
        private static final int MODE_SHIFT = 30;
        private static final int MODE_MASK  = 0x3 << MODE_SHIFT;
        /** @hide */
        @IntDef({UNSPECIFIED, EXACTLY, AT_MOST})
        @Retention(RetentionPolicy.SOURCE)
        public @interface MeasureSpecMode {}
        /**
         * Measure specification mode: The parent has not imposed any constraint
         * on the child. It can be whatever size it wants.
@@ -20208,7 +20214,8 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
         * @param mode the mode of the measure specification
         * @return the measure specification based on size and mode
         */
        public static int makeMeasureSpec(int size, int mode) {
        public static int makeMeasureSpec(@IntRange(from = 0, to = (1 << MeasureSpec.MODE_SHIFT) - 1) int size,
                                          @MeasureSpecMode int mode) {
            if (sUseBrokenMakeMeasureSpec) {
                return size + mode;
            } else {
@@ -20224,7 +20231,9 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
         *         {@link android.view.View.MeasureSpec#AT_MOST} or
         *         {@link android.view.View.MeasureSpec#EXACTLY}
         */
        @MeasureSpecMode
        public static int getMode(int measureSpec) {
            //noinspection ResourceType
            return (measureSpec & MODE_MASK);
        }
+1 −0
Original line number Diff line number Diff line
@@ -5737,6 +5737,7 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager
            }
            break;
        }
        //noinspection ResourceType
        return MeasureSpec.makeMeasureSpec(resultSize, resultMode);
    }