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

Commit edb2e637 authored by Dhina17's avatar Dhina17 Committed by Bruno Martins
Browse files

SystemUI: Move DT2S from PulsingGestureListener

PulsingGestureListener should handle the touch events in the
dozing state (AOD/ambient).
Our DT2S should work in non-dozing mode so move out from here.

Test:
Double tap to sleep on QQS status bar works fine as before.

Change-Id: Ia79df2eb73e54d8b0dcb1d10b18539f4e88a0a18
parent 87052f70
Loading
Loading
Loading
Loading
+9 −1
Original line number Diff line number Diff line
@@ -111,6 +111,9 @@ public class NotificationShadeWindowViewController {
                    step.getTransitionState() == TransitionState.RUNNING;
            };

    private GestureDetector mQQSGestureHandler;
    private final QQSGestureListener mQQSGestureListener;

    @Inject
    public NotificationShadeWindowViewController(
            LockscreenShadeTransitionController transitionController,
@@ -135,7 +138,8 @@ public class NotificationShadeWindowViewController {
            KeyguardBouncerComponent.Factory keyguardBouncerComponentFactory,
            AlternateBouncerInteractor alternateBouncerInteractor,
            KeyguardTransitionInteractor keyguardTransitionInteractor,
            PrimaryBouncerToGoneTransitionViewModel primaryBouncerToGoneTransitionViewModel
            PrimaryBouncerToGoneTransitionViewModel primaryBouncerToGoneTransitionViewModel,
            QQSGestureListener qqsGestureListener
    ) {
        mLockscreenShadeTransitionController = transitionController;
        mFalsingCollector = falsingCollector;
@@ -156,6 +160,7 @@ public class NotificationShadeWindowViewController {
        mPulsingGestureListener = pulsingGestureListener;
        mNotificationInsetsController = notificationInsetsController;
        mAlternateBouncerInteractor = alternateBouncerInteractor;
        mQQSGestureListener = qqsGestureListener;

        // This view is not part of the newly inflated expanded status bar.
        mBrightnessMirror = mView.findViewById(R.id.brightness_mirror_container);
@@ -188,6 +193,8 @@ public class NotificationShadeWindowViewController {
        mStackScrollLayout = mView.findViewById(R.id.notification_stack_scroller);
        mPulsingWakeupGestureHandler = new GestureDetector(mView.getContext(),
                mPulsingGestureListener);
        mQQSGestureHandler = new GestureDetector(mView.getContext(),
                mQQSGestureListener);

        mView.setLayoutInsetsController(mNotificationInsetsController);
        mView.setInteractionEventHandler(new NotificationShadeWindowView.InteractionEventHandler() {
@@ -239,6 +246,7 @@ public class NotificationShadeWindowViewController {
                }

                mFalsingCollector.onTouchEvent(ev);
                mQQSGestureHandler.onTouchEvent(ev);
                mPulsingWakeupGestureHandler.onTouchEvent(ev);
                if (mStatusBarKeyguardViewManager.onTouch(ev)) {
                    return true;
+13 −37
Original line number Diff line number Diff line
@@ -16,7 +16,6 @@

package com.android.systemui.shade

import android.content.Context
import android.hardware.display.AmbientDisplayConfiguration
import android.os.PowerManager
import android.os.SystemClock
@@ -34,7 +33,6 @@ import com.android.systemui.statusbar.phone.CentralSurfaces
import com.android.systemui.statusbar.phone.dagger.CentralSurfacesComponent
import com.android.systemui.tuner.TunerService
import com.android.systemui.tuner.TunerService.Tunable
import lineageos.providers.LineageSettings;
import java.io.PrintWriter
import javax.inject.Inject

@@ -56,23 +54,14 @@ class PulsingGestureListener @Inject constructor(
        private val ambientDisplayConfiguration: AmbientDisplayConfiguration,
        private val statusBarStateController: StatusBarStateController,
        private val shadeLogger: ShadeLogger,
        private val powerManager: PowerManager,
        userTracker: UserTracker,
        tunerService: TunerService,
        dumpManager: DumpManager,
        context: Context
        dumpManager: DumpManager
) : GestureDetector.SimpleOnGestureListener(), Dumpable {
    private var doubleTapEnabled = false
    private var singleTapEnabled = false
    private var doubleTapEnabledNative = false

    companion object {
        internal val DOUBLE_TAP_SLEEP_GESTURE =
            "lineagesystem:" + LineageSettings.System.DOUBLE_TAP_SLEEP_GESTURE
    }
    private var doubleTapToSleepEnabled = false
    private val quickQsOffsetHeight: Int

    init {
        val tunable = Tunable { key: String?, value: String? ->
            when (key) {
@@ -84,20 +73,14 @@ class PulsingGestureListener @Inject constructor(
                Settings.Secure.DOZE_TAP_SCREEN_GESTURE ->
                    singleTapEnabled = ambientDisplayConfiguration.tapGestureEnabled(
                            userTracker.userId)
                DOUBLE_TAP_SLEEP_GESTURE ->
                    doubleTapToSleepEnabled = TunerService.parseIntegerSwitch(value, true)
            }
        }
        tunerService.addTunable(tunable,
                Settings.Secure.DOUBLE_TAP_TO_WAKE,
                Settings.Secure.DOZE_DOUBLE_TAP_GESTURE,
                Settings.Secure.DOZE_TAP_SCREEN_GESTURE,
                DOUBLE_TAP_SLEEP_GESTURE)
                Settings.Secure.DOZE_TAP_SCREEN_GESTURE)

        dumpManager.registerDumpable(this)

        quickQsOffsetHeight = context.getResources().getDimensionPixelSize(
                com.android.internal.R.dimen.quick_qs_offset_height)
    }

    override fun onSingleTapUp(e: MotionEvent): Boolean {
@@ -129,10 +112,11 @@ class PulsingGestureListener @Inject constructor(
    override fun onDoubleTapEvent(e: MotionEvent): Boolean {
        // React to the [MotionEvent.ACTION_UP] event after double tap is detected. Falsing
        // checks MUST be on the ACTION_UP event.
        if (e.actionMasked == MotionEvent.ACTION_UP && !falsingManager.isFalseDoubleTap) {
            if (statusBarStateController.isDozing &&
        if (e.actionMasked == MotionEvent.ACTION_UP &&
                statusBarStateController.isDozing &&
                (doubleTapEnabled || singleTapEnabled || doubleTapEnabledNative) &&
                !falsingManager.isProximityNear
                !falsingManager.isProximityNear &&
                !falsingManager.isFalseDoubleTap
        ) {
            centralSurfaces.wakeUpIfDozing(
                    SystemClock.uptimeMillis(),
@@ -140,13 +124,6 @@ class PulsingGestureListener @Inject constructor(
                    "PULSING_DOUBLE_TAP",
                    PowerManager.WAKE_REASON_TAP)
            return true
            } else if (!statusBarStateController.isDozing &&
                doubleTapToSleepEnabled &&
                e.getY() < quickQsOffsetHeight
            ) {
                powerManager.goToSleep(e.getEventTime())
                return true
            }
        }
        return false
    }
@@ -155,7 +132,6 @@ class PulsingGestureListener @Inject constructor(
        pw.println("singleTapEnabled=$singleTapEnabled")
        pw.println("doubleTapEnabled=$doubleTapEnabled")
        pw.println("doubleTapEnabledNative=$doubleTapEnabledNative")
        pw.println("doubleTapToSleepEnabled=$doubleTapToSleepEnabled")
        pw.println("isDocked=${dockManager.isDocked}")
        pw.println("isProxCovered=${falsingManager.isProximityNear}")
    }
+77 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2023 The LineageOS Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.systemui.shade

import android.content.res.Resources
import android.os.PowerManager
import android.view.GestureDetector
import android.view.MotionEvent
import com.android.systemui.dagger.qualifiers.Main
import com.android.systemui.plugins.FalsingManager
import com.android.systemui.plugins.statusbar.StatusBarStateController
import com.android.systemui.statusbar.phone.dagger.CentralSurfacesComponent
import com.android.systemui.tuner.TunerService
import com.android.systemui.tuner.TunerService.Tunable
import lineageos.providers.LineageSettings

import javax.inject.Inject

@CentralSurfacesComponent.CentralSurfacesScope
class QQSGestureListener @Inject constructor(
        private val falsingManager: FalsingManager,
        private val powerManager: PowerManager,
        private val statusBarStateController: StatusBarStateController,
        tunerService: TunerService,
        @Main resources: Resources
) : GestureDetector.SimpleOnGestureListener() {

    companion object {
        internal val DOUBLE_TAP_SLEEP_GESTURE =
                "lineagesystem:" + LineageSettings.System.DOUBLE_TAP_SLEEP_GESTURE
    }

    private var doubleTapToSleepEnabled = false
    private val quickQsOffsetHeight: Int

    init {
        val tunable = Tunable { key: String?, value: String? ->
            when (key) {
                DOUBLE_TAP_SLEEP_GESTURE ->
                    doubleTapToSleepEnabled = TunerService.parseIntegerSwitch(value, true)
            }
        }
        tunerService.addTunable(tunable, DOUBLE_TAP_SLEEP_GESTURE)

        quickQsOffsetHeight = resources.getDimensionPixelSize(
                com.android.internal.R.dimen.quick_qs_offset_height)
    }

    override fun onDoubleTapEvent(e: MotionEvent): Boolean {
        // Go to sleep on double tap the QQS status bar
        if (e.actionMasked == MotionEvent.ACTION_UP &&
                !statusBarStateController.isDozing &&
                doubleTapToSleepEnabled &&
                e.getY() < quickQsOffsetHeight &&
                !falsingManager.isFalseDoubleTap
        ) {
            powerManager.goToSleep(e.getEventTime())
            return true
        }
        return false
    }

}