Add windowing mode to task snapshot.
Bug: 78155683
Test: atest FrameworksServicesTests:TaskSnapshotPersisterLoaderTest
Change-Id: I4e562d818416a30d6759baef37c74b6d9c514a00
diff --git a/core/java/android/app/ActivityManager.java b/core/java/android/app/ActivityManager.java
index 289a4dd..539a010 100644
--- a/core/java/android/app/ActivityManager.java
+++ b/core/java/android/app/ActivityManager.java
@@ -2102,18 +2102,24 @@
private final GraphicBuffer mSnapshot;
private final int mOrientation;
private final Rect mContentInsets;
+ // Whether this snapshot is a down-sampled version of the full resolution, used mainly for
+ // low-ram devices
private final boolean mReducedResolution;
+ // 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
private final boolean mIsRealSnapshot;
+ private final int mWindowingMode;
private final float mScale;
public TaskSnapshot(GraphicBuffer snapshot, int orientation, Rect contentInsets,
- boolean reducedResolution, float scale, boolean isRealSnapshot) {
+ boolean reducedResolution, float scale, boolean isRealSnapshot, int windowingMode) {
mSnapshot = snapshot;
mOrientation = orientation;
mContentInsets = new Rect(contentInsets);
mReducedResolution = reducedResolution;
mScale = scale;
mIsRealSnapshot = isRealSnapshot;
+ mWindowingMode = windowingMode;
}
private TaskSnapshot(Parcel source) {
@@ -2123,6 +2129,7 @@
mReducedResolution = source.readBoolean();
mScale = source.readFloat();
mIsRealSnapshot = source.readBoolean();
+ mWindowingMode = source.readInt();
}
/**
@@ -2163,6 +2170,13 @@
}
/**
+ * @return The windowing mode of the task when this snapshot was taken.
+ */
+ public int getWindowingMode() {
+ return mWindowingMode;
+ }
+
+ /**
* @return The scale this snapshot was taken in.
*/
public float getScale() {
@@ -2182,14 +2196,18 @@
dest.writeBoolean(mReducedResolution);
dest.writeFloat(mScale);
dest.writeBoolean(mIsRealSnapshot);
+ dest.writeInt(mWindowingMode);
}
@Override
public String toString() {
- return "TaskSnapshot{mSnapshot=" + mSnapshot + " mOrientation=" + mOrientation
+ final int width = mSnapshot != null ? mSnapshot.getWidth() : 0;
+ final int height = mSnapshot != null ? mSnapshot.getHeight() : 0;
+ return "TaskSnapshot{mSnapshot=" + mSnapshot + " (" + width + "x" + height + ")"
+ + " mOrientation=" + mOrientation
+ " mContentInsets=" + mContentInsets.toShortString()
+ " mReducedResolution=" + mReducedResolution + " mScale=" + mScale
- + " mIsRealSnapshot=" + mIsRealSnapshot;
+ + " mIsRealSnapshot=" + mIsRealSnapshot + " mWindowingMode=" + mWindowingMode;
}
public static final Creator<TaskSnapshot> CREATOR = new Creator<TaskSnapshot>() {
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 924e85d..7429cb5 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
@@ -17,6 +17,7 @@
package com.android.systemui.shared.recents.model;
import static android.content.res.Configuration.ORIENTATION_UNDEFINED;
+import static com.android.systemui.shared.system.WindowManagerWrapper.WINDOWING_MODE_UNDEFINED;
import android.app.ActivityManager.TaskSnapshot;
import android.graphics.Bitmap;
@@ -32,6 +33,7 @@
public Rect insets;
public boolean reducedResolution;
public boolean isRealSnapshot;
+ public int windowingMode;
public float scale;
public ThumbnailData() {
@@ -41,6 +43,7 @@
reducedResolution = false;
scale = 1f;
isRealSnapshot = true;
+ windowingMode = WINDOWING_MODE_UNDEFINED;
}
public ThumbnailData(TaskSnapshot snapshot) {
@@ -50,5 +53,6 @@
reducedResolution = snapshot.isReducedResolution();
scale = snapshot.getScale();
isRealSnapshot = snapshot.isRealSnapshot();
+ windowingMode = snapshot.getWindowingMode();
}
}
diff --git a/packages/SystemUI/shared/src/com/android/systemui/shared/system/WindowManagerWrapper.java b/packages/SystemUI/shared/src/com/android/systemui/shared/system/WindowManagerWrapper.java
index 68e3b92..1082a74 100644
--- a/packages/SystemUI/shared/src/com/android/systemui/shared/system/WindowManagerWrapper.java
+++ b/packages/SystemUI/shared/src/com/android/systemui/shared/system/WindowManagerWrapper.java
@@ -60,6 +60,16 @@
public static final int ACTIVITY_TYPE_STANDARD = WindowConfiguration.ACTIVITY_TYPE_STANDARD;
+ public static final int WINDOWING_MODE_UNDEFINED = WindowConfiguration.WINDOWING_MODE_UNDEFINED;
+ public static final int WINDOWING_MODE_FULLSCREEN =
+ WindowConfiguration.WINDOWING_MODE_FULLSCREEN;
+ public static final int WINDOWING_MODE_PINNED = WindowConfiguration.WINDOWING_MODE_PINNED;
+ public static final int WINDOWING_MODE_SPLIT_SCREEN_PRIMARY =
+ WindowConfiguration.WINDOWING_MODE_SPLIT_SCREEN_PRIMARY;
+ public static final int WINDOWING_MODE_SPLIT_SCREEN_SECONDARY =
+ WindowConfiguration.WINDOWING_MODE_SPLIT_SCREEN_SECONDARY;
+ public static final int WINDOWING_MODE_FREEFORM = WindowConfiguration.WINDOWING_MODE_FREEFORM;
+
private static final WindowManagerWrapper sInstance = new WindowManagerWrapper();
public static WindowManagerWrapper getInstance() {
diff --git a/proto/src/task_snapshot.proto b/proto/src/task_snapshot.proto
index 490a59e..27febef 100644
--- a/proto/src/task_snapshot.proto
+++ b/proto/src/task_snapshot.proto
@@ -28,4 +28,5 @@
int32 inset_right = 4;
int32 inset_bottom = 5;
bool is_real_snapshot = 6;
+ int32 windowing_mode = 7;
}
\ 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 5f9d679..6b13edd 100644
--- a/services/core/java/com/android/server/wm/TaskSnapshotController.java
+++ b/services/core/java/com/android/server/wm/TaskSnapshotController.java
@@ -273,9 +273,8 @@
return null;
}
return new TaskSnapshot(buffer, top.getConfiguration().orientation,
- getInsets(mainWindow),
- isLowRamDevice /* reduced */, scaleFraction /* scale */,
- true /* isRealSnapshot */);
+ getInsets(mainWindow), isLowRamDevice /* reduced */, scaleFraction /* scale */,
+ true /* isRealSnapshot */, task.getWindowingMode());
}
private boolean shouldDisableSnapshots() {
@@ -365,7 +364,7 @@
return new TaskSnapshot(hwBitmap.createGraphicBufferHandle(),
topChild.getConfiguration().orientation, mainWindow.mStableInsets,
ActivityManager.isLowRamDeviceStatic() /* reduced */, 1.0f /* scale */,
- false /* isRealSnapshot */);
+ false /* isRealSnapshot */, task.getWindowingMode());
}
/**
diff --git a/services/core/java/com/android/server/wm/TaskSnapshotLoader.java b/services/core/java/com/android/server/wm/TaskSnapshotLoader.java
index 31da5f3..b682a32 100644
--- a/services/core/java/com/android/server/wm/TaskSnapshotLoader.java
+++ b/services/core/java/com/android/server/wm/TaskSnapshotLoader.java
@@ -90,7 +90,7 @@
return new TaskSnapshot(buffer, proto.orientation,
new Rect(proto.insetLeft, proto.insetTop, proto.insetRight, proto.insetBottom),
reducedResolution, reducedResolution ? REDUCED_SCALE : 1f,
- proto.isRealSnapshot);
+ proto.isRealSnapshot, proto.windowingMode);
} 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 086fffa..408fb3c 100644
--- a/services/core/java/com/android/server/wm/TaskSnapshotPersister.java
+++ b/services/core/java/com/android/server/wm/TaskSnapshotPersister.java
@@ -24,9 +24,7 @@
import android.app.ActivityManager;
import android.app.ActivityManager.TaskSnapshot;
import android.graphics.Bitmap;
-import android.graphics.Bitmap.CompressFormat;
import android.graphics.Bitmap.Config;
-import android.graphics.GraphicBuffer;
import android.os.Process;
import android.os.SystemClock;
import android.util.ArraySet;
@@ -41,7 +39,6 @@
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayDeque;
-import java.util.ArrayList;
/**
* Persists {@link TaskSnapshot}s to disk.
@@ -319,6 +316,7 @@
proto.insetRight = mSnapshot.getContentInsets().right;
proto.insetBottom = mSnapshot.getContentInsets().bottom;
proto.isRealSnapshot = mSnapshot.isRealSnapshot();
+ proto.windowingMode = mSnapshot.getWindowingMode();
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 80cbf2a..13478df 100644
--- a/services/tests/servicestests/src/com/android/server/wm/TaskSnapshotPersisterLoaderTest.java
+++ b/services/tests/servicestests/src/com/android/server/wm/TaskSnapshotPersisterLoaderTest.java
@@ -16,6 +16,8 @@
package com.android.server.wm;
+import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN;
+import static android.app.WindowConfiguration.WINDOWING_MODE_PINNED;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
@@ -164,8 +166,10 @@
@Test
public void testIsRealSnapshotPersistAndLoadSnapshot() {
- TaskSnapshot a = createSnapshot(1f /* scale */, true /* isRealSnapshot */);
- TaskSnapshot b = createSnapshot(1f /* scale */, false /* isRealSnapshot */);
+ TaskSnapshot a = createSnapshot(1f /* scale */, true /* isRealSnapshot */,
+ WINDOWING_MODE_FULLSCREEN);
+ TaskSnapshot b = createSnapshot(1f /* scale */, false /* isRealSnapshot */,
+ WINDOWING_MODE_FULLSCREEN);
assertTrue(a.isRealSnapshot());
assertFalse(b.isRealSnapshot());
mPersister.persistSnapshot(1, mTestUserId, a);
@@ -180,6 +184,25 @@
}
@Test
+ public void testWindowingModePersistAndLoadSnapshot() {
+ TaskSnapshot a = createSnapshot(1f /* scale */, true /* isRealSnapshot */,
+ WINDOWING_MODE_FULLSCREEN);
+ TaskSnapshot b = createSnapshot(1f /* scale */, true /* isRealSnapshot */,
+ WINDOWING_MODE_PINNED);
+ assertTrue(a.getWindowingMode() == WINDOWING_MODE_FULLSCREEN);
+ assertTrue(b.getWindowingMode() == WINDOWING_MODE_PINNED);
+ 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.getWindowingMode() == WINDOWING_MODE_FULLSCREEN);
+ assertTrue(snapshotB.getWindowingMode() == WINDOWING_MODE_PINNED);
+ }
+
+ @Test
public void testRemoveObsoleteFiles() {
mPersister.persistSnapshot(1, mTestUserId, createSnapshot());
mPersister.persistSnapshot(2, 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 2ad5bf4..6a4acbe 100644
--- a/services/tests/servicestests/src/com/android/server/wm/TaskSnapshotPersisterTestBase.java
+++ b/services/tests/servicestests/src/com/android/server/wm/TaskSnapshotPersisterTestBase.java
@@ -16,6 +16,7 @@
package com.android.server.wm;
+import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN;
import static android.content.res.Configuration.ORIENTATION_PORTRAIT;
import static android.graphics.GraphicBuffer.USAGE_HW_TEXTURE;
import static android.graphics.GraphicBuffer.USAGE_SW_READ_RARELY;
@@ -84,16 +85,16 @@
}
TaskSnapshot createSnapshot(float scale) {
- return createSnapshot(scale, true /* isRealSnapshot */);
+ return createSnapshot(scale, true /* isRealSnapshot */, WINDOWING_MODE_FULLSCREEN);
}
- TaskSnapshot createSnapshot(float scale, boolean isRealSnapshot) {
+ TaskSnapshot createSnapshot(float scale, boolean isRealSnapshot, int windowingMode) {
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, isRealSnapshot);
+ scale < 1f /* reducedResolution */, scale, isRealSnapshot, windowingMode);
}
}
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 d5334ba..54d02d4 100644
--- a/services/tests/servicestests/src/com/android/server/wm/TaskSnapshotSurfaceTest.java
+++ b/services/tests/servicestests/src/com/android/server/wm/TaskSnapshotSurfaceTest.java
@@ -16,6 +16,7 @@
package com.android.server.wm;
+import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN;
import static android.content.res.Configuration.ORIENTATION_PORTRAIT;
import static android.view.WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS;
import static org.junit.Assert.assertEquals;
@@ -60,7 +61,8 @@
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, true /* isRealSnapshot */);
+ ORIENTATION_PORTRAIT, contentInsets, false, 1.0f, true /* isRealSnapshot */,
+ WINDOWING_MODE_FULLSCREEN);
mSurface = new TaskSnapshotSurface(sWm, new Window(), new Surface(), snapshot, "Test",
Color.WHITE, Color.RED, Color.BLUE, sysuiVis, windowFlags, 0, taskBounds,
ORIENTATION_PORTRAIT);