Fixes tapping home button on right edge with quickstep layout

Reverted ag/4731597 since it was causing issue and instead hides the
menu container when none of its children are visible.

Change-Id: Ie48ef32f8a66392796cb0330faed6dff499bc1b1
Fixes: 114099654
Test: tap around the right edge
diff --git a/packages/SystemUI/res/layout/menu_ime.xml b/packages/SystemUI/res/layout/menu_ime.xml
index b047efb..8a3a0b1 100644
--- a/packages/SystemUI/res/layout/menu_ime.xml
+++ b/packages/SystemUI/res/layout/menu_ime.xml
@@ -19,7 +19,6 @@
     android:id="@+id/menu_container"
     android:layout_width="@dimen/navigation_key_width"
     android:layout_height="match_parent"
-    android:focusable="false"
     android:importantForAccessibility="no"
     >
     <!-- Use nav button width & height=match_parent for parent FrameLayout and buttons because they
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarView.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarView.java
index 2141016..9d13ea2 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarView.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarView.java
@@ -615,6 +615,7 @@
                         ((mNavigationIconHints & StatusBarManager.NAVIGATION_HINT_IME_SHOWN) != 0);
         getImeSwitchButton().setVisibility(showImeButton ? View.VISIBLE : View.INVISIBLE);
         getImeSwitchButton().setImageDrawable(mImeIcon);
+        updateContextualContainerVisibility();
 
         // Update menu button, visibility logic in method
         setMenuVisibility(mShowMenu, true);
@@ -796,6 +797,7 @@
                 ((mNavigationIconHints & StatusBarManager.NAVIGATION_HINT_IME_SHOWN) == 0);
 
         getMenuButton().setVisibility(shouldShow ? View.VISIBLE : View.INVISIBLE);
+        updateContextualContainerVisibility();
     }
 
     public void setAccessibilityButtonState(final boolean visible, final boolean longClickable) {
@@ -810,6 +812,7 @@
 
         getAccessibilityButton().setVisibility(visible ? View.VISIBLE : View.INVISIBLE);
         getAccessibilityButton().setLongClickable(longClickable);
+        updateContextualContainerVisibility();
     }
 
     public void updateRotateSuggestionButtonStyle(@StyleRes int style, boolean setIcon) {
@@ -839,6 +842,7 @@
 
         getRotateSuggestionButton().setVisibility(vis);
         mShowRotateButton = visible;
+        updateContextualContainerVisibility();
 
         // Stop any active animations if hidden
         if (!visible && mRotateSuggestionIcon.canAnimate()) {
@@ -855,6 +859,13 @@
 
     public boolean isRotateButtonVisible() { return mShowRotateButton; }
 
+    private void updateContextualContainerVisibility() {
+        // Only show the menu container when one of its buttons are visible
+        getMenuContainer().setVisibility((mShowAccessibilityButton || mShowRotateButton || mShowMenu
+                || (mNavigationIconHints & StatusBarManager.NAVIGATION_HINT_IME_SHOWN) != 0)
+                ? VISIBLE : INVISIBLE);
+    }
+
     void hideRecentsOnboarding() {
         mRecentsOnboarding.hide(true);
     }
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NearestTouchFrame.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NearestTouchFrame.java
index 7b9ed88..09833d4 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NearestTouchFrame.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NearestTouchFrame.java
@@ -98,7 +98,6 @@
         return mClickableChildren
                 .stream()
                 .filter(v -> v.isAttachedToWindow())
-                .filter(v -> v.isFocusable())
                 .map(v -> new Pair<>(distance(v, event), v))
                 .min(Comparator.comparingInt(f -> f.first))
                 .get().second;
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/NearestTouchFrameTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/NearestTouchFrameTest.java
index 2423e14..667a508 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/NearestTouchFrameTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/NearestTouchFrameTest.java
@@ -171,23 +171,6 @@
         ev.recycle();
     }
 
-    @Test
-    public void testFurtherSelectedWhenCloserNotFocusable() {
-        View closer = mockViewAt(0, 0, 10, 10);
-        View further = mockViewAt(20, 0, 10, 10);
-        closer.setFocusable(false);
-
-        mNearestTouchFrame.addView(closer);
-        mNearestTouchFrame.addView(further);
-        mNearestTouchFrame.onMeasure(0, 0);
-
-        MotionEvent ev = MotionEvent.obtain(0, 0, 0,
-                12 /* x */, 5 /* y */, 0);
-        mNearestTouchFrame.onTouchEvent(ev);
-        verify(further).onTouchEvent(eq(ev));
-        ev.recycle();
-    }
-
     private View mockViewAt(int x, int y, int width, int height) {
         View v = spy(new View(mContext));
         doAnswer(invocation -> {
@@ -204,7 +187,6 @@
         v.setRight(width);
         v.setTop(0);
         v.setBottom(height);
-        v.setFocusable(true);
         return v;
     }
 }
\ No newline at end of file