InsetsAnimation: Fix crash if disabling decor fitting before view is attached

Bug: 149341851
Test: atest WindowTest
Change-Id: I6a688c493e79c0e95037dcc690c92fb33049dc95
This commit is contained in:
Adrian Roos
2020-02-11 16:00:13 -08:00
parent 43361f713d
commit ec8ac6ba2e

View File

@@ -1821,15 +1821,20 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback {
}
private ViewRootImpl getViewRootImpl() {
if (mDecor != null) {
ViewRootImpl viewRootImpl = mDecor.getViewRootImpl();
if (viewRootImpl != null) {
return viewRootImpl;
}
ViewRootImpl viewRootImpl = getViewRootImplOrNull();
if (viewRootImpl != null) {
return viewRootImpl;
}
throw new IllegalStateException("view not added");
}
private ViewRootImpl getViewRootImplOrNull() {
if (mDecor == null) {
return null;
}
return mDecor.getViewRootImpl();
}
/**
* Request that key events come to this activity. Use this if your activity
* has no views with focus, but the activity still wants a chance to process
@@ -3900,7 +3905,7 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback {
@Override
public void setDecorFitsSystemWindows(boolean decorFitsSystemWindows) {
ViewRootImpl impl = getViewRootImpl();
ViewRootImpl impl = getViewRootImplOrNull();
OnContentApplyWindowInsetsListener listener = decorFitsSystemWindows
? createDefaultContentWindowInsetsListener()
: null;