diff options
| author | 2024-01-29 15:42:24 +0100 | |
|---|---|---|
| committer | 2024-01-31 11:39:26 +0100 | |
| commit | d1a6be1b1472c683dd45344c936e543ac97533dc (patch) | |
| tree | 271ec1f45290f1671b74a6414bdb07642a5b4857 | |
| parent | 4e07be21bfb4f2fded216eca3bc1556422957219 (diff) | |
Fix VDM IME handling:
1. Whenever the selected input method changes, also update the default
device input method in settings, if the current device is the
default one.
2. Whenever new settings instance is created, always pass the current
device id, so the settings constructor knows whether to restore the
stored default device id or not.
Test: atest VirtualDeviceImeTest --iterations=50
Bug: 287269288
Change-Id: Ic8646fef8a18f03cdd387dc672bea991338c6793
| -rw-r--r-- | services/core/java/com/android/server/inputmethod/InputMethodManagerService.java | 30 | ||||
| -rw-r--r-- | services/core/java/com/android/server/inputmethod/InputMethodSettings.java | 7 |
2 files changed, 29 insertions, 8 deletions
diff --git a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java index 4767ebd0aab0..7445484335fe 100644 --- a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java +++ b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java @@ -3184,6 +3184,24 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub } } } + + if (mDeviceIdToShowIme == DEVICE_ID_DEFAULT) { + String ime = SecureSettingsWrapper.getString( + Settings.Secure.DEFAULT_INPUT_METHOD, null, mSettings.getUserId()); + String defaultDeviceIme = SecureSettingsWrapper.getString( + Settings.Secure.DEFAULT_DEVICE_INPUT_METHOD, null, mSettings.getUserId()); + if (defaultDeviceIme != null && !Objects.equals(ime, defaultDeviceIme)) { + if (DEBUG) { + Slog.v(TAG, "Current input method " + ime + " differs from the stored default" + + " device input method for user " + mSettings.getUserId() + + " - restoring " + defaultDeviceIme); + } + SecureSettingsWrapper.putString( + Settings.Secure.DEFAULT_INPUT_METHOD, defaultDeviceIme, + mSettings.getUserId()); + } + } + // We are assuming that whoever is changing DEFAULT_INPUT_METHOD and // ENABLED_INPUT_METHODS is taking care of keeping them correctly in // sync, so we will never have a DEFAULT_INPUT_METHOD that is not @@ -5363,7 +5381,11 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub if (!setSubtypeOnly) { // Set InputMethod here - mSettings.putSelectedInputMethod(imi != null ? imi.getId() : ""); + final String imeId = imi != null ? imi.getId() : ""; + mSettings.putSelectedInputMethod(imeId); + if (mDeviceIdToShowIme == DEVICE_ID_DEFAULT) { + mSettings.putSelectedDefaultDeviceInputMethod(imeId); + } } } @@ -5506,6 +5528,9 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub return false; // IME is not found or not enabled. } settings.putSelectedInputMethod(imeId); + if (mDeviceIdToShowIme == DEVICE_ID_DEFAULT) { + settings.putSelectedDefaultDeviceInputMethod(imeId); + } settings.putSelectedSubtype(NOT_A_SUBTYPE_ID); return true; } @@ -6541,6 +6566,9 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub // Reset selected IME. settings.putSelectedInputMethod(nextIme); + if (mDeviceIdToShowIme == DEVICE_ID_DEFAULT) { + settings.putSelectedDefaultDeviceInputMethod(nextIme); + } settings.putSelectedSubtype(NOT_A_SUBTYPE_ID); } out.println("Reset current and enabled IMEs for user #" + userId); diff --git a/services/core/java/com/android/server/inputmethod/InputMethodSettings.java b/services/core/java/com/android/server/inputmethod/InputMethodSettings.java index a51002be344f..e444db1b79e8 100644 --- a/services/core/java/com/android/server/inputmethod/InputMethodSettings.java +++ b/services/core/java/com/android/server/inputmethod/InputMethodSettings.java @@ -36,7 +36,6 @@ import com.android.internal.annotations.VisibleForTesting; import java.util.ArrayList; import java.util.List; -import java.util.Objects; import java.util.function.Predicate; /** @@ -88,12 +87,6 @@ final class InputMethodSettings { mMethodMap = methodMap; mMethodList = methodMap.values(); mUserId = userId; - String ime = getSelectedInputMethod(); - String defaultDeviceIme = getSelectedDefaultDeviceInputMethod(); - if (defaultDeviceIme != null && !Objects.equals(ime, defaultDeviceIme)) { - putSelectedInputMethod(defaultDeviceIme); - putSelectedDefaultDeviceInputMethod(null); - } } @AnyThread |