Fix NPE in setCurrentSpellCheckerSubtype
Change-Id: I9fce999f91dcccd2f877a0326c4f2e3ac9024f85
This commit is contained in:
@@ -162,10 +162,13 @@ public final class TextServicesManager {
|
|||||||
*/
|
*/
|
||||||
public void setSpellCheckerSubtype(SpellCheckerSubtype subtype) {
|
public void setSpellCheckerSubtype(SpellCheckerSubtype subtype) {
|
||||||
try {
|
try {
|
||||||
|
final int hashCode;
|
||||||
if (subtype == null) {
|
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) {
|
} catch (RemoteException e) {
|
||||||
Log.e(TAG, "Error in setSpellCheckerSubtype:" + e);
|
Log.e(TAG, "Error in setSpellCheckerSubtype:" + e);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -217,6 +217,9 @@ public class TextServicesManagerService extends ITextServicesManager.Stub {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
final int hashCode = Integer.valueOf(subtypeHashCodeStr);
|
final int hashCode = Integer.valueOf(subtypeHashCodeStr);
|
||||||
|
if (hashCode == 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
for (int i = 0; i < sci.getSubtypeCount(); ++i) {
|
for (int i = 0; i < sci.getSubtypeCount(); ++i) {
|
||||||
final SpellCheckerSubtype scs = sci.getSubtypeAt(i);
|
final SpellCheckerSubtype scs = sci.getSubtypeAt(i);
|
||||||
if (scs.hashCode() == hashCode) {
|
if (scs.hashCode() == hashCode) {
|
||||||
@@ -416,21 +419,17 @@ public class TextServicesManagerService extends ITextServicesManager.Stub {
|
|||||||
Slog.w(TAG, "setCurrentSpellCheckerSubtype: " + hashCode);
|
Slog.w(TAG, "setCurrentSpellCheckerSubtype: " + hashCode);
|
||||||
}
|
}
|
||||||
final SpellCheckerInfo sci = getCurrentSpellChecker(null);
|
final SpellCheckerInfo sci = getCurrentSpellChecker(null);
|
||||||
if (sci == null) return;
|
int tempHashCode = 0;
|
||||||
boolean found = false;
|
for (int i = 0; sci != null && i < sci.getSubtypeCount(); ++i) {
|
||||||
for (int i = 0; i < sci.getSubtypeCount(); ++i) {
|
|
||||||
if(sci.getSubtypeAt(i).hashCode() == hashCode) {
|
if(sci.getSubtypeAt(i).hashCode() == hashCode) {
|
||||||
found = true;
|
tempHashCode = hashCode;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!found) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
final long ident = Binder.clearCallingIdentity();
|
final long ident = Binder.clearCallingIdentity();
|
||||||
try {
|
try {
|
||||||
Settings.Secure.putString(mContext.getContentResolver(),
|
Settings.Secure.putString(mContext.getContentResolver(),
|
||||||
Settings.Secure.SELECTED_SPELL_CHECKER_SUBTYPE, String.valueOf(hashCode));
|
Settings.Secure.SELECTED_SPELL_CHECKER_SUBTYPE, String.valueOf(tempHashCode));
|
||||||
} finally {
|
} finally {
|
||||||
Binder.restoreCallingIdentity(ident);
|
Binder.restoreCallingIdentity(ident);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user