Merge "Add letterboxInsets to TaskSnapshot"
diff --git a/core/java/android/window/TaskSnapshot.java b/core/java/android/window/TaskSnapshot.java
index f1e5fb9..b7bb608 100644
--- a/core/java/android/window/TaskSnapshot.java
+++ b/core/java/android/window/TaskSnapshot.java
@@ -50,6 +50,7 @@
/** The size of the snapshot before scaling */
private final Point mTaskSize;
private final Rect mContentInsets;
+ private final Rect mLetterboxInsets;
// Whether this snapshot is a down-sampled version of the high resolution snapshot, used
// mainly for loading snapshots quickly from disk when user is flinging fast
private final boolean mIsLowResolution;
@@ -67,9 +68,10 @@
public TaskSnapshot(long id,
@NonNull ComponentName topActivityComponent, HardwareBuffer snapshot,
@NonNull ColorSpace colorSpace, int orientation, int rotation, Point taskSize,
- Rect contentInsets, boolean isLowResolution, boolean isRealSnapshot,
- int windowingMode, @WindowInsetsController.Appearance int appearance,
- boolean isTranslucent, boolean hasImeSurface) {
+ Rect contentInsets, Rect letterboxInsets, boolean isLowResolution,
+ boolean isRealSnapshot, int windowingMode,
+ @WindowInsetsController.Appearance int appearance, boolean isTranslucent,
+ boolean hasImeSurface) {
mId = id;
mTopActivityComponent = topActivityComponent;
mSnapshot = snapshot;
@@ -79,6 +81,7 @@
mRotation = rotation;
mTaskSize = new Point(taskSize);
mContentInsets = new Rect(contentInsets);
+ mLetterboxInsets = new Rect(letterboxInsets);
mIsLowResolution = isLowResolution;
mIsRealSnapshot = isRealSnapshot;
mWindowingMode = windowingMode;
@@ -99,6 +102,7 @@
mRotation = source.readInt();
mTaskSize = source.readTypedObject(Point.CREATOR);
mContentInsets = source.readTypedObject(Rect.CREATOR);
+ mLetterboxInsets = source.readTypedObject(Rect.CREATOR);
mIsLowResolution = source.readBoolean();
mIsRealSnapshot = source.readBoolean();
mWindowingMode = source.readInt();
@@ -179,6 +183,14 @@
}
/**
+ * @return The letterbox insets on the snapshot. These can be clipped off in order to
+ * remove any letterbox areas in the snapshot.
+ */
+ public Rect getLetterboxInsets() {
+ return mLetterboxInsets;
+ }
+
+ /**
* @return Whether this snapshot is a down-sampled version of the full resolution.
*/
@UnsupportedAppUsage
@@ -241,6 +253,7 @@
dest.writeInt(mRotation);
dest.writeTypedObject(mTaskSize, 0);
dest.writeTypedObject(mContentInsets, 0);
+ dest.writeTypedObject(mLetterboxInsets, 0);
dest.writeBoolean(mIsLowResolution);
dest.writeBoolean(mIsRealSnapshot);
dest.writeInt(mWindowingMode);
@@ -262,6 +275,7 @@
+ " mRotation=" + mRotation
+ " mTaskSize=" + mTaskSize.toString()
+ " mContentInsets=" + mContentInsets.toShortString()
+ + " mLetterboxInsets=" + mLetterboxInsets.toShortString()
+ " mIsLowResolution=" + mIsLowResolution
+ " mIsRealSnapshot=" + mIsRealSnapshot
+ " mWindowingMode=" + mWindowingMode
@@ -289,6 +303,7 @@
private int mRotation;
private Point mTaskSize;
private Rect mContentInsets;
+ private Rect mLetterboxInsets;
private boolean mIsRealSnapshot;
private int mWindowingMode;
private @WindowInsetsController.Appearance
@@ -340,6 +355,11 @@
return this;
}
+ public Builder setLetterboxInsets(Rect letterboxInsets) {
+ mLetterboxInsets = letterboxInsets;
+ return this;
+ }
+
public Builder setIsRealSnapshot(boolean realSnapshot) {
mIsRealSnapshot = realSnapshot;
return this;
@@ -387,6 +407,7 @@
mRotation,
mTaskSize,
mContentInsets,
+ mLetterboxInsets,
// When building a TaskSnapshot with the Builder class, isLowResolution
// is always false. Low-res snapshots are only created when loading from
// disk.
diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/startingsurface/StartingSurfaceDrawerTests.java b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/startingsurface/StartingSurfaceDrawerTests.java
index b866bf9..70b7c67 100644
--- a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/startingsurface/StartingSurfaceDrawerTests.java
+++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/startingsurface/StartingSurfaceDrawerTests.java
@@ -301,8 +301,8 @@
System.currentTimeMillis(),
new ComponentName("", ""), buffer,
ColorSpace.get(ColorSpace.Named.SRGB), ORIENTATION_PORTRAIT,
- Surface.ROTATION_0, taskSize, contentInsets, false,
- true /* isRealSnapshot */, WINDOWING_MODE_FULLSCREEN,
+ Surface.ROTATION_0, taskSize, contentInsets, new Rect() /* letterboxInsets */,
+ false, true /* isRealSnapshot */, WINDOWING_MODE_FULLSCREEN,
0 /* systemUiVisibility */, false /* isTranslucent */,
hasImeSurface /* hasImeSurface */);
}
diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/startingsurface/TaskSnapshotWindowTest.java b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/startingsurface/TaskSnapshotWindowTest.java
index aad9528..78e27c9 100644
--- a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/startingsurface/TaskSnapshotWindowTest.java
+++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/startingsurface/TaskSnapshotWindowTest.java
@@ -94,8 +94,8 @@
System.currentTimeMillis(),
new ComponentName("", ""), buffer,
ColorSpace.get(ColorSpace.Named.SRGB), ORIENTATION_PORTRAIT,
- Surface.ROTATION_0, taskSize, contentInsets, false,
- true /* isRealSnapshot */, WINDOWING_MODE_FULLSCREEN,
+ Surface.ROTATION_0, taskSize, contentInsets, new Rect() /* letterboxInsets */,
+ false, true /* isRealSnapshot */, WINDOWING_MODE_FULLSCREEN,
0 /* systemUiVisibility */, false /* isTranslucent */, false /* hasImeSurface */);
}
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 2f2876d..1142e05 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
@@ -42,6 +42,7 @@
public int orientation;
public int rotation;
public Rect insets;
+ public Rect letterboxInsets;
public boolean reducedResolution;
public boolean isRealSnapshot;
public boolean isTranslucent;
@@ -55,6 +56,7 @@
orientation = ORIENTATION_UNDEFINED;
rotation = ROTATION_UNDEFINED;
insets = new Rect();
+ letterboxInsets = new Rect();
reducedResolution = false;
scale = 1f;
isRealSnapshot = true;
@@ -97,6 +99,7 @@
public ThumbnailData(TaskSnapshot snapshot) {
thumbnail = makeThumbnail(snapshot);
insets = new Rect(snapshot.getContentInsets());
+ letterboxInsets = new Rect(snapshot.getLetterboxInsets());
orientation = snapshot.getOrientation();
rotation = snapshot.getRotation();
reducedResolution = snapshot.isLowResolution();
diff --git a/proto/src/task_snapshot.proto b/proto/src/task_snapshot.proto
index 4b0e4c2..1cbc17e 100644
--- a/proto/src/task_snapshot.proto
+++ b/proto/src/task_snapshot.proto
@@ -41,4 +41,8 @@
// The task height when the snapshot was taken
int32 task_height = 15;
int32 appearance = 16;
+ int32 letterbox_inset_left = 17;
+ int32 letterbox_inset_top = 18;
+ int32 letterbox_inset_right = 19;
+ int32 letterbox_inset_bottom = 20;
}
diff --git a/services/core/java/com/android/server/wm/TaskSnapshotController.java b/services/core/java/com/android/server/wm/TaskSnapshotController.java
index 81b7cbe..bf11ebc 100644
--- a/services/core/java/com/android/server/wm/TaskSnapshotController.java
+++ b/services/core/java/com/android/server/wm/TaskSnapshotController.java
@@ -298,11 +298,13 @@
final WindowState mainWindow = result.second;
final Rect contentInsets = getSystemBarInsets(task.getBounds(),
mainWindow.getInsetsStateWithVisibilityOverride());
- InsetUtils.addInsets(contentInsets, activity.getLetterboxInsets());
+ final Rect letterboxInsets = activity.getLetterboxInsets();
+ InsetUtils.addInsets(contentInsets, letterboxInsets);
builder.setIsRealSnapshot(true);
builder.setId(System.currentTimeMillis());
builder.setContentInsets(contentInsets);
+ builder.setLetterboxInsets(letterboxInsets);
final boolean isWindowTranslucent = mainWindow.getAttrs().format != PixelFormat.OPAQUE;
final boolean isShowWallpaper = mainWindow.hasWallpaper();
@@ -581,7 +583,8 @@
return null;
}
final Rect contentInsets = new Rect(systemBarInsets);
- InsetUtils.addInsets(contentInsets, topChild.getLetterboxInsets());
+ final Rect letterboxInsets = topChild.getLetterboxInsets();
+ InsetUtils.addInsets(contentInsets, letterboxInsets);
// Note, the app theme snapshot is never translucent because we enforce a non-translucent
// color above
@@ -590,9 +593,9 @@
topChild.mActivityComponent, hwBitmap.getHardwareBuffer(),
hwBitmap.getColorSpace(), mainWindow.getConfiguration().orientation,
mainWindow.getWindowConfiguration().getRotation(), new Point(taskWidth, taskHeight),
- contentInsets, false /* isLowResolution */, false /* isRealSnapshot */,
- task.getWindowingMode(), getAppearance(task), false /* isTranslucent */,
- false /* hasImeSurface */);
+ contentInsets, letterboxInsets, false /* isLowResolution */,
+ false /* isRealSnapshot */, task.getWindowingMode(),
+ getAppearance(task), false /* isTranslucent */, false /* hasImeSurface */);
}
/**
diff --git a/services/core/java/com/android/server/wm/TaskSnapshotLoader.java b/services/core/java/com/android/server/wm/TaskSnapshotLoader.java
index d3bfbab..9189e51 100644
--- a/services/core/java/com/android/server/wm/TaskSnapshotLoader.java
+++ b/services/core/java/com/android/server/wm/TaskSnapshotLoader.java
@@ -20,7 +20,6 @@
import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
import android.app.ActivityManager;
-import android.window.TaskSnapshot;
import android.content.ComponentName;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
@@ -30,6 +29,7 @@
import android.graphics.Rect;
import android.hardware.HardwareBuffer;
import android.util.Slog;
+import android.window.TaskSnapshot;
import com.android.server.wm.nano.WindowManagerProtos.TaskSnapshotProto;
@@ -196,6 +196,8 @@
return new TaskSnapshot(proto.id, topActivityComponent, buffer,
hwBitmap.getColorSpace(), proto.orientation, proto.rotation, taskSize,
new Rect(proto.insetLeft, proto.insetTop, proto.insetRight, proto.insetBottom),
+ new Rect(proto.letterboxInsetLeft, proto.letterboxInsetTop,
+ proto.letterboxInsetRight, proto.letterboxInsetBottom),
loadLowResolutionBitmap, proto.isRealSnapshot, proto.windowingMode,
proto.appearance, proto.isTranslucent, false /* hasImeSurface */);
} catch (IOException e) {
diff --git a/services/core/java/com/android/server/wm/TaskSnapshotPersister.java b/services/core/java/com/android/server/wm/TaskSnapshotPersister.java
index 60c4766..9fbcd7c 100644
--- a/services/core/java/com/android/server/wm/TaskSnapshotPersister.java
+++ b/services/core/java/com/android/server/wm/TaskSnapshotPersister.java
@@ -23,7 +23,6 @@
import android.annotation.NonNull;
import android.annotation.TestApi;
-import android.window.TaskSnapshot;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.os.Process;
@@ -31,6 +30,7 @@
import android.util.ArraySet;
import android.util.AtomicFile;
import android.util.Slog;
+import android.window.TaskSnapshot;
import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.VisibleForTesting;
@@ -380,6 +380,10 @@
proto.insetTop = mSnapshot.getContentInsets().top;
proto.insetRight = mSnapshot.getContentInsets().right;
proto.insetBottom = mSnapshot.getContentInsets().bottom;
+ proto.letterboxInsetLeft = mSnapshot.getLetterboxInsets().left;
+ proto.letterboxInsetTop = mSnapshot.getLetterboxInsets().top;
+ proto.letterboxInsetRight = mSnapshot.getLetterboxInsets().right;
+ proto.letterboxInsetBottom = mSnapshot.getLetterboxInsets().bottom;
proto.isRealSnapshot = mSnapshot.isRealSnapshot();
proto.windowingMode = mSnapshot.getWindowingMode();
proto.appearance = mSnapshot.getAppearance();
diff --git a/services/tests/wmtests/src/com/android/server/wm/RecentTasksTest.java b/services/tests/wmtests/src/com/android/server/wm/RecentTasksTest.java
index 22e687a..2847283 100644
--- a/services/tests/wmtests/src/com/android/server/wm/RecentTasksTest.java
+++ b/services/tests/wmtests/src/com/android/server/wm/RecentTasksTest.java
@@ -1244,7 +1244,8 @@
}
return new TaskSnapshot(1, new ComponentName("", ""), buffer,
ColorSpace.get(ColorSpace.Named.SRGB), ORIENTATION_PORTRAIT,
- Surface.ROTATION_0, taskSize, new Rect() /* insets */, false /* isLowResolution */,
+ Surface.ROTATION_0, taskSize, new Rect() /* contentInsets */,
+ new Rect() /* letterboxInsets*/, false /* isLowResolution */,
true /* isRealSnapshot */, WINDOWING_MODE_FULLSCREEN, 0 /* mSystemUiVisibility */,
false /* isTranslucent */, false /* hasImeSurface */);
}
diff --git a/services/tests/wmtests/src/com/android/server/wm/TaskSnapshotControllerTest.java b/services/tests/wmtests/src/com/android/server/wm/TaskSnapshotControllerTest.java
index 97afc16..f573b70 100644
--- a/services/tests/wmtests/src/com/android/server/wm/TaskSnapshotControllerTest.java
+++ b/services/tests/wmtests/src/com/android/server/wm/TaskSnapshotControllerTest.java
@@ -144,7 +144,8 @@
final int orientation = Configuration.ORIENTATION_PORTRAIT;
final float scaleFraction = 0.25f;
final Rect contentInsets = new Rect(1, 2, 3, 4);
- final Point taskSize = new Point(5, 6);
+ final Rect letterboxInsets = new Rect(5, 6, 7, 8);
+ final Point taskSize = new Point(9, 10);
try {
TaskSnapshot.Builder builder =
@@ -156,6 +157,7 @@
builder.setColorSpace(sRGB);
builder.setOrientation(orientation);
builder.setContentInsets(contentInsets);
+ builder.setLetterboxInsets(letterboxInsets);
builder.setIsTranslucent(true);
builder.setSnapshot(buffer);
builder.setIsRealSnapshot(true);
@@ -176,6 +178,7 @@
assertFalse(snapshot.isLowResolution());
assertEquals(orientation, snapshot.getOrientation());
assertEquals(contentInsets, snapshot.getContentInsets());
+ assertEquals(letterboxInsets, snapshot.getLetterboxInsets());
assertTrue(snapshot.isTranslucent());
assertSame(buffer, snapshot.getHardwareBuffer());
assertTrue(snapshot.isRealSnapshot());
diff --git a/services/tests/wmtests/src/com/android/server/wm/TaskSnapshotPersisterTestBase.java b/services/tests/wmtests/src/com/android/server/wm/TaskSnapshotPersisterTestBase.java
index d09ba29..437d418 100644
--- a/services/tests/wmtests/src/com/android/server/wm/TaskSnapshotPersisterTestBase.java
+++ b/services/tests/wmtests/src/com/android/server/wm/TaskSnapshotPersisterTestBase.java
@@ -59,7 +59,8 @@
*/
class TaskSnapshotPersisterTestBase extends WindowTestsBase {
- private static final Rect TEST_INSETS = new Rect(10, 20, 30, 40);
+ private static final Rect TEST_CONTENT_INSETS = new Rect(10, 20, 30, 40);
+ private static final Rect TEST_LETTERBOX_INSETS = new Rect();
static final File FILES_DIR = getInstrumentation().getTargetContext().getFilesDir();
static final long MOCK_SNAPSHOT_ID = 12345678;
@@ -208,7 +209,7 @@
return new TaskSnapshot(MOCK_SNAPSHOT_ID, mTopActivityComponent,
HardwareBuffer.createFromGraphicBuffer(buffer),
ColorSpace.get(ColorSpace.Named.SRGB), ORIENTATION_PORTRAIT,
- mRotation, taskSize, TEST_INSETS,
+ mRotation, taskSize, TEST_CONTENT_INSETS, TEST_LETTERBOX_INSETS,
// When building a TaskSnapshot with the Builder class, isLowResolution
// is always false. Low-res snapshots are only created when loading from
// disk.