From 55f6a873458b72b99364d531e9e0cd54236f1cc1 Mon Sep 17 00:00:00 2001 From: Adrian Roos Date: Tue, 24 May 2022 16:57:47 +0200 Subject: [PATCH] Prevent IMEs from switching to another IME that isn't enabled Fixes an issue where the current IME can switch to any IME, even if it hasn't been enabled. Fixes: 227207653 Test: atest android.view.inputmethod.cts.InputMethodServiceTest Change-Id: I12829de9fa58610a7d53e4b154e1550f0f791e75 --- .../server/inputmethod/InputMethodManagerService.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java index 8cf0ab7441243..99757d955863b 100644 --- a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java +++ b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java @@ -4710,6 +4710,13 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub Slog.w(TAG, "Ignoring setInputMethod of uid " + Binder.getCallingUid() + " token: " + token); return; + } else { + // Called with current IME's token. + if (mMethodMap.get(id) != null + && mSettings.getEnabledInputMethodListWithFilterLocked( + (info) -> info.getId().equals(id)).isEmpty()) { + throw new IllegalStateException("Requested IME is not enabled: " + id); + } } final long ident = Binder.clearCallingIdentity();