diff options
| author | 2023-10-05 15:03:11 +0200 | |
|---|---|---|
| committer | 2024-02-28 16:37:05 +0100 | |
| commit | df62c4faa80f6bc0d5ddae808bb93c24b31b540c (patch) | |
| tree | 441c2836c3d8c1cdc1e5a1fa04e81fb638f273e2 /libs | |
| parent | 2af839965ea12abda5429ca947e93af4c5c5a322 (diff) | |
Handle ImeTracker.Token missing flows
Created an empty ImeTracker.Token instance for testing,
and added more reasons to handle IME flows previously
missed from tracking.
Test: atest InputMethodStatsTest
ImeInsetsSourceConsumerTest
InputMethodManagerServiceWindowGainedFocusTest
DefaultImeVisibilityApplierTest
ImeVisibilityStateComputerTest#testOnApplyImeVisibilityFromComputer
Bug: 271426908
Change-Id: Idfa8dabf16d0bcd43ff0c0d64affb2e5f923f44b
Diffstat (limited to 'libs')
4 files changed, 48 insertions, 19 deletions
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/common/DisplayImeController.java b/libs/WindowManager/Shell/src/com/android/wm/shell/common/DisplayImeController.java index 2ea43162d225..ad01d0fa311a 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/common/DisplayImeController.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/common/DisplayImeController.java @@ -20,12 +20,12 @@ import static android.view.EventLogTags.IMF_IME_REMOTE_ANIM_CANCEL; import static android.view.EventLogTags.IMF_IME_REMOTE_ANIM_END; import static android.view.EventLogTags.IMF_IME_REMOTE_ANIM_START; import static android.view.inputmethod.ImeTracker.DEBUG_IME_VISIBILITY; -import static android.view.inputmethod.ImeTracker.TOKEN_NONE; import android.animation.Animator; import android.animation.AnimatorListenerAdapter; import android.animation.ValueAnimator; import android.annotation.IntDef; +import android.annotation.NonNull; import android.annotation.Nullable; import android.content.ComponentName; import android.content.res.Configuration; @@ -51,6 +51,7 @@ import android.view.inputmethod.InputMethodManagerGlobal; import androidx.annotation.VisibleForTesting; +import com.android.internal.inputmethod.SoftInputShowHideReason; import com.android.wm.shell.sysui.ShellInit; import java.util.ArrayList; @@ -122,7 +123,8 @@ public class DisplayImeController implements DisplayController.OnDisplaysChanged } if (mDisplayController.getDisplayLayout(displayId).rotation() != pd.mRotation && isImeShowing(displayId)) { - pd.startAnimation(true, false /* forceRestart */, null /* statsToken */); + pd.startAnimation(true, false /* forceRestart */, + SoftInputShowHideReason.DISPLAY_CONFIGURATION_CHANGED); } } @@ -257,7 +259,8 @@ public class DisplayImeController implements DisplayController.OnDisplaysChanged mInsetsState.set(insetsState, true /* copySources */); if (mImeShowing && !Objects.equals(oldFrame, newFrame) && newSourceVisible) { if (DEBUG) Slog.d(TAG, "insetsChanged when IME showing, restart animation"); - startAnimation(mImeShowing, true /* forceRestart */, null /* statsToken */); + startAnimation(mImeShowing, true /* forceRestart */, + SoftInputShowHideReason.DISPLAY_INSETS_CHANGED); } } @@ -291,7 +294,8 @@ public class DisplayImeController implements DisplayController.OnDisplaysChanged final boolean positionChanged = !imeSourceControl.getSurfacePosition().equals(lastSurfacePosition); if (positionChanged) { - startAnimation(mImeShowing, true /* forceRestart */, null /* statsToken */); + startAnimation(mImeShowing, true /* forceRestart */, + SoftInputShowHideReason.DISPLAY_CONTROLS_CHANGED); } } else { if (!haveSameLeash(mImeSourceControl, imeSourceControl)) { @@ -384,7 +388,20 @@ public class DisplayImeController implements DisplayController.OnDisplaysChanged } private void startAnimation(final boolean show, final boolean forceRestart, - @Nullable ImeTracker.Token statsToken) { + @SoftInputShowHideReason int reason) { + final var imeSource = mInsetsState.peekSource(InsetsSource.ID_IME); + if (imeSource == null || mImeSourceControl == null) { + return; + } + final var statsToken = ImeTracker.forLogging().onStart( + show ? ImeTracker.TYPE_SHOW : ImeTracker.TYPE_HIDE, ImeTracker.ORIGIN_WM_SHELL, + reason, false /* fromUser */); + + startAnimation(show, forceRestart, statsToken); + } + + private void startAnimation(final boolean show, final boolean forceRestart, + @NonNull final ImeTracker.Token statsToken) { final InsetsSource imeSource = mInsetsState.peekSource(InsetsSource.ID_IME); if (imeSource == null || mImeSourceControl == null) { ImeTracker.forLogging().onFailed(statsToken, ImeTracker.PHASE_WM_ANIMATION_CREATE); @@ -458,7 +475,7 @@ public class DisplayImeController implements DisplayController.OnDisplaysChanged ImeTracker.forLogging().onProgress(statsToken, ImeTracker.PHASE_WM_ANIMATION_CREATE); mAnimation.addListener(new AnimatorListenerAdapter() { private boolean mCancelled = false; - @Nullable + @NonNull private final ImeTracker.Token mStatsToken = statsToken; @Override @@ -484,7 +501,7 @@ public class DisplayImeController implements DisplayController.OnDisplaysChanged } if (DEBUG_IME_VISIBILITY) { EventLog.writeEvent(IMF_IME_REMOTE_ANIM_START, - statsToken != null ? statsToken.getTag() : TOKEN_NONE, + mStatsToken != null ? mStatsToken.getTag() : ImeTracker.TOKEN_NONE, mDisplayId, mAnimationDirection, alpha, startY , endY, Objects.toString(mImeSourceControl.getLeash()), Objects.toString(mImeSourceControl.getInsetsHint()), @@ -500,7 +517,8 @@ public class DisplayImeController implements DisplayController.OnDisplaysChanged mCancelled = true; if (DEBUG_IME_VISIBILITY) { EventLog.writeEvent(IMF_IME_REMOTE_ANIM_CANCEL, - statsToken != null ? statsToken.getTag() : TOKEN_NONE, mDisplayId, + mStatsToken != null ? mStatsToken.getTag() : ImeTracker.TOKEN_NONE, + mDisplayId, Objects.toString(mImeSourceControl.getInsetsHint())); } } @@ -528,7 +546,7 @@ public class DisplayImeController implements DisplayController.OnDisplaysChanged } if (DEBUG_IME_VISIBILITY) { EventLog.writeEvent(IMF_IME_REMOTE_ANIM_END, - statsToken != null ? statsToken.getTag() : TOKEN_NONE, + mStatsToken != null ? mStatsToken.getTag() : ImeTracker.TOKEN_NONE, mDisplayId, mAnimationDirection, endY, Objects.toString(mImeSourceControl.getLeash()), Objects.toString(mImeSourceControl.getInsetsHint()), diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/common/DisplayInsetsController.java b/libs/WindowManager/Shell/src/com/android/wm/shell/common/DisplayInsetsController.java index 9bdda14cf00b..ca06024a9adb 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/common/DisplayInsetsController.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/common/DisplayInsetsController.java @@ -277,8 +277,7 @@ public class DisplayInsetsController implements DisplayController.OnDisplaysChan * * @param types {@link InsetsType} to show * @param fromIme true if this request originated from IME (InputMethodService). - * @param statsToken the token tracking the current IME show request - * or {@code null} otherwise. + * @param statsToken the token tracking the current IME request or {@code null} otherwise. */ default void showInsets(@InsetsType int types, boolean fromIme, @Nullable ImeTracker.Token statsToken) {} @@ -288,8 +287,7 @@ public class DisplayInsetsController implements DisplayController.OnDisplaysChan * * @param types {@link InsetsType} to hide * @param fromIme true if this request originated from IME (InputMethodService). - * @param statsToken the token tracking the current IME hide request - * or {@code null} otherwise. + * @param statsToken the token tracking the current IME request or {@code null} otherwise. */ default void hideInsets(@InsetsType int types, boolean fromIme, @Nullable ImeTracker.Token statsToken) {} diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/common/DisplayImeControllerTest.java b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/common/DisplayImeControllerTest.java index 01e2f988fbfc..2c0aa12f22d2 100644 --- a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/common/DisplayImeControllerTest.java +++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/common/DisplayImeControllerTest.java @@ -38,6 +38,7 @@ import android.view.InsetsSource; import android.view.InsetsSourceControl; import android.view.InsetsState; import android.view.SurfaceControl; +import android.view.inputmethod.ImeTracker; import androidx.test.filters.SmallTest; @@ -51,6 +52,12 @@ import org.mockito.MockitoAnnotations; import java.util.concurrent.Executor; +/** + * Tests for the display IME controller. + * + * <p> Build/Install/Run: + * atest WMShellUnitTests:DisplayImeControllerTest + */ @SmallTest public class DisplayImeControllerTest extends ShellTestCase { @@ -99,13 +106,13 @@ public class DisplayImeControllerTest extends ShellTestCase { @Test public void showInsets_schedulesNoWorkOnExecutor() { - mPerDisplay.showInsets(ime(), true /* fromIme */, null /* statsToken */); + mPerDisplay.showInsets(ime(), true /* fromIme */, ImeTracker.Token.empty()); verifyZeroInteractions(mExecutor); } @Test public void hideInsets_schedulesNoWorkOnExecutor() { - mPerDisplay.hideInsets(ime(), true /* fromIme */, null /* statsToken */); + mPerDisplay.hideInsets(ime(), true /* fromIme */, ImeTracker.Token.empty()); verifyZeroInteractions(mExecutor); } diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/common/DisplayInsetsControllerTest.java b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/common/DisplayInsetsControllerTest.java index 956f1cd419c2..669e433ba386 100644 --- a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/common/DisplayInsetsControllerTest.java +++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/common/DisplayInsetsControllerTest.java @@ -50,6 +50,12 @@ import org.mockito.MockitoAnnotations; import java.util.List; +/** + * Tests for the display insets controller. + * + * <p> Build/Install/Run: + * atest WMShellUnitTests:DisplayInsetsControllerTest + */ @SmallTest public class DisplayInsetsControllerTest extends ShellTestCase { @@ -114,9 +120,9 @@ public class DisplayInsetsControllerTest extends ShellTestCase { mInsetsControllersByDisplayId.get(DEFAULT_DISPLAY).insetsChanged(null); mInsetsControllersByDisplayId.get(DEFAULT_DISPLAY).insetsControlChanged(null, null); mInsetsControllersByDisplayId.get(DEFAULT_DISPLAY).showInsets(0, false, - null /* statsToken */); + ImeTracker.Token.empty()); mInsetsControllersByDisplayId.get(DEFAULT_DISPLAY).hideInsets(0, false, - null /* statsToken */); + ImeTracker.Token.empty()); mExecutor.flushAll(); assertTrue(defaultListener.topFocusedWindowChangedCount == 1); @@ -136,9 +142,9 @@ public class DisplayInsetsControllerTest extends ShellTestCase { mInsetsControllersByDisplayId.get(SECOND_DISPLAY).insetsChanged(null); mInsetsControllersByDisplayId.get(SECOND_DISPLAY).insetsControlChanged(null, null); mInsetsControllersByDisplayId.get(SECOND_DISPLAY).showInsets(0, false, - null /* statsToken */); + ImeTracker.Token.empty()); mInsetsControllersByDisplayId.get(SECOND_DISPLAY).hideInsets(0, false, - null /* statsToken */); + ImeTracker.Token.empty()); mExecutor.flushAll(); assertTrue(defaultListener.topFocusedWindowChangedCount == 1); |