Loading services/core/java/com/android/server/wm/TaskSnapshotLoader.java +1 −1 Original line number Diff line number Diff line Loading @@ -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 { Loading services/tests/servicestests/src/com/android/server/wm/TaskSnapshotPersisterLoaderTest.java +24 −0 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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()); Loading services/tests/servicestests/src/com/android/server/wm/TaskSnapshotPersisterTestBase.java +5 −1 Original line number Diff line number Diff line Loading @@ -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); } } Loading
services/core/java/com/android/server/wm/TaskSnapshotLoader.java +1 −1 Original line number Diff line number Diff line Loading @@ -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 { Loading
services/tests/servicestests/src/com/android/server/wm/TaskSnapshotPersisterLoaderTest.java +24 −0 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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()); Loading
services/tests/servicestests/src/com/android/server/wm/TaskSnapshotPersisterTestBase.java +5 −1 Original line number Diff line number Diff line Loading @@ -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); } }