diff --git a/core/api/system-current.txt b/core/api/system-current.txt index ba152bc74181a..57cc756b96914 100755 --- a/core/api/system-current.txt +++ b/core/api/system-current.txt @@ -14399,6 +14399,7 @@ package android.view.contentcapture { method public int getFlags(); method @Nullable public android.view.contentcapture.ContentCaptureSessionId getParentSessionId(); method public int getTaskId(); + method @Nullable public android.os.IBinder getWindowToken(); field public static final int FLAG_DISABLED_BY_APP = 1; // 0x1 field public static final int FLAG_DISABLED_BY_FLAG_SECURE = 2; // 0x2 field public static final int FLAG_RECONNECTED = 4; // 0x4 diff --git a/core/java/android/view/contentcapture/ContentCaptureContext.java b/core/java/android/view/contentcapture/ContentCaptureContext.java index 71b8003954e67..3bc9a967ea207 100644 --- a/core/java/android/view/contentcapture/ContentCaptureContext.java +++ b/core/java/android/view/contentcapture/ContentCaptureContext.java @@ -27,6 +27,7 @@ import android.content.ComponentName; import android.content.Context; import android.content.LocusId; import android.os.Bundle; +import android.os.IBinder; import android.os.Parcel; import android.os.Parcelable; import android.view.Display; @@ -105,6 +106,7 @@ public final class ContentCaptureContext implements Parcelable { private final int mFlags; private final int mDisplayId; private final ActivityId mActivityId; + private final IBinder mWindowToken; // Fields below are set by the service upon "delivery" and are not marshalled in the parcel private int mParentSessionId = NO_SESSION_ID; @@ -112,7 +114,7 @@ public final class ContentCaptureContext implements Parcelable { /** @hide */ public ContentCaptureContext(@Nullable ContentCaptureContext clientContext, @NonNull ActivityId activityId, @NonNull ComponentName componentName, int displayId, - int flags) { + IBinder windowToken, int flags) { if (clientContext != null) { mHasClientContext = true; mExtras = clientContext.mExtras; @@ -126,6 +128,7 @@ public final class ContentCaptureContext implements Parcelable { mFlags = flags; mDisplayId = displayId; mActivityId = activityId; + mWindowToken = windowToken; } private ContentCaptureContext(@NonNull Builder builder) { @@ -137,6 +140,7 @@ public final class ContentCaptureContext implements Parcelable { mFlags = 0; mDisplayId = Display.INVALID_DISPLAY; mActivityId = null; + mWindowToken = null; } /** @hide */ @@ -148,6 +152,7 @@ public final class ContentCaptureContext implements Parcelable { mFlags = original.mFlags | extraFlags; mDisplayId = original.mDisplayId; mActivityId = original.mActivityId; + mWindowToken = original.mWindowToken; } /** @@ -229,6 +234,20 @@ public final class ContentCaptureContext implements Parcelable { return mDisplayId; } + /** + * Gets the window token of the activity associated with this context. + * + *

The token can be used to attach relevant overlay views to the activity's window. This can + * be done through {@link android.view.WindowManager.LayoutParams#token}. + * + * @hide + */ + @SystemApi + @Nullable + public IBinder getWindowToken() { + return mWindowToken; + } + /** * Gets the flags associated with this context. * @@ -328,6 +347,7 @@ public final class ContentCaptureContext implements Parcelable { } pw.print(", activityId="); pw.print(mActivityId); pw.print(", displayId="); pw.print(mDisplayId); + pw.print(", windowToken="); pw.print(mWindowToken); if (mParentSessionId != NO_SESSION_ID) { pw.print(", parentId="); pw.print(mParentSessionId); } @@ -352,6 +372,7 @@ public final class ContentCaptureContext implements Parcelable { builder.append("act=").append(ComponentName.flattenToShortString(mComponentName)) .append(", activityId=").append(mActivityId) .append(", displayId=").append(mDisplayId) + .append(", windowToken=").append(mWindowToken) .append(", flags=").append(mFlags); } else { builder.append("id=").append(mId); @@ -381,6 +402,7 @@ public final class ContentCaptureContext implements Parcelable { parcel.writeParcelable(mComponentName, flags); if (fromServer()) { parcel.writeInt(mDisplayId); + parcel.writeStrongBinder(mWindowToken); parcel.writeInt(mFlags); mActivityId.writeToParcel(parcel, flags); } @@ -411,11 +433,12 @@ public final class ContentCaptureContext implements Parcelable { return clientContext; } else { final int displayId = parcel.readInt(); + final IBinder windowToken = parcel.readStrongBinder(); final int flags = parcel.readInt(); final ActivityId activityId = new ActivityId(parcel); return new ContentCaptureContext(clientContext, activityId, componentName, - displayId, flags); + displayId, windowToken, flags); } } diff --git a/core/tests/coretests/src/android/view/contentcapture/ContentCaptureContextTest.java b/core/tests/coretests/src/android/view/contentcapture/ContentCaptureContextTest.java index ddb6729b55e13..4b19391da78e4 100644 --- a/core/tests/coretests/src/android/view/contentcapture/ContentCaptureContextTest.java +++ b/core/tests/coretests/src/android/view/contentcapture/ContentCaptureContextTest.java @@ -39,9 +39,10 @@ public class ContentCaptureContextTest { public void testConstructorAdditionalFlags() { final ComponentName componentName = new ComponentName("component", "name"); final IBinder token = new Binder(); + final IBinder windowToken = new Binder(); final ContentCaptureContext ctx = new ContentCaptureContext(/* clientContext= */ null, new ActivityId(/* taskId= */ 666, token), componentName, /* displayId= */ - 42, /* flags= */ 1); + 42, windowToken, /* flags= */ 1); final ContentCaptureContext newCtx = new ContentCaptureContext(ctx, /* extraFlags= */ 2); assertThat(newCtx.getFlags()).isEqualTo(3); assertThat(newCtx.getActivityComponent()).isEqualTo(componentName); @@ -50,6 +51,7 @@ public class ContentCaptureContextTest { assertThat(activityId.getTaskId()).isEqualTo(666); assertThat(activityId.getToken()).isEqualTo(token); assertThat(newCtx.getDisplayId()).isEqualTo(42); + assertThat(newCtx.getWindowToken()).isEqualTo(windowToken); assertThat(newCtx.getExtras()).isNull(); assertThat(newCtx.getLocusId()).isNull(); assertThat(newCtx.getParentSessionId()).isNull(); diff --git a/services/contentcapture/java/com/android/server/contentcapture/ContentCaptureServerSession.java b/services/contentcapture/java/com/android/server/contentcapture/ContentCaptureServerSession.java index 9f3045e685501..3a90a959b8770 100644 --- a/services/contentcapture/java/com/android/server/contentcapture/ContentCaptureServerSession.java +++ b/services/contentcapture/java/com/android/server/contentcapture/ContentCaptureServerSession.java @@ -87,7 +87,7 @@ final class ContentCaptureServerSession { mId = sessionId; mUid = uid; mContentCaptureContext = new ContentCaptureContext(/* clientContext= */ null, - activityId, appComponentName, displayId, flags); + activityId, appComponentName, displayId, activityToken, flags); mSessionStateReceiver = sessionStateReceiver; try { sessionStateReceiver.asBinder().linkToDeath(() -> onClientDeath(), 0);