Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3531dd06 authored by Matthew Ng's avatar Matthew Ng
Browse files

Test for writing and loading reduced resolution task snapshots

Added a test to write and load only low resolution task snapshots if the
snapshot's flag of reducedResolution is set to true. Then verify only
the low resolution bitmap is saved and not the full sized. This is for
the change ag/2579729.

Test: runtest frameworks-services -c
com.android.server.wm.TaskSnapshotPersisterLoaderTest
Bug: 63940837
Change-Id: I685046bdac0cddb9e24271152c91e7912c595e7f
parent 45e8fe20
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -68,7 +68,7 @@ class TaskSnapshotLoader {
        final File bitmapFile = reducedResolution
                ? mPersister.getReducedResolutionBitmapFile(taskId, userId)
                : mPersister.getBitmapFile(taskId, userId);
        if (!protoFile.exists() || !bitmapFile.exists()) {
        if (bitmapFile == null || !protoFile.exists() || !bitmapFile.exists()) {
            return null;
        }
        try {
+24 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package com.android.server.wm;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

@@ -139,6 +140,29 @@ public class TaskSnapshotPersisterLoaderTest extends TaskSnapshotPersisterTestBa
        assertEquals(1, removeObsoleteFilesQueueItem.getTaskId("1_reduced.jpg"));
    }

    @Test
    public void testLowResolutionPersistAndLoadSnapshot() {
        TaskSnapshot a = createSnapshot(0.5f /* reducedResolution */);
        assertTrue(a.isReducedResolution());
        mPersister.persistSnapshot(1 , mTestUserId, a);
        mPersister.waitForQueueEmpty();
        final File[] files = new File[] { new File(sFilesDir.getPath() + "/snapshots/1.proto"),
                new File(sFilesDir.getPath() + "/snapshots/1_reduced.jpg")};
        final File[] nonExistsFiles = new File[] {
                new File(sFilesDir.getPath() + "/snapshots/1.jpg"),
        };
        assertTrueForFiles(files, File::exists, " must exist");
        assertTrueForFiles(nonExistsFiles, file -> !file.exists(), " must not exist");
        final TaskSnapshot snapshot = mLoader.loadTask(1, mTestUserId, true /* reduced */);
        assertNotNull(snapshot);
        assertEquals(TEST_INSETS, snapshot.getContentInsets());
        assertNotNull(snapshot.getSnapshot());
        assertEquals(Configuration.ORIENTATION_PORTRAIT, snapshot.getOrientation());

        final TaskSnapshot snapshotNotExist = mLoader.loadTask(1, mTestUserId, false /* reduced */);
        assertNull(snapshotNotExist);
    }

    @Test
    public void testRemoveObsoleteFiles() {
        mPersister.persistSnapshot(1, mTestUserId, createSnapshot());
+5 −1
Original line number Diff line number Diff line
@@ -80,12 +80,16 @@ class TaskSnapshotPersisterTestBase extends WindowTestsBase {
    }

    TaskSnapshot createSnapshot() {
        return createSnapshot(1f /* scale */);
    }

    TaskSnapshot createSnapshot(float scale) {
        final GraphicBuffer buffer = GraphicBuffer.create(100, 100, PixelFormat.RGBA_8888,
                USAGE_HW_TEXTURE | USAGE_SW_READ_RARELY | USAGE_SW_READ_RARELY);
        Canvas c = buffer.lockCanvas();
        c.drawColor(Color.RED);
        buffer.unlockCanvasAndPost(c);
        return new TaskSnapshot(buffer, ORIENTATION_PORTRAIT, TEST_INSETS,
                false /* reducedResolution */, 1f /* scale */);
                scale < 1f /* reducedResolution */, scale);
    }
}