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

Commit 34a04e40 authored by Guliz Tuncay's avatar Guliz Tuncay Committed by Yohei Yukawa
Browse files

Update Settings properly when no Spell Checker is available.

Currently, Settings is not being updated properly when the current spell
checker service is removed or disabled and there is no other spell
checker service available. The correct behavior is that Secure.Settings
should be updated with empty string to indicate there is no selected
spell checker service.

Bug: 64812014
Fixes: 67412078
Test: Manually as follows:
  0. Make sure AOSP keyboard is installed.
  1. adb shell settings put --user 0 secure selected_spell_checker com.android.inputmethod.latin/.spellcheck.AndroidSpellCheckerService
  2. tapas SampleSpellCheckerService
  3. make -j
  4. adb install --user 0  -r out/target/product/generic/system/app/SampleSpellCheckerService/SampleSpellCheckerService.apk
  5. adb shell pm disable com.android.inputmethod.latin
  6. adb shell settings get --user 0 secure selected_spell_checker
      -> com.example.android.samplespellcheckerservice/.SampleSpellCheckerService
  7. adb uninstall com.example.android.samplespellcheckerservice
  8. adb shell settings get --user 0 secure selected_spell_checker
      -> empty
  9. adb root
  10. adb shell settings get --user 0 secure selected_spell_checker
      -> empty
  11. adb shell pm enable com.android.inputmethod.latin
  12. adb shell settings get --user 0 secure selected_spell_checker
Change-Id: I30902a3d94f2ddef33f4a8067799e98322ae3a03
Merged-In: I30902a3d94f2ddef33f4a8067799e98322ae3a03
(manual cherrypick of 83a7330b)
parent b119a085
Loading
Loading
Loading
Loading
+28 −28
Original line number Diff line number Diff line
@@ -187,14 +187,12 @@ public class TextServicesManagerService extends ITextServicesManager.Stub {
        SpellCheckerInfo sci = getCurrentSpellChecker(null);
        if (sci == null) {
            sci = findAvailSystemSpellCheckerLocked(null);
            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);
        }
    }
    }

    void updateCurrentProfileIds() {
        mSettings.setCurrentProfileIds(
@@ -221,9 +219,17 @@ public class TextServicesManagerService extends ITextServicesManager.Stub {
                SpellCheckerInfo sci = getCurrentSpellChecker(null);
                buildSpellCheckerMapLocked(
                        mContext, mSpellCheckerList, mSpellCheckerMap, mSettings);
                // 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 (!isSpellCheckerEnabledLocked()) return;

                if (sci == null) {
                    sci = findAvailSystemSpellCheckerLocked(null);
                    // 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);
                } else {
                    final String packageName = sci.getPackageName();
                    final int change = isPackageDisappearing(packageName);
                    if (// Package disappearing
@@ -239,6 +245,7 @@ public class TextServicesManagerService extends ITextServicesManager.Stub {
                }
            }
        }
    }

    private final class TextServicesBroadcastReceiver extends BroadcastReceiver {
        @Override
@@ -652,15 +659,14 @@ public class TextServicesManagerService extends ITextServicesManager.Stub {
        }
    }

    private void setCurrentSpellCheckerLocked(SpellCheckerInfo sci) {
        final String sciId = sci.getId();
    private void setCurrentSpellCheckerLocked(@Nullable SpellCheckerInfo sci) {
        final String sciId = (sci != null) ? sci.getId() : "";
        if (DBG) {
            Slog.w(TAG, "setCurrentSpellChecker: " + sciId);
        }
        final long ident = Binder.clearCallingIdentity();
        try {
            mSettings.putSelectedSpellChecker(sciId);
            setCurrentSpellCheckerSubtypeLocked(0);
        } finally {
            Binder.restoreCallingIdentity(ident);
        }
@@ -1106,14 +1112,8 @@ public class TextServicesManagerService extends ITextServicesManager.Stub {
        }

        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) {
            putInt(Settings.Secure.SELECTED_SPELL_CHECKER_SUBTYPE, hashCode);