Fix NPE in setCurrentSpellCheckerSubtype

Change-Id: I9fce999f91dcccd2f877a0326c4f2e3ac9024f85
This commit is contained in:
satok
2011-08-26 15:48:50 +09:00
parent 2388a7ba62
commit fbedf1a397
2 changed files with 12 additions and 10 deletions

View File

@@ -162,10 +162,13 @@ public final class TextServicesManager {
*/
public void setSpellCheckerSubtype(SpellCheckerSubtype subtype) {
try {
final int hashCode;
if (subtype == null) {
throw new NullPointerException("SpellCheckerSubtype is null.");
hashCode = 0;
} else {
hashCode = subtype.hashCode();
}
sService.setCurrentSpellCheckerSubtype(null, subtype.hashCode());
sService.setCurrentSpellCheckerSubtype(null, hashCode);
} catch (RemoteException e) {
Log.e(TAG, "Error in setSpellCheckerSubtype:" + e);
}

View File

@@ -217,6 +217,9 @@ public class TextServicesManagerService extends ITextServicesManager.Stub {
return null;
}
final int hashCode = Integer.valueOf(subtypeHashCodeStr);
if (hashCode == 0) {
return null;
}
for (int i = 0; i < sci.getSubtypeCount(); ++i) {
final SpellCheckerSubtype scs = sci.getSubtypeAt(i);
if (scs.hashCode() == hashCode) {
@@ -416,21 +419,17 @@ public class TextServicesManagerService extends ITextServicesManager.Stub {
Slog.w(TAG, "setCurrentSpellCheckerSubtype: " + hashCode);
}
final SpellCheckerInfo sci = getCurrentSpellChecker(null);
if (sci == null) return;
boolean found = false;
for (int i = 0; i < sci.getSubtypeCount(); ++i) {
int tempHashCode = 0;
for (int i = 0; sci != null && i < sci.getSubtypeCount(); ++i) {
if(sci.getSubtypeAt(i).hashCode() == hashCode) {
found = true;
tempHashCode = hashCode;
break;
}
}
if (!found) {
return;
}
final long ident = Binder.clearCallingIdentity();
try {
Settings.Secure.putString(mContext.getContentResolver(),
Settings.Secure.SELECTED_SPELL_CHECKER_SUBTYPE, String.valueOf(hashCode));
Settings.Secure.SELECTED_SPELL_CHECKER_SUBTYPE, String.valueOf(tempHashCode));
} finally {
Binder.restoreCallingIdentity(ident);
}