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

Commit fd577558 authored by Josh Tsuji's avatar Josh Tsuji Committed by Android (Google) Code Review
Browse files

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

parents 99b7eb15 cb27bd1a
Loading
Loading
Loading
Loading
+19 −0
Original line number Diff line number Diff line
@@ -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
+39 −0
Original line number Diff line number Diff line
@@ -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 */
+10 −7
Original line number Diff line number Diff line
@@ -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.
+14 −2
Original line number Diff line number Diff line
@@ -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();
+14 −7
Original line number Diff line number Diff line
@@ -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();
        }

Loading