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

Commit ef60a7c0 authored by Tyler Freeman's avatar Tyler Freeman
Browse files

feat(high contrast text): make high contrast text API public

This is so we can test it in CTS, so we can wait for the setting to take
effect before running the test.

It's also so Compose and other UI frameworks can check the setting and
do their own fixes and treatments of text.

Bug: 186567103
Bug: 326442372
Fix: 330241761
Flag: com.android.graphics.hwui.flags.high_contrast_text_small_text_rect
Test: atest cts/tests/tests/uirendering/src/android/uirendering/cts/testclasses/TextViewHighContrastTextTests.kt

Change-Id: I8dd5663e11c37df8aa86202d3a6f20a312ef69d5
parent e94b365d
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -54902,6 +54902,7 @@ package android.view.accessibility {
    method public boolean addAccessibilityStateChangeListener(@NonNull android.view.accessibility.AccessibilityManager.AccessibilityStateChangeListener);
    method public void addAccessibilityStateChangeListener(@NonNull android.view.accessibility.AccessibilityManager.AccessibilityStateChangeListener, @Nullable android.os.Handler);
    method public void addAudioDescriptionRequestedChangeListener(@NonNull java.util.concurrent.Executor, @NonNull android.view.accessibility.AccessibilityManager.AudioDescriptionRequestedChangeListener);
    method @FlaggedApi("com.android.graphics.hwui.flags.high_contrast_text_small_text_rect") public void addHighContrastTextStateChangeListener(@NonNull java.util.concurrent.Executor, @NonNull android.view.accessibility.AccessibilityManager.HighContrastTextStateChangeListener);
    method public boolean addTouchExplorationStateChangeListener(@NonNull android.view.accessibility.AccessibilityManager.TouchExplorationStateChangeListener);
    method public void addTouchExplorationStateChangeListener(@NonNull android.view.accessibility.AccessibilityManager.TouchExplorationStateChangeListener, @Nullable android.os.Handler);
    method @ColorInt public int getAccessibilityFocusColor();
@@ -54914,12 +54915,14 @@ package android.view.accessibility {
    method public static boolean isAccessibilityButtonSupported();
    method public boolean isAudioDescriptionRequested();
    method public boolean isEnabled();
    method @FlaggedApi("com.android.graphics.hwui.flags.high_contrast_text_small_text_rect") public boolean isHighContrastTextEnabled();
    method public boolean isRequestFromAccessibilityTool();
    method public boolean isTouchExplorationEnabled();
    method public void removeAccessibilityRequestPreparer(android.view.accessibility.AccessibilityRequestPreparer);
    method public boolean removeAccessibilityServicesStateChangeListener(@NonNull android.view.accessibility.AccessibilityManager.AccessibilityServicesStateChangeListener);
    method public boolean removeAccessibilityStateChangeListener(@NonNull android.view.accessibility.AccessibilityManager.AccessibilityStateChangeListener);
    method public boolean removeAudioDescriptionRequestedChangeListener(@NonNull android.view.accessibility.AccessibilityManager.AudioDescriptionRequestedChangeListener);
    method @FlaggedApi("com.android.graphics.hwui.flags.high_contrast_text_small_text_rect") public void removeHighContrastTextStateChangeListener(@NonNull android.view.accessibility.AccessibilityManager.HighContrastTextStateChangeListener);
    method public boolean removeTouchExplorationStateChangeListener(@NonNull android.view.accessibility.AccessibilityManager.TouchExplorationStateChangeListener);
    method public void sendAccessibilityEvent(android.view.accessibility.AccessibilityEvent);
    field public static final int FLAG_CONTENT_CONTROLS = 4; // 0x4
@@ -54939,6 +54942,10 @@ package android.view.accessibility {
    method public void onAudioDescriptionRequestedChanged(boolean);
  }
  @FlaggedApi("com.android.graphics.hwui.flags.high_contrast_text_small_text_rect") public static interface AccessibilityManager.HighContrastTextStateChangeListener {
    method public void onHighContrastTextStateChanged(boolean);
  }
  public static interface AccessibilityManager.TouchExplorationStateChangeListener {
    method public void onTouchExplorationStateChanged(boolean);
  }
+7 −7
Original line number Diff line number Diff line
@@ -238,7 +238,7 @@ import android.view.accessibility.AccessibilityEvent;
import android.view.accessibility.AccessibilityInteractionClient;
import android.view.accessibility.AccessibilityManager;
import android.view.accessibility.AccessibilityManager.AccessibilityStateChangeListener;
import android.view.accessibility.AccessibilityManager.HighTextContrastChangeListener;
import android.view.accessibility.AccessibilityManager.HighContrastTextStateChangeListener;
import android.view.accessibility.AccessibilityNodeIdManager;
import android.view.accessibility.AccessibilityNodeInfo;
import android.view.accessibility.AccessibilityNodeInfo.AccessibilityAction;
@@ -1800,8 +1800,8 @@ public final class ViewRootImpl implements ViewParent,
        }
        mAccessibilityManager.addAccessibilityStateChangeListener(
                mAccessibilityInteractionConnectionManager, mHandler);
        mAccessibilityManager.addHighTextContrastStateChangeListener(
                mHighContrastTextManager, mHandler);
        mAccessibilityManager.addHighContrastTextStateChangeListener(
                mExecutor, mHighContrastTextManager);
        DisplayManagerGlobal
                .getInstance()
                .registerDisplayListener(
@@ -1838,7 +1838,7 @@ public final class ViewRootImpl implements ViewParent,
    private void unregisterListeners() {
        mAccessibilityManager.removeAccessibilityStateChangeListener(
                mAccessibilityInteractionConnectionManager);
        mAccessibilityManager.removeHighTextContrastStateChangeListener(
        mAccessibilityManager.removeHighContrastTextStateChangeListener(
                mHighContrastTextManager);
        DisplayManagerGlobal
                .getInstance()
@@ -11903,12 +11903,12 @@ public final class ViewRootImpl implements ViewParent,
        }
    }
    final class HighContrastTextManager implements HighTextContrastChangeListener {
    final class HighContrastTextManager implements HighContrastTextStateChangeListener {
        HighContrastTextManager() {
            ThreadedRenderer.setHighContrastText(mAccessibilityManager.isHighTextContrastEnabled());
            ThreadedRenderer.setHighContrastText(mAccessibilityManager.isHighContrastTextEnabled());
        }
        @Override
        public void onHighTextContrastStateChanged(boolean enabled) {
        public void onHighContrastTextStateChanged(boolean enabled) {
            ThreadedRenderer.setHighContrastText(enabled);
            // Destroy Displaylists so they can be recreated with high contrast recordings
+43 −45
Original line number Diff line number Diff line
@@ -253,7 +253,7 @@ public final class AccessibilityManager {
    boolean mIsTouchExplorationEnabled;

    @UnsupportedAppUsage(trackingBug = 123768939L)
    boolean mIsHighTextContrastEnabled;
    boolean mIsHighContrastTextEnabled;

    boolean mIsAudioDescriptionByDefaultRequested;

@@ -276,8 +276,8 @@ public final class AccessibilityManager {
    private final ArrayMap<TouchExplorationStateChangeListener, Handler>
            mTouchExplorationStateChangeListeners = new ArrayMap<>();

    private final ArrayMap<HighTextContrastChangeListener, Handler>
            mHighTextContrastStateChangeListeners = new ArrayMap<>();
    private final ArrayMap<HighContrastTextStateChangeListener, Executor>
            mHighContrastTextStateChangeListeners = new ArrayMap<>();

    private final ArrayMap<AccessibilityServicesStateChangeListener, Executor>
            mServicesStateChangeListeners = new ArrayMap<>();
@@ -356,21 +356,20 @@ public final class AccessibilityManager {
    }

    /**
     * Listener for the system high text contrast state. To listen for changes to
     * the high text contrast state on the device, implement this interface and
     * Listener for the system high contrast text state. To listen for changes to
     * the high contrast text state on the device, implement this interface and
     * register it with the system by calling
     * {@link #addHighTextContrastStateChangeListener}.
     *
     * @hide
     * {@link #addHighContrastTextStateChangeListener}.
     */
    public interface HighTextContrastChangeListener {
    @FlaggedApi(com.android.graphics.hwui.flags.Flags.FLAG_HIGH_CONTRAST_TEXT_SMALL_TEXT_RECT)
    public interface HighContrastTextStateChangeListener {

        /**
         * Called when the high text contrast enabled state changes.
         * Called when the high contrast text enabled state changes.
         *
         * @param enabled Whether high text contrast is enabled.
         * @param enabled Whether high contrast text is enabled.
         */
        void onHighTextContrastStateChanged(boolean enabled);
        void onHighContrastTextStateChanged(boolean enabled);
    }

    /**
@@ -655,24 +654,23 @@ public final class AccessibilityManager {
    }

    /**
     * Returns if the high text contrast in the system is enabled.
     * Returns if high contrast text in the system is enabled.
     * <p>
     * <strong>Note:</strong> You need to query this only if you application is
     * doing its own rendering and does not rely on the platform rendering pipeline.
     * </p>
     *
     * @return True if high text contrast is enabled, false otherwise.
     * @return True if high contrast text is enabled, false otherwise.
     *
     * @hide
     */
    @UnsupportedAppUsage
    public boolean isHighTextContrastEnabled() {
    @FlaggedApi(com.android.graphics.hwui.flags.Flags.FLAG_HIGH_CONTRAST_TEXT_SMALL_TEXT_RECT)
    public boolean isHighContrastTextEnabled() {
        synchronized (mLock) {
            IAccessibilityManager service = getServiceLocked();
            if (service == null) {
                return false;
            }
            return mIsHighTextContrastEnabled;
            return mIsHighContrastTextEnabled;
        }
    }

@@ -1303,32 +1301,32 @@ public final class AccessibilityManager {
    }

    /**
     * Registers a {@link HighTextContrastChangeListener} for changes in
     * the global high text contrast state of the system.
     * Registers a {@link HighContrastTextStateChangeListener} for changes in
     * the global high contrast text state of the system.
     *
     * @param listener The listener.
     *
     * @hide
     * @param executor a executor to call the listener from
     * @param listener The listener to be called
     */
    public void addHighTextContrastStateChangeListener(
            @NonNull HighTextContrastChangeListener listener, @Nullable Handler handler) {
    @FlaggedApi(com.android.graphics.hwui.flags.Flags.FLAG_HIGH_CONTRAST_TEXT_SMALL_TEXT_RECT)
    public void addHighContrastTextStateChangeListener(
            @NonNull @CallbackExecutor Executor executor,
            @NonNull HighContrastTextStateChangeListener listener
    ) {
        synchronized (mLock) {
            mHighTextContrastStateChangeListeners
                    .put(listener, (handler == null) ? mHandler : handler);
            mHighContrastTextStateChangeListeners.put(listener, executor);
        }
    }

    /**
     * Unregisters a {@link HighTextContrastChangeListener}.
     * Unregisters a {@link HighContrastTextStateChangeListener}.
     *
     * @param listener The listener.
     *
     * @hide
     */
    public void removeHighTextContrastStateChangeListener(
            @NonNull HighTextContrastChangeListener listener) {
    @FlaggedApi(com.android.graphics.hwui.flags.Flags.FLAG_HIGH_CONTRAST_TEXT_SMALL_TEXT_RECT)
    public void removeHighContrastTextStateChangeListener(
            @NonNull HighContrastTextStateChangeListener listener) {
        synchronized (mLock) {
            mHighTextContrastStateChangeListeners.remove(listener);
            mHighContrastTextStateChangeListeners.remove(listener);
        }
    }

@@ -1505,13 +1503,13 @@ public final class AccessibilityManager {

        final boolean wasEnabled = isEnabled();
        final boolean wasTouchExplorationEnabled = mIsTouchExplorationEnabled;
        final boolean wasHighTextContrastEnabled = mIsHighTextContrastEnabled;
        final boolean wasHighTextContrastEnabled = mIsHighContrastTextEnabled;
        final boolean wasAudioDescriptionByDefaultRequested = mIsAudioDescriptionByDefaultRequested;

        // Ensure listeners get current state from isZzzEnabled() calls.
        mIsEnabled = enabled;
        mIsTouchExplorationEnabled = touchExplorationEnabled;
        mIsHighTextContrastEnabled = highTextContrastEnabled;
        mIsHighContrastTextEnabled = highTextContrastEnabled;
        mIsAudioDescriptionByDefaultRequested = audioDescriptionEnabled;

        if (wasEnabled != isEnabled()) {
@@ -1523,7 +1521,7 @@ public final class AccessibilityManager {
        }

        if (wasHighTextContrastEnabled != highTextContrastEnabled) {
            notifyHighTextContrastStateChanged();
            notifyHighContrastTextStateChanged();
        }

        if (wasAudioDescriptionByDefaultRequested
@@ -2397,24 +2395,24 @@ public final class AccessibilityManager {
    }

    /**
     * Notifies the registered {@link HighTextContrastChangeListener}s.
     * Notifies the registered {@link HighContrastTextStateChangeListener}s.
     */
    private void notifyHighTextContrastStateChanged() {
    private void notifyHighContrastTextStateChanged() {
        final boolean isHighTextContrastEnabled;
        final ArrayMap<HighTextContrastChangeListener, Handler> listeners;
        final ArrayMap<HighContrastTextStateChangeListener, Executor> listeners;
        synchronized (mLock) {
            if (mHighTextContrastStateChangeListeners.isEmpty()) {
            if (mHighContrastTextStateChangeListeners.isEmpty()) {
                return;
            }
            isHighTextContrastEnabled = mIsHighTextContrastEnabled;
            listeners = new ArrayMap<>(mHighTextContrastStateChangeListeners);
            isHighTextContrastEnabled = mIsHighContrastTextEnabled;
            listeners = new ArrayMap<>(mHighContrastTextStateChangeListeners);
        }

        final int numListeners = listeners.size();
        for (int i = 0; i < numListeners; i++) {
            final HighTextContrastChangeListener listener = listeners.keyAt(i);
            listeners.valueAt(i).post(() ->
                    listener.onHighTextContrastStateChanged(isHighTextContrastEnabled));
            final HighContrastTextStateChangeListener listener = listeners.keyAt(i);
            listeners.valueAt(i).execute(() ->
                    listener.onHighContrastTextStateChanged(isHighTextContrastEnabled));
        }
    }

+1 −1
Original line number Diff line number Diff line
@@ -155,7 +155,7 @@ public class Canvas extends BaseCanvas {
    /**
     * Indicates whether this Canvas is drawing high contrast text.
     *
     * @see android.view.accessibility.AccessibilityManager#isHighTextContrastEnabled()
     * @see android.view.accessibility.AccessibilityManager#isHighContrastTextEnabled()
     * @return True if high contrast text is enabled, false otherwise.
     *
     * @hide