From 15028e030be7977e60281541bd3cbd8f82153528 Mon Sep 17 00:00:00 2001 From: Vinit Nayak Date: Fri, 15 Oct 2021 13:00:28 -0700 Subject: [PATCH] Handle race between creating and assigning RemoteTargetHandles * Getting a callback from shell to inform when task is in split and when it's been removed is asynchronous, and not coordinated with launcher's swipe up gesture. * There's a chance that user can quickswitch to single app and start swipe up before shell could notify LauncherSplitScreenListener, which would cause mismatched state. Bug: 199658495 Change-Id: I722eeb26d83e99b2a2f77748984d0d7c390b5fec --- .../com/android/quickstep/RemoteTargetGluer.java | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/quickstep/src/com/android/quickstep/RemoteTargetGluer.java b/quickstep/src/com/android/quickstep/RemoteTargetGluer.java index dc04016898..7ef4d19283 100644 --- a/quickstep/src/com/android/quickstep/RemoteTargetGluer.java +++ b/quickstep/src/com/android/quickstep/RemoteTargetGluer.java @@ -16,9 +16,8 @@ package com.android.quickstep; -import static android.view.WindowManager.LayoutParams.TYPE_DOCK_DIVIDER; - import android.content.Context; +import android.util.Log; import androidx.annotation.Nullable; @@ -34,7 +33,9 @@ import com.android.systemui.shared.system.RemoteAnimationTargetCompat; * {@link TaskViewSimulator} */ public class RemoteTargetGluer { - private final RemoteTargetHandle[] mRemoteTargetHandles; + private static final String TAG = "RemoteTargetGluer"; + + private RemoteTargetHandle[] mRemoteTargetHandles; private SplitConfigurationOptions.StagedSplitBounds mStagedSplitBounds; /** @@ -93,6 +94,13 @@ public class RemoteTargetGluer { public RemoteTargetHandle[] assignTargetsForSplitScreen(RemoteAnimationTargets targets) { int[] splitIds = LauncherSplitScreenListener.INSTANCE.getNoCreate() .getRunningSplitTaskIds(); + if (splitIds.length == 0 && mRemoteTargetHandles.length > 1) { + // There's a chance that between the creation of this class and assigning targets, + // LauncherSplitScreenListener may have received callback that removes split + mRemoteTargetHandles = new RemoteTargetHandle[]{mRemoteTargetHandles[0]}; + Log.w(TAG, "splitTaskIds changed between creation and assignment"); + } + RemoteAnimationTargetCompat primaryTaskTarget; RemoteAnimationTargetCompat secondaryTaskTarget; if (mRemoteTargetHandles.length == 1) {