diff options
| author | 2016-02-16 16:11:49 +0000 | |
|---|---|---|
| committer | 2016-02-16 16:11:50 +0000 | |
| commit | ce3f338040894f23cdea7ac2f9e9e14a58fd15a3 (patch) | |
| tree | c052a95624a9e81731ec80876e1b78141c4aced6 | |
| parent | d6b6e9c2efd3454b2ab047a506ce925e45ea75a0 (diff) | |
| parent | 8752367042cb690f78953557433c16ac77eeea45 (diff) | |
Merge changes I0f79243e,Ia27e19f9,Iec6b89f0,I276c7eb0 into nyc-dev
* changes:
Have unified setter/getter for Secure Settings.
Remove redundant arguments.
Use Context#getSystemService(Class<T>) in IMMS.
Use Java7 diamond operator in InputMethodUtils.
3 files changed, 89 insertions, 88 deletions
diff --git a/core/java/com/android/internal/inputmethod/InputMethodUtils.java b/core/java/com/android/internal/inputmethod/InputMethodUtils.java index f0c10945f746..c1011503dae7 100644 --- a/core/java/com/android/internal/inputmethod/InputMethodUtils.java +++ b/core/java/com/android/internal/inputmethod/InputMethodUtils.java @@ -27,7 +27,6 @@ import android.content.pm.PackageManager; import android.content.res.Resources; import android.os.RemoteException; import android.provider.Settings; -import android.provider.Settings.SettingNotFoundException; import android.text.TextUtils; import android.text.TextUtils.SimpleStringSplitter; import android.util.ArrayMap; @@ -769,7 +768,7 @@ public class InputMethodUtils { public static ArrayMap<String, ArraySet<String>> parseInputMethodsAndSubtypesString( @Nullable final String inputMethodsAndSubtypesString) { - final ArrayMap<String, ArraySet<String>> imeMap = new ArrayMap<String, ArraySet<String>>(); + final ArrayMap<String, ArraySet<String>> imeMap = new ArrayMap<>(); if (TextUtils.isEmpty(inputMethodsAndSubtypesString)) { return imeMap; } @@ -784,7 +783,7 @@ public class InputMethodUtils { typeSplitter, subtypeSplitter); for (Pair<String, ArrayList<String>> ime : allImeSettings) { - ArraySet<String> subtypes = new ArraySet<String>(); + ArraySet<String> subtypes = new ArraySet<>(); if (ime.second != null) { subtypes.addAll(ime.second); } @@ -899,6 +898,31 @@ public class InputMethodUtils { mCurrentUserId = userId; } + private void putString(final String key, final String str) { + Settings.Secure.putStringForUser(mResolver, key, str, mCurrentUserId); + } + + private String getString(final String key) { + return Settings.Secure.getStringForUser(mResolver, key, mCurrentUserId); + } + + private void putInt(final String key, final int value) { + Settings.Secure.putIntForUser(mResolver, key, value, mCurrentUserId); + } + + private int getInt(final String key, final int defaultValue) { + return Settings.Secure.getIntForUser(mResolver, key, defaultValue, mCurrentUserId); + } + + private void putBoolean(final String key, final boolean value) { + Settings.Secure.putIntForUser(mResolver, key, value ? 1 : 0, mCurrentUserId); + } + + private boolean getBoolean(final String key, final boolean defaultValue) { + return Settings.Secure.getIntForUser(mResolver, key, defaultValue ? 1 : 0, + mCurrentUserId) == 1; + } + public void setCurrentProfileIds(int[] currentProfileIds) { synchronized (this) { mCurrentProfileIds = currentProfileIds; @@ -1035,17 +1059,15 @@ public class InputMethodUtils { } private void putEnabledInputMethodsStr(String str) { - Settings.Secure.putStringForUser( - mResolver, Settings.Secure.ENABLED_INPUT_METHODS, str, mCurrentUserId); - mEnabledInputMethodsStrCache = str; if (DEBUG) { Slog.d(TAG, "putEnabledInputMethodStr: " + str); } + putString(Settings.Secure.ENABLED_INPUT_METHODS, str); + mEnabledInputMethodsStrCache = str; } public String getEnabledInputMethodsStr() { - mEnabledInputMethodsStrCache = Settings.Secure.getStringForUser( - mResolver, Settings.Secure.ENABLED_INPUT_METHODS, mCurrentUserId); + mEnabledInputMethodsStrCache = getString(Settings.Secure.ENABLED_INPUT_METHODS); if (DEBUG) { Slog.d(TAG, "getEnabledInputMethodsStr: " + mEnabledInputMethodsStrCache + ", " + mCurrentUserId); @@ -1103,8 +1125,7 @@ public class InputMethodUtils { if (DEBUG) { Slog.d(TAG, "putSubtypeHistoryStr: " + str); } - Settings.Secure.putStringForUser( - mResolver, Settings.Secure.INPUT_METHODS_SUBTYPE_HISTORY, str, mCurrentUserId); + putString(Settings.Secure.INPUT_METHODS_SUBTYPE_HISTORY, str); } public Pair<String, String> getLastInputMethodAndSubtypeLocked() { @@ -1222,12 +1243,11 @@ public class InputMethodUtils { } private String getSubtypeHistoryStr() { + final String history = getString(Settings.Secure.INPUT_METHODS_SUBTYPE_HISTORY); if (DEBUG) { - Slog.d(TAG, "getSubtypeHistoryStr: " + Settings.Secure.getStringForUser( - mResolver, Settings.Secure.INPUT_METHODS_SUBTYPE_HISTORY, mCurrentUserId)); + Slog.d(TAG, "getSubtypeHistoryStr: " + history); } - return Settings.Secure.getStringForUser( - mResolver, Settings.Secure.INPUT_METHODS_SUBTYPE_HISTORY, mCurrentUserId); + return history; } public void putSelectedInputMethod(String imeId) { @@ -1235,8 +1255,7 @@ public class InputMethodUtils { Slog.d(TAG, "putSelectedInputMethodStr: " + imeId + ", " + mCurrentUserId); } - Settings.Secure.putStringForUser( - mResolver, Settings.Secure.DEFAULT_INPUT_METHOD, imeId, mCurrentUserId); + putString(Settings.Secure.DEFAULT_INPUT_METHOD, imeId); } public void putSelectedSubtype(int subtypeId) { @@ -1244,18 +1263,15 @@ public class InputMethodUtils { Slog.d(TAG, "putSelectedInputMethodSubtypeStr: " + subtypeId + ", " + mCurrentUserId); } - Settings.Secure.putIntForUser(mResolver, Settings.Secure.SELECTED_INPUT_METHOD_SUBTYPE, - subtypeId, mCurrentUserId); + putInt(Settings.Secure.SELECTED_INPUT_METHOD_SUBTYPE, subtypeId); } public String getSelectedInputMethod() { + final String imi = getString(Settings.Secure.DEFAULT_INPUT_METHOD); if (DEBUG) { - Slog.d(TAG, "getSelectedInputMethodStr: " + Settings.Secure.getStringForUser( - mResolver, Settings.Secure.DEFAULT_INPUT_METHOD, mCurrentUserId) - + ", " + mCurrentUserId); + Slog.d(TAG, "getSelectedInputMethodStr: " + imi); } - return Settings.Secure.getStringForUser( - mResolver, Settings.Secure.DEFAULT_INPUT_METHOD, mCurrentUserId); + return imi; } public boolean isSubtypeSelected() { @@ -1263,22 +1279,15 @@ public class InputMethodUtils { } private int getSelectedInputMethodSubtypeHashCode() { - try { - return Settings.Secure.getIntForUser( - mResolver, Settings.Secure.SELECTED_INPUT_METHOD_SUBTYPE, mCurrentUserId); - } catch (SettingNotFoundException e) { - return NOT_A_SUBTYPE_ID; - } + return getInt(Settings.Secure.SELECTED_INPUT_METHOD_SUBTYPE, NOT_A_SUBTYPE_ID); } public boolean isShowImeWithHardKeyboardEnabled() { - return Settings.Secure.getIntForUser(mResolver, - Settings.Secure.SHOW_IME_WITH_HARD_KEYBOARD, 0, mCurrentUserId) == 1; + return getBoolean(Settings.Secure.SHOW_IME_WITH_HARD_KEYBOARD, false); } public void setShowImeWithHardKeyboard(boolean show) { - Settings.Secure.putIntForUser(mResolver, Settings.Secure.SHOW_IME_WITH_HARD_KEYBOARD, - show ? 1 : 0, mCurrentUserId); + putBoolean(Settings.Secure.SHOW_IME_WITH_HARD_KEYBOARD, show); } public int getCurrentUserId() { diff --git a/core/tests/coretests/src/com/android/internal/inputmethod/InputMethodUtilsTest.java b/core/tests/coretests/src/com/android/internal/inputmethod/InputMethodUtilsTest.java index 93581db719d3..f962a4334933 100644 --- a/core/tests/coretests/src/com/android/internal/inputmethod/InputMethodUtilsTest.java +++ b/core/tests/coretests/src/com/android/internal/inputmethod/InputMethodUtilsTest.java @@ -219,7 +219,7 @@ public class InputMethodUtilsTest extends InstrumentationTestCase { // Make sure that an automatic subtype (overridesImplicitlyEnabledSubtype:true) is // selected no matter what locale is specified. { - final ArrayList<InputMethodSubtype> subtypes = new ArrayList<InputMethodSubtype>(); + final ArrayList<InputMethodSubtype> subtypes = new ArrayList<>(); subtypes.add(nonAutoEnUS); subtypes.add(nonAutoEnGB); subtypes.add(nonAutoJa); @@ -244,7 +244,7 @@ public class InputMethodUtilsTest extends InstrumentationTestCase { // selected as long as there is no no automatic subtype // (overridesImplicitlyEnabledSubtype:true) in the given list. { - final ArrayList<InputMethodSubtype> subtypes = new ArrayList<InputMethodSubtype>(); + final ArrayList<InputMethodSubtype> subtypes = new ArrayList<>(); subtypes.add(nonAutoEnUS); // locale == "en_US" subtypes.add(nonAutoEnGB); subtypes.add(nonAutoJa); @@ -267,7 +267,7 @@ public class InputMethodUtilsTest extends InstrumentationTestCase { // selected as long as there is no automatic subtype // (overridesImplicitlyEnabledSubtype:true) in the given list. { - final ArrayList<InputMethodSubtype> subtypes = new ArrayList<InputMethodSubtype>(); + final ArrayList<InputMethodSubtype> subtypes = new ArrayList<>(); subtypes.add(nonAutoEnUS); subtypes.add(nonAutoEnGB); // locale == "en_GB" subtypes.add(nonAutoJa); @@ -291,7 +291,7 @@ public class InputMethodUtilsTest extends InstrumentationTestCase { // try to find a subtype whose language is equal to the language part of the given locale. // Here make sure that a subtype (locale: "fr_CA") can be found with locale: "fr". { - final ArrayList<InputMethodSubtype> subtypes = new ArrayList<InputMethodSubtype>(); + final ArrayList<InputMethodSubtype> subtypes = new ArrayList<>(); subtypes.add(nonAutoFrCA); // locale == "fr_CA" subtypes.add(nonAutoJa); subtypes.add(nonAutoFil); @@ -311,7 +311,7 @@ public class InputMethodUtilsTest extends InstrumentationTestCase { } // Then make sure that a subtype (locale: "fr") can be found with locale: "fr_CA". { - final ArrayList<InputMethodSubtype> subtypes = new ArrayList<InputMethodSubtype>(); + final ArrayList<InputMethodSubtype> subtypes = new ArrayList<>(); subtypes.add(nonAutoFr); // locale == "fr" subtypes.add(nonAutoJa); subtypes.add(nonAutoFil); @@ -333,7 +333,7 @@ public class InputMethodUtilsTest extends InstrumentationTestCase { // Make sure that subtypes which have "EnabledWhenDefaultIsNotAsciiCapable" in its // extra value is selected if and only if all other selected IMEs are not AsciiCapable. { - final ArrayList<InputMethodSubtype> subtypes = new ArrayList<InputMethodSubtype>(); + final ArrayList<InputMethodSubtype> subtypes = new ArrayList<>(); subtypes.add(nonAutoEnUS); subtypes.add(nonAutoJa); // not ASCII capable subtypes.add(nonAutoEnabledWhenDefaultIsNotAsciiCalableSubtype); @@ -355,7 +355,7 @@ public class InputMethodUtilsTest extends InstrumentationTestCase { // Make sure that 3-letter language code can be handled. { - final ArrayList<InputMethodSubtype> subtypes = new ArrayList<InputMethodSubtype>(); + final ArrayList<InputMethodSubtype> subtypes = new ArrayList<>(); subtypes.add(nonAutoEnUS); subtypes.add(nonAutoFil); final InputMethodInfo imi = createDummyInputMethodInfo( @@ -374,7 +374,7 @@ public class InputMethodUtilsTest extends InstrumentationTestCase { // Make sure that we never end up matching "fi" (finnish) with "fil" (filipino). // Also make sure that the first subtype will be used as the last-resort candidate. { - final ArrayList<InputMethodSubtype> subtypes = new ArrayList<InputMethodSubtype>(); + final ArrayList<InputMethodSubtype> subtypes = new ArrayList<>(); subtypes.add(nonAutoJa); subtypes.add(nonAutoEnUS); subtypes.add(nonAutoFil); @@ -393,7 +393,7 @@ public class InputMethodUtilsTest extends InstrumentationTestCase { // Make sure that "in" and "id" conversion is taken into account. { - final ArrayList<InputMethodSubtype> subtypes = new ArrayList<InputMethodSubtype>(); + final ArrayList<InputMethodSubtype> subtypes = new ArrayList<>(); subtypes.add(nonAutoIn); subtypes.add(nonAutoEnUS); final InputMethodInfo imi = createDummyInputMethodInfo( @@ -409,7 +409,7 @@ public class InputMethodUtilsTest extends InstrumentationTestCase { verifyEquality(nonAutoIn, result.get(0)); } { - final ArrayList<InputMethodSubtype> subtypes = new ArrayList<InputMethodSubtype>(); + final ArrayList<InputMethodSubtype> subtypes = new ArrayList<>(); subtypes.add(nonAutoIn); subtypes.add(nonAutoEnUS); final InputMethodInfo imi = createDummyInputMethodInfo( @@ -425,7 +425,7 @@ public class InputMethodUtilsTest extends InstrumentationTestCase { verifyEquality(nonAutoIn, result.get(0)); } { - final ArrayList<InputMethodSubtype> subtypes = new ArrayList<InputMethodSubtype>(); + final ArrayList<InputMethodSubtype> subtypes = new ArrayList<>(); subtypes.add(nonAutoId); subtypes.add(nonAutoEnUS); final InputMethodInfo imi = createDummyInputMethodInfo( @@ -441,7 +441,7 @@ public class InputMethodUtilsTest extends InstrumentationTestCase { verifyEquality(nonAutoId, result.get(0)); } { - final ArrayList<InputMethodSubtype> subtypes = new ArrayList<InputMethodSubtype>(); + final ArrayList<InputMethodSubtype> subtypes = new ArrayList<>(); subtypes.add(nonAutoId); subtypes.add(nonAutoEnUS); final InputMethodInfo imi = createDummyInputMethodInfo( @@ -482,7 +482,7 @@ public class InputMethodUtilsTest extends InstrumentationTestCase { final boolean CHECK_COUNTRY = true; { - final ArrayList<InputMethodSubtype> subtypes = new ArrayList<InputMethodSubtype>(); + final ArrayList<InputMethodSubtype> subtypes = new ArrayList<>(); subtypes.add(nonAutoEnUS); final InputMethodInfo imi = createDummyInputMethodInfo( "com.android.apps.inputmethod.latin", @@ -514,7 +514,7 @@ public class InputMethodUtilsTest extends InstrumentationTestCase { // Make sure that 3-letter language code ("fil") can be handled. { - final ArrayList<InputMethodSubtype> subtypes = new ArrayList<InputMethodSubtype>(); + final ArrayList<InputMethodSubtype> subtypes = new ArrayList<>(); subtypes.add(nonAutoFil); final InputMethodInfo imi = createDummyInputMethodInfo( "com.android.apps.inputmethod.latin", @@ -541,7 +541,7 @@ public class InputMethodUtilsTest extends InstrumentationTestCase { // Make sure that 3-letter language code ("fil_PH") can be handled. { - final ArrayList<InputMethodSubtype> subtypes = new ArrayList<InputMethodSubtype>(); + final ArrayList<InputMethodSubtype> subtypes = new ArrayList<>(); subtypes.add(nonAutoFilPH); final InputMethodInfo imi = createDummyInputMethodInfo( "com.android.apps.inputmethod.latin", @@ -568,7 +568,7 @@ public class InputMethodUtilsTest extends InstrumentationTestCase { // Make sure that a subtype whose locale is "in" can be queried with "id". { - final ArrayList<InputMethodSubtype> subtypes = new ArrayList<InputMethodSubtype>(); + final ArrayList<InputMethodSubtype> subtypes = new ArrayList<>(); subtypes.add(nonAutoIn); subtypes.add(nonAutoEnUS); final InputMethodInfo imi = createDummyInputMethodInfo( @@ -587,7 +587,7 @@ public class InputMethodUtilsTest extends InstrumentationTestCase { // Make sure that a subtype whose locale is "id" can be queried with "in". { - final ArrayList<InputMethodSubtype> subtypes = new ArrayList<InputMethodSubtype>(); + final ArrayList<InputMethodSubtype> subtypes = new ArrayList<>(); subtypes.add(nonAutoId); subtypes.add(nonAutoEnUS); final InputMethodInfo imi = createDummyInputMethodInfo( @@ -712,7 +712,7 @@ public class InputMethodUtilsTest extends InstrumentationTestCase { private static ArrayList<InputMethodInfo> getImesWithDefaultVoiceIme() { ArrayList<InputMethodInfo> preinstalledImes = new ArrayList<>(); { - final ArrayList<InputMethodSubtype> subtypes = new ArrayList<InputMethodSubtype>(); + final ArrayList<InputMethodSubtype> subtypes = new ArrayList<>(); subtypes.add(createDummyInputMethodSubtype("auto", SUBTYPE_MODE_VOICE, IS_AUX, IS_OVERRIDES_IMPLICITLY_ENABLED_SUBTYPE, !IS_ASCII_CAPABLE, !IS_ENABLED_WHEN_DEFAULT_IS_NOT_ASCII_CAPABLE)); @@ -729,7 +729,7 @@ public class InputMethodUtilsTest extends InstrumentationTestCase { private static ArrayList<InputMethodInfo> getImesWithoutDefaultVoiceIme() { ArrayList<InputMethodInfo> preinstalledImes = new ArrayList<>(); { - final ArrayList<InputMethodSubtype> subtypes = new ArrayList<InputMethodSubtype>(); + final ArrayList<InputMethodSubtype> subtypes = new ArrayList<>(); subtypes.add(createDummyInputMethodSubtype("auto", SUBTYPE_MODE_VOICE, IS_AUX, IS_OVERRIDES_IMPLICITLY_ENABLED_SUBTYPE, !IS_ASCII_CAPABLE, !IS_ENABLED_WHEN_DEFAULT_IS_NOT_ASCII_CAPABLE)); @@ -740,7 +740,7 @@ public class InputMethodUtilsTest extends InstrumentationTestCase { "dummy.voice1", "DummyVoice1", IS_AUX, !IS_DEFAULT, subtypes)); } { - final ArrayList<InputMethodSubtype> subtypes = new ArrayList<InputMethodSubtype>(); + final ArrayList<InputMethodSubtype> subtypes = new ArrayList<>(); subtypes.add(createDummyInputMethodSubtype("auto", SUBTYPE_MODE_VOICE, IS_AUX, IS_OVERRIDES_IMPLICITLY_ENABLED_SUBTYPE, !IS_ASCII_CAPABLE, !IS_ENABLED_WHEN_DEFAULT_IS_NOT_ASCII_CAPABLE)); @@ -751,7 +751,7 @@ public class InputMethodUtilsTest extends InstrumentationTestCase { "dummy.voice2", "DummyVoice2", IS_AUX, !IS_DEFAULT, subtypes)); } { - final ArrayList<InputMethodSubtype> subtypes = new ArrayList<InputMethodSubtype>(); + final ArrayList<InputMethodSubtype> subtypes = new ArrayList<>(); subtypes.add(createDummyInputMethodSubtype("en_US", SUBTYPE_MODE_VOICE, IS_AUX, !IS_OVERRIDES_IMPLICITLY_ENABLED_SUBTYPE, !IS_ASCII_CAPABLE, !IS_ENABLED_WHEN_DEFAULT_IS_NOT_ASCII_CAPABLE)); @@ -759,7 +759,7 @@ public class InputMethodUtilsTest extends InstrumentationTestCase { "dummy.voice3", "DummyVoice3", IS_AUX, !IS_DEFAULT, subtypes)); } { - final ArrayList<InputMethodSubtype> subtypes = new ArrayList<InputMethodSubtype>(); + final ArrayList<InputMethodSubtype> subtypes = new ArrayList<>(); subtypes.add(createDummyInputMethodSubtype("en_US", SUBTYPE_MODE_KEYBOARD, !IS_AUX, !IS_OVERRIDES_IMPLICITLY_ENABLED_SUBTYPE, IS_ASCII_CAPABLE, !IS_ENABLED_WHEN_DEFAULT_IS_NOT_ASCII_CAPABLE)); @@ -787,7 +787,7 @@ public class InputMethodUtilsTest extends InstrumentationTestCase { // a dummy Voice IME { final boolean isDefaultIme = false; - final ArrayList<InputMethodSubtype> subtypes = new ArrayList<InputMethodSubtype>(); + final ArrayList<InputMethodSubtype> subtypes = new ArrayList<>(); subtypes.add(createDummyInputMethodSubtype("", SUBTYPE_MODE_VOICE, IS_AUX, IS_OVERRIDES_IMPLICITLY_ENABLED_SUBTYPE, !IS_ASCII_CAPABLE, !IS_ENABLED_WHEN_DEFAULT_IS_NOT_ASCII_CAPABLE)); @@ -798,7 +798,7 @@ public class InputMethodUtilsTest extends InstrumentationTestCase { // a dummy Hindi IME { final boolean isDefaultIme = contains(new String[]{ "hi", "en-rIN" }, localeString); - final ArrayList<InputMethodSubtype> subtypes = new ArrayList<InputMethodSubtype>(); + final ArrayList<InputMethodSubtype> subtypes = new ArrayList<>(); // TODO: This subtype should be marked as IS_ASCII_CAPABLE subtypes.add(createDummyInputMethodSubtype("en_IN", SUBTYPE_MODE_KEYBOARD, !IS_AUX, !IS_OVERRIDES_IMPLICITLY_ENABLED_SUBTYPE, !IS_ASCII_CAPABLE, @@ -814,7 +814,7 @@ public class InputMethodUtilsTest extends InstrumentationTestCase { // a dummy Pinyin IME { final boolean isDefaultIme = contains(new String[]{ "zh-rCN" }, localeString); - final ArrayList<InputMethodSubtype> subtypes = new ArrayList<InputMethodSubtype>(); + final ArrayList<InputMethodSubtype> subtypes = new ArrayList<>(); subtypes.add(createDummyInputMethodSubtype("zh_CN", SUBTYPE_MODE_KEYBOARD, !IS_AUX, !IS_OVERRIDES_IMPLICITLY_ENABLED_SUBTYPE, !IS_ASCII_CAPABLE, !IS_ENABLED_WHEN_DEFAULT_IS_NOT_ASCII_CAPABLE)); @@ -826,7 +826,7 @@ public class InputMethodUtilsTest extends InstrumentationTestCase { // a dummy Korean IME { final boolean isDefaultIme = contains(new String[]{ "ko" }, localeString); - final ArrayList<InputMethodSubtype> subtypes = new ArrayList<InputMethodSubtype>(); + final ArrayList<InputMethodSubtype> subtypes = new ArrayList<>(); subtypes.add(createDummyInputMethodSubtype("ko", SUBTYPE_MODE_KEYBOARD, !IS_AUX, !IS_OVERRIDES_IMPLICITLY_ENABLED_SUBTYPE, !IS_ASCII_CAPABLE, !IS_ENABLED_WHEN_DEFAULT_IS_NOT_ASCII_CAPABLE)); @@ -839,7 +839,7 @@ public class InputMethodUtilsTest extends InstrumentationTestCase { { final boolean isDefaultIme = contains( new String[]{ "en-rUS", "en-rGB", "en-rIN", "en", "hi" }, localeString); - final ArrayList<InputMethodSubtype> subtypes = new ArrayList<InputMethodSubtype>(); + final ArrayList<InputMethodSubtype> subtypes = new ArrayList<>(); subtypes.add(createDummyInputMethodSubtype("en_US", SUBTYPE_MODE_KEYBOARD, !IS_AUX, !IS_OVERRIDES_IMPLICITLY_ENABLED_SUBTYPE, IS_ASCII_CAPABLE, !IS_ENABLED_WHEN_DEFAULT_IS_NOT_ASCII_CAPABLE)); @@ -860,7 +860,7 @@ public class InputMethodUtilsTest extends InstrumentationTestCase { // a dummy Japanese IME { final boolean isDefaultIme = contains(new String[]{ "ja", "ja-rJP" }, localeString); - final ArrayList<InputMethodSubtype> subtypes = new ArrayList<InputMethodSubtype>(); + final ArrayList<InputMethodSubtype> subtypes = new ArrayList<>(); subtypes.add(createDummyInputMethodSubtype("ja", SUBTYPE_MODE_KEYBOARD, !IS_AUX, !IS_OVERRIDES_IMPLICITLY_ENABLED_SUBTYPE, !IS_ASCII_CAPABLE, !IS_ENABLED_WHEN_DEFAULT_IS_NOT_ASCII_CAPABLE)); diff --git a/services/core/java/com/android/server/InputMethodManagerService.java b/services/core/java/com/android/server/InputMethodManagerService.java index d77def67ab52..4a9412ffb958 100644 --- a/services/core/java/com/android/server/InputMethodManagerService.java +++ b/services/core/java/com/android/server/InputMethodManagerService.java @@ -666,8 +666,7 @@ public class InputMethodManagerService extends IInputMethodManager.Stub } } - buildInputMethodListLocked( - mMethodList, mMethodMap, false /* resetDefaultEnabledIme */); + buildInputMethodListLocked(false /* resetDefaultEnabledIme */); boolean changed = false; @@ -800,7 +799,7 @@ public class InputMethodManagerService extends IInputMethodManager.Stub handleMessage(msg); } }, true /*asyncHandler*/); - mAppOpsManager = (AppOpsManager) mContext.getSystemService(Context.APP_OPS_SERVICE); + mAppOpsManager = mContext.getSystemService(AppOpsManager.class); mHardKeyboardListener = new HardKeyboardListener(); mHasFeature = context.getPackageManager().hasSystemFeature( PackageManager.FEATURE_INPUT_METHODS); @@ -906,8 +905,7 @@ public class InputMethodManagerService extends IInputMethodManager.Stub mImeSelectedOnBoot = !TextUtils.isEmpty(defaultImiId); synchronized (mMethodMap) { - buildInputMethodListLocked(mMethodList, mMethodMap, - !mImeSelectedOnBoot /* resetDefaultEnabledIme */); + buildInputMethodListLocked(!mImeSelectedOnBoot /* resetDefaultEnabledIme */); } mSettings.enableAllIMEsIfThereIsNoEnabledIME(); @@ -987,7 +985,7 @@ public class InputMethodManagerService extends IInputMethodManager.Stub if (DEBUG) { Slog.i(TAG, "Locale has been changed to " + newLocale); } - buildInputMethodListLocked(mMethodList, mMethodMap, resetDefaultEnabledIme); + buildInputMethodListLocked(resetDefaultEnabledIme); if (!updateOnlyWhenLocaleChanged) { final String selectedImiId = mSettings.getSelectedInputMethod(); if (TextUtils.isEmpty(selectedImiId)) { @@ -1050,8 +1048,8 @@ public class InputMethodManagerService extends IInputMethodManager.Stub } void updateCurrentProfileIds() { - List<UserInfo> profiles = - UserManager.get(mContext).getProfiles(mSettings.getCurrentUserId()); + List<UserInfo> profiles = mContext.getSystemService(UserManager.class) + .getProfiles(mSettings.getCurrentUserId()); int[] currentProfileIds = new int[profiles.size()]; // profiles will not be null for (int i = 0; i < currentProfileIds.length; i++) { currentProfileIds[i] = profiles.get(i).id; @@ -1081,10 +1079,8 @@ public class InputMethodManagerService extends IInputMethodManager.Stub } if (!mSystemReady) { mSystemReady = true; - mKeyguardManager = - (KeyguardManager) mContext.getSystemService(Context.KEYGUARD_SERVICE); - mNotificationManager = (NotificationManager) - mContext.getSystemService(Context.NOTIFICATION_SERVICE); + mKeyguardManager = mContext.getSystemService(KeyguardManager.class); + mNotificationManager = mContext.getSystemService(NotificationManager.class); mStatusBar = statusBar; statusBar.setIconVisibility(mSlotIme, false); updateSystemUiLocked(mCurToken, mImeWindowVis, mBackDisposition); @@ -1094,8 +1090,7 @@ public class InputMethodManagerService extends IInputMethodManager.Stub mWindowManagerInternal.setOnHardKeyboardStatusChangeListener( mHardKeyboardListener); } - buildInputMethodListLocked(mMethodList, mMethodMap, - !mImeSelectedOnBoot /* resetDefaultEnabledIme */); + buildInputMethodListLocked(!mImeSelectedOnBoot /* resetDefaultEnabledIme */); if (!mImeSelectedOnBoot) { Slog.w(TAG, "Reset the default IME as \"Resource\" is ready here."); resetStateIfCurrentLocaleChangedLocked(); @@ -2601,8 +2596,7 @@ public class InputMethodManagerService extends IInputMethodManager.Stub mFileManager.addInputMethodSubtypes(imi, subtypes); final long ident = Binder.clearCallingIdentity(); try { - buildInputMethodListLocked(mMethodList, mMethodMap, - false /* resetDefaultEnabledIme */); + buildInputMethodListLocked(false /* resetDefaultEnabledIme */); } finally { Binder.restoreCallingIdentity(ident); } @@ -2957,14 +2951,13 @@ public class InputMethodManagerService extends IInputMethodManager.Stub return false; } - void buildInputMethodListLocked(ArrayList<InputMethodInfo> list, - HashMap<String, InputMethodInfo> map, boolean resetDefaultEnabledIme) { + void buildInputMethodListLocked(boolean resetDefaultEnabledIme) { if (DEBUG) { Slog.d(TAG, "--- re-buildInputMethodList reset = " + resetDefaultEnabledIme + " \n ------ caller=" + Debug.getCallers(10)); } - list.clear(); - map.clear(); + mMethodList.clear(); + mMethodMap.clear(); // Use for queryIntentServicesAsUser final PackageManager pm = mContext.getPackageManager(); @@ -2992,9 +2985,9 @@ public class InputMethodManagerService extends IInputMethodManager.Stub try { InputMethodInfo p = new InputMethodInfo(mContext, ri, additionalSubtypes); - list.add(p); + mMethodList.add(p); final String id = p.getId(); - map.put(id, p); + mMethodMap.put(id, p); if (DEBUG) { Slog.d(TAG, "Found an input method " + p); @@ -3006,7 +2999,7 @@ public class InputMethodManagerService extends IInputMethodManager.Stub if (resetDefaultEnabledIme) { final ArrayList<InputMethodInfo> defaultEnabledIme = - InputMethodUtils.getDefaultEnabledImes(mContext, mSystemReady, list); + InputMethodUtils.getDefaultEnabledImes(mContext, mSystemReady, mMethodList); for (int i = 0; i < defaultEnabledIme.size(); ++i) { final InputMethodInfo imi = defaultEnabledIme.get(i); if (DEBUG) { @@ -3018,7 +3011,7 @@ public class InputMethodManagerService extends IInputMethodManager.Stub final String defaultImiId = mSettings.getSelectedInputMethod(); if (!TextUtils.isEmpty(defaultImiId)) { - if (!map.containsKey(defaultImiId)) { + if (!mMethodMap.containsKey(defaultImiId)) { Slog.w(TAG, "Default IME is uninstalled. Choose new default IME."); if (chooseNewDefaultIMELocked()) { updateInputMethodsFromSettingsLocked(true); @@ -3137,8 +3130,7 @@ public class InputMethodManagerService extends IInputMethodManager.Stub mDialogBuilder.setIcon(dialogIcon); - final LayoutInflater inflater = (LayoutInflater) dialogContext.getSystemService( - Context.LAYOUT_INFLATER_SERVICE); + final LayoutInflater inflater = dialogContext.getSystemService(LayoutInflater.class); final View tv = inflater.inflate( com.android.internal.R.layout.input_method_switch_dialog_title, null); mDialogBuilder.setCustomTitle(tv); @@ -3222,7 +3214,7 @@ public class InputMethodManagerService extends IInputMethodManager.Stub mTextViewResourceId = textViewResourceId; mItemsList = itemsList; mCheckedItem = checkedItem; - mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); + mInflater = context.getSystemService(LayoutInflater.class); } @Override |