Fix NPE from using DeviceLockedInputConsumer after the surface has been released

Fixes: 243154747
Test: swipe up from camera app while device is locked
Change-Id: Ia92e3e3cccb37e0d14592b0f3094f5aba1073300
diff --git a/quickstep/src/com/android/quickstep/inputconsumers/DeviceLockedInputConsumer.java b/quickstep/src/com/android/quickstep/inputconsumers/DeviceLockedInputConsumer.java
index 8410149..db7e087 100644
--- a/quickstep/src/com/android/quickstep/inputconsumers/DeviceLockedInputConsumer.java
+++ b/quickstep/src/com/android/quickstep/inputconsumers/DeviceLockedInputConsumer.java
@@ -53,6 +53,7 @@
 import com.android.quickstep.RecentsAnimationController;
 import com.android.quickstep.RecentsAnimationDeviceState;
 import com.android.quickstep.RecentsAnimationTargets;
+import com.android.quickstep.RemoteAnimationTargets;
 import com.android.quickstep.TaskAnimationManager;
 import com.android.quickstep.util.SurfaceTransaction.SurfaceProperties;
 import com.android.quickstep.util.TransformParams;
@@ -226,6 +227,10 @@
                     mStateCallback.setState(STATE_HANDLER_INVALIDATED);
                 }
             });
+            RemoteAnimationTargets targets = mTransformParams.getTargetSet();
+            if (targets != null) {
+                targets.addReleaseCheck(new DeviceLockedReleaseCheck(animator));
+            }
             animator.start();
         } else {
             mStateCallback.setState(STATE_HANDLER_INVALIDATED);
@@ -304,4 +309,27 @@
     public boolean allowInterceptByParent() {
         return !mThresholdCrossed;
     }
+
+    private static final class DeviceLockedReleaseCheck extends
+            RemoteAnimationTargets.ReleaseCheck {
+
+        private DeviceLockedReleaseCheck(Animator animator) {
+            setCanRelease(true);
+
+            animator.addListener(new AnimatorListenerAdapter() {
+
+                @Override
+                public void onAnimationStart(Animator animation) {
+                    super.onAnimationStart(animation);
+                    setCanRelease(false);
+                }
+
+                @Override
+                public void onAnimationEnd(Animator animation) {
+                    super.onAnimationEnd(animation);
+                    setCanRelease(true);
+                }
+            });
+        }
+    }
 }