Merge "Expose whether a snapshot is a real snapshot" into pi-dev

This commit is contained in:
Winson Chung
2018-03-12 20:34:07 +00:00
committed by Android (Google) Code Review
9 changed files with 50 additions and 8 deletions

View File

@@ -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<TaskSnapshot> CREATOR = new Creator<TaskSnapshot>() {

View File

@@ -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();
}
}

View File

@@ -27,4 +27,5 @@
int32 inset_top = 3;
int32 inset_right = 4;
int32 inset_bottom = 5;
bool is_real_snapshot = 6;
}

View File

@@ -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 */);
}
/**

View File

@@ -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;

View File

@@ -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);

View File

@@ -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());

View File

@@ -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);
}
}

View File

@@ -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);