From 1ae56219578efb02eaf4a021e06f473316c5a8bc Mon Sep 17 00:00:00 2001 From: Alex Stetson Date: Tue, 15 Feb 2022 15:05:14 -0800 Subject: [PATCH] Ensure controller is attached before applying state On devices that don't use the default SystemUI status bar, it's possible that the StatusBarWindowController may not be attached. For this use case, the current state should not be applied until it's attached, as applying the state prior to this may cause NPE. Bug: 218582429 Test: manual (gcar_emu_x86 && sdk_gphone_x86) Change-Id: Ibe3c30ec8041dd5404c8a0def9a2a894362bf860 --- .../statusbar/window/StatusBarWindowController.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/window/StatusBarWindowController.java b/packages/SystemUI/src/com/android/systemui/statusbar/window/StatusBarWindowController.java index 6f587fde44362..c53d5107afcc2 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/window/StatusBarWindowController.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/window/StatusBarWindowController.java @@ -68,6 +68,7 @@ public class StatusBarWindowController { private final StatusBarContentInsetsProvider mContentInsetsProvider; private int mBarHeight = -1; private final State mCurrentState = new State(); + private boolean mIsAttached; private final ViewGroup mStatusBarWindowView; // The container in which we should run launch animations started from the status bar and @@ -136,6 +137,8 @@ public class StatusBarWindowController { mContentInsetsProvider.addCallback(this::calculateStatusBarLocationsForAllRotations); calculateStatusBarLocationsForAllRotations(); + mIsAttached = true; + apply(mCurrentState); } /** Adds the given view to the status bar window view. */ @@ -282,6 +285,9 @@ public class StatusBarWindowController { } private void apply(State state) { + if (!mIsAttached) { + return; + } applyForceStatusBarVisibleFlag(state); applyHeight(state); if (mLp != null && mLp.copyFrom(mLpChanged) != 0) {