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

Commit b7e76904 authored by Cosmin Băieș's avatar Cosmin Băieș
Browse files

Nullability improvements in InsetsController

This adds some explicit NonNull anotations to fields of
InsetsController, allowing the removal of some redundant nullability
checks.

Flag: EXEMPT cleanup
Bug: 281029564
Test: InsetsControllerTest
Change-Id: I1aa07ac86e0f64f53d33a7511bba78c8bff0a9b9
parent bfe2c0c9
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -121,7 +121,7 @@ public class InsetsAnimationControlImpl implements InternalInsetsAnimationContro
    private boolean mReadyDispatched;
    private Boolean mPerceptible;

    @VisibleForTesting
    @VisibleForTesting(visibility = PACKAGE)
    public InsetsAnimationControlImpl(SparseArray<InsetsSourceControl> controls,
            @Nullable Rect frame, InsetsState state, WindowInsetsAnimationControlListener listener,
            @InsetsType int types, InsetsAnimationControlCallbacks controller,
+44 −38
Original line number Diff line number Diff line
@@ -161,14 +161,13 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation

        /**
         * If this host is a view hierarchy, adds a pre-draw runnable to ensure proper ordering as
         * described in {@link WindowInsetsAnimation.Callback#onPrepare}.
         *
         * If this host isn't a view hierarchy, the runnable can be executed immediately.
         * described in {@link WindowInsetsAnimation.Callback#onPrepare}. If this host isn't a
         * view hierarchy, the runnable can be executed immediately.
         */
        void addOnPreDrawRunnable(Runnable r);

        /**
         * Adds a runnbale to be executed during {@link Choreographer#CALLBACK_INSETS_ANIMATION}
         * Adds a runnable to be executed during {@link Choreographer#CALLBACK_INSETS_ANIMATION}
         * phase.
         */
        void postInsetsAnimationCallback(Runnable r);
@@ -333,7 +332,8 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
    /**
     * Translation animation evaluator.
     */
    private static TypeEvaluator<Insets> sEvaluator = (fraction, startValue, endValue) -> Insets.of(
    private static final TypeEvaluator<Insets> sEvaluator =
            (fraction, startValue, endValue) -> Insets.of(
                    (int) (startValue.left + fraction * (endValue.left - startValue.left)),
                    (int) (startValue.top + fraction * (endValue.top - startValue.top)),
                    (int) (startValue.right + fraction * (endValue.right - startValue.right)),
@@ -346,7 +346,7 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
    private final InputMethodJankContext mJankContext = new InputMethodJankContext() {
        @Override
        public Context getDisplayContext() {
            return mHost != null ? mHost.getRootViewContext() : null;
            return mHost.getRootViewContext();
        }

        @Override
@@ -357,7 +357,7 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation

        @Override
        public String getHostPackageName() {
            return mHost != null ? mHost.getRootViewContext().getPackageName() : null;
            return mHost.getRootViewContext().getPackageName();
        }
    };

@@ -394,7 +394,7 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
        }

        @Override
        public void onReady(WindowInsetsAnimationController controller, int types) {
        public void onReady(@NonNull WindowInsetsAnimationController controller, int types) {
            mController = controller;
            if (DEBUG) Log.d(TAG, "default animation onReady types: " + types);
            if (mLoggingListener != null) {
@@ -464,7 +464,7 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
        }

        @Override
        public void onFinished(WindowInsetsAnimationController controller) {
        public void onFinished(@NonNull WindowInsetsAnimationController controller) {
            if (DEBUG) Log.d(TAG, "InternalAnimationControlListener onFinished types:"
                    + Type.toString(mRequestedTypes));
            if (mLoggingListener != null) {
@@ -615,11 +615,15 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
    private final InsetsState mLastDispatchedState = new InsetsState();

    private final Rect mFrame = new Rect();
    @NonNull
    private final TriFunction<InsetsController, Integer, Integer, InsetsSourceConsumer>
            mConsumerCreator;
    private final SparseArray<InsetsSourceConsumer> mSourceConsumers = new SparseArray<>();
    @NonNull
    private final InsetsSourceConsumer mImeSourceConsumer;
    @NonNull
    private final Host mHost;
    @NonNull
    private final Handler mHandler;

    private final SparseArray<InsetsSourceControl> mTmpControlArray = new SparseArray<>();
@@ -628,6 +632,7 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation

    private boolean mAnimCallbackScheduled;

    @NonNull
    private final Runnable mAnimCallback;

    /** Pending control request that is waiting on IME to be ready to be shown */
@@ -760,7 +765,7 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
                }
            };

    public InsetsController(Host host) {
    public InsetsController(@NonNull Host host) {
        this(host, (controller, id, type) -> {
            if (!Flags.refactorInsetsController() &&  type == ime()) {
                return new ImeInsetsSourceConsumer(id, controller.mState, controller);
@@ -771,9 +776,10 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
    }

    @VisibleForTesting
    public InsetsController(Host host,
            TriFunction<InsetsController, Integer, Integer, InsetsSourceConsumer> consumerCreator,
            Handler handler) {
    public InsetsController(@NonNull Host host,
            @NonNull TriFunction<InsetsController, Integer, Integer, InsetsSourceConsumer>
                    consumerCreator,
            @NonNull Handler handler) {
        mHost = host;
        mConsumerCreator = consumerCreator;
        mHandler = handler;
@@ -840,6 +846,7 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
    }

    @Override
    @NonNull
    public InsetsState getState() {
        return mState;
    }
@@ -849,6 +856,7 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
        return mRequestedVisibleTypes;
    }

    @NonNull
    public InsetsState getLastDispatchedState() {
        return mLastDispatchedState;
    }
@@ -1743,7 +1751,7 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
    }

    private void cancelExistingControllers(@InsetsType int types) {
        final int originalmTypesBeingCancelled = mTypesBeingCancelled;
        final int originalTypesBeingCancelled = mTypesBeingCancelled;
        mTypesBeingCancelled |= types;
        try {
            for (int i = mRunningAnimations.size() - 1; i >= 0; i--) {
@@ -1756,7 +1764,7 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
                abortPendingImeControlRequest();
            }
        } finally {
            mTypesBeingCancelled = originalmTypesBeingCancelled;
            mTypesBeingCancelled = originalTypesBeingCancelled;
        }
    }

@@ -1850,14 +1858,11 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
                    if (Flags.refactorInsetsController()) {
                        if ((removedTypes & ime()) != 0
                                && runner.getAnimationType() == ANIMATION_TYPE_HIDE) {
                            if (mHost != null) {
                                // if the (hide) animation is cancelled, the
                                // requestedVisibleTypes should be reported at this point.
                            // if the (hide) animation is cancelled, the requestedVisibleTypes
                            // should be reported at this point.
                            reportRequestedVisibleTypes(!Flags.reportAnimatingInsetsTypes()
                                    ? runner.getStatsToken() : null);
                                mHost.getInputMethodManager().removeImeSurface(
                                        mHost.getWindowToken());
                            }
                            mHost.getInputMethodManager().removeImeSurface(mHost.getWindowToken());
                        }
                    }
                }
@@ -1866,14 +1871,12 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
        }
        if (removedTypes > 0) {
            mAnimatingTypes &= ~removedTypes;
            if (mHost != null) {
            final boolean dispatchStatsToken =
                    Flags.reportAnimatingInsetsTypes() && (removedTypes & ime()) != 0
                            && runner.getAnimationType() == ANIMATION_TYPE_HIDE;
            mHost.updateAnimatingTypes(mAnimatingTypes,
                    dispatchStatsToken ? runner.getStatsToken() : null);
        }
        }

        onAnimationStateChanged(removedTypes, false /* running */);
    }
@@ -1908,6 +1911,7 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
        if (consumer != null) {
            return consumer;
        }
        // ImeSourceConsumer is created using getSourceConsumer, so it is initially null here.
        if (type == ime() && mImeSourceConsumer != null) {
            // WindowInsets.Type.ime() should be only provided by one source.
            mSourceConsumers.remove(mImeSourceConsumer.getId());
@@ -1921,7 +1925,8 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
    }

    @VisibleForTesting
    public @NonNull InsetsSourceConsumer getImeSourceConsumer() {
    @NonNull
    public InsetsSourceConsumer getImeSourceConsumer() {
        return mImeSourceConsumer;
    }

@@ -2053,7 +2058,7 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
            mReportedRequestedVisibleTypes = mRequestedVisibleTypes;
            mHost.updateRequestedVisibleTypes(mReportedRequestedVisibleTypes, statsToken);
        } else if (Flags.refactorInsetsController()) {
            if ((typesToReport & ime()) != 0 && mImeSourceConsumer != null) {
            if ((typesToReport & ime()) != 0) {
                InsetsSourceControl control = mImeSourceConsumer.getControl();
                if (control == null || control.getLeash() == null) {
                    // If the IME was requested to show twice, and we didn't receive the controls
@@ -2298,7 +2303,7 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation

    @Override
    public void addOnControllableInsetsChangedListener(
            OnControllableInsetsChangedListener listener) {
            @NonNull OnControllableInsetsChangedListener listener) {
        Objects.requireNonNull(listener);
        mControllableInsetsChangedListeners.add(listener);
        listener.onControllableInsetsChanged(this, calculateControllableTypes());
@@ -2306,7 +2311,7 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation

    @Override
    public void removeOnControllableInsetsChangedListener(
            OnControllableInsetsChangedListener listener) {
            @NonNull OnControllableInsetsChangedListener listener) {
        Objects.requireNonNull(listener);
        mControllableInsetsChangedListeners.remove(listener);
    }
@@ -2328,6 +2333,7 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
    }

    @VisibleForTesting(visibility = PACKAGE)
    @NonNull
    public Host getHost() {
        return mHost;
    }
+1 −1
Original line number Diff line number Diff line
@@ -715,7 +715,7 @@ public class InsetsState implements Parcelable {
     *                             not visible.
     * @return {@code true} if the two InsetsState objects are equal, {@code false} otherwise.
     */
    @VisibleForTesting
    @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE)
    public boolean equals(@Nullable Object o, boolean excludesCaptionBar,
            boolean excludesInvisibleIme) {
        if (this == o) { return true; }
+1 −0
Original line number Diff line number Diff line
@@ -132,6 +132,7 @@ public class PendingInsetsController implements WindowInsetsController {
    }

    @Override
    @NonNull
    public InsetsState getState() {
        return mDummyState;
    }
+1 −0
Original line number Diff line number Diff line
@@ -322,6 +322,7 @@ public interface WindowInsetsController {
    /**
     * @hide
     */
    @NonNull
    InsetsState getState();

    /**