Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ab6e84bc authored by Patrick Williams's avatar Patrick Williams Committed by Android (Google) Code Review
Browse files

Merge "Use display transform in WindowInfosListenerForTest" into main

parents 71dc75d9 a8179dba
Loading
Loading
Loading
Loading
+24 −4
Original line number Diff line number Diff line
@@ -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;
    }