Add rotation field to ThumbnailData for task snapshots
Add the rotation a task was in when its snapshot is taken. This is used by launcher to know which way to orient the bitmap when performing quickswitch fixes: 143892437 Test: Test: With launcher in portrait * Thumbnail in reverse portrait, landscape, seascape, normal With launcher in landscape * Thumbnail in seascape, normal, reverse portrait, landscape With launcher in seascape * Thumbnail in seascape, normal, reverse portrait, landscape Change-Id: Iaf32341d0db1fc023c29676e0d365eee03b98959
This commit is contained in:
@@ -73,6 +73,7 @@ import android.util.DisplayMetrics;
|
||||
import android.util.Singleton;
|
||||
import android.util.Size;
|
||||
import android.view.IWindowContainer;
|
||||
import android.view.Surface;
|
||||
|
||||
import com.android.internal.app.LocalePicker;
|
||||
import com.android.internal.app.procstats.ProcessStats;
|
||||
@@ -1928,7 +1929,12 @@ public class ActivityManager {
|
||||
// Top activity in task when snapshot was taken
|
||||
private final ComponentName mTopActivityComponent;
|
||||
private final GraphicBuffer mSnapshot;
|
||||
/** Indicates whether task was in landscape or portrait */
|
||||
@Configuration.Orientation
|
||||
private final int mOrientation;
|
||||
/** See {@link android.view.Surface.Rotation} */
|
||||
@Surface.Rotation
|
||||
private int mRotation;
|
||||
private final Rect mContentInsets;
|
||||
// Whether this snapshot is a down-sampled version of the full resolution, used mainly for
|
||||
// low-ram devices
|
||||
@@ -1945,7 +1951,7 @@ public class ActivityManager {
|
||||
|
||||
public TaskSnapshot(long id,
|
||||
@NonNull ComponentName topActivityComponent, GraphicBuffer snapshot,
|
||||
@NonNull ColorSpace colorSpace, int orientation, Rect contentInsets,
|
||||
@NonNull ColorSpace colorSpace, int orientation, int rotation, Rect contentInsets,
|
||||
boolean reducedResolution, float scale, boolean isRealSnapshot, int windowingMode,
|
||||
int systemUiVisibility, boolean isTranslucent) {
|
||||
mId = id;
|
||||
@@ -1954,6 +1960,7 @@ public class ActivityManager {
|
||||
mColorSpace = colorSpace.getId() < 0
|
||||
? ColorSpace.get(ColorSpace.Named.SRGB) : colorSpace;
|
||||
mOrientation = orientation;
|
||||
mRotation = rotation;
|
||||
mContentInsets = new Rect(contentInsets);
|
||||
mReducedResolution = reducedResolution;
|
||||
mScale = scale;
|
||||
@@ -1972,6 +1979,7 @@ public class ActivityManager {
|
||||
? ColorSpace.get(ColorSpace.Named.values()[colorSpaceId])
|
||||
: ColorSpace.get(ColorSpace.Named.SRGB);
|
||||
mOrientation = source.readInt();
|
||||
mRotation = source.readInt();
|
||||
mContentInsets = source.readParcelable(null /* classLoader */);
|
||||
mReducedResolution = source.readBoolean();
|
||||
mScale = source.readFloat();
|
||||
@@ -2018,6 +2026,13 @@ public class ActivityManager {
|
||||
return mOrientation;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The screen rotation the screenshot was taken in.
|
||||
*/
|
||||
public int getRotation() {
|
||||
return mRotation;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The system/content insets on the snapshot. These can be clipped off in order to
|
||||
* remove any areas behind system bars in the snapshot.
|
||||
@@ -2087,6 +2102,7 @@ public class ActivityManager {
|
||||
dest.writeParcelable(mSnapshot, 0);
|
||||
dest.writeInt(mColorSpace.getId());
|
||||
dest.writeInt(mOrientation);
|
||||
dest.writeInt(mRotation);
|
||||
dest.writeParcelable(mContentInsets, 0);
|
||||
dest.writeBoolean(mReducedResolution);
|
||||
dest.writeFloat(mScale);
|
||||
@@ -2106,6 +2122,7 @@ public class ActivityManager {
|
||||
+ " mSnapshot=" + mSnapshot + " (" + width + "x" + height + ")"
|
||||
+ " mColorSpace=" + mColorSpace.toString()
|
||||
+ " mOrientation=" + mOrientation
|
||||
+ " mRotation=" + mRotation
|
||||
+ " mContentInsets=" + mContentInsets.toShortString()
|
||||
+ " mReducedResolution=" + mReducedResolution + " mScale=" + mScale
|
||||
+ " mIsRealSnapshot=" + mIsRealSnapshot + " mWindowingMode=" + mWindowingMode
|
||||
@@ -2129,6 +2146,7 @@ public class ActivityManager {
|
||||
private GraphicBuffer mSnapshot;
|
||||
private ColorSpace mColorSpace;
|
||||
private int mOrientation;
|
||||
private int mRotation;
|
||||
private Rect mContentInsets;
|
||||
private boolean mReducedResolution;
|
||||
private float mScaleFraction;
|
||||
@@ -2163,6 +2181,11 @@ public class ActivityManager {
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setRotation(int rotation) {
|
||||
mRotation = rotation;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setContentInsets(Rect contentInsets) {
|
||||
mContentInsets = contentInsets;
|
||||
return this;
|
||||
@@ -2218,6 +2241,7 @@ public class ActivityManager {
|
||||
mSnapshot,
|
||||
mColorSpace,
|
||||
mOrientation,
|
||||
mRotation,
|
||||
mContentInsets,
|
||||
mReducedResolution,
|
||||
mScaleFraction,
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package com.android.systemui.shared.recents.model;
|
||||
|
||||
import static android.app.WindowConfiguration.ROTATION_UNDEFINED;
|
||||
import static android.content.res.Configuration.ORIENTATION_UNDEFINED;
|
||||
|
||||
import static com.android.systemui.shared.system.WindowManagerWrapper.WINDOWING_MODE_UNDEFINED;
|
||||
@@ -31,6 +32,7 @@ public class ThumbnailData {
|
||||
|
||||
public final Bitmap thumbnail;
|
||||
public int orientation;
|
||||
public int rotation;
|
||||
public Rect insets;
|
||||
public boolean reducedResolution;
|
||||
public boolean isRealSnapshot;
|
||||
@@ -43,6 +45,7 @@ public class ThumbnailData {
|
||||
public ThumbnailData() {
|
||||
thumbnail = null;
|
||||
orientation = ORIENTATION_UNDEFINED;
|
||||
rotation = ROTATION_UNDEFINED;
|
||||
insets = new Rect();
|
||||
reducedResolution = false;
|
||||
scale = 1f;
|
||||
@@ -57,6 +60,7 @@ public class ThumbnailData {
|
||||
thumbnail = Bitmap.wrapHardwareBuffer(snapshot.getSnapshot(), snapshot.getColorSpace());
|
||||
insets = new Rect(snapshot.getContentInsets());
|
||||
orientation = snapshot.getOrientation();
|
||||
rotation = snapshot.getRotation();
|
||||
reducedResolution = snapshot.isReducedResolution();
|
||||
scale = snapshot.getScale();
|
||||
isRealSnapshot = snapshot.isRealSnapshot();
|
||||
|
||||
@@ -34,4 +34,5 @@
|
||||
string top_activity_component = 10;
|
||||
float scale = 11;
|
||||
int64 id = 12;
|
||||
int32 rotation = 13;
|
||||
}
|
||||
|
||||
@@ -343,6 +343,7 @@ class TaskSnapshotController {
|
||||
builder.setPixelFormat(pixelFormat);
|
||||
builder.setIsTranslucent(isTranslucent);
|
||||
builder.setOrientation(activity.getTask().getConfiguration().orientation);
|
||||
builder.setRotation(activity.getTask().getDisplayContent().getRotation());
|
||||
builder.setWindowingMode(task.getWindowingMode());
|
||||
builder.setSystemUiVisibility(getSystemUiVisibility(task));
|
||||
return true;
|
||||
@@ -492,7 +493,8 @@ class TaskSnapshotController {
|
||||
return new TaskSnapshot(
|
||||
System.currentTimeMillis() /* id */,
|
||||
topChild.mActivityComponent, hwBitmap.createGraphicBufferHandle(),
|
||||
hwBitmap.getColorSpace(), topChild.getTask().getConfiguration().orientation,
|
||||
hwBitmap.getColorSpace(), mainWindow.getConfiguration().orientation,
|
||||
mainWindow.getWindowConfiguration().getRotation(),
|
||||
getInsets(mainWindow), ActivityManager.isLowRamDeviceStatic() /* reduced */,
|
||||
mFullSnapshotScale, false /* isRealSnapshot */, task.getWindowingMode(),
|
||||
getSystemUiVisibility(task), false);
|
||||
|
||||
@@ -102,8 +102,8 @@ class TaskSnapshotLoader {
|
||||
// For legacy snapshots, restore the scale based on the reduced resolution state
|
||||
final float legacyScale = reducedResolution ? mPersister.getReducedScale() : 1f;
|
||||
final float scale = Float.compare(proto.scale, 0f) != 0 ? proto.scale : legacyScale;
|
||||
return new TaskSnapshot(proto.id, topActivityComponent, buffer,
|
||||
hwBitmap.getColorSpace(), proto.orientation,
|
||||
return new TaskSnapshot(proto.id, topActivityComponent, buffer, hwBitmap.getColorSpace(),
|
||||
proto.orientation, proto.rotation,
|
||||
new Rect(proto.insetLeft, proto.insetTop, proto.insetRight, proto.insetBottom),
|
||||
reducedResolution, scale, proto.isRealSnapshot, proto.windowingMode,
|
||||
proto.systemUiVisibility, proto.isTranslucent);
|
||||
|
||||
@@ -338,6 +338,7 @@ class TaskSnapshotPersister {
|
||||
boolean writeProto() {
|
||||
final TaskSnapshotProto proto = new TaskSnapshotProto();
|
||||
proto.orientation = mSnapshot.getOrientation();
|
||||
proto.rotation = mSnapshot.getRotation();
|
||||
proto.insetLeft = mSnapshot.getContentInsets().left;
|
||||
proto.insetTop = mSnapshot.getContentInsets().top;
|
||||
proto.insetRight = mSnapshot.getContentInsets().right;
|
||||
|
||||
@@ -31,6 +31,7 @@ import android.graphics.Rect;
|
||||
import android.os.SystemClock;
|
||||
import android.platform.test.annotations.Presubmit;
|
||||
import android.util.ArraySet;
|
||||
import android.view.Surface;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.test.filters.MediumTest;
|
||||
@@ -47,7 +48,7 @@ import java.util.function.Predicate;
|
||||
* Test class for {@link TaskSnapshotPersister} and {@link TaskSnapshotLoader}
|
||||
*
|
||||
* Build/Install/Run:
|
||||
* atest WmTests:TaskSnapshotPersisterLoaderTest
|
||||
* atest TaskSnapshotPersisterLoaderTest
|
||||
*/
|
||||
@MediumTest
|
||||
@Presubmit
|
||||
@@ -316,4 +317,18 @@ public class TaskSnapshotPersisterLoaderTest extends TaskSnapshotPersisterTestBa
|
||||
new File(FILES_DIR.getPath() + "/snapshots/2_reduced.jpg")};
|
||||
assertTrueForFiles(existsFiles, File::exists, " must exist");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRotationPersistAndLoadSnapshot() {
|
||||
TaskSnapshot a = new TaskSnapshotBuilder()
|
||||
.setRotation(Surface.ROTATION_270)
|
||||
.build();
|
||||
mPersister.persistSnapshot(1 , mTestUserId, createSnapshot());
|
||||
mPersister.persistSnapshot(2 , mTestUserId, a);
|
||||
mPersister.waitForQueueEmpty();
|
||||
final TaskSnapshot snapshotA = mLoader.loadTask(1, mTestUserId, false /* reduced */);
|
||||
final TaskSnapshot snapshotB = mLoader.loadTask(2, mTestUserId, false /* reduced */);
|
||||
assertEquals(Surface.ROTATION_0, snapshotA.getRotation());
|
||||
assertEquals(Surface.ROTATION_270, snapshotB.getRotation());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,6 +32,7 @@ import android.graphics.GraphicBuffer;
|
||||
import android.graphics.PixelFormat;
|
||||
import android.graphics.Rect;
|
||||
import android.os.UserManager;
|
||||
import android.view.Surface;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
@@ -93,6 +94,7 @@ class TaskSnapshotPersisterTestBase extends WindowTestsBase {
|
||||
private boolean mIsTranslucent = false;
|
||||
private int mWindowingMode = WINDOWING_MODE_FULLSCREEN;
|
||||
private int mSystemUiVisibility = 0;
|
||||
private int mRotation = Surface.ROTATION_0;
|
||||
|
||||
TaskSnapshotBuilder setScale(float scale) {
|
||||
mScale = scale;
|
||||
@@ -124,6 +126,11 @@ class TaskSnapshotPersisterTestBase extends WindowTestsBase {
|
||||
return this;
|
||||
}
|
||||
|
||||
TaskSnapshotBuilder setRotation(int rotation) {
|
||||
mRotation = rotation;
|
||||
return this;
|
||||
}
|
||||
|
||||
TaskSnapshot build() {
|
||||
final GraphicBuffer buffer = GraphicBuffer.create(100, 100, PixelFormat.RGBA_8888,
|
||||
USAGE_HW_TEXTURE | USAGE_SW_READ_RARELY | USAGE_SW_READ_RARELY);
|
||||
@@ -131,7 +138,8 @@ class TaskSnapshotPersisterTestBase extends WindowTestsBase {
|
||||
c.drawColor(Color.RED);
|
||||
buffer.unlockCanvasAndPost(c);
|
||||
return new TaskSnapshot(MOCK_SNAPSHOT_ID, new ComponentName("", ""), buffer,
|
||||
ColorSpace.get(ColorSpace.Named.SRGB), ORIENTATION_PORTRAIT, TEST_INSETS,
|
||||
ColorSpace.get(ColorSpace.Named.SRGB), ORIENTATION_PORTRAIT,
|
||||
mRotation, TEST_INSETS,
|
||||
mReducedResolution, mScale, mIsRealSnapshot,
|
||||
mWindowingMode, mSystemUiVisibility, mIsTranslucent);
|
||||
}
|
||||
|
||||
@@ -40,6 +40,7 @@ import android.graphics.GraphicBuffer;
|
||||
import android.graphics.PixelFormat;
|
||||
import android.graphics.Rect;
|
||||
import android.platform.test.annotations.Presubmit;
|
||||
import android.view.Surface;
|
||||
import android.view.SurfaceControl;
|
||||
|
||||
import androidx.test.filters.SmallTest;
|
||||
@@ -69,7 +70,8 @@ public class TaskSnapshotSurfaceTest extends WindowTestsBase {
|
||||
final TaskSnapshot snapshot = new TaskSnapshot(
|
||||
System.currentTimeMillis(),
|
||||
new ComponentName("", ""), buffer,
|
||||
ColorSpace.get(ColorSpace.Named.SRGB), ORIENTATION_PORTRAIT, contentInsets, false,
|
||||
ColorSpace.get(ColorSpace.Named.SRGB), ORIENTATION_PORTRAIT,
|
||||
Surface.ROTATION_0, contentInsets, false,
|
||||
1.0f, true /* isRealSnapshot */, WINDOWING_MODE_FULLSCREEN,
|
||||
0 /* systemUiVisibility */, false /* isTranslucent */);
|
||||
mSurface = new TaskSnapshotSurface(mWm, new Window(), new SurfaceControl(), snapshot, "Test",
|
||||
|
||||
Reference in New Issue
Block a user