Commit e448e976 authored by Evan Stade's avatar Evan Stade Committed by Commit Bot

Fix crash in DisplayCutoutController

Bug: 1107361
Change-Id: I6e5413b8c717690d04a078001ed93b61a64447b0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2307691Reviewed-by: default avatarBecca Hughes <beccahughes@chromium.org>
Commit-Queue: Evan Stade <estade@chromium.org>
Cr-Commit-Position: refs/heads/master@{#790038}
parent 1977207d
...@@ -204,7 +204,7 @@ public class DisplayCutoutController implements InsetObserverView.WindowInsetObs ...@@ -204,7 +204,7 @@ public class DisplayCutoutController implements InsetObserverView.WindowInsetObs
@VisibleForTesting @VisibleForTesting
protected LayoutParams getWindowAttributes() { protected LayoutParams getWindowAttributes() {
return mWindow.getAttributes(); return mWindow == null ? null : mWindow.getAttributes();
} }
@VisibleForTesting @VisibleForTesting
...@@ -218,6 +218,8 @@ public class DisplayCutoutController implements InsetObserverView.WindowInsetObs ...@@ -218,6 +218,8 @@ public class DisplayCutoutController implements InsetObserverView.WindowInsetObs
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.P) return; if (Build.VERSION.SDK_INT < Build.VERSION_CODES.P) return;
LayoutParams attributes = getWindowAttributes(); LayoutParams attributes = getWindowAttributes();
if (attributes == null) return;
attributes.layoutInDisplayCutoutMode = getDisplayCutoutMode(); attributes.layoutInDisplayCutoutMode = getDisplayCutoutMode();
setWindowAttributes(attributes); setWindowAttributes(attributes);
} }
......
...@@ -197,6 +197,18 @@ public class DisplayCutoutControllerTest { ...@@ -197,6 +197,18 @@ public class DisplayCutoutControllerTest {
verify(mWindow).getAttributes(); verify(mWindow).getAttributes();
} }
@Test
@SmallTest
public void testLayout_NoWindow() {
// Verify there's no crash when the tab's interactability changes after activity detachment.
verify(mTab).addObserver(mTabObserverCaptor.capture());
reset(mTab);
mTabObserverCaptor.getValue().onActivityAttachmentChanged(mTab, null);
mTabObserverCaptor.getValue().onInteractabilityChanged(mTab, false);
verify(mWindow, never()).getAttributes();
}
@Test @Test
@SmallTest @SmallTest
public void testLayoutOnShown() { public void testLayoutOnShown() {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment