From 16b6b5109a1b1023d859bf9a46040387f24f3c20 Mon Sep 17 00:00:00 2001 From: Taran Singh Date: Mon, 7 Aug 2023 20:48:48 +0000 Subject: [PATCH] Invalidate stylus handwriting availability cache In [1] we introduced caching of attributes that determines if stylus handwriting is available. The strategy used to invalidate cache on IME unbind. However, a stale value of InputMethodInfo#supportsStylusHandwriting can be cached if IMM#isStylusHandwritingAvailable() previous IME unbinds and the next one isn't yet connected. A better approach would be to cache the value on the new IME service connection. [1]: I6d89d82589e4946e07bfbc4b97811fe4537b1a9b Bug: 288618291 Bug: 294162601 Test: atest InputMethodServiceLifecycleTest Change-Id: I35013b6194a67656aefca004e69cfc64f12c1e88 Merged-In: I35013b6194a67656aefca004e69cfc64f12c1e88 --- .../server/inputmethod/InputMethodBindingController.java | 6 ++++++ .../server/inputmethod/InputMethodManagerService.java | 1 - 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/services/core/java/com/android/server/inputmethod/InputMethodBindingController.java b/services/core/java/com/android/server/inputmethod/InputMethodBindingController.java index ba9e280be49d0..53083366b0417 100644 --- a/services/core/java/com/android/server/inputmethod/InputMethodBindingController.java +++ b/services/core/java/com/android/server/inputmethod/InputMethodBindingController.java @@ -40,6 +40,7 @@ import android.util.Slog; import android.view.WindowManager; import android.view.inputmethod.InputMethod; import android.view.inputmethod.InputMethodInfo; +import android.view.inputmethod.InputMethodManager; import com.android.internal.annotations.GuardedBy; import com.android.internal.annotations.VisibleForTesting; @@ -295,7 +296,12 @@ final class InputMethodBindingController { } if (DEBUG) Slog.v(TAG, "Initiating attach with token: " + mCurToken); final InputMethodInfo info = mMethodMap.get(mSelectedMethodId); + boolean supportsStylusHwChanged = + mSupportsStylusHw != info.supportsStylusHandwriting(); mSupportsStylusHw = info.supportsStylusHandwriting(); + if (supportsStylusHwChanged) { + InputMethodManager.invalidateLocalStylusHandwritingAvailabilityCaches(); + } mService.initializeImeLocked(mCurMethod, mCurToken); mService.scheduleNotifyImeUidToAudioService(mCurMethodUid); mService.reRequestCurrentClientSessionLocked(); diff --git a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java index cfcb4620bf25e..771ac9481a758 100644 --- a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java +++ b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java @@ -2369,7 +2369,6 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub mCurVirtualDisplayToScreenMatrix = null; ImeTracker.forLogging().onFailed(mCurStatsToken, ImeTracker.PHASE_SERVER_WAIT_IME); mCurStatsToken = null; - InputMethodManager.invalidateLocalStylusHandwritingAvailabilityCaches(); mMenuController.hideInputMethodMenuLocked(); } }