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

Commit a5c6322d authored by Adrian Roos's avatar Adrian Roos
Browse files

AOD: Fix more flickering

Fixes an issue where waking up with fingerprint would not work correctly
if the keyguard was not locked.

Also fixes flickering when triggering the Assistant on AOD.

To achieve the above, also ensures that whenever the scrim is visible, the status bar window is expanded.

Finally, log the alpha and tint of the scrims to systrace.

Fixes: 63983663
Fixes: 63065774
Bug: 63531607
Test: Disable power key locks immediately, trigger AOD, unlock with fingerprint. Verify no flicker; Trigger Assistant from AOD in various scenarios. Verify no flicker.

Change-Id: I0db2938afdde23c1995f6ac905d4a6abdf25cdec
parent 076d6f76
Loading
Loading
Loading
Loading
+6 −2
Original line number Diff line number Diff line
@@ -40,6 +40,8 @@ import com.android.systemui.statusbar.phone.StatusBarIconController;
import com.android.systemui.statusbar.phone.StatusBarKeyguardViewManager;
import com.android.systemui.volume.VolumeDialogControllerImpl;

import java.util.function.Consumer;

/**
 * Class factory to provide customizable SystemUI components.
 */
@@ -84,8 +86,10 @@ public class SystemUIFactory {

    public ScrimController createScrimController(LightBarController lightBarController,
            ScrimView scrimBehind, ScrimView scrimInFront, View headsUpScrim,
            LockscreenWallpaper lockscreenWallpaper) {
        return new ScrimController(lightBarController, scrimBehind, scrimInFront, headsUpScrim);
            LockscreenWallpaper lockscreenWallpaper,
            Consumer<Boolean> scrimVisibleListener) {
        return new ScrimController(lightBarController, scrimBehind, scrimInFront, headsUpScrim,
                scrimVisibleListener);
    }

    public NotificationIconAreaController createNotificationIconAreaController(Context context,
+36 −3
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import android.content.Context;
import android.graphics.Color;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.os.Trace;
import android.util.MathUtils;
import android.view.View;
import android.view.ViewGroup;
@@ -46,6 +47,8 @@ import com.android.systemui.statusbar.ScrimView;
import com.android.systemui.statusbar.policy.OnHeadsUpChangedListener;
import com.android.systemui.statusbar.stack.ViewState;

import java.util.function.Consumer;

/**
 * Controls both the scrim behind the notifications and in front of the notifications (when a
 * security method gets shown).
@@ -125,12 +128,16 @@ public class ScrimController implements ViewTreeObserver.OnPreDrawListener,
    private boolean mWakingUpFromAodInProgress;
    /** Wake up from AOD transition is animating; need to reset when animation finishes */
    private boolean mWakingUpFromAodAnimationRunning;
    private boolean mScrimsVisble;
    private final Consumer<Boolean> mScrimVisibleListener;

    public ScrimController(LightBarController lightBarController, ScrimView scrimBehind,
            ScrimView scrimInFront, View headsUpScrim) {
            ScrimView scrimInFront, View headsUpScrim,
            Consumer<Boolean> scrimVisibleListener) {
        mScrimBehind = scrimBehind;
        mScrimInFront = scrimInFront;
        mHeadsUpScrim = headsUpScrim;
        mScrimVisibleListener = scrimVisibleListener;
        final Context context = scrimBehind.getContext();
        mUnlockMethodCache = UnlockMethodCache.getInstance(context);
        mKeyguardUpdateMonitor = KeyguardUpdateMonitor.getInstance(context);
@@ -192,7 +199,11 @@ public class ScrimController implements ViewTreeObserver.OnPreDrawListener,
        scheduleUpdate();
    }

    /** Prepares the wakeUpFromAod animation (while turning on screen); Forces black scrims. */
    public void prepareWakeUpFromAod() {
        if (mWakingUpFromAodInProgress) {
            return;
        }
        mWakingUpFromAodInProgress = true;
        mWakingUpFromAodStarting = true;
        mAnimateChange = false;
@@ -200,10 +211,12 @@ public class ScrimController implements ViewTreeObserver.OnPreDrawListener,
        onPreDraw();
    }

    /** Starts the wakeUpFromAod animation (once screen is on); animate to transparent scrims. */
    public void wakeUpFromAod() {
        if (mWakeAndUnlocking || mAnimateKeyguardFadingOut) {
            // Wake and unlocking has a separate transition that must not be interfered with.
            mWakingUpFromAodStarting = false;
            mWakingUpFromAodInProgress = false;
            return;
        }
        if (mWakingUpFromAodStarting) {
@@ -218,6 +231,7 @@ public class ScrimController implements ViewTreeObserver.OnPreDrawListener,
        mWakeAndUnlocking = true;
        mAnimatingDozeUnlock = true;
        mWakingUpFromAodStarting = false;
        mWakingUpFromAodInProgress = false;
        scheduleUpdate();
    }

@@ -328,7 +342,6 @@ public class ScrimController implements ViewTreeObserver.OnPreDrawListener,
    }

    protected void updateScrims() {

        // Make sure we have the right gradients
        if (mNeedsDrawableColorUpdate) {
            mNeedsDrawableColorUpdate = false;
@@ -359,13 +372,24 @@ public class ScrimController implements ViewTreeObserver.OnPreDrawListener,
                setScrimInFrontAlpha(1f);
                setScrimBehindAlpha(0f);
            }
        } else if (!mKeyguardShowing && !mBouncerShowing) {
        } else if (!mKeyguardShowing && !mBouncerShowing && !mWakingUpFromAodStarting) {
            updateScrimNormal();
            setScrimInFrontAlpha(0);
        } else {
            updateScrimKeyguard();
        }
        mAnimateChange = false;
        dispatchScrimsVisible();
    }

    private void dispatchScrimsVisible() {
        boolean scrimsVisible = mScrimBehind.getViewAlpha() > 0 || mScrimInFront.getViewAlpha() > 0;

        if (mScrimsVisble != scrimsVisible) {
            mScrimsVisble = scrimsVisible;

            mScrimVisibleListener.accept(scrimsVisible);
        }
    }

    private void updateScrimKeyguard() {
@@ -457,6 +481,10 @@ public class ScrimController implements ViewTreeObserver.OnPreDrawListener,
            alpha = Math.max(0, Math.min(1.0f, alpha));
            scrimView.setViewAlpha(alpha);

            Trace.traceCounter(Trace.TRACE_TAG_APP,
                    scrim == mScrimInFront ? "front_scrim_alpha" : "back_scrim_alpha",
                    (int) (alpha * 255));

            int dozeTint = Color.TRANSPARENT;

            boolean dozing = mAnimatingDozeUnlock || mDozing;
@@ -464,6 +492,10 @@ public class ScrimController implements ViewTreeObserver.OnPreDrawListener,
            if (dozing || frontScrimDozing && scrim == mScrimInFront) {
                dozeTint = Color.BLACK;
            }
            Trace.traceCounter(Trace.TRACE_TAG_APP,
                    scrim == mScrimInFront ? "front_scrim_tint" : "back_scrim_tint",
                    dozeTint == Color.BLACK ? 1 : 0);

            scrimView.setTint(dozeTint);
        } else {
            scrim.setAlpha(alpha1);
@@ -477,6 +509,7 @@ public class ScrimController implements ViewTreeObserver.OnPreDrawListener,
            float alpha = (float) animation.getAnimatedValue();
            setCurrentScrimAlpha(scrim, alpha);
            updateScrimColor(scrim);
            dispatchScrimsVisible();
        });
        anim.setInterpolator(getInterpolator());
        anim.setStartDelay(mAnimationDelay);
+18 −6
Original line number Diff line number Diff line
@@ -1132,7 +1132,12 @@ public class StatusBar extends SystemUI implements DemoMode,
        ScrimView scrimInFront = (ScrimView) mStatusBarWindow.findViewById(R.id.scrim_in_front);
        View headsUpScrim = mStatusBarWindow.findViewById(R.id.heads_up_scrim);
        mScrimController = SystemUIFactory.getInstance().createScrimController(mLightBarController,
                scrimBehind, scrimInFront, headsUpScrim, mLockscreenWallpaper);
                scrimBehind, scrimInFront, headsUpScrim, mLockscreenWallpaper,
                scrimsVisible -> {
                    if (mStatusBarWindowManager != null) {
                        mStatusBarWindowManager.setScrimsVisible(scrimsVisible);
                    }
                });
        if (mScrimSrcModeEnabled) {
            Runnable runnable = new Runnable() {
                @Override
@@ -5171,6 +5176,9 @@ public class StatusBar extends SystemUI implements DemoMode,
            mStackScroller.setAnimationsEnabled(true);
            mVisualStabilityManager.setScreenOn(true);
            mNotificationPanel.setTouchDisabled(false);

            maybePrepareWakeUpFromAod();

            mDozeServiceHost.stopDozing();
            updateVisibleToUser();
            updateIsKeyguard();
@@ -5183,11 +5191,7 @@ public class StatusBar extends SystemUI implements DemoMode,
            mFalsingManager.onScreenTurningOn();
            mNotificationPanel.onScreenTurningOn();

            int wakefulness = mWakefulnessLifecycle.getWakefulness();
            if (mDozing && (wakefulness == WAKEFULNESS_WAKING
                    || wakefulness == WAKEFULNESS_ASLEEP) && !isPulsing()) {
                mScrimController.prepareWakeUpFromAod();
            }
            maybePrepareWakeUpFromAod();

            if (mLaunchCameraOnScreenTurningOn) {
                mNotificationPanel.launchCamera(false, mLastCameraLaunchSource);
@@ -5216,6 +5220,14 @@ public class StatusBar extends SystemUI implements DemoMode,
        return mWakefulnessLifecycle.getWakefulness();
    }

    private void maybePrepareWakeUpFromAod() {
        int wakefulness = mWakefulnessLifecycle.getWakefulness();
        if (mDozing && (wakefulness == WAKEFULNESS_WAKING
                || wakefulness == WAKEFULNESS_ASLEEP) && !isPulsing()) {
            mScrimController.prepareWakeUpFromAod();
        }
    }

    private void vibrateForCameraGesture() {
        // Make sure to pass -1 for repeat so VibratorService doesn't stop us when going to sleep.
        mVibrator.vibrate(mCameraLaunchGestureVibePattern, -1 /* repeat */);
+7 −1
Original line number Diff line number Diff line
@@ -186,7 +186,7 @@ public class StatusBarWindowManager implements RemoteInputController.Callback, D
    private boolean isExpanded(State state) {
        return !state.forceCollapsed && (state.isKeyguardShowingAndNotOccluded()
                || state.panelVisible || state.keyguardFadingAway || state.bouncerShowing
                || state.headsUpShowing);
                || state.headsUpShowing || state.scrimsVisible);
    }

    private void applyFitsSystemWindows(State state) {
@@ -325,6 +325,11 @@ public class StatusBarWindowManager implements RemoteInputController.Callback, D
        apply(mCurrentState);
    }

    public void setScrimsVisible(boolean scrimsVisible) {
        mCurrentState.scrimsVisible = scrimsVisible;
        apply(mCurrentState);
    }

    public void setHeadsUpShowing(boolean showing) {
        mCurrentState.headsUpShowing = showing;
        apply(mCurrentState);
@@ -426,6 +431,7 @@ public class StatusBarWindowManager implements RemoteInputController.Callback, D
        boolean remoteInputActive;
        boolean forcePluginOpen;
        boolean dozing;
        boolean scrimsVisible;

        private boolean isKeyguardShowingAndNotOccluded() {
            return keyguardShowing && !keyguardOccluded;