Merge "Do not use obsoleted snapshot as staring window" into sc-dev

This commit is contained in:
Chilun Huang
2021-03-19 02:07:48 +00:00
committed by Android (Google) Code Review
4 changed files with 40 additions and 2 deletions

View File

@@ -150,6 +150,13 @@ public class StartingWindowController {
}
return false;
}
if (!snapshot.getTopActivityComponent().equals(windowInfo.taskInfo.topActivity)) {
if (DEBUG_SPLASH_SCREEN || DEBUG_TASK_SNAPSHOT) {
Slog.d(TAG, "isSnapshotCompatible obsoleted snapshot "
+ windowInfo.taskInfo.topActivity);
}
return false;
}
final int taskRotation = windowInfo.taskInfo.configuration
.windowConfiguration.getRotation();

View File

@@ -2114,6 +2114,10 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
if (snapshot == null) {
return false;
}
if (!snapshot.getTopActivityComponent().equals(mActivityComponent)) {
// Obsoleted snapshot.
return false;
}
final int rotation = mDisplayContent.rotationForActivityInDifferentOrientation(this);
final int targetRotation = rotation != ROTATION_UNDEFINED
// The display may rotate according to the orientation of this activity.

View File

@@ -1687,6 +1687,7 @@ public class ActivityRecordTests extends WindowTestsBase {
public void testIsSnapshotCompatible() {
final ActivityRecord activity = createActivityWithTask();
final TaskSnapshot snapshot = new TaskSnapshotPersisterTestBase.TaskSnapshotBuilder()
.setTopActivityComponent(activity.mActivityComponent)
.setRotation(activity.getWindowConfiguration().getRotation())
.build();
@@ -1697,6 +1698,26 @@ public class ActivityRecordTests extends WindowTestsBase {
assertFalse(activity.isSnapshotCompatible(snapshot));
}
/**
* Test that the snapshot should be obsoleted if the top activity changed.
*/
@Test
public void testIsSnapshotCompatibleTopActivityChanged() {
final ActivityRecord activity = createActivityWithTask();
final ActivityRecord secondActivity = new ActivityBuilder(mAtm)
.setTask(activity.getTask())
.setOnTop(true)
.build();
final TaskSnapshot snapshot = new TaskSnapshotPersisterTestBase.TaskSnapshotBuilder()
.setTopActivityComponent(secondActivity.mActivityComponent)
.build();
assertTrue(secondActivity.isSnapshotCompatible(snapshot));
// Emulate the top activity changed.
assertFalse(activity.isSnapshotCompatible(snapshot));
}
@Test
public void testFixedRotationSnapshotStartingWindow() {
final ActivityRecord activity = createActivityWithTask();

View File

@@ -28,7 +28,6 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
import android.window.TaskSnapshot;
import android.content.ComponentName;
import android.content.ContextWrapper;
import android.content.res.Resources;
@@ -42,6 +41,7 @@ import android.graphics.Rect;
import android.hardware.HardwareBuffer;
import android.os.UserManager;
import android.view.Surface;
import android.window.TaskSnapshot;
import com.android.server.LocalServices;
import com.android.server.pm.UserManagerInternal;
@@ -154,10 +154,16 @@ class TaskSnapshotPersisterTestBase extends WindowTestsBase {
private int mWindowingMode = WINDOWING_MODE_FULLSCREEN;
private int mSystemUiVisibility = 0;
private int mRotation = Surface.ROTATION_0;
private ComponentName mTopActivityComponent = new ComponentName("", "");
TaskSnapshotBuilder() {
}
TaskSnapshotBuilder setTopActivityComponent(ComponentName topActivityComponent) {
mTopActivityComponent = topActivityComponent;
return this;
}
TaskSnapshotBuilder setScaleFraction(float scale) {
mScaleFraction = scale;
return this;
@@ -199,7 +205,7 @@ class TaskSnapshotPersisterTestBase extends WindowTestsBase {
Canvas c = buffer.lockCanvas();
c.drawColor(Color.RED);
buffer.unlockCanvasAndPost(c);
return new TaskSnapshot(MOCK_SNAPSHOT_ID, new ComponentName("", ""),
return new TaskSnapshot(MOCK_SNAPSHOT_ID, mTopActivityComponent,
HardwareBuffer.createFromGraphicBuffer(buffer),
ColorSpace.get(ColorSpace.Named.SRGB), ORIENTATION_PORTRAIT,
mRotation, taskSize, TEST_INSETS,