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

Commit 0a4050f9 authored by Josh Tsuji's avatar Josh Tsuji
Browse files

Refactor SysUI's interface with ATMS#setLockScreenShown/keyguardGoingAway.

Bug: 278086361
Test: atest SystemUITests
Change-Id: Iaacccacbbc408bf5d39b32016b981199aa36dcc0
parent 4660c49c
Loading
Loading
Loading
Loading
+9 −1
Original line number Diff line number Diff line
@@ -78,6 +78,7 @@ import com.android.systemui.classifier.FalsingCollector;
import com.android.systemui.flags.FeatureFlags;
import com.android.systemui.flags.Flags;
import com.android.systemui.keyguard.domain.interactor.KeyguardFaceAuthInteractor;
import com.android.systemui.keyguard.domain.interactor.KeyguardTransitionInteractor;
import com.android.systemui.log.SessionTracker;
import com.android.systemui.plugins.ActivityStarter;
import com.android.systemui.plugins.FalsingManager;
@@ -128,6 +129,7 @@ public class KeyguardSecurityContainerController extends ViewController<Keyguard
    private final KeyguardFaceAuthInteractor mKeyguardFaceAuthInteractor;
    private final BouncerMessageInteractor mBouncerMessageInteractor;
    private int mTranslationY;
    private final KeyguardTransitionInteractor mKeyguardTransitionInteractor;
    // Whether the volume keys should be handled by keyguard. If true, then
    // they will be handled here for specific media types such as music, otherwise
    // the audio service will bring up the volume dialog.
@@ -301,6 +303,10 @@ public class KeyguardSecurityContainerController extends ViewController<Keyguard
                    mViewMediatorCallback.keyguardDone(fromPrimaryAuth, targetUserId);
                }
            }

            if (mFeatureFlags.isEnabled(Flags.KEYGUARD_WM_STATE_REFACTOR)) {
                mKeyguardTransitionInteractor.startDismissKeyguardTransition();
            }
        }

        @Override
@@ -419,7 +425,8 @@ public class KeyguardSecurityContainerController extends ViewController<Keyguard
            Provider<JavaAdapter> javaAdapter,
            UserInteractor userInteractor,
            FaceAuthAccessibilityDelegate faceAuthAccessibilityDelegate,
            Provider<SceneInteractor> sceneInteractor
            Provider<SceneInteractor> sceneInteractor,
            KeyguardTransitionInteractor keyguardTransitionInteractor
    ) {
        super(view);
        view.setAccessibilityDelegate(faceAuthAccessibilityDelegate);
@@ -450,6 +457,7 @@ public class KeyguardSecurityContainerController extends ViewController<Keyguard
        mUserInteractor = userInteractor;
        mSceneInteractor = sceneInteractor;
        mJavaAdapter = javaAdapter;
        mKeyguardTransitionInteractor = keyguardTransitionInteractor;
    }

    @Override
+13 −0
Original line number Diff line number Diff line
@@ -286,6 +286,19 @@ object Flags {
                teamfood = true
            )

    /**
     * TODO(b/278086361): Tracking bug
     * Complete rewrite of the interactions between System UI and Window Manager involving keyguard
     * state. When enabled, calls to ActivityTaskManagerService from System UI will exclusively
     * occur from [WmLockscreenVisibilityManager] rather than the legacy KeyguardViewMediator.
     *
     * This flag is under development; some types of unlock may not animate properly if you enable
     * it.
     */
    @JvmField
    val KEYGUARD_WM_STATE_REFACTOR: UnreleasedFlag =
            unreleasedFlag("keyguard_wm_state_refactor")

    /** Stop running face auth when the display state changes to OFF. */
    // TODO(b/294221702): Tracking bug.
    @JvmField val STOP_FACE_AUTH_ON_DISPLAY_OFF = resourceBooleanFlag(
+32 −1
Original line number Diff line number Diff line
@@ -73,6 +73,14 @@ import com.android.internal.policy.IKeyguardService;
import com.android.internal.policy.IKeyguardStateCallback;
import com.android.keyguard.mediator.ScreenOnCoordinator;
import com.android.systemui.SystemUIApplication;
import com.android.systemui.dagger.qualifiers.Application;
import com.android.systemui.flags.FeatureFlags;
import com.android.systemui.flags.Flags;
import com.android.systemui.keyguard.ui.binder.KeyguardSurfaceBehindParamsApplier;
import com.android.systemui.keyguard.ui.binder.KeyguardSurfaceBehindViewBinder;
import com.android.systemui.keyguard.ui.binder.WindowManagerLockscreenVisibilityViewBinder;
import com.android.systemui.keyguard.ui.viewmodel.KeyguardSurfaceBehindViewModel;
import com.android.systemui.keyguard.ui.viewmodel.WindowManagerLockscreenVisibilityViewModel;
import com.android.systemui.settings.DisplayTracker;
import com.android.wm.shell.transition.ShellTransitions;
import com.android.wm.shell.transition.Transitions;
@@ -85,10 +93,13 @@ import java.util.WeakHashMap;

import javax.inject.Inject;

import kotlinx.coroutines.CoroutineScope;

public class KeyguardService extends Service {
    static final String TAG = "KeyguardService";
    static final String PERMISSION = android.Manifest.permission.CONTROL_KEYGUARD;

    private final FeatureFlags mFlags;
    private final KeyguardViewMediator mKeyguardViewMediator;
    private final KeyguardLifecyclesDispatcher mKeyguardLifecyclesDispatcher;
    private final ScreenOnCoordinator mScreenOnCoordinator;
@@ -291,13 +302,33 @@ public class KeyguardService extends Service {
                           KeyguardLifecyclesDispatcher keyguardLifecyclesDispatcher,
                           ScreenOnCoordinator screenOnCoordinator,
                           ShellTransitions shellTransitions,
                           DisplayTracker displayTracker) {
                           DisplayTracker displayTracker,
                           WindowManagerLockscreenVisibilityViewModel
                                   wmLockscreenVisibilityViewModel,
                           WindowManagerLockscreenVisibilityManager wmLockscreenVisibilityManager,
                           KeyguardSurfaceBehindViewModel keyguardSurfaceBehindViewModel,
                           KeyguardSurfaceBehindParamsApplier keyguardSurfaceBehindAnimator,
                           @Application CoroutineScope scope,
                           FeatureFlags featureFlags) {
        super();
        mKeyguardViewMediator = keyguardViewMediator;
        mKeyguardLifecyclesDispatcher = keyguardLifecyclesDispatcher;
        mScreenOnCoordinator = screenOnCoordinator;
        mShellTransitions = shellTransitions;
        mDisplayTracker = displayTracker;
        mFlags = featureFlags;

        if (mFlags.isEnabled(Flags.KEYGUARD_WM_STATE_REFACTOR)) {
            WindowManagerLockscreenVisibilityViewBinder.bind(
                    wmLockscreenVisibilityViewModel,
                    wmLockscreenVisibilityManager,
                    scope);

            KeyguardSurfaceBehindViewBinder.bind(
                    keyguardSurfaceBehindViewModel,
                    keyguardSurfaceBehindAnimator,
                    scope);
        }
    }

    @Override
+56 −49
Original line number Diff line number Diff line
@@ -403,7 +403,9 @@ class KeyguardUnlockAnimationController @Inject constructor(
     * the device.
     */
    fun canPerformInWindowLauncherAnimations(): Boolean {
        return isNexusLauncherUnderneath() &&
        // TODO(b/278086361): Refactor in-window animations.
        return !featureFlags.isEnabled(Flags.KEYGUARD_WM_STATE_REFACTOR) &&
                isNexusLauncherUnderneath() &&
                // If the launcher is underneath, but we're about to launch an activity, don't do
                // the animations since they won't be visible.
                !notificationShadeWindowController.isLaunchingActivity &&
@@ -847,14 +849,16 @@ class KeyguardUnlockAnimationController @Inject constructor(
        }

        surfaceBehindRemoteAnimationTargets?.forEach { surfaceBehindRemoteAnimationTarget ->
            val surfaceHeight: Int = surfaceBehindRemoteAnimationTarget.screenSpaceBounds.height()
            if (!featureFlags.isEnabled(Flags.KEYGUARD_WM_STATE_REFACTOR)) {
                val surfaceHeight: Int =
                        surfaceBehindRemoteAnimationTarget.screenSpaceBounds.height()

                var scaleFactor = (SURFACE_BEHIND_START_SCALE_FACTOR +
                        (1f - SURFACE_BEHIND_START_SCALE_FACTOR) *
                        MathUtils.clamp(amount, 0f, 1f))

            // If we're dismissing via swipe to the Launcher, we'll play in-window scale animations,
            // so don't also scale the window.
                // If we're dismissing via swipe to the Launcher, we'll play in-window scale
                // animations, so don't also scale the window.
                if (keyguardStateController.isDismissingFromSwipe &&
                        willUnlockWithInWindowLauncherAnimations) {
                    scaleFactor = 1f
@@ -897,6 +901,7 @@ class KeyguardUnlockAnimationController @Inject constructor(
                    )
                }
            }
        }

        if (wallpapers) {
            setWallpaperAppearAmount(amount)
@@ -977,10 +982,12 @@ class KeyguardUnlockAnimationController @Inject constructor(
        if (keyguardStateController.isShowing) {
            // Hide the keyguard, with no fade out since we animated it away during the unlock.

            if (!featureFlags.isEnabled(Flags.KEYGUARD_WM_STATE_REFACTOR)) {
                keyguardViewController.hide(
                        surfaceBehindRemoteAnimationStartTime,
                        0 /* fadeOutDuration */
                )
            }
        } else {
            Log.i(TAG, "#hideKeyguardViewAfterRemoteAnimation called when keyguard view is not " +
                    "showing. Ignoring...")
+77 −30
Original line number Diff line number Diff line
@@ -171,8 +171,6 @@ import com.android.systemui.util.time.SystemClock;
import com.android.systemui.wallpapers.data.repository.WallpaperRepository;
import com.android.wm.shell.keyguard.KeyguardTransitions;

import dagger.Lazy;

import java.io.PrintWriter;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@@ -182,6 +180,7 @@ import java.util.Objects;
import java.util.concurrent.Executor;
import java.util.function.Consumer;

import dagger.Lazy;
import kotlinx.coroutines.CoroutineDispatcher;

/**
@@ -1035,12 +1034,19 @@ public class KeyguardViewMediator implements CoreStartable, Dumpable,
                IRemoteAnimationFinishedCallback finishedCallback) {
            Trace.beginSection("mExitAnimationRunner.onAnimationStart#startKeyguardExitAnimation");
            startKeyguardExitAnimation(transit, apps, wallpapers, nonApps, finishedCallback);
            if (mFeatureFlags.isEnabled(Flags.KEYGUARD_WM_STATE_REFACTOR)) {
                mWmLockscreenVisibilityManager.get().onKeyguardGoingAwayRemoteAnimationStart(
                        transit, apps, wallpapers, nonApps, finishedCallback);
            }
            Trace.endSection();
        }

        @Override // Binder interface
        public void onAnimationCancelled() {
            cancelKeyguardExitAnimation();
            if (mFeatureFlags.isEnabled(Flags.KEYGUARD_WM_STATE_REFACTOR)) {
                mWmLockscreenVisibilityManager.get().onKeyguardGoingAwayRemoteAnimationCancelled();
            }
        }
    };

@@ -1106,7 +1112,7 @@ public class KeyguardViewMediator implements CoreStartable, Dumpable,

                        mOccludeByDreamAnimator = ValueAnimator.ofFloat(0f, 1f);
                        mOccludeByDreamAnimator.setDuration(mDreamOpenAnimationDuration);
                        mOccludeByDreamAnimator.setInterpolator(Interpolators.LINEAR);
                        //mOccludeByDreamAnimator.setInterpolator(Interpolators.LINEAR);
                        mOccludeByDreamAnimator.addUpdateListener(
                                animation -> {
                                    SyncRtSurfaceTransactionApplier.SurfaceParams.Builder
@@ -1336,6 +1342,8 @@ public class KeyguardViewMediator implements CoreStartable, Dumpable,
            mDreamingToLockscreenTransitionViewModel;
    private RemoteAnimationTarget mRemoteAnimationTarget;

    private Lazy<WindowManagerLockscreenVisibilityManager> mWmLockscreenVisibilityManager;

    /**
     * Injected constructor. See {@link KeyguardModule}.
     */
@@ -1379,7 +1387,8 @@ public class KeyguardViewMediator implements CoreStartable, Dumpable,
            SystemClock systemClock,
            @Main CoroutineDispatcher mainDispatcher,
            Lazy<DreamingToLockscreenTransitionViewModel> dreamingToLockscreenTransitionViewModel,
            SystemPropertiesHelper systemPropertiesHelper) {
            SystemPropertiesHelper systemPropertiesHelper,
            Lazy<WindowManagerLockscreenVisibilityManager> wmLockscreenVisibilityManager) {
        mContext = context;
        mUserTracker = userTracker;
        mFalsingCollector = falsingCollector;
@@ -1446,8 +1455,9 @@ public class KeyguardViewMediator implements CoreStartable, Dumpable,
        mUiEventLogger = uiEventLogger;
        mSessionTracker = sessionTracker;

        mMainDispatcher = mainDispatcher;
        mDreamingToLockscreenTransitionViewModel = dreamingToLockscreenTransitionViewModel;
        mWmLockscreenVisibilityManager = wmLockscreenVisibilityManager;
        mMainDispatcher = mainDispatcher;
    }

    public void userActivity() {
@@ -2685,6 +2695,12 @@ public class KeyguardViewMediator implements CoreStartable, Dumpable,
            if (DEBUG) {
                Log.d(TAG, "updateActivityLockScreenState(" + showing + ", " + aodShowing + ")");
            }

            if (mFeatureFlags.isEnabled(Flags.KEYGUARD_WM_STATE_REFACTOR)) {
                // Handled in WmLockscreenVisibilityManager if flag is enabled.
                return;
            }

            try {
                mActivityTaskManagerService.setLockScreenShown(showing, aodShowing);
            } catch (RemoteException e) {
@@ -2724,7 +2740,11 @@ public class KeyguardViewMediator implements CoreStartable, Dumpable,
            }
            mHiding = false;

            if (!mFeatureFlags.isEnabled(Flags.KEYGUARD_WM_STATE_REFACTOR)) {
                // Handled directly in StatusBarKeyguardViewManager if enabled.
                mKeyguardViewControllerLazy.get().show(options);
            }

            resetKeyguardDonePendingLocked();
            mHideAnimationRun = false;
            adjustStatusBarLocked();
@@ -2795,11 +2815,12 @@ public class KeyguardViewMediator implements CoreStartable, Dumpable,
            mUpdateMonitor.setKeyguardGoingAway(true);
            mKeyguardViewControllerLazy.get().setKeyguardGoingAwayState(true);

            // Don't actually hide the Keyguard at the moment, wait for window
            // manager until it tells us it's safe to do so with
            // startKeyguardExitAnimation.
            // Posting to mUiOffloadThread to ensure that calls to ActivityTaskManager will be in
            // order.
            // Handled in WmLockscreenVisibilityManager if flag is enabled.
            if (!mFeatureFlags.isEnabled(Flags.KEYGUARD_WM_STATE_REFACTOR)) {
                    // Don't actually hide the Keyguard at the moment, wait for window manager 
                    // until it tells us it's safe to do so with startKeyguardExitAnimation.
		    // Posting to mUiOffloadThread to ensure that calls to ActivityTaskManager 
		    // will be in order.
		    final int keyguardFlag = flags;
		    mUiBgExecutor.execute(() -> {
		        try {
@@ -2808,6 +2829,8 @@ public class KeyguardViewMediator implements CoreStartable, Dumpable,
		            Log.e(TAG, "Error while calling WindowManager", e);
		        }
		    });
            }

            Trace.endSection();
        }
    };
@@ -2919,7 +2942,10 @@ public class KeyguardViewMediator implements CoreStartable, Dumpable,
            if (!mHiding
                    && !mSurfaceBehindRemoteAnimationRequested
                    && !mKeyguardStateController.isFlingingToDismissKeyguardDuringSwipeGesture()) {
                if (finishedCallback != null) {
                // If the flag is enabled, remote animation state is handled in
                // WmLockscreenVisibilityManager.
                if (finishedCallback != null
                        && !mFeatureFlags.isEnabled(Flags.KEYGUARD_WM_STATE_REFACTOR)) {
                    // There will not execute animation, send a finish callback to ensure the remote
                    // animation won't hang there.
                    try {
@@ -2945,11 +2971,13 @@ public class KeyguardViewMediator implements CoreStartable, Dumpable,
                        new IRemoteAnimationFinishedCallback() {
                            @Override
                            public void onAnimationFinished() throws RemoteException {
                                if (!mFeatureFlags.isEnabled(Flags.KEYGUARD_WM_STATE_REFACTOR)) {
                                    try {
                                        finishedCallback.onAnimationFinished();
                                    } catch (RemoteException e) {
                                        Slog.w(TAG, "Failed to call onAnimationFinished", e);
                                    }
                                }
                                onKeyguardExitFinished();
                                mKeyguardViewControllerLazy.get().hide(0 /* startTime */,
                                        0 /* fadeoutDuration */);
@@ -2975,7 +3003,11 @@ public class KeyguardViewMediator implements CoreStartable, Dumpable,
            // it will dismiss the panel in that case.
            } else if (!mStatusBarStateController.leaveOpenOnKeyguardHide()
                    && apps != null && apps.length > 0) {
                if (!mFeatureFlags.isEnabled(Flags.KEYGUARD_WM_STATE_REFACTOR)) {
                    // Handled in WmLockscreenVisibilityManager. Other logic in this class will
                    // short circuit when this is null.
                    mSurfaceBehindRemoteAnimationFinishedCallback = finishedCallback;
                }
                mSurfaceBehindRemoteAnimationRunning = true;

                mInteractionJankMonitor.begin(
@@ -2995,7 +3027,10 @@ public class KeyguardViewMediator implements CoreStartable, Dumpable,
                        createInteractionJankMonitorConf(
                                CUJ_LOCKSCREEN_UNLOCK_ANIMATION, "RemoteAnimationDisabled"));

                if (!mFeatureFlags.isEnabled(Flags.KEYGUARD_WM_STATE_REFACTOR)) {
                    // Handled directly in StatusBarKeyguardViewManager if enabled.
                    mKeyguardViewControllerLazy.get().hide(startTime, fadeoutDuration);
                }

                // TODO(bc-animation): When remote animation is enabled for keyguard exit animation,
                // apps, wallpapers and finishedCallback are set to non-null. nonApps is not yet
@@ -3009,13 +3044,17 @@ public class KeyguardViewMediator implements CoreStartable, Dumpable,
                    }
                    if (apps == null || apps.length == 0) {
                        Slog.e(TAG, "Keyguard exit without a corresponding app to show.");

                        try {
                            if (!mFeatureFlags.isEnabled(Flags.KEYGUARD_WM_STATE_REFACTOR)) {
                                finishedCallback.onAnimationFinished();
                            }
                        } catch (RemoteException e) {
                            Slog.e(TAG, "RemoteException");
                        } finally {
                            mInteractionJankMonitor.end(CUJ_LOCKSCREEN_UNLOCK_ANIMATION);
                        }

                        return;
                    }

@@ -3039,7 +3078,9 @@ public class KeyguardViewMediator implements CoreStartable, Dumpable,
                        @Override
                        public void onAnimationEnd(Animator animation) {
                            try {
                                if (!mFeatureFlags.isEnabled(Flags.KEYGUARD_WM_STATE_REFACTOR)) {
                                    finishedCallback.onAnimationFinished();
                                }
                            } catch (RemoteException e) {
                                Slog.e(TAG, "RemoteException");
                            } finally {
@@ -3050,7 +3091,9 @@ public class KeyguardViewMediator implements CoreStartable, Dumpable,
                        @Override
                        public void onAnimationCancel(Animator animation) {
                            try {
                                if (!mFeatureFlags.isEnabled(Flags.KEYGUARD_WM_STATE_REFACTOR)) {
                                    finishedCallback.onAnimationFinished();
                                }
                            } catch (RemoteException e) {
                                Slog.e(TAG, "RemoteException");
                            } finally {
@@ -3200,7 +3243,11 @@ public class KeyguardViewMediator implements CoreStartable, Dumpable,
                flags |= KEYGUARD_GOING_AWAY_FLAG_TO_LAUNCHER_CLEAR_SNAPSHOT;
            }

            if (!mFeatureFlags.isEnabled(Flags.KEYGUARD_WM_STATE_REFACTOR)) {
                // Handled in WmLockscreenVisibilityManager.
                mActivityTaskManagerService.keyguardGoingAway(flags);
            }

            mKeyguardStateController.notifyKeyguardGoingAway(true);
        } catch (RemoteException e) {
            mSurfaceBehindRemoteAnimationRequested = false;
Loading