Merge "Add isAnimationCallback() in BackNavigationInfo" into udc-dev am: fc0e17a688

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/22428649

Change-Id: I54b9fd4453bd51920ea7b82ae0f24f562a2ebc6d
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Omar Miatello
2023-04-18 12:48:34 +00:00
committed by Automerger Merge Worker
5 changed files with 89 additions and 12 deletions

View File

@@ -94,6 +94,7 @@ public final class BackNavigationInfo implements Parcelable {
@Nullable @Nullable
private final IOnBackInvokedCallback mOnBackInvokedCallback; private final IOnBackInvokedCallback mOnBackInvokedCallback;
private final boolean mPrepareRemoteAnimation; private final boolean mPrepareRemoteAnimation;
private final boolean mAnimationCallback;
@Nullable @Nullable
private final CustomAnimationInfo mCustomAnimationInfo; private final CustomAnimationInfo mCustomAnimationInfo;
@@ -109,11 +110,13 @@ public final class BackNavigationInfo implements Parcelable {
@Nullable RemoteCallback onBackNavigationDone, @Nullable RemoteCallback onBackNavigationDone,
@Nullable IOnBackInvokedCallback onBackInvokedCallback, @Nullable IOnBackInvokedCallback onBackInvokedCallback,
boolean isPrepareRemoteAnimation, boolean isPrepareRemoteAnimation,
boolean isAnimationCallback,
@Nullable CustomAnimationInfo customAnimationInfo) { @Nullable CustomAnimationInfo customAnimationInfo) {
mType = type; mType = type;
mOnBackNavigationDone = onBackNavigationDone; mOnBackNavigationDone = onBackNavigationDone;
mOnBackInvokedCallback = onBackInvokedCallback; mOnBackInvokedCallback = onBackInvokedCallback;
mPrepareRemoteAnimation = isPrepareRemoteAnimation; mPrepareRemoteAnimation = isPrepareRemoteAnimation;
mAnimationCallback = isAnimationCallback;
mCustomAnimationInfo = customAnimationInfo; mCustomAnimationInfo = customAnimationInfo;
} }
@@ -122,6 +125,7 @@ public final class BackNavigationInfo implements Parcelable {
mOnBackNavigationDone = in.readTypedObject(RemoteCallback.CREATOR); mOnBackNavigationDone = in.readTypedObject(RemoteCallback.CREATOR);
mOnBackInvokedCallback = IOnBackInvokedCallback.Stub.asInterface(in.readStrongBinder()); mOnBackInvokedCallback = IOnBackInvokedCallback.Stub.asInterface(in.readStrongBinder());
mPrepareRemoteAnimation = in.readBoolean(); mPrepareRemoteAnimation = in.readBoolean();
mAnimationCallback = in.readBoolean();
mCustomAnimationInfo = in.readTypedObject(CustomAnimationInfo.CREATOR); mCustomAnimationInfo = in.readTypedObject(CustomAnimationInfo.CREATOR);
} }
@@ -132,6 +136,7 @@ public final class BackNavigationInfo implements Parcelable {
dest.writeTypedObject(mOnBackNavigationDone, flags); dest.writeTypedObject(mOnBackNavigationDone, flags);
dest.writeStrongInterface(mOnBackInvokedCallback); dest.writeStrongInterface(mOnBackInvokedCallback);
dest.writeBoolean(mPrepareRemoteAnimation); dest.writeBoolean(mPrepareRemoteAnimation);
dest.writeBoolean(mAnimationCallback);
dest.writeTypedObject(mCustomAnimationInfo, flags); dest.writeTypedObject(mCustomAnimationInfo, flags);
} }
@@ -159,13 +164,21 @@ public final class BackNavigationInfo implements Parcelable {
} }
/** /**
* Return true if the core is preparing a back gesture nimation. * Return true if the core is preparing a back gesture animation.
* @hide * @hide
*/ */
public boolean isPrepareRemoteAnimation() { public boolean isPrepareRemoteAnimation() {
return mPrepareRemoteAnimation; return mPrepareRemoteAnimation;
} }
/**
* Return true if the callback is {@link OnBackAnimationCallback}.
* @hide
*/
public boolean isAnimationCallback() {
return mAnimationCallback;
}
/** /**
* Callback to be called when the back preview is finished in order to notify the server that * Callback to be called when the back preview is finished in order to notify the server that
* it can clean up the resources created for the animation. * it can clean up the resources created for the animation.
@@ -214,6 +227,8 @@ public final class BackNavigationInfo implements Parcelable {
+ "mType=" + typeToString(mType) + " (" + mType + ")" + "mType=" + typeToString(mType) + " (" + mType + ")"
+ ", mOnBackNavigationDone=" + mOnBackNavigationDone + ", mOnBackNavigationDone=" + mOnBackNavigationDone
+ ", mOnBackInvokedCallback=" + mOnBackInvokedCallback + ", mOnBackInvokedCallback=" + mOnBackInvokedCallback
+ ", mPrepareRemoteAnimation=" + mPrepareRemoteAnimation
+ ", mAnimationCallback=" + mAnimationCallback
+ ", mCustomizeAnimationInfo=" + mCustomAnimationInfo + ", mCustomizeAnimationInfo=" + mCustomAnimationInfo
+ '}'; + '}';
} }
@@ -343,6 +358,7 @@ public final class BackNavigationInfo implements Parcelable {
private IOnBackInvokedCallback mOnBackInvokedCallback = null; private IOnBackInvokedCallback mOnBackInvokedCallback = null;
private boolean mPrepareRemoteAnimation; private boolean mPrepareRemoteAnimation;
private CustomAnimationInfo mCustomAnimationInfo; private CustomAnimationInfo mCustomAnimationInfo;
private boolean mAnimationCallback = false;
/** /**
* @see BackNavigationInfo#getType() * @see BackNavigationInfo#getType()
@@ -387,6 +403,7 @@ public final class BackNavigationInfo implements Parcelable {
mCustomAnimationInfo.mWindowAnimations = windowAnimations; mCustomAnimationInfo.mWindowAnimations = windowAnimations;
return this; return this;
} }
/** /**
* Set resources ids for customize activity animation. * Set resources ids for customize activity animation.
*/ */
@@ -401,6 +418,14 @@ public final class BackNavigationInfo implements Parcelable {
return this; return this;
} }
/**
* @param isAnimationCallback whether the callback is {@link OnBackAnimationCallback}
*/
public Builder setAnimationCallback(boolean isAnimationCallback) {
mAnimationCallback = isAnimationCallback;
return this;
}
/** /**
* Builds and returns an instance of {@link BackNavigationInfo} * Builds and returns an instance of {@link BackNavigationInfo}
*/ */
@@ -408,6 +433,7 @@ public final class BackNavigationInfo implements Parcelable {
return new BackNavigationInfo(mType, mOnBackNavigationDone, return new BackNavigationInfo(mType, mOnBackNavigationDone,
mOnBackInvokedCallback, mOnBackInvokedCallback,
mPrepareRemoteAnimation, mPrepareRemoteAnimation,
mAnimationCallback,
mCustomAnimationInfo); mCustomAnimationInfo);
} }
} }

View File

@@ -28,15 +28,20 @@ public final class OnBackInvokedCallbackInfo implements Parcelable {
@NonNull @NonNull
private final IOnBackInvokedCallback mCallback; private final IOnBackInvokedCallback mCallback;
private @OnBackInvokedDispatcher.Priority int mPriority; private @OnBackInvokedDispatcher.Priority int mPriority;
private final boolean mIsAnimationCallback;
public OnBackInvokedCallbackInfo(@NonNull IOnBackInvokedCallback callback, int priority) { public OnBackInvokedCallbackInfo(@NonNull IOnBackInvokedCallback callback,
int priority,
boolean isAnimationCallback) {
mCallback = callback; mCallback = callback;
mPriority = priority; mPriority = priority;
mIsAnimationCallback = isAnimationCallback;
} }
private OnBackInvokedCallbackInfo(@NonNull Parcel in) { private OnBackInvokedCallbackInfo(@NonNull Parcel in) {
mCallback = IOnBackInvokedCallback.Stub.asInterface(in.readStrongBinder()); mCallback = IOnBackInvokedCallback.Stub.asInterface(in.readStrongBinder());
mPriority = in.readInt(); mPriority = in.readInt();
mIsAnimationCallback = in.readBoolean();
} }
@Override @Override
@@ -48,6 +53,7 @@ public final class OnBackInvokedCallbackInfo implements Parcelable {
public void writeToParcel(@NonNull Parcel dest, int flags) { public void writeToParcel(@NonNull Parcel dest, int flags) {
dest.writeStrongInterface(mCallback); dest.writeStrongInterface(mCallback);
dest.writeInt(mPriority); dest.writeInt(mPriority);
dest.writeBoolean(mIsAnimationCallback);
} }
public static final Creator<OnBackInvokedCallbackInfo> CREATOR = public static final Creator<OnBackInvokedCallbackInfo> CREATOR =
@@ -77,9 +83,16 @@ public final class OnBackInvokedCallbackInfo implements Parcelable {
return mPriority; return mPriority;
} }
public boolean isAnimationCallback() {
return mIsAnimationCallback;
}
@Override @Override
public String toString() { public String toString() {
return "OnBackInvokedCallbackInfo{" return "OnBackInvokedCallbackInfo{"
+ "mCallback=" + mCallback + ", mPriority=" + mPriority + '}'; + "mCallback=" + mCallback
+ ", mPriority=" + mPriority
+ ", mIsAnimationCallback=" + mIsAnimationCallback
+ '}';
} }
} }

View File

@@ -193,7 +193,10 @@ public class WindowOnBackInvokedDispatcher implements OnBackInvokedDispatcher {
? ((ImeOnBackInvokedDispatcher.ImeOnBackInvokedCallback) ? ((ImeOnBackInvokedDispatcher.ImeOnBackInvokedCallback)
callback).getIOnBackInvokedCallback() callback).getIOnBackInvokedCallback()
: new OnBackInvokedCallbackWrapper(callback); : new OnBackInvokedCallbackWrapper(callback);
callbackInfo = new OnBackInvokedCallbackInfo(iCallback, priority); callbackInfo = new OnBackInvokedCallbackInfo(
iCallback,
priority,
callback instanceof OnBackAnimationCallback);
} }
mWindowSession.setOnBackInvokedCallbackInfo(mWindow, callbackInfo); mWindowSession.setOnBackInvokedCallbackInfo(mWindow, callbackInfo);
} catch (RemoteException e) { } catch (RemoteException e) {

View File

@@ -227,6 +227,7 @@ class BackNavigationController {
backType = BackNavigationInfo.TYPE_CALLBACK; backType = BackNavigationInfo.TYPE_CALLBACK;
} }
infoBuilder.setOnBackInvokedCallback(callbackInfo.getCallback()); infoBuilder.setOnBackInvokedCallback(callbackInfo.getCallback());
infoBuilder.setAnimationCallback(callbackInfo.isAnimationCallback());
mNavigationMonitor.startMonitor(window, navigationObserver); mNavigationMonitor.startMonitor(window, navigationObserver);
} }

View File

@@ -232,11 +232,36 @@ public class BackNavigationControllerTests extends WindowTestsBase {
IOnBackInvokedCallback callback = createOnBackInvokedCallback(); IOnBackInvokedCallback callback = createOnBackInvokedCallback();
window.setOnBackInvokedCallbackInfo( window.setOnBackInvokedCallbackInfo(
new OnBackInvokedCallbackInfo(callback, OnBackInvokedDispatcher.PRIORITY_DEFAULT)); new OnBackInvokedCallbackInfo(
callback,
OnBackInvokedDispatcher.PRIORITY_DEFAULT,
/* isAnimationCallback = */ false));
BackNavigationInfo backNavigationInfo = startBackNavigation(); BackNavigationInfo backNavigationInfo = startBackNavigation();
assertWithMessage("BackNavigationInfo").that(backNavigationInfo).isNotNull(); assertWithMessage("BackNavigationInfo").that(backNavigationInfo).isNotNull();
assertThat(backNavigationInfo.getType()).isEqualTo(BackNavigationInfo.TYPE_CALLBACK); assertThat(backNavigationInfo.getType()).isEqualTo(BackNavigationInfo.TYPE_CALLBACK);
assertThat(backNavigationInfo.isAnimationCallback()).isEqualTo(false);
assertThat(backNavigationInfo.getOnBackInvokedCallback()).isEqualTo(callback);
}
@Test
public void backInfoWithAnimationCallback() {
WindowState window = createWindow(null, WindowManager.LayoutParams.TYPE_WALLPAPER,
"Wallpaper");
addToWindowMap(window, true);
makeWindowVisibleAndDrawn(window);
IOnBackInvokedCallback callback = createOnBackInvokedCallback();
window.setOnBackInvokedCallbackInfo(
new OnBackInvokedCallbackInfo(
callback,
OnBackInvokedDispatcher.PRIORITY_DEFAULT,
/* isAnimationCallback = */ true));
BackNavigationInfo backNavigationInfo = startBackNavigation();
assertWithMessage("BackNavigationInfo").that(backNavigationInfo).isNotNull();
assertThat(backNavigationInfo.getType()).isEqualTo(BackNavigationInfo.TYPE_CALLBACK);
assertThat(backNavigationInfo.isAnimationCallback()).isEqualTo(true);
assertThat(backNavigationInfo.getOnBackInvokedCallback()).isEqualTo(callback); assertThat(backNavigationInfo.getOnBackInvokedCallback()).isEqualTo(callback);
} }
@@ -364,7 +389,10 @@ public class BackNavigationControllerTests extends WindowTestsBase {
IOnBackInvokedCallback callback = createOnBackInvokedCallback(); IOnBackInvokedCallback callback = createOnBackInvokedCallback();
window.setOnBackInvokedCallbackInfo( window.setOnBackInvokedCallbackInfo(
new OnBackInvokedCallbackInfo(callback, OnBackInvokedDispatcher.PRIORITY_DEFAULT)); new OnBackInvokedCallbackInfo(
callback,
OnBackInvokedDispatcher.PRIORITY_DEFAULT,
/* isAnimationCallback = */ false));
BackNavigationInfo backNavigationInfo = startBackNavigation(); BackNavigationInfo backNavigationInfo = startBackNavigation();
assertThat(backNavigationInfo).isNull(); assertThat(backNavigationInfo).isNull();
@@ -450,14 +478,20 @@ public class BackNavigationControllerTests extends WindowTestsBase {
private IOnBackInvokedCallback withSystemCallback(Task task) { private IOnBackInvokedCallback withSystemCallback(Task task) {
IOnBackInvokedCallback callback = createOnBackInvokedCallback(); IOnBackInvokedCallback callback = createOnBackInvokedCallback();
task.getTopMostActivity().getTopChild().setOnBackInvokedCallbackInfo( task.getTopMostActivity().getTopChild().setOnBackInvokedCallbackInfo(
new OnBackInvokedCallbackInfo(callback, OnBackInvokedDispatcher.PRIORITY_SYSTEM)); new OnBackInvokedCallbackInfo(
callback,
OnBackInvokedDispatcher.PRIORITY_SYSTEM,
/* isAnimationCallback = */ false));
return callback; return callback;
} }
private IOnBackInvokedCallback withAppCallback(Task task) { private IOnBackInvokedCallback withAppCallback(Task task) {
IOnBackInvokedCallback callback = createOnBackInvokedCallback(); IOnBackInvokedCallback callback = createOnBackInvokedCallback();
task.getTopMostActivity().getTopChild().setOnBackInvokedCallbackInfo( task.getTopMostActivity().getTopChild().setOnBackInvokedCallbackInfo(
new OnBackInvokedCallbackInfo(callback, OnBackInvokedDispatcher.PRIORITY_DEFAULT)); new OnBackInvokedCallbackInfo(
callback,
OnBackInvokedDispatcher.PRIORITY_DEFAULT,
/* isAnimationCallback = */ false));
return callback; return callback;
} }