Add taskId to bubble xml
* Save the bubble taskId to XML * Doesn't increase version # of XML, just sets the taskId as INVALID_TASK_ID if it's the old XML without taskId Test: atest BubbleXmlHelperTest Bug: 179676966 Change-Id: Ied04458fb4715a3de32784378568495128b54163
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
|
||||
package com.android.wm.shell.bubbles.storage
|
||||
|
||||
import android.app.ActivityTaskManager.INVALID_TASK_ID
|
||||
import android.testing.AndroidTestingRunner
|
||||
import androidx.test.filters.SmallTest
|
||||
import com.android.wm.shell.ShellTestCase
|
||||
@@ -31,9 +32,10 @@ import org.junit.runner.RunWith
|
||||
class BubblePersistentRepositoryTest : ShellTestCase() {
|
||||
|
||||
private val bubbles = listOf(
|
||||
BubbleEntity(0, "com.example.messenger", "shortcut-1", "key-1", 120, 0),
|
||||
BubbleEntity(10, "com.example.chat", "alice and bob", "key-2", 0, 16537428, "title"),
|
||||
BubbleEntity(0, "com.example.messenger", "shortcut-2", "key-3", 120, 0)
|
||||
BubbleEntity(0, "com.example.messenger", "shortcut-1", "key-1", 120, 0, null, 1),
|
||||
BubbleEntity(10, "com.example.chat", "alice and bob", "key-2", 0, 16537428, "title", 2),
|
||||
BubbleEntity(0, "com.example.messenger", "shortcut-2", "key-3", 120, 0, null,
|
||||
INVALID_TASK_ID)
|
||||
)
|
||||
private lateinit var repository: BubblePersistentRepository
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package com.android.wm.shell.bubbles.storage
|
||||
|
||||
import android.app.ActivityTaskManager.INVALID_TASK_ID
|
||||
import android.content.pm.LauncherApps
|
||||
import android.os.UserHandle
|
||||
import android.testing.AndroidTestingRunner
|
||||
@@ -37,10 +38,12 @@ class BubbleVolatileRepositoryTest : ShellTestCase() {
|
||||
private val user0 = UserHandle.of(0)
|
||||
private val user10 = UserHandle.of(10)
|
||||
|
||||
private val bubble1 = BubbleEntity(0, "com.example.messenger", "shortcut-1", "key-1", 120, 0)
|
||||
private val bubble1 = BubbleEntity(0, "com.example.messenger", "shortcut-1", "key-1", 120, 0,
|
||||
null, 1)
|
||||
private val bubble2 = BubbleEntity(10, "com.example.chat", "alice and bob",
|
||||
"key-2", 0, 16537428, "title")
|
||||
private val bubble3 = BubbleEntity(0, "com.example.messenger", "shortcut-2", "key-3", 120, 0)
|
||||
"key-2", 0, 16537428, "title", 2)
|
||||
private val bubble3 = BubbleEntity(0, "com.example.messenger", "shortcut-2", "key-3", 120, 0,
|
||||
null, INVALID_TASK_ID)
|
||||
|
||||
private val bubbles = listOf(bubble1, bubble2, bubble3)
|
||||
|
||||
@@ -105,13 +108,13 @@ class BubbleVolatileRepositoryTest : ShellTestCase() {
|
||||
|
||||
@Test
|
||||
fun testAddBubbleMatchesByKey() {
|
||||
val bubble = BubbleEntity(0, "com.example.pkg", "shortcut-id", "key", 120, 0, "title")
|
||||
val bubble = BubbleEntity(0, "com.example.pkg", "shortcut-id", "key", 120, 0, "title", 1)
|
||||
repository.addBubbles(listOf(bubble))
|
||||
assertEquals(bubble, repository.bubbles.get(0))
|
||||
|
||||
// Same key as first bubble but different entry
|
||||
val bubbleModified = BubbleEntity(0, "com.example.pkg", "shortcut-id", "key", 120, 0,
|
||||
"different title")
|
||||
"different title", 2)
|
||||
repository.addBubbles(listOf(bubbleModified))
|
||||
assertEquals(bubbleModified, repository.bubbles.get(0))
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package com.android.wm.shell.bubbles.storage
|
||||
|
||||
import android.app.ActivityTaskManager.INVALID_TASK_ID
|
||||
import android.testing.AndroidTestingRunner
|
||||
import androidx.test.filters.SmallTest
|
||||
import com.android.wm.shell.ShellTestCase
|
||||
@@ -31,17 +32,18 @@ import java.io.ByteArrayOutputStream
|
||||
class BubbleXmlHelperTest : ShellTestCase() {
|
||||
|
||||
private val bubbles = listOf(
|
||||
BubbleEntity(0, "com.example.messenger", "shortcut-1", "k1", 120, 0),
|
||||
BubbleEntity(10, "com.example.chat", "alice and bob", "k2", 0, 16537428, "title"),
|
||||
BubbleEntity(0, "com.example.messenger", "shortcut-2", "k3", 120, 0)
|
||||
BubbleEntity(0, "com.example.messenger", "shortcut-1", "k1", 120, 0, null, 1),
|
||||
BubbleEntity(10, "com.example.chat", "alice and bob", "k2", 0, 16537428, "title", 2),
|
||||
BubbleEntity(0, "com.example.messenger", "shortcut-2", "k3", 120, 0, null,
|
||||
INVALID_TASK_ID)
|
||||
)
|
||||
|
||||
@Test
|
||||
fun testWriteXml() {
|
||||
val expectedEntries = """
|
||||
<bb uid="0" pkg="com.example.messenger" sid="shortcut-1" key="k1" h="120" hid="0" />
|
||||
<bb uid="10" pkg="com.example.chat" sid="alice and bob" key="k2" h="0" hid="16537428" t="title" />
|
||||
<bb uid="0" pkg="com.example.messenger" sid="shortcut-2" key="k3" h="120" hid="0" />
|
||||
<bb uid="0" pkg="com.example.messenger" sid="shortcut-1" key="k1" h="120" hid="0" tid="1" />
|
||||
<bb uid="10" pkg="com.example.chat" sid="alice and bob" key="k2" h="0" hid="16537428" t="title" tid="2" />
|
||||
<bb uid="0" pkg="com.example.messenger" sid="shortcut-2" key="k3" h="120" hid="0" tid="-1" />
|
||||
""".trimIndent()
|
||||
ByteArrayOutputStream().use {
|
||||
writeXml(it, bubbles)
|
||||
@@ -56,9 +58,9 @@ class BubbleXmlHelperTest : ShellTestCase() {
|
||||
val src = """
|
||||
<?xml version='1.0' encoding='utf-8' standalone='yes' ?>
|
||||
<bs v="1">
|
||||
<bb uid="0" pkg="com.example.messenger" sid="shortcut-1" key="k1" h="120" hid="0" />
|
||||
<bb uid="10" pkg="com.example.chat" sid="alice and bob" key="k2" h="0" hid="16537428" t="title" />
|
||||
<bb uid="0" pkg="com.example.messenger" sid="shortcut-2" key="k3" h="120" hid="0" />
|
||||
<bb uid="0" pkg="com.example.messenger" sid="shortcut-1" key="k1" h="120" hid="0" tid="1" />
|
||||
<bb uid="10" pkg="com.example.chat" sid="alice and bob" key="k2" h="0" hid="16537428" t="title" tid="2" />
|
||||
<bb uid="0" pkg="com.example.messenger" sid="shortcut-2" key="k3" h="120" hid="0" tid="-1" />
|
||||
</bs>
|
||||
""".trimIndent()
|
||||
val actual = readXml(ByteArrayInputStream(src.toByteArray(Charsets.UTF_8)))
|
||||
@@ -79,4 +81,32 @@ class BubbleXmlHelperTest : ShellTestCase() {
|
||||
val actual = readXml(ByteArrayInputStream(src.toByteArray(Charsets.UTF_8)))
|
||||
assertEquals("failed parsing bubbles from xml\n$src", emptyList<BubbleEntity>(), actual)
|
||||
}
|
||||
|
||||
/**
|
||||
* In S we changed the XML to include a taskId, version didn't increase because we can set a
|
||||
* reasonable default for taskId (INVALID_TASK_ID) if it wasn't in the XML previously, this
|
||||
* tests that that works.
|
||||
*/
|
||||
@Test
|
||||
fun testReadXMLWithoutTaskId() {
|
||||
val expectedBubbles = listOf(
|
||||
BubbleEntity(0, "com.example.messenger", "shortcut-1", "k1", 120, 0, null,
|
||||
INVALID_TASK_ID),
|
||||
BubbleEntity(10, "com.example.chat", "alice and bob", "k2", 0, 16537428, "title",
|
||||
INVALID_TASK_ID),
|
||||
BubbleEntity(0, "com.example.messenger", "shortcut-2", "k3", 120, 0, null,
|
||||
INVALID_TASK_ID)
|
||||
)
|
||||
|
||||
val src = """
|
||||
<?xml version='1.0' encoding='utf-8' standalone='yes' ?>
|
||||
<bs v="1">
|
||||
<bb uid="0" pkg="com.example.messenger" sid="shortcut-1" key="k1" h="120" hid="0" />
|
||||
<bb uid="10" pkg="com.example.chat" sid="alice and bob" key="k2" h="0" hid="16537428" t="title" />
|
||||
<bb uid="0" pkg="com.example.messenger" sid="shortcut-2" key="k3" h="120" hid="0" />
|
||||
</bs>
|
||||
""".trimIndent()
|
||||
val actual = readXml(ByteArrayInputStream(src.toByteArray(Charsets.UTF_8)))
|
||||
assertEquals("failed parsing bubbles from xml\n$src", expectedBubbles, actual)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user