Merge "Update SysUI to use new PowerManager WakeReasons" into tm-qpr-dev

This commit is contained in:
Beverly Tai
2022-12-22 17:52:22 +00:00
committed by Android (Google) Code Review
15 changed files with 126 additions and 33 deletions

View File

@@ -884,7 +884,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
Assert.isMainThread(); Assert.isMainThread();
if (mWakeOnFingerprintAcquiredStart && acquireInfo == FINGERPRINT_ACQUIRED_START) { if (mWakeOnFingerprintAcquiredStart && acquireInfo == FINGERPRINT_ACQUIRED_START) {
mPowerManager.wakeUp( mPowerManager.wakeUp(
SystemClock.uptimeMillis(), PowerManager.WAKE_REASON_GESTURE, SystemClock.uptimeMillis(), PowerManager.WAKE_REASON_BIOMETRIC,
"com.android.systemui.keyguard:FINGERPRINT_ACQUIRED_START"); "com.android.systemui.keyguard:FINGERPRINT_ACQUIRED_START");
} }
for (int i = 0; i < mCallbacks.size(); i++) { for (int i = 0; i < mCallbacks.size(); i++) {

View File

@@ -16,7 +16,14 @@
package com.android.systemui.doze; package com.android.systemui.doze;
import static android.os.PowerManager.WAKE_REASON_BIOMETRIC;
import static android.os.PowerManager.WAKE_REASON_GESTURE;
import static android.os.PowerManager.WAKE_REASON_LIFT;
import static android.os.PowerManager.WAKE_REASON_PLUGGED_IN;
import static android.os.PowerManager.WAKE_REASON_TAP;
import android.annotation.IntDef; import android.annotation.IntDef;
import android.os.PowerManager;
import android.util.TimeUtils; import android.util.TimeUtils;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
@@ -511,6 +518,25 @@ public class DozeLog implements Dumpable {
} }
} }
/**
* Converts {@link Reason} to {@link PowerManager.WakeReason}.
*/
public static @PowerManager.WakeReason int getPowerManagerWakeReason(@Reason int wakeReason) {
switch (wakeReason) {
case REASON_SENSOR_DOUBLE_TAP:
case REASON_SENSOR_TAP:
return WAKE_REASON_TAP;
case REASON_SENSOR_PICKUP:
return WAKE_REASON_LIFT;
case REASON_SENSOR_UDFPS_LONG_PRESS:
return WAKE_REASON_BIOMETRIC;
case PULSE_REASON_DOCKING:
return WAKE_REASON_PLUGGED_IN;
default:
return WAKE_REASON_GESTURE;
}
}
@Retention(RetentionPolicy.SOURCE) @Retention(RetentionPolicy.SOURCE)
@IntDef({PULSE_REASON_NONE, PULSE_REASON_INTENT, PULSE_REASON_NOTIFICATION, @IntDef({PULSE_REASON_NONE, PULSE_REASON_INTENT, PULSE_REASON_NOTIFICATION,
PULSE_REASON_SENSOR_SIGMOTION, REASON_SENSOR_PICKUP, REASON_SENSOR_DOUBLE_TAP, PULSE_REASON_SENSOR_SIGMOTION, REASON_SENSOR_PICKUP, REASON_SENSOR_DOUBLE_TAP,

View File

@@ -116,8 +116,8 @@ public class DozeService extends DreamService
@Override @Override
public void requestWakeUp(@DozeLog.Reason int reason) { public void requestWakeUp(@DozeLog.Reason int reason) {
PowerManager pm = getSystemService(PowerManager.class); final PowerManager pm = getSystemService(PowerManager.class);
pm.wakeUp(SystemClock.uptimeMillis(), PowerManager.WAKE_REASON_GESTURE, pm.wakeUp(SystemClock.uptimeMillis(), DozeLog.getPowerManagerWakeReason(reason),
"com.android.systemui:NODOZE " + DozeLog.reasonToString(reason)); "com.android.systemui:NODOZE " + DozeLog.reasonToString(reason));
} }

View File

@@ -19,6 +19,7 @@ package com.android.systemui.shade;
import android.app.StatusBarManager; import android.app.StatusBarManager;
import android.media.AudioManager; import android.media.AudioManager;
import android.media.session.MediaSessionLegacyHelper; import android.media.session.MediaSessionLegacyHelper;
import android.os.PowerManager;
import android.os.SystemClock; import android.os.SystemClock;
import android.util.Log; import android.util.Log;
import android.view.GestureDetector; import android.view.GestureDetector;
@@ -238,7 +239,9 @@ public class NotificationShadeWindowViewController {
() -> mService.wakeUpIfDozing( () -> mService.wakeUpIfDozing(
SystemClock.uptimeMillis(), SystemClock.uptimeMillis(),
mView, mView,
"LOCK_ICON_TOUCH")); "LOCK_ICON_TOUCH",
PowerManager.WAKE_REASON_GESTURE)
);
// In case we start outside of the view bounds (below the status bar), we need to // In case we start outside of the view bounds (below the status bar), we need to
// dispatch // dispatch

View File

@@ -17,6 +17,7 @@
package com.android.systemui.shade package com.android.systemui.shade
import android.hardware.display.AmbientDisplayConfiguration import android.hardware.display.AmbientDisplayConfiguration
import android.os.PowerManager
import android.os.SystemClock import android.os.SystemClock
import android.os.UserHandle import android.os.UserHandle
import android.provider.Settings import android.provider.Settings
@@ -89,7 +90,8 @@ class PulsingGestureListener @Inject constructor(
centralSurfaces.wakeUpIfDozing( centralSurfaces.wakeUpIfDozing(
SystemClock.uptimeMillis(), SystemClock.uptimeMillis(),
notificationShadeWindowView, notificationShadeWindowView,
"PULSING_SINGLE_TAP" "PULSING_SINGLE_TAP",
PowerManager.WAKE_REASON_TAP
) )
} }
return true return true
@@ -114,7 +116,9 @@ class PulsingGestureListener @Inject constructor(
centralSurfaces.wakeUpIfDozing( centralSurfaces.wakeUpIfDozing(
SystemClock.uptimeMillis(), SystemClock.uptimeMillis(),
notificationShadeWindowView, notificationShadeWindowView,
"PULSING_DOUBLE_TAP") "PULSING_DOUBLE_TAP",
PowerManager.WAKE_REASON_TAP
)
return true return true
} }
return false return false

View File

@@ -5,6 +5,7 @@ import android.animation.AnimatorListenerAdapter
import android.animation.ValueAnimator import android.animation.ValueAnimator
import android.content.Context import android.content.Context
import android.content.res.Configuration import android.content.res.Configuration
import android.os.PowerManager
import android.os.SystemClock import android.os.SystemClock
import android.util.IndentingPrintWriter import android.util.IndentingPrintWriter
import android.util.MathUtils import android.util.MathUtils
@@ -272,7 +273,12 @@ class LockscreenShadeTransitionController @Inject constructor(
// Bind the click listener of the shelf to go to the full shade // Bind the click listener of the shelf to go to the full shade
notificationShelfController.setOnClickListener { notificationShelfController.setOnClickListener {
if (statusBarStateController.state == StatusBarState.KEYGUARD) { if (statusBarStateController.state == StatusBarState.KEYGUARD) {
centralSurfaces.wakeUpIfDozing(SystemClock.uptimeMillis(), it, "SHADE_CLICK") centralSurfaces.wakeUpIfDozing(
SystemClock.uptimeMillis(),
it,
"SHADE_CLICK",
PowerManager.WAKE_REASON_GESTURE,
)
goToLockedShade(it) goToLockedShade(it)
} }
} }

View File

@@ -24,6 +24,7 @@ import android.app.RemoteInput;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.pm.UserInfo; import android.content.pm.UserInfo;
import android.os.PowerManager;
import android.os.RemoteException; import android.os.RemoteException;
import android.os.ServiceManager; import android.os.ServiceManager;
import android.os.SystemClock; import android.os.SystemClock;
@@ -64,6 +65,8 @@ import com.android.systemui.statusbar.policy.RemoteInputView;
import com.android.systemui.util.DumpUtilsKt; import com.android.systemui.util.DumpUtilsKt;
import com.android.systemui.util.ListenerSet; import com.android.systemui.util.ListenerSet;
import dagger.Lazy;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@@ -71,8 +74,6 @@ import java.util.Objects;
import java.util.Optional; import java.util.Optional;
import java.util.function.Consumer; import java.util.function.Consumer;
import dagger.Lazy;
/** /**
* Class for handling remote input state over a set of notifications. This class handles things * Class for handling remote input state over a set of notifications. This class handles things
* like keeping notifications temporarily that were cancelled as a response to a remote input * like keeping notifications temporarily that were cancelled as a response to a remote input
@@ -120,7 +121,8 @@ public class NotificationRemoteInputManager implements Dumpable {
View view, PendingIntent pendingIntent, RemoteViews.RemoteResponse response) { View view, PendingIntent pendingIntent, RemoteViews.RemoteResponse response) {
mCentralSurfacesOptionalLazy.get().ifPresent( mCentralSurfacesOptionalLazy.get().ifPresent(
centralSurfaces -> centralSurfaces.wakeUpIfDozing( centralSurfaces -> centralSurfaces.wakeUpIfDozing(
SystemClock.uptimeMillis(), view, "NOTIFICATION_CLICK")); SystemClock.uptimeMillis(), view, "NOTIFICATION_CLICK",
PowerManager.WAKE_REASON_GESTURE));
final NotificationEntry entry = getNotificationForParent(view.getParent()); final NotificationEntry entry = getNotificationForParent(view.getParent());
mLogger.logInitialClick(entry, pendingIntent); mLogger.logInitialClick(entry, pendingIntent);

View File

@@ -22,7 +22,6 @@ import android.animation.ValueAnimator
import android.content.Context import android.content.Context
import android.content.res.Configuration import android.content.res.Configuration
import android.os.PowerManager import android.os.PowerManager
import android.os.PowerManager.WAKE_REASON_GESTURE
import android.os.SystemClock import android.os.SystemClock
import android.util.IndentingPrintWriter import android.util.IndentingPrintWriter
import android.view.MotionEvent import android.view.MotionEvent
@@ -249,7 +248,7 @@ constructor(
} }
if (statusBarStateController.isDozing) { if (statusBarStateController.isDozing) {
wakeUpCoordinator.willWakeUp = true wakeUpCoordinator.willWakeUp = true
mPowerManager!!.wakeUp(SystemClock.uptimeMillis(), WAKE_REASON_GESTURE, mPowerManager!!.wakeUp(SystemClock.uptimeMillis(), PowerManager.WAKE_REASON_GESTURE,
"com.android.systemui:PULSEDRAG") "com.android.systemui:PULSEDRAG")
} }
lockscreenShadeTransitionController.goToLockedShade(startingChild, lockscreenShadeTransitionController.goToLockedShade(startingChild,

View File

@@ -16,6 +16,7 @@
package com.android.systemui.statusbar.notification; package com.android.systemui.statusbar.notification;
import android.app.Notification; import android.app.Notification;
import android.os.PowerManager;
import android.os.SystemClock; import android.os.SystemClock;
import android.service.notification.StatusBarNotification; import android.service.notification.StatusBarNotification;
import android.util.Log; import android.util.Log;
@@ -70,7 +71,8 @@ public final class NotificationClicker implements View.OnClickListener {
} }
mCentralSurfacesOptional.ifPresent(centralSurfaces -> centralSurfaces.wakeUpIfDozing( mCentralSurfacesOptional.ifPresent(centralSurfaces -> centralSurfaces.wakeUpIfDozing(
SystemClock.uptimeMillis(), v, "NOTIFICATION_CLICK")); SystemClock.uptimeMillis(), v, "NOTIFICATION_CLICK",
PowerManager.WAKE_REASON_GESTURE));
final ExpandableNotificationRow row = (ExpandableNotificationRow) v; final ExpandableNotificationRow row = (ExpandableNotificationRow) v;
final NotificationEntry entry = row.getEntry(); final NotificationEntry entry = row.getEntry();

View File

@@ -429,7 +429,7 @@ public class BiometricUnlockController extends KeyguardUpdateMonitorCallback imp
Runnable wakeUp = ()-> { Runnable wakeUp = ()-> {
if (!wasDeviceInteractive || mUpdateMonitor.isDreaming()) { if (!wasDeviceInteractive || mUpdateMonitor.isDreaming()) {
mLogger.i("bio wakelock: Authenticated, waking up..."); mLogger.i("bio wakelock: Authenticated, waking up...");
mPowerManager.wakeUp(SystemClock.uptimeMillis(), PowerManager.WAKE_REASON_GESTURE, mPowerManager.wakeUp(SystemClock.uptimeMillis(), PowerManager.WAKE_REASON_BIOMETRIC,
"android.policy:BIOMETRIC"); "android.policy:BIOMETRIC");
} }
Trace.beginSection("release wake-and-unlock"); Trace.beginSection("release wake-and-unlock");

View File

@@ -25,6 +25,7 @@ import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.os.Bundle; import android.os.Bundle;
import android.os.PowerManager;
import android.os.UserHandle; import android.os.UserHandle;
import android.service.notification.StatusBarNotification; import android.service.notification.StatusBarNotification;
import android.view.KeyEvent; import android.view.KeyEvent;
@@ -203,7 +204,10 @@ public interface CentralSurfaces extends Dumpable, ActivityStarter, LifecycleOwn
@Override @Override
Lifecycle getLifecycle(); Lifecycle getLifecycle();
void wakeUpIfDozing(long time, View where, String why); /**
* Wakes up the device if the device was dozing.
*/
void wakeUpIfDozing(long time, View where, String why, @PowerManager.WakeReason int wakeReason);
NotificationShadeWindowView getNotificationShadeWindowView(); NotificationShadeWindowView getNotificationShadeWindowView();

View File

@@ -899,8 +899,6 @@ public class CentralSurfacesImpl implements CoreStartable, CentralSurfaces {
mKeyguardIndicationController.init(); mKeyguardIndicationController.init();
mColorExtractor.addOnColorsChangedListener(mOnColorsChangedListener); mColorExtractor.addOnColorsChangedListener(mOnColorsChangedListener);
mStatusBarStateController.addCallback(mStateListener,
SysuiStatusBarStateController.RANK_STATUS_BAR);
mWindowManager = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE); mWindowManager = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
@@ -1519,10 +1517,11 @@ public class CentralSurfacesImpl implements CoreStartable, CentralSurfaces {
* @param why the reason for the wake up * @param why the reason for the wake up
*/ */
@Override @Override
public void wakeUpIfDozing(long time, View where, String why) { public void wakeUpIfDozing(long time, View where, String why,
@PowerManager.WakeReason int wakeReason) {
if (mDozing && mScreenOffAnimationController.allowWakeUpIfDozing()) { if (mDozing && mScreenOffAnimationController.allowWakeUpIfDozing()) {
mPowerManager.wakeUp( mPowerManager.wakeUp(
time, PowerManager.WAKE_REASON_GESTURE, "com.android.systemui:" + why); time, wakeReason, "com.android.systemui:" + why);
mWakeUpComingFromTouch = true; mWakeUpComingFromTouch = true;
mFalsingCollector.onScreenOnFromTouch(); mFalsingCollector.onScreenOnFromTouch();
} }
@@ -1599,6 +1598,8 @@ public class CentralSurfacesImpl implements CoreStartable, CentralSurfaces {
protected void startKeyguard() { protected void startKeyguard() {
Trace.beginSection("CentralSurfaces#startKeyguard"); Trace.beginSection("CentralSurfaces#startKeyguard");
mStatusBarStateController.addCallback(mStateListener,
SysuiStatusBarStateController.RANK_STATUS_BAR);
mBiometricUnlockController = mBiometricUnlockControllerLazy.get(); mBiometricUnlockController = mBiometricUnlockControllerLazy.get();
mBiometricUnlockController.addBiometricModeListener( mBiometricUnlockController.addBiometricModeListener(
new BiometricUnlockController.BiometricModeListener() { new BiometricUnlockController.BiometricModeListener() {
@@ -3379,7 +3380,8 @@ public class CentralSurfacesImpl implements CoreStartable, CentralSurfaces {
mStatusBarHideIconsForBouncerManager.setBouncerShowingAndTriggerUpdate(bouncerShowing); mStatusBarHideIconsForBouncerManager.setBouncerShowingAndTriggerUpdate(bouncerShowing);
mCommandQueue.recomputeDisableFlags(mDisplayId, true /* animate */); mCommandQueue.recomputeDisableFlags(mDisplayId, true /* animate */);
if (mBouncerShowing) { if (mBouncerShowing) {
wakeUpIfDozing(SystemClock.uptimeMillis(), null, "BOUNCER_VISIBLE"); wakeUpIfDozing(SystemClock.uptimeMillis(), null, "BOUNCER_VISIBLE",
PowerManager.WAKE_REASON_GESTURE);
} }
updateScrimController(); updateScrimController();
if (!mBouncerShowing) { if (!mBouncerShowing) {

View File

@@ -20,6 +20,7 @@ import static com.android.systemui.statusbar.phone.CentralSurfaces.MULTIUSER_DEB
import android.app.KeyguardManager; import android.app.KeyguardManager;
import android.content.Context; import android.content.Context;
import android.os.PowerManager;
import android.os.RemoteException; import android.os.RemoteException;
import android.os.ServiceManager; import android.os.ServiceManager;
import android.os.SystemClock; import android.os.SystemClock;
@@ -270,7 +271,8 @@ class StatusBarNotificationPresenter implements NotificationPresenter,
boolean nowExpanded) { boolean nowExpanded) {
mHeadsUpManager.setExpanded(clickedEntry, nowExpanded); mHeadsUpManager.setExpanded(clickedEntry, nowExpanded);
mCentralSurfaces.wakeUpIfDozing( mCentralSurfaces.wakeUpIfDozing(
SystemClock.uptimeMillis(), clickedView, "NOTIFICATION_CLICK"); SystemClock.uptimeMillis(), clickedView, "NOTIFICATION_CLICK",
PowerManager.WAKE_REASON_GESTURE);
if (nowExpanded) { if (nowExpanded) {
if (mStatusBarStateController.getState() == StatusBarState.KEYGUARD) { if (mStatusBarStateController.getState() == StatusBarState.KEYGUARD) {
mShadeTransitionController.goToLockedShade(clickedEntry.getRow()); mShadeTransitionController.goToLockedShade(clickedEntry.getRow());

View File

@@ -21,6 +21,7 @@ import android.provider.Settings.Secure.DOZE_DOUBLE_TAP_GESTURE
import android.provider.Settings.Secure.DOZE_TAP_SCREEN_GESTURE import android.provider.Settings.Secure.DOZE_TAP_SCREEN_GESTURE
import android.testing.AndroidTestingRunner import android.testing.AndroidTestingRunner
import android.testing.TestableLooper.RunWithLooper import android.testing.TestableLooper.RunWithLooper
import android.os.PowerManager
import android.view.MotionEvent import android.view.MotionEvent
import androidx.test.filters.SmallTest import androidx.test.filters.SmallTest
import com.android.systemui.SysuiTestCase import com.android.systemui.SysuiTestCase
@@ -36,9 +37,9 @@ import org.junit.Before
import org.junit.Test import org.junit.Test
import org.junit.runner.RunWith import org.junit.runner.RunWith
import org.mockito.ArgumentCaptor import org.mockito.ArgumentCaptor
import org.mockito.ArgumentMatchers.any
import org.mockito.ArgumentMatchers.anyInt import org.mockito.ArgumentMatchers.anyInt
import org.mockito.ArgumentMatchers.anyLong import org.mockito.ArgumentMatchers.anyLong
import org.mockito.ArgumentMatchers.anyObject
import org.mockito.ArgumentMatchers.anyString import org.mockito.ArgumentMatchers.anyString
import org.mockito.Mock import org.mockito.Mock
import org.mockito.Mockito.never import org.mockito.Mockito.never
@@ -106,7 +107,8 @@ class PulsingGestureListenerTest : SysuiTestCase() {
underTest.onSingleTapUp(upEv) underTest.onSingleTapUp(upEv)
// THEN wake up device if dozing // THEN wake up device if dozing
verify(centralSurfaces).wakeUpIfDozing(anyLong(), anyObject(), anyString()) verify(centralSurfaces).wakeUpIfDozing(
anyLong(), any(), anyString(), eq(PowerManager.WAKE_REASON_TAP))
} }
@Test @Test
@@ -125,7 +127,8 @@ class PulsingGestureListenerTest : SysuiTestCase() {
underTest.onDoubleTapEvent(upEv) underTest.onDoubleTapEvent(upEv)
// THEN wake up device if dozing // THEN wake up device if dozing
verify(centralSurfaces).wakeUpIfDozing(anyLong(), anyObject(), anyString()) verify(centralSurfaces).wakeUpIfDozing(
anyLong(), any(), anyString(), eq(PowerManager.WAKE_REASON_TAP))
} }
@Test @Test
@@ -156,7 +159,8 @@ class PulsingGestureListenerTest : SysuiTestCase() {
underTest.onSingleTapUp(upEv) underTest.onSingleTapUp(upEv)
// THEN the device doesn't wake up // THEN the device doesn't wake up
verify(centralSurfaces, never()).wakeUpIfDozing(anyLong(), anyObject(), anyString()) verify(centralSurfaces, never()).wakeUpIfDozing(
anyLong(), any(), anyString(), anyInt())
} }
@Test @Test
@@ -203,7 +207,8 @@ class PulsingGestureListenerTest : SysuiTestCase() {
underTest.onDoubleTapEvent(upEv) underTest.onDoubleTapEvent(upEv)
// THEN the device doesn't wake up // THEN the device doesn't wake up
verify(centralSurfaces, never()).wakeUpIfDozing(anyLong(), anyObject(), anyString()) verify(centralSurfaces, never()).wakeUpIfDozing(
anyLong(), any(), anyString(), anyInt())
} }
@Test @Test
@@ -222,7 +227,8 @@ class PulsingGestureListenerTest : SysuiTestCase() {
underTest.onSingleTapUp(upEv) underTest.onSingleTapUp(upEv)
// THEN the device doesn't wake up // THEN the device doesn't wake up
verify(centralSurfaces, never()).wakeUpIfDozing(anyLong(), anyObject(), anyString()) verify(centralSurfaces, never()).wakeUpIfDozing(
anyLong(), any(), anyString(), anyInt())
} }
@Test @Test
@@ -241,7 +247,8 @@ class PulsingGestureListenerTest : SysuiTestCase() {
underTest.onDoubleTapEvent(upEv) underTest.onDoubleTapEvent(upEv)
// THEN the device doesn't wake up // THEN the device doesn't wake up
verify(centralSurfaces, never()).wakeUpIfDozing(anyLong(), anyObject(), anyString()) verify(centralSurfaces, never()).wakeUpIfDozing(
anyLong(), any(), anyString(), anyInt())
} }
fun updateSettings() { fun updateSettings() {

View File

@@ -31,6 +31,7 @@ import static junit.framework.TestCase.fail;
import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq; import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.clearInvocations; import static org.mockito.Mockito.clearInvocations;
@@ -176,6 +177,8 @@ import com.android.systemui.volume.VolumeComponent;
import com.android.wm.shell.bubbles.Bubbles; import com.android.wm.shell.bubbles.Bubbles;
import com.android.wm.shell.startingsurface.StartingSurface; import com.android.wm.shell.startingsurface.StartingSurface;
import dagger.Lazy;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
@@ -188,8 +191,6 @@ import java.io.ByteArrayOutputStream;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.util.Optional; import java.util.Optional;
import dagger.Lazy;
@SmallTest @SmallTest
@RunWith(AndroidTestingRunner.class) @RunWith(AndroidTestingRunner.class)
@RunWithLooper(setAsMainLooper = true) @RunWithLooper(setAsMainLooper = true)
@@ -304,6 +305,7 @@ public class CentralSurfacesImplTest extends SysuiTestCase {
@Mock private ViewRootImpl mViewRootImpl; @Mock private ViewRootImpl mViewRootImpl;
@Mock private WindowOnBackInvokedDispatcher mOnBackInvokedDispatcher; @Mock private WindowOnBackInvokedDispatcher mOnBackInvokedDispatcher;
@Captor private ArgumentCaptor<OnBackInvokedCallback> mOnBackInvokedCallback; @Captor private ArgumentCaptor<OnBackInvokedCallback> mOnBackInvokedCallback;
@Mock IPowerManager mPowerManagerService;
private ShadeController mShadeController; private ShadeController mShadeController;
private final FakeSystemClock mFakeSystemClock = new FakeSystemClock(); private final FakeSystemClock mFakeSystemClock = new FakeSystemClock();
@@ -317,9 +319,8 @@ public class CentralSurfacesImplTest extends SysuiTestCase {
public void setup() throws Exception { public void setup() throws Exception {
MockitoAnnotations.initMocks(this); MockitoAnnotations.initMocks(this);
IPowerManager powerManagerService = mock(IPowerManager.class);
IThermalService thermalService = mock(IThermalService.class); IThermalService thermalService = mock(IThermalService.class);
mPowerManager = new PowerManager(mContext, powerManagerService, thermalService, mPowerManager = new PowerManager(mContext, mPowerManagerService, thermalService,
Handler.createAsync(Looper.myLooper())); Handler.createAsync(Looper.myLooper()));
mNotificationInterruptStateProvider = mNotificationInterruptStateProvider =
@@ -361,7 +362,7 @@ public class CentralSurfacesImplTest extends SysuiTestCase {
when(mStackScrollerController.getView()).thenReturn(mStackScroller); when(mStackScrollerController.getView()).thenReturn(mStackScroller);
when(mStackScroller.generateLayoutParams(any())).thenReturn(new LayoutParams(0, 0)); when(mStackScroller.generateLayoutParams(any())).thenReturn(new LayoutParams(0, 0));
when(mNotificationPanelView.getLayoutParams()).thenReturn(new LayoutParams(0, 0)); when(mNotificationPanelView.getLayoutParams()).thenReturn(new LayoutParams(0, 0));
when(powerManagerService.isInteractive()).thenReturn(true); when(mPowerManagerService.isInteractive()).thenReturn(true);
when(mStackScroller.getActivatedChild()).thenReturn(null); when(mStackScroller.getActivatedChild()).thenReturn(null);
doAnswer(invocation -> { doAnswer(invocation -> {
@@ -1186,6 +1187,34 @@ public class CentralSurfacesImplTest extends SysuiTestCase {
verify(mStatusBarStateController).setState(SHADE); verify(mStatusBarStateController).setState(SHADE);
} }
@Test
public void dozing_wakeUp() throws RemoteException {
// GIVEN can wakeup when dozing & is dozing
when(mScreenOffAnimationController.allowWakeUpIfDozing()).thenReturn(true);
setDozing(true);
// WHEN wakeup is requested
final int wakeReason = PowerManager.WAKE_REASON_TAP;
mCentralSurfaces.wakeUpIfDozing(0, null, "", wakeReason);
// THEN power manager receives wakeup
verify(mPowerManagerService).wakeUp(eq(0L), eq(wakeReason), anyString(), anyString());
}
@Test
public void notDozing_noWakeUp() throws RemoteException {
// GIVEN can wakeup when dozing and NOT dozing
when(mScreenOffAnimationController.allowWakeUpIfDozing()).thenReturn(true);
setDozing(false);
// WHEN wakeup is requested
final int wakeReason = PowerManager.WAKE_REASON_TAP;
mCentralSurfaces.wakeUpIfDozing(0, null, "", wakeReason);
// THEN power manager receives wakeup
verify(mPowerManagerService, never()).wakeUp(anyLong(), anyInt(), anyString(), anyString());
}
/** /**
* Configures the appropriate mocks and then calls {@link CentralSurfacesImpl#updateIsKeyguard} * Configures the appropriate mocks and then calls {@link CentralSurfacesImpl#updateIsKeyguard}
* to reconfigure the keyguard to reflect the requested showing/occluded states. * to reconfigure the keyguard to reflect the requested showing/occluded states.
@@ -1222,6 +1251,13 @@ public class CentralSurfacesImplTest extends SysuiTestCase {
states); states);
} }
private void setDozing(boolean isDozing) {
ArgumentCaptor<StatusBarStateController.StateListener> callbackCaptor =
ArgumentCaptor.forClass(StatusBarStateController.StateListener.class);
verify(mStatusBarStateController).addCallback(callbackCaptor.capture(), anyInt());
callbackCaptor.getValue().onDozingChanged(isDozing);
}
public static class TestableNotificationInterruptStateProviderImpl extends public static class TestableNotificationInterruptStateProviderImpl extends
NotificationInterruptStateProviderImpl { NotificationInterruptStateProviderImpl {