diff options
| author | 2024-02-01 21:48:46 +0000 | |
|---|---|---|
| committer | 2024-02-01 21:48:46 +0000 | |
| commit | a41fb7b32b2dd4a13ae7057472cb27ab03c6fa2a (patch) | |
| tree | e30780945647899069817d950355f85f87352baf | |
| parent | 669a68487f34653f2587c6636d08634b86fca0da (diff) | |
| parent | e823afc21cba1d3bacce94094680f2c5d45a93e3 (diff) | |
Merge changes from topic "setCanOccludePresentation" into main
* changes:
Use CanOccludePresentation state to calculate TrustedPresentationThresholds
Introduce eCanOccludePresentation layer flag
6 files changed, 71 insertions, 29 deletions
diff --git a/core/java/android/view/InputWindowHandle.java b/core/java/android/view/InputWindowHandle.java index 59ec60545d6d..9db1060abad4 100644 --- a/core/java/android/view/InputWindowHandle.java +++ b/core/java/android/view/InputWindowHandle.java @@ -162,6 +162,12 @@ public final class InputWindowHandle { public float alpha; /** + * Sets a property on this window indicating that its visible region should be considered when + * computing TrustedPresentation Thresholds. + */ + public boolean canOccludePresentation; + + /** * The input token for the window to which focus should be transferred when this input window * can be successfully focused. If null, this input window will not transfer its focus to * any other window. @@ -205,6 +211,7 @@ public final class InputWindowHandle { focusTransferTarget = other.focusTransferTarget; contentSize = new Size(other.contentSize.getWidth(), other.contentSize.getHeight()); alpha = other.alpha; + canOccludePresentation = other.canOccludePresentation; } @Override @@ -219,6 +226,7 @@ public final class InputWindowHandle { .append(", isClone=").append((inputConfig & InputConfig.CLONE) != 0) .append(", contentSize=").append(contentSize) .append(", alpha=").append(alpha) + .append(", canOccludePresentation=").append(canOccludePresentation) .toString(); } diff --git a/core/java/android/view/SurfaceControl.java b/core/java/android/view/SurfaceControl.java index 3ed03859ffa6..3c0ac06ae13f 100644 --- a/core/java/android/view/SurfaceControl.java +++ b/core/java/android/view/SurfaceControl.java @@ -168,6 +168,8 @@ public final class SurfaceControl implements Parcelable { boolean isTrustedOverlay); private static native void nativeSetDropInputMode( long transactionObj, long nativeObject, int flags); + private static native void nativeSetCanOccludePresentation(long transactionObj, + long nativeObject, boolean canOccludePresentation); private static native void nativeSurfaceFlushJankData(long nativeSurfaceObject); private static native boolean nativeClearContentFrameStats(long nativeObject); private static native boolean nativeGetContentFrameStats(long nativeObject, WindowContentFrameStats outStats); @@ -589,6 +591,28 @@ public final class SurfaceControl implements Parcelable { public static final int DISPLAY_DECORATION = 0x00000200; /** + * Ignore any destination frame set on the layer. This is used when the buffer scaling mode + * is freeze and the destination frame is applied asynchronously with the buffer submission. + * This is needed to maintain compatibility for SurfaceView scaling behavior. + * See SurfaceView scaling behavior for more details. + * @hide + */ + public static final int IGNORE_DESTINATION_FRAME = 0x00000400; + + /** + * Special casing for layer that is a refresh rate indicator + * @hide + */ + public static final int LAYER_IS_REFRESH_RATE_INDICATOR = 0x00000800; + + /** + * Sets a property on this layer indicating that its visible region should be considered when + * computing TrustedPresentation Thresholds + * @hide + */ + public static final int CAN_OCCLUDE_PRESENTATION = 0x00001000; + + /** * Surface creation flag: Creates a surface where color components are interpreted * as "non pre-multiplied" by their alpha channel. Of course this flag is * meaningless for surfaces without an alpha channel. By default @@ -4163,6 +4187,29 @@ public final class SurfaceControl implements Parcelable { } /** + * Sets a property on this SurfaceControl and all its children indicating that the visible + * region of this SurfaceControl should be considered when computing TrustedPresentation + * Thresholds. + * <p> + * API Guidance: + * The goal of this API is to identify windows that can be used to occlude content on + * another window. This includes windows controlled by the user or the system. If the window + * is transient, like Toast or notification shade, the window should not set this flag since + * the user or the app cannot use the window to occlude content in a persistent manner. All + * apps should have this flag set. + * <p> + * The caller must hold the ACCESS_SURFACE_FLINGER permission. + * @hide + */ + public Transaction setCanOccludePresentation(SurfaceControl sc, + boolean canOccludePresentation) { + checkPreconditions(sc); + final int value = (canOccludePresentation) ? CAN_OCCLUDE_PRESENTATION : 0; + nativeSetFlags(mNativeObject, sc.mNativeObject, value, CAN_OCCLUDE_PRESENTATION); + return this; + } + + /** * Sends a flush jank data transaction for the given surface. * @hide */ diff --git a/core/jni/android_hardware_input_InputWindowHandle.cpp b/core/jni/android_hardware_input_InputWindowHandle.cpp index ae23942f2500..bed776836043 100644 --- a/core/jni/android_hardware_input_InputWindowHandle.cpp +++ b/core/jni/android_hardware_input_InputWindowHandle.cpp @@ -75,6 +75,7 @@ static struct { jfieldID windowToken; jfieldID focusTransferTarget; jfieldID alpha; + jfieldID canOccludePresentation; } gInputWindowHandleClassInfo; static struct { @@ -327,6 +328,8 @@ jobject android_view_InputWindowHandle_fromWindowInfo(JNIEnv* env, gui::WindowIn javaObjectForIBinder(env, windowInfo.windowToken)); env->SetFloatField(inputWindowHandle, gInputWindowHandleClassInfo.alpha, windowInfo.alpha); + env->SetBooleanField(inputWindowHandle, gInputWindowHandleClassInfo.canOccludePresentation, + windowInfo.canOccludePresentation); return inputWindowHandle; } @@ -451,6 +454,9 @@ int register_android_view_InputWindowHandle(JNIEnv* env) { GET_FIELD_ID(gInputWindowHandleClassInfo.alpha, clazz, "alpha", "F"); + GET_FIELD_ID(gInputWindowHandleClassInfo.canOccludePresentation, clazz, + "canOccludePresentation", "Z"); + jclass surfaceControlClazz; FIND_CLASS(surfaceControlClazz, "android/view/SurfaceControl"); GET_FIELD_ID(gInputWindowHandleClassInfo.touchableRegionSurfaceControl.mNativeObject, diff --git a/services/core/java/com/android/server/wm/TrustedPresentationListenerController.java b/services/core/java/com/android/server/wm/TrustedPresentationListenerController.java index 1688a1a91114..817901f96ad4 100644 --- a/services/core/java/com/android/server/wm/TrustedPresentationListenerController.java +++ b/services/core/java/com/android/server/wm/TrustedPresentationListenerController.java @@ -32,7 +32,6 @@ import android.os.HandlerThread; import android.os.IBinder; import android.os.RemoteException; import android.util.ArrayMap; -import android.util.ArraySet; import android.util.IntArray; import android.util.Pair; import android.util.Size; @@ -159,10 +158,6 @@ public class TrustedPresentationListenerController { private InputWindowHandle[] mLastWindowHandles; - private final Object mIgnoredWindowTokensLock = new Object(); - - private final ArraySet<IBinder> mIgnoredWindowTokens = new ArraySet<>(); - private void startHandlerThreadIfNeeded() { synchronized (mHandlerThreadLock) { if (mHandler == null) { @@ -173,18 +168,6 @@ public class TrustedPresentationListenerController { } } - void addIgnoredWindowTokens(IBinder token) { - synchronized (mIgnoredWindowTokensLock) { - mIgnoredWindowTokens.add(token); - } - } - - void removeIgnoredWindowTokens(IBinder token) { - synchronized (mIgnoredWindowTokensLock) { - mIgnoredWindowTokens.remove(token); - } - } - void registerListener(IBinder window, ITrustedPresentationListener listener, TrustedPresentationThresholds thresholds, int id) { startHandlerThreadIfNeeded(); @@ -271,12 +254,8 @@ public class TrustedPresentationListenerController { ArrayMap<ITrustedPresentationListener, Pair<IntArray, IntArray>> listenerUpdates = new ArrayMap<>(); - ArraySet<IBinder> ignoredWindowTokens; - synchronized (mIgnoredWindowTokensLock) { - ignoredWindowTokens = new ArraySet<>(mIgnoredWindowTokens); - } for (var windowHandle : mLastWindowHandles) { - if (ignoredWindowTokens.contains(windowHandle.getWindowToken())) { + if (!windowHandle.canOccludePresentation) { ProtoLog.v(WM_DEBUG_TPL, "Skipping %s", windowHandle.name); continue; } diff --git a/services/core/java/com/android/server/wm/WindowState.java b/services/core/java/com/android/server/wm/WindowState.java index 24e50c54aa61..f5806c07c572 100644 --- a/services/core/java/com/android/server/wm/WindowState.java +++ b/services/core/java/com/android/server/wm/WindowState.java @@ -1148,10 +1148,6 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP parentWindow.addChild(this, sWindowSubLayerComparator); } - if (token.mRoundedCornerOverlay) { - mWmService.mTrustedPresentationListenerController.addIgnoredWindowTokens( - getWindowToken()); - } } @Override @@ -1163,6 +1159,9 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP if (secureWindowState()) { getPendingTransaction().setSecure(mSurfaceControl, isSecureLocked()); } + // All apps should be considered as occluding when computing TrustedPresentation Thresholds. + final boolean canOccludePresentation = !mSession.mCanAddInternalSystemWindow; + getPendingTransaction().setCanOccludePresentation(mSurfaceControl, canOccludePresentation); } void updateTrustedOverlay() { @@ -2344,9 +2343,6 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP mSession.onWindowRemoved(this); mWmService.postWindowRemoveCleanupLocked(this); - mWmService.mTrustedPresentationListenerController.removeIgnoredWindowTokens( - getWindowToken()); - consumeInsetsChange(); } diff --git a/services/tests/servicestests/utils/com/android/server/testutils/StubTransaction.java b/services/tests/servicestests/utils/com/android/server/testutils/StubTransaction.java index b8dcecdbfb95..e27bb4c8c3b6 100644 --- a/services/tests/servicestests/utils/com/android/server/testutils/StubTransaction.java +++ b/services/tests/servicestests/utils/com/android/server/testutils/StubTransaction.java @@ -320,4 +320,10 @@ public class StubTransaction extends SurfaceControl.Transaction { mWindowInfosReportedListeners.add(listener); return this; } + + @Override + public SurfaceControl.Transaction setCanOccludePresentation(SurfaceControl sc, + boolean canOccludePresentation) { + return this; + } } |