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

Commit f0ed48d1 authored by Yohei Yukawa's avatar Yohei Yukawa
Browse files

Have unified setter/getter for TSMS Settings.

This ports my previous CL for InputMethodManagerService [1] to
TextServicesManagerService (TSMS).

In order to make TSMS encryption-aware, we are going to introduce a new
state where any read/write access to Secure Settings from TSMS is
virtualized so that we can temporarily enable only encryption-aware
spell checkers until the user unlocks the device then revert
any changes made before the device enters into an unlocked state.

See my previous commit message [1] for details.

This is still a preparation code.  Behavior change is not intended yet
in this CL.

  [1]: I0f79243e5cc1556764da37fa38078e075a27d42b
       87523670

Bug: 27456430
Change-Id: I97a1e2f75bdecb0aa88fb35dfe56732c08fcbbd5
parent e47b0d4f
Loading
Loading
Loading
Loading
+30 −13
Original line number Diff line number Diff line
@@ -1051,6 +1051,30 @@ public class TextServicesManagerService extends ITextServicesManager.Stub {
            mCurrentUserId = userId;
        }

        private void putString(final String key, final String str) {
            Settings.Secure.putStringForUser(mResolver, key, str, mCurrentUserId);
        }

        private String getString(final String key) {
            return Settings.Secure.getStringForUser(mResolver, key, mCurrentUserId);
        }

        private void putInt(final String key, final int value) {
            Settings.Secure.putIntForUser(mResolver, key, value, mCurrentUserId);
        }

        private int getInt(final String key, final int defaultValue) {
            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;
        }

        public void setCurrentProfileIds(int[] currentProfileIds) {
            synchronized (mLock) {
                mCurrentProfileIds = currentProfileIds;
@@ -1073,34 +1097,27 @@ public class TextServicesManagerService extends ITextServicesManager.Stub {
        }

        public void putSelectedSpellChecker(String sciId) {
            Settings.Secure.putStringForUser(mResolver,
                    Settings.Secure.SELECTED_SPELL_CHECKER, sciId, mCurrentUserId);
            putString(Settings.Secure.SELECTED_SPELL_CHECKER, sciId);
        }

        public void putSelectedSpellCheckerSubtype(int hashCode) {
            Settings.Secure.putStringForUser(mResolver,
                    Settings.Secure.SELECTED_SPELL_CHECKER_SUBTYPE, String.valueOf(hashCode),
                    mCurrentUserId);
            putString(Settings.Secure.SELECTED_SPELL_CHECKER_SUBTYPE, String.valueOf(hashCode));
        }

        public void setSpellCheckerEnabled(boolean enabled) {
            Settings.Secure.putIntForUser(mResolver,
                    Settings.Secure.SPELL_CHECKER_ENABLED, enabled ? 1 : 0, mCurrentUserId);
            putBoolean(Settings.Secure.SPELL_CHECKER_ENABLED, enabled);
        }

        public String getSelectedSpellChecker() {
            return Settings.Secure.getStringForUser(mResolver,
                    Settings.Secure.SELECTED_SPELL_CHECKER, mCurrentUserId);
            return getString(Settings.Secure.SELECTED_SPELL_CHECKER);
        }

        public String getSelectedSpellCheckerSubtype() {
            return Settings.Secure.getStringForUser(mResolver,
                    Settings.Secure.SELECTED_SPELL_CHECKER_SUBTYPE, mCurrentUserId);
            return getString(Settings.Secure.SELECTED_SPELL_CHECKER_SUBTYPE);
        }

        public boolean isSpellCheckerEnabled() {
            return Settings.Secure.getIntForUser(mResolver,
                    Settings.Secure.SPELL_CHECKER_ENABLED, 1, mCurrentUserId) == 1;
            return getBoolean(Settings.Secure.SPELL_CHECKER_ENABLED, true);
        }
    }