WM: Mock or stub SurfaceControl and Surface calls in wm unit tests
WM unit tests create a test instance of the WMS service and run assertions
on them. This change limits calls to native code via SurfaceControl#Transaction
and Surface classes on the test instance in order to provide a more hermetic
environment to run the tests on.
- Create a Surface factory class and override SurfaceControl#Transaction,
SurfaceControl and Surface factory classes in the test service during test
setup.
- Modify WallpaperControllerTests to not call native code and assert
WallpaperController state as opposed to native call results.
- Cleanup use of mSkipOnParentChanged for TestAppWindowToken
Test: atest WmTests
Bug: 124357362
Change-Id: I25a16d0eca70be3b3ae93ed5bbff101007196105
diff --git a/services/core/java/com/android/server/wm/ScreenRotationAnimation.java b/services/core/java/com/android/server/wm/ScreenRotationAnimation.java
index 84cd8d1..2d5c97f 100644
--- a/services/core/java/com/android/server/wm/ScreenRotationAnimation.java
+++ b/services/core/java/com/android/server/wm/ScreenRotationAnimation.java
@@ -257,7 +257,7 @@
mOriginalWidth = originalWidth;
mOriginalHeight = originalHeight;
- final SurfaceControl.Transaction t = new SurfaceControl.Transaction();
+ final SurfaceControl.Transaction t = mService.mTransactionFactory.make();
try {
mSurfaceControl = displayContent.makeOverlay()
.setName("ScreenshotSurface")
@@ -267,13 +267,13 @@
// In case display bounds change, screenshot buffer and surface may mismatch so set a
// scaling mode.
- SurfaceControl.Transaction t2 = new SurfaceControl.Transaction();
+ SurfaceControl.Transaction t2 = mService.mTransactionFactory.make();
t2.setOverrideScalingMode(mSurfaceControl, Surface.SCALING_MODE_SCALE_TO_WINDOW);
t2.apply(true /* sync */);
// Capture a screenshot into the surface we just created.
final int displayId = display.getDisplayId();
- final Surface surface = new Surface();
+ final Surface surface = mService.mSurfaceFactory.make();
surface.copyFrom(mSurfaceControl);
if (mService.mDisplayManagerInternal.screenshot(displayId, surface)) {
t.setLayer(mSurfaceControl, SCREEN_FREEZE_LAYER_SCREENSHOT);