From f3609800ae8ee603d0959b7137ad8e326f6cfe0b Mon Sep 17 00:00:00 2001 From: Yohei Yukawa Date: Mon, 25 Jul 2022 10:25:50 +0900 Subject: [PATCH] Move getLastInputMethodSubtype() logic to InputMethodSettings This is a mechanical refactoring CL that moves the main logic of InputMethodManagerService#getLastInputMethodSubtype() to InputMethodUtils.InputMethodSettings#getLastInputMethodSubtypeLocked() without changing any developer observable behavior. This is also a preparation to support InputMethodManager#getLastInputMethodSubtype() for background users. Bug: 234882948 Test: atest CtsInputMethodTestCases:InputMethodSubtypeTest Change-Id: I39077b2ef170287af851e3d0e0bd51c6e668ca17 --- .../InputMethodManagerService.java | 18 +--------------- .../server/inputmethod/InputMethodUtils.java | 21 +++++++++++++++++++ 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java index 794c06fec5ae4..be7e8a0a6dcf9 100644 --- a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java +++ b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java @@ -4167,23 +4167,7 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub if (!calledFromValidUserLocked()) { return null; } - final Pair lastIme = mSettings.getLastInputMethodAndSubtypeLocked(); - // TODO: Handle the case of the last IME with no subtypes - if (lastIme == null || TextUtils.isEmpty(lastIme.first) - || TextUtils.isEmpty(lastIme.second)) return null; - final InputMethodInfo lastImi = mMethodMap.get(lastIme.first); - if (lastImi == null) return null; - try { - final int lastSubtypeHash = Integer.parseInt(lastIme.second); - final int lastSubtypeId = SubtypeUtils.getSubtypeIdFromHashCode(lastImi, - lastSubtypeHash); - if (lastSubtypeId < 0 || lastSubtypeId >= lastImi.getSubtypeCount()) { - return null; - } - return lastImi.getSubtypeAt(lastSubtypeId); - } catch (NumberFormatException e) { - return null; - } + return mSettings.getLastInputMethodSubtypeLocked(); } } diff --git a/services/core/java/com/android/server/inputmethod/InputMethodUtils.java b/services/core/java/com/android/server/inputmethod/InputMethodUtils.java index 3373f0c436f98..e37a8e031c57a 100644 --- a/services/core/java/com/android/server/inputmethod/InputMethodUtils.java +++ b/services/core/java/com/android/server/inputmethod/InputMethodUtils.java @@ -592,6 +592,27 @@ final class InputMethodUtils { return getLastSubtypeForInputMethodLockedInternal(null); } + @Nullable + InputMethodSubtype getLastInputMethodSubtypeLocked() { + final Pair lastIme = getLastInputMethodAndSubtypeLocked(); + // TODO: Handle the case of the last IME with no subtypes + if (lastIme == null || TextUtils.isEmpty(lastIme.first) + || TextUtils.isEmpty(lastIme.second)) return null; + final InputMethodInfo lastImi = mMethodMap.get(lastIme.first); + if (lastImi == null) return null; + try { + final int lastSubtypeHash = Integer.parseInt(lastIme.second); + final int lastSubtypeId = SubtypeUtils.getSubtypeIdFromHashCode(lastImi, + lastSubtypeHash); + if (lastSubtypeId < 0 || lastSubtypeId >= lastImi.getSubtypeCount()) { + return null; + } + return lastImi.getSubtypeAt(lastSubtypeId); + } catch (NumberFormatException e) { + return null; + } + } + String getLastSubtypeForInputMethodLocked(String imeId) { Pair ime = getLastSubtypeForInputMethodLockedInternal(imeId); if (ime != null) {