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

Commit 198b5dc3 authored by kwaky's avatar kwaky
Browse files

DO NOT MERGE Create KeyguardViewController that extracts view-related logic in...

DO NOT MERGE Create KeyguardViewController that extracts view-related logic in KeyguardViewMediator and re-wire Dagger accordingly.

Prior to this change, KeyguardViewMediator used StatusBarKeyguardViewManager for making view-related changes.
This meant that KeyguardViewMediator could only be used with a specific Keyguard view that is mounted to the StatusBar.
This change makes KeyguardViewMediator compatible with any Keyguard view no matter where it is mounted, as long as it implements
the methods defined in the KeyguardViewController interface.

For AAOS, This refactorization allows us to implements our own Keyguard View and its Manager as the next step.

Bug: 150467593
Test: Build and Manual Test -- Android builds successfully on Hawk and Pixel 2 and interacting with Keyguard functionalities works.

Change-Id: Idda93514eac030f1d92523aebc9444a4d55b21d2
parent e6750fd5
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import static com.android.systemui.Dependency.LEAK_REPORT_EMAIL_NAME;

import android.content.Context;

import com.android.keyguard.KeyguardViewController;
import com.android.systemui.car.CarDeviceProvisionedControllerImpl;
import com.android.systemui.car.CarNotificationInterruptionStateProvider;
import com.android.systemui.dagger.SystemUIRootComponent;
@@ -135,6 +136,10 @@ abstract class CarSystemUIModule {
    abstract StatusBarKeyguardViewManager bindStatusBarKeyguardViewManager(
            CarStatusBarKeyguardViewManager keyguardViewManager);

    @Binds
    abstract KeyguardViewController bindKeyguardViewController(
            CarStatusBarKeyguardViewManager keyguardViewManager);

    @Binds
    abstract DeviceProvisionedController bindDeviceProvisionedController(
            CarDeviceProvisionedControllerImpl deviceProvisionedController);
+174 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2020 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.keyguard;

import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewRootImpl;

import com.android.systemui.keyguard.DismissCallbackRegistry;
import com.android.systemui.keyguard.KeyguardViewMediator;
import com.android.systemui.plugins.FalsingManager;
import com.android.systemui.statusbar.phone.BiometricUnlockController;
import com.android.systemui.statusbar.phone.KeyguardBypassController;
import com.android.systemui.statusbar.phone.NotificationPanelViewController;
import com.android.systemui.statusbar.phone.StatusBar;

/**
 *  Interface to control Keyguard View. It should be implemented by KeyguardViewManagers, which
 *  should, in turn, be injected into {@link KeyguardViewMediator}.
 */
public interface KeyguardViewController {
    /**
     * Shows Keyguard.
     * @param options
     */
    void show(Bundle options);

    /**
     * Hides Keyguard with the fade-out animation as configured by the parameters provided.
     *
     * @param startTime
     * @param fadeoutDuration
     */
    void hide(long startTime, long fadeoutDuration);

    /**
     * Resets the state of Keyguard View.
     * @param hideBouncerWhenShowing
     */
    void reset(boolean hideBouncerWhenShowing);

    /**
     * Called when the device started going to sleep.
     */
    void onStartedGoingToSleep();

    /**
     * Called when the device has finished going to sleep.
     */
    void onFinishedGoingToSleep();

    /**
     * Called when the device started waking up.
     */
    void onStartedWakingUp();

    /**
     * Called when the device started turning on.
     */
    void onScreenTurningOn();

    /**
     * Called when the device has finished turning on.
     */
    void onScreenTurnedOn();

    /**
     * Sets whether the Keyguard needs input.
     * @param needsInput
     */
    void setNeedsInput(boolean needsInput);

    /**
     * Called when cancel button in bouncer is pressed.
     */
    void onCancelClicked();

    /**
     * Sets whether the keyguard is occluded by another window.
     *
     * @param occluded
     * @param animate
     */
    void setOccluded(boolean occluded, boolean animate);

    /**
     * @return Whether the keyguard is showing
     */
    boolean isShowing();

    /**
     * Dismisses the keyguard by going to the next screen or making it gone.
     */
    void dismissAndCollapse();

    /**
     * Notifies that Keyguard is just about to go away.
     */
    void keyguardGoingAway();

    /**
     * @return Whether window animation for unlock should be disabled.
     */
    boolean shouldDisableWindowAnimationsForUnlock();

    /**
     * @return Whether the keyguard is going to notification shade.
     */
    boolean isGoingToNotificationShade();

    /**
     * @return Whether subtle animation should be used for unlocking the device.
     */
    boolean isUnlockWithWallpaper();

    /**
     * @return Whether subtle animation should be used for unlocking the device.
     */
    boolean shouldSubtleWindowAnimationsForUnlock();

    /**
     * Starts the animation before we dismiss Keyguard, i.e. an disappearing animation on the
     * security view of the bouncer.
     *
     * @param finishRunnable the runnable to be run after the animation finished, or {@code null} if
     *                       no action should be run
     */
    void startPreHideAnimation(Runnable finishRunnable);

    /**
     * @return the ViewRootImpl of the View where the Keyguard is mounted.
     */
    ViewRootImpl getViewRootImpl();

    // TODO: Deprecate registerStatusBar in KeyguardViewController interface. It is currently
    //  only used for testing purposes in StatusBarKeyguardViewManager, and it prevents us from
    //  achieving complete abstraction away from where the Keyguard View is mounted.

    /**
     * Registers the StatusBar to which this Keyguard View is mounted.
     *
     * @param statusBar
     * @param container
     * @param notificationPanelViewController
     * @param biometricUnlockController
     * @param dismissCallbackRegistry
     * @param lockIconContainer
     * @param notificationContainer
     * @param bypassController
     * @param falsingManager
     */
    void registerStatusBar(StatusBar statusBar,
            ViewGroup container,
            NotificationPanelViewController notificationPanelViewController,
            BiometricUnlockController biometricUnlockController,
            DismissCallbackRegistry dismissCallbackRegistry,
            ViewGroup lockIconContainer, View notificationContainer,
            KeyguardBypassController bypassController, FalsingManager falsingManager);
}
+6 −0
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import android.content.Context;

import androidx.annotation.Nullable;

import com.android.keyguard.KeyguardViewController;
import com.android.systemui.dock.DockManager;
import com.android.systemui.dock.DockManagerImpl;
import com.android.systemui.plugins.statusbar.StatusBarStateController;
@@ -41,6 +42,7 @@ import com.android.systemui.statusbar.phone.KeyguardEnvironmentImpl;
import com.android.systemui.statusbar.phone.NotificationGroupManager;
import com.android.systemui.statusbar.phone.ShadeController;
import com.android.systemui.statusbar.phone.ShadeControllerImpl;
import com.android.systemui.statusbar.phone.StatusBarKeyguardViewManager;
import com.android.systemui.statusbar.policy.ConfigurationController;
import com.android.systemui.statusbar.policy.DeviceProvisionedController;
import com.android.systemui.statusbar.policy.DeviceProvisionedControllerImpl;
@@ -117,4 +119,8 @@ public abstract class SystemUIDefaultModule {
    @Binds
    abstract DeviceProvisionedController bindDeviceProvisionedController(
            DeviceProvisionedControllerImpl deviceProvisionedController);

    @Binds
    abstract KeyguardViewController bindKeyguardViewController(
            StatusBarKeyguardViewManager statusBarKeyguardViewManager);
}
+41 −29
Original line number Diff line number Diff line
@@ -80,6 +80,7 @@ import com.android.keyguard.KeyguardDisplayManager;
import com.android.keyguard.KeyguardSecurityView;
import com.android.keyguard.KeyguardUpdateMonitor;
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;
@@ -95,7 +96,6 @@ import com.android.systemui.statusbar.phone.KeyguardBypassController;
import com.android.systemui.statusbar.phone.NotificationPanelViewController;
import com.android.systemui.statusbar.phone.NotificationShadeWindowController;
import com.android.systemui.statusbar.phone.StatusBar;
import com.android.systemui.statusbar.phone.StatusBarKeyguardViewManager;
import com.android.systemui.util.DeviceConfigProxy;
import com.android.systemui.util.InjectionInflationController;

@@ -236,7 +236,7 @@ public class KeyguardViewMediator extends SystemUI implements Dumpable {
     */
    private PowerManager.WakeLock mShowKeyguardWakeLock;

    private final Lazy<StatusBarKeyguardViewManager> mStatusBarKeyguardViewManagerLazy;
    private final Lazy<KeyguardViewController> mKeyguardViewControllerLazy;

    // these are protected by synchronized (this)

@@ -601,7 +601,7 @@ public class KeyguardViewMediator extends SystemUI implements Dumpable {

        @Override
        public void setNeedsInput(boolean needsInput) {
            mStatusBarKeyguardViewManagerLazy.get().setNeedsInput(needsInput);
            mKeyguardViewControllerLazy.get().setNeedsInput(needsInput);
        }

        @Override
@@ -615,7 +615,7 @@ public class KeyguardViewMediator extends SystemUI implements Dumpable {
            mKeyguardDonePending = true;
            mHideAnimationRun = true;
            mHideAnimationRunning = true;
            mStatusBarKeyguardViewManagerLazy.get()
            mKeyguardViewControllerLazy.get()
                    .startPreHideAnimation(mHideAnimationFinishedRunnable);
            mHandler.sendEmptyMessageDelayed(KEYGUARD_DONE_PENDING_TIMEOUT,
                    KEYGUARD_DONE_PENDING_TIMEOUT_MS);
@@ -647,7 +647,7 @@ public class KeyguardViewMediator extends SystemUI implements Dumpable {

        @Override
        public void onCancelClicked() {
            mStatusBarKeyguardViewManagerLazy.get().onCancelClicked();
            mKeyguardViewControllerLazy.get().onCancelClicked();
        }

        @Override
@@ -715,7 +715,7 @@ public class KeyguardViewMediator extends SystemUI implements Dumpable {
            LockPatternUtils lockPatternUtils,
            BroadcastDispatcher broadcastDispatcher,
            NotificationShadeWindowController notificationShadeWindowController,
            Lazy<StatusBarKeyguardViewManager> statusBarKeyguardViewManagerLazy,
            Lazy<KeyguardViewController> statusBarKeyguardViewManagerLazy,
            DismissCallbackRegistry dismissCallbackRegistry,
            KeyguardUpdateMonitor keyguardUpdateMonitor, DumpManager dumpManager,
            @UiBackground Executor uiBgExecutor, PowerManager powerManager,
@@ -726,7 +726,7 @@ public class KeyguardViewMediator extends SystemUI implements Dumpable {
        mLockPatternUtils = lockPatternUtils;
        mBroadcastDispatcher = broadcastDispatcher;
        mNotificationShadeWindowController = notificationShadeWindowController;
        mStatusBarKeyguardViewManagerLazy = statusBarKeyguardViewManagerLazy;
        mKeyguardViewControllerLazy = statusBarKeyguardViewManagerLazy;
        mDismissCallbackRegistry = dismissCallbackRegistry;
        mUiBgExecutor = uiBgExecutor;
        mUpdateMonitor = keyguardUpdateMonitor;
@@ -1288,7 +1288,7 @@ public class KeyguardViewMediator extends SystemUI implements Dumpable {
            if (mOccluded != isOccluded) {
                mOccluded = isOccluded;
                mUpdateMonitor.setKeyguardOccluded(isOccluded);
                mStatusBarKeyguardViewManagerLazy.get().setOccluded(isOccluded, animate
                mKeyguardViewControllerLazy.get().setOccluded(isOccluded, animate
                        && mDeviceInteractive);
                adjustStatusBarLocked();
            }
@@ -1359,7 +1359,7 @@ public class KeyguardViewMediator extends SystemUI implements Dumpable {
        }

        // if the keyguard is already showing, don't bother
        if (mStatusBarKeyguardViewManagerLazy.get().isShowing()) {
        if (mKeyguardViewControllerLazy.get().isShowing()) {
            if (DEBUG) Log.d(TAG, "doKeyguard: not showing because it is already showing");
            resetStateLocked();
            return;
@@ -1423,7 +1423,7 @@ public class KeyguardViewMediator extends SystemUI implements Dumpable {
                mDismissCallbackRegistry.addCallback(callback);
            }
            mCustomMessage = message;
            mStatusBarKeyguardViewManagerLazy.get().dismissAndCollapse();
            mKeyguardViewControllerLazy.get().dismissAndCollapse();
        } else if (callback != null) {
            new DismissCallbackWrapper(callback).notifyDismissError();
        }
@@ -1690,7 +1690,7 @@ public class KeyguardViewMediator extends SystemUI implements Dumpable {
        } else if (!mHideAnimationRun) {
            mHideAnimationRun = true;
            mHideAnimationRunning = true;
            mStatusBarKeyguardViewManagerLazy.get()
            mKeyguardViewControllerLazy.get()
                    .startPreHideAnimation(mHideAnimationFinishedRunnable);
        }
    }
@@ -1847,7 +1847,7 @@ public class KeyguardViewMediator extends SystemUI implements Dumpable {
            mHiding = false;
            mWakeAndUnlocking = false;
            setShowingLocked(true);
            mStatusBarKeyguardViewManagerLazy.get().show(options);
            mKeyguardViewControllerLazy.get().show(options);
            resetKeyguardDonePendingLocked();
            mHideAnimationRun = false;
            adjustStatusBarLocked();
@@ -1872,22 +1872,22 @@ public class KeyguardViewMediator extends SystemUI implements Dumpable {
        public void run() {
            Trace.beginSection("KeyguardViewMediator.mKeyGuardGoingAwayRunnable");
            if (DEBUG) Log.d(TAG, "keyguardGoingAway");
            mStatusBarKeyguardViewManagerLazy.get().keyguardGoingAway();
            mKeyguardViewControllerLazy.get().keyguardGoingAway();

            int flags = 0;
            if (mStatusBarKeyguardViewManagerLazy.get().shouldDisableWindowAnimationsForUnlock()
            if (mKeyguardViewControllerLazy.get().shouldDisableWindowAnimationsForUnlock()
                    || (mWakeAndUnlocking && !mPulsing)) {
                flags |= WindowManagerPolicyConstants
                        .KEYGUARD_GOING_AWAY_FLAG_NO_WINDOW_ANIMATIONS;
            }
            if (mStatusBarKeyguardViewManagerLazy.get().isGoingToNotificationShade()
            if (mKeyguardViewControllerLazy.get().isGoingToNotificationShade()
                    || (mWakeAndUnlocking && mPulsing)) {
                flags |= WindowManagerPolicyConstants.KEYGUARD_GOING_AWAY_FLAG_TO_SHADE;
            }
            if (mStatusBarKeyguardViewManagerLazy.get().isUnlockWithWallpaper()) {
            if (mKeyguardViewControllerLazy.get().isUnlockWithWallpaper()) {
                flags |= WindowManagerPolicyConstants.KEYGUARD_GOING_AWAY_FLAG_WITH_WALLPAPER;
            }
            if (mStatusBarKeyguardViewManagerLazy.get().shouldSubtleWindowAnimationsForUnlock()) {
            if (mKeyguardViewControllerLazy.get().shouldSubtleWindowAnimationsForUnlock()) {
                flags |= WindowManagerPolicyConstants
                        .KEYGUARD_GOING_AWAY_FLAG_SUBTLE_WINDOW_ANIMATIONS;
            }
@@ -1973,7 +1973,7 @@ public class KeyguardViewMediator extends SystemUI implements Dumpable {
                // Hack level over 9000: To speed up wake-and-unlock sequence, force it to report
                // the next draw from here so we don't have to wait for window manager to signal
                // this to our ViewRootImpl.
                mStatusBarKeyguardViewManagerLazy.get().getViewRootImpl().setReportNextDraw();
                mKeyguardViewControllerLazy.get().getViewRootImpl().setReportNextDraw();
                notifyDrawn(mDrawnCallback);
                mDrawnCallback = null;
            }
@@ -1987,7 +1987,7 @@ public class KeyguardViewMediator extends SystemUI implements Dumpable {
            setShowingLocked(false);
            mWakeAndUnlocking = false;
            mDismissCallbackRegistry.notifyDismissSucceeded();
            mStatusBarKeyguardViewManagerLazy.get().hide(startTime, fadeoutDuration);
            mKeyguardViewControllerLazy.get().hide(startTime, fadeoutDuration);
            resetKeyguardDonePendingLocked();
            mHideAnimationRun = false;
            adjustStatusBarLocked();
@@ -2036,7 +2036,7 @@ public class KeyguardViewMediator extends SystemUI implements Dumpable {
    private void handleReset() {
        synchronized (KeyguardViewMediator.this) {
            if (DEBUG) Log.d(TAG, "handleReset");
            mStatusBarKeyguardViewManagerLazy.get().reset(true /* hideBouncerWhenShowing */);
            mKeyguardViewControllerLazy.get().reset(true /* hideBouncerWhenShowing */);
        }
    }

@@ -2049,7 +2049,7 @@ public class KeyguardViewMediator extends SystemUI implements Dumpable {
        synchronized (KeyguardViewMediator.this) {
            if (DEBUG) Log.d(TAG, "handleVerifyUnlock");
            setShowingLocked(true);
            mStatusBarKeyguardViewManagerLazy.get().dismissAndCollapse();
            mKeyguardViewControllerLazy.get().dismissAndCollapse();
        }
        Trace.endSection();
    }
@@ -2057,7 +2057,7 @@ public class KeyguardViewMediator extends SystemUI implements Dumpable {
    private void handleNotifyStartedGoingToSleep() {
        synchronized (KeyguardViewMediator.this) {
            if (DEBUG) Log.d(TAG, "handleNotifyStartedGoingToSleep");
            mStatusBarKeyguardViewManagerLazy.get().onStartedGoingToSleep();
            mKeyguardViewControllerLazy.get().onStartedGoingToSleep();
        }
    }

@@ -2068,7 +2068,7 @@ public class KeyguardViewMediator extends SystemUI implements Dumpable {
    private void handleNotifyFinishedGoingToSleep() {
        synchronized (KeyguardViewMediator.this) {
            if (DEBUG) Log.d(TAG, "handleNotifyFinishedGoingToSleep");
            mStatusBarKeyguardViewManagerLazy.get().onFinishedGoingToSleep();
            mKeyguardViewControllerLazy.get().onFinishedGoingToSleep();
        }
    }

@@ -2076,7 +2076,7 @@ public class KeyguardViewMediator extends SystemUI implements Dumpable {
        Trace.beginSection("KeyguardViewMediator#handleMotifyStartedWakingUp");
        synchronized (KeyguardViewMediator.this) {
            if (DEBUG) Log.d(TAG, "handleNotifyWakingUp");
            mStatusBarKeyguardViewManagerLazy.get().onStartedWakingUp();
            mKeyguardViewControllerLazy.get().onStartedWakingUp();
        }
        Trace.endSection();
    }
@@ -2085,7 +2085,7 @@ public class KeyguardViewMediator extends SystemUI implements Dumpable {
        Trace.beginSection("KeyguardViewMediator#handleNotifyScreenTurningOn");
        synchronized (KeyguardViewMediator.this) {
            if (DEBUG) Log.d(TAG, "handleNotifyScreenTurningOn");
            mStatusBarKeyguardViewManagerLazy.get().onScreenTurningOn();
            mKeyguardViewControllerLazy.get().onScreenTurningOn();
            if (callback != null) {
                if (mWakeAndUnlocking) {
                    mDrawnCallback = callback;
@@ -2104,7 +2104,7 @@ public class KeyguardViewMediator extends SystemUI implements Dumpable {
        }
        synchronized (this) {
            if (DEBUG) Log.d(TAG, "handleNotifyScreenTurnedOn");
            mStatusBarKeyguardViewManagerLazy.get().onScreenTurnedOn();
            mKeyguardViewControllerLazy.get().onScreenTurnedOn();
        }
        Trace.endSection();
    }
@@ -2148,14 +2148,26 @@ public class KeyguardViewMediator extends SystemUI implements Dumpable {
        Trace.endSection();
    }

    public StatusBarKeyguardViewManager registerStatusBar(StatusBar statusBar,
    /**
     * Registers the StatusBar to which the Keyguard View is mounted.
     *
     * @param statusBar
     * @param container
     * @param panelView
     * @param biometricUnlockController
     * @param lockIconContainer
     * @param notificationContainer
     * @param bypassController
     * @return the View Controller for the Keyguard View this class is mediating.
     */
    public KeyguardViewController registerStatusBar(StatusBar statusBar,
            ViewGroup container, NotificationPanelViewController panelView,
            BiometricUnlockController biometricUnlockController, ViewGroup lockIconContainer,
            View notificationContainer, KeyguardBypassController bypassController) {
        mStatusBarKeyguardViewManagerLazy.get().registerStatusBar(statusBar, container, panelView,
        mKeyguardViewControllerLazy.get().registerStatusBar(statusBar, container, panelView,
                biometricUnlockController, mDismissCallbackRegistry, lockIconContainer,
                notificationContainer, bypassController, mFalsingManager);
        return mStatusBarKeyguardViewManagerLazy.get();
        return mKeyguardViewControllerLazy.get();
    }

    public void startKeyguardExitAnimation(long startTime, long fadeoutDuration) {
+2 −2
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import android.os.PowerManager;

import com.android.internal.widget.LockPatternUtils;
import com.android.keyguard.KeyguardUpdateMonitor;
import com.android.keyguard.KeyguardViewController;
import com.android.systemui.broadcast.BroadcastDispatcher;
import com.android.systemui.dagger.qualifiers.UiBackground;
import com.android.systemui.dump.DumpManager;
@@ -30,7 +31,6 @@ import com.android.systemui.keyguard.KeyguardViewMediator;
import com.android.systemui.plugins.FalsingManager;
import com.android.systemui.statusbar.phone.NotificationShadeWindowController;
import com.android.systemui.statusbar.phone.StatusBar;
import com.android.systemui.statusbar.phone.StatusBarKeyguardViewManager;
import com.android.systemui.util.DeviceConfigProxy;

import java.util.concurrent.Executor;
@@ -57,7 +57,7 @@ public class KeyguardModule {
            LockPatternUtils lockPatternUtils,
            BroadcastDispatcher broadcastDispatcher,
            NotificationShadeWindowController notificationShadeWindowController,
            Lazy<StatusBarKeyguardViewManager> statusBarKeyguardViewManagerLazy,
            Lazy<KeyguardViewController> statusBarKeyguardViewManagerLazy,
            DismissCallbackRegistry dismissCallbackRegistry,
            KeyguardUpdateMonitor updateMonitor,
            DumpManager dumpManager,
Loading