[go: nahoru, domu]

Fixing crash in getToggles when slice is empty

Bug: 123731421
Test: SliceMetadataTest passed
Change-Id: I53111e82204471130888a1f765ead3c782bbfe3b
diff --git a/slices/view/src/androidTest/java/androidx/slice/SliceMetadataTest.java b/slices/view/src/androidTest/java/androidx/slice/SliceMetadataTest.java
index 15e9b23..c31eff0f 100644
--- a/slices/view/src/androidTest/java/androidx/slice/SliceMetadataTest.java
+++ b/slices/view/src/androidTest/java/androidx/slice/SliceMetadataTest.java
@@ -485,6 +485,16 @@
     }
 
     @Test
+    public void testGetToggleEmptySlice() {
+        Uri uri = Uri.parse("content://pkg/slice");
+
+        ListBuilder lb = new ListBuilder(mContext, uri, ListBuilder.INFINITY);
+        Slice rowSlice = lb.build();
+        SliceMetadata rowInfo = SliceMetadata.from(mContext, rowSlice);
+        assertTrue(rowInfo.getToggles().isEmpty());
+    }
+
+    @Test
     public void testSendToggleAction() {
         final AtomicBoolean toggleState = new AtomicBoolean(true);
         final CountDownLatch latch = new CountDownLatch(3);
diff --git a/slices/view/src/main/java/androidx/slice/SliceMetadata.java b/slices/view/src/main/java/androidx/slice/SliceMetadata.java
index b407c45..10234ed 100644
--- a/slices/view/src/main/java/androidx/slice/SliceMetadata.java
+++ b/slices/view/src/main/java/androidx/slice/SliceMetadata.java
@@ -241,8 +241,8 @@
                     toggles.add(action);
                 }
             }
-        } else {
-            toggles = mHeaderContent.getToggleItems();
+        } else if (mHeaderContent != null) {
+            toggles.addAll(mHeaderContent.getToggleItems());
         }
         return toggles;
     }