Merge "Set accessibility ID to window surface"

This commit is contained in:
TreeHugger Robot
2019-12-05 22:22:58 +00:00
committed by Android (Google) Code Review
4 changed files with 49 additions and 4 deletions

View File

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

View File

@@ -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);
}
}
/**

View File

@@ -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);
}

View File

@@ -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) {