Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit fbedf1a3 authored by satok's avatar satok
Browse files

Fix NPE in setCurrentSpellCheckerSubtype

Change-Id: I9fce999f91dcccd2f877a0326c4f2e3ac9024f85
parent 2388a7ba
Loading
Loading
Loading
Loading
+5 −2
Original line number Diff line number Diff line
@@ -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);
        }
+7 −8
Original line number Diff line number Diff line
@@ -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);
        }