Implement restoring & correct caching of snapshots

Introduce a retrieval cache that holds the last accessed
snapshots, in addition to the cache of the activities
that are the top most activtiy of a task that have a
running process.

Change everything to use an integer id instead of a Task object
to work around the issue that some tasks SystemUI might access
might not exist in WM yet (not yet restored from recents).

Don't put anything in the cache on the SystemUI side, but still
retrieve the thumbnails after a task changed event to make sure
the cache on the system_server side is fresh.

Test: runtest frameworks-services -c
com.android.server.wm.TaskSnapshotCacheTest

Bug: 31339431
Change-Id: I8e56365459a677735320adaa169da8fb033ceab0
diff --git a/services/core/java/com/android/server/am/TaskRecord.java b/services/core/java/com/android/server/am/TaskRecord.java
index db6c0f7..742988f 100644
--- a/services/core/java/com/android/server/am/TaskRecord.java
+++ b/services/core/java/com/android/server/am/TaskRecord.java
@@ -583,11 +583,14 @@
         mWindowContainerController.cancelThumbnailTransition();
     }
 
-    public TaskSnapshot getSnapshot() {
-        if (mWindowContainerController == null) {
-            return null;
-        }
-        return mWindowContainerController.getSnapshot();
+    /**
+     * DO NOT HOLD THE ACTIVITY MANAGER LOCK WHEN CALLING THIS METHOD!
+     */
+    TaskSnapshot getSnapshot() {
+
+        // TODO: Move this to {@link TaskWindowContainerController} once recent tasks are more
+        // synchronized between AM and WM.
+        return mService.mWindowManager.getTaskSnapshot(taskId, userId);
     }
 
     void touchActiveTime() {