Update IME SECURE flag if Window updates SECURE flag

If the IME target is set before the IME target updates its SECURE flag,
the IME  may not get the SECURE flag. This is because we only update the
IME flag when the new target is being set.

This change ensures we also update the IME secure flag if needed when a
Window updates its SECURE flag since it could already be the target.

Fixes: 215005011
Test: testImeSecureFlagGetUpdatedAfterImeInputTarget
Test: Add SECURE flag after IME target is set.
Change-Id: Ie59042c8efa2527208e4020107b7aa15c885755f
This commit is contained in:
chaviw
2022-04-05 11:59:00 -05:00
parent d7b7a5a2e9
commit 90d0e50b6f
4 changed files with 31 additions and 4 deletions

View File

@@ -4047,12 +4047,20 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
@VisibleForTesting
void setImeInputTarget(InputTarget target) {
mImeInputTarget = target;
boolean canScreenshot = mImeInputTarget == null || mImeInputTarget.canScreenshotIme();
if (mImeWindowsContainer.setCanScreenshot(canScreenshot)) {
if (refreshImeSecureFlag(getPendingTransaction())) {
mWmService.requestTraversal();
}
}
/**
* Re-check the IME target's SECURE flag since it's possible to have changed after the target
* was set.
*/
boolean refreshImeSecureFlag(Transaction t) {
boolean canScreenshot = mImeInputTarget == null || mImeInputTarget.canScreenshotIme();
return mImeWindowsContainer.setCanScreenshot(t, canScreenshot);
}
@VisibleForTesting
void setImeControlTarget(InsetsControlTarget target) {
mImeControlTarget = target;

View File

@@ -3782,11 +3782,11 @@ class WindowContainer<E extends WindowContainer> extends ConfigurationContainer<
return INVALID_WINDOW_TYPE;
}
boolean setCanScreenshot(boolean canScreenshot) {
boolean setCanScreenshot(Transaction t, boolean canScreenshot) {
if (mSurfaceControl == null) {
return false;
}
getPendingTransaction().setSecure(mSurfaceControl, !canScreenshot);
t.setSecure(mSurfaceControl, !canScreenshot);
return true;
}

View File

@@ -217,6 +217,11 @@ class WindowSurfaceController {
mService.openSurfaceTransaction();
try {
getGlobalTransaction().setSecure(mSurfaceControl, isSecure);
final DisplayContent dc = mAnimator.mWin.mDisplayContent;
if (dc != null) {
dc.refreshImeSecureFlag(getGlobalTransaction());
}
} finally {
mService.closeSurfaceTransaction("setSecure");
if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION setSecureLocked");

View File

@@ -1201,6 +1201,20 @@ public class DisplayContentTests extends WindowTestsBase {
dc.computeImeControlTarget());
}
@UseTestDisplay(addWindows = W_INPUT_METHOD)
@Test
public void testImeSecureFlagGetUpdatedAfterImeInputTarget() {
// Verify IME window can get up-to-date secure flag update when the IME input target
// set before setCanScreenshot called.
final WindowState app = createWindow(null, TYPE_APPLICATION, "app");
SurfaceControl.Transaction t = mDisplayContent.mInputMethodWindow.getPendingTransaction();
spyOn(t);
mDisplayContent.setImeInputTarget(app);
mDisplayContent.mInputMethodWindow.setCanScreenshot(t, false /* canScreenshot */);
verify(t).setSecure(eq(mDisplayContent.mInputMethodWindow.mSurfaceControl), eq(true));
}
@UseTestDisplay(addWindows = W_ACTIVITY)
@Test
public void testComputeImeControlTarget_notMatchParentBounds() throws Exception {