Fix screenshot behavior with display cutout

Insets need to be set on the decor view, rather than the screenshot
view, in order to be picked up correctly.

Bug: 179050074
Fix: 179050074
Test: manual; taking a screenshot on a phone with a display cutout
results in a black bar at the top of the screen pre-change and
correctly fills the screen post-change

Change-Id: I4784027009359376624699c4ef3e174c047c086d
This commit is contained in:
Miranda Kephart
2021-02-01 14:50:05 -05:00
parent 5d9b76bd83
commit f93d23ac58

View File

@@ -388,12 +388,6 @@ public class ScreenshotController {
}
});
// ignore system bar insets for the purpose of window layout
mScreenshotView.setOnApplyWindowInsetsListener((v, insets) -> v.onApplyWindowInsets(
new WindowInsets.Builder(insets)
.setInsets(WindowInsets.Type.all(), Insets.NONE)
.build()));
// TODO(159460485): Remove this when focus is handled properly in the system
mScreenshotView.setOnTouchListener((v, event) -> {
if (event.getActionMasked() == MotionEvent.ACTION_OUTSIDE) {
@@ -533,9 +527,6 @@ public class ScreenshotController {
attachWindow();
if (DEBUG_WINDOW) {
Log.d(TAG, "setContentView: " + mScreenshotView);
}
mScreenshotView.getViewTreeObserver().addOnPreDrawListener(
new ViewTreeObserver.OnPreDrawListener() {
@Override
@@ -549,7 +540,13 @@ public class ScreenshotController {
}
});
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);
cancelTimeout(); // restarted after animation
}