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

Commit 41234fdc authored by Adrian Roos's avatar Adrian Roos Committed by android-build-merger
Browse files

Merge "Keyguard: Factor out Screen and Wakefulness lifecycles" into oc-dr1-dev

am: d3878b5e

Change-Id: Ibe7749ee616295426cdeae07deb9dc998c49e8e2
parents ac2abee0 d3878b5e
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -63,6 +63,11 @@ oneway interface IKeyguardService {
     */
    void onStartedWakingUp();

    /**
     * Called when the device has finished waking up.
     */
    void onFinishedWakingUp();

    /**
     * Called when the device screen is turning on.
     */
@@ -73,6 +78,11 @@ oneway interface IKeyguardService {
     */
    void onScreenTurnedOn();

    /**
     * Called when the screen starts turning off.
     */
    void onScreenTurningOff();

    /**
     * Called when the screen has turned off.
     */
+15 −0
Original line number Diff line number Diff line
@@ -154,13 +154,19 @@ public class KeyguardUpdateMonitorCallback {

    /**
     * Called when the device has started waking up.
     *
     * @deprecated use {@link com.android.systemui.keyguard.WakefulnessLifecycle}.
     */
    @Deprecated
    public void onStartedWakingUp() { }

    /**
     * Called when the device has started going to sleep.
     * @param why see {@link #onFinishedGoingToSleep(int)}
     *
     * @deprecated use {@link com.android.systemui.keyguard.WakefulnessLifecycle}.
     */
    @Deprecated
    public void onStartedGoingToSleep(int why) { }

    /**
@@ -168,17 +174,26 @@ public class KeyguardUpdateMonitorCallback {
     * @param why either {@link WindowManagerPolicy#OFF_BECAUSE_OF_ADMIN},
     * {@link WindowManagerPolicy#OFF_BECAUSE_OF_USER}, or
     * {@link WindowManagerPolicy#OFF_BECAUSE_OF_TIMEOUT}.
     *
     * @deprecated use {@link com.android.systemui.keyguard.WakefulnessLifecycle}.
     */
    @Deprecated
    public void onFinishedGoingToSleep(int why) { }

    /**
     * Called when the screen has been turned on.
     *
     * @deprecated use {@link com.android.systemui.keyguard.ScreenLifecycle}.
     */
    @Deprecated
    public void onScreenTurnedOn() { }

    /**
     * Called when the screen has been turned off.
     *
     * @deprecated use {@link com.android.systemui.keyguard.ScreenLifecycle}.
     */
    @Deprecated
    public void onScreenTurnedOff() { }

    /**
+8 −0
Original line number Diff line number Diff line
@@ -30,6 +30,8 @@ import com.android.settingslib.bluetooth.LocalBluetoothManager;
import com.android.systemui.assist.AssistManager;
import com.android.systemui.colorextraction.SysuiColorExtractor;
import com.android.systemui.fragments.FragmentService;
import com.android.systemui.keyguard.ScreenLifecycle;
import com.android.systemui.keyguard.WakefulnessLifecycle;
import com.android.systemui.plugins.ActivityStarter;
import com.android.systemui.plugins.PluginActivityManager;
import com.android.systemui.plugins.PluginDependencyProvider;
@@ -248,6 +250,12 @@ public class Dependency extends SystemUI {
        mProviders.put(StatusBarIconController.class, () ->
                new StatusBarIconControllerImpl(mContext));

        mProviders.put(ScreenLifecycle.class, () ->
                new ScreenLifecycle());

        mProviders.put(WakefulnessLifecycle.class, () ->
                new WakefulnessLifecycle());

        mProviders.put(FragmentService.class, () ->
                new FragmentService(mContext));

+86 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2017 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.systemui.keyguard;

import android.os.Handler;
import android.os.Message;

import com.android.internal.policy.IKeyguardDrawnCallback;

/**
 * Dispatches the lifecycles keyguard gets from WindowManager on the main thread.
 */
public class KeyguardLifecyclesDispatcher {

    static final int SCREEN_TURNING_ON = 0;
    static final int SCREEN_TURNED_ON = 1;
    static final int SCREEN_TURNING_OFF = 2;
    static final int SCREEN_TURNED_OFF = 3;

    static final int STARTED_WAKING_UP = 4;
    static final int FINISHED_WAKING_UP = 5;
    static final int STARTED_GOING_TO_SLEEP = 6;
    static final int FINISHED_GOING_TO_SLEEP = 7;

    private final ScreenLifecycle mScreenLifecycle;
    private final WakefulnessLifecycle mWakefulnessLifecycle;

    public KeyguardLifecyclesDispatcher(ScreenLifecycle screenLifecycle,
            WakefulnessLifecycle wakefulnessLifecycle) {
        mScreenLifecycle = screenLifecycle;
        mWakefulnessLifecycle = wakefulnessLifecycle;
    }

    void dispatch(int what) {
        mHandler.obtainMessage(what).sendToTarget();
    }

    private Handler mHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            switch (msg.what) {
                case SCREEN_TURNING_ON:
                    mScreenLifecycle.dispatchScreenTurningOn();
                    break;
                case SCREEN_TURNED_ON:
                    mScreenLifecycle.dispatchScreenTurnedOn();
                    break;
                case SCREEN_TURNING_OFF:
                    mScreenLifecycle.dispatchScreenTurningOff();
                    break;
                case SCREEN_TURNED_OFF:
                    mScreenLifecycle.dispatchScreenTurnedOff();
                    break;
                case STARTED_WAKING_UP:
                    mWakefulnessLifecycle.dispatchStartedWakingUp();
                    break;
                case FINISHED_WAKING_UP:
                    mWakefulnessLifecycle.dispatchFinishedWakingUp();
                    break;
                case STARTED_GOING_TO_SLEEP:
                    mWakefulnessLifecycle.dispatchStartedGoingToSleep();
                    break;
                case FINISHED_GOING_TO_SLEEP:
                    mWakefulnessLifecycle.dispatchFinishedGoingToSleep();
                    break;
                default:
                    throw new IllegalArgumentException("Unknown message: " + msg);
            }
        }
    };

}
+28 −0
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ import com.android.internal.policy.IKeyguardDrawnCallback;
import com.android.internal.policy.IKeyguardExitCallback;
import com.android.internal.policy.IKeyguardService;
import com.android.internal.policy.IKeyguardStateCallback;
import com.android.systemui.Dependency;
import com.android.systemui.SystemUIApplication;

import static android.content.pm.PackageManager.PERMISSION_GRANTED;
@@ -40,12 +41,17 @@ public class KeyguardService extends Service {
    static final String PERMISSION = android.Manifest.permission.CONTROL_KEYGUARD;

    private KeyguardViewMediator mKeyguardViewMediator;
    private KeyguardLifecyclesDispatcher mKeyguardLifecyclesDispatcher;

    @Override
    public void onCreate() {
        ((SystemUIApplication) getApplication()).startServicesIfNeeded();
        mKeyguardViewMediator =
                ((SystemUIApplication) getApplication()).getComponent(KeyguardViewMediator.class);
        mKeyguardLifecyclesDispatcher = new KeyguardLifecyclesDispatcher(
                Dependency.get(ScreenLifecycle.class),
                Dependency.get(WakefulnessLifecycle.class));

    }

    @Override
@@ -111,12 +117,16 @@ public class KeyguardService extends Service {
        public void onStartedGoingToSleep(int reason) {
            checkPermission();
            mKeyguardViewMediator.onStartedGoingToSleep(reason);
            mKeyguardLifecyclesDispatcher.dispatch(
                    KeyguardLifecyclesDispatcher.STARTED_GOING_TO_SLEEP);
        }

        @Override // Binder interface
        public void onFinishedGoingToSleep(int reason, boolean cameraGestureTriggered) {
            checkPermission();
            mKeyguardViewMediator.onFinishedGoingToSleep(reason, cameraGestureTriggered);
            mKeyguardLifecyclesDispatcher.dispatch(
                    KeyguardLifecyclesDispatcher.FINISHED_GOING_TO_SLEEP);
        }

        @Override // Binder interface
@@ -124,6 +134,15 @@ public class KeyguardService extends Service {
            Trace.beginSection("KeyguardService.mBinder#onStartedWakingUp");
            checkPermission();
            mKeyguardViewMediator.onStartedWakingUp();
            mKeyguardLifecyclesDispatcher.dispatch(KeyguardLifecyclesDispatcher.STARTED_WAKING_UP);
            Trace.endSection();
        }

        @Override // Binder interface
        public void onFinishedWakingUp() {
            Trace.beginSection("KeyguardService.mBinder#onFinishedWakingUp");
            checkPermission();
            mKeyguardLifecyclesDispatcher.dispatch(KeyguardLifecyclesDispatcher.FINISHED_WAKING_UP);
            Trace.endSection();
        }

@@ -132,6 +151,7 @@ public class KeyguardService extends Service {
            Trace.beginSection("KeyguardService.mBinder#onScreenTurningOn");
            checkPermission();
            mKeyguardViewMediator.onScreenTurningOn(callback);
            mKeyguardLifecyclesDispatcher.dispatch(KeyguardLifecyclesDispatcher.SCREEN_TURNING_ON);
            Trace.endSection();
        }

@@ -140,13 +160,21 @@ public class KeyguardService extends Service {
            Trace.beginSection("KeyguardService.mBinder#onScreenTurnedOn");
            checkPermission();
            mKeyguardViewMediator.onScreenTurnedOn();
            mKeyguardLifecyclesDispatcher.dispatch(KeyguardLifecyclesDispatcher.SCREEN_TURNED_ON);
            Trace.endSection();
        }

        @Override // Binder interface
        public void onScreenTurningOff() {
            checkPermission();
            mKeyguardLifecyclesDispatcher.dispatch(KeyguardLifecyclesDispatcher.SCREEN_TURNING_OFF);
        }

        @Override // Binder interface
        public void onScreenTurnedOff() {
            checkPermission();
            mKeyguardViewMediator.onScreenTurnedOff();
            mKeyguardLifecyclesDispatcher.dispatch(KeyguardLifecyclesDispatcher.SCREEN_TURNED_OFF);
        }

        @Override // Binder interface
Loading