Merge "Wake up wallpaper even if there's a notification"

This commit is contained in:
Lucas Dupin
2019-03-28 19:57:51 +00:00
committed by Android (Google) Code Review
13 changed files with 85 additions and 81 deletions

View File

@@ -87,7 +87,8 @@ public class DozeDockHandler implements DozeMachine.Part {
}
private void requestPulseOutNow(State dozeState) {
if (dozeState == State.DOZE_REQUEST_PULSE || dozeState == State.DOZE_PULSING) {
if (dozeState == State.DOZE_REQUEST_PULSE || dozeState == State.DOZE_PULSING
|| dozeState == State.DOZE_PULSING_BRIGHT) {
final int pulseReason = mMachine.getPulseReason();
if (pulseReason == DozeLog.PULSE_REASON_DOCKING) {
mDozeHost.stopPulsing();

View File

@@ -71,7 +71,7 @@ public class DozeFactory {
new DozeScreenState(wrappedService, handler, params, wakeLock),
createDozeScreenBrightness(context, wrappedService, sensorManager, host, params,
handler),
new DozeWallpaperState(context, machine),
new DozeWallpaperState(context),
new DozeDockHandler(context, machine, host, config, handler, dockManager)
});

View File

@@ -33,7 +33,11 @@ public interface DozeHost {
boolean isProvisioned();
boolean isBlockingDoze();
void extendPulse();
/**
* Makes a current pulse last for twice as long.
* @param reason why we're extending it.
*/
void extendPulse(int reason);
void setAnimateWakeup(boolean animateWakeup);
void setAnimateScreenOff(boolean animateScreenOff);

View File

@@ -59,6 +59,8 @@ public class DozeMachine {
DOZE_REQUEST_PULSE,
/** Pulse is showing. Device is awake and showing UI. */
DOZE_PULSING,
/** Pulse is showing with bright wallpaper. Device is awake and showing UI. */
DOZE_PULSING_BRIGHT,
/** Pulse is done showing. Followed by transition to DOZE or DOZE_AOD. */
DOZE_PULSE_DONE,
/** Doze is done. DozeService is finished. */
@@ -84,6 +86,7 @@ public class DozeMachine {
switch (this) {
case DOZE_REQUEST_PULSE:
case DOZE_PULSING:
case DOZE_PULSING_BRIGHT:
return true;
default:
return false;
@@ -101,6 +104,7 @@ public class DozeMachine {
case DOZE:
return Display.STATE_OFF;
case DOZE_PULSING:
case DOZE_PULSING_BRIGHT:
return Display.STATE_ON;
case DOZE_AOD:
case DOZE_AOD_PAUSING:
@@ -202,6 +206,7 @@ public class DozeMachine {
Assert.isMainThread();
Preconditions.checkState(mState == State.DOZE_REQUEST_PULSE
|| mState == State.DOZE_PULSING
|| mState == State.DOZE_PULSING_BRIGHT
|| mState == State.DOZE_PULSE_DONE, "must be in pulsing state, but is " + mState);
return mPulseReason;
}
@@ -283,7 +288,8 @@ public class DozeMachine {
break;
case DOZE_PULSE_DONE:
Preconditions.checkState(
mState == State.DOZE_REQUEST_PULSE || mState == State.DOZE_PULSING);
mState == State.DOZE_REQUEST_PULSE || mState == State.DOZE_PULSING
|| mState == State.DOZE_PULSING_BRIGHT);
break;
default:
break;

View File

@@ -168,7 +168,7 @@ public class DozeTriggers implements DozeMachine.Part {
} else if (isPickup) {
gentleWakeUp(pulseReason);
} else {
mDozeHost.extendPulse();
mDozeHost.extendPulse(pulseReason);
}
}, sensorPerformedProxCheck
|| (mDockManager != null && mDockManager.isDocked()), pulseReason);
@@ -212,7 +212,8 @@ public class DozeTriggers implements DozeMachine.Part {
final boolean pausing = (state == DozeMachine.State.DOZE_AOD_PAUSING);
final boolean aod = (state == DozeMachine.State.DOZE_AOD);
if (state == DozeMachine.State.DOZE_PULSING) {
if (state == DozeMachine.State.DOZE_PULSING
|| state == DozeMachine.State.DOZE_PULSING_BRIGHT) {
boolean ignoreTouch = near;
if (DEBUG) Log.i(TAG, "Prox changed, ignore touch = " + ignoreTouch);
mDozeHost.onIgnoreTouchWhilePulsing(ignoreTouch);
@@ -276,6 +277,7 @@ public class DozeTriggers implements DozeMachine.Part {
mDozeSensors.setListening(false);
break;
case DOZE_PULSING:
case DOZE_PULSING_BRIGHT:
mDozeSensors.setTouchscreenSensorsListening(false);
mDozeSensors.setProxListening(true);
break;
@@ -306,7 +308,16 @@ public class DozeTriggers implements DozeMachine.Part {
private void requestPulse(final int reason, boolean performedProxCheck) {
Assert.isMainThread();
mDozeHost.extendPulse();
mDozeHost.extendPulse(reason);
// When already pulsing we're allowed to show the wallpaper directly without
// requesting a new pulse.
if (mMachine.getState() == DozeMachine.State.DOZE_PULSING
&& reason == DozeLog.PULSE_REASON_SENSOR_WAKE_LOCK_SCREEN) {
mMachine.requestState(DozeMachine.State.DOZE_PULSING_BRIGHT);
return;
}
if (mPulsePending || !mAllowPulseTriggers || !canPulse()) {
if (mAllowPulseTriggers) {
DozeLog.tracePulseDropped(mContext, mPulsePending, mMachine.getState(),

View File

@@ -94,7 +94,10 @@ public class DozeUi implements DozeMachine.Part {
@Override
public void onPulseStarted() {
try {
mMachine.requestState(DozeMachine.State.DOZE_PULSING);
mMachine.requestState(
reason == DozeLog.PULSE_REASON_SENSOR_WAKE_LOCK_SCREEN
? DozeMachine.State.DOZE_PULSING_BRIGHT
: DozeMachine.State.DOZE_PULSING);
} catch (IllegalStateException e) {
// It's possible that the pulse was asynchronously cancelled while
// we were waiting for it to start (under stress conditions.)
@@ -148,6 +151,7 @@ public class DozeUi implements DozeMachine.Part {
switch (state) {
case DOZE_REQUEST_PULSE:
case DOZE_PULSING:
case DOZE_PULSING_BRIGHT:
case DOZE_PULSE_DONE:
mHost.setAnimateWakeup(true);
break;

View File

@@ -38,19 +38,17 @@ public class DozeWallpaperState implements DozeMachine.Part {
private final IWallpaperManager mWallpaperManagerService;
private final DozeParameters mDozeParameters;
private final DozeMachine mMachine;
private boolean mIsAmbientMode;
public DozeWallpaperState(Context context, DozeMachine machine) {
this(machine, IWallpaperManager.Stub.asInterface(
public DozeWallpaperState(Context context) {
this(IWallpaperManager.Stub.asInterface(
ServiceManager.getService(Context.WALLPAPER_SERVICE)),
DozeParameters.getInstance(context));
}
@VisibleForTesting
DozeWallpaperState(DozeMachine machine, IWallpaperManager wallpaperManagerService,
DozeWallpaperState(IWallpaperManager wallpaperManagerService,
DozeParameters parameters) {
mMachine = machine;
mWallpaperManagerService = wallpaperManagerService;
mDozeParameters = parameters;
}
@@ -65,16 +63,13 @@ public class DozeWallpaperState implements DozeMachine.Part {
case DOZE_AOD_PAUSED:
case DOZE_REQUEST_PULSE:
case DOZE_PULSE_DONE:
case DOZE_PULSING:
isAmbientMode = true;
break;
case DOZE_PULSING:
isAmbientMode =
mMachine.getPulseReason() != DozeLog.PULSE_REASON_SENSOR_WAKE_LOCK_SCREEN;
break;
case DOZE_PULSING_BRIGHT:
default:
isAmbientMode = false;
}
final boolean animated;
if (isAmbientMode) {
animated = mDozeParameters.shouldControlScreenOff();

View File

@@ -92,7 +92,7 @@ public class ScrimController implements ViewTreeObserver.OnPreDrawListener, OnCo
/**
* Scrim opacity when the phone is about to wake-up.
*/
public static final float AOD2_SCRIM_ALPHA = 0.6f;
public static final float WAKE_SENSOR_SCRIM_ALPHA = 0.6f;
/**
* A scrim varies its opacity based on a busyness factor, for example
* how many notifications are currently visible.
@@ -458,6 +458,23 @@ public class ScrimController implements ViewTreeObserver.OnPreDrawListener, OnCo
mState.AOD.setAodFrontScrimAlpha(alpha);
}
/**
* If the lock screen sensor is active.
*/
public void setWakeLockScreenSensorActive(boolean active) {
for (ScrimState state : ScrimState.values()) {
state.setWakeLockScreenSensorActive(active);
}
if (mState == ScrimState.PULSING) {
float newBehindAlpha = mState.getBehindAlpha();
if (mCurrentBehindAlpha != newBehindAlpha) {
mCurrentBehindAlpha = newBehindAlpha;
updateScrims();
}
}
}
protected void scheduleUpdate() {
if (mUpdatePending) return;
@@ -904,10 +921,6 @@ public class ScrimController implements ViewTreeObserver.OnPreDrawListener, OnCo
}
}
public void setPulseReason(int pulseReason) {
ScrimState.PULSING.setPulseReason(pulseReason);
}
public interface Callback {
default void onStart() {
}

View File

@@ -19,7 +19,6 @@ package com.android.systemui.statusbar.phone;
import android.graphics.Color;
import android.os.Trace;
import com.android.systemui.doze.DozeLog;
import com.android.systemui.statusbar.ScrimView;
import com.android.systemui.statusbar.notification.stack.StackStateAnimator;
@@ -129,16 +128,15 @@ public enum ScrimState {
@Override
public void prepare(ScrimState previousState) {
mCurrentInFrontAlpha = 0f;
if (mPulseReason == DozeLog.PULSE_REASON_NOTIFICATION
|| mPulseReason == DozeLog.PULSE_REASON_DOCKING
|| mPulseReason == DozeLog.PULSE_REASON_INTENT) {
mCurrentBehindAlpha = previousState.getBehindAlpha();
} else {
mCurrentBehindAlpha = ScrimController.AOD2_SCRIM_ALPHA;
}
mCurrentBehindTint = Color.BLACK;
mBlankScreen = mDisplayRequiresBlanking;
}
@Override
public float getBehindAlpha() {
return mWakeLockScreenSensorActive ? ScrimController.WAKE_SENSOR_SCRIM_ALPHA
: AOD.getBehindAlpha();
}
},
/**
@@ -199,7 +197,7 @@ public enum ScrimState {
int mIndex;
boolean mHasBackdrop;
boolean mLaunchingAffordanceWithPreview;
int mPulseReason;
boolean mWakeLockScreenSensorActive;
ScrimState(int index) {
mIndex = index;
@@ -264,10 +262,6 @@ public enum ScrimState {
mAodFrontScrimAlpha = aodFrontScrimAlpha;
}
public void setPulseReason(int pulseReason) {
mPulseReason = pulseReason;
}
public void setScrimBehindAlphaKeyguard(float scrimBehindAlphaKeyguard) {
mScrimBehindAlphaKeyguard = scrimBehindAlphaKeyguard;
}
@@ -287,4 +281,8 @@ public enum ScrimState {
public void setHasBackdrop(boolean hasBackdrop) {
mHasBackdrop = hasBackdrop;
}
public void setWakeLockScreenSensorActive(boolean active) {
mWakeLockScreenSensorActive = active;
}
}

View File

@@ -3908,7 +3908,6 @@ public class StatusBar extends SystemUI implements DemoMode,
@Override
public void pulseWhileDozing(@NonNull PulseCallback callback, int reason) {
mScrimController.setPulseReason(reason);
if (reason == DozeLog.PULSE_REASON_SENSOR_LONG_PRESS) {
mPowerManager.wakeUp(SystemClock.uptimeMillis(), PowerManager.WAKE_REASON_GESTURE,
"com.android.systemui:LONG_PRESS");
@@ -3916,6 +3915,10 @@ public class StatusBar extends SystemUI implements DemoMode,
return;
}
if (reason == DozeLog.PULSE_REASON_SENSOR_WAKE_LOCK_SCREEN) {
mScrimController.setWakeLockScreenSensorActive(true);
}
boolean passiveAuthInterrupt = reason == DozeLog.PULSE_REASON_NOTIFICATION;
// Set the state to pulsing, so ScrimController will know what to do once we ask it to
// execute the transition. The pulse callback will then be invoked when the scrims
@@ -3934,6 +3937,7 @@ public class StatusBar extends SystemUI implements DemoMode,
mPulsing = false;
callback.onPulseFinished();
updateNotificationPanelTouchState();
mScrimController.setWakeLockScreenSensorActive(false);
setPulsing(false);
}
@@ -4010,7 +4014,10 @@ public class StatusBar extends SystemUI implements DemoMode,
}
@Override
public void extendPulse() {
public void extendPulse(int reason) {
if (reason == DozeLog.PULSE_REASON_SENSOR_WAKE_LOCK_SCREEN) {
mScrimController.setWakeLockScreenSensorActive(true);
}
if (mDozeScrimController.isPulsing() && mAmbientPulseManager.hasNotifications()) {
mAmbientPulseManager.extendPulse();
} else {

View File

@@ -86,7 +86,7 @@ class DozeHostFake implements DozeHost {
}
@Override
public void extendPulse() {
public void extendPulse(int reason) {
pulseExtended = true;
}

View File

@@ -45,12 +45,11 @@ public class DozeWallpaperStateTest extends SysuiTestCase {
private DozeWallpaperState mDozeWallpaperState;
@Mock IWallpaperManager mIWallpaperManager;
@Mock DozeParameters mDozeParameters;
@Mock DozeMachine mMachine;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mDozeWallpaperState = new DozeWallpaperState(mMachine, mIWallpaperManager, mDozeParameters);
mDozeWallpaperState = new DozeWallpaperState(mIWallpaperManager, mDozeParameters);
}
@Test
@@ -109,29 +108,19 @@ public class DozeWallpaperStateTest extends SysuiTestCase {
verify(mIWallpaperManager).setInAmbientMode(eq(true), eq(0L));
}
@Test
public void testTransitionTo_notificationPulseIsAmbientMode() throws RemoteException {
when(mMachine.getPulseReason()).thenReturn(DozeLog.PULSE_REASON_NOTIFICATION);
mDozeWallpaperState.transitionTo(DozeMachine.State.DOZE_REQUEST_PULSE,
DozeMachine.State.DOZE_PULSING);
verify(mIWallpaperManager).setInAmbientMode(eq(true), eq(0L));
}
@Test
public void testTransitionTo_wakeFromPulseIsNotAmbientMode() throws RemoteException {
when(mMachine.getPulseReason()).thenReturn(DozeLog.PULSE_REASON_SENSOR_WAKE_LOCK_SCREEN);
mDozeWallpaperState.transitionTo(DozeMachine.State.DOZE_AOD,
DozeMachine.State.DOZE_REQUEST_PULSE);
reset(mIWallpaperManager);
mDozeWallpaperState.transitionTo(DozeMachine.State.DOZE_REQUEST_PULSE,
DozeMachine.State.DOZE_PULSING);
DozeMachine.State.DOZE_PULSING_BRIGHT);
verify(mIWallpaperManager).setInAmbientMode(eq(false), anyLong());
}
@Test
public void testTransitionTo_animatesWhenWakingUpFromPulse() throws RemoteException {
when(mMachine.getPulseReason()).thenReturn(DozeLog.PULSE_REASON_NOTIFICATION);
mDozeWallpaperState.transitionTo(DozeMachine.State.DOZE_REQUEST_PULSE,
DozeMachine.State.DOZE_PULSING);
reset(mIWallpaperManager);

View File

@@ -46,7 +46,6 @@ import androidx.test.filters.SmallTest;
import com.android.internal.colorextraction.ColorExtractor.GradientColors;
import com.android.internal.util.function.TriConsumer;
import com.android.systemui.SysuiTestCase;
import com.android.systemui.doze.DozeLog;
import com.android.systemui.statusbar.ScrimView;
import com.android.systemui.util.wakelock.WakeLock;
import com.android.systemui.utils.os.FakeHandler;
@@ -140,7 +139,6 @@ public class ScrimControllerTest extends SysuiTestCase {
assertScrimVisibility(VISIBILITY_FULLY_TRANSPARENT, VISIBILITY_FULLY_TRANSPARENT);
// Pulsing notification should conserve AOD wallpaper.
mScrimController.setPulseReason(DozeLog.PULSE_REASON_NOTIFICATION);
mScrimController.transitionTo(ScrimState.PULSING);
mScrimController.finishAnimationsImmediately();
assertScrimVisibility(VISIBILITY_FULLY_TRANSPARENT, VISIBILITY_FULLY_TRANSPARENT);
@@ -225,14 +223,17 @@ public class ScrimControllerTest extends SysuiTestCase {
mScrimController.finishAnimationsImmediately();
assertScrimVisibility(VISIBILITY_FULLY_TRANSPARENT, VISIBILITY_FULLY_OPAQUE);
mScrimController.setPulseReason(DozeLog.PULSE_REASON_SENSOR_WAKE_LOCK_SCREEN);
mScrimController.transitionTo(ScrimState.PULSING);
mScrimController.finishAnimationsImmediately();
// Front scrim should be transparent
// Back scrim should be semi-transparent so the user can see the wallpaper
// Pulse callback should have been invoked
assertScrimVisibility(VISIBILITY_FULLY_TRANSPARENT, VISIBILITY_SEMI_TRANSPARENT);
assertScrimVisibility(VISIBILITY_FULLY_TRANSPARENT, VISIBILITY_FULLY_OPAQUE);
assertScrimTint(mScrimBehind, true /* tinted */);
mScrimController.setWakeLockScreenSensorActive(true);
mScrimController.finishAnimationsImmediately();
assertScrimVisibility(VISIBILITY_FULLY_TRANSPARENT, VISIBILITY_SEMI_TRANSPARENT);
}
@Test
@@ -486,7 +487,6 @@ public class ScrimControllerTest extends SysuiTestCase {
@Test
public void testHoldsPulsingWallpaperAnimationLock() {
// Pre-conditions
mScrimController.setPulseReason(DozeLog.PULSE_REASON_NOTIFICATION);
mScrimController.transitionTo(ScrimState.PULSING);
mScrimController.finishAnimationsImmediately();
reset(mWakeLock);
@@ -507,30 +507,6 @@ public class ScrimControllerTest extends SysuiTestCase {
verify(mAlarmManager).cancel(any(AlarmManager.OnAlarmListener.class));
}
@Test
public void testWillHidePulsingWallpaper_whenNotification() {
mScrimController.setWallpaperSupportsAmbientMode(false);
mScrimController.transitionTo(ScrimState.AOD);
mScrimController.finishAnimationsImmediately();
mScrimController.setPulseReason(DozeLog.PULSE_REASON_NOTIFICATION);
mScrimController.transitionTo(ScrimState.PULSING);
mScrimController.finishAnimationsImmediately();
assertScrimVisibility(VISIBILITY_FULLY_TRANSPARENT, VISIBILITY_FULLY_OPAQUE);
assertScrimTint(mScrimBehind, true);
}
@Test
public void testWillHidePulsingWallpaper_whenDocking() {
mScrimController.setWallpaperSupportsAmbientMode(false);
mScrimController.transitionTo(ScrimState.AOD);
mScrimController.finishAnimationsImmediately();
mScrimController.setPulseReason(DozeLog.PULSE_REASON_DOCKING);
mScrimController.transitionTo(ScrimState.PULSING);
mScrimController.finishAnimationsImmediately();
assertScrimVisibility(VISIBILITY_FULLY_TRANSPARENT, VISIBILITY_FULLY_OPAQUE);
assertScrimTint(mScrimBehind, true);
}
@Test
public void testConservesExpansionOpacityAfterTransition() {
mScrimController.transitionTo(ScrimState.UNLOCKED);