commit | ed3541d868fc00f199888995acabd7edccfa2880 | [log] [tgz] |
---|---|---|
author | Sunny Goyal <sunnygoyal@google.com> | Fri Feb 01 14:37:11 2019 -0800 |
committer | Sunny Goyal <sunnygoyal@google.com> | Fri Feb 01 14:40:12 2019 -0800 |
tree | 8a8de7a2aed1faf0330e1b1aefc64fa56551f126 | |
parent | bcb319d6c6ded02eab585633106611df1239e623 [diff] |
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; }