diff options
6 files changed, 44 insertions, 49 deletions
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/Bubble.java b/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/Bubble.java index 09dc68a4ccea..2534498bdcc1 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/Bubble.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/Bubble.java @@ -21,6 +21,7 @@ import static android.os.AsyncTask.Status.FINISHED; import static com.android.internal.annotations.VisibleForTesting.Visibility.PRIVATE; import android.annotation.DimenRes; +import android.annotation.Hide; import android.annotation.NonNull; import android.annotation.Nullable; import android.app.Notification; @@ -180,7 +181,7 @@ public class Bubble implements BubbleViewProvider { @VisibleForTesting(visibility = PRIVATE) public Bubble(@NonNull final String key, @NonNull final ShortcutInfo shortcutInfo, final int desiredHeight, final int desiredHeightResId, @Nullable final String title, - int taskId, @Nullable final String locus, Executor mainExecutor, + int taskId, @Nullable final String locus, boolean isClearable, Executor mainExecutor, final Bubbles.BubbleMetadataFlagListener listener) { Objects.requireNonNull(key); Objects.requireNonNull(shortcutInfo); @@ -189,6 +190,7 @@ public class Bubble implements BubbleViewProvider { mKey = key; mGroupKey = null; mLocusId = locus != null ? new LocusId(locus) : null; + mIsClearable = isClearable; mFlags = 0; mUser = shortcutInfo.getUserHandle(); mPackageName = shortcutInfo.getPackage(); @@ -245,6 +247,11 @@ public class Bubble implements BubbleViewProvider { return mKey; } + @Hide + public boolean isClearable() { + return mIsClearable; + } + /** * @see StatusBarNotification#getGroupKey() * @return the group key for this bubble, if one exists. diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubbleDataRepository.kt b/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubbleDataRepository.kt index 3a5961462c87..e3aefa5bd8aa 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubbleDataRepository.kt +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubbleDataRepository.kt @@ -109,7 +109,8 @@ internal class BubbleDataRepository( b.rawDesiredHeightResId, b.title, b.taskId, - b.locusId?.id + b.locusId?.id, + b.isClearable ) } } @@ -205,6 +206,7 @@ internal class BubbleDataRepository( entity.title, entity.taskId, entity.locus, + entity.isClearable, mainExecutor, bubbleMetadataFlagListener ) diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/storage/BubbleEntity.kt b/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/storage/BubbleEntity.kt index 186b9b1efa9a..f3abc271dad4 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/storage/BubbleEntity.kt +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/storage/BubbleEntity.kt @@ -27,5 +27,6 @@ data class BubbleEntity( @DimenRes val desiredHeightResId: Int, val title: String? = null, val taskId: Int, - val locus: String? = null + val locus: String? = null, + val isClearable: Boolean = false ) diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/storage/BubbleXmlHelper.kt b/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/storage/BubbleXmlHelper.kt index f4fa1835b7a5..14c053c58f1f 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/storage/BubbleXmlHelper.kt +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/storage/BubbleXmlHelper.kt @@ -44,6 +44,9 @@ private const val ATTR_TITLE = "t" private const val ATTR_TASK_ID = "tid" private const val ATTR_LOCUS = "l" +// TODO rename it to dismissable to follow NotificationEntry namings +private const val ATTR_CLEARABLE = "d" + /** * Writes the bubbles in xml format into given output stream. */ @@ -84,6 +87,7 @@ private fun writeXmlEntry(serializer: XmlSerializer, bubble: BubbleEntity) { bubble.title?.let { serializer.attribute(null, ATTR_TITLE, it) } serializer.attribute(null, ATTR_TASK_ID, bubble.taskId.toString()) bubble.locus?.let { serializer.attribute(null, ATTR_LOCUS, it) } + serializer.attribute(null, ATTR_CLEARABLE, bubble.isClearable.toString()) serializer.endTag(null, TAG_BUBBLE) } catch (e: IOException) { throw RuntimeException(e) @@ -142,7 +146,8 @@ private fun readXmlEntry(parser: XmlPullParser): BubbleEntity? { parser.getAttributeWithName(ATTR_DESIRED_HEIGHT_RES_ID)?.toInt() ?: return null, parser.getAttributeWithName(ATTR_TITLE), parser.getAttributeWithName(ATTR_TASK_ID)?.toInt() ?: INVALID_TASK_ID, - parser.getAttributeWithName(ATTR_LOCUS) + parser.getAttributeWithName(ATTR_LOCUS), + parser.getAttributeWithName(ATTR_CLEARABLE)?.toBoolean() ?: false ) } diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/bubbles/storage/BubblePersistentRepositoryTest.kt b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/bubbles/storage/BubblePersistentRepositoryTest.kt index 1636c5f73133..0a31338a7c81 100644 --- a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/bubbles/storage/BubblePersistentRepositoryTest.kt +++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/bubbles/storage/BubblePersistentRepositoryTest.kt @@ -21,7 +21,6 @@ import android.testing.AndroidTestingRunner import android.util.SparseArray import androidx.test.filters.SmallTest import com.android.wm.shell.ShellTestCase -import com.android.wm.shell.bubbles.storage.BubbleXmlHelperTest.Companion.sparseArraysEqual import junit.framework.Assert.assertEquals import junit.framework.Assert.assertNotNull import junit.framework.Assert.assertTrue @@ -36,7 +35,8 @@ class BubblePersistentRepositoryTest : ShellTestCase() { // user, package, shortcut, notification key, height, res-height, title, taskId, locusId private val user0Bubbles = listOf( - BubbleEntity(0, "com.example.messenger", "shortcut-1", "0k1", 120, 0, null, 1, null), + BubbleEntity(0, "com.example.messenger", "shortcut-1", "0k1", 120, 0, null, 1, null, + true), BubbleEntity(10, "com.example.chat", "alice and bob", "0k2", 0, 16537428, "title", 2, null), BubbleEntity(0, "com.example.messenger", "shortcut-2", "0k3", 120, 0, null, @@ -44,7 +44,8 @@ class BubblePersistentRepositoryTest : ShellTestCase() { ) private val user1Bubbles = listOf( - BubbleEntity(1, "com.example.messenger", "shortcut-1", "1k1", 120, 0, null, 3, null), + BubbleEntity(1, "com.example.messenger", "shortcut-1", "1k1", 120, 0, null, 3, null, + true), BubbleEntity(12, "com.example.chat", "alice and bob", "1k2", 0, 16537428, "title", 4, null), BubbleEntity(1, "com.example.messenger", "shortcut-2", "1k3", 120, 0, null, @@ -76,6 +77,6 @@ class BubblePersistentRepositoryTest : ShellTestCase() { assertEquals(actual.size(), 0) repository.persistsToDisk(bubbles) - assertTrue(sparseArraysEqual(bubbles, repository.readFromDisk())) + assertTrue(bubbles.contentEquals(repository.readFromDisk())) } } diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/bubbles/storage/BubbleXmlHelperTest.kt b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/bubbles/storage/BubbleXmlHelperTest.kt index 4ab9f87dbbf6..c02e2d177029 100644 --- a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/bubbles/storage/BubbleXmlHelperTest.kt +++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/bubbles/storage/BubbleXmlHelperTest.kt @@ -34,7 +34,8 @@ import java.io.ByteArrayOutputStream class BubbleXmlHelperTest : ShellTestCase() { private val user0Bubbles = listOf( - BubbleEntity(0, "com.example.messenger", "shortcut-1", "0k1", 120, 0, null, 1), + BubbleEntity(0, "com.example.messenger", "shortcut-1", "0k1", 120, 0, null, 1, + isClearable = true), BubbleEntity(10, "com.example.chat", "alice and bob", "0k2", 0, 16537428, "title", 2, null), BubbleEntity(0, "com.example.messenger", "shortcut-2", "0k3", 120, 0, null, @@ -42,7 +43,8 @@ class BubbleXmlHelperTest : ShellTestCase() { ) private val user1Bubbles = listOf( - BubbleEntity(1, "com.example.messenger", "shortcut-1", "1k1", 120, 0, null, 3), + BubbleEntity(1, "com.example.messenger", "shortcut-1", "1k1", 120, 0, null, 3, + isClearable = true), BubbleEntity(12, "com.example.chat", "alice and bob", "1k2", 0, 16537428, "title", 4, null), BubbleEntity(1, "com.example.messenger", "shortcut-2", "1k3", 120, 0, null, @@ -51,28 +53,6 @@ class BubbleXmlHelperTest : ShellTestCase() { private val bubbles = SparseArray<List<BubbleEntity>>() - // Checks that the contents of the two sparse arrays are the same. - companion object { - fun sparseArraysEqual( - one: SparseArray<List<BubbleEntity>>?, - two: SparseArray<List<BubbleEntity>>? - ): Boolean { - if (one == null && two == null) return true - if ((one == null) != (two == null)) return false - if (one!!.size() != two!!.size()) return false - for (i in 0 until one.size()) { - val k1 = one.keyAt(i) - val v1 = one.valueAt(i) - val k2 = two.keyAt(i) - val v2 = two.valueAt(i) - if (k1 != k2 && v1 != v2) { - return false - } - } - return true - } - } - @Before fun setup() { bubbles.put(0, user0Bubbles) @@ -83,14 +63,14 @@ class BubbleXmlHelperTest : ShellTestCase() { fun testWriteXml() { val expectedEntries = """ <bs uid="0"> -<bb uid="0" pkg="com.example.messenger" sid="shortcut-1" key="0k1" h="120" hid="0" tid="1" /> -<bb uid="10" pkg="com.example.chat" sid="alice and bob" key="0k2" h="0" hid="16537428" t="title" tid="2" /> -<bb uid="0" pkg="com.example.messenger" sid="shortcut-2" key="0k3" h="120" hid="0" tid="-1" l="l3" /> +<bb uid="0" pkg="com.example.messenger" sid="shortcut-1" key="0k1" h="120" hid="0" tid="1" d="true" /> +<bb uid="10" pkg="com.example.chat" sid="alice and bob" key="0k2" h="0" hid="16537428" t="title" tid="2" d="false" /> +<bb uid="0" pkg="com.example.messenger" sid="shortcut-2" key="0k3" h="120" hid="0" tid="-1" l="l3" d="false" /> </bs> <bs uid="1"> -<bb uid="1" pkg="com.example.messenger" sid="shortcut-1" key="1k1" h="120" hid="0" tid="3" /> -<bb uid="12" pkg="com.example.chat" sid="alice and bob" key="1k2" h="0" hid="16537428" t="title" tid="4" /> -<bb uid="1" pkg="com.example.messenger" sid="shortcut-2" key="1k3" h="120" hid="0" tid="-1" l="l4" /> +<bb uid="1" pkg="com.example.messenger" sid="shortcut-1" key="1k1" h="120" hid="0" tid="3" d="true" /> +<bb uid="12" pkg="com.example.chat" sid="alice and bob" key="1k2" h="0" hid="16537428" t="title" tid="4" d="false" /> +<bb uid="1" pkg="com.example.messenger" sid="shortcut-2" key="1k3" h="120" hid="0" tid="-1" l="l4" d="false" /> </bs> """.trimIndent() ByteArrayOutputStream().use { @@ -107,19 +87,19 @@ class BubbleXmlHelperTest : ShellTestCase() { <?xml version='1.0' encoding='utf-8' standalone='yes' ?> <bs v="2"> <bs uid="0"> -<bb uid="0" pkg="com.example.messenger" sid="shortcut-1" key="0k1" h="120" hid="0" tid="1" /> -<bb uid="10" pkg="com.example.chat" sid="alice and bob" key="0k2" h="0" hid="16537428" t="title" tid="2" /> -<bb uid="0" pkg="com.example.messenger" sid="shortcut-2" key="0k3" h="120" hid="0" tid="-1" l="l3" /> +<bb uid="0" pkg="com.example.messenger" sid="shortcut-1" key="0k1" h="120" hid="0" tid="1" d="true" /> +<bb uid="10" pkg="com.example.chat" sid="alice and bob" key="0k2" h="0" hid="16537428" t="title" tid="2" d="false" /> +<bb uid="0" pkg="com.example.messenger" sid="shortcut-2" key="0k3" h="120" hid="0" tid="-1" l="l3" d="false" /> </bs> <bs uid="1"> -<bb uid="1" pkg="com.example.messenger" sid="shortcut-1" key="1k1" h="120" hid="0" tid="3" /> -<bb uid="12" pkg="com.example.chat" sid="alice and bob" key="1k2" h="0" hid="16537428" t="title" tid="4" /> -<bb uid="1" pkg="com.example.messenger" sid="shortcut-2" key="1k3" h="120" hid="0" tid="-1" l="l4" /> +<bb uid="1" pkg="com.example.messenger" sid="shortcut-1" key="1k1" h="120" hid="0" tid="3" d="true" /> +<bb uid="12" pkg="com.example.chat" sid="alice and bob" key="1k2" h="0" hid="16537428" t="title" tid="4" d="false" /> +<bb uid="1" pkg="com.example.messenger" sid="shortcut-2" key="1k3" h="120" hid="0" tid="-1" l="l4" d="false" /> </bs> </bs> """.trimIndent() val actual = readXml(ByteArrayInputStream(src.toByteArray(Charsets.UTF_8))) - assertTrue("failed parsing bubbles from xml\n$src", sparseArraysEqual(bubbles, actual)) + assertTrue("failed parsing bubbles from xml\n$src", bubbles.contentEquals(actual)) } // V0 -> V1 happened prior to release / during dogfood so nothing is saved @@ -161,8 +141,7 @@ class BubbleXmlHelperTest : ShellTestCase() { </bs> """.trimIndent() val actual = readXml(ByteArrayInputStream(src.toByteArray(Charsets.UTF_8))) - assertTrue("failed parsing bubbles from xml\n$src", - sparseArraysEqual(expectedBubbles, actual)) + assertTrue("failed parsing bubbles from xml\n$src", expectedBubbles.contentEquals(actual)) } /** @@ -187,7 +166,7 @@ class BubbleXmlHelperTest : ShellTestCase() { """.trimIndent() val actual = readXml(ByteArrayInputStream(src.toByteArray(Charsets.UTF_8))) assertTrue("failed parsing bubbles from xml\n$src", - sparseArraysEqual(expectedBubbles, actual)) + expectedBubbles.contentEquals(actual)) } @Test @@ -210,6 +189,6 @@ class BubbleXmlHelperTest : ShellTestCase() { ) val actual = readXml(ByteArrayInputStream(src.toByteArray(Charsets.UTF_8))) assertTrue("failed parsing bubbles from xml\n$src", - sparseArraysEqual(expectedBubbles, actual)) + expectedBubbles.contentEquals(actual)) } }
\ No newline at end of file |