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
       49ed140176
  [2]: I169ad4957e68b65c64251b0849056195b8ca4911

Bug: 27687531
Change-Id: I068f8821a32d2e199fbf6239bbe833da8c5a4e5e
This commit is contained in:
Yohei Yukawa
2016-03-16 17:22:30 -07:00
parent ad150ee271
commit 08ce18728c

View File

@@ -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) {