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

Commit 1c94b8cc authored by Guliz Tuncay's avatar Guliz Tuncay
Browse files

Clean up TSMS#setCurrentSpellCheckerLocked.

Remove the unnecessary calls to getCurrentSpellChecker and containsKey
in TSMS#setCurrentSpellCheckerLocked. We do not change visible
user/developer behavior in this CL.

Fixes: 63540846
Test: Manually as follows:
  Test 1:
   1. Make sure you have two users such as this:
     User Owner (userId 0), User A (userId 11)
   2. Clear A's SC settings on the command line by
     adb shell "settings --user 11 put secure selected_spell_checker ''"
   4. Check SC value in settings, should be null
   5. Switch to Owner
   6. Switch back to A (so that TSMS#resetInternalState is called)
   7. Make sure SC value in settings is not empty by
     adb shell settings --user 11 get secure selected_spell_checker
  Test 2:
   1. 2 versions of SampleSpellCheckerService:
     one with a single SCS (v1), one with 2 SCSs (v2)
   2. Install v2 by
   adb install -r out/target/product/generic/system/app/SampleSpellCheckerService/SampleSpellCheckerService.apk
   3. adb shell settings put secure selected_spell_checker com.example.android.samplespellcheckerservice/.SampleSpellCheckerService2
   4. Install v1
   5. adb shell settings get secure selected_spell_checker
    Should return
    com.example.android.samplespellcheckerservice/.SampleSpellCheckerService2
    This is buggy behavior, see bug#63542224. We aim to keep the
    user/developer behavior as is.
Change-Id: Idaa5b738d0d8c01c12a8d9cd7ac2a6b27c7ae4ad
parent 43bc8a0f
Loading
Loading
Loading
Loading
+7 −11
Original line number Diff line number Diff line
@@ -191,7 +191,7 @@ public class TextServicesManagerService extends ITextServicesManager.Stub {
                // Set the current spell checker if there is one or more spell checkers
                // available. In this case, "sci" is the first one in the available spell
                // checkers.
                setCurrentSpellCheckerLocked(sci.getId());
                setCurrentSpellCheckerLocked(sci);
            }
        }
    }
@@ -230,9 +230,10 @@ public class TextServicesManagerService extends ITextServicesManager.Stub {
                        change == PACKAGE_PERMANENT_CHANGE || change == PACKAGE_TEMPORARY_CHANGE
                        // Package modified
                        || isPackageModified(packageName)) {
                    sci = findAvailSpellCheckerLocked(packageName);
                    if (sci != null) {
                        setCurrentSpellCheckerLocked(sci.getId());
                    SpellCheckerInfo availSci = findAvailSpellCheckerLocked(packageName);
                    // Set the spell checker settings if different than before
                    if (availSci != null && !availSci.getId().equals(sci.getId())) {
                        setCurrentSpellCheckerLocked(availSci);
                    }
                }
            }
@@ -643,16 +644,11 @@ public class TextServicesManagerService extends ITextServicesManager.Stub {
        }
    }

    private void setCurrentSpellCheckerLocked(String sciId) {
    private void setCurrentSpellCheckerLocked(SpellCheckerInfo sci) {
        final String sciId = sci.getId();
        if (DBG) {
            Slog.w(TAG, "setCurrentSpellChecker: " + sciId);
        }
        if (TextUtils.isEmpty(sciId) || !mSpellCheckerMap.containsKey(sciId)) return;
        final SpellCheckerInfo currentSci = getCurrentSpellChecker(null);
        if (currentSci != null && currentSci.getId().equals(sciId)) {
            // Do nothing if the current spell checker is same as new spell checker.
            return;
        }
        final long ident = Binder.clearCallingIdentity();
        try {
            mSettings.putSelectedSpellChecker(sciId);