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

Commit c3cc8b9e authored by Peter Kalauskas's avatar Peter Kalauskas
Browse files

Remove unused setter

setEnableLowResSnapshots was only added for testing, but it is unused
because we are using a Resource mock to override the value. This is a
better way to test the feature because it ensures expected behavior of
the config overlay.

In addition: remove duplicate test, fix comments for test, and add new
assertions. Also, removed setIsLowResolution in test Builder class to
reflect ActivityManager.TaskSnapshot.Builder.

Test: TaskSnapshotCacheTest
Test: TaskSnapshotControllerTest
Test: TaskSnapshotPersisterLoaderTest
Test: TaskSnapshotSurfaceTest
Bug: 142063079
Change-Id: I83a9503a2f75490e5cf80bdc93041208c4897c6e
parent 093ba7e5
Loading
Loading
Loading
Loading
+3 −11
Original line number Diff line number Diff line
@@ -99,10 +99,10 @@ class TaskSnapshotPersister {

        if (lowResTaskSnapshotScale > 0) {
            mLowResScaleFactor = lowResTaskSnapshotScale / highResTaskSnapshotScale;
            setEnableLowResSnapshots(true);
            mEnableLowResSnapshots = true;
        } else {
            mLowResScaleFactor = 0;
            setEnableLowResSnapshots(false);
            mEnableLowResSnapshots = false;
        }

        mUse16BitFormat = service.mContext.getResources().getBoolean(
@@ -174,14 +174,6 @@ class TaskSnapshotPersister {
        return mEnableLowResSnapshots;
    }

    /**
     * Not to be used. Only here for testing.
     */
    @VisibleForTesting
    void setEnableLowResSnapshots(boolean enabled) {
        mEnableLowResSnapshots = enabled;
    }

    /**
     * Return if task snapshots are stored in 16 bit pixel format.
     *
@@ -405,7 +397,7 @@ class TaskSnapshotPersister {
                return false;
            }

            if (!enableLowResSnapshots()) {
            if (!mEnableLowResSnapshots) {
                swBitmap.recycle();
                return true;
            }
+10 −2
Original line number Diff line number Diff line
@@ -81,9 +81,9 @@ public class TaskSnapshotLowResDisabledTest extends TaskSnapshotPersisterTestBas
        assertEquals(TEST_INSETS, snapshot.getContentInsets());
        assertNotNull(snapshot.getSnapshot());
        assertEquals(Configuration.ORIENTATION_PORTRAIT, snapshot.getOrientation());
        assertNull(mLoader.loadTask(1, mTestUserId, true /* isLowResolution */));
    }


    @Test
    public void testRemoveObsoleteFiles() {
        mPersister.persistSnapshot(1, mTestUserId, createSnapshot());
@@ -132,10 +132,18 @@ public class TaskSnapshotLowResDisabledTest extends TaskSnapshotPersisterTestBas
        assertNull(mCache.getSnapshot(window.getTask().mTaskId, mWm.mCurrentUserId,
                false /* restoreFromDisk */, false /* isLowResolution */));

        // Load it from disk
        // Attempt to load the low-res snapshot from the disk
        assertNull(mCache.getSnapshot(window.getTask().mTaskId, mWm.mCurrentUserId,
                true /* restoreFromDisk */, true /* isLowResolution */));

        // Load the high-res (default) snapshot from disk
        assertNotNull(mCache.getSnapshot(window.getTask().mTaskId, mWm.mCurrentUserId,
                true /* restoreFromDisk */, false /* isLowResolution */));

        // Make sure it's not in the cache now.
        assertNull(mCache.getSnapshot(window.getTask().mTaskId, mWm.mCurrentUserId,
                false /* restoreFromDisk */, true /* isLowResolution */));

        // Make sure it's not in the cache now.
        assertNull(mCache.getSnapshot(window.getTask().mTaskId, mWm.mCurrentUserId,
                false /* restoreFromDisk */, false /* isLowResolution */));
+0 −29
Original line number Diff line number Diff line
@@ -292,35 +292,6 @@ public class TaskSnapshotPersisterLoaderTest extends TaskSnapshotPersisterTestBa
        assertNull(lowResConf);
    }

    @Test
    public void testDisabledLowResolutionPersistAndLoadSnapshot() {
        mPersister.setEnableLowResSnapshots(false);

        TaskSnapshot a = new TaskSnapshotBuilder()
                .setScaleFraction(0.5f)
                .setIsLowResolution(true)
                .build();
        assertTrue(a.isLowResolution());
        mPersister.persistSnapshot(1, mTestUserId, a);
        mPersister.waitForQueueEmpty();
        final File[] files = new File[]{new File(FILES_DIR.getPath() + "/snapshots/1.proto"),
                new File(FILES_DIR.getPath() + "/snapshots/1.jpg")};
        final File[] nonExistsFiles = new File[]{
                new File(FILES_DIR.getPath() + "/snapshots/1_reduced.jpg"),
        };
        assertTrueForFiles(files, File::exists, " must exist");
        assertTrueForFiles(nonExistsFiles, file -> !file.exists(), " must not exist");
        final TaskSnapshot snapshot = mLoader.loadTask(1, mTestUserId, false /* isLowResolution */);
        assertNotNull(snapshot);
        assertEquals(TEST_INSETS, snapshot.getContentInsets());
        assertNotNull(snapshot.getSnapshot());
        assertEquals(Configuration.ORIENTATION_PORTRAIT, snapshot.getOrientation());

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

    @Test
    public void testIsRealSnapshotPersistAndLoadSnapshot() {
        TaskSnapshot a = new TaskSnapshotBuilder()
+5 −8
Original line number Diff line number Diff line
@@ -127,7 +127,6 @@ class TaskSnapshotPersisterTestBase extends WindowTestsBase {
        private static final int SNAPSHOT_HEIGHT = 100;

        private float mScaleFraction = 1f;
        private boolean mIsLowResolution = false;
        private boolean mIsRealSnapshot = true;
        private boolean mIsTranslucent = false;
        private int mWindowingMode = WINDOWING_MODE_FULLSCREEN;
@@ -142,11 +141,6 @@ class TaskSnapshotPersisterTestBase extends WindowTestsBase {
            return this;
        }

        TaskSnapshotBuilder setIsLowResolution(boolean isLowResolution) {
            mIsLowResolution = isLowResolution;
            return this;
        }

        TaskSnapshotBuilder setIsRealSnapshot(boolean isRealSnapshot) {
            mIsRealSnapshot = isRealSnapshot;
            return this;
@@ -186,8 +180,11 @@ class TaskSnapshotPersisterTestBase extends WindowTestsBase {
            return new TaskSnapshot(MOCK_SNAPSHOT_ID, new ComponentName("", ""), buffer,
                    ColorSpace.get(ColorSpace.Named.SRGB), ORIENTATION_PORTRAIT,
                    mRotation, taskSize, TEST_INSETS,
                    mIsLowResolution, mIsRealSnapshot,
                    mWindowingMode, mSystemUiVisibility, mIsTranslucent);
                    // When building a TaskSnapshot with the Builder class, isLowResolution
                    // is always false. Low-res snapshots are only created when loading from
                    // disk.
                    false /* isLowResolution */,
                    mIsRealSnapshot, mWindowingMode, mSystemUiVisibility, mIsTranslucent);
        }
    }
}