Merge "[automerger skipped] Prioritize system toasts am: 939612739c am: 6c15eac41d am: e37e10aa95 -s ours" into main
diff --git a/core/api/current.txt b/core/api/current.txt
index 0ab37a3..a3e39dc 100644
--- a/core/api/current.txt
+++ b/core/api/current.txt
@@ -61408,11 +61408,11 @@
   @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") @FloatRange(from=0.0f, fromInclusive=false, to=1.0f) public float getMinAlpha();
+    method @FlaggedApi("com.android.window.flags.trusted_presentation_listener_for_window") @FloatRange(from=0.0f, fromInclusive=false, to=1.0f) public float getMinFractionRendered();
+    method @FlaggedApi("com.android.window.flags.trusted_presentation_listener_for_window") @IntRange(from=1) public int getStabilityRequirementMillis();
     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;
   }
 
 }
diff --git a/core/java/android/window/TrustedPresentationThresholds.java b/core/java/android/window/TrustedPresentationThresholds.java
index 90f8834..a30c8fa 100644
--- a/core/java/android/window/TrustedPresentationThresholds.java
+++ b/core/java/android/window/TrustedPresentationThresholds.java
@@ -19,15 +19,15 @@
 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;
 
+import java.util.Objects;
+
 /**
  * Threshold values that are sent with
  * {@link android.view.WindowManager#registerTrustedPresentationListener(IBinder,
@@ -36,33 +36,53 @@
 @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
+     * The min alpha the Window is required to have to be considered inside the
      * threshold.
      */
     @FloatRange(from = 0f, fromInclusive = false, to = 1f)
-    @FlaggedApi(Flags.FLAG_TRUSTED_PRESENTATION_LISTENER_FOR_WINDOW)
-    @SuppressLint("InternalField") // simple data class
-    public final float minAlpha;
+    private final float mMinAlpha;
 
     /**
-     * The min fraction of the SurfaceControl that was presented to the user to be considered
+     * The min fraction of the Window that was presented to the user to be considered
      * inside the threshold.
      */
     @FloatRange(from = 0f, fromInclusive = false, to = 1f)
-    @FlaggedApi(Flags.FLAG_TRUSTED_PRESENTATION_LISTENER_FOR_WINDOW)
-    @SuppressLint("InternalField") // simple data class
-    public final float minFractionRendered;
+    private final float mMinFractionRendered;
 
     /**
-     * The time in milliseconds required for the {@link SurfaceControl} to be in the threshold.
+     * The time in milliseconds required for the Window to be in the threshold.
      */
     @IntRange(from = 1)
+    private final int mStabilityRequirementMs;
+
+    /**
+     * The min alpha the Window is required to have to be considered inside the
+     * threshold.
+     */
     @FlaggedApi(Flags.FLAG_TRUSTED_PRESENTATION_LISTENER_FOR_WINDOW)
-    @SuppressLint("InternalField") // simple data class
-    public final int stabilityRequirementMs;
+    public @FloatRange(from = 0f, fromInclusive = false, to = 1f) float getMinAlpha() {
+        return mMinAlpha;
+    }
+
+    /**
+     * The min fraction of the Window that was presented to the user to be considered
+     * inside the threshold.
+     */
+    @FlaggedApi(Flags.FLAG_TRUSTED_PRESENTATION_LISTENER_FOR_WINDOW)
+    public @FloatRange(from = 0f, fromInclusive = false, to = 1f) float getMinFractionRendered() {
+        return mMinFractionRendered;
+    }
+
+    /**
+     * The time in milliseconds required for the Window to be in the threshold.
+     */
+    @FlaggedApi(Flags.FLAG_TRUSTED_PRESENTATION_LISTENER_FOR_WINDOW)
+    public @IntRange(from = 1) int getStabilityRequirementMillis() {
+        return mStabilityRequirementMs;
+    }
 
     private void checkValid() {
-        if (minAlpha <= 0 || minFractionRendered <= 0 || stabilityRequirementMs < 1) {
+        if (mMinAlpha <= 0 || mMinFractionRendered <= 0 || mStabilityRequirementMs < 1) {
             throw new IllegalArgumentException(
                     "TrustedPresentationThresholds values are invalid");
         }
@@ -71,23 +91,23 @@
     /**
      * Creates a new TrustedPresentationThresholds.
      *
-     * @param minAlpha               The min alpha the {@link SurfaceControl} is required to
+     * @param minAlpha               The min alpha the Window is required to
      *                               have to be considered inside the
      *                               threshold.
-     * @param minFractionRendered    The min fraction of the SurfaceControl that was presented
+     * @param minFractionRendered    The min fraction of the Window that was presented
      *                               to the user to be considered
      *                               inside the threshold.
      * @param stabilityRequirementMs The time in milliseconds required for the
-     *                               {@link SurfaceControl} to be in the threshold.
+     *                               Window 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.minAlpha = minAlpha;
-        this.minFractionRendered = minFractionRendered;
-        this.stabilityRequirementMs = stabilityRequirementMs;
+        this.mMinAlpha = minAlpha;
+        this.mMinFractionRendered = minFractionRendered;
+        this.mStabilityRequirementMs = stabilityRequirementMs;
         checkValid();
     }
 
@@ -95,18 +115,18 @@
     @FlaggedApi(Flags.FLAG_TRUSTED_PRESENTATION_LISTENER_FOR_WINDOW)
     public String toString() {
         return "TrustedPresentationThresholds { "
-                + "minAlpha = " + minAlpha + ", "
-                + "minFractionRendered = " + minFractionRendered + ", "
-                + "stabilityRequirementMs = " + stabilityRequirementMs
+                + "minAlpha = " + mMinAlpha + ", "
+                + "minFractionRendered = " + mMinFractionRendered + ", "
+                + "stabilityRequirementMs = " + mStabilityRequirementMs
                 + " }";
     }
 
     @Override
     @FlaggedApi(Flags.FLAG_TRUSTED_PRESENTATION_LISTENER_FOR_WINDOW)
     public void writeToParcel(@NonNull Parcel dest, int flags) {
-        dest.writeFloat(minAlpha);
-        dest.writeFloat(minFractionRendered);
-        dest.writeInt(stabilityRequirementMs);
+        dest.writeFloat(mMinAlpha);
+        dest.writeFloat(mMinFractionRendered);
+        dest.writeInt(mStabilityRequirementMs);
     }
 
     @Override
@@ -115,13 +135,34 @@
         return 0;
     }
 
+
+    @Override
+    @FlaggedApi(Flags.FLAG_TRUSTED_PRESENTATION_LISTENER_FOR_WINDOW)
+    public int hashCode() {
+        return Objects.hash(mMinAlpha, mMinFractionRendered, mStabilityRequirementMs);
+    }
+
+    @Override
+    @FlaggedApi(Flags.FLAG_TRUSTED_PRESENTATION_LISTENER_FOR_WINDOW)
+    public boolean equals(Object o) {
+        if (this == o) {
+            return true;
+        }
+        if (!(o instanceof TrustedPresentationThresholds that)) {
+            return false;
+        }
+        return mMinAlpha == that.mMinAlpha
+                && mMinFractionRendered == that.mMinFractionRendered
+                && mStabilityRequirementMs == that.mStabilityRequirementMs;
+    }
+
     /**
      * @hide
      */
     TrustedPresentationThresholds(@NonNull Parcel in) {
-        minAlpha = in.readFloat();
-        minFractionRendered = in.readFloat();
-        stabilityRequirementMs = in.readInt();
+        mMinAlpha = in.readFloat();
+        mMinFractionRendered = in.readFloat();
+        mStabilityRequirementMs = in.readInt();
 
         checkValid();
     }
diff --git a/services/core/java/com/android/server/wm/TrustedPresentationListenerController.java b/services/core/java/com/android/server/wm/TrustedPresentationListenerController.java
index 817901f..fa2d9bf 100644
--- a/services/core/java/com/android/server/wm/TrustedPresentationListenerController.java
+++ b/services/core/java/com/android/server/wm/TrustedPresentationListenerController.java
@@ -322,15 +322,17 @@
             var listener = trustedPresentationInfo.mListener;
             boolean lastState = trustedPresentationInfo.mLastComputedTrustedPresentationState;
             boolean newState =
-                    (alpha >= trustedPresentationInfo.mThresholds.minAlpha) && (fractionRendered
-                            >= trustedPresentationInfo.mThresholds.minFractionRendered);
+                    (alpha >= trustedPresentationInfo.mThresholds.getMinAlpha())
+                            && (fractionRendered >= trustedPresentationInfo.mThresholds
+                                    .getMinFractionRendered());
             trustedPresentationInfo.mLastComputedTrustedPresentationState = newState;
 
             ProtoLog.v(WM_DEBUG_TPL,
                     "lastState=%s newState=%s alpha=%f minAlpha=%f fractionRendered=%f "
                             + "minFractionRendered=%f",
-                    lastState, newState, alpha, trustedPresentationInfo.mThresholds.minAlpha,
-                    fractionRendered, trustedPresentationInfo.mThresholds.minFractionRendered);
+                    lastState, newState, alpha, trustedPresentationInfo.mThresholds.getMinAlpha(),
+                    fractionRendered, trustedPresentationInfo.mThresholds
+                            .getMinFractionRendered());
 
             if (lastState && !newState) {
                 // We were in the trusted presentation state, but now we left it,
@@ -350,13 +352,15 @@
                 trustedPresentationInfo.mEnteredTrustedPresentationStateTime = currTimeMs;
                 mHandler.postDelayed(() -> {
                     computeTpl(mLastWindowHandles);
-                }, (long) (trustedPresentationInfo.mThresholds.stabilityRequirementMs * 1.5));
+                }, (long) (trustedPresentationInfo.mThresholds
+                            .getStabilityRequirementMillis() * 1.5));
             }
 
             // Has the timer elapsed, but we are still in the state? Emit a callback if needed
             if (!trustedPresentationInfo.mLastReportedTrustedPresentationState && newState && (
                     currTimeMs - trustedPresentationInfo.mEnteredTrustedPresentationStateTime
-                            > trustedPresentationInfo.mThresholds.stabilityRequirementMs)) {
+                            > trustedPresentationInfo.mThresholds
+                                        .getStabilityRequirementMillis())) {
                 trustedPresentationInfo.mLastReportedTrustedPresentationState = true;
                 addListenerUpdate(listenerUpdates, listener,
                         trustedPresentationInfo.mId, /*presentationState*/ true);
@@ -413,15 +417,6 @@
             mThresholds = thresholds;
             mId = id;
             mListener = listener;
-            checkValid(thresholds);
-        }
-
-        private void checkValid(TrustedPresentationThresholds thresholds) {
-            if (thresholds.minAlpha <= 0 || thresholds.minFractionRendered <= 0
-                    || thresholds.stabilityRequirementMs < 1) {
-                throw new IllegalArgumentException(
-                        "TrustedPresentationThresholds values are invalid");
-            }
         }
     }
 }