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

Commit afbbb201 authored by Luca Stefani's avatar Luca Stefani
Browse files

SystemUI: Add onStatusBarMotionEvent hook

Change-Id: I6217ce8cb64809c7d3a9a8439057e591557cbe49
parent 0847bcd8
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -17,6 +17,8 @@
package com.android.systemui.shared.recents;

import android.graphics.Rect;
import android.view.MotionEvent;

import com.android.systemui.shared.system.GraphicBufferCompat;

/**
@@ -60,4 +62,9 @@ interface ISystemUiProxy {
     * needed from current value
     */
    void setBackButtonAlpha(float alpha, boolean animate) = 8;

    /**
     * Notifies SystemUI that StatusBar is moving.
     */
    void onStatusBarMotionEvent(in MotionEvent event) = 9;
}
+44 −1
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ import android.os.PatternMatcher;
import android.os.RemoteException;
import android.os.UserHandle;
import android.util.Log;
import android.view.MotionEvent;
import android.view.SurfaceControl;

import com.android.systemui.OverviewProxyService.OverviewProxyListener;
@@ -81,6 +82,7 @@ public class OverviewProxyService implements CallbackController<OverviewProxyLis
    private int mConnectionBackoffAttempts;
    private @InteractionType int mInteractionFlags;
    private boolean mIsEnabled;
    private MotionEvent mStatusBarGestureDownEvent;

    private ISystemUiProxy mSysUiProxy = new ISystemUiProxy.Stub() {

@@ -172,6 +174,31 @@ public class OverviewProxyService implements CallbackController<OverviewProxyLis
                Binder.restoreCallingIdentity(token);
            }
        }

        public void onStatusBarMotionEvent(MotionEvent motionEvent) {
            long token = Binder.clearCallingIdentity();
            try {
                mHandler.post(() -> {
                    StatusBar statusBar = ((SystemUIApplication) mContext).getComponent(
                            StatusBar.class);
                    if (statusBar != null) {
                        statusBar.dispatchNotificationsPanelTouchEvent(motionEvent);
                        int actionMasked = motionEvent.getActionMasked();
                        if (actionMasked == MotionEvent.ACTION_DOWN) {
                            mStatusBarGestureDownEvent = MotionEvent.obtain(motionEvent);
                        }
                        if (actionMasked == MotionEvent.ACTION_UP ||
                                actionMasked == MotionEvent.ACTION_CANCEL) {
                            mStatusBarGestureDownEvent.recycle();
                            mStatusBarGestureDownEvent = null;
                        }
                        motionEvent.recycle();
                    }
                });
            } finally {
                Binder.restoreCallingIdentity(token);
            }
        }
    };

    private final Runnable mDeferredConnectionCallback = () -> {
@@ -252,7 +279,7 @@ public class OverviewProxyService implements CallbackController<OverviewProxyLis

    // This is the death handler for the binder from the launcher service
    private final IBinder.DeathRecipient mOverviewServiceDeathRcpt
            = this::startConnectionToCurrentUser;
            = this::cleanupAfterDeath;

    public OverviewProxyService(Context context) {
        mContext = context;
@@ -278,6 +305,22 @@ public class OverviewProxyService implements CallbackController<OverviewProxyLis
        }
    }

    public void cleanupAfterDeath() {
        if (mStatusBarGestureDownEvent != null) {
            mHandler.post(() -> {
                StatusBar statusBar = ((SystemUIApplication) mContext).getComponent(
                        StatusBar.class);
                if (statusBar != null) {
                    mStatusBarGestureDownEvent.setAction(MotionEvent.ACTION_CANCEL);
                    statusBar.dispatchNotificationsPanelTouchEvent(mStatusBarGestureDownEvent);
                    mStatusBarGestureDownEvent.recycle();
                    mStatusBarGestureDownEvent = null;
                }
            });
        }
        startConnectionToCurrentUser();
    }

    public void startConnectionToCurrentUser() {
        if (mHandler.getLooper() != Looper.myLooper()) {
            mHandler.post(mConnectionRunnable);
+12 −0
Original line number Diff line number Diff line
@@ -2465,6 +2465,18 @@ public class StatusBar extends SystemUI implements DemoMode, TunerService.Tunabl
        mStatusBarKeyguardViewManager.readyForKeyguardDone();
    }

    public void dispatchNotificationsPanelTouchEvent(MotionEvent motionEvent) {
        if (panelsEnabled()) {
            mNotificationPanel.dispatchTouchEvent(motionEvent);
            int action = motionEvent.getAction();
            if (action == MotionEvent.ACTION_DOWN) {
                mStatusBarWindowManager.setNotTouchable(true);
            } else if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL) {
                mStatusBarWindowManager.setNotTouchable(false);
            }
        }
    }

    @Override
    public void animateExpandNotificationsPanel() {
        if (SPEW) Log.d(TAG, "animateExpand: mExpandedVisible=" + mExpandedVisible);
+15 −0
Original line number Diff line number Diff line
@@ -268,6 +268,7 @@ public class StatusBarWindowManager implements RemoteInputController.Callback, D
        applyBrightness(state);
        applyHasTopUi(state);
        applySleepToken(state);
        applyNotTouchable(state);
        if (mLp.copyFrom(mLpChanged) != 0) {
            mWindowManager.updateViewLayout(mStatusBarView, mLp);
        }
@@ -311,6 +312,14 @@ public class StatusBarWindowManager implements RemoteInputController.Callback, D
        mHasTopUiChanged = isExpanded(state);
    }

    private void applyNotTouchable(State state) {
        if (state.notTouchable) {
            mLpChanged.flags |= WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
        } else {
            mLpChanged.flags &= ~WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
        }
    }

    private void applySleepToken(State state) {
        if (state.dozing) {
            mLpChanged.privateFlags |= LayoutParams.PRIVATE_FLAG_ACQUIRES_SLEEP_TOKEN;
@@ -443,6 +452,11 @@ public class StatusBarWindowManager implements RemoteInputController.Callback, D
        apply(mCurrentState);
    }

    public void setNotTouchable(boolean notTouchable) {
        mCurrentState.notTouchable = notTouchable;
        apply(mCurrentState);
    }

    public void setStateListener(OtherwisedCollapsedListener listener) {
        mListener = listener;
    }
@@ -473,6 +487,7 @@ public class StatusBarWindowManager implements RemoteInputController.Callback, D
        boolean forceUserActivity;
        boolean backdropShowing;
        boolean wallpaperSupportsAmbientMode;
        boolean notTouchable;

        /**
         * The {@link StatusBar} state from the status bar.