Make CameraX blocklist remote configurable.

This commit is contained in:
Greyson Parrelli
2022-08-05 09:38:04 -04:00
committed by Cody Henthorne
parent ace4157a14
commit 91d3f331e5
7 changed files with 59 additions and 148 deletions

View File

@@ -0,0 +1,23 @@
package org.signal.core.util
/**
* Treats the string as a serialized list of tokens and tells you if an item is present in the list.
* In addition to exact matches, this handles wildcards at the end of an item.
*
* e.g. a,b,c*,d
*/
fun String.asListContains(item: String): Boolean {
val items: List<String> = this
.split(",")
.map { it.trim() }
.filter { it.isNotEmpty() }
.toList()
val exactMatches = items.filter { it.last() != '*' }
val prefixMatches = items.filter { it.last() == '*' }
return exactMatches.contains(item) ||
prefixMatches
.map { it.substring(0, it.length - 1) }
.any { item.startsWith(it) }
}

View File

@@ -0,0 +1,39 @@
package org.signal.core.util
import org.junit.Assert.assertEquals
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.Parameterized
@RunWith(Parameterized::class)
class StringExtensions_asListContains(
private val model: String,
private val serializedList: String,
private val expected: Boolean
) {
@Test
fun testModelInList() {
val actual = serializedList.asListContains(model)
assertEquals(expected, actual)
}
companion object {
@JvmStatic
@Parameterized.Parameters(name = "{index}: modelInList(model={0}, list={1})={2}")
fun data(): List<Array<Any>> {
return listOf<Array<Any>>(
arrayOf("a", "a", true),
arrayOf("a", "a,b", true),
arrayOf("a", "c,a,b", true),
arrayOf("ab", "a*", true),
arrayOf("ab", "c,a*,b", true),
arrayOf("abc", "c,ab*,b", true),
arrayOf("a", "b", false),
arrayOf("a", "abc", false),
arrayOf("b", "a*", false),
).toList()
}
}
}