Fix crash on power menu rotation, and re-render power menu onUiModeChanged.

Test: Automated tests pass. Unplug phone, turn on battery saver, open a rotateable app (like Chrome), hold power to open Global Actions. Rotate the phone -- shouldn't crash. Plug the phone in, battery saver should disable, and the power menu should re-render with a light theme.

Fixes: 129108888
Fixes: 129555054

Change-Id: If2646d5332b18ac32796ba44a86d3cc2aae18982
diff --git a/packages/SystemUI/src/com/android/systemui/globalactions/GlobalActionsDialog.java b/packages/SystemUI/src/com/android/systemui/globalactions/GlobalActionsDialog.java
index f07887e..dcacd0f 100644
--- a/packages/SystemUI/src/com/android/systemui/globalactions/GlobalActionsDialog.java
+++ b/packages/SystemUI/src/com/android/systemui/globalactions/GlobalActionsDialog.java
@@ -439,6 +439,9 @@
     @Override
     public void onUiModeChanged() {
         mContext.getTheme().applyStyle(mContext.getThemeResId(), true);
+        if (mDialog.isShowing()) {
+            mDialog.refreshDialog();
+        }
     }
 
     public void destroy() {
@@ -1577,7 +1580,9 @@
 
             boolean panelEnabled = initializePanel();
             if (!panelEnabled) {
-                mBackgroundDrawable = new GradientDrawable(mContext);
+                if (mBackgroundDrawable == null) {
+                    mBackgroundDrawable = new GradientDrawable(mContext);
+                }
                 mScrimAlpha = ScrimController.GRADIENT_SCRIM_ALPHA;
             } else {
                 mBackgroundDrawable = mContext.getDrawable(
@@ -1720,10 +1725,14 @@
             mKeyguardShowing = keyguardShowing;
         }
 
+        public void refreshDialog() {
+            initializeLayout();
+            mGlobalActionsLayout.updateList();
+        }
+
         public void onRotate(int from, int to) {
             if (mShowing && isGridEnabled(mContext)) {
-                initializeLayout();
-                mGlobalActionsLayout.updateList();
+                refreshDialog();
             }
         }
     }