diff options
| author | 2023-08-21 16:29:32 -0500 | |
|---|---|---|
| committer | 2023-09-12 17:43:14 +0000 | |
| commit | b5c6cc39d346e37f4d3aa49ddb289f90830502a5 (patch) | |
| tree | 8c5fc1c85f33cbe05ebe7b548660fc79eb2133c2 | |
| parent | 3cfa79c53cf9e10cecb93a62d25507bb45da08b0 (diff) | |
Use display transform in WindowInfosListenerForTest
This fixes some test issues when physical and logical display sizes differ.
Bug: 294251187
Bug: 296424695
Test: SurfaceControlViewHostTests after running `adb shell wm size 800x1920`
Change-Id: Id9553b7d965ecaa6adf9c5c7acffe2f57576c716
Merged-In: Id9553b7d965ecaa6adf9c5c7acffe2f57576c716
(cherry picked from commit f103479f921a1d9e2c8ddc022c22b692b4baff71)
| -rw-r--r-- | core/java/android/window/WindowInfosListenerForTest.java | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/core/java/android/window/WindowInfosListenerForTest.java b/core/java/android/window/WindowInfosListenerForTest.java index 25bf85cfaa58..ec792197a329 100644 --- a/core/java/android/window/WindowInfosListenerForTest.java +++ b/core/java/android/window/WindowInfosListenerForTest.java @@ -21,11 +21,13 @@ import android.annotation.NonNull; import android.annotation.RequiresPermission; import android.annotation.TestApi; 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; @@ -119,13 +121,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(); } @@ -140,11 +142,28 @@ 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.frameLeft, handle.frameTop, handle.frameRight, handle.frameBottom); + + // 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, bounds, handle.inputConfig)); } |