diff options
| author | 2024-08-21 23:34:58 +0000 | |
|---|---|---|
| committer | 2024-08-21 23:34:58 +0000 | |
| commit | c43d1224a18f8f10bcb4022990f0532026a09548 (patch) | |
| tree | 866c6a745c80ee72ea54c26a6e44d07903c2e527 | |
| parent | 86e0244738539b4684de6870f66e91505c30e032 (diff) | |
| parent | 89d5ce6ee71e8cb49dc3a4df586115d83ccc9ca2 (diff) | |
Merge "Add back old WindowInfosListenerForTest test api" into main
| -rw-r--r-- | core/api/test-current.txt | 2 | ||||
| -rw-r--r-- | core/java/android/window/WindowInfosListenerForTest.java | 53 |
2 files changed, 54 insertions, 1 deletions
diff --git a/core/api/test-current.txt b/core/api/test-current.txt index 177b859da0ad..ce0d38ffe9ad 100644 --- a/core/api/test-current.txt +++ b/core/api/test-current.txt @@ -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>>); } diff --git a/core/java/android/window/WindowInfosListenerForTest.java b/core/java/android/window/WindowInfosListenerForTest.java index d1d403114106..ac9bec305fff 100644 --- a/core/java/android/window/WindowInfosListenerForTest.java +++ b/core/java/android/window/WindowInfosListenerForTest.java @@ -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( |