diff --git a/core/java/android/view/SurfaceControl.java b/core/java/android/view/SurfaceControl.java index b300f3031a00e..d6186d71331e1 100644 --- a/core/java/android/view/SurfaceControl.java +++ b/core/java/android/view/SurfaceControl.java @@ -148,6 +148,8 @@ public final class SurfaceControl implements Parcelable { float width, float height, float vecX, float vecY, float maxStretchAmountX, float maxStretchAmountY, float childRelativeLeft, float childRelativeTop, float childRelativeRight, float childRelativeBottom); + private static native void nativeSetTrustedOverlay(long transactionObj, long nativeObject, + boolean isTrustedOverlay); private static native boolean nativeClearContentFrameStats(long nativeObject); private static native boolean nativeGetContentFrameStats(long nativeObject, WindowContentFrameStats outStats); @@ -3435,6 +3437,17 @@ public final class SurfaceControl implements Parcelable { return this; } + /** + * Sets the trusted overlay state on this SurfaceControl and it is inherited to all the + * children. The caller must hold the ACCESS_SURFACE_FLINGER permission. + * @hide + */ + public Transaction setTrustedOverlay(SurfaceControl sc, boolean isTrustedOverlay) { + checkPreconditions(sc); + nativeSetTrustedOverlay(mNativeObject, sc.mNativeObject, isTrustedOverlay); + return this; + } + /** * Merge the other transaction into this transaction, clearing the * other transaction as if it had been applied. diff --git a/core/jni/android_view_SurfaceControl.cpp b/core/jni/android_view_SurfaceControl.cpp index dd80c731fbce9..50cd70f7d0567 100644 --- a/core/jni/android_view_SurfaceControl.cpp +++ b/core/jni/android_view_SurfaceControl.cpp @@ -825,6 +825,14 @@ static void nativeSetShadowRadius(JNIEnv* env, jclass clazz, jlong transactionOb transaction->setShadowRadius(ctrl, shadowRadius); } +static void nativeSetTrustedOverlay(JNIEnv* env, jclass clazz, jlong transactionObj, + jlong nativeObject, jboolean isTrustedOverlay) { + auto transaction = reinterpret_cast(transactionObj); + + SurfaceControl* const ctrl = reinterpret_cast(nativeObject); + transaction->setTrustedOverlay(ctrl, isTrustedOverlay); +} + static void nativeSetFrameRate(JNIEnv* env, jclass clazz, jlong transactionObj, jlong nativeObject, jfloat frameRate, jint compatibility, jint changeFrameRateStrategy) { auto transaction = reinterpret_cast(transactionObj); @@ -1999,6 +2007,8 @@ static const JNINativeMethod sSurfaceControlMethods[] = { (void*)nativeSetTransformHint }, {"nativeGetTransformHint", "(J)I", (void*)nativeGetTransformHint }, + {"nativeSetTrustedOverlay", "(JJZ)V", + (void*)nativeSetTrustedOverlay }, // clang-format on }; diff --git a/services/core/java/com/android/server/wm/RootWindowContainer.java b/services/core/java/com/android/server/wm/RootWindowContainer.java index 629d20e2f5692..0b463a962cb3d 100644 --- a/services/core/java/com/android/server/wm/RootWindowContainer.java +++ b/services/core/java/com/android/server/wm/RootWindowContainer.java @@ -2212,16 +2212,17 @@ class RootWindowContainer extends WindowContainer ensureActivitiesVisible(null, 0, false /* preserveWindows */); resumeFocusedTasksTopActivities(); - notifyActivityPipModeChanged(r); + notifyActivityPipModeChanged(r.getTask(), r); } /** * Notifies when an activity enters or leaves PIP mode. * + * @param task the task of {@param r} * @param r indicates the activity currently in PIP, can be null to indicate no activity is * currently in PIP mode. */ - void notifyActivityPipModeChanged(@Nullable ActivityRecord r) { + void notifyActivityPipModeChanged(@NonNull Task task, @Nullable ActivityRecord r) { final boolean inPip = r != null; if (inPip) { mService.getTaskChangeNotificationController().notifyActivityPinned(r); @@ -2229,6 +2230,9 @@ class RootWindowContainer extends WindowContainer mService.getTaskChangeNotificationController().notifyActivityUnpinned(); } mWindowManager.mPolicy.setPipVisibilityLw(inPip); + mWmService.mTransactionFactory.get() + .setTrustedOverlay(task.getSurfaceControl(), inPip) + .apply(); } void executeAppTransitionForAllDisplay() { diff --git a/services/core/java/com/android/server/wm/Task.java b/services/core/java/com/android/server/wm/Task.java index 91e316ee6e16f..796654a42999d 100644 --- a/services/core/java/com/android/server/wm/Task.java +++ b/services/core/java/com/android/server/wm/Task.java @@ -1202,7 +1202,7 @@ class Task extends TaskFragment { && (newParent == null || !newParent.inPinnedWindowingMode())) { // Notify if a task from the root pinned task is being removed // (or moved depending on the mode). - mRootWindowContainer.notifyActivityPipModeChanged(null); + mRootWindowContainer.notifyActivityPipModeChanged(this, null); } } @@ -4562,7 +4562,7 @@ class Task extends TaskFragment { : WINDOWING_MODE_FULLSCREEN; } if (currentMode == WINDOWING_MODE_PINNED) { - mRootWindowContainer.notifyActivityPipModeChanged(null); + mRootWindowContainer.notifyActivityPipModeChanged(this, null); } if (likelyResolvedMode == WINDOWING_MODE_PINNED) { // In the case that we've disabled affecting the SysUI flags as a part of seamlessly diff --git a/services/tests/wmtests/src/com/android/server/wm/StubTransaction.java b/services/tests/wmtests/src/com/android/server/wm/StubTransaction.java index e32b2aa68b695..cac948c97b254 100644 --- a/services/tests/wmtests/src/com/android/server/wm/StubTransaction.java +++ b/services/tests/wmtests/src/com/android/server/wm/StubTransaction.java @@ -270,4 +270,10 @@ public class StubTransaction extends SurfaceControl.Transaction { public SurfaceControl.Transaction setColorSpace(SurfaceControl sc, ColorSpace colorSpace) { return this; } + + @Override + public SurfaceControl.Transaction setTrustedOverlay(SurfaceControl sc, + boolean isTrustedOverlay) { + return this; + } }