Copy resume callbacks list prior to making callbacks

- Starting a deferred activity can trigger a new callback to be added
  to the list while we are iterating it

Bug: 136613192
Change-Id: I6690ab0695bb73f11bf343fb41e9fc86b4afec1b
Merged-In: I6690ab0695bb73f11bf343fb41e9fc86b4afec1b
(cherry picked from commit 940b0ac0157945a40d8b3b44d976da53aaeff81f)
(cherry picked from commit a8971c1462f276b2b4d6daab6b18941b9dc9a94a)
diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java
index d9af4da..bc3aa7e 100644
--- a/src/com/android/launcher3/Launcher.java
+++ b/src/com/android/launcher3/Launcher.java
@@ -952,10 +952,14 @@
         mHandler.removeCallbacks(mHandleDeferredResume);
         Utilities.postAsyncCallback(mHandler, mHandleDeferredResume);
 
-        for (OnResumeCallback cb : mOnResumeCallbacks) {
-            cb.onLauncherResume();
+        if (!mOnResumeCallbacks.isEmpty()) {
+            final ArrayList<OnResumeCallback> resumeCallbacks = new ArrayList<>(mOnResumeCallbacks);
+            mOnResumeCallbacks.clear();
+            for (int i = resumeCallbacks.size() - 1; i >= 0; i--) {
+                resumeCallbacks.get(i).onLauncherResume();
+            }
+            resumeCallbacks.clear();
         }
-        mOnResumeCallbacks.clear();
 
         if (mLauncherCallbacks != null) {
             mLauncherCallbacks.onResume();