Add config to control full task snapshot scale

- Also save the scale with the snapshot data instead of trying to infer it
  from the state
- Also recycle the reduced resolution snapshot copy after writing it

Bug: 135150767
Test: atest TaskSnapshotPersisterLoaderTest
Change-Id: I64a9ccf16f3966ad5c6d07ff0b6ce8e9dd710e40
diff --git a/services/core/java/com/android/server/wm/TaskSnapshotPersister.java b/services/core/java/com/android/server/wm/TaskSnapshotPersister.java
index 0b63f48..72fc189 100644
--- a/services/core/java/com/android/server/wm/TaskSnapshotPersister.java
+++ b/services/core/java/com/android/server/wm/TaskSnapshotPersister.java
@@ -342,6 +342,7 @@
             proto.systemUiVisibility = mSnapshot.getSystemUiVisibility();
             proto.isTranslucent = mSnapshot.isTranslucent();
             proto.topActivityComponent = mSnapshot.getTopActivityComponent().flattenToString();
+            proto.scale = mSnapshot.getScale();
             final byte[] bytes = TaskSnapshotProto.toByteArray(proto);
             final File file = getProtoFile(mTaskId, mUserId);
             final AtomicFile atomicFile = new AtomicFile(file);
@@ -369,12 +370,13 @@
             }
 
             final Bitmap swBitmap = bitmap.copy(Config.ARGB_8888, false /* isMutable */);
-            final File reducedFile = getReducedResolutionBitmapFile(mTaskId, mUserId);
             final Bitmap reduced = mSnapshot.isReducedResolution()
                     ? swBitmap
                     : Bitmap.createScaledBitmap(swBitmap,
                             (int) (bitmap.getWidth() * mReducedScale),
                             (int) (bitmap.getHeight() * mReducedScale), true /* filter */);
+
+            final File reducedFile = getReducedResolutionBitmapFile(mTaskId, mUserId);
             try {
                 FileOutputStream reducedFos = new FileOutputStream(reducedFile);
                 reduced.compress(JPEG, QUALITY, reducedFos);
@@ -383,6 +385,7 @@
                 Slog.e(TAG, "Unable to open " + reducedFile +" for persisting.", e);
                 return false;
             }
+            reduced.recycle();
 
             // For snapshots with reduced resolution, do not create or save full sized bitmaps
             if (mSnapshot.isReducedResolution()) {
@@ -399,7 +402,6 @@
                 Slog.e(TAG, "Unable to open " + file + " for persisting.", e);
                 return false;
             }
-            reduced.recycle();
             swBitmap.recycle();
             return true;
         }