Use current rotation for snapshot of canceling fixed rotation

The display rotation doesn't change in the case (the app is rotated).
So use the identity matrix for the snapshot surface.

Also fix a potential case of app freeze timeout:
(e.g. from AR#onCancelFixedRotationTransform)
1. Previous states: allDrawn=true, mLastAllDrawn=true.
2. Request redraw:
   AR#clearAllDrawn -> allDrawn=false, mLastAllDrawn=true
3. App reported drawn:
   AR#updateAllDrawn -> allDrawn=true, mLastAllDrawn=true
4. AR#checkAppWindowsReadyToShow skipped by allDrawn==mLastAllDrawn
   that missed to unfreeze even allDrawn was changed to true.

Bug: 188615885
Test: Auto rotation enabled. Put device in landscape. Launch a
      rotatable app from portrait launcher and rotate the device
      to portrait immediately. The snapshot should keep the same
      rotation for animation.

Change-Id: If9fe8e317669d3d9ef57af9acdbdbf53cd575efe
diff --git a/services/core/java/com/android/server/wm/ActivityRecord.java b/services/core/java/com/android/server/wm/ActivityRecord.java
index b55e653..6d2b2d3 100644
--- a/services/core/java/com/android/server/wm/ActivityRecord.java
+++ b/services/core/java/com/android/server/wm/ActivityRecord.java
@@ -4213,6 +4213,7 @@
 
     void clearAllDrawn() {
         allDrawn = false;
+        mLastAllDrawn = false;
     }
 
     /**
diff --git a/services/core/java/com/android/server/wm/ScreenRotationAnimation.java b/services/core/java/com/android/server/wm/ScreenRotationAnimation.java
index d67a0d3..50749a9 100644
--- a/services/core/java/com/android/server/wm/ScreenRotationAnimation.java
+++ b/services/core/java/com/android/server/wm/ScreenRotationAnimation.java
@@ -253,7 +253,16 @@
 
         ProtoLog.i(WM_SHOW_SURFACE_ALLOC,
                 "  FREEZE %s: CREATE", mScreenshotLayer);
-        setRotation(t, realOriginalRotation);
+        if (originalRotation == realOriginalRotation) {
+            setRotation(t, realOriginalRotation);
+        } else {
+            // If the given original rotation is different from real original display rotation,
+            // this is playing non-zero degree rotation animation without display rotation change,
+            // so the snapshot doesn't need to be transformed.
+            mCurRotation = realOriginalRotation;
+            mSnapshotInitialMatrix.reset();
+            setRotationTransform(t, mSnapshotInitialMatrix);
+        }
         t.apply();
     }