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

Commit 21742f09 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Remove CentralSurfaces from ShadeController" into tm-qpr-dev am: b2356696 am: 2cdce64f

parents 30f462ae 2cdce64f
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -135,7 +135,7 @@ public class EmergencyButtonController extends ViewController<EmergencyButton> {
            mPowerManager.userActivity(SystemClock.uptimeMillis(), true);
        }
        mActivityTaskManager.stopSystemLockTaskMode();
        mShadeController.collapsePanel(false);
        mShadeController.collapseShade(false);
        if (mTelecomManager != null && mTelecomManager.isInCall()) {
            mTelecomManager.showInCallScreen(false);
            if (mEmergencyButtonCallback != null) {
+5 −3
Original line number Diff line number Diff line
@@ -52,6 +52,7 @@ import com.android.internal.util.ScreenshotHelper;
import com.android.systemui.CoreStartable;
import com.android.systemui.dagger.SysUISingleton;
import com.android.systemui.recents.Recents;
import com.android.systemui.shade.ShadeController;
import com.android.systemui.statusbar.CommandQueue;
import com.android.systemui.statusbar.NotificationShadeWindowController;
import com.android.systemui.statusbar.phone.CentralSurfaces;
@@ -183,15 +184,18 @@ public class SystemActions implements CoreStartable {
    private final AccessibilityManager mA11yManager;
    private final Lazy<Optional<CentralSurfaces>> mCentralSurfacesOptionalLazy;
    private final NotificationShadeWindowController mNotificationShadeController;
    private final ShadeController mShadeController;
    private final StatusBarWindowCallback mNotificationShadeCallback;
    private boolean mDismissNotificationShadeActionRegistered;

    @Inject
    public SystemActions(Context context,
            NotificationShadeWindowController notificationShadeController,
            ShadeController shadeController,
            Lazy<Optional<CentralSurfaces>> centralSurfacesOptionalLazy,
            Optional<Recents> recentsOptional) {
        mContext = context;
        mShadeController = shadeController;
        mRecentsOptional = recentsOptional;
        mReceiver = new SystemActionsBroadcastReceiver();
        mLocale = mContext.getResources().getConfiguration().getLocales().get(0);
@@ -529,9 +533,7 @@ public class SystemActions implements CoreStartable {
    }

    private void handleAccessibilityDismissNotificationShade() {
        mCentralSurfacesOptionalLazy.get().ifPresent(
                centralSurfaces -> centralSurfaces.animateCollapsePanels(
                        CommandQueue.FLAG_EXCLUDE_NONE, false /* force */));
        mShadeController.animateCollapseShade(CommandQueue.FLAG_EXCLUDE_NONE);
    }

    private void handleDpadUp() {
+1 −1
Original line number Diff line number Diff line
@@ -870,7 +870,7 @@ public class KeyguardViewMediator implements CoreStartable, Dumpable,
                @Override
                public void onLaunchAnimationEnd(boolean launchIsFullScreen) {
                    if (launchIsFullScreen) {
                        mCentralSurfaces.instantCollapseNotificationPanel();
                        mShadeController.get().instantCollapseShade();
                    }

                    mOccludeAnimationPlaying = false;
+60 −23
Original line number Diff line number Diff line
@@ -16,6 +16,9 @@

package com.android.systemui.shade;

import android.view.MotionEvent;

import com.android.systemui.statusbar.NotificationPresenter;
import com.android.systemui.statusbar.StatusBarState;
import com.android.systemui.statusbar.phone.CentralSurfaces;
import com.android.systemui.statusbar.phone.StatusBarKeyguardViewManager;
@@ -29,31 +32,32 @@ import com.android.systemui.statusbar.phone.StatusBarKeyguardViewManager;
 */
public interface ShadeController {

    /**
     * Make our window larger and the panel expanded
     */
    void instantExpandNotificationsPanel();
    /** Make our window larger and the shade expanded */
    void instantExpandShade();

    /** Collapse the shade instantly with no animation. */
    void instantCollapseShade();

    /** See {@link #animateCollapsePanels(int, boolean, boolean, float)}. */
    void animateCollapseShade();

    /** See {@link #animateCollapsePanels(int, boolean, boolean, float)}. */
    void animateCollapseShade(int flags);

    /** See {@link #animateCollapsePanels(int, boolean)}. */
    void animateCollapsePanels();
    /** See {@link #animateCollapsePanels(int, boolean, boolean, float)}. */
    void animateCollapseShadeForced();

    /** See {@link #animateCollapsePanels(int, boolean)}. */
    void animateCollapsePanels(int flags);
    /** See {@link #animateCollapsePanels(int, boolean, boolean, float)}. */
    void animateCollapseShadeDelayed();

    /**
     * Collapse the shade animated, showing the bouncer when on {@link StatusBarState#KEYGUARD} or
     * dismissing {@link CentralSurfaces} when on {@link StatusBarState#SHADE}.
     * dismissing status bar when on {@link StatusBarState#SHADE}.
     */
    void animateCollapsePanels(int flags, boolean force);

    /** See {@link #animateCollapsePanels(int, boolean)}. */
    void animateCollapsePanels(int flags, boolean force, boolean delayed);

    /** See {@link #animateCollapsePanels(int, boolean)}. */
    void animateCollapsePanels(int flags, boolean force, boolean delayed, float speedUpFactor);

    /**
     * If the notifications panel is not fully expanded, collapse it animated.
     * If the shade is not fully expanded, collapse it animated.
     *
     * @return Seems to always return false
     */
@@ -77,9 +81,7 @@ public interface ShadeController {
     */
    void addPostCollapseAction(Runnable action);

    /**
     * Run all of the runnables added by {@link #addPostCollapseAction}.
     */
    /** Run all of the runnables added by {@link #addPostCollapseAction}. */
    void runPostCollapseRunnables();

    /**
@@ -87,13 +89,48 @@ public interface ShadeController {
     *
     * @return true if the shade was open, else false
     */
    boolean collapsePanel();
    boolean collapseShade();

    /**
     * If animate is true, does the same as {@link #collapsePanel()}. Otherwise, instantly collapse
     * the panel. Post collapse runnables will be executed
     * If animate is true, does the same as {@link #collapseShade()}. Otherwise, instantly collapse
     * the shade. Post collapse runnables will be executed
     *
     * @param animate true to animate the collapse, false for instantaneous collapse
     */
    void collapsePanel(boolean animate);
    void collapseShade(boolean animate);

    /** Makes shade expanded but not visible. */
    void makeExpandedInvisible();

    /** Makes shade expanded and visible. */
    void makeExpandedVisible(boolean force);

    /** Returns whether the shade is expanded and visible. */
    boolean isExpandedVisible();

    /** Handle status bar touch event. */
    void onStatusBarTouch(MotionEvent event);

    /** Sets the listener for when the visibility of the shade changes. */
    void setVisibilityListener(ShadeVisibilityListener listener);

    /** */
    void setNotificationPresenter(NotificationPresenter presenter);

    /** */
    void setNotificationShadeWindowViewController(
            NotificationShadeWindowViewController notificationShadeWindowViewController);

    /** */
    void setNotificationPanelViewController(
            NotificationPanelViewController notificationPanelViewController);

    /** Listens for shade visibility changes. */
    interface ShadeVisibilityListener {
        /** Called when the visibility of the shade changes. */
        void visibilityChanged(boolean visible);

        /** Called when shade expanded and visible state changed. */
        void expandedVisibleChanged(boolean expandedVisible);
    }
}
+168 −64
Original line number Diff line number Diff line
@@ -16,9 +16,12 @@

package com.android.systemui.shade;

import android.content.ComponentCallbacks2;
import android.util.Log;
import android.view.MotionEvent;
import android.view.ViewTreeObserver;
import android.view.WindowManager;
import android.view.WindowManagerGlobal;

import com.android.systemui.assist.AssistManager;
import com.android.systemui.dagger.SysUISingleton;
@@ -27,11 +30,12 @@ import com.android.systemui.statusbar.CommandQueue;
import com.android.systemui.statusbar.NotificationPresenter;
import com.android.systemui.statusbar.NotificationShadeWindowController;
import com.android.systemui.statusbar.StatusBarState;
import com.android.systemui.statusbar.phone.CentralSurfaces;
import com.android.systemui.statusbar.notification.row.NotificationGutsManager;
import com.android.systemui.statusbar.phone.StatusBarKeyguardViewManager;
import com.android.systemui.statusbar.policy.KeyguardStateController;
import com.android.systemui.statusbar.window.StatusBarWindowController;

import java.util.ArrayList;
import java.util.Optional;

import javax.inject.Inject;

@@ -39,68 +43,81 @@ import dagger.Lazy;

/** An implementation of {@link ShadeController}. */
@SysUISingleton
public class ShadeControllerImpl implements ShadeController {
public final class ShadeControllerImpl implements ShadeController {

    private static final String TAG = "ShadeControllerImpl";
    private static final boolean SPEW = false;

    private final int mDisplayId;

    private final CommandQueue mCommandQueue;
    private final KeyguardStateController mKeyguardStateController;
    private final NotificationShadeWindowController mNotificationShadeWindowController;
    private final StatusBarStateController mStatusBarStateController;
    protected final NotificationShadeWindowController mNotificationShadeWindowController;
    private final StatusBarKeyguardViewManager mStatusBarKeyguardViewManager;
    private final int mDisplayId;
    protected final Lazy<Optional<CentralSurfaces>> mCentralSurfacesOptionalLazy;
    private final StatusBarWindowController mStatusBarWindowController;

    private final Lazy<AssistManager> mAssistManagerLazy;
    private final Lazy<NotificationGutsManager> mGutsManager;

    private final ArrayList<Runnable> mPostCollapseRunnables = new ArrayList<>();

    private boolean mExpandedVisible;

    private NotificationPanelViewController mNotificationPanelViewController;
    private NotificationPresenter mPresenter;
    private NotificationShadeWindowViewController mNotificationShadeWindowViewController;
    private ShadeVisibilityListener mShadeVisibilityListener;

    @Inject
    public ShadeControllerImpl(
            CommandQueue commandQueue,
            KeyguardStateController keyguardStateController,
            StatusBarStateController statusBarStateController,
            NotificationShadeWindowController notificationShadeWindowController,
            StatusBarKeyguardViewManager statusBarKeyguardViewManager,
            StatusBarWindowController statusBarWindowController,
            NotificationShadeWindowController notificationShadeWindowController,
            WindowManager windowManager,
            Lazy<Optional<CentralSurfaces>> centralSurfacesOptionalLazy,
            Lazy<AssistManager> assistManagerLazy
            Lazy<AssistManager> assistManagerLazy,
            Lazy<NotificationGutsManager> gutsManager
    ) {
        mCommandQueue = commandQueue;
        mStatusBarStateController = statusBarStateController;
        mStatusBarWindowController = statusBarWindowController;
        mGutsManager = gutsManager;
        mNotificationShadeWindowController = notificationShadeWindowController;
        mStatusBarKeyguardViewManager = statusBarKeyguardViewManager;
        mDisplayId = windowManager.getDefaultDisplay().getDisplayId();
        // TODO: Remove circular reference to CentralSurfaces when possible.
        mCentralSurfacesOptionalLazy = centralSurfacesOptionalLazy;
        mKeyguardStateController = keyguardStateController;
        mAssistManagerLazy = assistManagerLazy;
    }

    @Override
    public void instantExpandNotificationsPanel() {
    public void instantExpandShade() {
        // Make our window larger and the panel expanded.
        getCentralSurfaces().makeExpandedVisible(true /* force */);
        getNotificationPanelViewController().expand(false /* animate */);
        makeExpandedVisible(true /* force */);
        mNotificationPanelViewController.expand(false /* animate */);
        mCommandQueue.recomputeDisableFlags(mDisplayId, false /* animate */);
    }

    @Override
    public void animateCollapsePanels() {
        animateCollapsePanels(CommandQueue.FLAG_EXCLUDE_NONE);
    public void animateCollapseShade() {
        animateCollapseShade(CommandQueue.FLAG_EXCLUDE_NONE);
    }

    @Override
    public void animateCollapsePanels(int flags) {
        animateCollapsePanels(flags, false /* force */, false /* delayed */,
                1.0f /* speedUpFactor */);
    public void animateCollapseShade(int flags) {
        animateCollapsePanels(flags, false, false, 1.0f);
    }

    @Override
    public void animateCollapsePanels(int flags, boolean force) {
        animateCollapsePanels(flags, force, false /* delayed */, 1.0f /* speedUpFactor */);
    public void animateCollapseShadeForced() {
        animateCollapsePanels(CommandQueue.FLAG_EXCLUDE_NONE, true, false, 1.0f);
    }

    @Override
    public void animateCollapsePanels(int flags, boolean force, boolean delayed) {
        animateCollapsePanels(flags, force, delayed, 1.0f /* speedUpFactor */);
    public void animateCollapseShadeDelayed() {
        animateCollapsePanels(CommandQueue.FLAG_EXCLUDE_RECENTS_PANEL, true, true, 1.0f);
    }

    @Override
@@ -111,34 +128,26 @@ public class ShadeControllerImpl implements ShadeController {
            return;
        }
        if (SPEW) {
            Log.d(TAG, "animateCollapse():"
                    + " mExpandedVisible=" + getCentralSurfaces().isExpandedVisible()
                    + " flags=" + flags);
            Log.d(TAG,
                    "animateCollapse(): mExpandedVisible=" + mExpandedVisible + "flags=" + flags);
        }

        // TODO(b/62444020): remove when this bug is fixed
        Log.v(TAG, "NotificationShadeWindow: " + getNotificationShadeWindowView()
                + " canPanelBeCollapsed(): "
                + getNotificationPanelViewController().canPanelBeCollapsed());
        if (getNotificationShadeWindowView() != null
                && getNotificationPanelViewController().canPanelBeCollapsed()
                && mNotificationPanelViewController.canPanelBeCollapsed()
                && (flags & CommandQueue.FLAG_EXCLUDE_NOTIFICATION_PANEL) == 0) {
            // release focus immediately to kick off focus change transition
            mNotificationShadeWindowController.setNotificationShadeFocusable(false);

            getCentralSurfaces().getNotificationShadeWindowViewController().cancelExpandHelper();
            getNotificationPanelViewController()
                    .collapsePanel(true /* animate */, delayed, speedUpFactor);
            mNotificationShadeWindowViewController.cancelExpandHelper();
            mNotificationPanelViewController.collapsePanel(true, delayed, speedUpFactor);
        }
    }


    @Override
    public boolean closeShadeIfOpen() {
        if (!getNotificationPanelViewController().isFullyCollapsed()) {
        if (!mNotificationPanelViewController.isFullyCollapsed()) {
            mCommandQueue.animateCollapsePanels(
                    CommandQueue.FLAG_EXCLUDE_RECENTS_PANEL, true /* force */);
            getCentralSurfaces().visibilityChanged(false);
            notifyVisibilityChanged(false);
            mAssistManagerLazy.get().hideAssist();
        }
        return false;
@@ -146,21 +155,19 @@ public class ShadeControllerImpl implements ShadeController {

    @Override
    public boolean isShadeOpen() {
        NotificationPanelViewController controller =
                getNotificationPanelViewController();
        return controller.isExpanding() || controller.isFullyExpanded();
        return mNotificationPanelViewController.isExpanding()
                || mNotificationPanelViewController.isFullyExpanded();
    }

    @Override
    public void postOnShadeExpanded(Runnable executable) {
        getNotificationPanelViewController().addOnGlobalLayoutListener(
        mNotificationPanelViewController.addOnGlobalLayoutListener(
                new ViewTreeObserver.OnGlobalLayoutListener() {
                    @Override
                    public void onGlobalLayout() {
                        if (getCentralSurfaces().getNotificationShadeWindowView()
                                .isVisibleToUser()) {
                            getNotificationPanelViewController().removeOnGlobalLayoutListener(this);
                            getNotificationPanelViewController().postToView(executable);
                        if (getNotificationShadeWindowView().isVisibleToUser()) {
                            mNotificationPanelViewController.removeOnGlobalLayoutListener(this);
                            mNotificationPanelViewController.postToView(executable);
                        }
                    }
                });
@@ -183,12 +190,11 @@ public class ShadeControllerImpl implements ShadeController {
    }

    @Override
    public boolean collapsePanel() {
        if (!getNotificationPanelViewController().isFullyCollapsed()) {
    public boolean collapseShade() {
        if (!mNotificationPanelViewController.isFullyCollapsed()) {
            // close the shade if it was open
            animateCollapsePanels(CommandQueue.FLAG_EXCLUDE_RECENTS_PANEL,
                    true /* force */, true /* delayed */);
            getCentralSurfaces().visibilityChanged(false);
            animateCollapseShadeDelayed();
            notifyVisibilityChanged(false);

            return true;
        } else {
@@ -197,33 +203,131 @@ public class ShadeControllerImpl implements ShadeController {
    }

    @Override
    public void collapsePanel(boolean animate) {
    public void collapseShade(boolean animate) {
        if (animate) {
            boolean willCollapse = collapsePanel();
            boolean willCollapse = collapseShade();
            if (!willCollapse) {
                runPostCollapseRunnables();
            }
        } else if (!getPresenter().isPresenterFullyCollapsed()) {
            getCentralSurfaces().instantCollapseNotificationPanel();
            getCentralSurfaces().visibilityChanged(false);
        } else if (!mPresenter.isPresenterFullyCollapsed()) {
            instantCollapseShade();
            notifyVisibilityChanged(false);
        } else {
            runPostCollapseRunnables();
        }
    }

    private CentralSurfaces getCentralSurfaces() {
        return mCentralSurfacesOptionalLazy.get().get();
    @Override
    public void onStatusBarTouch(MotionEvent event) {
        if (event.getAction() == MotionEvent.ACTION_UP) {
            if (mExpandedVisible) {
                animateCollapseShade();
            }
        }
    }

    @Override
    public void instantCollapseShade() {
        mNotificationPanelViewController.instantCollapse();
        runPostCollapseRunnables();
    }

    @Override
    public void makeExpandedVisible(boolean force) {
        if (SPEW) Log.d(TAG, "Make expanded visible: expanded visible=" + mExpandedVisible);
        if (!force && (mExpandedVisible || !mCommandQueue.panelsEnabled())) {
            return;
        }

        mExpandedVisible = true;

        // Expand the window to encompass the full screen in anticipation of the drag.
        // It's only possible to do atomically because the status bar is at the top of the screen!
        mNotificationShadeWindowController.setPanelVisible(true);

        notifyVisibilityChanged(true);
        mCommandQueue.recomputeDisableFlags(mDisplayId, !force /* animate */);
        notifyExpandedVisibleChanged(true);
    }

    @Override
    public void makeExpandedInvisible() {
        if (SPEW) Log.d(TAG, "makeExpandedInvisible: mExpandedVisible=" + mExpandedVisible);

        if (!mExpandedVisible || getNotificationShadeWindowView() == null) {
            return;
        }

        // Ensure the panel is fully collapsed (just in case; bug 6765842, 7260868)
        mNotificationPanelViewController.collapsePanel(false, false, 1.0f);

        mNotificationPanelViewController.closeQs();

        mExpandedVisible = false;
        notifyVisibilityChanged(false);

        // Update the visibility of notification shade and status bar window.
        mNotificationShadeWindowController.setPanelVisible(false);
        mStatusBarWindowController.setForceStatusBarVisible(false);

        // Close any guts that might be visible
        mGutsManager.get().closeAndSaveGuts(
                true /* removeLeavebehind */,
                true /* force */,
                true /* removeControls */,
                -1 /* x */,
                -1 /* y */,
                true /* resetMenu */);

        runPostCollapseRunnables();
        notifyExpandedVisibleChanged(false);
        mCommandQueue.recomputeDisableFlags(
                mDisplayId,
                mNotificationPanelViewController.hideStatusBarIconsWhenExpanded() /* animate */);

        // Trimming will happen later if Keyguard is showing - doing it here might cause a jank in
        // the bouncer appear animation.
        if (!mKeyguardStateController.isShowing()) {
            WindowManagerGlobal.getInstance().trimMemory(ComponentCallbacks2.TRIM_MEMORY_UI_HIDDEN);
        }
    }

    @Override
    public boolean isExpandedVisible() {
        return mExpandedVisible;
    }

    @Override
    public void setVisibilityListener(ShadeVisibilityListener listener) {
        mShadeVisibilityListener = listener;
    }

    private NotificationPresenter getPresenter() {
        return getCentralSurfaces().getPresenter();
    private void notifyVisibilityChanged(boolean visible) {
        mShadeVisibilityListener.visibilityChanged(visible);
    }

    protected NotificationShadeWindowView getNotificationShadeWindowView() {
        return getCentralSurfaces().getNotificationShadeWindowView();
    private void notifyExpandedVisibleChanged(boolean expandedVisible) {
        mShadeVisibilityListener.expandedVisibleChanged(expandedVisible);
    }

    @Override
    public void setNotificationPresenter(NotificationPresenter presenter) {
        mPresenter = presenter;
    }

    private NotificationPanelViewController getNotificationPanelViewController() {
        return getCentralSurfaces().getNotificationPanelViewController();
    @Override
    public void setNotificationShadeWindowViewController(
            NotificationShadeWindowViewController controller) {
        mNotificationShadeWindowViewController = controller;
    }

    private NotificationShadeWindowView getNotificationShadeWindowView() {
        return mNotificationShadeWindowViewController.getView();
    }

    @Override
    public void setNotificationPanelViewController(
            NotificationPanelViewController notificationPanelViewController) {
        mNotificationPanelViewController = notificationPanelViewController;
    }
}
Loading