Skip updating launcher state if it's already destroyed

- Prior to ag/9526193, there were a mixture of getCreatedActivity() and
  passed in Activity calls. In the cases where we used the passed in
  activity, it would happily make the call even if the activity is already
  destroyed, but since we migrated to using the unified getCreatedActivity()
  call, it results in an NPE. Since it's unnecessary to update the destroyed
  activity, we can simply skip this work.

  Long term, we should consider baking the activity associated with the
  call into the activity interface, and ensure that the interface itself
  is updated whenever the activity is recreated.

Bug: 141886704

Change-Id: I4f043e455d8d0d1c1b86362cc72618018bfbd900
Signed-off-by: Winson Chung <winsonc@google.com>
diff --git a/quickstep/recents_ui_overrides/src/com/android/quickstep/FallbackActivityInterface.java b/quickstep/recents_ui_overrides/src/com/android/quickstep/FallbackActivityInterface.java
index 3d1ecef..f889bc1 100644
--- a/quickstep/recents_ui_overrides/src/com/android/quickstep/FallbackActivityInterface.java
+++ b/quickstep/recents_ui_overrides/src/com/android/quickstep/FallbackActivityInterface.java
@@ -75,6 +75,9 @@
     @Override
     public void onSwipeUpToRecentsComplete() {
         RecentsActivity activity = getCreatedActivity();
+        if (activity == null) {
+            return;
+        }
         RecentsView recentsView = activity.getOverviewPanel();
         recentsView.getClearAllButton().setVisibilityAlpha(1);
         recentsView.setDisallowScrollToClearAll(false);
@@ -236,12 +239,18 @@
     public void onLaunchTaskFailed() {
         // TODO: probably go back to overview instead.
         RecentsActivity activity = getCreatedActivity();
+        if (activity == null) {
+            return;
+        }
         activity.<RecentsView>getOverviewPanel().startHome();
     }
 
     @Override
     public void onLaunchTaskSuccess() {
         RecentsActivity activity = getCreatedActivity();
+        if (activity == null) {
+            return;
+        }
         activity.onTaskLaunched();
     }
 }
diff --git a/quickstep/recents_ui_overrides/src/com/android/quickstep/LauncherActivityInterface.java b/quickstep/recents_ui_overrides/src/com/android/quickstep/LauncherActivityInterface.java
index 4406314..48b8fc6 100644
--- a/quickstep/recents_ui_overrides/src/com/android/quickstep/LauncherActivityInterface.java
+++ b/quickstep/recents_ui_overrides/src/com/android/quickstep/LauncherActivityInterface.java
@@ -94,6 +94,9 @@
     @Override
     public void onTransitionCancelled(boolean activityVisible) {
         Launcher launcher = getCreatedActivity();
+        if (launcher == null) {
+            return;
+        }
         LauncherState startState = launcher.getStateManager().getRestState();
         launcher.getStateManager().goToState(startState, activityVisible);
     }
@@ -102,32 +105,40 @@
     public void onSwipeUpToRecentsComplete() {
         // Re apply state in case we did something funky during the transition.
         Launcher launcher = getCreatedActivity();
+        if (launcher == null) {
+            return;
+        }
         launcher.getStateManager().reapplyState();
         DiscoveryBounce.showForOverviewIfNeeded(launcher);
     }
 
     @Override
     public void onSwipeUpToHomeComplete() {
+        Launcher launcher = getCreatedActivity();
+        if (launcher == null) {
+            return;
+        }
         // Ensure recents is at the correct position for NORMAL state. For example, when we detach
         // recents, we assume the first task is invisible, making translation off by one task.
-        Launcher launcher = getCreatedActivity();
         launcher.getStateManager().reapplyState();
         setLauncherHideBackArrow(false);
     }
 
     private void setLauncherHideBackArrow(boolean hideBackArrow) {
         Launcher launcher = getCreatedActivity();
-        if (launcher != null) {
-            launcher.getRootView().setForceHideBackArrow(hideBackArrow);
+        if (launcher == null) {
+            return;
         }
+        launcher.getRootView().setForceHideBackArrow(hideBackArrow);
     }
 
     @Override
     public void onAssistantVisibilityChanged(float visibility) {
         Launcher launcher = getCreatedActivity();
-        if (launcher != null) {
-            launcher.onAssistantVisibilityChanged(visibility);
+        if (launcher == null) {
+            return;
         }
+        launcher.onAssistantVisibilityChanged(visibility);
     }
 
     @NonNull
@@ -476,12 +487,18 @@
     @Override
     public void onLaunchTaskFailed() {
         Launcher launcher = getCreatedActivity();
+        if (launcher == null) {
+            return;
+        }
         launcher.getStateManager().goToState(OVERVIEW);
     }
 
     @Override
     public void onLaunchTaskSuccess() {
         Launcher launcher = getCreatedActivity();
+        if (launcher == null) {
+            return;
+        }
         launcher.getStateManager().moveToRestState();
     }
 
@@ -503,6 +520,9 @@
     public void switchRunningTaskViewToScreenshot(ThumbnailData thumbnailData,
             Runnable onFinishRunnable) {
         Launcher launcher = getCreatedActivity();
+        if (launcher == null) {
+            return;
+        }
         RecentsView recentsView = launcher.getOverviewPanel();
         if (recentsView == null) {
             if (onFinishRunnable != null) {
@@ -516,8 +536,9 @@
     @Override
     public void setOnDeferredActivityLaunchCallback(Runnable r) {
         Launcher launcher = getCreatedActivity();
-        if (launcher != null) {
-            launcher.setOnDeferredActivityLaunchCallback(r);
+        if (launcher == null) {
+            return;
         }
+        launcher.setOnDeferredActivityLaunchCallback(r);
     }
 }
\ No newline at end of file