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

Commit 99249ffe authored by Vishnu Nair's avatar Vishnu Nair
Browse files

Expose TrustedPresentationListener for Window

Bug: 278027319
Test: TrustedPresentationCallbackTest
Change-Id: I87d4a0b786daa9255ba150ff2409028b874c7b7b
parent 06ebddac
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -53795,9 +53795,11 @@ package android.view {
    method @Deprecated public android.view.Display getDefaultDisplay();
    method @NonNull public default android.view.WindowMetrics getMaximumWindowMetrics();
    method public default boolean isCrossWindowBlurEnabled();
    method @FlaggedApi("com.android.window.flags.trusted_presentation_listener_for_window") public default void registerTrustedPresentationListener(@NonNull android.os.IBinder, @NonNull android.window.TrustedPresentationThresholds, @NonNull java.util.concurrent.Executor, @NonNull java.util.function.Consumer<java.lang.Boolean>);
    method public default void removeCrossWindowBlurEnabledListener(@NonNull java.util.function.Consumer<java.lang.Boolean>);
    method public default void removeProposedRotationListener(@NonNull java.util.function.IntConsumer);
    method public void removeViewImmediate(android.view.View);
    method @FlaggedApi("com.android.window.flags.trusted_presentation_listener_for_window") public default void unregisterTrustedPresentationListener(@NonNull java.util.function.Consumer<java.lang.Boolean>);
    field public static final String PROPERTY_ACTIVITY_EMBEDDING_ALLOW_SYSTEM_OVERRIDE = "android.window.PROPERTY_ACTIVITY_EMBEDDING_ALLOW_SYSTEM_OVERRIDE";
    field public static final String PROPERTY_ACTIVITY_EMBEDDING_SPLITS_ENABLED = "android.window.PROPERTY_ACTIVITY_EMBEDDING_SPLITS_ENABLED";
    field public static final String PROPERTY_CAMERA_COMPAT_ALLOW_FORCE_ROTATION = "android.window.PROPERTY_CAMERA_COMPAT_ALLOW_FORCE_ROTATION";
@@ -60775,6 +60777,16 @@ package android.window {
    method public void markSyncReady();
  }
  @FlaggedApi("com.android.window.flags.trusted_presentation_listener_for_window") public final class TrustedPresentationThresholds implements android.os.Parcelable {
    ctor @FlaggedApi("com.android.window.flags.trusted_presentation_listener_for_window") public TrustedPresentationThresholds(@FloatRange(from=0.0f, fromInclusive=false, to=1.0f) float, @FloatRange(from=0.0f, fromInclusive=false, to=1.0f) float, @IntRange(from=1) int);
    method @FlaggedApi("com.android.window.flags.trusted_presentation_listener_for_window") public int describeContents();
    method @FlaggedApi("com.android.window.flags.trusted_presentation_listener_for_window") public void writeToParcel(@NonNull android.os.Parcel, int);
    field @FlaggedApi("com.android.window.flags.trusted_presentation_listener_for_window") @NonNull public static final android.os.Parcelable.Creator<android.window.TrustedPresentationThresholds> CREATOR;
    field @FlaggedApi("com.android.window.flags.trusted_presentation_listener_for_window") @FloatRange(from=0.0f, fromInclusive=false, to=1.0f) public final float minAlpha;
    field @FlaggedApi("com.android.window.flags.trusted_presentation_listener_for_window") @FloatRange(from=0.0f, fromInclusive=false, to=1.0f) public final float minFractionRendered;
    field @FlaggedApi("com.android.window.flags.trusted_presentation_listener_for_window") @IntRange(from=1) public final int stabilityRequirementMs;
  }
}
package javax.microedition.khronos.egl {
+10 −9
Original line number Diff line number Diff line
@@ -126,6 +126,8 @@ import android.window.ITrustedPresentationListener;
import android.window.TaskFpsCallback;
import android.window.TrustedPresentationThresholds;

import com.android.window.flags.Flags;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.ArrayList;
@@ -5888,18 +5890,18 @@ public interface WindowManager extends ViewManager {
    }

    /**
     * Add a trusted presentation listener associated with a window. If the listener has already
     * been registered, an AndroidRuntimeException will be thrown.
     * Add a trusted presentation listener associated with a window.
     *
     * <p> If this listener is already registered then the window and thresholds will be updated.
     *
     * @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
     * @param listener   The {@link Consumer} that will receive the callbacks
     *                  when entered or exited trusted presentation per the thresholds.
     *
     * @hide b/287076178 un-hide with API bump
     */
    @FlaggedApi(Flags.FLAG_TRUSTED_PRESENTATION_LISTENER_FOR_WINDOW)
    default void registerTrustedPresentationListener(@NonNull IBinder window,
            @NonNull TrustedPresentationThresholds thresholds,  @NonNull Executor executor,
            @NonNull Consumer<Boolean> listener) {
@@ -5910,10 +5912,9 @@ public interface WindowManager extends ViewManager {
     * 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)
     * @see WindowManager#registerTrustedPresentationListener(IBinder, TrustedPresentationThresholds, Executor, Consumer)
     */
    @FlaggedApi(Flags.FLAG_TRUSTED_PRESENTATION_LISTENER_FOR_WINDOW)
    default void unregisterTrustedPresentationListener(@NonNull Consumer<Boolean> listener) {
        throw new UnsupportedOperationException();
    }
+2 −1
Original line number Diff line number Diff line
@@ -820,7 +820,8 @@ public final class WindowManagerGlobal {
                Consumer<Boolean> listener, Executor executor) {
            synchronized (mTplLock) {
                if (mListeners.containsKey(listener)) {
                    throw new AndroidRuntimeException("Trying to add duplicate listener");
                    Log.i(TAG, "Updating listener " + listener + " thresholds to " + thresholds);
                    removeListener(listener);
                }
                int id = sId++;
                mListeners.put(listener, new Pair<>(id, executor));
+37 −20
Original line number Diff line number Diff line
@@ -16,40 +16,53 @@

package android.window;

import android.annotation.FlaggedApi;
import android.annotation.FloatRange;
import android.annotation.IntRange;
import android.annotation.SuppressLint;
import android.os.Parcel;
import android.os.Parcelable;
import android.view.SurfaceControl;

import androidx.annotation.NonNull;

import com.android.window.flags.Flags;

/**
 * @hide
 * Threshold values that are sent with
 * {@link android.view.WindowManager#registerTrustedPresentationListener(IBinder,
 * TrustedPresentationThresholds, Executor, Consumer)}
 */
@FlaggedApi(Flags.FLAG_TRUSTED_PRESENTATION_LISTENER_FOR_WINDOW)
public final class TrustedPresentationThresholds implements Parcelable {
    /**
     * The min alpha the {@link SurfaceControl} is required to have to be considered inside the
     * threshold.
     */
    @FloatRange(from = 0f, fromInclusive = false, to = 1f)
    public final float mMinAlpha;
    @FlaggedApi(Flags.FLAG_TRUSTED_PRESENTATION_LISTENER_FOR_WINDOW)
    @SuppressLint("InternalField") // simple data class
    public final float minAlpha;

    /**
     * The min fraction of the SurfaceControl that was presented to the user to be considered
     * inside the threshold.
     */
    @FloatRange(from = 0f, fromInclusive = false, to = 1f)
    public final float mMinFractionRendered;
    @FlaggedApi(Flags.FLAG_TRUSTED_PRESENTATION_LISTENER_FOR_WINDOW)
    @SuppressLint("InternalField") // simple data class
    public final float minFractionRendered;

    /**
     * The time in milliseconds required for the {@link SurfaceControl} to be in the threshold.
     */
    @IntRange(from = 1)
    public final int mStabilityRequirementMs;
    @FlaggedApi(Flags.FLAG_TRUSTED_PRESENTATION_LISTENER_FOR_WINDOW)
    @SuppressLint("InternalField") // simple data class
    public final int stabilityRequirementMs;

    private void checkValid() {
        if (mMinAlpha <= 0 || mMinFractionRendered <= 0 || mStabilityRequirementMs < 1) {
        if (minAlpha <= 0 || minFractionRendered <= 0 || stabilityRequirementMs < 1) {
            throw new IllegalArgumentException(
                    "TrustedPresentationThresholds values are invalid");
        }
@@ -67,33 +80,37 @@ public final class TrustedPresentationThresholds implements Parcelable {
     * @param stabilityRequirementMs The time in milliseconds required for the
     *                               {@link SurfaceControl} to be in the threshold.
     */
    @FlaggedApi(Flags.FLAG_TRUSTED_PRESENTATION_LISTENER_FOR_WINDOW)
    public TrustedPresentationThresholds(
            @FloatRange(from = 0f, fromInclusive = false, to = 1f) float minAlpha,
            @FloatRange(from = 0f, fromInclusive = false, to = 1f) float minFractionRendered,
            @IntRange(from = 1) int stabilityRequirementMs) {
        this.mMinAlpha = minAlpha;
        this.mMinFractionRendered = minFractionRendered;
        this.mStabilityRequirementMs = stabilityRequirementMs;
        this.minAlpha = minAlpha;
        this.minFractionRendered = minFractionRendered;
        this.stabilityRequirementMs = stabilityRequirementMs;
        checkValid();
    }

    @Override
    @FlaggedApi(Flags.FLAG_TRUSTED_PRESENTATION_LISTENER_FOR_WINDOW)
    public String toString() {
        return "TrustedPresentationThresholds { "
                + "minAlpha = " + mMinAlpha + ", "
                + "minFractionRendered = " + mMinFractionRendered + ", "
                + "stabilityRequirementMs = " + mStabilityRequirementMs
                + "minAlpha = " + minAlpha + ", "
                + "minFractionRendered = " + minFractionRendered + ", "
                + "stabilityRequirementMs = " + stabilityRequirementMs
                + " }";
    }

    @Override
    @FlaggedApi(Flags.FLAG_TRUSTED_PRESENTATION_LISTENER_FOR_WINDOW)
    public void writeToParcel(@NonNull Parcel dest, int flags) {
        dest.writeFloat(mMinAlpha);
        dest.writeFloat(mMinFractionRendered);
        dest.writeInt(mStabilityRequirementMs);
        dest.writeFloat(minAlpha);
        dest.writeFloat(minFractionRendered);
        dest.writeInt(stabilityRequirementMs);
    }

    @Override
    @FlaggedApi(Flags.FLAG_TRUSTED_PRESENTATION_LISTENER_FOR_WINDOW)
    public int describeContents() {
        return 0;
    }
@@ -102,24 +119,24 @@ public final class TrustedPresentationThresholds implements Parcelable {
     * @hide
     */
    TrustedPresentationThresholds(@NonNull Parcel in) {
        mMinAlpha = in.readFloat();
        mMinFractionRendered = in.readFloat();
        mStabilityRequirementMs = in.readInt();
        minAlpha = in.readFloat();
        minFractionRendered = in.readFloat();
        stabilityRequirementMs = in.readInt();

        checkValid();
    }

    /**
     * @hide
     */
    @FlaggedApi(Flags.FLAG_TRUSTED_PRESENTATION_LISTENER_FOR_WINDOW)
    public static final @NonNull Creator<TrustedPresentationThresholds> CREATOR =
            new Creator<TrustedPresentationThresholds>() {
                @Override
                @FlaggedApi(Flags.FLAG_TRUSTED_PRESENTATION_LISTENER_FOR_WINDOW)
                public TrustedPresentationThresholds[] newArray(int size) {
                    return new TrustedPresentationThresholds[size];
                }

                @Override
                @FlaggedApi(Flags.FLAG_TRUSTED_PRESENTATION_LISTENER_FOR_WINDOW)
                public TrustedPresentationThresholds createFromParcel(@NonNull Parcel in) {
                    return new TrustedPresentationThresholds(in);
                }
+8 −0
Original line number Diff line number Diff line
@@ -56,3 +56,11 @@ flag {
    is_fixed_read_only: true
    bug: "308662081"
}

flag {
    namespace: "window_surfaces"
    name: "trusted_presentation_listener_for_window"
    description: "Enable trustedPresentationListener on windows public API"
    is_fixed_read_only: true
    bug: "278027319"
}
 No newline at end of file
Loading