Moving check for empty snapshots earlier.

- This also prevents them from being added to the cache and reporting that
  the snapshot changed.

Bug: 62727429
Test: bit FrameworksServicesTests:com.android.server.wm.TaskSnapshotControllerTest,com.android.server.wm.TaskSnapshotPersisterLoaderTest,com.android.server.wm.TaskSnapshotCacheTest

Change-Id: Ie02f120e5460322da28faa8a5679191024377c4c
Signed-off-by: Winson Chung <winsonc@google.com>
diff --git a/services/core/java/com/android/server/wm/TaskSnapshotPersister.java b/services/core/java/com/android/server/wm/TaskSnapshotPersister.java
index b628869..f90b3fb 100644
--- a/services/core/java/com/android/server/wm/TaskSnapshotPersister.java
+++ b/services/core/java/com/android/server/wm/TaskSnapshotPersister.java
@@ -291,7 +291,6 @@
                 failed = true;
             }
             if (!writeBuffer()) {
-                writeBuffer();
                 failed = true;
             }
             if (failed) {
@@ -327,11 +326,7 @@
             final File reducedFile = getReducedResolutionBitmapFile(mTaskId, mUserId);
             final Bitmap bitmap = Bitmap.createHardwareBitmap(mSnapshot.getSnapshot());
             if (bitmap == null) {
-                Slog.e(TAG, "Invalid task snapshot");
-                return false;
-            } else if (bitmap.getWidth() == 0 || bitmap.getHeight() == 0) {
-                Slog.e(TAG, "Invalid task snapshot dimensions " + bitmap.getWidth() + "x"
-                        + bitmap.getHeight());
+                Slog.e(TAG, "Invalid task snapshot hw bitmap");
                 return false;
             }