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

Commit 1051fd4f authored by Abdelrahman Awadalla's avatar Abdelrahman Awadalla Committed by Android (Google) Code Review
Browse files

Merge "Checking if the touchpad visualizer developer option is enabled" into main

parents cb197a1d 3087fc6c
Loading
Loading
Loading
Loading
+33 −0
Original line number Diff line number Diff line
@@ -335,6 +335,39 @@ public class InputSettings {
        return touchpadVisualizer();
    }

    /**
     * Returns true if the touchpad visualizer is allowed to appear.
     *
     * @param context The application context.
     * @return Whether it is allowed to show touchpad visualizer or not.
     *
     * @hide
     */
    public static boolean useTouchpadVisualizer(@NonNull Context context) {
        if (!isTouchpadVisualizerFeatureFlagEnabled()) {
            return false;
        }
        return Settings.System.getIntForUser(context.getContentResolver(),
                Settings.System.TOUCHPAD_VISUALIZER, 0, UserHandle.USER_CURRENT) == 1;
    }

    /**
     * Sets the touchpad visualizer behaviour.
     *
     * @param context The application context.
     * @param enabled Will enable touchpad visualizer if true, disable it if false
     *
     * @hide
     */
    @RequiresPermission(Manifest.permission.WRITE_SETTINGS)
    public static void setTouchpadVisualizer(@NonNull Context context, boolean enabled) {
        if (!isTouchpadVisualizerFeatureFlagEnabled()) {
            return;
        }
        Settings.System.putIntForUser(context.getContentResolver(),
                Settings.System.TOUCHPAD_VISUALIZER, enabled ? 1 : 0, UserHandle.USER_CURRENT);
    }

    /**
     * Returns true if the touchpad should allow tap dragging.
     *
+6 −0
Original line number Diff line number Diff line
@@ -71,6 +71,8 @@ class InputSettingsObserver extends ContentObserver {
                        (reason) -> updateTouchpadTapToClickEnabled()),
                Map.entry(Settings.System.getUriFor(Settings.System.TOUCHPAD_TAP_DRAGGING),
                        (reason) -> updateTouchpadTapDraggingEnabled()),
                Map.entry(Settings.System.getUriFor(Settings.System.TOUCHPAD_VISUALIZER),
                        (reason) -> updateTouchpadHardwareStateNotificationsEnabled()),
                Map.entry(Settings.System.getUriFor(Settings.System.TOUCHPAD_RIGHT_CLICK_ZONE),
                        (reason) -> updateTouchpadRightClickZoneEnabled()),
                Map.entry(Settings.System.getUriFor(Settings.System.SHOW_TOUCHES),
@@ -177,6 +179,10 @@ class InputSettingsObserver extends ContentObserver {
        mNative.setTouchpadTapDraggingEnabled(InputSettings.useTouchpadTapDragging(mContext));
    }

    private void updateTouchpadHardwareStateNotificationsEnabled() {
        mNative.setShouldNotifyTouchpadHardwareState(InputSettings.useTouchpadVisualizer(mContext));
    }

    private void updateTouchpadRightClickZoneEnabled() {
        mNative.setTouchpadRightClickZoneEnabled(InputSettings.useTouchpadRightClickZone(mContext));
    }
+5 −0
Original line number Diff line number Diff line
@@ -135,6 +135,8 @@ interface NativeInputManagerService {

    void setTouchpadTapDraggingEnabled(boolean enabled);

    void setShouldNotifyTouchpadHardwareState(boolean enabled);

    void setTouchpadRightClickZoneEnabled(boolean enabled);

    void setShowTouches(boolean enabled);
@@ -394,6 +396,9 @@ interface NativeInputManagerService {
        @Override
        public native void setTouchpadTapDraggingEnabled(boolean enabled);

        @Override
        public native void setShouldNotifyTouchpadHardwareState(boolean enabled);

        @Override
        public native void setTouchpadRightClickZoneEnabled(boolean enabled);

+30 −0
Original line number Diff line number Diff line
@@ -291,6 +291,7 @@ public:
    void setTouchpadNaturalScrollingEnabled(bool enabled);
    void setTouchpadTapToClickEnabled(bool enabled);
    void setTouchpadTapDraggingEnabled(bool enabled);
    void setShouldNotifyTouchpadHardwareState(bool enabled);
    void setTouchpadRightClickZoneEnabled(bool enabled);
    void setInputDeviceEnabled(uint32_t deviceId, bool enabled);
    void setShowTouches(bool enabled);
@@ -440,6 +441,9 @@ private:
        // True to enable tap dragging on touchpads.
        bool touchpadTapDraggingEnabled{false};

        // True if hardware state update notifications should be sent to the policy.
        bool shouldNotifyTouchpadHardwareState{false};

        // True to enable a zone on the right-hand side of touchpads where clicks will be turned
        // into context (a.k.a. "right") clicks.
        bool touchpadRightClickZoneEnabled{false};
@@ -698,6 +702,7 @@ void NativeInputManager::getReaderConfiguration(InputReaderConfiguration* outCon
        outConfig->touchpadNaturalScrollingEnabled = mLocked.touchpadNaturalScrollingEnabled;
        outConfig->touchpadTapToClickEnabled = mLocked.touchpadTapToClickEnabled;
        outConfig->touchpadTapDraggingEnabled = mLocked.touchpadTapDraggingEnabled;
        outConfig->shouldNotifyTouchpadHardwareState = mLocked.shouldNotifyTouchpadHardwareState;
        outConfig->touchpadRightClickZoneEnabled = mLocked.touchpadRightClickZoneEnabled;

        outConfig->disabledDevices = mLocked.disabledInputDevices;
@@ -1260,6 +1265,22 @@ void NativeInputManager::setTouchpadTapDraggingEnabled(bool enabled) {
            InputReaderConfiguration::Change::TOUCHPAD_SETTINGS);
}

void NativeInputManager::setShouldNotifyTouchpadHardwareState(bool enabled) {
    { // acquire lock
        std::scoped_lock _l(mLock);

        if (mLocked.shouldNotifyTouchpadHardwareState == enabled) {
            return;
        }

        ALOGI("Should touchpad hardware state be notified: %s.", toString(enabled));
        mLocked.shouldNotifyTouchpadHardwareState = enabled;
    } // release lock

    mInputManager->getReader().requestRefreshConfiguration(
            InputReaderConfiguration::Change::TOUCHPAD_SETTINGS);
}

void NativeInputManager::setTouchpadRightClickZoneEnabled(bool enabled) {
    { // acquire lock
        std::scoped_lock _l(mLock);
@@ -2144,6 +2165,13 @@ static void nativeSetTouchpadTapDraggingEnabled(JNIEnv* env, jobject nativeImplO
    im->setTouchpadTapDraggingEnabled(enabled);
}

static void nativeSetShouldNotifyTouchpadHardwareState(JNIEnv* env, jobject nativeImplObj,
                                                       jboolean enabled) {
    NativeInputManager* im = getNativeInputManager(env, nativeImplObj);

    im->setShouldNotifyTouchpadHardwareState(enabled);
}

static void nativeSetTouchpadRightClickZoneEnabled(JNIEnv* env, jobject nativeImplObj,
                                                   jboolean enabled) {
    NativeInputManager* im = getNativeInputManager(env, nativeImplObj);
@@ -2762,6 +2790,8 @@ static const JNINativeMethod gInputManagerMethods[] = {
         (void*)nativeSetTouchpadNaturalScrollingEnabled},
        {"setTouchpadTapToClickEnabled", "(Z)V", (void*)nativeSetTouchpadTapToClickEnabled},
        {"setTouchpadTapDraggingEnabled", "(Z)V", (void*)nativeSetTouchpadTapDraggingEnabled},
        {"setShouldNotifyTouchpadHardwareState", "(Z)V",
         (void*)nativeSetShouldNotifyTouchpadHardwareState},
        {"setTouchpadRightClickZoneEnabled", "(Z)V", (void*)nativeSetTouchpadRightClickZoneEnabled},
        {"setShowTouches", "(Z)V", (void*)nativeSetShowTouches},
        {"setInteractive", "(Z)V", (void*)nativeSetInteractive},
+1 −0
Original line number Diff line number Diff line
@@ -151,6 +151,7 @@ class InputManagerServiceTests {
        verify(native).setTouchpadNaturalScrollingEnabled(anyBoolean())
        verify(native).setTouchpadTapToClickEnabled(anyBoolean())
        verify(native).setTouchpadTapDraggingEnabled(anyBoolean())
        verify(native).setShouldNotifyTouchpadHardwareState(anyBoolean())
        verify(native).setTouchpadRightClickZoneEnabled(anyBoolean())
        verify(native).setShowTouches(anyBoolean())
        verify(native).setMotionClassifierEnabled(anyBoolean())