Fix StatusBar setting disable flags before setting up

StatusBar#start() was was trying to initialize disable flags before
finishing start(). This triggered
NotificationEntryManager#setDisableNotificationAlerts() before calling
NEM setUpWithPresenter.

Fixed by moving the disable flag setup to a post-init task and making
sure we set up the notification state before doing anything crazy

Fixes: 118357487
Test: verifying that there are no systemui exceptions after rebooting
that look like this:
    java.lang.NullPointerException: Attempt to invoke virtual method
    'void android.database.ContentObserver.onChange(boolean)' on a null
    object reference

Change-Id: Id75a34c8f7414397d7f14de4b4638864262df426
(cherry picked from commit b5d95d977cdb1454fe8fa717c1a89d0435c149e6)
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java
index f56e219..b96a33d 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java
@@ -651,7 +651,9 @@
                 wallpaperChangedFilter, null /* broadcastPermission */, null /* scheduler */);
         mWallpaperChangedReceiver.onReceive(mContext, null);
 
-        mCommandQueue.disable(switches[0], switches[6], false /* animate */);
+        // Set up the initial notification state. This needs to happen before CommandQueue.disable()
+        setUpPresenter();
+
         setSystemUiVisibility(switches[1], switches[7], switches[8], 0xffffffff,
                 fullscreenStackBounds, dockedStackBounds);
         topAppWindowChanged(switches[2] != 0);
@@ -664,17 +666,6 @@
             mCommandQueue.setIcon(iconSlots.get(i), icons.get(i));
         }
 
-        // Set up the initial notification state.
-        mPresenter = new StatusBarNotificationPresenter(mContext, mNotificationPanel,
-                mHeadsUpManager, mStatusBarWindow, mStackScroller, mDozeScrimController,
-                mScrimController, this);
-        mAppOpsListener.setUpWithPresenter(mPresenter);
-        mNotificationListener.setUpWithPresenter(mPresenter);
-        mNotificationShelf.setOnActivatedListener(mPresenter);
-        mRemoteInputManager.getController().addCallback(mStatusBarWindowController);
-
-        // set the initial view visibility
-        Dependency.get(InitController.class).addPostInitTask(this::updateAreThereNotifications);
 
         if (DEBUG) {
             Log.d(TAG, String.format(
@@ -720,6 +711,13 @@
         Dependency.get(ActivityStarterDelegate.class).setActivityStarterImpl(this);
 
         Dependency.get(ConfigurationController.class).addCallback(this);
+
+        // set the initial view visibility
+        Dependency.get(InitController.class).addPostInitTask(this::updateAreThereNotifications);
+        Dependency.get(InitController.class).addPostInitTask(() -> {
+            setUpDisableFlags(switches[0], switches[6]);
+        });
+
     }
 
     // ================================================================================
@@ -981,6 +979,26 @@
         ThreadedRenderer.overrideProperty("ambientRatio", String.valueOf(1.5f));
     }
 
+    protected void setUpPresenter() {
+        // Set up the initial notification state.
+        mPresenter = new StatusBarNotificationPresenter(mContext, mNotificationPanel,
+                mHeadsUpManager, mStatusBarWindow, mStackScroller, mDozeScrimController,
+                mScrimController, this);
+        mAppOpsListener.setUpWithPresenter(mPresenter);
+        mNotificationListener.setUpWithPresenter(mPresenter);
+        mNotificationShelf.setOnActivatedListener(mPresenter);
+        mRemoteInputManager.getController().addCallback(mStatusBarWindowController);
+    }
+
+    /**
+     * Post-init task of {@link #start()}
+     * @param state1 disable1 flags
+     * @param state2 disable2 flags
+     */
+    protected void setUpDisableFlags(int state1, int state2) {
+        mCommandQueue.disable(state1, state2, false /* animate */);
+    }
+
     @Override
     public void addAfterKeyguardGoneRunnable(Runnable runnable) {
         mStatusBarKeyguardViewManager.addAfterKeyguardGoneRunnable(runnable);