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

Commit c959ca6b authored by Cosmin Băieș's avatar Cosmin Băieș Committed by Android (Google) Code Review
Browse files

Merge "InsetsSourceProvider nullability cleanup" into main

parents dd8d2108 604e56af
Loading
Loading
Loading
Loading
+34 −41
Original line number Diff line number Diff line
@@ -56,6 +56,7 @@ final class ImeInsetsSourceProvider extends InsetsSourceProvider {
    /** @see #isImeShowing() */
    private boolean mImeShowing;
    /** The latest received insets source. */
    @NonNull
    private final InsetsSource mLastSource = new InsetsSource(ID_IME, WindowInsets.Type.ime());

    /** @see #setFrozen(boolean) */
@@ -171,13 +172,12 @@ final class ImeInsetsSourceProvider extends InsetsSourceProvider {
        return isSurfaceVisible;
    }


    @Nullable
    @Override
    InsetsSourceControl getControl(InsetsControlTarget target) {
    InsetsSourceControl getControl(@NonNull InsetsControlTarget target) {
        final InsetsSourceControl control = super.getControl(target);
        if (control != null && target != null && target.getWindow() != null) {
        final WindowState targetWin = target.getWindow();
        if (control != null && targetWin != null) {
            final Task task = targetWin.getTask();
            // If the control target has a starting window, and its snapshot was captured while
            // the IME was visible, skip the next IME show animation on the IME source control,
@@ -262,7 +262,7 @@ final class ImeInsetsSourceProvider extends InsetsSourceProvider {
    }

    @Override
    void updateSourceFrame(Rect frame) {
    void updateSourceFrame(@NonNull Rect frame) {
        super.updateSourceFrame(frame);
        onSourceChanged();
    }
@@ -316,7 +316,7 @@ final class ImeInsetsSourceProvider extends InsetsSourceProvider {

    // TODO(b/353463205) change statsToken to be NonNull, after the flag is permanently enabled
    @Override
    protected boolean updateClientVisibility(InsetsTarget caller,
    protected boolean updateClientVisibility(@NonNull InsetsTarget caller,
            @Nullable ImeTracker.Token statsToken) {
        InsetsControlTarget controlTarget = getControlTarget();
        if (caller != controlTarget) {
@@ -334,7 +334,7 @@ final class ImeInsetsSourceProvider extends InsetsSourceProvider {
            }
            return false;
        }
        boolean changed = super.updateClientVisibility(caller, statsToken);
        final boolean changed = super.updateClientVisibility(controlTarget, statsToken);
        if (changed) {
            ImeTracker.forLogging().onProgress(statsToken,
                    ImeTracker.PHASE_SERVER_UPDATE_CLIENT_VISIBILITY);
@@ -406,11 +406,10 @@ final class ImeInsetsSourceProvider extends InsetsSourceProvider {
    }

    // TODO(b/353463205) check callers to see if we can make statsToken @NonNull
    private void invokeOnImeRequestedChangedListener(@Nullable InsetsControlTarget controlTarget,
    private void invokeOnImeRequestedChangedListener(@NonNull InsetsControlTarget controlTarget,
            @Nullable ImeTracker.Token statsToken) {
        final var imeListener = mDisplayContent.mWmService.mOnImeRequestedChangedListener;
        if (imeListener != null) {
            if (controlTarget != null) {
            final boolean imeAnimating = Flags.reportAnimatingInsetsTypes()
                    && (controlTarget.getAnimatingTypes() & WindowInsets.Type.ime()) != 0;
            final boolean imeVisible =
@@ -430,25 +429,19 @@ final class ImeInsetsSourceProvider extends InsetsSourceProvider {
                        finalStatsToken);
            });
        } else {
                ImeTracker.forLogging().onFailed(statsToken,
                        ImeTracker.PHASE_WM_POSTING_CHANGED_IME_VISIBILITY);
            }
        } else {
            // TODO(b/353463205) We could combine the upper if's and remove the additional phase.
            ImeTracker.forLogging().onFailed(statsToken,
                    ImeTracker.PHASE_WM_DISPATCH_IME_REQUESTED_CHANGED);
        }
    }

    @Override
    void onAnimatingTypesChanged(InsetsControlTarget caller,
    void onAnimatingTypesChanged(@NonNull InsetsControlTarget caller,
            @Nullable ImeTracker.Token statsToken) {
        if (Flags.reportAnimatingInsetsTypes()) {
            final InsetsControlTarget controlTarget = getControlTarget();
            // If the IME is not being requested anymore and the animation is finished, we need to
            // invoke the listener, to let IMS eventually know
            if (caller != null && caller == controlTarget && !caller.isRequestedVisible(
                    WindowInsets.Type.ime())
            if (caller == controlTarget && !caller.isRequestedVisible(WindowInsets.Type.ime())
                    && (caller.getAnimatingTypes() & WindowInsets.Type.ime()) == 0) {
                ImeTracker.forLogging().onFailed(statsToken,
                        ImeTracker.PHASE_WM_NOTIFY_HIDE_ANIMATION_FINISHED);
@@ -478,13 +471,12 @@ final class ImeInsetsSourceProvider extends InsetsSourceProvider {
    }

    private void reportImeDrawnForOrganizer(@NonNull InsetsControlTarget caller) {
        final WindowState callerWindow = caller.getWindow();
        if (callerWindow == null || callerWindow.getTask() == null) {
        final Task callerTask = caller.getWindow() != null ? caller.getWindow().getTask() : null;
        if (callerTask == null) {
            return;
        }
        if (callerWindow.getTask().isOrganized()) {
            mWin.mWmService.mAtmService.mTaskOrganizerController
                    .reportImeDrawnOnTask(caller.getWindow().getTask());
        if (callerTask.isOrganized()) {
            mWin.mWmService.mAtmService.mTaskOrganizerController.reportImeDrawnOnTask(callerTask);
        }
    }

@@ -563,7 +555,7 @@ final class ImeInsetsSourceProvider extends InsetsSourceProvider {
    }

    @Override
    public void dump(PrintWriter pw, String prefix) {
    public void dump(@NonNull PrintWriter pw, @NonNull String prefix) {
        super.dump(pw, prefix);
        prefix = prefix + "  ";
        pw.print(prefix);
@@ -575,7 +567,8 @@ final class ImeInsetsSourceProvider extends InsetsSourceProvider {
    }

    @Override
    void dumpDebug(ProtoOutputStream proto, long fieldId, @WindowTracingLogLevel int logLevel) {
    void dumpDebug(@NonNull ProtoOutputStream proto, long fieldId,
            @WindowTracingLogLevel int logLevel) {
        final long token = proto.start(fieldId);
        super.dumpDebug(proto, INSETS_SOURCE_PROVIDER, logLevel);
        proto.end(token);
+121 −142

File changed.

Preview size limit exceeded, changes collapsed.

+16 −6
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@ import android.graphics.Rect;
import android.platform.test.annotations.Presubmit;
import android.view.InsetsSource;

import androidx.annotation.NonNull;
import androidx.test.filters.SmallTest;

import org.junit.Before;
@@ -46,10 +47,14 @@ import org.junit.runner.RunWith;
@RunWith(WindowTestRunner.class)
public class InsetsSourceProviderTest extends WindowTestsBase {

    private InsetsSource mSource = new InsetsSource(
    @NonNull
    private final InsetsSource mSource = new InsetsSource(
            InsetsSource.createId(null, 0, statusBars()), statusBars());
    @NonNull
    private InsetsSourceProvider mProvider;
    private InsetsSource mImeSource = new InsetsSource(ID_IME, ime());
    @NonNull
    private final InsetsSource mImeSource = new InsetsSource(ID_IME, ime());
    @NonNull
    private InsetsSourceProvider mImeProvider;

    @Before
@@ -158,8 +163,9 @@ public class InsetsSourceProviderTest extends WindowTestsBase {
        statusBar.getFrame().set(0, 0, 500, 100);
        mProvider.setWindow(statusBar, null, null);
        mProvider.updateFakeControlTarget(target);
        assertNotNull(mProvider.getControl(target));
        assertNull(mProvider.getControl(target).getLeash());
        final var control = mProvider.getControl(target);
        assertNotNull(control);
        assertNull(control.getLeash());
        mProvider.updateFakeControlTarget(null);
        assertNull(mProvider.getControl(target));
    }
@@ -270,7 +276,9 @@ public class InsetsSourceProviderTest extends WindowTestsBase {
        mImeProvider.updateControlForTarget(target, false /* force */, null /* statsToken */);
        ime1.getFrame().set(new Rect(0, 400, 500, 500));
        mImeProvider.updateInsetsControlPosition(ime1);
        assertEquals(new Point(0, 400), mImeProvider.getControl(target).getSurfacePosition());
        var control = mImeProvider.getControl(target);
        assertNotNull(control);
        assertEquals(new Point(0, 400), control.getSurfacePosition());

        final WindowState ime2 = newWindowBuilder("ime2", TYPE_INPUT_METHOD).build();
        ime2.getFrame().set(new Rect(0, 0, 0, 0));
@@ -278,7 +286,9 @@ public class InsetsSourceProviderTest extends WindowTestsBase {
        mImeProvider.updateControlForTarget(target, false /* force */, null /* statsToken */);
        ime2.getFrame().set(new Rect(0, 400, 500, 500));
        mImeProvider.updateInsetsControlPosition(ime2);
        assertEquals(new Point(0, 400), mImeProvider.getControl(target).getSurfacePosition());
        control = mImeProvider.getControl(target);
        assertNotNull(control);
        assertEquals(new Point(0, 400), control.getSurfacePosition());
    }

    @Test