Adds the power button unlock animation and plumbs detailed wake/sleep reason to System UI.

Test: unlock the phone using either the power button or lifting it
Bug: 169693662
Change-Id: I567555e6ee04f369ce7f4b32744639be70583112
This commit is contained in:
Josh Tsuji
2021-01-20 17:41:35 -05:00
parent 4cf643e12d
commit cb27bd1a83
17 changed files with 283 additions and 155 deletions

View File

@@ -525,6 +525,25 @@ public final class PowerManager {
@Retention(RetentionPolicy.SOURCE)
public @interface WakeReason{}
/**
* @hide
*/
@IntDef(prefix = { "GO_TO_SLEEP_REASON_" }, value = {
GO_TO_SLEEP_REASON_APPLICATION,
GO_TO_SLEEP_REASON_DEVICE_ADMIN,
GO_TO_SLEEP_REASON_TIMEOUT,
GO_TO_SLEEP_REASON_LID_SWITCH,
GO_TO_SLEEP_REASON_POWER_BUTTON,
GO_TO_SLEEP_REASON_HDMI,
GO_TO_SLEEP_REASON_SLEEP_BUTTON,
GO_TO_SLEEP_REASON_ACCESSIBILITY,
GO_TO_SLEEP_REASON_FORCE_SUSPEND,
GO_TO_SLEEP_REASON_INATTENTIVE,
GO_TO_SLEEP_REASON_QUIESCENT
})
@Retention(RetentionPolicy.SOURCE)
public @interface GoToSleepReason{}
/**
* Wake up reason code: Waking for an unknown reason.
* @hide

View File

@@ -17,6 +17,7 @@
package android.view;
import android.annotation.IntDef;
import android.os.PowerManager;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@@ -108,6 +109,27 @@ public interface WindowManagerPolicyConstants {
void onPointerEvent(MotionEvent motionEvent);
}
@IntDef(prefix = { "OFF_BECAUSE_OF_" }, value = {
OFF_BECAUSE_OF_ADMIN,
OFF_BECAUSE_OF_USER,
OFF_BECAUSE_OF_TIMEOUT,
})
@Retention(RetentionPolicy.SOURCE)
public @interface OffReason{}
static @OffReason int translateSleepReasonToOffReason(
@PowerManager.GoToSleepReason int reason) {
switch (reason) {
case PowerManager.GO_TO_SLEEP_REASON_DEVICE_ADMIN:
return OFF_BECAUSE_OF_ADMIN;
case PowerManager.GO_TO_SLEEP_REASON_TIMEOUT:
case PowerManager.GO_TO_SLEEP_REASON_INATTENTIVE:
return OFF_BECAUSE_OF_TIMEOUT;
default:
return OFF_BECAUSE_OF_USER;
}
}
/** Screen turned off because of a device admin */
int OFF_BECAUSE_OF_ADMIN = 1;
/** Screen turned off because of power button */
@@ -137,6 +159,23 @@ public interface WindowManagerPolicyConstants {
}
}
static @OnReason int translateWakeReasonToOnReason(@PowerManager.WakeReason int reason) {
switch (reason) {
case PowerManager.WAKE_REASON_POWER_BUTTON:
case PowerManager.WAKE_REASON_PLUGGED_IN:
case PowerManager.WAKE_REASON_GESTURE:
case PowerManager.WAKE_REASON_CAMERA_LAUNCH:
case PowerManager.WAKE_REASON_WAKE_KEY:
case PowerManager.WAKE_REASON_WAKE_MOTION:
case PowerManager.WAKE_REASON_LID:
return ON_BECAUSE_OF_USER;
case PowerManager.WAKE_REASON_APPLICATION:
return ON_BECAUSE_OF_APPLICATION;
default:
return ON_BECAUSE_OF_UNKNOWN;
}
}
/** Screen turned on because of a user-initiated action. */
int ON_BECAUSE_OF_USER = 1;
/** Screen turned on because of an application request or event */

View File

@@ -42,26 +42,29 @@ oneway interface IKeyguardService {
/**
* Called when the device has started going to sleep.
*
* @param why {@link #OFF_BECAUSE_OF_USER}, {@link #OFF_BECAUSE_OF_ADMIN},
* or {@link #OFF_BECAUSE_OF_TIMEOUT}.
* @param pmSleepReason One of PowerManager.GO_TO_SLEEP_REASON_*, detailing the specific reason
* we're going to sleep, such as GO_TO_SLEEP_REASON_POWER_BUTTON or GO_TO_SLEEP_REASON_TIMEOUT.
*/
void onStartedGoingToSleep(int reason);
void onStartedGoingToSleep(int pmSleepReason);
/**
* Called when the device has finished going to sleep.
*
* @param why {@link #OFF_BECAUSE_OF_USER}, {@link #OFF_BECAUSE_OF_ADMIN},
* or {@link #OFF_BECAUSE_OF_TIMEOUT}.
* @param pmSleepReason One of PowerManager.GO_TO_SLEEP_REASON_*, detailing the specific reason
* we're going to sleep, such as GO_TO_SLEEP_REASON_POWER_BUTTON or GO_TO_SLEEP_REASON_TIMEOUT.
* @param cameraGestureTriggered whether the camera gesture was triggered between
* {@link #onStartedGoingToSleep} and this method; if it's been
* triggered, we shouldn't lock the device.
*/
void onFinishedGoingToSleep(int reason, boolean cameraGestureTriggered);
void onFinishedGoingToSleep(int pmSleepReason, boolean cameraGestureTriggered);
/**
* Called when the device has started waking up.
* @param pmWakeReason One of PowerManager.WAKE_REASON_*, detailing the reason we're waking up,
* such as WAKE_REASON_POWER_BUTTON or WAKE_REASON_GESTURE.
*/
void onStartedWakingUp();
void onStartedWakingUp(int pmWakeReason);
/**
* Called when the device has finished waking up.

View File

@@ -18,6 +18,7 @@ package com.android.systemui.keyguard;
import android.os.Handler;
import android.os.Message;
import android.os.PowerManager;
import com.android.systemui.dagger.SysUISingleton;
@@ -53,6 +54,17 @@ public class KeyguardLifecyclesDispatcher {
mHandler.obtainMessage(what).sendToTarget();
}
/**
* @param what Message to send.
* @param pmReason Reason this message was triggered - this should be a value from either
* {@link PowerManager.WakeReason} or {@link PowerManager.GoToSleepReason}.
*/
void dispatch(int what, int pmReason) {
final Message message = mHandler.obtainMessage(what);
message.arg1 = pmReason;
message.sendToTarget();
}
private Handler mHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
@@ -70,13 +82,13 @@ public class KeyguardLifecyclesDispatcher {
mScreenLifecycle.dispatchScreenTurnedOff();
break;
case STARTED_WAKING_UP:
mWakefulnessLifecycle.dispatchStartedWakingUp();
mWakefulnessLifecycle.dispatchStartedWakingUp(msg.arg1 /* pmReason */);
break;
case FINISHED_WAKING_UP:
mWakefulnessLifecycle.dispatchFinishedWakingUp();
break;
case STARTED_GOING_TO_SLEEP:
mWakefulnessLifecycle.dispatchStartedGoingToSleep();
mWakefulnessLifecycle.dispatchStartedGoingToSleep(msg.arg1 /* pmReason */);
break;
case FINISHED_GOING_TO_SLEEP:
mWakefulnessLifecycle.dispatchFinishedGoingToSleep();

View File

@@ -24,9 +24,11 @@ import android.os.Binder;
import android.os.Bundle;
import android.os.Debug;
import android.os.IBinder;
import android.os.PowerManager;
import android.os.Process;
import android.os.Trace;
import android.util.Log;
import android.view.WindowManagerPolicyConstants;
import com.android.internal.policy.IKeyguardDismissCallback;
import com.android.internal.policy.IKeyguardDrawnCallback;
@@ -117,27 +119,32 @@ public class KeyguardService extends Service {
}
@Override // Binder interface
public void onStartedGoingToSleep(int reason) {
public void onStartedGoingToSleep(@PowerManager.GoToSleepReason int pmSleepReason) {
checkPermission();
mKeyguardViewMediator.onStartedGoingToSleep(reason);
mKeyguardViewMediator.onStartedGoingToSleep(
WindowManagerPolicyConstants.translateSleepReasonToOffReason(pmSleepReason));
mKeyguardLifecyclesDispatcher.dispatch(
KeyguardLifecyclesDispatcher.STARTED_GOING_TO_SLEEP);
KeyguardLifecyclesDispatcher.STARTED_GOING_TO_SLEEP, pmSleepReason);
}
@Override // Binder interface
public void onFinishedGoingToSleep(int reason, boolean cameraGestureTriggered) {
public void onFinishedGoingToSleep(
@PowerManager.GoToSleepReason int pmSleepReason, boolean cameraGestureTriggered) {
checkPermission();
mKeyguardViewMediator.onFinishedGoingToSleep(reason, cameraGestureTriggered);
mKeyguardViewMediator.onFinishedGoingToSleep(
WindowManagerPolicyConstants.translateSleepReasonToOffReason(pmSleepReason),
cameraGestureTriggered);
mKeyguardLifecyclesDispatcher.dispatch(
KeyguardLifecyclesDispatcher.FINISHED_GOING_TO_SLEEP);
}
@Override // Binder interface
public void onStartedWakingUp() {
public void onStartedWakingUp(@PowerManager.WakeReason int pmWakeReason) {
Trace.beginSection("KeyguardService.mBinder#onStartedWakingUp");
checkPermission();
mKeyguardViewMediator.onStartedWakingUp();
mKeyguardLifecyclesDispatcher.dispatch(KeyguardLifecyclesDispatcher.STARTED_WAKING_UP);
mKeyguardLifecyclesDispatcher.dispatch(
KeyguardLifecyclesDispatcher.STARTED_WAKING_UP, pmWakeReason);
Trace.endSection();
}

View File

@@ -85,13 +85,11 @@ import com.android.keyguard.KeyguardUpdateMonitorCallback;
import com.android.keyguard.KeyguardViewController;
import com.android.keyguard.ViewMediatorCallback;
import com.android.systemui.Dumpable;
import com.android.systemui.R;
import com.android.systemui.SystemUI;
import com.android.systemui.broadcast.BroadcastDispatcher;
import com.android.systemui.classifier.FalsingCollector;
import com.android.systemui.dagger.qualifiers.UiBackground;
import com.android.systemui.dump.DumpManager;
import com.android.systemui.keyguard.KeyguardService;
import com.android.systemui.keyguard.dagger.KeyguardModule;
import com.android.systemui.navigationbar.NavigationModeController;
import com.android.systemui.shared.system.QuickStepContract;
@@ -863,11 +861,11 @@ public class KeyguardViewMediator extends SystemUI implements Dumpable {
/**
* Called to let us know the screen was turned off.
* @param why either {@link WindowManagerPolicyConstants#OFF_BECAUSE_OF_USER} or
* {@link WindowManagerPolicyConstants#OFF_BECAUSE_OF_TIMEOUT}.
* @param offReason either {@link WindowManagerPolicyConstants#OFF_BECAUSE_OF_USER} or
* {@link WindowManagerPolicyConstants#OFF_BECAUSE_OF_TIMEOUT}.
*/
public void onStartedGoingToSleep(int why) {
if (DEBUG) Log.d(TAG, "onStartedGoingToSleep(" + why + ")");
public void onStartedGoingToSleep(@WindowManagerPolicyConstants.OffReason int offReason) {
if (DEBUG) Log.d(TAG, "onStartedGoingToSleep(" + offReason + ")");
synchronized (this) {
mDeviceInteractive = false;
mGoingToSleep = true;
@@ -900,8 +898,11 @@ public class KeyguardViewMediator extends SystemUI implements Dumpable {
}
} else if (mShowing) {
mPendingReset = true;
} else if ((why == WindowManagerPolicyConstants.OFF_BECAUSE_OF_TIMEOUT && timeout > 0)
|| (why == WindowManagerPolicyConstants.OFF_BECAUSE_OF_USER && !lockImmediately)) {
} else if (
(offReason == WindowManagerPolicyConstants.OFF_BECAUSE_OF_TIMEOUT
&& timeout > 0)
|| (offReason == WindowManagerPolicyConstants.OFF_BECAUSE_OF_USER
&& !lockImmediately)) {
doKeyguardLaterLocked(timeout);
mLockLater = true;
} else if (!mLockPatternUtils.isLockScreenDisabled(currentUser)) {
@@ -912,12 +913,18 @@ public class KeyguardViewMediator extends SystemUI implements Dumpable {
playSounds(true);
}
}
mUpdateMonitor.dispatchStartedGoingToSleep(why);
mUpdateMonitor.dispatchStartedGoingToSleep(offReason);
notifyStartedGoingToSleep();
}
public void onFinishedGoingToSleep(int why, boolean cameraGestureTriggered) {
if (DEBUG) Log.d(TAG, "onFinishedGoingToSleep(" + why + ")");
/**
* Called to let us know the screen finished turning off.
* @param offReason either {@link WindowManagerPolicyConstants#OFF_BECAUSE_OF_USER} or
* {@link WindowManagerPolicyConstants#OFF_BECAUSE_OF_TIMEOUT}.
*/
public void onFinishedGoingToSleep(
@WindowManagerPolicyConstants.OffReason int offReason, boolean cameraGestureTriggered) {
if (DEBUG) Log.d(TAG, "onFinishedGoingToSleep(" + offReason + ")");
synchronized (this) {
mDeviceInteractive = false;
mGoingToSleep = false;
@@ -957,7 +964,7 @@ public class KeyguardViewMediator extends SystemUI implements Dumpable {
}
}
mUpdateMonitor.dispatchFinishedGoingToSleep(why);
mUpdateMonitor.dispatchFinishedGoingToSleep(offReason);
}
private boolean isKeyguardServiceEnabled() {

View File

@@ -17,6 +17,7 @@
package com.android.systemui.keyguard;
import android.annotation.IntDef;
import android.os.PowerManager;
import android.os.Trace;
import com.android.systemui.Dumpable;
@@ -51,6 +52,9 @@ public class WakefulnessLifecycle extends Lifecycle<WakefulnessLifecycle.Observe
public static final int WAKEFULNESS_GOING_TO_SLEEP = 3;
private int mWakefulness = WAKEFULNESS_ASLEEP;
private @PowerManager.WakeReason int mLastWakeReason = PowerManager.WAKE_REASON_UNKNOWN;
private @PowerManager.GoToSleepReason int mLastSleepReason =
PowerManager.GO_TO_SLEEP_REASON_MIN;
@Inject
public WakefulnessLifecycle() {
@@ -60,11 +64,27 @@ public class WakefulnessLifecycle extends Lifecycle<WakefulnessLifecycle.Observe
return mWakefulness;
}
public void dispatchStartedWakingUp() {
/**
* Returns the most recent reason the device woke up. This is one of PowerManager.WAKE_REASON_*.
*/
public @PowerManager.WakeReason int getLastWakeReason() {
return mLastWakeReason;
}
/**
* Returns the most recent reason the device went to sleep up. This is one of
* PowerManager.GO_TO_SLEEP_REASON_*.
*/
public @PowerManager.GoToSleepReason int getLastSleepReason() {
return mLastSleepReason;
}
public void dispatchStartedWakingUp(@PowerManager.WakeReason int pmWakeReason) {
if (getWakefulness() == WAKEFULNESS_WAKING) {
return;
}
setWakefulness(WAKEFULNESS_WAKING);
mLastWakeReason = pmWakeReason;
dispatch(Observer::onStartedWakingUp);
}
@@ -76,11 +96,12 @@ public class WakefulnessLifecycle extends Lifecycle<WakefulnessLifecycle.Observe
dispatch(Observer::onFinishedWakingUp);
}
public void dispatchStartedGoingToSleep() {
public void dispatchStartedGoingToSleep(@PowerManager.GoToSleepReason int pmSleepReason) {
if (getWakefulness() == WAKEFULNESS_GOING_TO_SLEEP) {
return;
}
setWakefulness(WAKEFULNESS_GOING_TO_SLEEP);
mLastSleepReason = pmSleepReason;
dispatch(Observer::onStartedGoingToSleep);
}

View File

@@ -86,6 +86,35 @@ object LiftReveal : LightRevealEffect {
}
}
class PowerButtonReveal(
/** Approximate Y-value of the center of the power button on the physical device. */
val powerButtonY: Float
) : LightRevealEffect {
private val OVAL_INITIAL_HEIGHT = 50f
private val WIDTH_INCREASE_MULTIPLIER = 1.25f
override fun setRevealAmountOnScrim(amount: Float, scrim: LightRevealScrim) {
val interpolatedAmount = Interpolators.FAST_OUT_SLOW_IN_REVERSE.getInterpolation(amount)
val fadeAmount =
LightRevealEffect.getPercentPastThreshold(interpolatedAmount, 0.5f)
with(scrim) {
revealGradientEndColorAlpha = 1f - fadeAmount
setRevealGradientBounds(
width -
width * WIDTH_INCREASE_MULTIPLIER * interpolatedAmount,
powerButtonY - (OVAL_INITIAL_HEIGHT / 2f) -
height * interpolatedAmount,
width * WIDTH_INCREASE_MULTIPLIER +
width * WIDTH_INCREASE_MULTIPLIER * interpolatedAmount,
powerButtonY + (OVAL_INITIAL_HEIGHT / 2f) +
height * interpolatedAmount)
}
}
}
/**
* Scrim view that partially reveals the content underneath it using a [RadialGradient] with a
* transparent center. The center position, size, and stops of the gradient can be manipulated to

View File

@@ -192,6 +192,7 @@ import com.android.systemui.statusbar.NotificationShadeDepthController;
import com.android.systemui.statusbar.NotificationShadeWindowController;
import com.android.systemui.statusbar.NotificationShelfController;
import com.android.systemui.statusbar.NotificationViewHierarchyManager;
import com.android.systemui.statusbar.PowerButtonReveal;
import com.android.systemui.statusbar.PulseExpansionHandler;
import com.android.systemui.statusbar.ScrimView;
import com.android.systemui.statusbar.StatusBarState;
@@ -371,6 +372,7 @@ public class StatusBar extends SystemUI implements DemoMode,
private boolean mWakeUpComingFromTouch;
private PointF mWakeUpTouchLocation;
private LightRevealScrim mLightRevealScrim;
private PowerButtonReveal mPowerButtonReveal;
private final Object mQueueLock = new Object();
@@ -2965,6 +2967,9 @@ public class StatusBar extends SystemUI implements DemoMode,
if (mBrightnessMirrorController != null) {
mBrightnessMirrorController.updateResources();
}
mPowerButtonReveal = new PowerButtonReveal(mContext.getResources().getDimensionPixelSize(
R.dimen.global_actions_top_padding));
}
// Visibility reporting
@@ -3672,6 +3677,16 @@ public class StatusBar extends SystemUI implements DemoMode,
updateQsExpansionEnabled();
mKeyguardViewMediator.setDozing(mDozing);
final boolean usePowerButtonEffect =
(isDozing && mWakefulnessLifecycle.getLastSleepReason()
== PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON)
|| (!isDozing && mWakefulnessLifecycle.getLastWakeReason()
== PowerManager.WAKE_REASON_POWER_BUTTON);
mLightRevealScrim.setRevealEffect(usePowerButtonEffect
? mPowerButtonReveal
: LiftReveal.INSTANCE);
mNotificationsController.requestNotificationUpdate("onDozingChanged");
updateDozingState();
mDozeServiceHost.updateDozing();

View File

@@ -22,6 +22,7 @@ import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import android.os.PowerManager;
import android.testing.AndroidTestingRunner;
import androidx.test.filters.SmallTest;
@@ -58,7 +59,7 @@ public class WakefulnessLifecycleTest extends SysuiTestCase {
@Test
public void dispatchStartedWakingUp() throws Exception {
mWakefulness.dispatchStartedWakingUp();
mWakefulness.dispatchStartedWakingUp(PowerManager.WAKE_REASON_UNKNOWN);
assertEquals(WakefulnessLifecycle.WAKEFULNESS_WAKING, mWakefulness.getWakefulness());
@@ -67,7 +68,7 @@ public class WakefulnessLifecycleTest extends SysuiTestCase {
@Test
public void dispatchFinishedWakingUp() throws Exception {
mWakefulness.dispatchStartedWakingUp();
mWakefulness.dispatchStartedWakingUp(PowerManager.WAKE_REASON_UNKNOWN);
mWakefulness.dispatchFinishedWakingUp();
assertEquals(WakefulnessLifecycle.WAKEFULNESS_AWAKE, mWakefulness.getWakefulness());
@@ -77,9 +78,9 @@ public class WakefulnessLifecycleTest extends SysuiTestCase {
@Test
public void dispatchStartedGoingToSleep() throws Exception {
mWakefulness.dispatchStartedWakingUp();
mWakefulness.dispatchStartedWakingUp(PowerManager.WAKE_REASON_UNKNOWN);
mWakefulness.dispatchFinishedWakingUp();
mWakefulness.dispatchStartedGoingToSleep();
mWakefulness.dispatchStartedGoingToSleep(PowerManager.GO_TO_SLEEP_REASON_MIN);
assertEquals(WakefulnessLifecycle.WAKEFULNESS_GOING_TO_SLEEP,
mWakefulness.getWakefulness());
@@ -89,9 +90,9 @@ public class WakefulnessLifecycleTest extends SysuiTestCase {
@Test
public void dispatchFinishedGoingToSleep() throws Exception {
mWakefulness.dispatchStartedWakingUp();
mWakefulness.dispatchStartedWakingUp(PowerManager.WAKE_REASON_UNKNOWN);
mWakefulness.dispatchFinishedWakingUp();
mWakefulness.dispatchStartedGoingToSleep();
mWakefulness.dispatchStartedGoingToSleep(PowerManager.GO_TO_SLEEP_REASON_MIN);
mWakefulness.dispatchFinishedGoingToSleep();
assertEquals(WakefulnessLifecycle.WAKEFULNESS_ASLEEP,
@@ -102,12 +103,12 @@ public class WakefulnessLifecycleTest extends SysuiTestCase {
@Test
public void doesNotDispatchTwice() throws Exception {
mWakefulness.dispatchStartedWakingUp();
mWakefulness.dispatchStartedWakingUp();
mWakefulness.dispatchStartedWakingUp(PowerManager.WAKE_REASON_UNKNOWN);
mWakefulness.dispatchStartedWakingUp(PowerManager.WAKE_REASON_UNKNOWN);
mWakefulness.dispatchFinishedWakingUp();
mWakefulness.dispatchFinishedWakingUp();
mWakefulness.dispatchStartedGoingToSleep();
mWakefulness.dispatchStartedGoingToSleep();
mWakefulness.dispatchStartedGoingToSleep(PowerManager.GO_TO_SLEEP_REASON_MIN);
mWakefulness.dispatchStartedGoingToSleep(PowerManager.GO_TO_SLEEP_REASON_MIN);
mWakefulness.dispatchFinishedGoingToSleep();
mWakefulness.dispatchFinishedGoingToSleep();

View File

@@ -323,7 +323,7 @@ public class StatusBarTest extends SysuiTestCase {
when(mRemoteInputManager.getController()).thenReturn(mRemoteInputController);
WakefulnessLifecycle wakefulnessLifecycle = new WakefulnessLifecycle();
wakefulnessLifecycle.dispatchStartedWakingUp();
wakefulnessLifecycle.dispatchStartedWakingUp(PowerManager.WAKE_REASON_UNKNOWN);
wakefulnessLifecycle.dispatchFinishedWakingUp();
when(mGradientColors.supportsDarkText()).thenReturn(true);

View File

@@ -1897,8 +1897,8 @@ public class PhoneWindowManager implements WindowManagerPolicy {
// Match current screen state.
if (!mPowerManager.isInteractive()) {
startedGoingToSleep(WindowManagerPolicy.OFF_BECAUSE_OF_USER);
finishedGoingToSleep(WindowManagerPolicy.OFF_BECAUSE_OF_USER);
startedGoingToSleep(PowerManager.GO_TO_SLEEP_REASON_TIMEOUT);
finishedGoingToSleep(PowerManager.GO_TO_SLEEP_REASON_TIMEOUT);
}
mWindowManagerInternal.registerAppTransitionListener(new AppTransitionListener() {
@@ -4234,27 +4234,31 @@ public class PhoneWindowManager implements WindowManagerPolicy {
// Called on the PowerManager's Notifier thread.
@Override
public void startedGoingToSleep(int why) {
public void startedGoingToSleep(@PowerManager.GoToSleepReason int pmSleepReason) {
if (DEBUG_WAKEUP) {
Slog.i(TAG, "Started going to sleep... (why="
+ WindowManagerPolicyConstants.offReasonToString(why) + ")");
+ WindowManagerPolicyConstants.offReasonToString(
WindowManagerPolicyConstants.translateSleepReasonToOffReason(
pmSleepReason)) + ")");
}
mGoingToSleep = true;
mRequestedOrGoingToSleep = true;
if (mKeyguardDelegate != null) {
mKeyguardDelegate.onStartedGoingToSleep(why);
mKeyguardDelegate.onStartedGoingToSleep(pmSleepReason);
}
}
// Called on the PowerManager's Notifier thread.
@Override
public void finishedGoingToSleep(int why) {
public void finishedGoingToSleep(@PowerManager.GoToSleepReason int pmSleepReason) {
EventLogTags.writeScreenToggled(0);
if (DEBUG_WAKEUP) {
Slog.i(TAG, "Finished going to sleep... (why="
+ WindowManagerPolicyConstants.offReasonToString(why) + ")");
+ WindowManagerPolicyConstants.offReasonToString(
WindowManagerPolicyConstants.translateSleepReasonToOffReason(
pmSleepReason)) + ")");
}
MetricsLogger.histogram(mContext, "screen_timeout", mLockScreenTimeout / 1000);
@@ -4271,7 +4275,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
mDefaultDisplayRotation.updateOrientationListener();
if (mKeyguardDelegate != null) {
mKeyguardDelegate.onFinishedGoingToSleep(why,
mKeyguardDelegate.onFinishedGoingToSleep(pmSleepReason,
mCameraGestureTriggeredDuringGoingToSleep);
}
if (mDisplayFoldController != null) {
@@ -4282,11 +4286,13 @@ public class PhoneWindowManager implements WindowManagerPolicy {
// Called on the PowerManager's Notifier thread.
@Override
public void startedWakingUp(@OnReason int why) {
public void startedWakingUp(@PowerManager.WakeReason int pmWakeReason) {
EventLogTags.writeScreenToggled(1);
if (DEBUG_WAKEUP) {
Slog.i(TAG, "Started waking up... (why="
+ WindowManagerPolicyConstants.onReasonToString(why) + ")");
+ WindowManagerPolicyConstants.onReasonToString(
WindowManagerPolicyConstants.translateWakeReasonToOnReason(
pmWakeReason)) + ")");
}
mDefaultDisplayPolicy.setAwake(true);
@@ -4302,16 +4308,18 @@ public class PhoneWindowManager implements WindowManagerPolicy {
mDefaultDisplayRotation.updateOrientationListener();
if (mKeyguardDelegate != null) {
mKeyguardDelegate.onStartedWakingUp();
mKeyguardDelegate.onStartedWakingUp(pmWakeReason);
}
}
// Called on the PowerManager's Notifier thread.
@Override
public void finishedWakingUp(@OnReason int why) {
public void finishedWakingUp(@PowerManager.WakeReason int pmWakeReason) {
if (DEBUG_WAKEUP) {
Slog.i(TAG, "Finished waking up... (why="
+ WindowManagerPolicyConstants.onReasonToString(why) + ")");
+ WindowManagerPolicyConstants.onReasonToString(
WindowManagerPolicyConstants.translateWakeReasonToOnReason(
pmWakeReason)) + ")");
}
if (mKeyguardDelegate != null) {
@@ -4730,8 +4738,8 @@ public class PhoneWindowManager implements WindowManagerPolicy {
mKeyguardDelegate.onBootCompleted();
}
}
startedWakingUp(ON_BECAUSE_OF_UNKNOWN);
finishedWakingUp(ON_BECAUSE_OF_UNKNOWN);
startedWakingUp(PowerManager.WAKE_REASON_UNKNOWN);
finishedWakingUp(PowerManager.WAKE_REASON_UNKNOWN);
screenTurningOn(DEFAULT_DISPLAY, null);
screenTurnedOn(DEFAULT_DISPLAY);
}

View File

@@ -73,6 +73,7 @@ import android.content.res.Configuration;
import android.graphics.Rect;
import android.os.Bundle;
import android.os.IBinder;
import android.os.PowerManager;
import android.os.RemoteException;
import android.util.Slog;
import android.util.proto.ProtoOutputStream;
@@ -803,29 +804,35 @@ public interface WindowManagerPolicy extends WindowManagerPolicyConstants {
/**
* Called when the device has started waking up.
*
* @param pmWakeReason One of PowerManager.WAKE_REASON_*, detailing the specific reason we're
* waking up, such as WAKE_REASON_POWER_BUTTON or WAKE_REASON_GESTURE.
*/
void startedWakingUp(@OnReason int reason);
void startedWakingUp(@PowerManager.WakeReason int pmWakeReason);
/**
* Called when the device has finished waking up.
*
* @param pmWakeReason One of PowerManager.WAKE_REASON_*, detailing the specific reason we're
* waking up, such as WAKE_REASON_POWER_BUTTON or WAKE_REASON_GESTURE.
*/
void finishedWakingUp(@OnReason int reason);
void finishedWakingUp(@PowerManager.WakeReason int pmWakeReason);
/**
* Called when the device has started going to sleep.
*
* @param why {@link #OFF_BECAUSE_OF_USER}, {@link #OFF_BECAUSE_OF_ADMIN},
* or {@link #OFF_BECAUSE_OF_TIMEOUT}.
* @param pmSleepReason One of PowerManager.GO_TO_SLEEP_REASON_*, detailing the specific reason
* we're going to sleep, such as GO_TO_SLEEP_REASON_POWER_BUTTON or GO_TO_SLEEP_REASON_TIMEOUT.
*/
public void startedGoingToSleep(int why);
public void startedGoingToSleep(@PowerManager.GoToSleepReason int pmSleepReason);
/**
* Called when the device has finished going to sleep.
*
* @param why {@link #OFF_BECAUSE_OF_USER}, {@link #OFF_BECAUSE_OF_ADMIN},
* or {@link #OFF_BECAUSE_OF_TIMEOUT}.
* @param pmSleepReason One of PowerManager.GO_TO_SLEEP_REASON_*, detailing the specific reason
* we're going to sleep, such as GO_TO_SLEEP_REASON_POWER_BUTTON or GO_TO_SLEEP_REASON_TIMEOUT.
*/
public void finishedGoingToSleep(int why);
public void finishedGoingToSleep(@PowerManager.GoToSleepReason int pmSleepReason);
/**
* Called when the display is about to turn on to show content.

View File

@@ -15,6 +15,7 @@ import android.content.res.Resources;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
import android.os.PowerManager;
import android.os.RemoteException;
import android.os.UserHandle;
import android.util.Log;
@@ -176,7 +177,7 @@ public class KeyguardServiceDelegate {
// This is used to hide the scrim once keyguard displays.
if (mKeyguardState.interactiveState == INTERACTIVE_STATE_AWAKE
|| mKeyguardState.interactiveState == INTERACTIVE_STATE_WAKING) {
mKeyguardService.onStartedWakingUp();
mKeyguardService.onStartedWakingUp(PowerManager.WAKE_REASON_UNKNOWN);
}
if (mKeyguardState.interactiveState == INTERACTIVE_STATE_AWAKE) {
mKeyguardService.onFinishedWakingUp();
@@ -291,10 +292,10 @@ public class KeyguardServiceDelegate {
mKeyguardState.dreaming = false;
}
public void onStartedWakingUp() {
public void onStartedWakingUp(@PowerManager.WakeReason int pmWakeReason) {
if (mKeyguardService != null) {
if (DEBUG) Log.v(TAG, "onStartedWakingUp()");
mKeyguardService.onStartedWakingUp();
mKeyguardService.onStartedWakingUp(pmWakeReason);
}
mKeyguardState.interactiveState = INTERACTIVE_STATE_WAKING;
}
@@ -345,17 +346,19 @@ public class KeyguardServiceDelegate {
mKeyguardState.screenState = SCREEN_STATE_ON;
}
public void onStartedGoingToSleep(int why) {
public void onStartedGoingToSleep(@PowerManager.GoToSleepReason int pmSleepReason) {
if (mKeyguardService != null) {
mKeyguardService.onStartedGoingToSleep(why);
mKeyguardService.onStartedGoingToSleep(pmSleepReason);
}
mKeyguardState.offReason = why;
mKeyguardState.offReason =
WindowManagerPolicyConstants.translateSleepReasonToOffReason(pmSleepReason);
mKeyguardState.interactiveState = INTERACTIVE_STATE_GOING_TO_SLEEP;
}
public void onFinishedGoingToSleep(int why, boolean cameraGestureTriggered) {
public void onFinishedGoingToSleep(
@PowerManager.GoToSleepReason int pmSleepReason, boolean cameraGestureTriggered) {
if (mKeyguardService != null) {
mKeyguardService.onFinishedGoingToSleep(why, cameraGestureTriggered);
mKeyguardService.onFinishedGoingToSleep(pmSleepReason, cameraGestureTriggered);
}
mKeyguardState.interactiveState = INTERACTIVE_STATE_SLEEP;
}

View File

@@ -19,6 +19,7 @@ package com.android.server.policy.keyguard;
import android.content.Context;
import android.os.Bundle;
import android.os.IBinder;
import android.os.PowerManager;
import android.os.RemoteException;
import android.util.Slog;
@@ -101,27 +102,28 @@ public class KeyguardServiceWrapper implements IKeyguardService {
}
@Override
public void onStartedGoingToSleep(int reason) {
public void onStartedGoingToSleep(@PowerManager.GoToSleepReason int pmSleepReason) {
try {
mService.onStartedGoingToSleep(reason);
mService.onStartedGoingToSleep(pmSleepReason);
} catch (RemoteException e) {
Slog.w(TAG , "Remote Exception", e);
}
}
@Override
public void onFinishedGoingToSleep(int reason, boolean cameraGestureTriggered) {
public void onFinishedGoingToSleep(
@PowerManager.GoToSleepReason int pmSleepReason, boolean cameraGestureTriggered) {
try {
mService.onFinishedGoingToSleep(reason, cameraGestureTriggered);
mService.onFinishedGoingToSleep(pmSleepReason, cameraGestureTriggered);
} catch (RemoteException e) {
Slog.w(TAG , "Remote Exception", e);
}
}
@Override
public void onStartedWakingUp() {
public void onStartedWakingUp(@PowerManager.WakeReason int pmWakeReason) {
try {
mService.onStartedWakingUp();
mService.onStartedWakingUp(pmWakeReason);
} catch (RemoteException e) {
Slog.w(TAG , "Remote Exception", e);
}

View File

@@ -36,7 +36,6 @@ import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.os.PowerManager;
import android.os.PowerManager.WakeReason;
import android.os.PowerManagerInternal;
import android.os.Process;
import android.os.RemoteException;
@@ -49,7 +48,7 @@ import android.provider.Settings;
import android.telephony.TelephonyManager;
import android.util.EventLog;
import android.util.Slog;
import android.view.WindowManagerPolicyConstants.OnReason;
import android.view.WindowManagerPolicyConstants;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.app.IBatteryStats;
@@ -455,13 +454,7 @@ public class Notifier {
synchronized (mLock) {
if (mInteractive) {
// Waking up...
mHandler.post(new Runnable() {
@Override
public void run() {
final int why = translateOnReason(mInteractiveChangeReason);
mPolicy.startedWakingUp(why);
}
});
mHandler.post(() -> mPolicy.startedWakingUp(mInteractiveChangeReason));
// Send interactive broadcast.
mPendingInteractiveState = INTERACTIVE_STATE_AWAKE;
@@ -470,13 +463,7 @@ public class Notifier {
} else {
// Going to sleep...
// Tell the policy that we started going to sleep.
final int why = translateOffReason(mInteractiveChangeReason);
mHandler.post(new Runnable() {
@Override
public void run() {
mPolicy.startedGoingToSleep(why);
}
});
mHandler.post(() -> mPolicy.startedGoingToSleep(mInteractiveChangeReason));
}
}
}
@@ -492,20 +479,17 @@ public class Notifier {
(int) (SystemClock.uptimeMillis() - mInteractiveChangeStartTime);
if (mInteractive) {
// Finished waking up...
final int why = translateOnReason(mInteractiveChangeReason);
mHandler.post(new Runnable() {
@Override
public void run() {
LogMaker log = new LogMaker(MetricsEvent.SCREEN);
log.setType(MetricsEvent.TYPE_OPEN);
log.setSubtype(why);
log.setLatency(interactiveChangeLatency);
log.addTaggedData(
MetricsEvent.FIELD_SCREEN_WAKE_REASON, mInteractiveChangeReason);
MetricsLogger.action(log);
EventLogTags.writePowerScreenState(1, 0, 0, 0, interactiveChangeLatency);
mPolicy.finishedWakingUp(why);
}
mHandler.post(() -> {
LogMaker log = new LogMaker(MetricsEvent.SCREEN);
log.setType(MetricsEvent.TYPE_OPEN);
log.setSubtype(WindowManagerPolicyConstants.translateWakeReasonToOnReason(
mInteractiveChangeReason));
log.setLatency(interactiveChangeLatency);
log.addTaggedData(
MetricsEvent.FIELD_SCREEN_WAKE_REASON, mInteractiveChangeReason);
MetricsLogger.action(log);
EventLogTags.writePowerScreenState(1, 0, 0, 0, interactiveChangeLatency);
mPolicy.finishedWakingUp(mInteractiveChangeReason);
});
} else {
// Finished going to sleep...
@@ -521,20 +505,19 @@ public class Notifier {
}
// Tell the policy we finished going to sleep.
final int why = translateOffReason(mInteractiveChangeReason);
mHandler.post(new Runnable() {
@Override
public void run() {
LogMaker log = new LogMaker(MetricsEvent.SCREEN);
log.setType(MetricsEvent.TYPE_CLOSE);
log.setSubtype(why);
log.setLatency(interactiveChangeLatency);
log.addTaggedData(
MetricsEvent.FIELD_SCREEN_SLEEP_REASON, mInteractiveChangeReason);
MetricsLogger.action(log);
EventLogTags.writePowerScreenState(0, why, 0, 0, interactiveChangeLatency);
mPolicy.finishedGoingToSleep(why);
}
final int offReason = WindowManagerPolicyConstants.translateSleepReasonToOffReason(
mInteractiveChangeReason);
mHandler.post(() -> {
LogMaker log = new LogMaker(MetricsEvent.SCREEN);
log.setType(MetricsEvent.TYPE_CLOSE);
log.setSubtype(offReason);
log.setLatency(interactiveChangeLatency);
log.addTaggedData(
MetricsEvent.FIELD_SCREEN_SLEEP_REASON, mInteractiveChangeReason);
MetricsLogger.action(log);
EventLogTags.writePowerScreenState(
0, offReason, 0, 0, interactiveChangeLatency);
mPolicy.finishedGoingToSleep(mInteractiveChangeReason);
});
// Send non-interactive broadcast.
@@ -545,35 +528,6 @@ public class Notifier {
}
}
private static int translateOffReason(int reason) {
switch (reason) {
case PowerManager.GO_TO_SLEEP_REASON_DEVICE_ADMIN:
return WindowManagerPolicy.OFF_BECAUSE_OF_ADMIN;
case PowerManager.GO_TO_SLEEP_REASON_TIMEOUT:
case PowerManager.GO_TO_SLEEP_REASON_INATTENTIVE:
return WindowManagerPolicy.OFF_BECAUSE_OF_TIMEOUT;
default:
return WindowManagerPolicy.OFF_BECAUSE_OF_USER;
}
}
private static @OnReason int translateOnReason(@WakeReason int reason) {
switch (reason) {
case PowerManager.WAKE_REASON_POWER_BUTTON:
case PowerManager.WAKE_REASON_PLUGGED_IN:
case PowerManager.WAKE_REASON_GESTURE:
case PowerManager.WAKE_REASON_CAMERA_LAUNCH:
case PowerManager.WAKE_REASON_WAKE_KEY:
case PowerManager.WAKE_REASON_WAKE_MOTION:
case PowerManager.WAKE_REASON_LID:
return WindowManagerPolicy.ON_BECAUSE_OF_USER;
case PowerManager.WAKE_REASON_APPLICATION:
return WindowManagerPolicy.ON_BECAUSE_OF_APPLICATION;
default:
return WindowManagerPolicy.ON_BECAUSE_OF_UNKNOWN;
}
}
/**
* Called when there has been user activity.
*/

View File

@@ -28,6 +28,7 @@ import android.content.res.CompatibilityInfo;
import android.content.res.Configuration;
import android.os.Bundle;
import android.os.IBinder;
import android.os.PowerManager.GoToSleepReason;
import android.os.PowerManager.WakeReason;
import android.os.RemoteException;
import android.util.proto.ProtoOutputStream;
@@ -177,19 +178,19 @@ class TestWindowManagerPolicy implements WindowManagerPolicy {
}
@Override
public void startedWakingUp(@WakeReason int reason) {
public void startedWakingUp(@WakeReason int wakeReason) {
}
@Override
public void finishedWakingUp(@WakeReason int reason) {
public void finishedWakingUp(@WakeReason int wakeReason) {
}
@Override
public void startedGoingToSleep(int why) {
public void startedGoingToSleep(@GoToSleepReason int sleepReason) {
}
@Override
public void finishedGoingToSleep(int why) {
public void finishedGoingToSleep(@GoToSleepReason int sleepReason) {
}
@Override