Fixed a crash when changing font scales

The shelf doesn't need to be reinflated but should
reload its properties. Recreating lead to a bunch
of crashes.

Change-Id: I4628e0469f74c1a0201f7b1e6e86d187ad0e548d
Test: Change font size, observe no crash
Fixes: 33189282
(cherry picked from commit 0e8d77e0bad09885d8f1a7017313f86c6f0b3bae)
diff --git a/packages/SystemUI/res/layout/status_bar_notification_shelf.xml b/packages/SystemUI/res/layout/status_bar_notification_shelf.xml
index 088deba..7bfbd3c 100644
--- a/packages/SystemUI/res/layout/status_bar_notification_shelf.xml
+++ b/packages/SystemUI/res/layout/status_bar_notification_shelf.xml
@@ -35,8 +35,8 @@
         android:id="@+id/content"
         android:layout_width="match_parent"
         android:layout_height="match_parent"
-        android:paddingStart="13dp"
-        android:paddingEnd="13dp"
+        android:paddingStart="@dimen/shelf_icon_container_padding"
+        android:paddingEnd="@dimen/shelf_icon_container_padding"
         android:gravity="center_vertical" />
 
     <com.android.systemui.statusbar.notification.FakeShadowView
diff --git a/packages/SystemUI/res/values/dimens.xml b/packages/SystemUI/res/values/dimens.xml
index b889343..1b6b04d 100644
--- a/packages/SystemUI/res/values/dimens.xml
+++ b/packages/SystemUI/res/values/dimens.xml
@@ -84,6 +84,9 @@
     <!-- Height of a the shelf with the notification icons -->
     <dimen name="notification_shelf_height">32dp</dimen>
 
+    <!-- the padding of the shelf icon container -->
+    <dimen name="shelf_icon_container_padding">13dp</dimen>
+
     <!-- The padding of a notification icon on top to the start of the notification. Used for custom
          views where the distance can't be measured -->
     <dimen name="notification_icon_appear_padding">15dp</dimen>
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationShelf.java b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationShelf.java
index 6b9a89ef..add4764 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationShelf.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationShelf.java
@@ -95,6 +95,12 @@
                 R.dimen.status_bar_padding_start);
         mPaddingBetweenElements = getResources().getDimensionPixelSize(
                 R.dimen.notification_divider_height);
+        ViewGroup.LayoutParams layoutParams = getLayoutParams();
+        layoutParams.height = getResources().getDimensionPixelOffset(
+                R.dimen.notification_shelf_height);
+        setLayoutParams(layoutParams);
+        int padding = getResources().getDimensionPixelOffset(R.dimen.shelf_icon_container_padding);
+        mShelfIcons.setPadding(padding, 0, padding, 0);
     }
 
     @Override
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationIconAreaController.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationIconAreaController.java
index 0dbff19..d543f49 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationIconAreaController.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationIconAreaController.java
@@ -8,7 +8,7 @@
 import android.support.annotation.NonNull;
 import android.view.LayoutInflater;
 import android.view.View;
-import android.widget.LinearLayout;
+import android.widget.FrameLayout;
 
 import com.android.internal.util.NotificationColorUtil;
 import com.android.systemui.R;
@@ -73,16 +73,18 @@
 
     public void onDensityOrFontScaleChanged(Context context) {
         reloadDimens(context);
-        final LinearLayout.LayoutParams params = generateIconLayoutParams();
+        final FrameLayout.LayoutParams params = generateIconLayoutParams();
         for (int i = 0; i < mNotificationIcons.getChildCount(); i++) {
             View child = mNotificationIcons.getChildAt(i);
             child.setLayoutParams(params);
+            child = mShelfIcons.getChildAt(i);
+            child.setLayoutParams(params);
         }
     }
 
     @NonNull
-    private LinearLayout.LayoutParams generateIconLayoutParams() {
-        return new LinearLayout.LayoutParams(
+    private FrameLayout.LayoutParams generateIconLayoutParams() {
+        return new FrameLayout.LayoutParams(
                 mIconSize + 2 * mIconHPadding, getHeight());
     }
 
@@ -203,7 +205,7 @@
             hostLayout.removeView(toRemove.get(i));
         }
 
-        final LinearLayout.LayoutParams params = generateIconLayoutParams();
+        final FrameLayout.LayoutParams params = generateIconLayoutParams();
         for (int i = 0; i < toShow.size(); i++) {
             View v = toShow.get(i);
             // The view might still be transiently added if it was just removed and added again
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java
index bb86d6f..bbbdc13 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java
@@ -1074,7 +1074,6 @@
         updateClearAll();
         inflateEmptyShadeView();
         updateEmptyShadeView();
-        inflateShelf();
         mStatusBarKeyguardViewManager.onDensityOrFontScaleChanged();
         mUserInfoController.onDensityOrFontScaleChanged();
         if (mUserSwitcherController != null) {
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/stack/NotificationStackScrollLayout.java b/packages/SystemUI/src/com/android/systemui/statusbar/stack/NotificationStackScrollLayout.java
index 49da793..522e4a9 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/stack/NotificationStackScrollLayout.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/stack/NotificationStackScrollLayout.java
@@ -3961,12 +3961,12 @@
     }
 
     public void setShelf(NotificationShelf shelf) {
-        mShelf = shelf;
         int index = -1;
         if (mShelf != null) {
             index = indexOfChild(mShelf);
             removeView(mShelf);
         }
+        mShelf = shelf;
         addView(mShelf, index);
         mAmbientState.setShelf(shelf);
         mStateAnimator.setShelf(shelf);