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

Commit b212459e authored by Diego Vela's avatar Diego Vela Committed by Android (Google) Code Review
Browse files

Merge "Ensure listener is not triggered when reregistered" into main

parents d5346496 9dea2c45
Loading
Loading
Loading
Loading
+6 −2
Original line number Diff line number Diff line
@@ -329,13 +329,17 @@ public final class WindowManagerGlobal {

    /**
     * Adds a listener that will be notified whenever {@link #getWindowViews()} changes. The
     * current value is provided immediately. If it was registered previously then this is ano op.
     * current value is provided immediately using the provided {@link Executor}. If this
     * {@link Consumer} was registered previously, then this is a no op.
     */
    public void addWindowViewsListener(@NonNull Executor executor,
            @NonNull Consumer<List<View>> consumer) {
        synchronized (mLock) {
            if (mWindowViewsListenerGroup.isConsumerPresent(consumer)) {
                return;
            }
            mWindowViewsListenerGroup.addListener(executor, consumer);
            mWindowViewsListenerGroup.accept(getWindowViews());
            executor.execute(() -> consumer.accept(getWindowViews()));
        }
    }

+3 −2
Original line number Diff line number Diff line
@@ -42,8 +42,9 @@ public final class WindowInspector {
    }

    /**
     * Adds a listener that is notified whenever the list of global window views changes. If a
     * {@link Consumer} is already registered this method is a no op.
     * Adds a listener that is notified whenever the value of {@link #getGlobalWindowViews()}
     * changes. The current value is provided immediately using the provided {@link Executor}.
     * If this {@link Consumer} is already registered, then this method is a no op.
     * @see #getGlobalWindowViews()
     */
    @FlaggedApi(android.view.flags.Flags.FLAG_ROOT_VIEW_CHANGED_LISTENER)
+2 −2
Original line number Diff line number Diff line
@@ -48,7 +48,7 @@ public class ListenerGroup<T> {
     * is a no op.
     */
    public void addListener(@NonNull Executor executor, @NonNull Consumer<T> consumer) {
        if (isContained(consumer)) {
        if (isConsumerPresent(consumer)) {
            return;
        }
        mListeners.add(new ListenerWrapper<>(executor, consumer));
@@ -69,7 +69,7 @@ public class ListenerGroup<T> {
     * Returns {@code true} if the {@link Consumer} is present in the list, {@code false}
     * otherwise.
     */
    private boolean isContained(Consumer<T> consumer) {
    public boolean isConsumerPresent(Consumer<T> consumer) {
        return computeIndex(consumer) > -1;
    }