Fixing activity referred after destroying by PinnedStackAnimationListener

This is perhaps not a leak, but it conflicts with how StrictMode
activity leak detection works.

Bug: 139137636
Change-Id: If7fd0361b8e5ff81a2c0adb2308793ff87349951
diff --git a/quickstep/recents_ui_overrides/src/com/android/quickstep/views/RecentsView.java b/quickstep/recents_ui_overrides/src/com/android/quickstep/views/RecentsView.java
index 27ef93c..114071a 100644
--- a/quickstep/recents_ui_overrides/src/com/android/quickstep/views/RecentsView.java
+++ b/quickstep/recents_ui_overrides/src/com/android/quickstep/views/RecentsView.java
@@ -268,15 +268,8 @@
         }
     };
 
-    private final IPinnedStackAnimationListener mIPinnedStackAnimationListener =
-            new IPinnedStackAnimationListener.Stub() {
-        @Override
-        public void onPinnedStackAnimationStarted() {
-            // Needed for activities that auto-enter PiP, which will not trigger a remote
-            // animation to be created
-            mActivity.clearForceInvisibleFlag(STATE_HANDLER_INVISIBILITY_FLAGS);
-        }
-    };
+    private final PinnedStackAnimationListener mIPinnedStackAnimationListener =
+            new PinnedStackAnimationListener();
 
     // Used to keep track of the last requested task list id, so that we do not request to load the
     // tasks again if we have already requested it and the task list has not changed
@@ -451,6 +444,7 @@
         mSyncTransactionApplier = new SyncRtSurfaceTransactionApplierCompat(this);
         RecentsModel.INSTANCE.get(getContext()).addThumbnailChangeListener(this);
         mIdp.addOnChangeListener(this);
+        mIPinnedStackAnimationListener.setActivity(mActivity);
         SystemUiProxy.INSTANCE.get(getContext()).setPinnedStackAnimationListener(
                 mIPinnedStackAnimationListener);
     }
@@ -466,6 +460,7 @@
         RecentsModel.INSTANCE.get(getContext()).removeThumbnailChangeListener(this);
         mIdp.removeOnChangeListener(this);
         SystemUiProxy.INSTANCE.get(getContext()).setPinnedStackAnimationListener(null);
+        mIPinnedStackAnimationListener.setActivity(null);
     }
 
     @Override
@@ -1962,4 +1957,20 @@
         /** @param isEmpty Whether RecentsView is empty (i.e. has no children) */
         void onEmptyMessageUpdated(boolean isEmpty);
     }
+
+    private static class PinnedStackAnimationListener<T extends BaseActivity> extends
+            IPinnedStackAnimationListener.Stub {
+        private T mActivity;
+
+        public void setActivity(T activity) {
+            mActivity = activity;
+        }
+
+        @Override
+        public void onPinnedStackAnimationStarted() {
+            // Needed for activities that auto-enter PiP, which will not trigger a remote
+            // animation to be created
+            mActivity.clearForceInvisibleFlag(STATE_HANDLER_INVISIBILITY_FLAGS);
+        }
+    }
 }