Revert "Support keyboard long-press on notifications"

This reverts commit 2ca798932ea2945184df1c5500b5b9f08af9af55.

Fixes: 65061056
Change-Id: I88bcb549b9e76958d280625a96796791b6f29060
diff --git a/packages/SystemUI/src/com/android/systemui/SwipeHelper.java b/packages/SystemUI/src/com/android/systemui/SwipeHelper.java
index 8c1b736..4b37715 100644
--- a/packages/SystemUI/src/com/android/systemui/SwipeHelper.java
+++ b/packages/SystemUI/src/com/android/systemui/SwipeHelper.java
@@ -83,6 +83,7 @@
 
     private boolean mMenuRowIntercepting;
     private boolean mLongPressSent;
+    private LongPressListener mLongPressListener;
     private Runnable mWatchLongPress;
     private final long mLongPressTimeout;
 
@@ -114,6 +115,10 @@
         mFlingAnimationUtils = new FlingAnimationUtils(context, getMaxEscapeAnimDuration() / 1000f);
     }
 
+    public void setLongPressListener(LongPressListener listener) {
+        mLongPressListener = listener;
+    }
+
     public void setDensityScale(float densityScale) {
         mDensityScale = densityScale;
     }
@@ -252,7 +257,7 @@
         }
     }
 
-    public void cancelLongPress() {
+    public void removeLongPressCallback() {
         if (mWatchLongPress != null) {
             mHandler.removeCallbacks(mWatchLongPress);
             mWatchLongPress = null;
@@ -276,14 +281,6 @@
                 mVelocityTracker.clear();
                 mCurrView = mCallback.getChildAtPosition(ev);
 
-                // The SwipeHelper sends its own long-press, don't let the view send a dupe.
-                // Queue up a cancelLongPress on the view a few ms after we see a down event.
-                mHandler.post(() -> {
-                    if (mCurrView != null) {
-                        mCurrView.cancelLongPress();
-                    }
-                });
-
                 if (mCurrView != null) {
                     onDownUpdate(mCurrView, ev);
                     mCanCurrViewBeDimissed = mCallback.canChildBeDismissed(mCurrView);
@@ -291,26 +288,33 @@
                     mInitialTouchPos = getPos(ev);
                     mPerpendicularInitialTouchPos = getPerpendicularPos(ev);
                     mTranslation = getTranslation(mCurrView);
-                    if (mWatchLongPress == null) {
-                        mWatchLongPress = new Runnable() {
-                            @Override
-                            public void run() {
-                                if (mCurrView != null && !mLongPressSent) {
-                                    mLongPressSent = true;
-                                    mCurrView.getLocationOnScreen(mTmpPos);
-                                    final int x = (int) ev.getRawX() - mTmpPos[0];
-                                    final int y = (int) ev.getRawY() - mTmpPos[1];
-                                    if (mCurrView instanceof ExpandableNotificationRow) {
-                                        ExpandableNotificationRow currRow =
-                                                (ExpandableNotificationRow) mCurrView;
-                                        currRow.setLongPressPosition(x, y);
-                                        currRow.performLongClick(x, y);
+                    if (mLongPressListener != null) {
+                        if (mWatchLongPress == null) {
+                            mWatchLongPress = new Runnable() {
+                                @Override
+                                public void run() {
+                                    if (mCurrView != null && !mLongPressSent) {
+                                        mLongPressSent = true;
+                                        mCurrView.sendAccessibilityEvent(
+                                                AccessibilityEvent.TYPE_VIEW_LONG_CLICKED);
+                                        mCurrView.getLocationOnScreen(mTmpPos);
+                                        final int x = (int) ev.getRawX() - mTmpPos[0];
+                                        final int y = (int) ev.getRawY() - mTmpPos[1];
+                                        MenuItem menuItem = null;
+                                        if (mCurrView instanceof ExpandableNotificationRow) {
+                                            menuItem = ((ExpandableNotificationRow) mCurrView)
+                                                    .getProvider().getLongpressMenuItem(mContext);
+                                        }
+                                        if (menuItem != null) {
+                                            mLongPressListener.onLongPress(mCurrView, x, y,
+                                                    menuItem);
+                                        }
                                     }
                                 }
-                            }
-                        };
+                            };
+                        }
+                        mHandler.postDelayed(mWatchLongPress, mLongPressTimeout);
                     }
-                    mHandler.postDelayed(mWatchLongPress, mLongPressTimeout);
                 }
                 break;
 
@@ -327,7 +331,7 @@
                         mDragging = true;
                         mInitialTouchPos = getPos(ev);
                         mTranslation = getTranslation(mCurrView);
-                        cancelLongPress();
+                        removeLongPressCallback();
                     }
                 }
                 break;
@@ -339,7 +343,7 @@
                 mCurrView = null;
                 mLongPressSent = false;
                 mMenuRowIntercepting = false;
-                cancelLongPress();
+                removeLongPressCallback();
                 if (captured) return true;
                 break;
         }
@@ -582,7 +586,7 @@
 
                 // We are not doing anything, make sure the long press callback
                 // is not still ticking like a bomb waiting to go off.
-                cancelLongPress();
+                removeLongPressCallback();
                 return false;
             }
         }
@@ -730,4 +734,15 @@
          */
         float getFalsingThresholdFactor();
     }
+
+    /**
+     * Equivalent to View.OnLongClickListener with coordinates
+     */
+    public interface LongPressListener {
+        /**
+         * Equivalent to {@link View.OnLongClickListener#onLongClick(View)} with coordinates
+         * @return whether the longpress was handled
+         */
+        boolean onLongPress(View v, int x, int y, MenuItem item);
+    }
 }
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/ExpandableNotificationRow.java b/packages/SystemUI/src/com/android/systemui/statusbar/ExpandableNotificationRow.java
index b43626f..7bc1a39 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/ExpandableNotificationRow.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/ExpandableNotificationRow.java
@@ -172,14 +172,6 @@
     private boolean mShowNoBackground;
     private ExpandableNotificationRow mNotificationParent;
     private OnExpandClickListener mOnExpandClickListener;
-
-    // Listener will be called when receiving a long click event.
-    // Use #setLongPressPosition to optionally assign positional data with the long press.
-    private LongPressListener mLongPressListener;
-    private boolean mLongPressPositionSet = false;
-    private int mLongPressX = 0;
-    private int mLongPressY = 0;
-
     private boolean mGroupExpansionChanging;
 
     /**
@@ -781,16 +773,6 @@
         mOnExpandClickListener = onExpandClickListener;
     }
 
-    public void setLongPressListener(LongPressListener longPressListener) {
-        mLongPressListener = longPressListener;
-    }
-
-    public void setLongPressPosition(int x, int y) {
-        mLongPressPositionSet = true;
-        mLongPressX = x;
-        mLongPressY = y;
-    }
-
     @Override
     public void setOnClickListener(@Nullable OnClickListener l) {
         super.setOnClickListener(l);
@@ -1339,25 +1321,6 @@
             mTranslateableViews.remove(mChildrenContainerStub);
             mTranslateableViews.remove(mGutsStub);
         }
-
-        setOnLongClickListener((View v) -> {
-            createMenu();
-            MenuItem menuItem = getProvider().getLongpressMenuItem(mContext);
-            if (mLongPressListener != null && menuItem != null) {
-                int x, y;
-                if (mLongPressPositionSet) {
-                    x = mLongPressX;
-                    y = mLongPressY;
-                } else {
-                    // No position assigned - use the center of the View
-                    x = getWidth() / 2;
-                    y = getHeight() / 2;
-                }
-                mLongPressPositionSet = false;
-                return mLongPressListener.onLongPress(this, x, y, menuItem);
-            }
-            return false;
-        });
     }
 
     public void resetTranslation() {
@@ -2341,15 +2304,4 @@
     protected void setChildrenContainer(NotificationChildrenContainer childrenContainer) {
         mChildrenContainer = childrenContainer;
     }
-
-    /**
-     * Equivalent to View.OnLongClickListener with coordinates
-     */
-    public interface LongPressListener {
-        /**
-         * Equivalent to {@link View.OnLongClickListener#onLongClick(View)} with coordinates
-         * @return whether the longpress was handled
-         */
-        boolean onLongPress(View v, int x, int y, MenuItem item);
-    }
 }
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/car/CarStatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/car/CarStatusBar.java
index 2c50736..680f693 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/car/CarStatusBar.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/car/CarStatusBar.java
@@ -44,7 +44,6 @@
 import com.android.systemui.recents.Recents;
 import com.android.systemui.recents.misc.SystemServicesProxy;
 import com.android.systemui.recents.misc.SystemServicesProxy.TaskStackListener;
-import com.android.systemui.statusbar.ExpandableNotificationRow;
 import com.android.systemui.statusbar.NotificationData;
 import com.android.systemui.statusbar.StatusBarState;
 import com.android.systemui.statusbar.phone.CollapsedStatusBarFragment;
@@ -248,12 +247,11 @@
     }
 
     /**
-     * Returns the
-     * {@link com.android.systemui.statusbar.ExpandableNotificationRow.LongPressListener} that will
-     * be triggered when a notification card is long-pressed.
+     * Returns the {@link com.android.systemui.SwipeHelper.LongPressListener} that will be
+     * triggered when a notification card is long-pressed.
      */
     @Override
-    protected ExpandableNotificationRow.LongPressListener getNotificationLongClicker() {
+    protected SwipeHelper.LongPressListener getNotificationLongClicker() {
         // For the automative use case, we do not want to the user to be able to interact with
         // a notification other than a regular click. As a result, just return null for the
         // long click listener.
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelView.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelView.java
index 9453035..04be357 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelView.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelView.java
@@ -700,7 +700,7 @@
                     mInitialHeightOnTouch = mQsExpansionHeight;
                     mQsTracking = true;
                     mIntercepting = false;
-                    mNotificationStackScroller.cancelLongPress();
+                    mNotificationStackScroller.removeLongPressCallback();
                 }
                 break;
             case MotionEvent.ACTION_POINTER_UP:
@@ -736,7 +736,7 @@
                     mInitialTouchY = y;
                     mInitialTouchX = x;
                     mIntercepting = false;
-                    mNotificationStackScroller.cancelLongPress();
+                    mNotificationStackScroller.removeLongPressCallback();
                     return true;
                 }
                 break;
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java
index ad7453a..db4ea50 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java
@@ -168,6 +168,7 @@
 import com.android.systemui.Prefs;
 import com.android.systemui.R;
 import com.android.systemui.RecentsComponent;
+import com.android.systemui.SwipeHelper;
 import com.android.systemui.SystemUI;
 import com.android.systemui.SystemUIFactory;
 import com.android.systemui.UiOffloadThread;
@@ -4939,7 +4940,7 @@
 
     @Override
     public void onTouchSlopExceeded() {
-        mStackScroller.cancelLongPress();
+        mStackScroller.removeLongPressCallback();
         mStackScroller.checkSnoozeLeavebehind();
     }
 
@@ -5575,7 +5576,7 @@
 
         @Override
         public void onDoubleTap(float screenX, float screenY) {
-            if (screenX > 0 && screenY > 0 && mAmbientIndicationContainer != null
+            if (screenX > 0 && screenY > 0 && mAmbientIndicationContainer != null 
                 && mAmbientIndicationContainer.getVisibility() == View.VISIBLE) {
                 mAmbientIndicationContainer.getLocationOnScreen(mTmpInt2);
                 float viewX = screenX - mTmpInt2[0];
@@ -6421,15 +6422,14 @@
                 true /* removeControls */, x, y, true /* resetMenu */);
     }
 
-    protected ExpandableNotificationRow.LongPressListener getNotificationLongClicker() {
-        return new ExpandableNotificationRow.LongPressListener() {
+    protected SwipeHelper.LongPressListener getNotificationLongClicker() {
+        return new SwipeHelper.LongPressListener() {
             @Override
             public boolean onLongPress(View v, final int x, final int y,
                     MenuItem item) {
                 if (!(v instanceof ExpandableNotificationRow)) {
                     return false;
                 }
-
                 if (v.getWindowToken() == null) {
                     Log.e(TAG, "Trying to show notification guts, but not attached to window");
                     return false;
@@ -6444,7 +6444,7 @@
                     closeAndSaveGuts(false /* removeLeavebehind */, false /* force */,
                             true /* removeControls */, -1 /* x */, -1 /* y */,
                             true /* resetMenu */);
-                    return true;
+                    return false;
                 }
                 bindGuts(row, item);
                 NotificationGuts guts = row.getGuts();
@@ -6730,7 +6730,6 @@
         row.setOnExpandClickListener(this);
         row.setRemoteViewClickHandler(mOnClickHandler);
         row.setInflationCallback(this);
-        row.setLongPressListener(getNotificationLongClicker());
 
         // Get the app name.
         // Note that Notification.Builder#bindHeaderAppName has similar logic
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/stack/NotificationStackScrollLayout.java b/packages/SystemUI/src/com/android/systemui/statusbar/stack/NotificationStackScrollLayout.java
index dcf7439..c2da72b 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/stack/NotificationStackScrollLayout.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/stack/NotificationStackScrollLayout.java
@@ -241,7 +241,7 @@
      * motion.
      */
     private int mMaxScrollAfterExpand;
-    private ExpandableNotificationRow.LongPressListener mLongPressListener;
+    private SwipeHelper.LongPressListener mLongPressListener;
 
     private NotificationMenuRowPlugin mCurrMenuRow;
     private View mTranslatingParentView;
@@ -411,6 +411,7 @@
         mExpandHelper.setEventSource(this);
         mExpandHelper.setScrollAdapter(this);
         mSwipeHelper = new NotificationSwipeHelper(SwipeHelper.X, this, getContext());
+        mSwipeHelper.setLongPressListener(mLongPressListener);
         mStackScrollAlgorithm = createStackScrollAlgorithm(context);
         initView(context);
         mFalsingManager = FalsingManager.getInstance(context);
@@ -884,7 +885,8 @@
         return firstChild != null ? firstChild.getMinHeight() : mCollapsedSize;
     }
 
-    public void setLongPressListener(ExpandableNotificationRow.LongPressListener listener) {
+    public void setLongPressListener(SwipeHelper.LongPressListener listener) {
+        mSwipeHelper.setLongPressListener(listener);
         mLongPressListener = listener;
     }
 
@@ -1160,7 +1162,7 @@
         if (v instanceof ExpandableNotificationRow) {
             ((ExpandableNotificationRow) v).setUserLocked(userLocked);
         }
-        cancelLongPress();
+        removeLongPressCallback();
         requestDisallowInterceptTouchEvent(true);
     }
 
@@ -2566,7 +2568,7 @@
     public void requestDisallowInterceptTouchEvent(boolean disallowIntercept) {
         super.requestDisallowInterceptTouchEvent(disallowIntercept);
         if (disallowIntercept) {
-            cancelLongPress();
+            mSwipeHelper.removeLongPressCallback();
         }
     }
 
@@ -3287,7 +3289,7 @@
         mIsBeingDragged = isDragged;
         if (isDragged) {
             requestDisallowInterceptTouchEvent(true);
-            cancelLongPress();
+            removeLongPressCallback();
         }
     }
 
@@ -3295,7 +3297,7 @@
     public void onWindowFocusChanged(boolean hasWindowFocus) {
         super.onWindowFocusChanged(hasWindowFocus);
         if (!hasWindowFocus) {
-            cancelLongPress();
+            removeLongPressCallback();
         }
     }
 
@@ -3309,7 +3311,7 @@
 
     @Override
     public void requestDisallowLongPress() {
-        cancelLongPress();
+        removeLongPressCallback();
     }
 
     @Override
@@ -3317,8 +3319,8 @@
         mDisallowDismissInThisMotion = true;
     }
 
-    public void cancelLongPress() {
-        mSwipeHelper.cancelLongPress();
+    public void removeLongPressCallback() {
+        mSwipeHelper.removeLongPressCallback();
     }
 
     @Override