diff options
| author | 2024-09-02 17:12:05 +0200 | |
|---|---|---|
| committer | 2024-09-03 17:20:22 +0200 | |
| commit | 81ad33cfd4eb826caeb006939d852f0fa2820aea (patch) | |
| tree | 3f669684dbe04cd4925bd7991bf06a57d4e75502 | |
| parent | 5ff76a1a8e988edc85f3e5dc07b0dcdae5fa8ba0 (diff) | |
Store and check IME window vis value before update
This stores the last reported value of IME window vis (similar to the
IME back disposition), to be checked against the new value in avoiding
duplicate updates.
Flag: EXEMPT refactor
Bug: 364270925
Test: presubmit
Change-Id: I72e81f259b33eecfc956c78fa0da3209b492d99c
| -rw-r--r-- | core/java/android/inputmethodservice/InputMethodService.java | 44 |
1 files changed, 28 insertions, 16 deletions
diff --git a/core/java/android/inputmethodservice/InputMethodService.java b/core/java/android/inputmethodservice/InputMethodService.java index ff737a4f9fb8..49e23584cf4f 100644 --- a/core/java/android/inputmethodservice/InputMethodService.java +++ b/core/java/android/inputmethodservice/InputMethodService.java @@ -664,9 +664,14 @@ public class InputMethodService extends AbstractInputMethodService { int mStatusIcon; + /** Latest reported value of back disposition mode. */ @BackDispositionMode int mBackDisposition; + /** Latest reported value of IME window visibility state. */ + @ImeWindowVisibility + private int mImeWindowVisibility; + private Object mLock = new Object(); @GuardedBy("mLock") private boolean mNotifyUserActionSent; @@ -1047,7 +1052,7 @@ public class InputMethodService extends AbstractInputMethodService { ImeTracker.forLogging().onFailed(statsToken, ImeTracker.PHASE_IME_ON_SHOW_SOFT_INPUT_TRUE); } - setImeWindowStatus(mapToImeWindowStatus(), mBackDisposition); + setImeWindowVisibility(computeImeWindowVis()); final boolean isVisible = isInputViewShown(); final boolean visibilityChanged = isVisible != wasVisible; @@ -1357,9 +1362,22 @@ public class InputMethodService extends AbstractInputMethodService { mImeSurfaceRemoverRunnable = null; } - private void setImeWindowStatus(@ImeWindowVisibility int visibilityFlags, + /** + * Sets the IME window visibility state. + * + * @param vis the IME window visibility state to be set. + */ + private void setImeWindowVisibility(@ImeWindowVisibility int vis) { + if (vis == mImeWindowVisibility) { + return; + } + mImeWindowVisibility = vis; + setImeWindowStatus(mImeWindowVisibility, mBackDisposition); + } + + private void setImeWindowStatus(@ImeWindowVisibility int vis, @BackDispositionMode int backDisposition) { - mPrivOps.setImeWindowStatusAsync(visibilityFlags, backDisposition); + mPrivOps.setImeWindowStatusAsync(vis, backDisposition); } /** Set region of the keyboard to be avoided from back gesture */ @@ -1986,7 +2004,7 @@ public class InputMethodService extends AbstractInputMethodService { } // If user uses hard keyboard, IME button should always be shown. boolean showing = onEvaluateInputViewShown(); - setImeWindowStatus(IME_ACTIVE | (showing ? IME_VISIBLE : 0), mBackDisposition); + setImeWindowVisibility(IME_ACTIVE | (showing ? IME_VISIBLE : 0)); } Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER); } @@ -2053,7 +2071,7 @@ public class InputMethodService extends AbstractInputMethodService { return; } mBackDisposition = disposition; - setImeWindowStatus(mapToImeWindowStatus(), mBackDisposition); + setImeWindowStatus(mImeWindowVisibility, mBackDisposition); } /** @@ -3132,14 +3150,8 @@ public class InputMethodService extends AbstractInputMethodService { Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "IMS.showWindow"); mDecorViewWasVisible = mDecorViewVisible; mInShowWindow = true; - final int previousImeWindowStatus = - (mDecorViewVisible ? IME_ACTIVE : 0) | (isInputViewShown() - ? (!mWindowVisible ? -1 : IME_VISIBLE) : 0); startViews(prepareWindow(showInput)); - final int nextImeWindowStatus = mapToImeWindowStatus(); - if (previousImeWindowStatus != nextImeWindowStatus) { - setImeWindowStatus(nextImeWindowStatus, mBackDisposition); - } + setImeWindowVisibility(computeImeWindowVis()); mNavigationBarController.onWindowShown(); // compute visibility @@ -3317,7 +3329,7 @@ public class InputMethodService extends AbstractInputMethodService { ImeTracker.forLogging().onProgress(statsToken, ImeTracker.PHASE_IME_HIDE_WINDOW); ImeTracing.getInstance().triggerServiceDump("InputMethodService#hideWindow", mDumper, null /* icProto */); - setImeWindowStatus(0 /* visibilityFlags */, mBackDisposition); + setImeWindowVisibility(0 /* vis */); if (android.view.inputmethod.Flags.refactorInsetsController()) { // The ImeInsetsSourceProvider need the statsToken when dispatching the control. We // send the token here, so that another request in the provider can be cancelled. @@ -4492,10 +4504,10 @@ public class InputMethodService extends AbstractInputMethodService { }; } + /** Computes the IME window visibility state. */ @ImeWindowVisibility - private int mapToImeWindowStatus() { - return IME_ACTIVE - | (isInputViewShown() ? IME_VISIBLE : 0); + private int computeImeWindowVis() { + return IME_ACTIVE | (isInputViewShown() ? IME_VISIBLE : 0); } /** |