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

Commit 57bb01c7 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Set accessibility ID to window surface"

parents 6697c2fe 1d56ce37
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -441,6 +441,12 @@ public final class SurfaceControl implements Parcelable {
     */
    public static final int METADATA_TASK_ID = 3;

    /**
     * Accessibility ID to allow association between surfaces and accessibility tree.
     * @hide
     */
    public static final int METADATA_ACCESSIBILITY_ID = 4;

    /**
     * A wrapper around GraphicBuffer that contains extra information about how to
     * interpret the screenshot GraphicBuffer.
+16 −4
Original line number Diff line number Diff line
@@ -972,6 +972,9 @@ public class AccessibilityWindowManager {
        if (shouldComputeWindows) {
            mWindowManagerInternal.computeWindowsForAccessibility(displayId);
        }

        mWindowManagerInternal.setAccessibilityIdToSurfaceMetadata(
                windowToken.asBinder(), windowId);
        return windowId;
    }

@@ -991,7 +994,7 @@ public class AccessibilityWindowManager {
            final int removedWindowId = removeAccessibilityInteractionConnectionInternalLocked(
                    token, mGlobalWindowTokens, mGlobalInteractionConnections);
            if (removedWindowId >= 0) {
                onAccessibilityInteractionConnectionRemovedLocked(removedWindowId);
                onAccessibilityInteractionConnectionRemovedLocked(removedWindowId, token);
                if (DEBUG) {
                    Slog.i(LOG_TAG, "Removed global connection for pid:" + Binder.getCallingPid()
                            + " with windowId: " + removedWindowId + " and token: "
@@ -1007,7 +1010,8 @@ public class AccessibilityWindowManager {
                                getWindowTokensForUserLocked(userId),
                                getInteractionConnectionsForUserLocked(userId));
                if (removedWindowIdForUser >= 0) {
                    onAccessibilityInteractionConnectionRemovedLocked(removedWindowIdForUser);
                    onAccessibilityInteractionConnectionRemovedLocked(
                            removedWindowIdForUser, token);
                    if (DEBUG) {
                        Slog.i(LOG_TAG, "Removed user connection for pid:" + Binder.getCallingPid()
                                + " with windowId: " + removedWindowIdForUser + " and userId:"
@@ -1069,18 +1073,21 @@ public class AccessibilityWindowManager {
     * @param userId The userId to remove
     */
    private void removeAccessibilityInteractionConnectionLocked(int windowId, int userId) {
        IBinder window = null;
        if (userId == UserHandle.USER_ALL) {
            window = mGlobalWindowTokens.get(windowId);
            mGlobalWindowTokens.remove(windowId);
            mGlobalInteractionConnections.remove(windowId);
        } else {
            if (isValidUserForWindowTokensLocked(userId)) {
                window = getWindowTokensForUserLocked(userId).get(windowId);
                getWindowTokensForUserLocked(userId).remove(windowId);
            }
            if (isValidUserForInteractionConnectionsLocked(userId)) {
                getInteractionConnectionsForUserLocked(userId).remove(windowId);
            }
        }
        onAccessibilityInteractionConnectionRemovedLocked(windowId);
        onAccessibilityInteractionConnectionRemovedLocked(windowId, window);
        if (DEBUG) {
            Slog.i(LOG_TAG, "Removing interaction connection to windowId: " + windowId);
        }
@@ -1091,12 +1098,17 @@ public class AccessibilityWindowManager {
     *
     * @param windowId Removed windowId
     */
    private void onAccessibilityInteractionConnectionRemovedLocked(int windowId) {
    private void onAccessibilityInteractionConnectionRemovedLocked(
            int windowId, @Nullable IBinder binder) {
        // Active window will not update, if windows callback is unregistered.
        // Update active window to invalid, when its a11y interaction connection is removed.
        if (!isTrackingWindowsLocked() && windowId >= 0 && mActiveWindowId == windowId) {
            mActiveWindowId = AccessibilityWindowInfo.UNDEFINED_WINDOW_ID;
        }
        if (binder != null) {
            mWindowManagerInternal.setAccessibilityIdToSurfaceMetadata(
                    binder, AccessibilityWindowInfo.UNDEFINED_WINDOW_ID);
        }
    }

    /**
+6 −0
Original line number Diff line number Diff line
@@ -550,4 +550,10 @@ public abstract class WindowManagerInternal {
     * the next time the activities are opened.
     */
    public abstract void clearSnapshotCache();

    /**
     * Assigns accessibility ID a window surface as a layer metadata.
     */
    public abstract void setAccessibilityIdToSurfaceMetadata(
            IBinder windowToken, int accessibilityWindowId);
}
+21 −0
Original line number Diff line number Diff line
@@ -7398,6 +7398,27 @@ public class WindowManagerService extends IWindowManager.Stub
        public @Nullable KeyInterceptionInfo getKeyInterceptionInfoFromToken(IBinder inputToken) {
            return mKeyInterceptionInfoForToken.get(inputToken);
        }

        @Override
        public void setAccessibilityIdToSurfaceMetadata(
                IBinder windowToken, int accessibilityWindowId) {
            synchronized (mGlobalLock) {
                final WindowState state = mWindowMap.get(windowToken);
                if (state == null) {
                    Slog.w(TAG, "Cannot find window which accessibility connection is added to");
                    return;
                }
                try (SurfaceControl.Transaction t = new SurfaceControl.Transaction()) {
                    t.setMetadata(
                            state.mSurfaceControl,
                            SurfaceControl.METADATA_ACCESSIBILITY_ID,
                            accessibilityWindowId);
                    t.apply();
                } finally {
                    SurfaceControl.closeTransaction();
                }
            }
        }
    }

    void registerAppFreezeListener(AppFreezeListener listener) {