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

Commit 247eb895 authored by Sunny Goyal's avatar Sunny Goyal
Browse files

Exposing some accessibility methods and state to be used in Launcher

Bug: 130905838
Test: Verified the build with updated launcher
Change-Id: I09f77abc8c767fca8879610bc3fcef1f4da7f821
parent 8cb52286
Loading
Loading
Loading
Loading
+10 −11
Original line number Diff line number Diff line
@@ -72,17 +72,6 @@ interface ISystemUiProxy {
     */
    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.
     */
@@ -97,4 +86,14 @@ interface ISystemUiProxy {
     * 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;
}
+6 −1
Original line number Diff line number Diff line
@@ -52,11 +52,16 @@ public class QuickStepContract {
    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 {}

+40 −23
Original line number Diff line number Diff line
@@ -54,6 +54,7 @@ import android.os.UserHandle;
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 @@ public class OverviewProxyService implements CallbackController<OverviewProxyLis

    private ISystemUiProxy mSysUiProxy = new ISystemUiProxy.Stub() {

        @Override
        public void startScreenPinning(int taskId) {
            if (!verifyCaller("startScreenPinning")) {
                return;
@@ -144,6 +146,7 @@ public class OverviewProxyService implements CallbackController<OverviewProxyLis
            }
        }

        @Override
        public void onStatusBarMotionEvent(MotionEvent event) {
            if (!verifyCaller("onStatusBarMotionEvent")) {
                return;
@@ -172,6 +175,7 @@ public class OverviewProxyService implements CallbackController<OverviewProxyLis
            }
        }

        @Override
        public void onSplitScreenInvoked() {
            if (!verifyCaller("onSplitScreenInvoked")) {
                return;
@@ -187,6 +191,7 @@ public class OverviewProxyService implements CallbackController<OverviewProxyLis
            }
        }

        @Override
        public void onOverviewShown(boolean fromHome) {
            if (!verifyCaller("onOverviewShown")) {
                return;
@@ -203,6 +208,7 @@ public class OverviewProxyService implements CallbackController<OverviewProxyLis
            }
        }

        @Override
        public void setInteractionState(@InteractionType int flags) {
            if (!verifyCaller("setInteractionState")) {
                return;
@@ -223,6 +229,7 @@ public class OverviewProxyService implements CallbackController<OverviewProxyLis
            }
        }

        @Override
        public Rect getNonMinimizedSplitScreenSecondaryBounds() {
            if (!verifyCaller("getNonMinimizedSplitScreenSecondaryBounds")) {
                return null;
@@ -239,6 +246,7 @@ public class OverviewProxyService implements CallbackController<OverviewProxyLis
            }
        }

        @Override
        public void setBackButtonAlpha(float alpha, boolean animate) {
            if (!verifyCaller("setBackButtonAlpha")) {
                return;
@@ -254,65 +262,73 @@ public class OverviewProxyService implements CallbackController<OverviewProxyLis
            }
        }

        public float getWindowCornerRadius() {
            if (!verifyCaller("getWindowCornerRadius")) {
                return 0;
        @Override
        public void onAssistantProgress(@FloatRange(from = 0.0, to = 1.0) float progress) {
            if (!verifyCaller("onAssistantProgress")) {
                return;
            }
            long token = Binder.clearCallingIdentity();
            try {
                return mWindowCornerRadius;
                mHandler.post(() -> notifyAssistantProgress(progress));
            } finally {
                Binder.restoreCallingIdentity(token);
            }
        }

        public boolean supportsRoundedCornersOnWindows() {
            if (!verifyCaller("supportsRoundedCornersOnWindows")) {
                return false;
        @Override
        public void startAssistant(Bundle bundle) {
            if (!verifyCaller("startAssistant")) {
                return;
            }
            long token = Binder.clearCallingIdentity();
            try {
                return mSupportsRoundedCornersOnWindows;
                mHandler.post(() -> notifyStartAssistant(bundle));
            } finally {
                Binder.restoreCallingIdentity(token);
            }
        }

        public void onAssistantProgress(@FloatRange(from = 0.0, to = 1.0) float progress) {
            if (!verifyCaller("onAssistantProgress")) {
                return;
        @Override
        public Bundle monitorGestureInput(String name, int displayId) {
            if (!verifyCaller("monitorGestureInput")) {
                return null;
            }
            long token = Binder.clearCallingIdentity();
            try {
                mHandler.post(() -> notifyAssistantProgress(progress));
                InputMonitor monitor =
                        InputManager.getInstance().monitorGestureInput(name, displayId);
                Bundle result = new Bundle();
                result.putParcelable(KEY_EXTRA_INPUT_MONITOR, monitor);
                return result;
            } finally {
                Binder.restoreCallingIdentity(token);
            }
        }

        public void startAssistant(Bundle bundle) {
            if (!verifyCaller("startAssistant")) {
        @Override
        public void notifyAccessibilityButtonClicked(int displayId) {
            if (!verifyCaller("notifyAccessibilityButtonClicked")) {
                return;
            }
            long token = Binder.clearCallingIdentity();
            try {
                mHandler.post(() -> notifyStartAssistant(bundle));
                AccessibilityManager.getInstance(mContext)
                        .notifyAccessibilityButtonClicked(displayId);
            } finally {
                Binder.restoreCallingIdentity(token);
            }
        }

        public Bundle monitorGestureInput(String name, int displayId) {
            if (!verifyCaller("monitorGestureInput")) {
                return null;
        @Override
        public void notifyAccessibilityButtonLongClicked() {
            if (!verifyCaller("notifyAccessibilityButtonLongClicked")) {
                return;
            }
            long token = Binder.clearCallingIdentity();
            try {
                InputMonitor monitor =
                        InputManager.getInstance().monitorGestureInput(name, displayId);
                Bundle result = new Bundle();
                result.putParcelable(KEY_EXTRA_INPUT_MONITOR, monitor);
                return result;
                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);
            }
@@ -515,6 +531,7 @@ public class OverviewProxyService implements CallbackController<OverviewProxyLis
                ? SYSUI_STATE_NOTIFICATION_PANEL_EXPANDED : 0;
        mSysUiStateFlags |= bouncerShowing
                ? SYSUI_STATE_BOUNCER_SHOWING : 0;
        mSysUiStateFlags |= navBarFragment != null ? navBarFragment.getA11yButtonState(null) : 0;
        notifySystemUiStateFlags(mSysUiStateFlags);
    }

+27 −6
Original line number Diff line number Diff line
@@ -24,6 +24,8 @@ import static android.app.StatusBarManager.windowStateToString;

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 @@ public class NavigationBarFragment extends LifecycleFragment implements Callback
    }

    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 @@ public class NavigationBarFragment extends LifecycleFragment implements Callback
        // 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 @@ public class NavigationBarFragment extends LifecycleFragment implements Callback
            }
        }

        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 -----