From 20ef3338c666cf34de2068d183218cde9619a118 Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Tue, 9 Nov 2010 12:19:32 -0800 Subject: [PATCH] Revert "Add a history of InputMethodSubtype for getting the last subtype of selected IME when IME was changed." This reverts commit 1ab852fbcfe155c9d4373b7130f8515591669634. --- core/java/android/provider/Settings.java | 8 - .../android/server/InputMethodManagerService.java | 273 ++++----------------- 2 files changed, 47 insertions(+), 234 deletions(-) diff --git a/core/java/android/provider/Settings.java b/core/java/android/provider/Settings.java index 1fe2c5a94094..ddfcb0652fd9 100644 --- a/core/java/android/provider/Settings.java +++ b/core/java/android/provider/Settings.java @@ -2396,14 +2396,6 @@ public final class Settings { "selected_input_method_subtype"; /** - * Setting to record the history of input method subtype, holding the pair of ID of IME - * and its last used subtype. - * @hide - */ - public static final String INPUT_METHODS_SUBTYPE_HISTORY = - "input_methods_subtype_history"; - - /** * Whether the device has been provisioned (0 = false, 1 = true) */ public static final String DEVICE_PROVISIONED = "device_provisioned"; diff --git a/services/java/com/android/server/InputMethodManagerService.java b/services/java/com/android/server/InputMethodManagerService.java index da5f204f438c..d035eb586aad 100644 --- a/services/java/com/android/server/InputMethodManagerService.java +++ b/services/java/com/android/server/InputMethodManagerService.java @@ -116,7 +116,6 @@ public class InputMethodManagerService extends IInputMethodManager.Stub static final long TIME_TO_RECONNECT = 10*1000; private static final int NOT_A_SUBTYPE_ID = -1; - private static final String NOT_A_SUBTYPE_ID_STR = String.valueOf(NOT_A_SUBTYPE_ID); // If IME doesn't support the system locale, the default subtype will be the first defined one. private static final int DEFAULT_SUBTYPE_ID = 0; @@ -367,7 +366,9 @@ public class InputMethodManagerService extends IInputMethodManager.Stub if (!doit) { return true; } - resetSelectedInputMethodAndSubtypeLocked(""); + Settings.Secure.putString(mContext.getContentResolver(), + Settings.Secure.DEFAULT_INPUT_METHOD, ""); + resetSelectedInputMethodSubtype(); chooseNewDefaultIMELocked(); return true; } @@ -424,7 +425,9 @@ public class InputMethodManagerService extends IInputMethodManager.Stub changed = true; curIm = null; Slog.i(TAG, "Unsetting current input method"); - resetSelectedInputMethodAndSubtypeLocked(""); + Settings.Secure.putString(mContext.getContentResolver(), + Settings.Secure.DEFAULT_INPUT_METHOD, ""); + resetSelectedInputMethodSubtype(); } } } @@ -507,7 +510,9 @@ public class InputMethodManagerService extends IInputMethodManager.Stub Slog.i(TAG, "No default found, using " + defIm.getId()); } if (defIm != null) { - setSelectSubtypeLocked(defIm, NOT_A_SUBTYPE_ID); + Settings.Secure.putString(mContext.getContentResolver(), + Settings.Secure.DEFAULT_INPUT_METHOD, defIm.getId()); + putSelectedInputMethodSubtype(defIm, NOT_A_SUBTYPE_ID); } } @@ -989,7 +994,7 @@ public class InputMethodManagerService extends IInputMethodManager.Stub synchronized (mMethodMap) { if (mCurMethod != null) { try { - setSelectSubtypeLocked(info, subtypeId); + putSelectedInputMethodSubtype(info, subtypeId); if (mInputShown) { // If mInputShown is false, there is no IME button on the // system bar. @@ -1009,13 +1014,13 @@ public class InputMethodManagerService extends IInputMethodManager.Stub final long ident = Binder.clearCallingIdentity(); try { + mCurMethodId = id; // Set a subtype to this input method. // subtypeId the name of a subtype which will be set. - setSelectedInputMethodAndSubtypeLocked(info, subtypeId); - // mCurMethodId should be updated after setSelectedInputMethodAndSubtypeLocked() - // because mCurMethodId is stored as a history in - // setSelectedInputMethodAndSubtypeLocked(). - mCurMethodId = id; + putSelectedInputMethodSubtype(info, subtypeId); + + Settings.Secure.putString(mContext.getContentResolver(), + Settings.Secure.DEFAULT_INPUT_METHOD, id); if (ActivityManagerNative.isSystemReady()) { Intent intent = new Intent(Intent.ACTION_INPUT_METHOD_CHANGED); @@ -1482,7 +1487,9 @@ public class InputMethodManagerService extends IInputMethodManager.Stub } } InputMethodInfo imi = enabled.get(i); - resetSelectedInputMethodAndSubtypeLocked(imi.getId()); + Settings.Secure.putString(mContext.getContentResolver(), + Settings.Secure.DEFAULT_INPUT_METHOD, imi.getId()); + putSelectedInputMethodSubtype(imi, NOT_A_SUBTYPE_ID); return true; } @@ -1786,8 +1793,11 @@ public class InputMethodManagerService extends IInputMethodManager.Stub String selId = Settings.Secure.getString(mContext.getContentResolver(), Settings.Secure.DEFAULT_INPUT_METHOD); if (id.equals(selId)) { - resetSelectedInputMethodAndSubtypeLocked(enabledInputMethodsList.size() > 0 - ? enabledInputMethodsList.get(0).first : ""); + Settings.Secure.putString( + mContext.getContentResolver(), Settings.Secure.DEFAULT_INPUT_METHOD, + enabledInputMethodsList.size() > 0 + ? enabledInputMethodsList.get(0).first : ""); + resetSelectedInputMethodSubtype(); } // Previous state was enabled. return true; @@ -1799,54 +1809,22 @@ public class InputMethodManagerService extends IInputMethodManager.Stub } } - private void saveCurrentInputMethodAndSubtypeToHistory() { - String subtypeId = NOT_A_SUBTYPE_ID_STR; - if (mCurrentSubtype != null) { - subtypeId = String.valueOf(mCurrentSubtype.hashCode()); - } - mSettings.addSubtypeToHistory(mCurMethodId, subtypeId); + private void resetSelectedInputMethodSubtype() { + Settings.Secure.putInt(mContext.getContentResolver(), + Settings.Secure.SELECTED_INPUT_METHOD_SUBTYPE, NOT_A_SUBTYPE_ID); } - private void setSelectSubtypeLocked(InputMethodInfo imi, int subtypeId) { - saveCurrentInputMethodAndSubtypeToHistory(); - if (imi == null || subtypeId < 0) { - mSettings.putSelectedSubtype(NOT_A_SUBTYPE_ID); - mCurrentSubtype = null; + private void putSelectedInputMethodSubtype(InputMethodInfo imi, int subtypeId) { + final ArrayList subtypes = imi.getSubtypes(); + if (subtypeId >= 0 && subtypeId < subtypes.size()) { + Settings.Secure.putInt(mContext.getContentResolver(), + Settings.Secure.SELECTED_INPUT_METHOD_SUBTYPE, + subtypes.get(subtypeId).hashCode()); + mCurrentSubtype = subtypes.get(subtypeId); } else { - final ArrayList subtypes = imi.getSubtypes(); - if (subtypeId < subtypes.size()) { - mSettings.putSelectedSubtype(subtypes.get(subtypeId).hashCode()); - mCurrentSubtype = subtypes.get(subtypeId); - } else { - mSettings.putSelectedSubtype(NOT_A_SUBTYPE_ID); - mCurrentSubtype = null; - } - } - - } - - private void setSelectedInputMethodAndSubtypeLocked(InputMethodInfo imi, int subtypeId) { - setSelectSubtypeLocked(imi, subtypeId); - mSettings.putSelectedInputMethod(imi.getId()); - } - - private void resetSelectedInputMethodAndSubtypeLocked(String newDefaultIme) { - InputMethodInfo imi = mMethodMap.get(newDefaultIme); - int lastSubtypeId = NOT_A_SUBTYPE_ID; - // newDefaultIme is empty when there is no candidate for the selected IME. - if (imi != null && !TextUtils.isEmpty(newDefaultIme)) { - String subtypeHashCode = mSettings.getLastSubtypeForInputMethodLocked(newDefaultIme); - if (subtypeHashCode != null) { - try { - lastSubtypeId = getSubtypeIdFromHashCode( - imi, Integer.valueOf(subtypeHashCode)); - } catch (NumberFormatException e) { - Slog.w(TAG, "HashCode for subtype looks broken: " + subtypeHashCode, e); - } - } + resetSelectedInputMethodSubtype(); + mCurrentSubtype = null; } - setSelectSubtypeLocked(imi, lastSubtypeId); - mSettings.putSelectedInputMethod(newDefaultIme); } private int getSelectedInputMethodSubtypeId(String id) { @@ -1854,6 +1832,7 @@ public class InputMethodManagerService extends IInputMethodManager.Stub if (imi == null) { return NOT_A_SUBTYPE_ID; } + ArrayList subtypes = imi.getSubtypes(); int subtypeId; try { subtypeId = Settings.Secure.getInt(mContext.getContentResolver(), @@ -1861,14 +1840,9 @@ public class InputMethodManagerService extends IInputMethodManager.Stub } catch (SettingNotFoundException e) { return NOT_A_SUBTYPE_ID; } - return getSubtypeIdFromHashCode(imi, subtypeId); - } - - private int getSubtypeIdFromHashCode(InputMethodInfo imi, int subtypeHashCode) { - ArrayList subtypes = imi.getSubtypes(); for (int i = 0; i < subtypes.size(); ++i) { InputMethodSubtype ims = subtypes.get(i); - if (subtypeHashCode == ims.hashCode()) { + if (subtypeId == ims.hashCode()) { return i; } } @@ -1948,10 +1922,10 @@ public class InputMethodManagerService extends IInputMethodManager.Stub // example: ("ime0;subtype0;subtype1;subtype2:ime1:ime2;subtype0") private static final char INPUT_METHOD_SEPARATER = ':'; private static final char INPUT_METHOD_SUBTYPE_SEPARATER = ';'; - private final TextUtils.SimpleStringSplitter mInputMethodSplitter = + private final TextUtils.SimpleStringSplitter mStringColonSplitter = new TextUtils.SimpleStringSplitter(INPUT_METHOD_SEPARATER); - private final TextUtils.SimpleStringSplitter mSubtypeSplitter = + private final TextUtils.SimpleStringSplitter mStringSemiColonSplitter = new TextUtils.SimpleStringSplitter(INPUT_METHOD_SUBTYPE_SEPARATER); private final ContentResolver mResolver; @@ -2014,16 +1988,16 @@ public class InputMethodManagerService extends IInputMethodManager.Stub if (TextUtils.isEmpty(enabledInputMethodsStr)) { return imsList; } - mInputMethodSplitter.setString(enabledInputMethodsStr); - while (mInputMethodSplitter.hasNext()) { - String nextImsStr = mInputMethodSplitter.next(); - mSubtypeSplitter.setString(nextImsStr); - if (mSubtypeSplitter.hasNext()) { + mStringColonSplitter.setString(enabledInputMethodsStr); + while (mStringColonSplitter.hasNext()) { + String nextImsStr = mStringColonSplitter.next(); + mStringSemiColonSplitter.setString(nextImsStr); + if (mStringSemiColonSplitter.hasNext()) { ArrayList subtypeHashes = new ArrayList(); // The first element is ime id. - String imeId = mSubtypeSplitter.next(); - while (mSubtypeSplitter.hasNext()) { - subtypeHashes.add(mSubtypeSplitter.next()); + String imeId = mStringSemiColonSplitter.next(); + while (mStringSemiColonSplitter.hasNext()) { + subtypeHashes.add(mStringSemiColonSplitter.next()); } imsList.add(new Pair>(imeId, subtypeHashes)); } @@ -2109,161 +2083,8 @@ public class InputMethodManagerService extends IInputMethodManager.Stub private String getEnabledInputMethodsStr() { mEnabledInputMethodsStrCache = Settings.Secure.getString( mResolver, Settings.Secure.ENABLED_INPUT_METHODS); - if (DEBUG) { - Slog.d(TAG, "getEnabledInputMethodsStr: " + mEnabledInputMethodsStrCache); - } return mEnabledInputMethodsStrCache; } - - private void saveSubtypeHistory( - List> savedImes, String newImeId, String newSubtypeId) { - StringBuilder builder = new StringBuilder(); - boolean isImeAdded = false; - if (!TextUtils.isEmpty(newImeId) && !TextUtils.isEmpty(newSubtypeId)) { - builder.append(newImeId).append(INPUT_METHOD_SUBTYPE_SEPARATER).append( - newSubtypeId); - isImeAdded = true; - } - for (Pair ime: savedImes) { - String imeId = ime.first; - String subtypeId = ime.second; - if (TextUtils.isEmpty(subtypeId)) { - subtypeId = NOT_A_SUBTYPE_ID_STR; - } - if (isImeAdded) { - builder.append(INPUT_METHOD_SEPARATER); - } else { - isImeAdded = true; - } - builder.append(imeId).append(INPUT_METHOD_SUBTYPE_SEPARATER).append( - subtypeId); - } - // Remove the last INPUT_METHOD_SEPARATER - putSubtypeHistoryStr(builder.toString()); - } - - public void addSubtypeToHistory(String imeId, String subtypeId) { - List> subtypeHistory = loadInputMethodAndSubtypeHistoryLocked(); - for (Pair ime: subtypeHistory) { - if (ime.first.equals(imeId)) { - if (DEBUG) { - Slog.v(TAG, "Subtype found in the history: " + imeId - + ime.second); - } - // We should break here - subtypeHistory.remove(ime); - break; - } - } - saveSubtypeHistory(subtypeHistory, imeId, subtypeId); - } - - private void putSubtypeHistoryStr(String str) { - if (DEBUG) { - Slog.d(TAG, "putSubtypeHistoryStr: " + str); - } - Settings.Secure.putString( - mResolver, Settings.Secure.INPUT_METHODS_SUBTYPE_HISTORY, str); - } - - public Pair getLastInputMethodAndSubtypeLocked() { - // Gets the first one from the history - return getLastSubtypeForInputMethodLockedInternal(null); - } - - public String getLastSubtypeForInputMethodLocked(String imeId) { - Pair ime = getLastSubtypeForInputMethodLockedInternal(imeId); - if (ime != null) { - return ime.second; - } else { - return null; - } - } - - private Pair getLastSubtypeForInputMethodLockedInternal(String imeId) { - List>> enabledImes = - getEnabledInputMethodsAndSubtypeListLocked(); - List> subtypeHistory = loadInputMethodAndSubtypeHistoryLocked(); - for (Pair imeAndSubtype: subtypeHistory) { - final String imeInTheHistory = imeAndSubtype.first; - // If imeId is empty, returns the first IME and subtype in the history - if (TextUtils.isEmpty(imeId) || imeInTheHistory.equals(imeId)) { - final String subtypeInTheHistory = imeAndSubtype.second; - final String subtypeHashCode = getEnabledSubtypeForInputMethodAndSubtypeLocked( - enabledImes, imeInTheHistory, subtypeInTheHistory); - if (!TextUtils.isEmpty(subtypeHashCode)) { - if (DEBUG) { - Slog.d(TAG, "Enabled subtype found in the history:" + subtypeHashCode); - } - return new Pair(imeInTheHistory, subtypeHashCode); - } - } - } - if (DEBUG) { - Slog.d(TAG, "No enabled IME found in the history"); - } - return null; - } - - private String getEnabledSubtypeForInputMethodAndSubtypeLocked(List>> enabledImes, String imeId, String subtypeHashCode) { - for (Pair> enabledIme: enabledImes) { - if (enabledIme.first.equals(imeId)) { - for (String s: enabledIme.second) { - if (s.equals(subtypeHashCode)) { - // If both imeId and subtypeId are enabled, return subtypeId. - return s; - } - } - // If imeId was enabled but subtypeId was disabled. - return NOT_A_SUBTYPE_ID_STR; - } - } - // If both imeId and subtypeId are disabled, return null - return null; - } - - private List> loadInputMethodAndSubtypeHistoryLocked() { - ArrayList> imsList = new ArrayList>(); - final String subtypeHistoryStr = getSubtypeHistoryStr(); - if (TextUtils.isEmpty(subtypeHistoryStr)) { - return imsList; - } - mInputMethodSplitter.setString(subtypeHistoryStr); - while (mInputMethodSplitter.hasNext()) { - String nextImsStr = mInputMethodSplitter.next(); - mSubtypeSplitter.setString(nextImsStr); - if (mSubtypeSplitter.hasNext()) { - String subtypeId = NOT_A_SUBTYPE_ID_STR; - // The first element is ime id. - String imeId = mSubtypeSplitter.next(); - while (mSubtypeSplitter.hasNext()) { - subtypeId = mSubtypeSplitter.next(); - break; - } - imsList.add(new Pair(imeId, subtypeId)); - } - } - return imsList; - } - - private String getSubtypeHistoryStr() { - if (DEBUG) { - Slog.d(TAG, "getSubtypeHistoryStr: " + Settings.Secure.getString( - mResolver, Settings.Secure.INPUT_METHODS_SUBTYPE_HISTORY)); - } - return Settings.Secure.getString( - mResolver, Settings.Secure.INPUT_METHODS_SUBTYPE_HISTORY); - } - - public void putSelectedInputMethod(String imeId) { - Settings.Secure.putString(mResolver, Settings.Secure.DEFAULT_INPUT_METHOD, imeId); - } - - public void putSelectedSubtype(int subtypeId) { - Settings.Secure.putInt( - mResolver, Settings.Secure.SELECTED_INPUT_METHOD_SUBTYPE, subtypeId); - } } // ---------------------------------------------------------------------- -- 2.11.0