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

Commit 7348be74 authored by Danesh M's avatar Danesh M
Browse files

Move high touch sensitivity and hovering to InputService

Doing so allows us to keep track of user changes and restore
preferences.
CYNGNOS-1166

Change-Id: I5a6af73129acefa6530ceb3f73cc4cd83a19a676
parent 1292e862
Loading
Loading
Loading
Loading
+48 −0
Original line number Diff line number Diff line
@@ -143,6 +143,7 @@ import java.util.HashSet;
import java.util.List;
import java.util.Locale;

import cyanogenmod.hardware.CMHardwareManager;
import cyanogenmod.providers.CMSettings;

import org.cyanogenmod.internal.util.QSUtils;
@@ -239,6 +240,7 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
    private boolean mShowOngoingImeSwitcherForPhones;
    private boolean mNotificationShown;
    private final boolean mImeSelectedOnBoot;
    private CMHardwareManager mCMHardware;

    static class SessionState {
        final ClientState client;
@@ -506,15 +508,32 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
                        }
                    }, userId);

            if (mCMHardware.isSupported(CMHardwareManager.FEATURE_HIGH_TOUCH_SENSITIVITY)) {
                resolver.registerContentObserver(CMSettings.System.getUriFor(
                        CMSettings.System.HIGH_TOUCH_SENSITIVITY_ENABLE), false, this, userId);
            }
            if (mCMHardware.isSupported(CMHardwareManager.FEATURE_TOUCH_HOVERING)) {
                resolver.registerContentObserver(CMSettings.Secure.getUriFor(
                        CMSettings.Secure.FEATURE_TOUCH_HOVERING), false, this, userId);
            }

            mRegistered = true;
        }

        @Override public void onChange(boolean selfChange, Uri uri) {
            final Uri showImeUri =
                    Settings.Secure.getUriFor(Settings.Secure.SHOW_IME_WITH_HARD_KEYBOARD);
            final Uri touchSensitivityUri =
                    CMSettings.System.getUriFor(CMSettings.System.HIGH_TOUCH_SENSITIVITY_ENABLE);
            final Uri touchHoveringUri =
                    CMSettings.Secure.getUriFor(CMSettings.Secure.FEATURE_TOUCH_HOVERING);
            synchronized (mMethodMap) {
                if (showImeUri.equals(uri)) {
                    updateKeyboardFromSettingsLocked();
                } else if (touchSensitivityUri.equals(uri)) {
                    updateTouchSensitivity();
                } else if (touchHoveringUri.equals(uri)) {
                    updateTouchHovering();
                } else {
                    boolean enabledChanged = false;
                    String newEnabled = mSettings.getEnabledInputMethodsStr();
@@ -943,11 +962,17 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
            }
        }

        // Must happen before registerContentObserverLocked
        mCMHardware = CMHardwareManager.getInstance(mContext);

        synchronized (mMethodMap) {
            mSettingsObserver.registerContentObserverLocked(userId);
            updateFromSettingsLocked(true);
        }

        updateTouchHovering();
        updateTouchSensitivity();

        // IMMS wants to receive Intent.ACTION_LOCALE_CHANGED in order to update the current IME
        // according to the new system locale.
        final IntentFilter filter = new IntentFilter();
@@ -1072,6 +1097,9 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
                    mContext.getBasePackageName());
        }

        updateTouchHovering();
        updateTouchSensitivity();

        if (DEBUG) Slog.d(TAG, "Switching user stage 3/3. newUserId=" + newUserId
                + " selectedIme=" + mSettings.getSelectedInputMethod());
    }
@@ -1970,6 +1998,26 @@ public class InputMethodManagerService extends IInputMethodManager.Stub

    }

    private void updateTouchSensitivity() {
        if (!mCMHardware.isSupported(CMHardwareManager.FEATURE_HIGH_TOUCH_SENSITIVITY)) {
            return;
        }
        boolean touchSensitivityEnable = CMSettings.System.getInt(mContext.getContentResolver(),
                CMSettings.System.HIGH_TOUCH_SENSITIVITY_ENABLE, 0) == 1;
        mCMHardware.set(CMHardwareManager.FEATURE_HIGH_TOUCH_SENSITIVITY,
                touchSensitivityEnable);
    }

    private void updateTouchHovering() {
        if (!mCMHardware.isSupported(CMHardwareManager.FEATURE_TOUCH_HOVERING)) {
            return;
        }
        boolean touchHovering = CMSettings.Secure.getInt(mContext.getContentResolver(),
                CMSettings.Secure.FEATURE_TOUCH_HOVERING, 0) == 1;
        mCMHardware.set(CMHardwareManager.FEATURE_TOUCH_HOVERING,
                touchHovering);
    }

    public void updateKeyboardFromSettingsLocked() {
        mShowImeWithHardKeyboard = mSettings.isShowImeWithHardKeyboardEnabled();
        if (mSwitchingDialog != null