Exposing some accessibility methods and state to be used in Launcher

Bug: 130905838
Test: Verified the build with updated launcher
Change-Id: I09f77abc8c767fca8879610bc3fcef1f4da7f821
diff --git a/packages/SystemUI/shared/src/com/android/systemui/shared/recents/ISystemUiProxy.aidl b/packages/SystemUI/shared/src/com/android/systemui/shared/recents/ISystemUiProxy.aidl
index 5764fe8..6f44623 100644
--- a/packages/SystemUI/shared/src/com/android/systemui/shared/recents/ISystemUiProxy.aidl
+++ b/packages/SystemUI/shared/src/com/android/systemui/shared/recents/ISystemUiProxy.aidl
@@ -73,17 +73,6 @@
     void onStatusBarMotionEvent(in MotionEvent event) = 9;
 
     /**
-     * Get the corner radius of windows in pixels.
-     */
-    float getWindowCornerRadius() = 10;
-
-    /**
-     * If device supports live rounded corners on windows.
-     * This might be turned off for performance reasons
-     */
-    boolean supportsRoundedCornersOnWindows() = 11;
-
-    /**
      * Proxies the assistant gesture's progress started from navigation bar.
      */
     void onAssistantProgress(float progress) = 12;
@@ -97,4 +86,14 @@
      * Creates a new gesture monitor
      */
     Bundle monitorGestureInput(String name, int displayId) = 14;
+
+    /**
+     * Notifies that the accessibility button in the system's navigation area has been clicked
+     */
+    void notifyAccessibilityButtonClicked(int displayId) = 15;
+
+    /**
+     * Notifies that the accessibility button in the system's navigation area has been long clicked
+     */
+    void notifyAccessibilityButtonLongClicked() = 16;
 }
diff --git a/packages/SystemUI/shared/src/com/android/systemui/shared/system/QuickStepContract.java b/packages/SystemUI/shared/src/com/android/systemui/shared/system/QuickStepContract.java
index 4054784..3e70bad 100644
--- a/packages/SystemUI/shared/src/com/android/systemui/shared/system/QuickStepContract.java
+++ b/packages/SystemUI/shared/src/com/android/systemui/shared/system/QuickStepContract.java
@@ -52,11 +52,16 @@
     public static final int SYSUI_STATE_NAV_BAR_HIDDEN = 1 << 1;
     public static final int SYSUI_STATE_NOTIFICATION_PANEL_EXPANDED = 1 << 2;
     public static final int SYSUI_STATE_BOUNCER_SHOWING = 1 << 3;
+    public static final int SYSUI_STATE_A11Y_BUTTON_CLICKABLE = 1 << 4;
+    public static final int SYSUI_STATE_A11Y_BUTTON_LONG_CLICKABLE = 1 << 5;
 
     @Retention(RetentionPolicy.SOURCE)
     @IntDef({SYSUI_STATE_SCREEN_PINNING,
             SYSUI_STATE_NAV_BAR_HIDDEN,
-            SYSUI_STATE_NOTIFICATION_PANEL_EXPANDED
+            SYSUI_STATE_NOTIFICATION_PANEL_EXPANDED,
+            SYSUI_STATE_BOUNCER_SHOWING,
+            SYSUI_STATE_A11Y_BUTTON_CLICKABLE,
+            SYSUI_STATE_A11Y_BUTTON_LONG_CLICKABLE
     })
     public @interface SystemUiStateFlags {}
 
diff --git a/packages/SystemUI/src/com/android/systemui/recents/OverviewProxyService.java b/packages/SystemUI/src/com/android/systemui/recents/OverviewProxyService.java
index 898f64b..ee72955 100644
--- a/packages/SystemUI/src/com/android/systemui/recents/OverviewProxyService.java
+++ b/packages/SystemUI/src/com/android/systemui/recents/OverviewProxyService.java
@@ -54,6 +54,7 @@
 import android.util.Log;
 import android.view.InputMonitor;
 import android.view.MotionEvent;
+import android.view.accessibility.AccessibilityManager;
 
 import com.android.internal.policy.ScreenDecorationsUtils;
 import com.android.systemui.Dependency;
@@ -126,6 +127,7 @@
 
     private ISystemUiProxy mSysUiProxy = new ISystemUiProxy.Stub() {
 
+        @Override
         public void startScreenPinning(int taskId) {
             if (!verifyCaller("startScreenPinning")) {
                 return;
@@ -144,6 +146,7 @@
             }
         }
 
+        @Override
         public void onStatusBarMotionEvent(MotionEvent event) {
             if (!verifyCaller("onStatusBarMotionEvent")) {
                 return;
@@ -172,6 +175,7 @@
             }
         }
 
+        @Override
         public void onSplitScreenInvoked() {
             if (!verifyCaller("onSplitScreenInvoked")) {
                 return;
@@ -187,6 +191,7 @@
             }
         }
 
+        @Override
         public void onOverviewShown(boolean fromHome) {
             if (!verifyCaller("onOverviewShown")) {
                 return;
@@ -203,6 +208,7 @@
             }
         }
 
+        @Override
         public void setInteractionState(@InteractionType int flags) {
             if (!verifyCaller("setInteractionState")) {
                 return;
@@ -223,6 +229,7 @@
             }
         }
 
+        @Override
         public Rect getNonMinimizedSplitScreenSecondaryBounds() {
             if (!verifyCaller("getNonMinimizedSplitScreenSecondaryBounds")) {
                 return null;
@@ -239,6 +246,7 @@
             }
         }
 
+        @Override
         public void setBackButtonAlpha(float alpha, boolean animate) {
             if (!verifyCaller("setBackButtonAlpha")) {
                 return;
@@ -254,30 +262,7 @@
             }
         }
 
-        public float getWindowCornerRadius() {
-            if (!verifyCaller("getWindowCornerRadius")) {
-                return 0;
-            }
-            long token = Binder.clearCallingIdentity();
-            try {
-                return mWindowCornerRadius;
-            } finally {
-                Binder.restoreCallingIdentity(token);
-            }
-        }
-
-        public boolean supportsRoundedCornersOnWindows() {
-            if (!verifyCaller("supportsRoundedCornersOnWindows")) {
-                return false;
-            }
-            long token = Binder.clearCallingIdentity();
-            try {
-                return mSupportsRoundedCornersOnWindows;
-            } finally {
-                Binder.restoreCallingIdentity(token);
-            }
-        }
-
+        @Override
         public void onAssistantProgress(@FloatRange(from = 0.0, to = 1.0) float progress) {
             if (!verifyCaller("onAssistantProgress")) {
                 return;
@@ -290,6 +275,7 @@
             }
         }
 
+        @Override
         public void startAssistant(Bundle bundle) {
             if (!verifyCaller("startAssistant")) {
                 return;
@@ -302,6 +288,7 @@
             }
         }
 
+        @Override
         public Bundle monitorGestureInput(String name, int displayId) {
             if (!verifyCaller("monitorGestureInput")) {
                 return null;
@@ -318,6 +305,35 @@
             }
         }
 
+        @Override
+        public void notifyAccessibilityButtonClicked(int displayId) {
+            if (!verifyCaller("notifyAccessibilityButtonClicked")) {
+                return;
+            }
+            long token = Binder.clearCallingIdentity();
+            try {
+                AccessibilityManager.getInstance(mContext)
+                        .notifyAccessibilityButtonClicked(displayId);
+            } finally {
+                Binder.restoreCallingIdentity(token);
+            }
+        }
+
+        @Override
+        public void notifyAccessibilityButtonLongClicked() {
+            if (!verifyCaller("notifyAccessibilityButtonLongClicked")) {
+                return;
+            }
+            long token = Binder.clearCallingIdentity();
+            try {
+                Intent intent = new Intent(AccessibilityManager.ACTION_CHOOSE_ACCESSIBILITY_BUTTON);
+                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
+                mContext.startActivityAsUser(intent, UserHandle.CURRENT);
+            } finally {
+                Binder.restoreCallingIdentity(token);
+            }
+        }
+
         private boolean verifyCaller(String reason) {
             final int callerId = Binder.getCallingUserHandle().getIdentifier();
             if (callerId != mCurrentBoundedUserId) {
@@ -515,6 +531,7 @@
                 ? SYSUI_STATE_NOTIFICATION_PANEL_EXPANDED : 0;
         mSysUiStateFlags |= bouncerShowing
                 ? SYSUI_STATE_BOUNCER_SHOWING : 0;
+        mSysUiStateFlags |= navBarFragment != null ? navBarFragment.getA11yButtonState(null) : 0;
         notifySystemUiStateFlags(mSysUiStateFlags);
     }
 
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarFragment.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarFragment.java
index 2a933a7..fd8110d 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarFragment.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarFragment.java
@@ -24,6 +24,8 @@
 
 import static com.android.systemui.recents.OverviewProxyService.OverviewProxyListener;
 import static com.android.systemui.shared.system.NavigationBarCompat.InteractionType;
+import static com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_A11Y_BUTTON_CLICKABLE;
+import static com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_A11Y_BUTTON_LONG_CLICKABLE;
 import static com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_NAV_BAR_HIDDEN;
 import static com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_SCREEN_PINNING;
 import static com.android.systemui.statusbar.phone.BarTransitions.MODE_LIGHTS_OUT;
@@ -867,6 +869,25 @@
     }
 
     private void updateAccessibilityServicesState(AccessibilityManager accessibilityManager) {
+        boolean[] feedbackEnabled = new boolean[1];
+        int flags = getA11yButtonState(feedbackEnabled);
+
+        mNavigationBarView.getRotateSuggestionButton()
+                .setAccessibilityFeedbackEnabled(feedbackEnabled[0]);
+
+        boolean clickable = (flags & SYSUI_STATE_A11Y_BUTTON_CLICKABLE) != 0;
+        boolean longClickable = (flags & SYSUI_STATE_A11Y_BUTTON_LONG_CLICKABLE) != 0;
+        mNavigationBarView.setAccessibilityButtonState(clickable, longClickable);
+        mOverviewProxyService.setSystemUiStateFlag(SYSUI_STATE_A11Y_BUTTON_CLICKABLE, clickable);
+        mOverviewProxyService.setSystemUiStateFlag(
+                SYSUI_STATE_A11Y_BUTTON_LONG_CLICKABLE, longClickable);
+    }
+
+    /**
+     * Returns the system UI flags corresponding the the current accessibility button state
+     * @param outFeedbackEnabled if non-null, sets it to true if accessibility feedback is enabled.
+     */
+    public int getA11yButtonState(@Nullable boolean[] outFeedbackEnabled) {
         int requestingServices = 0;
         try {
             if (Settings.Secure.getIntForUser(mContentResolver,
@@ -881,7 +902,7 @@
         // AccessibilityManagerService resolves services for the current user since the local
         // AccessibilityManager is created from a Context with the INTERACT_ACROSS_USERS permission
         final List<AccessibilityServiceInfo> services =
-                accessibilityManager.getEnabledAccessibilityServiceList(
+                mAccessibilityManager.getEnabledAccessibilityServiceList(
                         AccessibilityServiceInfo.FEEDBACK_ALL_MASK);
         for (int i = services.size() - 1; i >= 0; --i) {
             AccessibilityServiceInfo info = services.get(i);
@@ -895,12 +916,12 @@
             }
         }
 
-        mNavigationBarView.getRotateSuggestionButton()
-                .setAccessibilityFeedbackEnabled(feedbackEnabled);
+        if (outFeedbackEnabled != null) {
+            outFeedbackEnabled[0] = feedbackEnabled;
+        }
 
-        final boolean showAccessibilityButton = requestingServices >= 1;
-        final boolean targetSelection = requestingServices >= 2;
-        mNavigationBarView.setAccessibilityButtonState(showAccessibilityButton, targetSelection);
+        return (requestingServices >= 1 ? SYSUI_STATE_A11Y_BUTTON_CLICKABLE : 0)
+                | (requestingServices >= 2 ? SYSUI_STATE_A11Y_BUTTON_LONG_CLICKABLE : 0);
     }
 
     // ----- Methods that DisplayNavigationBarController talks to -----