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

Commit 68c65e58 authored by Alan Viverette's avatar Alan Viverette
Browse files

Nullability annotations for view and widget

I inferred nullability annotations in Jetpack based on the guaranteed
behavior of the platform, so now I'm propagating those inferences back
to the platform as annotations.

Test: nullability presubmit checks
Fixes: 206801689
Change-Id: I78a1997faeecdafc51d303b0fc766369938b9101
parent 1a8fe9a3
Loading
Loading
Loading
Loading
+168 −168

File changed.

Preview size limit exceeded, changes collapsed.

+8 −6
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package android.view;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.compat.annotation.UnsupportedAppUsage;
import android.content.Context;
import android.util.Log;
@@ -67,7 +69,7 @@ public abstract class ActionProvider {
     *
     * @param context Context for accessing resources.
     */
    public ActionProvider(Context context) {
    public ActionProvider(@NonNull Context context) {
    }

    /**
@@ -82,7 +84,7 @@ public abstract class ActionProvider {
     * @deprecated use {@link #onCreateActionView(MenuItem)}
     */
    @Deprecated
    public abstract View onCreateActionView();
    public abstract @NonNull View onCreateActionView();

    /**
     * Factory method called by the Android framework to create new action views.
@@ -96,7 +98,7 @@ public abstract class ActionProvider {
     * @param forItem MenuItem to create the action view for
     * @return the new action view
     */
    public View onCreateActionView(MenuItem forItem) {
    public @NonNull View onCreateActionView(@NonNull MenuItem forItem) {
        return onCreateActionView();
    }

@@ -200,7 +202,7 @@ public abstract class ActionProvider {
     *
     * @param subMenu Submenu that will be displayed
     */
    public void onPrepareSubMenu(SubMenu subMenu) {
    public void onPrepareSubMenu(@NonNull SubMenu subMenu) {
    }

    /**
@@ -220,7 +222,7 @@ public abstract class ActionProvider {
     * @hide Internal use only
     */
    @UnsupportedAppUsage
    public void setSubUiVisibilityListener(SubUiVisibilityListener listener) {
    public void setSubUiVisibilityListener(@Nullable SubUiVisibilityListener listener) {
        mSubUiVisibilityListener = listener;
    }

@@ -230,7 +232,7 @@ public abstract class ActionProvider {
     *
     * @param listener listener to set
     */
    public void setVisibilityListener(VisibilityListener listener) {
    public void setVisibilityListener(@Nullable VisibilityListener listener) {
        if (mVisibilityListener != null) {
            Log.w(TAG, "setVisibilityListener: Setting a new ActionProvider.VisibilityListener " +
                    "when one is already set. Are you reusing this " + getClass().getSimpleName() +
+2 −2
Original line number Diff line number Diff line
@@ -260,7 +260,7 @@ public final class DisplayCutout {
        private final float mScale;

        public CutoutPathParserInfo(int displayWidth, int displayHeight, float density,
                String cutoutSpec, @Rotation int rotation, float scale) {
                @Nullable String cutoutSpec, @Rotation int rotation, float scale) {
            mDisplayWidth = displayWidth;
            mDisplayHeight = displayHeight;
            mDensity = density;
@@ -269,7 +269,7 @@ public final class DisplayCutout {
            mScale = scale;
        }

        public CutoutPathParserInfo(CutoutPathParserInfo cutoutPathParserInfo) {
        public CutoutPathParserInfo(@NonNull CutoutPathParserInfo cutoutPathParserInfo) {
            mDisplayWidth = cutoutPathParserInfo.mDisplayWidth;
            mDisplayHeight = cutoutPathParserInfo.mDisplayHeight;
            mDensity = cutoutPathParserInfo.mDensity;
+39 −35
Original line number Diff line number Diff line
@@ -23,6 +23,8 @@ import static com.android.internal.util.FrameworkStatsLog.TOUCH_GESTURE_CLASSIFI
import static com.android.internal.util.FrameworkStatsLog.TOUCH_GESTURE_CLASSIFIED__CLASSIFICATION__SINGLE_TAP;
import static com.android.internal.util.FrameworkStatsLog.TOUCH_GESTURE_CLASSIFIED__CLASSIFICATION__UNKNOWN_CLASSIFICATION;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.UiContext;
import android.compat.annotation.UnsupportedAppUsage;
import android.content.Context;
@@ -68,7 +70,7 @@ public class GestureDetector {
         *
         * @param e The down motion event.
         */
        boolean onDown(MotionEvent e);
        boolean onDown(@NonNull MotionEvent e);

        /**
         * The user has performed a down {@link MotionEvent} and not performed
@@ -78,7 +80,7 @@ public class GestureDetector {
         *
         * @param e The down motion event
         */
        void onShowPress(MotionEvent e);
        void onShowPress(@NonNull MotionEvent e);

        /**
         * Notified when a tap occurs with the up {@link MotionEvent}
@@ -87,7 +89,7 @@ public class GestureDetector {
         * @param e The up motion event that completed the first tap
         * @return true if the event is consumed, else false
         */
        boolean onSingleTapUp(MotionEvent e);
        boolean onSingleTapUp(@NonNull MotionEvent e);

        /**
         * Notified when a scroll occurs with the initial on down {@link MotionEvent} and the
@@ -104,7 +106,8 @@ public class GestureDetector {
         *              and {@code e2}.
         * @return true if the event is consumed, else false
         */
        boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY);
        boolean onScroll(@NonNull MotionEvent e1, @NonNull MotionEvent e2, float distanceX,
                float distanceY);

        /**
         * Notified when a long press occurs with the initial on down {@link MotionEvent}
@@ -112,7 +115,7 @@ public class GestureDetector {
         *
         * @param e The initial on down motion event that started the longpress.
         */
        void onLongPress(MotionEvent e);
        void onLongPress(@NonNull MotionEvent e);

        /**
         * Notified of a fling event when it occurs with the initial on down {@link MotionEvent}
@@ -127,7 +130,8 @@ public class GestureDetector {
         *              along the y axis.
         * @return true if the event is consumed, else false
         */
        boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY);
        boolean onFling(@NonNull MotionEvent e1, @NonNull MotionEvent e2, float velocityX,
                float velocityY);
    }

    /**
@@ -146,7 +150,7 @@ public class GestureDetector {
         * @param e The down motion event of the single-tap.
         * @return true if the event is consumed, else false
         */
        boolean onSingleTapConfirmed(MotionEvent e);
        boolean onSingleTapConfirmed(@NonNull MotionEvent e);
 
        /**
         * Notified when a double-tap occurs. Triggered on the down event of second tap.
@@ -154,7 +158,7 @@ public class GestureDetector {
         * @param e The down motion event of the first tap of the double-tap.
         * @return true if the event is consumed, else false
         */
        boolean onDoubleTap(MotionEvent e);
        boolean onDoubleTap(@NonNull MotionEvent e);

        /**
         * Notified when an event within a double-tap gesture occurs, including
@@ -163,7 +167,7 @@ public class GestureDetector {
         * @param e The motion event that occurred during the double-tap gesture.
         * @return true if the event is consumed, else false
         */
        boolean onDoubleTapEvent(MotionEvent e);
        boolean onDoubleTapEvent(@NonNull MotionEvent e);
    }

    /**
@@ -178,7 +182,7 @@ public class GestureDetector {
         * @param e The motion event that occurred during the context click.
         * @return true if the event is consumed, else false
         */
        boolean onContextClick(MotionEvent e);
        boolean onContextClick(@NonNull MotionEvent e);
    }

    /**
@@ -190,43 +194,43 @@ public class GestureDetector {
    public static class SimpleOnGestureListener implements OnGestureListener, OnDoubleTapListener,
            OnContextClickListener {

        public boolean onSingleTapUp(MotionEvent e) {
        public boolean onSingleTapUp(@NonNull MotionEvent e) {
            return false;
        }

        public void onLongPress(MotionEvent e) {
        public void onLongPress(@NonNull MotionEvent e) {
        }

        public boolean onScroll(MotionEvent e1, MotionEvent e2,
        public boolean onScroll(@NonNull MotionEvent e1, @NonNull MotionEvent e2,
                float distanceX, float distanceY) {
            return false;
        }

        public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
        public boolean onFling(@NonNull MotionEvent e1, @NonNull MotionEvent e2, float velocityX,
                float velocityY) {
            return false;
        }

        public void onShowPress(MotionEvent e) {
        public void onShowPress(@NonNull MotionEvent e) {
        }

        public boolean onDown(MotionEvent e) {
        public boolean onDown(@NonNull MotionEvent e) {
            return false;
        }

        public boolean onDoubleTap(MotionEvent e) {
        public boolean onDoubleTap(@NonNull MotionEvent e) {
            return false;
        }

        public boolean onDoubleTapEvent(MotionEvent e) {
        public boolean onDoubleTapEvent(@NonNull MotionEvent e) {
            return false;
        }

        public boolean onSingleTapConfirmed(MotionEvent e) {
        public boolean onSingleTapConfirmed(@NonNull MotionEvent e) {
            return false;
        }

        public boolean onContextClick(MotionEvent e) {
        public boolean onContextClick(@NonNull MotionEvent e) {
            return false;
        }
    }
@@ -348,14 +352,13 @@ public class GestureDetector {
     * not be null.
     * @param handler the handler to use
     *
     * @throws NullPointerException if either {@code listener} or
     * {@code handler} is null.
     * @throws NullPointerException if {@code listener} is null.
     *
     * @deprecated Use {@link #GestureDetector(android.content.Context,
     *      android.view.GestureDetector.OnGestureListener, android.os.Handler)} instead.
     */
    @Deprecated
    public GestureDetector(OnGestureListener listener, Handler handler) {
    public GestureDetector(@NonNull OnGestureListener listener, @Nullable Handler handler) {
        this(null, listener, handler);
    }

@@ -373,7 +376,7 @@ public class GestureDetector {
     *      android.view.GestureDetector.OnGestureListener)} instead.
     */
    @Deprecated
    public GestureDetector(OnGestureListener listener) {
    public GestureDetector(@NonNull OnGestureListener listener) {
        this(null, listener, null);
    }

@@ -392,7 +395,8 @@ public class GestureDetector {
     * @throws NullPointerException if {@code listener} is null.
     */
    // TODO(b/182007470): Use @ConfigurationContext instead
    public GestureDetector(@UiContext Context context, OnGestureListener listener) {
    public GestureDetector(@Nullable @UiContext Context context,
            @NonNull OnGestureListener listener) {
        this(context, listener, null);
    }

@@ -411,8 +415,8 @@ public class GestureDetector {
     *
     * @throws NullPointerException if {@code listener} is null.
     */
    public GestureDetector(@UiContext Context context, OnGestureListener listener,
            Handler handler) {
    public GestureDetector(@Nullable @UiContext Context context,
            @NonNull OnGestureListener listener, @Nullable Handler handler) {
        if (handler != null) {
            mHandler = new GestureHandler(handler);
        } else {
@@ -442,8 +446,8 @@ public class GestureDetector {
     *
     * @throws NullPointerException if {@code listener} is null.
     */
    public GestureDetector(@UiContext Context context, OnGestureListener listener, Handler handler,
            boolean unused) {
    public GestureDetector(@Nullable @UiContext Context context,
            @NonNull OnGestureListener listener, @Nullable Handler handler, boolean unused) {
        this(context, listener, handler);
    }

@@ -486,7 +490,7 @@ public class GestureDetector {
     * @param onDoubleTapListener the listener invoked for all the callbacks, or
     *        null to stop listening for double-tap gestures.
     */
    public void setOnDoubleTapListener(OnDoubleTapListener onDoubleTapListener) {
    public void setOnDoubleTapListener(@Nullable OnDoubleTapListener onDoubleTapListener) {
        mDoubleTapListener = onDoubleTapListener;
    }

@@ -496,7 +500,7 @@ public class GestureDetector {
     * @param onContextClickListener the listener invoked for all the callbacks, or null to stop
     *            listening for context clicks.
     */
    public void setContextClickListener(OnContextClickListener onContextClickListener) {
    public void setContextClickListener(@Nullable OnContextClickListener onContextClickListener) {
        mContextClickListener = onContextClickListener;
    }

@@ -528,7 +532,7 @@ public class GestureDetector {
     * @return true if the {@link OnGestureListener} consumed the event,
     *              else false.
     */
    public boolean onTouchEvent(MotionEvent ev) {
    public boolean onTouchEvent(@NonNull MotionEvent ev) {
        if (mInputEventConsistencyVerifier != null) {
            mInputEventConsistencyVerifier.onTouchEvent(ev, 0);
        }
@@ -800,7 +804,7 @@ public class GestureDetector {
     * @return true if the {@link OnGestureListener} consumed the event,
     *              else false.
     */
    public boolean onGenericMotionEvent(MotionEvent ev) {
    public boolean onGenericMotionEvent(@NonNull MotionEvent ev) {
        if (mInputEventConsistencyVerifier != null) {
            mInputEventConsistencyVerifier.onGenericMotionEvent(ev, 0);
        }
@@ -860,8 +864,8 @@ public class GestureDetector {
        mIgnoreNextUpEvent = false;
    }

    private boolean isConsideredDoubleTap(MotionEvent firstDown, MotionEvent firstUp,
            MotionEvent secondDown) {
    private boolean isConsideredDoubleTap(@NonNull MotionEvent firstDown,
            @NonNull MotionEvent firstUp, @NonNull MotionEvent secondDown) {
        if (!mAlwaysInBiggerTapRegion) {
            return false;
        }
+10 −8
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package android.view;

import android.annotation.IntDef;
import android.annotation.NonNull;
import android.graphics.Rect;

import java.lang.annotation.Retention;
@@ -187,8 +188,8 @@ public class Gravity
     * @see View#LAYOUT_DIRECTION_LTR
     * @see View#LAYOUT_DIRECTION_RTL
     */
    public static void apply(int gravity, int w, int h, Rect container,
            Rect outRect, int layoutDirection) {
    public static void apply(int gravity, int w, int h, @NonNull Rect container,
            @NonNull Rect outRect, int layoutDirection) {
        int absGravity = getAbsoluteGravity(gravity, layoutDirection);
        apply(absGravity, w, h, container, 0, 0, outRect);
    }
@@ -214,8 +215,8 @@ public class Gravity
     * @param outRect Receives the computed frame of the object in its
     *                container.
     */
    public static void apply(int gravity, int w, int h, Rect container,
            int xAdj, int yAdj, Rect outRect) {
    public static void apply(int gravity, int w, int h, @NonNull Rect container,
            int xAdj, int yAdj, @NonNull Rect outRect) {
        switch (gravity&((AXIS_PULL_BEFORE|AXIS_PULL_AFTER)<<AXIS_X_SHIFT)) {
            case 0:
                outRect.left = container.left
@@ -324,8 +325,8 @@ public class Gravity
     * @see View#LAYOUT_DIRECTION_LTR
     * @see View#LAYOUT_DIRECTION_RTL
     */
    public static void apply(int gravity, int w, int h, Rect container,
                             int xAdj, int yAdj, Rect outRect, int layoutDirection) {
    public static void apply(int gravity, int w, int h, @NonNull Rect container,
                             int xAdj, int yAdj, @NonNull Rect outRect, int layoutDirection) {
        int absGravity = getAbsoluteGravity(gravity, layoutDirection);
        apply(absGravity, w, h, container, xAdj, yAdj, outRect);
    }
@@ -346,7 +347,7 @@ public class Gravity
     * @param inoutObj Supplies the current object position; returns with it
     * modified if needed to fit in the display.
     */
    public static void applyDisplay(int gravity, Rect display, Rect inoutObj) {
    public static void applyDisplay(int gravity, @NonNull Rect display, @NonNull Rect inoutObj) {
        if ((gravity&DISPLAY_CLIP_VERTICAL) != 0) {
            if (inoutObj.top < display.top) inoutObj.top = display.top;
            if (inoutObj.bottom > display.bottom) inoutObj.bottom = display.bottom;
@@ -404,7 +405,8 @@ public class Gravity
     * @see View#LAYOUT_DIRECTION_LTR
     * @see View#LAYOUT_DIRECTION_RTL
     */
    public static void applyDisplay(int gravity, Rect display, Rect inoutObj, int layoutDirection) {
    public static void applyDisplay(int gravity, @NonNull Rect display, @NonNull Rect inoutObj,
            int layoutDirection) {
        int absGravity = getAbsoluteGravity(gravity, layoutDirection);
        applyDisplay(absGravity, display, inoutObj);
    }
Loading