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

Commit 89d5ce6e authored by Patrick Williams's avatar Patrick Williams
Browse files

Add back old WindowInfosListenerForTest test api

24Q3-release and 24Q4-release are both run against 24Q3-ts-dev. This means 24Q3-ts-dev must use the API available in 24Q3-release. This CL fixes failures that occur when 24Q3-ts-dev is run against 24Q4-release.

Bug: 360785196
Flag: TEST_ONLY
Test: ran SurfaceControlViewHostTests with temporary revert back to old WindowInfosListenerForTest interface
Change-Id: Ibaacaa7c9f0f231d4ebeeb0335be5b5447a4bd83
parent e3e4506e
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -4426,7 +4426,9 @@ package android.window {

  public class WindowInfosListenerForTest {
    ctor public WindowInfosListenerForTest();
    method @Deprecated @RequiresPermission(android.Manifest.permission.ACCESS_SURFACE_FLINGER) public void addWindowInfosListener(@NonNull java.util.function.Consumer<java.util.List<android.window.WindowInfosListenerForTest.WindowInfo>>);
    method @RequiresPermission(android.Manifest.permission.ACCESS_SURFACE_FLINGER) public void addWindowInfosListener(@NonNull java.util.function.BiConsumer<java.util.List<android.window.WindowInfosListenerForTest.WindowInfo>,java.util.List<android.window.WindowInfosListenerForTest.DisplayInfo>>);
    method @Deprecated public void removeWindowInfosListener(@NonNull java.util.function.Consumer<java.util.List<android.window.WindowInfosListenerForTest.WindowInfo>>);
    method public void removeWindowInfosListener(@NonNull java.util.function.BiConsumer<java.util.List<android.window.WindowInfosListenerForTest.WindowInfo>,java.util.List<android.window.WindowInfosListenerForTest.DisplayInfo>>);
  }

+52 −1
Original line number Diff line number Diff line
@@ -37,6 +37,7 @@ import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CountDownLatch;
import java.util.function.BiConsumer;
import java.util.function.Consumer;

/**
 * Wrapper class to provide access to WindowInfosListener within tests.
@@ -184,11 +185,15 @@ public class WindowInfosListenerForTest {

    private static final String TAG = "WindowInfosListenerForTest";

    private ArrayMap<BiConsumer<List<WindowInfo>, List<DisplayInfo>>, WindowInfosListener>
    private final ArrayMap<BiConsumer<List<WindowInfo>, List<DisplayInfo>>, WindowInfosListener>
            mListeners;
    private final ArrayMap<Consumer<List<WindowInfo>>, BiConsumer<List<WindowInfo>,
            List<DisplayInfo>>>
            mConsumersToBiConsumers;

    public WindowInfosListenerForTest() {
        mListeners = new ArrayMap<>();
        mConsumersToBiConsumers = new ArrayMap<>();
    }

    /**
@@ -197,6 +202,29 @@ public class WindowInfosListenerForTest {
     *
     * @param consumer Consumer that is called with reverse Z ordered lists of WindowInfo instances
     *                 where the first value is the topmost window.
     *
     * @deprecated Use {@link #addWindowInfosListener(BiConsumer)} which provides window and
     *             display info.
     */
    @Deprecated
    @SuppressLint("UnflaggedApi") // The API is only used for tests.
    @RequiresPermission(Manifest.permission.ACCESS_SURFACE_FLINGER)
    public void addWindowInfosListener(@NonNull Consumer<List<WindowInfo>> consumer) {
        // This method isn't used in current versions of CTS but can't be removed yet because
        // newer builds need to pass on some older versions of CTS.
        BiConsumer<List<WindowInfo>, List<DisplayInfo>> biConsumer =
                (windowHandles, displayInfos) -> consumer.accept(windowHandles);
        mConsumersToBiConsumers.put(consumer, biConsumer);
        addWindowInfosListener(biConsumer);
    }

    /**
     * Register a listener that is called when the system's list of visible windows or displays has
     * changes in position or visibility.
     *
     * @param consumer Consumer that is called with window and display info. {@code WindowInfo}
     *                 instances are passed as a reverse Z ordered list of WindowInfo instances
     *                 where the first value is the topmost window.
     */
    @SuppressLint("UnflaggedApi") // The API is only used for tests.
    @RequiresPermission(Manifest.permission.ACCESS_SURFACE_FLINGER)
@@ -228,6 +256,29 @@ public class WindowInfosListenerForTest {
        calledWithInitialState.countDown();
    }

    /**
     * Unregisters the listener.
     *
     * @deprecated Use {@link #addWindowInfosListener(BiConsumer)} and
     *             {@link #removeWindowInfosListener(BiConsumer)} instead.
     */
    @Deprecated
    @SuppressLint("UnflaggedApi") // The API is only used for tests.
    public void removeWindowInfosListener(
            @NonNull Consumer<List<WindowInfo>> consumer) {
        // This method isn't used in current versions of CTS but can't be removed yet because
        // newer builds need to pass on some older versions of CTS.
        var biConsumer = mConsumersToBiConsumers.remove(consumer);
        if (biConsumer == null) {
            return;
        }
        WindowInfosListener listener = mListeners.remove(biConsumer);
        if (listener == null) {
            return;
        }
        listener.unregister();
    }

    /** Unregisters the listener. */
    @SuppressLint("UnflaggedApi") // The API is only used for tests.
    public void removeWindowInfosListener(