From ccff5a6a8b402e1069ac76c89b8467c46f098ae8 Mon Sep 17 00:00:00 2001 From: Chris Li Date: Thu, 24 Jun 2021 16:56:31 -0700 Subject: Add onErrorCallback for TaskFragmentOrganizer When app wants to create activity through sidecar (for example, startActivityToSide), we need a callback in case it failed to finish the request. Allow the caller to set a token for the WCT, which will be passed back if there is any error, so that the caller can identify the error callback. Bug: 190433129 Test: N/A Change-Id: Icffb7255e75465b90ed822559296f147a7e3418a --- .../android/window/WindowContainerTransaction.java | 37 +++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) (limited to 'core/java/android/window/WindowContainerTransaction.java') diff --git a/core/java/android/window/WindowContainerTransaction.java b/core/java/android/window/WindowContainerTransaction.java index 8c3dc2e2044e..9c512add3345 100644 --- a/core/java/android/window/WindowContainerTransaction.java +++ b/core/java/android/window/WindowContainerTransaction.java @@ -49,11 +49,15 @@ public final class WindowContainerTransaction implements Parcelable { // Flat list because re-order operations are order-dependent private final ArrayList mHierarchyOps = new ArrayList<>(); + @Nullable + private IBinder mErrorCallbackToken; + public WindowContainerTransaction() {} private WindowContainerTransaction(Parcel in) { in.readMap(mChanges, null /* loader */); in.readList(mHierarchyOps, null /* loader */); + mErrorCallbackToken = in.readStrongBinder(); } private Change getOrCreateChange(IBinder token) { @@ -475,6 +479,23 @@ public final class WindowContainerTransaction implements Parcelable { return this; } + /** + * When this {@link WindowContainerTransaction} failed to finish on the server side, it will + * trigger callback with this {@param errorCallbackToken}. + * @param errorCallbackToken client provided token that will be passed back as parameter in + * the callback if there is an error on the server side. + * @see ITaskFragmentOrganizer#onTaskFragmentError + * @hide + */ + @NonNull + public WindowContainerTransaction setErrorCallbackToken(@NonNull IBinder errorCallbackToken) { + if (mErrorCallbackToken != null) { + throw new IllegalStateException("Can't set multiple error token for one transaction."); + } + mErrorCallbackToken = errorCallbackToken; + return this; + } + /** * Merges another WCT into this one. * @param transfer When true, this will transfer everything from other potentially leaving @@ -496,6 +517,13 @@ public final class WindowContainerTransaction implements Parcelable { mHierarchyOps.add(transfer ? other.mHierarchyOps.get(i) : new HierarchyOp(other.mHierarchyOps.get(i))); } + if (mErrorCallbackToken != null && other.mErrorCallbackToken != null && mErrorCallbackToken + != other.mErrorCallbackToken) { + throw new IllegalArgumentException("Can't merge two WCT with different error token"); + } + mErrorCallbackToken = mErrorCallbackToken != null + ? mErrorCallbackToken + : other.mErrorCallbackToken; } /** @hide */ @@ -513,11 +541,17 @@ public final class WindowContainerTransaction implements Parcelable { return mHierarchyOps; } + /** @hide */ + @Nullable + public IBinder getErrorCallbackToken() { + return mErrorCallbackToken; + } + @Override @NonNull public String toString() { return "WindowContainerTransaction { changes = " + mChanges + " hops = " + mHierarchyOps - + " }"; + + " errorCallbackToken=" + mErrorCallbackToken + " }"; } @Override @@ -525,6 +559,7 @@ public final class WindowContainerTransaction implements Parcelable { public void writeToParcel(@NonNull Parcel dest, int flags) { dest.writeMap(mChanges); dest.writeList(mHierarchyOps); + dest.writeStrongBinder(mErrorCallbackToken); } @Override -- cgit v1.2.3