From 08ce18728cbdadbf376d2d1014daa06cf05c295a Mon Sep 17 00:00:00 2001 From: Yohei Yukawa Date: Wed, 16 Mar 2016 17:22:30 -0700 Subject: [PATCH] Add more @NonNull/@Nullable to TextServicesSettings. We need to fix TextServicesSettings as well as InputMethodSettings, because regarding Bug 27687531 the same issue was copied from InputMethodSettings to TextServicesSettings by my CL [1]. This is basically a mirror of the fix for InputMethodSettings [2]. [1]: Ie3d61458648df469abe149b7aaad8087c531a675 49ed14017697f8f19b8d49d55462713396a0588e [2]: I169ad4957e68b65c64251b0849056195b8ca4911 Bug: 27687531 Change-Id: I068f8821a32d2e199fbf6239bbe833da8c5a4e5e --- .../server/TextServicesManagerService.java | 25 +++++++++++++------ 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/services/core/java/com/android/server/TextServicesManagerService.java b/services/core/java/com/android/server/TextServicesManagerService.java index 3da20bf285ee3..3eb20a0c580e2 100644 --- a/services/core/java/com/android/server/TextServicesManagerService.java +++ b/services/core/java/com/android/server/TextServicesManagerService.java @@ -28,6 +28,7 @@ import com.android.internal.textservice.ITextServicesSessionListener; import org.xmlpull.v1.XmlPullParserException; import android.annotation.NonNull; +import android.annotation.Nullable; import android.annotation.UserIdInt; import android.app.ActivityManagerNative; import android.app.AppGlobals; @@ -1092,12 +1093,15 @@ public class TextServicesManagerService extends ITextServicesManager.Stub { } } - private String getString(final String key) { + @Nullable + private String getString(@NonNull final String key, @Nullable final String defaultValue) { + final String result; if (mCopyOnWrite && mCopyOnWriteDataStore.containsKey(key)) { - final String result = mCopyOnWriteDataStore.get(key); - return result != null ? result : ""; + result = mCopyOnWriteDataStore.get(key); + } else { + result = Settings.Secure.getStringForUser(mResolver, key, mCurrentUserId); } - return Settings.Secure.getStringForUser(mResolver, key, mCurrentUserId); + return result != null ? result : defaultValue; } private void putInt(final String key, final int value) { @@ -1145,8 +1149,14 @@ public class TextServicesManagerService extends ITextServicesManager.Stub { return mCurrentUserId; } - public void putSelectedSpellChecker(String sciId) { - putString(Settings.Secure.SELECTED_SPELL_CHECKER, sciId); + public void putSelectedSpellChecker(@Nullable String sciId) { + if (TextUtils.isEmpty(sciId)) { + // OK to coalesce to null, since getSelectedSpellChecker() can take care of the + // empty data scenario. + putString(Settings.Secure.SELECTED_SPELL_CHECKER, null); + } else { + putString(Settings.Secure.SELECTED_SPELL_CHECKER, sciId); + } } public void putSelectedSpellCheckerSubtype(int hashCode) { @@ -1157,8 +1167,9 @@ public class TextServicesManagerService extends ITextServicesManager.Stub { putBoolean(Settings.Secure.SPELL_CHECKER_ENABLED, enabled); } + @NonNull public String getSelectedSpellChecker() { - return getString(Settings.Secure.SELECTED_SPELL_CHECKER); + return getString(Settings.Secure.SELECTED_SPELL_CHECKER, ""); } public int getSelectedSpellCheckerSubtype(final int defaultValue) {