Add mechanism for a task's windows to be trusted overlays

- Exposes a method to set that a certain part of the SF hierarchy is
  trusted, and sets this state for tasks in PIP.

Bug: 191529039
Bug: 196389741
Test: Manual, try using permission dialog while PIP is active

Change-Id: I170cb5a7d22ef569eb36de21cc0bcbef60dd385e
Merged-In: I170cb5a7d22ef569eb36de21cc0bcbef60dd385e
This commit is contained in:
Winson Chung
2021-07-15 10:35:46 -07:00
parent 716333761d
commit 47fb132ef2
6 changed files with 54 additions and 5 deletions

View File

@@ -139,6 +139,8 @@ public final class SurfaceControl implements Parcelable {
int blurRadius); int blurRadius);
private static native void nativeSetLayerStack(long transactionObj, long nativeObject, private static native void nativeSetLayerStack(long transactionObj, long nativeObject,
int layerStack); int layerStack);
private static native void nativeSetTrustedOverlay(long transactionObj, long nativeObject,
boolean isTrustedOverlay);
private static native boolean nativeClearContentFrameStats(long nativeObject); private static native boolean nativeClearContentFrameStats(long nativeObject);
private static native boolean nativeGetContentFrameStats(long nativeObject, WindowContentFrameStats outStats); private static native boolean nativeGetContentFrameStats(long nativeObject, WindowContentFrameStats outStats);
@@ -3037,6 +3039,17 @@ public final class SurfaceControl implements Parcelable {
return this; 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 * Merge the other transaction into this transaction, clearing the
* other transaction as if it had been applied. * other transaction as if it had been applied.

View File

@@ -627,6 +627,14 @@ static void nativeSetShadowRadius(JNIEnv* env, jclass clazz, jlong transactionOb
transaction->setShadowRadius(ctrl, shadowRadius); transaction->setShadowRadius(ctrl, shadowRadius);
} }
static void nativeSetTrustedOverlay(JNIEnv* env, jclass clazz, jlong transactionObj,
jlong nativeObject, jboolean isTrustedOverlay) {
auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
transaction->setTrustedOverlay(ctrl, isTrustedOverlay);
}
static void nativeSetFrameRate(JNIEnv* env, jclass clazz, jlong transactionObj, jlong nativeObject, static void nativeSetFrameRate(JNIEnv* env, jclass clazz, jlong transactionObj, jlong nativeObject,
jfloat frameRate, jint compatibility) { jfloat frameRate, jint compatibility) {
auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj); auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
@@ -1666,7 +1674,10 @@ static const JNINativeMethod sSurfaceControlMethods[] = {
(void*)nativeSetGlobalShadowSettings }, (void*)nativeSetGlobalShadowSettings },
{"nativeGetHandle", "(J)J", {"nativeGetHandle", "(J)J",
(void*)nativeGetHandle }, (void*)nativeGetHandle },
{"nativeSetFixedTransformHint", "(JJI)V", (void*)nativeSetFixedTransformHint}, {"nativeSetFixedTransformHint", "(JJI)V",
(void*)nativeSetFixedTransformHint},
{"nativeSetTrustedOverlay", "(JJZ)V",
(void*)nativeSetTrustedOverlay },
}; };
int register_android_view_SurfaceControl(JNIEnv* env) int register_android_view_SurfaceControl(JNIEnv* env)

View File

@@ -716,7 +716,7 @@ class ActivityStack extends Task {
: WINDOWING_MODE_FULLSCREEN; : WINDOWING_MODE_FULLSCREEN;
} }
if (currentMode == WINDOWING_MODE_PINNED) { if (currentMode == WINDOWING_MODE_PINNED) {
mAtmService.getTaskChangeNotificationController().notifyActivityUnpinned(); mRootWindowContainer.notifyActivityPipModeChanged(this, null);
} }
if (likelyResolvedMode == WINDOWING_MODE_PINNED if (likelyResolvedMode == WINDOWING_MODE_PINNED
&& taskDisplayArea.getRootPinnedTask() != null) { && taskDisplayArea.getRootPinnedTask() != null) {

View File

@@ -2212,7 +2212,27 @@ class RootWindowContainer extends WindowContainer<DisplayContent>
ensureActivitiesVisible(null, 0, false /* preserveWindows */); ensureActivitiesVisible(null, 0, false /* preserveWindows */);
resumeFocusedStacksTopActivities(); resumeFocusedStacksTopActivities();
mService.getTaskChangeNotificationController().notifyActivityPinned(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(@NonNull Task task, @Nullable ActivityRecord r) {
final boolean inPip = r != null;
if (inPip) {
mService.getTaskChangeNotificationController().notifyActivityPinned(r);
} else {
mService.getTaskChangeNotificationController().notifyActivityUnpinned();
}
mWindowManager.mPolicy.setPipVisibilityLw(inPip);
mWmService.mTransactionFactory.get()
.setTrustedOverlay(task.getSurfaceControl(), inPip)
.apply();
} }
void executeAppTransitionForAllDisplay() { void executeAppTransitionForAllDisplay() {

View File

@@ -1131,7 +1131,7 @@ class Task extends WindowContainer<WindowContainer> {
&& (newParent == null || !newParent.inPinnedWindowingMode())) { && (newParent == null || !newParent.inPinnedWindowingMode())) {
// Notify if a task from the pinned stack is being removed // Notify if a task from the pinned stack is being removed
// (or moved depending on the mode). // (or moved depending on the mode).
mAtmService.getTaskChangeNotificationController().notifyActivityUnpinned(); mRootWindowContainer.notifyActivityPipModeChanged(this, null);
} }
} }
@@ -4583,5 +4583,4 @@ class Task extends WindowContainer<WindowContainer> {
long getProtoFieldId() { long getProtoFieldId() {
return TASK; return TASK;
} }
} }

View File

@@ -277,4 +277,10 @@ public class StubTransaction extends SurfaceControl.Transaction {
public SurfaceControl.Transaction unsetFixedTransformHint(@NonNull SurfaceControl sc) { public SurfaceControl.Transaction unsetFixedTransformHint(@NonNull SurfaceControl sc) {
return this; return this;
} }
@Override
public SurfaceControl.Transaction setTrustedOverlay(SurfaceControl sc,
boolean isTrustedOverlay) {
return this;
}
} }