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

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

Optimize scheduleShowImePostLayout

This adds various small improvements to the logic in
ImeInsetsSourceProvider for scheduleShowImePostLayout.

The mShowImeRunner is inlined, as there is no need for a runnable for
this code. This allows removing the duplicated isReadyToShowIme check.
The order of the checks in isReadyToShowIme is slightly tweaked to early
return in the most common cases (when no request is scheduled), as well
as now including the WindowContainer checks. This method is now renamed
to isScheduledAndReadyToShowIme, and checkShowImePostLayout is renamed
to checkAndStartShowImePostLayout, to reflect the actual behaviour.

The mIsImeLayoutDrawn property is removed, as this didn't actually allow
skipping the isReadyToShowIme check, nor protect agains re-entry.

The abortShowImePostLayout is called only when we actually abort (hide
while we have a scheduled and unhandled show), and no longer after
handling a show. The trace for showImePostLayout is also marked ended in
the abort, to avoid unfinished traces.

Bug: 332898042
Test: atest ImeInsetsSourceProviderTest
Change-Id: Id8e8560f961339574f53c95e81e41147eef276d8
parent 08df28f4
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -607,7 +607,7 @@ message ImeInsetsSourceProviderProto {

    optional InsetsSourceProviderProto insets_source_provider = 1;
    optional WindowStateProto ime_target_from_ime = 2;
    optional bool is_ime_layout_drawn = 3;
    optional bool is_ime_layout_drawn = 3 [deprecated=true];
}

message BackNavigationProto {
+1 −1
Original line number Diff line number Diff line
@@ -5109,7 +5109,7 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp

        // This should be called after the insets have been dispatched to clients and we have
        // committed finish drawing windows.
        mInsetsStateController.getImeSourceProvider().checkShowImePostLayout();
        mInsetsStateController.getImeSourceProvider().checkAndStartShowImePostLayout();

        mLastHasContent = mTmpApplySurfaceChangesTransactionState.displayHasContent;
        if (!inTransition() && !mDisplayRotation.isRotatingSeamlessly()) {
+122 −132

File changed.

Preview size limit exceeded, changes collapsed.

+1 −1
Original line number Diff line number Diff line
@@ -390,7 +390,7 @@ class InsetsStateController {
            newControlTargets.clear();
            // Check for and try to run the scheduled show IME request (if it exists), as we
            // now applied the surface transaction and notified the target of the new control.
            getImeSourceProvider().checkShowImePostLayout();
            getImeSourceProvider().checkAndStartShowImePostLayout();
        });
    }

+15 −15
Original line number Diff line number Diff line
@@ -65,7 +65,7 @@ public class ImeInsetsSourceProviderTest extends WindowTestsBase {
        performSurfacePlacementAndWaitForWindowAnimator();

        mImeProvider.scheduleShowImePostLayout(appWin, ImeTracker.Token.empty());
        assertTrue(mImeProvider.isReadyToShowIme());
        assertTrue(mImeProvider.isScheduledAndReadyToShowIme());
    }

    /**
@@ -84,13 +84,13 @@ public class ImeInsetsSourceProviderTest extends WindowTestsBase {

        // Schedule (without triggering) after everything is ready.
        mImeProvider.scheduleShowImePostLayout(target, ImeTracker.Token.empty());
        assertTrue(mImeProvider.isReadyToShowIme());
        assertTrue(mImeProvider.isScheduledAndReadyToShowIme());
        assertFalse(mImeProvider.isImeShowing());

        // Manually trigger the show.
        mImeProvider.checkShowImePostLayout();
        // No longer ready as it was already shown.
        assertFalse(mImeProvider.isReadyToShowIme());
        mImeProvider.checkAndStartShowImePostLayout();
        // No longer scheduled as it was already shown.
        assertFalse(mImeProvider.isScheduledAndReadyToShowIme());
        assertTrue(mImeProvider.isImeShowing());
    }

@@ -104,7 +104,7 @@ public class ImeInsetsSourceProviderTest extends WindowTestsBase {

        // Schedule before anything is ready.
        mImeProvider.scheduleShowImePostLayout(target, ImeTracker.Token.empty());
        assertFalse(mImeProvider.isReadyToShowIme());
        assertFalse(mImeProvider.isScheduledAndReadyToShowIme());
        assertFalse(mImeProvider.isImeShowing());

        final WindowState ime = createWindow(null, TYPE_INPUT_METHOD, "ime");
@@ -115,8 +115,8 @@ public class ImeInsetsSourceProviderTest extends WindowTestsBase {
        mDisplayContent.updateImeInputAndControlTarget(target);
        // Performing surface placement picks up the show scheduled above.
        performSurfacePlacementAndWaitForWindowAnimator();
        // No longer ready as it was already shown.
        assertFalse(mImeProvider.isReadyToShowIme());
        // No longer scheduled as it was already shown.
        assertFalse(mImeProvider.isScheduledAndReadyToShowIme());
        assertTrue(mImeProvider.isImeShowing());
    }

@@ -137,19 +137,19 @@ public class ImeInsetsSourceProviderTest extends WindowTestsBase {

        // Schedule before starting the afterPrepareSurfacesRunnable.
        mImeProvider.scheduleShowImePostLayout(target, ImeTracker.Token.empty());
        assertFalse(mImeProvider.isReadyToShowIme());
        assertFalse(mImeProvider.isScheduledAndReadyToShowIme());
        assertFalse(mImeProvider.isImeShowing());

        // This tries to pick up the show scheduled above, but must fail as the
        // afterPrepareSurfacesRunnable was not started yet.
        mDisplayContent.applySurfaceChangesTransaction();
        assertFalse(mImeProvider.isReadyToShowIme());
        assertFalse(mImeProvider.isScheduledAndReadyToShowIme());
        assertFalse(mImeProvider.isImeShowing());

        // Starting the afterPrepareSurfacesRunnable picks up the show scheduled above.
        mWm.mAnimator.executeAfterPrepareSurfacesRunnables();
        // No longer ready as it was already shown.
        assertFalse(mImeProvider.isReadyToShowIme());
        // No longer scheduled as it was already shown.
        assertFalse(mImeProvider.isScheduledAndReadyToShowIme());
        assertTrue(mImeProvider.isImeShowing());
    }

@@ -169,7 +169,7 @@ public class ImeInsetsSourceProviderTest extends WindowTestsBase {

        // Schedule before surface placement.
        mImeProvider.scheduleShowImePostLayout(target, ImeTracker.Token.empty());
        assertFalse(mImeProvider.isReadyToShowIme());
        assertFalse(mImeProvider.isScheduledAndReadyToShowIme());
        assertFalse(mImeProvider.isImeShowing());

        // Performing surface placement picks up the show scheduled above, and succeeds.
@@ -177,8 +177,8 @@ public class ImeInsetsSourceProviderTest extends WindowTestsBase {
        // applySurfaceChangesTransaction. Both of them try to trigger the show,
        // but only the second one can succeed, as it comes after onPostLayout.
        performSurfacePlacementAndWaitForWindowAnimator();
        // No longer ready as it was already shown.
        assertFalse(mImeProvider.isReadyToShowIme());
        // No longer scheduled as it was already shown.
        assertFalse(mImeProvider.isScheduledAndReadyToShowIme());
        assertTrue(mImeProvider.isImeShowing());
    }