diff --git a/core/java/android/view/WindowInfo.java b/core/java/android/view/WindowInfo.java index 57dfc62b4f8fb..1edbbba09eef9 100644 --- a/core/java/android/view/WindowInfo.java +++ b/core/java/android/view/WindowInfo.java @@ -16,6 +16,7 @@ package android.view; +import android.app.ActivityTaskManager; import android.graphics.Region; import android.os.IBinder; import android.os.Parcel; @@ -51,6 +52,7 @@ public class WindowInfo implements Parcelable { public boolean inPictureInPicture; public boolean hasFlagWatchOutsideTouch; public int displayId = Display.INVALID_DISPLAY; + public int taskId = ActivityTaskManager.INVALID_TASK_ID; private WindowInfo() { /* do nothing - hide constructor */ @@ -67,6 +69,7 @@ public class WindowInfo implements Parcelable { public static WindowInfo obtain(WindowInfo other) { WindowInfo window = obtain(); window.displayId = other.displayId; + window.taskId = other.taskId; window.type = other.type; window.layer = other.layer; window.token = other.token; @@ -103,6 +106,7 @@ public class WindowInfo implements Parcelable { @Override public void writeToParcel(Parcel parcel, int flags) { parcel.writeInt(displayId); + parcel.writeInt(taskId); parcel.writeInt(type); parcel.writeInt(layer); parcel.writeStrongBinder(token); @@ -129,6 +133,7 @@ public class WindowInfo implements Parcelable { builder.append("WindowInfo["); builder.append("title=").append(title); builder.append(", displayId=").append(displayId); + builder.append(", taskId=").append(taskId); builder.append(", type=").append(type); builder.append(", layer=").append(layer); builder.append(", token=").append(token); @@ -146,6 +151,7 @@ public class WindowInfo implements Parcelable { private void initFromParcel(Parcel parcel) { displayId = parcel.readInt(); + taskId = parcel.readInt(); type = parcel.readInt(); layer = parcel.readInt(); token = parcel.readStrongBinder(); @@ -169,6 +175,7 @@ public class WindowInfo implements Parcelable { private void clear() { displayId = Display.INVALID_DISPLAY; + taskId = ActivityTaskManager.INVALID_TASK_ID; type = 0; layer = 0; token = null; diff --git a/core/java/android/view/accessibility/AccessibilityWindowInfo.java b/core/java/android/view/accessibility/AccessibilityWindowInfo.java index edcb59a79c70c..76e226163ca1c 100644 --- a/core/java/android/view/accessibility/AccessibilityWindowInfo.java +++ b/core/java/android/view/accessibility/AccessibilityWindowInfo.java @@ -19,6 +19,7 @@ package android.view.accessibility; import android.annotation.NonNull; import android.annotation.Nullable; import android.annotation.TestApi; +import android.app.ActivityTaskManager; import android.graphics.Rect; import android.graphics.Region; import android.os.Parcel; @@ -114,6 +115,7 @@ public final class AccessibilityWindowInfo implements Parcelable { private int mBooleanProperties; private int mId = UNDEFINED_WINDOW_ID; private int mParentId = UNDEFINED_WINDOW_ID; + private int mTaskId = ActivityTaskManager.INVALID_TASK_ID; private Region mRegionInScreen = new Region(); private LongArray mChildIds; private CharSequence mTitle; @@ -306,6 +308,28 @@ public final class AccessibilityWindowInfo implements Parcelable { mId = id; } + /** + * Gets the task ID. + * + * @return The task ID. + * + * @hide + */ + public int getTaskId() { + return mTaskId; + } + + /** + * Sets the task ID. + * + * @param taskId The task ID. + * + * @hide + */ + public void setTaskId(int taskId) { + mTaskId = taskId; + } + /** * Sets the unique id of the IAccessibilityServiceConnection over which * this instance can send requests to the system. @@ -578,6 +602,7 @@ public final class AccessibilityWindowInfo implements Parcelable { parcel.writeInt(mBooleanProperties); parcel.writeInt(mId); parcel.writeInt(mParentId); + parcel.writeInt(mTaskId); mRegionInScreen.writeToParcel(parcel, flags); parcel.writeCharSequence(mTitle); parcel.writeLong(mAnchorId); @@ -608,6 +633,7 @@ public final class AccessibilityWindowInfo implements Parcelable { mBooleanProperties = other.mBooleanProperties; mId = other.mId; mParentId = other.mParentId; + mTaskId = other.mTaskId; mRegionInScreen.set(other.mRegionInScreen); mTitle = other.mTitle; mAnchorId = other.mAnchorId; @@ -631,6 +657,7 @@ public final class AccessibilityWindowInfo implements Parcelable { mBooleanProperties = parcel.readInt(); mId = parcel.readInt(); mParentId = parcel.readInt(); + mTaskId = parcel.readInt(); mRegionInScreen = Region.CREATOR.createFromParcel(parcel); mTitle = parcel.readCharSequence(); mAnchorId = parcel.readLong(); @@ -676,6 +703,7 @@ public final class AccessibilityWindowInfo implements Parcelable { builder.append("title=").append(mTitle); builder.append(", displayId=").append(mDisplayId); builder.append(", id=").append(mId); + builder.append(", taskId=").append(mTaskId); builder.append(", type=").append(typeToString(mType)); builder.append(", layer=").append(mLayer); builder.append(", region=").append(mRegionInScreen); @@ -719,6 +747,7 @@ public final class AccessibilityWindowInfo implements Parcelable { mBooleanProperties = 0; mId = UNDEFINED_WINDOW_ID; mParentId = UNDEFINED_WINDOW_ID; + mTaskId = ActivityTaskManager.INVALID_TASK_ID; mRegionInScreen.setEmpty(); mChildIds = null; mConnectionId = UNDEFINED_WINDOW_ID; diff --git a/core/tests/coretests/src/android/view/WindowInfoTest.java b/core/tests/coretests/src/android/view/WindowInfoTest.java index 05e8bd8b6cab1..0a99b08f58ff8 100644 --- a/core/tests/coretests/src/android/view/WindowInfoTest.java +++ b/core/tests/coretests/src/android/view/WindowInfoTest.java @@ -25,6 +25,7 @@ import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import static org.mockito.Mockito.mock; +import android.app.ActivityTaskManager; import android.os.IBinder; import android.os.Parcel; import android.platform.test.annotations.Presubmit; @@ -83,6 +84,7 @@ public class WindowInfoTest { assertEquals(0, w.layer); assertEquals(AccessibilityNodeInfo.UNDEFINED_NODE_ID, w.accessibilityIdOfAnchor); assertEquals(Display.INVALID_DISPLAY, w.displayId); + assertEquals(ActivityTaskManager.INVALID_TASK_ID, w.taskId); assertNull(w.title); assertNull(w.token); assertNull(w.childTokens); @@ -123,6 +125,7 @@ public class WindowInfoTest { windowInfo.displayId = 2; windowInfo.layer = 3; windowInfo.accessibilityIdOfAnchor = 4L; + windowInfo.taskId = 5; windowInfo.title = "title"; windowInfo.token = mock(IBinder.class); windowInfo.childTokens = new ArrayList<>(); diff --git a/services/accessibility/java/com/android/server/accessibility/AccessibilityWindowManager.java b/services/accessibility/java/com/android/server/accessibility/AccessibilityWindowManager.java index b05dffef9c53f..244f35700d8bb 100644 --- a/services/accessibility/java/com/android/server/accessibility/AccessibilityWindowManager.java +++ b/services/accessibility/java/com/android/server/accessibility/AccessibilityWindowManager.java @@ -499,6 +499,9 @@ public class AccessibilityWindowManager { if (oldWindow.displayId != newWindow.displayId) { return true; } + if (oldWindow.taskId != newWindow.taskId) { + return true; + } return false; } @@ -699,6 +702,7 @@ public class AccessibilityWindowManager { reportedWindow.setAnchorId(window.accessibilityIdOfAnchor); reportedWindow.setPictureInPicture(window.inPictureInPicture); reportedWindow.setDisplayId(window.displayId); + reportedWindow.setTaskId(window.taskId); final int parentId = findWindowIdLocked(userId, window.parentToken); if (parentId >= 0) { diff --git a/services/core/java/com/android/server/wm/WindowState.java b/services/core/java/com/android/server/wm/WindowState.java index f9727e23ea8a0..bee8bda16008e 100644 --- a/services/core/java/com/android/server/wm/WindowState.java +++ b/services/core/java/com/android/server/wm/WindowState.java @@ -193,6 +193,7 @@ import static com.android.server.wm.WindowStateProto.WINDOW_FRAMES; import android.annotation.CallSuper; import android.annotation.NonNull; import android.annotation.Nullable; +import android.app.ActivityTaskManager; import android.app.AppOpsManager; import android.app.admin.DevicePolicyCache; import android.app.compat.CompatChanges; @@ -4824,6 +4825,7 @@ class WindowState extends WindowContainer implements WindowManagerP windowInfo.focused = isFocused(); Task task = getTask(); windowInfo.inPictureInPicture = (task != null) && task.inPinnedWindowingMode(); + windowInfo.taskId = task == null ? ActivityTaskManager.INVALID_TASK_ID : task.mTaskId; windowInfo.hasFlagWatchOutsideTouch = (mAttrs.flags & WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH) != 0;