diff --git a/core/java/android/app/ActivityManager.java b/core/java/android/app/ActivityManager.java index 2d73ce0c05945..a18ba718ecef3 100644 --- a/core/java/android/app/ActivityManager.java +++ b/core/java/android/app/ActivityManager.java @@ -2101,15 +2101,17 @@ public class ActivityManager { private final int mOrientation; private final Rect mContentInsets; private final boolean mReducedResolution; + private final boolean mIsRealSnapshot; private final float mScale; public TaskSnapshot(GraphicBuffer snapshot, int orientation, Rect contentInsets, - boolean reducedResolution, float scale) { + boolean reducedResolution, float scale, boolean isRealSnapshot) { mSnapshot = snapshot; mOrientation = orientation; mContentInsets = new Rect(contentInsets); mReducedResolution = reducedResolution; mScale = scale; + mIsRealSnapshot = isRealSnapshot; } private TaskSnapshot(Parcel source) { @@ -2118,6 +2120,7 @@ public class ActivityManager { mContentInsets = source.readParcelable(null /* classLoader */); mReducedResolution = source.readBoolean(); mScale = source.readFloat(); + mIsRealSnapshot = source.readBoolean(); } /** @@ -2149,6 +2152,14 @@ public class ActivityManager { return mReducedResolution; } + /** + * @return Whether or not the snapshot is a real snapshot or an app-theme generated snapshot + * due to the task having a secure window or having previews disabled. + */ + public boolean isRealSnapshot() { + return mIsRealSnapshot; + } + /** * @return The scale this snapshot was taken in. */ @@ -2168,13 +2179,15 @@ public class ActivityManager { dest.writeParcelable(mContentInsets, 0); dest.writeBoolean(mReducedResolution); dest.writeFloat(mScale); + dest.writeBoolean(mIsRealSnapshot); } @Override public String toString() { return "TaskSnapshot{mSnapshot=" + mSnapshot + " mOrientation=" + mOrientation + " mContentInsets=" + mContentInsets.toShortString() - + " mReducedResolution=" + mReducedResolution + " mScale=" + mScale; + + " mReducedResolution=" + mReducedResolution + " mScale=" + mScale + + " mIsRealSnapshot=" + mIsRealSnapshot; } public static final Creator CREATOR = new Creator() { diff --git a/packages/SystemUI/shared/src/com/android/systemui/shared/recents/model/ThumbnailData.java b/packages/SystemUI/shared/src/com/android/systemui/shared/recents/model/ThumbnailData.java index dd1763bb118bf..924e85dec37a4 100644 --- a/packages/SystemUI/shared/src/com/android/systemui/shared/recents/model/ThumbnailData.java +++ b/packages/SystemUI/shared/src/com/android/systemui/shared/recents/model/ThumbnailData.java @@ -31,6 +31,7 @@ public class ThumbnailData { public int orientation; public Rect insets; public boolean reducedResolution; + public boolean isRealSnapshot; public float scale; public ThumbnailData() { @@ -39,6 +40,7 @@ public class ThumbnailData { insets = new Rect(); reducedResolution = false; scale = 1f; + isRealSnapshot = true; } public ThumbnailData(TaskSnapshot snapshot) { @@ -47,5 +49,6 @@ public class ThumbnailData { orientation = snapshot.getOrientation(); reducedResolution = snapshot.isReducedResolution(); scale = snapshot.getScale(); + isRealSnapshot = snapshot.isRealSnapshot(); } } diff --git a/proto/src/task_snapshot.proto b/proto/src/task_snapshot.proto index c9d5c272d48c9..490a59e770ecc 100644 --- a/proto/src/task_snapshot.proto +++ b/proto/src/task_snapshot.proto @@ -27,4 +27,5 @@ int32 inset_top = 3; int32 inset_right = 4; int32 inset_bottom = 5; + bool is_real_snapshot = 6; } \ No newline at end of file diff --git a/services/core/java/com/android/server/wm/TaskSnapshotController.java b/services/core/java/com/android/server/wm/TaskSnapshotController.java index a5a1ca5a9ffe2..9310dc488c747 100644 --- a/services/core/java/com/android/server/wm/TaskSnapshotController.java +++ b/services/core/java/com/android/server/wm/TaskSnapshotController.java @@ -273,7 +273,8 @@ class TaskSnapshotController { } return new TaskSnapshot(buffer, top.getConfiguration().orientation, getInsetsFromTaskBounds(mainWindow, task), - isLowRamDevice /* reduced */, scaleFraction /* scale */); + isLowRamDevice /* reduced */, scaleFraction /* scale */, + true /* isRealSnapshot */); } private boolean shouldDisableSnapshots() { @@ -369,7 +370,8 @@ class TaskSnapshotController { } return new TaskSnapshot(hwBitmap.createGraphicBufferHandle(), topChild.getConfiguration().orientation, mainWindow.mStableInsets, - ActivityManager.isLowRamDeviceStatic() /* reduced */, 1.0f /* scale */); + ActivityManager.isLowRamDeviceStatic() /* reduced */, 1.0f /* scale */, + false /* isRealSnapshot */); } /** diff --git a/services/core/java/com/android/server/wm/TaskSnapshotLoader.java b/services/core/java/com/android/server/wm/TaskSnapshotLoader.java index 537f31775951a..31da5f3ff1c8a 100644 --- a/services/core/java/com/android/server/wm/TaskSnapshotLoader.java +++ b/services/core/java/com/android/server/wm/TaskSnapshotLoader.java @@ -89,7 +89,8 @@ class TaskSnapshotLoader { } return new TaskSnapshot(buffer, proto.orientation, new Rect(proto.insetLeft, proto.insetTop, proto.insetRight, proto.insetBottom), - reducedResolution, reducedResolution ? REDUCED_SCALE : 1f); + reducedResolution, reducedResolution ? REDUCED_SCALE : 1f, + proto.isRealSnapshot); } catch (IOException e) { Slog.w(TAG, "Unable to load task snapshot data for taskId=" + taskId); return null; diff --git a/services/core/java/com/android/server/wm/TaskSnapshotPersister.java b/services/core/java/com/android/server/wm/TaskSnapshotPersister.java index 621bee7d17e01..086fffa9d6214 100644 --- a/services/core/java/com/android/server/wm/TaskSnapshotPersister.java +++ b/services/core/java/com/android/server/wm/TaskSnapshotPersister.java @@ -318,6 +318,7 @@ class TaskSnapshotPersister { proto.insetTop = mSnapshot.getContentInsets().top; proto.insetRight = mSnapshot.getContentInsets().right; proto.insetBottom = mSnapshot.getContentInsets().bottom; + proto.isRealSnapshot = mSnapshot.isRealSnapshot(); final byte[] bytes = TaskSnapshotProto.toByteArray(proto); final File file = getProtoFile(mTaskId, mUserId); final AtomicFile atomicFile = new AtomicFile(file); diff --git a/services/tests/servicestests/src/com/android/server/wm/TaskSnapshotPersisterLoaderTest.java b/services/tests/servicestests/src/com/android/server/wm/TaskSnapshotPersisterLoaderTest.java index 96fbc14022964..80cbf2aae3f05 100644 --- a/services/tests/servicestests/src/com/android/server/wm/TaskSnapshotPersisterLoaderTest.java +++ b/services/tests/servicestests/src/com/android/server/wm/TaskSnapshotPersisterLoaderTest.java @@ -42,7 +42,7 @@ import java.io.File; /** * Test class for {@link TaskSnapshotPersister} and {@link TaskSnapshotLoader} * - * runtest frameworks-services -c com.android.server.wm.TaskSnapshotPersisterLoaderTest + * atest FrameworksServicesTests:TaskSnapshotPersisterLoaderTest */ @MediumTest @Presubmit @@ -162,6 +162,23 @@ public class TaskSnapshotPersisterLoaderTest extends TaskSnapshotPersisterTestBa assertNull(snapshotNotExist); } + @Test + public void testIsRealSnapshotPersistAndLoadSnapshot() { + TaskSnapshot a = createSnapshot(1f /* scale */, true /* isRealSnapshot */); + TaskSnapshot b = createSnapshot(1f /* scale */, false /* isRealSnapshot */); + assertTrue(a.isRealSnapshot()); + assertFalse(b.isRealSnapshot()); + mPersister.persistSnapshot(1, mTestUserId, a); + mPersister.persistSnapshot(2, mTestUserId, b); + mPersister.waitForQueueEmpty(); + final TaskSnapshot snapshotA = mLoader.loadTask(1, mTestUserId, false /* reduced */); + final TaskSnapshot snapshotB = mLoader.loadTask(2, mTestUserId, false /* reduced */); + assertNotNull(snapshotA); + assertNotNull(snapshotB); + assertTrue(snapshotA.isRealSnapshot()); + assertFalse(snapshotB.isRealSnapshot()); + } + @Test public void testRemoveObsoleteFiles() { mPersister.persistSnapshot(1, mTestUserId, createSnapshot()); diff --git a/services/tests/servicestests/src/com/android/server/wm/TaskSnapshotPersisterTestBase.java b/services/tests/servicestests/src/com/android/server/wm/TaskSnapshotPersisterTestBase.java index b49a0fdf8f38c..2ad5bf4040521 100644 --- a/services/tests/servicestests/src/com/android/server/wm/TaskSnapshotPersisterTestBase.java +++ b/services/tests/servicestests/src/com/android/server/wm/TaskSnapshotPersisterTestBase.java @@ -84,12 +84,16 @@ class TaskSnapshotPersisterTestBase extends WindowTestsBase { } TaskSnapshot createSnapshot(float scale) { + return createSnapshot(scale, true /* isRealSnapshot */); + } + + TaskSnapshot createSnapshot(float scale, boolean isRealSnapshot) { 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, - scale < 1f /* reducedResolution */, scale); + scale < 1f /* reducedResolution */, scale, isRealSnapshot); } } diff --git a/services/tests/servicestests/src/com/android/server/wm/TaskSnapshotSurfaceTest.java b/services/tests/servicestests/src/com/android/server/wm/TaskSnapshotSurfaceTest.java index 4288eac0faa94..d5334babc1a6c 100644 --- a/services/tests/servicestests/src/com/android/server/wm/TaskSnapshotSurfaceTest.java +++ b/services/tests/servicestests/src/com/android/server/wm/TaskSnapshotSurfaceTest.java @@ -60,7 +60,7 @@ public class TaskSnapshotSurfaceTest extends WindowTestsBase { final GraphicBuffer buffer = GraphicBuffer.create(width, height, PixelFormat.RGBA_8888, GraphicBuffer.USAGE_SW_READ_NEVER | GraphicBuffer.USAGE_SW_WRITE_NEVER); final TaskSnapshot snapshot = new TaskSnapshot(buffer, - ORIENTATION_PORTRAIT, contentInsets, false, 1.0f); + ORIENTATION_PORTRAIT, contentInsets, false, 1.0f, true /* isRealSnapshot */); mSurface = new TaskSnapshotSurface(sWm, new Window(), new Surface(), snapshot, "Test", Color.WHITE, Color.RED, Color.BLUE, sysuiVis, windowFlags, 0, taskBounds, ORIENTATION_PORTRAIT);