Safeguard against no tiles in QS

In PagedTileLayout:
* Make sure that each page displays at least 1 tile (never 0).
* Make sure that there's at least one page (even if it's empty)

In QSTileHost:
* If the new value of sysui_qs_tiles produces no tiles (but it's not set
to empty), set the tile set to the empty default
@string/quick_settings_tiles

Test: adb shell settings put secure sysui_qs_tiles not-a-valid-tile-spec
Test: atest QSTileHostTest
Fixes: 135023694
Fixes: 135677464
Change-Id: I1e5cf4d2688370001ecae87fc0272acecd48af73
diff --git a/packages/SystemUI/src/com/android/systemui/qs/PagedTileLayout.java b/packages/SystemUI/src/com/android/systemui/qs/PagedTileLayout.java
index e22a21a..991d9fa 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/PagedTileLayout.java
+++ b/packages/SystemUI/src/com/android/systemui/qs/PagedTileLayout.java
@@ -244,7 +244,9 @@
 
     private void emptyAndInflateOrRemovePages() {
         final int nTiles = mTiles.size();
-        int numPages = nTiles / mPages.get(0).maxTiles();
+        // We should always have at least one page, even if it's empty.
+        int numPages = Math.max(nTiles / mPages.get(0).maxTiles(), 1);
+
         // Add one more not full page if needed
         numPages += (nTiles % mPages.get(0).maxTiles() == 0 ? 0 : 1);
 
@@ -434,11 +436,14 @@
         }
 
         public boolean isFull() {
-            return mRecords.size() >= mColumns * mRows;
+            return mRecords.size() >= maxTiles();
         }
 
         public int maxTiles() {
-            return mColumns * mRows;
+            // Each page should be able to hold at least one tile. If there's not enough room to
+            // show even 1 or there are no tiles, it probably means we are in the middle of setting
+            // up.
+            return Math.max(mColumns * mRows, 1);
         }
 
         @Override