diff options
| author | 2023-08-21 16:29:32 -0500 | |
|---|---|---|
| committer | 2023-08-23 16:29:09 -0500 | |
| commit | a8179dbaafbfacd2c2a167a24b9f7a452ef481d2 (patch) | |
| tree | c46e6cd177bdcd5d60690ea8f6b206b2be101d64 | |
| parent | 6162ea96867142ee7ebffb6dd2655deded0c6f68 (diff) | |
Use display transform in WindowInfosListenerForTest
This fixes some test issues when physical and logical display sizes differ.
Bug: 296424695
Test: SurfaceControlViewHostTests after running `adb shell wm size 800x1920`
Change-Id: Id9553b7d965ecaa6adf9c5c7acffe2f57576c716
| -rw-r--r-- | core/java/android/window/WindowInfosListenerForTest.java | 28 |
1 files changed, 24 insertions, 4 deletions
diff --git a/core/java/android/window/WindowInfosListenerForTest.java b/core/java/android/window/WindowInfosListenerForTest.java index 6e9f04482313..35ce72620d09 100644 --- a/core/java/android/window/WindowInfosListenerForTest.java +++ b/core/java/android/window/WindowInfosListenerForTest.java @@ -22,11 +22,13 @@ import android.annotation.RequiresPermission; import android.annotation.TestApi; import android.graphics.Matrix; import android.graphics.Rect; +import android.graphics.RectF; import android.os.IBinder; import android.os.InputConfig; import android.util.ArrayMap; import android.util.Log; import android.util.Pair; +import android.util.SparseArray; import android.view.InputWindowHandle; import java.util.ArrayList; @@ -137,13 +139,13 @@ public class WindowInfosListenerForTest { "Exception thrown while waiting for listener to be called with " + "initial state"); } - consumer.accept(buildWindowInfos(windowHandles)); + consumer.accept(buildWindowInfos(windowHandles, displayInfos)); } }; mListeners.put(consumer, listener); Pair<InputWindowHandle[], WindowInfosListener.DisplayInfo[]> initialState = listener.register(); - consumer.accept(buildWindowInfos(initialState.first)); + consumer.accept(buildWindowInfos(initialState.first, initialState.second)); calledWithInitialState.countDown(); } @@ -158,11 +160,29 @@ public class WindowInfosListenerForTest { listener.unregister(); } - private static List<WindowInfo> buildWindowInfos(InputWindowHandle[] windowHandles) { + private static List<WindowInfo> buildWindowInfos( + InputWindowHandle[] windowHandles, WindowInfosListener.DisplayInfo[] displayInfos) { var windowInfos = new ArrayList<WindowInfo>(windowHandles.length); + + var displayInfoById = new SparseArray<WindowInfosListener.DisplayInfo>(displayInfos.length); + for (var displayInfo : displayInfos) { + displayInfoById.put(displayInfo.mDisplayId, displayInfo); + } + + var tmp = new RectF(); for (var handle : windowHandles) { + var bounds = new Rect(handle.frame); + + // Transform bounds from physical display coordinates to logical display coordinates. + var display = displayInfoById.get(handle.displayId); + if (display != null) { + tmp.set(bounds); + display.mTransform.mapRect(tmp); + tmp.round(bounds); + } + windowInfos.add(new WindowInfo(handle.getWindowToken(), handle.name, handle.displayId, - handle.frame, handle.inputConfig, handle.transform)); + bounds, handle.inputConfig, handle.transform)); } return windowInfos; } |