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

Commit 99c3313d authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Update Settings properly when no Spell Checker is available."

parents 66761d46 83a7330b
Loading
Loading
Loading
Loading
+37 −30
Original line number Diff line number Diff line
@@ -122,14 +122,8 @@ public class TextServicesManagerService extends ITextServicesManager.Stub {
        }

        private 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);
        }
        }

        private void putSelectedSpellCheckerSubtype(int hashCode) {
            putInt(Settings.Secure.SELECTED_SPELL_CHECKER_SUBTYPE, hashCode);
@@ -157,8 +151,12 @@ public class TextServicesManagerService extends ITextServicesManager.Stub {
            return mSpellCheckerMap.get(curSpellCheckerId);
        }

        public void setCurrentSpellChecker(SpellCheckerInfo sci) {
        public void setCurrentSpellChecker(@Nullable SpellCheckerInfo sci) {
            if (sci != null) {
                putSelectedSpellChecker(sci.getId());
            } else {
                putSelectedSpellChecker("");
            }
            putSelectedSpellCheckerSubtype(SpellCheckerSubtype.SUBTYPE_ID_NONE);
        }

@@ -331,14 +329,12 @@ public class TextServicesManagerService extends ITextServicesManager.Stub {
        SpellCheckerInfo sci = tsd.getCurrentSpellChecker();
        if (sci == null) {
            sci = findAvailSystemSpellCheckerLocked(null, tsd);
            if (sci != null) {
                // Set the current spell checker if there is one or more spell checkers
            // Set the current spell checker if there is one or more system spell checkers
            // available. In this case, "sci" is the first one in the available spell
            // checkers.
            setCurrentSpellCheckerLocked(sci, tsd);
        }
    }
    }

    private final class TextServicesMonitor extends PackageMonitor {
        @Override
@@ -355,9 +351,17 @@ public class TextServicesManagerService extends ITextServicesManager.Stub {
                // TODO: Update for each locale
                SpellCheckerInfo sci = tsd.getCurrentSpellChecker();
                tsd.initializeTextServicesData();
                // If no spell checker is enabled, just return. The user should explicitly
                // If spell checker is disabled, just return. The user should explicitly
                // enable the spell checker.
                if (sci == null) return;
                if (!tsd.isSpellCheckerEnabled()) return;

                if (sci == null) {
                    sci = findAvailSystemSpellCheckerLocked(null, tsd);
                    // Set the current spell checker if there is one or more system spell checkers
                    // available. In this case, "sci" is the first one in the available spell
                    // checkers.
                    setCurrentSpellCheckerLocked(sci, tsd);
                } else {
                    final String packageName = sci.getPackageName();
                    final int change = isPackageDisappearing(packageName);
                    if (DBG) Slog.d(TAG, "Changing package name: " + packageName);
@@ -365,15 +369,18 @@ public class TextServicesManagerService extends ITextServicesManager.Stub {
                            change == PACKAGE_PERMANENT_CHANGE || change == PACKAGE_TEMPORARY_CHANGE
                                    // Package modified
                                    || isPackageModified(packageName)) {
                    SpellCheckerInfo availSci = findAvailSystemSpellCheckerLocked(packageName, tsd);
                        SpellCheckerInfo availSci =
                                findAvailSystemSpellCheckerLocked(packageName, tsd);
                        // Set the spell checker settings if different than before
                    if (availSci != null && !availSci.getId().equals(sci.getId())) {
                        if (availSci == null
                                || (availSci != null && !availSci.getId().equals(sci.getId()))) {
                            setCurrentSpellCheckerLocked(availSci, tsd);
                        }
                    }
                }
            }
        }
    }

    private boolean bindCurrentSpellCheckerService(
            Intent service, ServiceConnection conn, int flags, @UserIdInt int userId) {
@@ -677,8 +684,8 @@ public class TextServicesManagerService extends ITextServicesManager.Stub {
        }
    }

    private void setCurrentSpellCheckerLocked(SpellCheckerInfo sci, TextServicesData tsd) {
        final String sciId = sci.getId();
    private void setCurrentSpellCheckerLocked(@Nullable SpellCheckerInfo sci, TextServicesData tsd) {
        final String sciId = (sci != null) ? sci.getId() : "";
        if (DBG) {
            Slog.w(TAG, "setCurrentSpellChecker: " + sciId);
        }