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

Commit 46a54e8b authored by Guliz Tuncay's avatar Guliz Tuncay
Browse files

Remove the internal APIs of TSM to change spell checker settings

Previously, TextServicesManager was exposing APIs to system services to
modify spell checker settings. However, Settings application is the only
client of these APIs and there is no need to expose it to all the other
services. Settings app already has the WRITE_SECURE_SETTINGS permission
and can directly update the spell checker settings. Hence, we can remove
these APIs from TSM.

Fixes: 62950392
Test: Manually as follows.
      1. Build and flash an OS image.
      2. Complete the setup wizard (if any).
      3. Make sure AOSP Keyboard (com.android.inputmethod.latin) is installed
      4. Install SampleSpellCheckerService
       4.1 tapas SampleSpellCheckerService
       4.2. make -j
       4.3. adb install -r out/target/product/generic/system/app/SampleSpellCheckerService/SampleSpellCheckerService.apk
      5. Set the current spell checker service to be AOSP SCS by
       adb shell settings put secure selected_spell_checker com.android.inputmethod.latin/.spellcheck.AndroidSpellCheckerService
      6. Run a test program that has TextView and tap on one of the
       TextViews and type some text.
      7. Observe that there is a connection to AOSP SCS by
       adb shell dumpsys textservices
      8. Set the current spell checker service to be
      SampleSpellCheckerService SCS by
adb shell settings put secure selected_spell_checker com.example.android.samplespellcheckerservice/.SampleSpellCheckerService
      9. Observe that there is a connection to SampleSpellCheckerService
      SCS by
       adb shell dumpsys textservices
Change-Id: I4513ca661788f00785f684c21d7244c233b6e33e
parent d687b5dd
Loading
Loading
Loading
Loading
+0 −42
Original line number Diff line number Diff line
@@ -210,20 +210,6 @@ public final class TextServicesManager {
        }
    }

    /**
     * @hide
     */
    public void setCurrentSpellChecker(SpellCheckerInfo sci) {
        try {
            if (sci == null) {
                throw new NullPointerException("SpellCheckerInfo is null.");
            }
            mService.setCurrentSpellChecker(null, sci.getId());
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    /**
     * @hide
     */
@@ -237,34 +223,6 @@ public final class TextServicesManager {
        }
    }

    /**
     * @hide
     */
    public void setSpellCheckerSubtype(SpellCheckerSubtype subtype) {
        try {
            final int hashCode;
            if (subtype == null) {
                hashCode = 0;
            } else {
                hashCode = subtype.hashCode();
            }
            mService.setCurrentSpellCheckerSubtype(null, hashCode);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    /**
     * @hide
     */
    public void setSpellCheckerEnabled(boolean enabled) {
        try {
            mService.setSpellCheckerEnabled(enabled);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    /**
     * @hide
     */
+0 −3
Original line number Diff line number Diff line
@@ -36,9 +36,6 @@ interface ITextServicesManager {
            in ITextServicesSessionListener tsListener,
            in ISpellCheckerSessionListener scListener, in Bundle bundle);
    oneway void finishSpellCheckerService(in ISpellCheckerSessionListener listener);
    oneway void setCurrentSpellChecker(String locale, String sciId);
    oneway void setCurrentSpellCheckerSubtype(String locale, int hashCode);
    oneway void setSpellCheckerEnabled(boolean enabled);
    boolean isSpellCheckerEnabled();
    SpellCheckerInfo[] getEnabledSpellCheckers();
}
+0 −71
Original line number Diff line number Diff line
@@ -642,57 +642,6 @@ public class TextServicesManagerService extends ITextServicesManager.Stub {
        }
    }

    @Override
    public void setCurrentSpellChecker(String locale, String sciId) {
        if (!calledFromValidUser()) {
            return;
        }
        synchronized(mSpellCheckerMap) {
            if (mContext.checkCallingOrSelfPermission(
                    android.Manifest.permission.WRITE_SECURE_SETTINGS)
                    != PackageManager.PERMISSION_GRANTED) {
                throw new SecurityException(
                        "Requires permission "
                        + android.Manifest.permission.WRITE_SECURE_SETTINGS);
            }
            setCurrentSpellCheckerLocked(sciId);
        }
    }

    @Override
    public void setCurrentSpellCheckerSubtype(String locale, int hashCode) {
        if (!calledFromValidUser()) {
            return;
        }
        synchronized(mSpellCheckerMap) {
            if (mContext.checkCallingOrSelfPermission(
                    android.Manifest.permission.WRITE_SECURE_SETTINGS)
                    != PackageManager.PERMISSION_GRANTED) {
                throw new SecurityException(
                        "Requires permission "
                        + android.Manifest.permission.WRITE_SECURE_SETTINGS);
            }
            setCurrentSpellCheckerSubtypeLocked(hashCode);
        }
    }

    @Override
    public void setSpellCheckerEnabled(boolean enabled) {
        if (!calledFromValidUser()) {
            return;
        }
        synchronized(mSpellCheckerMap) {
            if (mContext.checkCallingOrSelfPermission(
                    android.Manifest.permission.WRITE_SECURE_SETTINGS)
                    != PackageManager.PERMISSION_GRANTED) {
                throw new SecurityException(
                        "Requires permission "
                        + android.Manifest.permission.WRITE_SECURE_SETTINGS);
            }
            setSpellCheckerEnabledLocked(enabled);
        }
    }

    private void setCurrentSpellCheckerLocked(String sciId) {
        if (DBG) {
            Slog.w(TAG, "setCurrentSpellChecker: " + sciId);
@@ -732,18 +681,6 @@ public class TextServicesManagerService extends ITextServicesManager.Stub {
        }
    }

    private void setSpellCheckerEnabledLocked(boolean enabled) {
        if (DBG) {
            Slog.w(TAG, "setSpellCheckerEnabled: " + enabled);
        }
        final long ident = Binder.clearCallingIdentity();
        try {
            mSettings.setSpellCheckerEnabled(enabled);
        } finally {
            Binder.restoreCallingIdentity(ident);
        }
    }

    private boolean isSpellCheckerEnabledLocked() {
        final long ident = Binder.clearCallingIdentity();
        try {
@@ -1135,10 +1072,6 @@ public class TextServicesManagerService extends ITextServicesManager.Stub {
            return Settings.Secure.getIntForUser(mResolver, key, defaultValue, mCurrentUserId);
        }

        private void putBoolean(final String key, final boolean value) {
            putInt(key, value ? 1 : 0);
        }

        private boolean getBoolean(final String key, final boolean defaultValue) {
            return getInt(key, defaultValue ? 1 : 0) == 1;
        }
@@ -1178,10 +1111,6 @@ public class TextServicesManagerService extends ITextServicesManager.Stub {
            putInt(Settings.Secure.SELECTED_SPELL_CHECKER_SUBTYPE, hashCode);
        }

        public void setSpellCheckerEnabled(boolean enabled) {
            putBoolean(Settings.Secure.SPELL_CHECKER_ENABLED, enabled);
        }

        @NonNull
        public String getSelectedSpellChecker() {
            return getString(Settings.Secure.SELECTED_SPELL_CHECKER, "");