Fix screenshot back key recognition

We were only requesting focus once, on screenshot view inflation,
and the focus got reset when window.setContentView was called,
causing us to no longer receive key events. This change moves the
setContentView call to only happen once, and requests focus
explicitly for each screenshot.

Test: manual -- took two screenshots in succession and verified that
back gesture worked to dismiss screenshot
Bug: 259490332
Fix: 259490332

Change-Id: Ia0dd38b32f7986088b87f3838bcb05dbbb02238d
This commit is contained in:
Miranda Kephart
2022-12-01 15:06:22 -05:00
parent 45fdabd5f9
commit 0b8ada648e

View File

@@ -513,6 +513,10 @@ public class ScreenshotController {
Log.d(TAG, "adding OnComputeInternalInsetsListener");
}
mScreenshotView.getViewTreeObserver().addOnComputeInternalInsetsListener(mScreenshotView);
if (DEBUG_WINDOW) {
Log.d(TAG, "setContentView: " + mScreenshotView);
}
setContentView(mScreenshotView);
}
/**
@@ -587,6 +591,7 @@ public class ScreenshotController {
// The window is focusable by default
setWindowFocusable(true);
mScreenshotView.requestFocus();
// Wait until this window is attached to request because it is
// the reference used to locate the target window (below).
@@ -645,10 +650,7 @@ public class ScreenshotController {
mContext.getPackageManager().getUserBadgeForDensity(owner, 0));
}
mScreenshotView.setScreenshot(mScreenBitmap, screenInsets);
if (DEBUG_WINDOW) {
Log.d(TAG, "setContentView: " + mScreenshotView);
}
setContentView(mScreenshotView);
// ignore system bar insets for the purpose of window layout
mWindow.getDecorView().setOnApplyWindowInsetsListener(
(v, insets) -> WindowInsets.CONSUMED);