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

Commit 3cbe2c8b authored by Vishnu Nair's avatar Vishnu Nair Committed by Android (Google) Code Review
Browse files

Merge "Revert "Use WindowInfosListener for TPL"" into main

parents 0a2b125e c6b20cda
Loading
Loading
Loading
Loading
+39 −0
Original line number Diff line number Diff line
@@ -27,6 +27,9 @@ import android.window.SurfaceSyncGroup;

import com.android.window.flags.Flags;

import java.util.concurrent.Executor;
import java.util.function.Consumer;

/**
 * Provides an interface to the root-Surface of a View Hierarchy or Window. This
 * is used in combination with the {@link android.view.SurfaceControl} API to enable
@@ -193,6 +196,42 @@ public interface AttachedSurfaceControl {
            + "implemented before making this call.");
    }

    /**
     * Add a trusted presentation listener on the SurfaceControl associated with this window.
     *
     * @param t          Transaction that the trusted presentation listener is added on. This should
     *                   be applied by the caller.
     * @param thresholds The {@link SurfaceControl.TrustedPresentationThresholds} that will specify
     *                   when the to invoke the callback.
     * @param executor   The {@link Executor} where the callback will be invoked on.
     * @param listener   The {@link Consumer} that will receive the callbacks when entered or
     *                   exited the threshold.
     *
     * @see SurfaceControl.Transaction#setTrustedPresentationCallback(SurfaceControl,
     * SurfaceControl.TrustedPresentationThresholds, Executor, Consumer)
     *
     * @hide b/287076178 un-hide with API bump
     */
    default void addTrustedPresentationCallback(@NonNull SurfaceControl.Transaction t,
            @NonNull SurfaceControl.TrustedPresentationThresholds thresholds,
            @NonNull Executor executor, @NonNull Consumer<Boolean> listener) {
    }

    /**
     * Remove a trusted presentation listener on the SurfaceControl associated with this window.
     *
     * @param t          Transaction that the trusted presentation listener removed on. This should
     *                   be applied by the caller.
     * @param listener   The {@link Consumer} that was previously registered with
     *                   addTrustedPresentationCallback that should be removed.
     *
     * @see SurfaceControl.Transaction#clearTrustedPresentationCallback(SurfaceControl)
     * @hide b/287076178 un-hide with API bump
     */
    default void removeTrustedPresentationCallback(@NonNull SurfaceControl.Transaction t,
            @NonNull Consumer<Boolean> listener) {
    }

    /**
     * Transfer the currently in progress touch gesture from the host to the requested
     * {@link SurfaceControlViewHost.SurfacePackage}. This requires that the
+0 −8
Original line number Diff line number Diff line
@@ -73,8 +73,6 @@ import android.window.ISurfaceSyncGroupCompletedListener;
import android.window.ITaskFpsCallback;
import android.window.ScreenCapture;
import android.window.WindowContextInfo;
import android.window.ITrustedPresentationListener;
import android.window.TrustedPresentationThresholds;

/**
 * System private interface to the window manager.
@@ -1077,10 +1075,4 @@ interface IWindowManager
    @JavaPassthrough(annotation = "@android.annotation.RequiresPermission(android.Manifest"
            + ".permission.MONITOR_INPUT)")
    void unregisterDecorViewGestureListener(IDecorViewGestureListener listener, int displayId);

    void registerTrustedPresentationListener(in IBinder window, in ITrustedPresentationListener listener,
            in TrustedPresentationThresholds thresholds, int id);


    void unregisterTrustedPresentationListener(in ITrustedPresentationListener listener, int id);
}
+12 −0
Original line number Diff line number Diff line
@@ -12032,6 +12032,18 @@ public final class ViewRootImpl implements ViewParent,
        scheduleTraversals();
    }

    @Override
    public void addTrustedPresentationCallback(@NonNull SurfaceControl.Transaction t,
            @NonNull SurfaceControl.TrustedPresentationThresholds thresholds,
            @NonNull Executor executor, @NonNull Consumer<Boolean> listener) {
        t.setTrustedPresentationCallback(getSurfaceControl(), thresholds, executor, listener);
    }

    @Override
    public void removeTrustedPresentationCallback(@NonNull SurfaceControl.Transaction t,
            @NonNull Consumer<Boolean> listener) {
        t.clearTrustedPresentationCallback(getSurfaceControl());
    }

    private void logAndTrace(String msg) {
        if (Trace.isTagEnabled(Trace.TRACE_TAG_VIEW)) {
+0 −33
Original line number Diff line number Diff line
@@ -122,9 +122,7 @@ import android.view.WindowInsets.Side.InsetsSide;
import android.view.WindowInsets.Type;
import android.view.WindowInsets.Type.InsetsType;
import android.view.accessibility.AccessibilityNodeInfo;
import android.window.ITrustedPresentationListener;
import android.window.TaskFpsCallback;
import android.window.TrustedPresentationThresholds;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@@ -5886,35 +5884,4 @@ public interface WindowManager extends ViewManager {
    default boolean replaceContentOnDisplayWithSc(int displayId, @NonNull SurfaceControl sc) {
        throw new UnsupportedOperationException();
    }

    /**
     * Add a trusted presentation listener associated with a window. If the listener has already
     * been registered, an AndroidRuntimeException will be thrown.
     *
     * @param window  The Window to add the trusted presentation listener for
     * @param thresholds The {@link TrustedPresentationThresholds} that will specify
     *                   when the to invoke the callback.
     * @param executor   The {@link Executor} where the callback will be invoked on.
     * @param listener   The {@link ITrustedPresentationListener} that will receive the callbacks
     *                  when entered or exited trusted presentation per the thresholds.
     *
     * @hide b/287076178 un-hide with API bump
     */
    default void registerTrustedPresentationListener(@NonNull IBinder window,
            @NonNull TrustedPresentationThresholds thresholds,  @NonNull Executor executor,
            @NonNull Consumer<Boolean> listener) {
        throw new UnsupportedOperationException();
    }

    /**
     * Removes a presentation listener associated with a window. If the listener was not previously
     * registered, the call will be a noop.
     *
     * @hide
     * @see #registerTrustedPresentationListener(IBinder,
     * TrustedPresentationThresholds, Executor, Consumer)
     */
    default void unregisterTrustedPresentationListener(@NonNull Consumer<Boolean> listener) {
        throw new UnsupportedOperationException();
    }
}
+3 −91
Original line number Diff line number Diff line
@@ -30,13 +30,9 @@ import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.SystemProperties;
import android.util.AndroidRuntimeException;
import android.util.ArrayMap;
import android.util.ArraySet;
import android.util.Log;
import android.util.Pair;
import android.view.inputmethod.InputMethodManager;
import android.window.ITrustedPresentationListener;
import android.window.TrustedPresentationThresholds;

import com.android.internal.util.FastPrintWriter;

@@ -47,7 +43,6 @@ import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.WeakHashMap;
import java.util.concurrent.Executor;
import java.util.function.Consumer;
import java.util.function.IntConsumer;

/**
@@ -148,9 +143,6 @@ public final class WindowManagerGlobal {

    private Runnable mSystemPropertyUpdater;

    private final TrustedPresentationListener mTrustedPresentationListener =
            new TrustedPresentationListener();

    private WindowManagerGlobal() {
    }

@@ -798,86 +790,6 @@ public final class WindowManagerGlobal {
        }
    }

    public void registerTrustedPresentationListener(@NonNull IBinder window,
            @NonNull TrustedPresentationThresholds thresholds, Executor executor,
            @NonNull Consumer<Boolean> listener) {
        mTrustedPresentationListener.addListener(window, thresholds, listener, executor);
    }

    public void unregisterTrustedPresentationListener(@NonNull Consumer<Boolean> listener) {
        mTrustedPresentationListener.removeListener(listener);
    }

    private final class TrustedPresentationListener extends
            ITrustedPresentationListener.Stub {
        private static int sId = 0;
        private final ArrayMap<Consumer<Boolean>, Pair<Integer, Executor>> mListeners =
                new ArrayMap<>();

        private final Object mTplLock = new Object();

        private void addListener(IBinder window, TrustedPresentationThresholds thresholds,
                Consumer<Boolean> listener, Executor executor) {
            synchronized (mTplLock) {
                if (mListeners.containsKey(listener)) {
                    throw new AndroidRuntimeException("Trying to add duplicate listener");
                }
                int id = sId++;
                mListeners.put(listener, new Pair<>(id, executor));
                try {
                    WindowManagerGlobal.getWindowManagerService()
                            .registerTrustedPresentationListener(window, this, thresholds, id);
                } catch (RemoteException e) {
                    e.rethrowAsRuntimeException();
                }
            }
        }

        private void removeListener(Consumer<Boolean> listener) {
            synchronized (mTplLock) {
                var removedListener = mListeners.remove(listener);
                if (removedListener == null) {
                    Log.i(TAG, "listener " + listener + " does not exist.");
                    return;
                }

                try {
                    WindowManagerGlobal.getWindowManagerService()
                            .unregisterTrustedPresentationListener(this, removedListener.first);
                } catch (RemoteException e) {
                    e.rethrowAsRuntimeException();
                }
            }
        }

        @Override
        public void onTrustedPresentationChanged(int[] inTrustedStateListenerIds,
                int[] outOfTrustedStateListenerIds) {
            ArrayList<Runnable> firedListeners = new ArrayList<>();
            synchronized (mTplLock) {
                mListeners.forEach((listener, idExecutorPair) -> {
                    final var listenerId =  idExecutorPair.first;
                    final var executor = idExecutorPair.second;
                    for (int id : inTrustedStateListenerIds) {
                        if (listenerId == id) {
                            firedListeners.add(() -> executor.execute(
                                    () -> listener.accept(/*presentationState*/true)));
                        }
                    }
                    for (int id : outOfTrustedStateListenerIds) {
                        if (listenerId == id) {
                            firedListeners.add(() -> executor.execute(
                                    () -> listener.accept(/*presentationState*/false)));
                        }
                    }
                });
            }
            for (int i = 0; i < firedListeners.size(); i++) {
                firedListeners.get(i).run();
            }
        }
    }

    /** @hide */
    public void addWindowlessRoot(ViewRootImpl impl) {
        synchronized (mLock) {
Loading