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

Commit e8e2865b authored by Christoph Studer's avatar Christoph Studer
Browse files

SysUI: Use mScreenOnFromKeyguard for panel visibility

We currently depend on mScreenOn when determining whether the panel
is visible to the user. However, this variable is updated via a
broadcast and might hence be slightly out-of-date with other keyguard
state.

Bug: 18067294
Change-Id: I51078b4a470db9a5a1f639e84ac65f6066c5669c
parent d3a8c8aa
Loading
Loading
Loading
Loading
+42 −18
Original line number Diff line number Diff line
@@ -155,9 +155,6 @@ public abstract class BaseStatusBar extends SystemUI implements
    protected HeadsUpNotificationView mHeadsUpNotificationView;
    protected int mHeadsUpNotificationDecay;

    // used to notify status bar for suppressing notification LED
    protected boolean mPanelSlightlyVisible;

    // Search panel
    protected SearchPanelView mSearchPanelView;

@@ -169,6 +166,20 @@ public abstract class BaseStatusBar extends SystemUI implements

    // on-screen navigation buttons
    protected NavigationBarView mNavigationBarView = null;

    protected Boolean mScreenOn;

    // The second field is a bit different from the first one because it only listens to screen on/
    // screen of events from Keyguard. We need this so we don't have a race condition with the
    // broadcast. In the future, we should remove the first field altogether and rename the second
    // field.
    protected boolean mScreenOnFromKeyguard;

    protected boolean mVisible;

    // mScreenOnFromKeyguard && mVisible.
    private boolean mVisibleToUser;

    private Locale mLocale;
    private float mFontScale;

@@ -1589,21 +1600,35 @@ public abstract class BaseStatusBar extends SystemUI implements
        }
    }

    protected void visibilityChanged(boolean visible) {
        if (mVisible != visible) {
            mVisible = visible;
            if (!visible) {
                dismissPopups();
            }
        }
        updateVisibleToUser();
    }

    protected void updateVisibleToUser() {
        boolean oldVisibleToUser = mVisibleToUser;
        mVisibleToUser = mVisible && mScreenOnFromKeyguard;

        if (oldVisibleToUser != mVisibleToUser) {
            handleVisibleToUserChanged(mVisibleToUser);
        }
    }

    /**
     * The LEDs are turned o)ff when the notification panel is shown, even just a little bit.
     * The LEDs are turned off when the notification panel is shown, even just a little bit.
     * This was added last-minute and is inconsistent with the way the rest of the notifications
     * are handled, because the notification isn't really cancelled.  The lights are just
     * turned off.  If any other notifications happen, the lights will turn back on.  Steve says
     * this is what he wants. (see bug 1131461)
     */
    protected void visibilityChanged(boolean visible) {
        if (mPanelSlightlyVisible != visible) {
            mPanelSlightlyVisible = visible;
            if (!visible) {
                dismissPopups();
            }
    protected void handleVisibleToUserChanged(boolean visibleToUser) {
        try {
                if (visible) {
            if (visibleToUser) {
                mBarService.onPanelRevealed();
            } else {
                mBarService.onPanelHidden();
@@ -1612,7 +1637,6 @@ public abstract class BaseStatusBar extends SystemUI implements
            // Won't fail unless the world has ended.
        }
    }
    }

    /**
     * Cancel this notification and tell the StatusBarManagerService / NotificationManagerService
+16 −28
Original line number Diff line number Diff line
@@ -55,7 +55,6 @@ import android.graphics.Point;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffXfermode;
import android.graphics.Rect;
import android.graphics.Xfermode;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.inputmethodservice.InputMethodService;
@@ -98,7 +97,6 @@ import android.view.ViewTreeObserver;
import android.view.WindowManager;
import android.view.WindowManagerGlobal;
import android.view.accessibility.AccessibilityEvent;
import android.view.accessibility.AccessibilityManager;
import android.view.animation.AccelerateDecelerateInterpolator;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.Animation;
@@ -409,13 +407,6 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
    private boolean mAutohideSuspended;
    private int mStatusBarMode;
    private int mNavigationBarMode;
    private Boolean mScreenOn;

    // The second field is a bit different from the first one because it only listens to screen on/
    // screen of events from Keyguard. We need this so we don't have a race condition with the
    // broadcast. In the future, we should remove the first field altogether and rename the second
    // field.
    private boolean mScreenOnFromKeyguard;

    private ViewMediatorCallback mKeyguardViewMediatorCallback;
    private ScrimController mScrimController;
@@ -429,7 +420,6 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
            }
        }};

    private boolean mVisible;
    private boolean mWaitingForKeyguardExit;
    private boolean mDozing;
    private boolean mScrimSrcModeEnabled;
@@ -3077,7 +3067,6 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
                notifyNavigationBarScreenOn(false);
                notifyHeadsUpScreenOn(false);
                finishBarAnimations();
                stopNotificationLogging();
                resetUserExpandedStates();
            }
            else if (Intent.ACTION_SCREEN_ON.equals(action)) {
@@ -3085,7 +3074,6 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
                // work around problem where mDisplay.getRotation() is not stable while screen is off (bug 7086018)
                repositionNavigationBar();
                notifyNavigationBarScreenOn(true);
                startNotificationLoggingIfScreenOnAndVisible();
            }
            else if (ACTION_DEMO.equals(action)) {
                Bundle bundle = intent.getExtras();
@@ -3274,14 +3262,14 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
    // Visibility reporting

    @Override
    protected void visibilityChanged(boolean visible) {
        mVisible = visible;
        if (visible) {
            startNotificationLoggingIfScreenOnAndVisible();
    protected void handleVisibleToUserChanged(boolean visibleToUser) {
        if (visibleToUser) {
            super.handleVisibleToUserChanged(visibleToUser);
            startNotificationLogging();
        } else {
            stopNotificationLogging();
            super.handleVisibleToUserChanged(visibleToUser);
        }
        super.visibilityChanged(visible);
    }

    private void stopNotificationLogging() {
@@ -3296,10 +3284,9 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
        mStackScroller.setChildLocationsChangedListener(null);
    }

    private void startNotificationLoggingIfScreenOnAndVisible() {
        if (mVisible && mScreenOn) {
    private void startNotificationLogging() {
        mStackScroller.setChildLocationsChangedListener(mNotificationLocationsChangedListener);
            // Some transitions like mScreenOn=false -> mScreenOn=true don't
        // Some transitions like mVisibleToUser=false -> mVisibleToUser=true don't
        // cause the scroller to emit child location events. Hence generate
        // one ourselves to guarantee that we're reporting visible
        // notifications.
@@ -3307,7 +3294,6 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
        // additional event doesn't break anything.)
        mNotificationLocationsChangedListener.onChildLocationsChanged(mStackScroller);
    }
    }

    private void logNotificationVisibilityChanges(
            Collection<String> newlyVisible, Collection<String> noLongerVisible) {
@@ -3944,6 +3930,7 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
        mScreenOnFromKeyguard = false;
        mScreenOnComingFromTouch = false;
        mStackScroller.setAnimationsEnabled(false);
        updateVisibleToUser();
    }

    public void onScreenTurnedOn() {
@@ -3951,6 +3938,7 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
        mStackScroller.setAnimationsEnabled(true);
        mNotificationPanel.onScreenTurnedOn();
        mNotificationPanel.setTouchDisabled(false);
        updateVisibleToUser();
    }

    /**