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

Commit 32eeaa14 authored by Caitlin Shkuratov's avatar Caitlin Shkuratov
Browse files

[Central Surfaces] Move #wakeUpIfDozing to PowerRepository.

Also moves PulsingGestureListener's calls to #wakeUpIfDozing to the
power interactor.

Other references to CentralSurfaces#wakeUpIfDozing will be moved in
future CLs.

Bug: 277762009
Bug: 277764509
Test: Single tap on AOD -> verify device wakes with reason
"PULSING_SINGLE_TAP"
Test: Double tap on AOD -> verify device wakes with reason
"PULSING_DOUBLE_TAP"
Test: atest PowerRepositoryImplTest PowerInteractorTest
Test: atest PulsingGestureListenerTest

Change-Id: I96d2ec9343fc9a329dc3142800db41d2ddfe4510
parent b9777bc4
Loading
Loading
Loading
Loading
+16 −1
Original line number Original line Diff line number Diff line
@@ -26,6 +26,8 @@ import com.android.systemui.broadcast.BroadcastDispatcher
import com.android.systemui.common.coroutine.ChannelExt.trySendWithFailureLogging
import com.android.systemui.common.coroutine.ChannelExt.trySendWithFailureLogging
import com.android.systemui.common.coroutine.ConflatedCallbackFlow.conflatedCallbackFlow
import com.android.systemui.common.coroutine.ConflatedCallbackFlow.conflatedCallbackFlow
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Application
import com.android.systemui.util.time.SystemClock
import javax.inject.Inject
import javax.inject.Inject
import kotlinx.coroutines.channels.awaitClose
import kotlinx.coroutines.channels.awaitClose
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.Flow
@@ -34,13 +36,18 @@ import kotlinx.coroutines.flow.Flow
interface PowerRepository {
interface PowerRepository {
    /** Whether the device is interactive. Starts with the current state. */
    /** Whether the device is interactive. Starts with the current state. */
    val isInteractive: Flow<Boolean>
    val isInteractive: Flow<Boolean>

    /** Wakes up the device. */
    fun wakeUp(why: String, @PowerManager.WakeReason wakeReason: Int)
}
}


@SysUISingleton
@SysUISingleton
class PowerRepositoryImpl
class PowerRepositoryImpl
@Inject
@Inject
constructor(
constructor(
    manager: PowerManager,
    private val manager: PowerManager,
    @Application private val applicationContext: Context,
    private val systemClock: SystemClock,
    dispatcher: BroadcastDispatcher,
    dispatcher: BroadcastDispatcher,
) : PowerRepository {
) : PowerRepository {


@@ -68,6 +75,14 @@ constructor(
        awaitClose { dispatcher.unregisterReceiver(receiver) }
        awaitClose { dispatcher.unregisterReceiver(receiver) }
    }
    }


    override fun wakeUp(why: String, wakeReason: Int) {
        manager.wakeUp(
            systemClock.uptimeMillis(),
            wakeReason,
            "${applicationContext.packageName}:$why",
        )
    }

    companion object {
    companion object {
        private const val TAG = "PowerRepository"
        private const val TAG = "PowerRepository"
    }
    }
+24 −1
Original line number Original line Diff line number Diff line
@@ -17,8 +17,12 @@


package com.android.systemui.power.domain.interactor
package com.android.systemui.power.domain.interactor


import android.os.PowerManager
import com.android.systemui.classifier.FalsingCollector
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.plugins.statusbar.StatusBarStateController
import com.android.systemui.power.data.repository.PowerRepository
import com.android.systemui.power.data.repository.PowerRepository
import com.android.systemui.statusbar.phone.ScreenOffAnimationController
import javax.inject.Inject
import javax.inject.Inject
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.Flow


@@ -27,8 +31,27 @@ import kotlinx.coroutines.flow.Flow
class PowerInteractor
class PowerInteractor
@Inject
@Inject
constructor(
constructor(
    repository: PowerRepository,
    private val repository: PowerRepository,
    private val falsingCollector: FalsingCollector,
    private val screenOffAnimationController: ScreenOffAnimationController,
    private val statusBarStateController: StatusBarStateController,
) {
) {
    /** Whether the screen is on or off. */
    /** Whether the screen is on or off. */
    val isInteractive: Flow<Boolean> = repository.isInteractive
    val isInteractive: Flow<Boolean> = repository.isInteractive

    /**
     * Wakes up the device if the device was dozing.
     *
     * @param why a string explaining why we're waking the device for debugging purposes. Should be
     *   in SCREAMING_SNAKE_CASE.
     * @param wakeReason the PowerManager-based reason why we're waking the device.
     */
    fun wakeUpIfDozing(why: String, @PowerManager.WakeReason wakeReason: Int) {
        if (
            statusBarStateController.isDozing && screenOffAnimationController.allowWakeUpIfDozing()
        ) {
            repository.wakeUp(why, wakeReason)
            falsingCollector.onScreenOnFromTouch()
        }
    }
}
}
+4 −13
Original line number Original line Diff line number Diff line
@@ -18,7 +18,6 @@ package com.android.systemui.shade


import android.hardware.display.AmbientDisplayConfiguration
import android.hardware.display.AmbientDisplayConfiguration
import android.os.PowerManager
import android.os.PowerManager
import android.os.SystemClock
import android.provider.Settings
import android.provider.Settings
import android.view.GestureDetector
import android.view.GestureDetector
import android.view.MotionEvent
import android.view.MotionEvent
@@ -28,8 +27,8 @@ import com.android.systemui.dump.DumpManager
import com.android.systemui.plugins.FalsingManager
import com.android.systemui.plugins.FalsingManager
import com.android.systemui.plugins.FalsingManager.LOW_PENALTY
import com.android.systemui.plugins.FalsingManager.LOW_PENALTY
import com.android.systemui.plugins.statusbar.StatusBarStateController
import com.android.systemui.plugins.statusbar.StatusBarStateController
import com.android.systemui.power.domain.interactor.PowerInteractor
import com.android.systemui.settings.UserTracker
import com.android.systemui.settings.UserTracker
import com.android.systemui.statusbar.phone.CentralSurfaces
import com.android.systemui.statusbar.phone.dagger.CentralSurfacesComponent
import com.android.systemui.statusbar.phone.dagger.CentralSurfacesComponent
import com.android.systemui.tuner.TunerService
import com.android.systemui.tuner.TunerService
import com.android.systemui.tuner.TunerService.Tunable
import com.android.systemui.tuner.TunerService.Tunable
@@ -50,7 +49,7 @@ class PulsingGestureListener @Inject constructor(
        private val notificationShadeWindowView: NotificationShadeWindowView,
        private val notificationShadeWindowView: NotificationShadeWindowView,
        private val falsingManager: FalsingManager,
        private val falsingManager: FalsingManager,
        private val dockManager: DockManager,
        private val dockManager: DockManager,
        private val centralSurfaces: CentralSurfaces,
        private val powerInteractor: PowerInteractor,
        private val ambientDisplayConfiguration: AmbientDisplayConfiguration,
        private val ambientDisplayConfiguration: AmbientDisplayConfiguration,
        private val statusBarStateController: StatusBarStateController,
        private val statusBarStateController: StatusBarStateController,
        private val shadeLogger: ShadeLogger,
        private val shadeLogger: ShadeLogger,
@@ -88,11 +87,7 @@ class PulsingGestureListener @Inject constructor(
            shadeLogger.logSingleTapUpFalsingState(proximityIsNotNear, isNotAFalseTap)
            shadeLogger.logSingleTapUpFalsingState(proximityIsNotNear, isNotAFalseTap)
            if (proximityIsNotNear && isNotAFalseTap) {
            if (proximityIsNotNear && isNotAFalseTap) {
                shadeLogger.d("Single tap handled, requesting centralSurfaces.wakeUpIfDozing")
                shadeLogger.d("Single tap handled, requesting centralSurfaces.wakeUpIfDozing")
                centralSurfaces.wakeUpIfDozing(
                powerInteractor.wakeUpIfDozing("PULSING_SINGLE_TAP", PowerManager.WAKE_REASON_TAP)
                    SystemClock.uptimeMillis(),
                    "PULSING_SINGLE_TAP",
                    PowerManager.WAKE_REASON_TAP
                )
            }
            }
            return true
            return true
        }
        }
@@ -113,11 +108,7 @@ class PulsingGestureListener @Inject constructor(
                !falsingManager.isProximityNear &&
                !falsingManager.isProximityNear &&
                !falsingManager.isFalseDoubleTap
                !falsingManager.isFalseDoubleTap
        ) {
        ) {
            centralSurfaces.wakeUpIfDozing(
            powerInteractor.wakeUpIfDozing("PULSING_DOUBLE_TAP", PowerManager.WAKE_REASON_TAP)
                    SystemClock.uptimeMillis(),
                    "PULSING_DOUBLE_TAP",
                    PowerManager.WAKE_REASON_TAP
            )
            return true
            return true
        }
        }
        return false
        return false
+4 −0
Original line number Original line Diff line number Diff line
@@ -43,6 +43,7 @@ import com.android.systemui.Dumpable;
import com.android.systemui.animation.ActivityLaunchAnimator;
import com.android.systemui.animation.ActivityLaunchAnimator;
import com.android.systemui.navigationbar.NavigationBarView;
import com.android.systemui.navigationbar.NavigationBarView;
import com.android.systemui.plugins.ActivityStarter.OnDismissAction;
import com.android.systemui.plugins.ActivityStarter.OnDismissAction;
import com.android.systemui.power.domain.interactor.PowerInteractor;
import com.android.systemui.qs.QSPanelController;
import com.android.systemui.qs.QSPanelController;
import com.android.systemui.shade.ShadeViewController;
import com.android.systemui.shade.ShadeViewController;
import com.android.systemui.shared.system.RemoteAnimationRunnerCompat;
import com.android.systemui.shared.system.RemoteAnimationRunnerCompat;
@@ -197,7 +198,10 @@ public interface CentralSurfaces extends Dumpable, LifecycleOwner {


    /**
    /**
     * Wakes up the device if the device was dozing.
     * Wakes up the device if the device was dozing.
     *
     * @deprecated Use {@link PowerInteractor#wakeUpIfDozing(String, int)} instead.
     */
     */
    @Deprecated
    void wakeUpIfDozing(long time, String why, @PowerManager.WakeReason int wakeReason);
    void wakeUpIfDozing(long time, String why, @PowerManager.WakeReason int wakeReason);


    /** */
    /** */
+4 −1
Original line number Original line Diff line number Diff line
@@ -136,6 +136,7 @@ import com.android.systemui.accessibility.floatingmenu.AccessibilityFloatingMenu
import com.android.systemui.animation.ActivityLaunchAnimator;
import com.android.systemui.animation.ActivityLaunchAnimator;
import com.android.systemui.assist.AssistManager;
import com.android.systemui.assist.AssistManager;
import com.android.systemui.biometrics.AuthRippleController;
import com.android.systemui.biometrics.AuthRippleController;
import com.android.systemui.bouncer.domain.interactor.AlternateBouncerInteractor;
import com.android.systemui.broadcast.BroadcastDispatcher;
import com.android.systemui.broadcast.BroadcastDispatcher;
import com.android.systemui.camera.CameraIntents;
import com.android.systemui.camera.CameraIntents;
import com.android.systemui.charging.WiredChargingRippleController;
import com.android.systemui.charging.WiredChargingRippleController;
@@ -157,7 +158,6 @@ import com.android.systemui.keyguard.KeyguardUnlockAnimationController;
import com.android.systemui.keyguard.KeyguardViewMediator;
import com.android.systemui.keyguard.KeyguardViewMediator;
import com.android.systemui.keyguard.ScreenLifecycle;
import com.android.systemui.keyguard.ScreenLifecycle;
import com.android.systemui.keyguard.WakefulnessLifecycle;
import com.android.systemui.keyguard.WakefulnessLifecycle;
import com.android.systemui.bouncer.domain.interactor.AlternateBouncerInteractor;
import com.android.systemui.keyguard.ui.binder.LightRevealScrimViewBinder;
import com.android.systemui.keyguard.ui.binder.LightRevealScrimViewBinder;
import com.android.systemui.keyguard.ui.viewmodel.LightRevealScrimViewModel;
import com.android.systemui.keyguard.ui.viewmodel.LightRevealScrimViewModel;
import com.android.systemui.navigationbar.NavigationBarController;
import com.android.systemui.navigationbar.NavigationBarController;
@@ -1587,10 +1587,13 @@ public class CentralSurfacesImpl implements CoreStartable, CentralSurfaces {
    /**
    /**
     * Ask the display to wake up if currently dozing, else do nothing
     * Ask the display to wake up if currently dozing, else do nothing
     *
     *
     * @deprecated Use {@link PowerInteractor#wakeUpIfDozing(String, int)} instead.
     *
     * @param time when to wake up
     * @param time when to wake up
     * @param why the reason for the wake up
     * @param why the reason for the wake up
     */
     */
    @Override
    @Override
    @Deprecated
    public void wakeUpIfDozing(long time, String why, @PowerManager.WakeReason int wakeReason) {
    public void wakeUpIfDozing(long time, String why, @PowerManager.WakeReason int wakeReason) {
        if (mDozing && mScreenOffAnimationController.allowWakeUpIfDozing()) {
        if (mDozing && mScreenOffAnimationController.allowWakeUpIfDozing()) {
            mPowerManager.wakeUp(
            mPowerManager.wakeUp(
Loading