diff options
| author | 2019-05-29 17:11:57 +0800 | |
|---|---|---|
| committer | 2019-05-30 12:27:17 +0800 | |
| commit | e0af39403ed67d26b918da32c9da05d0371835ea (patch) | |
| tree | 214656d8fc60d5330f45922a7a983fa41bbf098a | |
| parent | acd959e53f82f3b19bb5ffc442d08264139d11b9 (diff) | |
Skip IME initialization when received the token that already registered
When IME window switches from current display to another display and back quickly,
system will re-bind InputMethodService to re-attach window token for each moving,
the IME service lifecycle will be onBind -> onUnBind -> onDestroy -> onBind.
Ideally, system will deliver window token when onServiceConnected and system should
only receive one onServiceConnected when the last service bound.
But due to user switch display very quick, before unbind service callbacked from client,
the next bind service request comes, caused the connection exists in system side and
client will then callback 2 onServiceConnected to system.
Since CL [1] introduced InputMethodPrivilegedOperationsRegistry to deal with token
registraction singleton-ness, the exception will be thrown for above case due to
the duplicate window token passed to client.
Add InputMethodPrivilegedOperationsRegistry#isRegistered to check if the token
already registered, if so, skip this duplicate initialization request.
[1]: I4a61470f06ffac5f7a512536f8431489db0108f4
Fix: 133624278
Test: manual as below steps:
1) Settings > Developer options, enable "Simulated display" & "force desktop mode"
2) Reboot device.
3) Launch app from simulated display.
4) Launch app from primary display (i.e. contacts), focus EditText to show IME.
5) Tapping primary & simulated display repeatly & quickly.
6) See if any exception log from IME application. (i.e. Gboard)
Change-Id: Ie6bfbae735724fe744590e715124d2737d2b665d
| -rw-r--r-- | core/java/android/inputmethodservice/InputMethodService.java | 6 | ||||
| -rw-r--r-- | core/java/com/android/internal/inputmethod/InputMethodPrivilegedOperationsRegistry.java | 17 |
2 files changed, 22 insertions, 1 deletions
diff --git a/core/java/android/inputmethodservice/InputMethodService.java b/core/java/android/inputmethodservice/InputMethodService.java index ab630fd7467b..82d4d1d10d7e 100644 --- a/core/java/android/inputmethodservice/InputMethodService.java +++ b/core/java/android/inputmethodservice/InputMethodService.java @@ -472,8 +472,12 @@ public class InputMethodService extends AbstractInputMethodService { */ @MainThread @Override - public final void initializeInternal(IBinder token, int displayId, + public final void initializeInternal(@NonNull IBinder token, int displayId, IInputMethodPrivilegedOperations privilegedOperations) { + if (InputMethodPrivilegedOperationsRegistry.isRegistered(token)) { + Log.w(TAG, "The token has already registered, ignore this initialization."); + return; + } mPrivOps.set(privilegedOperations); InputMethodPrivilegedOperationsRegistry.put(token, mPrivOps); updateInputMethodDisplay(displayId); diff --git a/core/java/com/android/internal/inputmethod/InputMethodPrivilegedOperationsRegistry.java b/core/java/com/android/internal/inputmethod/InputMethodPrivilegedOperationsRegistry.java index 1436aed5129a..049f952fceb8 100644 --- a/core/java/com/android/internal/inputmethod/InputMethodPrivilegedOperationsRegistry.java +++ b/core/java/com/android/internal/inputmethod/InputMethodPrivilegedOperationsRegistry.java @@ -132,4 +132,21 @@ public final class InputMethodPrivilegedOperationsRegistry { } } } + + /** + * Check the given IME token registration status. + * + * @param token IME token + * @return {@code true} when the IME token has already registered + * {@link InputMethodPrivilegedOperations}, {@code false} otherwise. + */ + @AnyThread + public static boolean isRegistered(IBinder token) { + synchronized (sLock) { + if (sRegistry == null) { + return false; + } + return sRegistry.containsKey(token); + } + } } |