Merge "Add hidden APIs to allow to get and set task ID in AccessibilityWindowInfo" into sc-v2-dev

This commit is contained in:
Yabin Huang
2021-08-05 01:22:36 +00:00
committed by Android (Google) Code Review
5 changed files with 45 additions and 0 deletions

View File

@@ -16,6 +16,7 @@
package android.view; package android.view;
import android.app.ActivityTaskManager;
import android.graphics.Region; import android.graphics.Region;
import android.os.IBinder; import android.os.IBinder;
import android.os.Parcel; import android.os.Parcel;
@@ -51,6 +52,7 @@ public class WindowInfo implements Parcelable {
public boolean inPictureInPicture; public boolean inPictureInPicture;
public boolean hasFlagWatchOutsideTouch; public boolean hasFlagWatchOutsideTouch;
public int displayId = Display.INVALID_DISPLAY; public int displayId = Display.INVALID_DISPLAY;
public int taskId = ActivityTaskManager.INVALID_TASK_ID;
private WindowInfo() { private WindowInfo() {
/* do nothing - hide constructor */ /* do nothing - hide constructor */
@@ -67,6 +69,7 @@ public class WindowInfo implements Parcelable {
public static WindowInfo obtain(WindowInfo other) { public static WindowInfo obtain(WindowInfo other) {
WindowInfo window = obtain(); WindowInfo window = obtain();
window.displayId = other.displayId; window.displayId = other.displayId;
window.taskId = other.taskId;
window.type = other.type; window.type = other.type;
window.layer = other.layer; window.layer = other.layer;
window.token = other.token; window.token = other.token;
@@ -103,6 +106,7 @@ public class WindowInfo implements Parcelable {
@Override @Override
public void writeToParcel(Parcel parcel, int flags) { public void writeToParcel(Parcel parcel, int flags) {
parcel.writeInt(displayId); parcel.writeInt(displayId);
parcel.writeInt(taskId);
parcel.writeInt(type); parcel.writeInt(type);
parcel.writeInt(layer); parcel.writeInt(layer);
parcel.writeStrongBinder(token); parcel.writeStrongBinder(token);
@@ -129,6 +133,7 @@ public class WindowInfo implements Parcelable {
builder.append("WindowInfo["); builder.append("WindowInfo[");
builder.append("title=").append(title); builder.append("title=").append(title);
builder.append(", displayId=").append(displayId); builder.append(", displayId=").append(displayId);
builder.append(", taskId=").append(taskId);
builder.append(", type=").append(type); builder.append(", type=").append(type);
builder.append(", layer=").append(layer); builder.append(", layer=").append(layer);
builder.append(", token=").append(token); builder.append(", token=").append(token);
@@ -146,6 +151,7 @@ public class WindowInfo implements Parcelable {
private void initFromParcel(Parcel parcel) { private void initFromParcel(Parcel parcel) {
displayId = parcel.readInt(); displayId = parcel.readInt();
taskId = parcel.readInt();
type = parcel.readInt(); type = parcel.readInt();
layer = parcel.readInt(); layer = parcel.readInt();
token = parcel.readStrongBinder(); token = parcel.readStrongBinder();
@@ -169,6 +175,7 @@ public class WindowInfo implements Parcelable {
private void clear() { private void clear() {
displayId = Display.INVALID_DISPLAY; displayId = Display.INVALID_DISPLAY;
taskId = ActivityTaskManager.INVALID_TASK_ID;
type = 0; type = 0;
layer = 0; layer = 0;
token = null; token = null;

View File

@@ -19,6 +19,7 @@ package android.view.accessibility;
import android.annotation.NonNull; import android.annotation.NonNull;
import android.annotation.Nullable; import android.annotation.Nullable;
import android.annotation.TestApi; import android.annotation.TestApi;
import android.app.ActivityTaskManager;
import android.graphics.Rect; import android.graphics.Rect;
import android.graphics.Region; import android.graphics.Region;
import android.os.Parcel; import android.os.Parcel;
@@ -114,6 +115,7 @@ public final class AccessibilityWindowInfo implements Parcelable {
private int mBooleanProperties; private int mBooleanProperties;
private int mId = UNDEFINED_WINDOW_ID; private int mId = UNDEFINED_WINDOW_ID;
private int mParentId = UNDEFINED_WINDOW_ID; private int mParentId = UNDEFINED_WINDOW_ID;
private int mTaskId = ActivityTaskManager.INVALID_TASK_ID;
private Region mRegionInScreen = new Region(); private Region mRegionInScreen = new Region();
private LongArray mChildIds; private LongArray mChildIds;
private CharSequence mTitle; private CharSequence mTitle;
@@ -306,6 +308,28 @@ public final class AccessibilityWindowInfo implements Parcelable {
mId = id; 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 * Sets the unique id of the IAccessibilityServiceConnection over which
* this instance can send requests to the system. * this instance can send requests to the system.
@@ -578,6 +602,7 @@ public final class AccessibilityWindowInfo implements Parcelable {
parcel.writeInt(mBooleanProperties); parcel.writeInt(mBooleanProperties);
parcel.writeInt(mId); parcel.writeInt(mId);
parcel.writeInt(mParentId); parcel.writeInt(mParentId);
parcel.writeInt(mTaskId);
mRegionInScreen.writeToParcel(parcel, flags); mRegionInScreen.writeToParcel(parcel, flags);
parcel.writeCharSequence(mTitle); parcel.writeCharSequence(mTitle);
parcel.writeLong(mAnchorId); parcel.writeLong(mAnchorId);
@@ -608,6 +633,7 @@ public final class AccessibilityWindowInfo implements Parcelable {
mBooleanProperties = other.mBooleanProperties; mBooleanProperties = other.mBooleanProperties;
mId = other.mId; mId = other.mId;
mParentId = other.mParentId; mParentId = other.mParentId;
mTaskId = other.mTaskId;
mRegionInScreen.set(other.mRegionInScreen); mRegionInScreen.set(other.mRegionInScreen);
mTitle = other.mTitle; mTitle = other.mTitle;
mAnchorId = other.mAnchorId; mAnchorId = other.mAnchorId;
@@ -631,6 +657,7 @@ public final class AccessibilityWindowInfo implements Parcelable {
mBooleanProperties = parcel.readInt(); mBooleanProperties = parcel.readInt();
mId = parcel.readInt(); mId = parcel.readInt();
mParentId = parcel.readInt(); mParentId = parcel.readInt();
mTaskId = parcel.readInt();
mRegionInScreen = Region.CREATOR.createFromParcel(parcel); mRegionInScreen = Region.CREATOR.createFromParcel(parcel);
mTitle = parcel.readCharSequence(); mTitle = parcel.readCharSequence();
mAnchorId = parcel.readLong(); mAnchorId = parcel.readLong();
@@ -676,6 +703,7 @@ public final class AccessibilityWindowInfo implements Parcelable {
builder.append("title=").append(mTitle); builder.append("title=").append(mTitle);
builder.append(", displayId=").append(mDisplayId); builder.append(", displayId=").append(mDisplayId);
builder.append(", id=").append(mId); builder.append(", id=").append(mId);
builder.append(", taskId=").append(mTaskId);
builder.append(", type=").append(typeToString(mType)); builder.append(", type=").append(typeToString(mType));
builder.append(", layer=").append(mLayer); builder.append(", layer=").append(mLayer);
builder.append(", region=").append(mRegionInScreen); builder.append(", region=").append(mRegionInScreen);
@@ -719,6 +747,7 @@ public final class AccessibilityWindowInfo implements Parcelable {
mBooleanProperties = 0; mBooleanProperties = 0;
mId = UNDEFINED_WINDOW_ID; mId = UNDEFINED_WINDOW_ID;
mParentId = UNDEFINED_WINDOW_ID; mParentId = UNDEFINED_WINDOW_ID;
mTaskId = ActivityTaskManager.INVALID_TASK_ID;
mRegionInScreen.setEmpty(); mRegionInScreen.setEmpty();
mChildIds = null; mChildIds = null;
mConnectionId = UNDEFINED_WINDOW_ID; mConnectionId = UNDEFINED_WINDOW_ID;

View File

@@ -25,6 +25,7 @@ import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail; import static org.junit.Assert.fail;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import android.app.ActivityTaskManager;
import android.os.IBinder; import android.os.IBinder;
import android.os.Parcel; import android.os.Parcel;
import android.platform.test.annotations.Presubmit; import android.platform.test.annotations.Presubmit;
@@ -83,6 +84,7 @@ public class WindowInfoTest {
assertEquals(0, w.layer); assertEquals(0, w.layer);
assertEquals(AccessibilityNodeInfo.UNDEFINED_NODE_ID, w.accessibilityIdOfAnchor); assertEquals(AccessibilityNodeInfo.UNDEFINED_NODE_ID, w.accessibilityIdOfAnchor);
assertEquals(Display.INVALID_DISPLAY, w.displayId); assertEquals(Display.INVALID_DISPLAY, w.displayId);
assertEquals(ActivityTaskManager.INVALID_TASK_ID, w.taskId);
assertNull(w.title); assertNull(w.title);
assertNull(w.token); assertNull(w.token);
assertNull(w.childTokens); assertNull(w.childTokens);
@@ -123,6 +125,7 @@ public class WindowInfoTest {
windowInfo.displayId = 2; windowInfo.displayId = 2;
windowInfo.layer = 3; windowInfo.layer = 3;
windowInfo.accessibilityIdOfAnchor = 4L; windowInfo.accessibilityIdOfAnchor = 4L;
windowInfo.taskId = 5;
windowInfo.title = "title"; windowInfo.title = "title";
windowInfo.token = mock(IBinder.class); windowInfo.token = mock(IBinder.class);
windowInfo.childTokens = new ArrayList<>(); windowInfo.childTokens = new ArrayList<>();

View File

@@ -499,6 +499,9 @@ public class AccessibilityWindowManager {
if (oldWindow.displayId != newWindow.displayId) { if (oldWindow.displayId != newWindow.displayId) {
return true; return true;
} }
if (oldWindow.taskId != newWindow.taskId) {
return true;
}
return false; return false;
} }
@@ -699,6 +702,7 @@ public class AccessibilityWindowManager {
reportedWindow.setAnchorId(window.accessibilityIdOfAnchor); reportedWindow.setAnchorId(window.accessibilityIdOfAnchor);
reportedWindow.setPictureInPicture(window.inPictureInPicture); reportedWindow.setPictureInPicture(window.inPictureInPicture);
reportedWindow.setDisplayId(window.displayId); reportedWindow.setDisplayId(window.displayId);
reportedWindow.setTaskId(window.taskId);
final int parentId = findWindowIdLocked(userId, window.parentToken); final int parentId = findWindowIdLocked(userId, window.parentToken);
if (parentId >= 0) { if (parentId >= 0) {

View File

@@ -193,6 +193,7 @@ import static com.android.server.wm.WindowStateProto.WINDOW_FRAMES;
import android.annotation.CallSuper; import android.annotation.CallSuper;
import android.annotation.NonNull; import android.annotation.NonNull;
import android.annotation.Nullable; import android.annotation.Nullable;
import android.app.ActivityTaskManager;
import android.app.AppOpsManager; import android.app.AppOpsManager;
import android.app.admin.DevicePolicyCache; import android.app.admin.DevicePolicyCache;
import android.app.compat.CompatChanges; import android.app.compat.CompatChanges;
@@ -4824,6 +4825,7 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP
windowInfo.focused = isFocused(); windowInfo.focused = isFocused();
Task task = getTask(); Task task = getTask();
windowInfo.inPictureInPicture = (task != null) && task.inPinnedWindowingMode(); windowInfo.inPictureInPicture = (task != null) && task.inPinnedWindowingMode();
windowInfo.taskId = task == null ? ActivityTaskManager.INVALID_TASK_ID : task.mTaskId;
windowInfo.hasFlagWatchOutsideTouch = windowInfo.hasFlagWatchOutsideTouch =
(mAttrs.flags & WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH) != 0; (mAttrs.flags & WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH) != 0;