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

Commit 5e4f6dad authored by Matthew Ng's avatar Matthew Ng Committed by android-build-merger
Browse files

Merge "Test for writing and loading reduced resolution task snapshots" into oc-mr1-dev

am: b952c755

Change-Id: I66e78a3eb612a16d9dfcac749cb68c4f9e2e7334
parents 3490fd43 b952c755
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);
    }
}