Handle nullable multicast lock creation before acquiring ownership
This commit is contained in:
1 parent
af8db9b5b4
commit
932472e621
3 files changed
+13
-1
No files matched your search
@@ -170,6 +170,7 @@ object LocalDiscovery {
|
||||
if (wifi == null) { LogManager.addLog("WARN", "discovery", "Wi-Fi service unavailable"); return }
|
||||
operation = "create"
|
||||
lock = wifi.createMulticastLock("utun-local-discovery")
|
||||
if (lock == null) { LogManager.addLog("ERROR", "discovery", "MulticastLock creation returned null"); return }
|
||||
multicastLock = lock
|
||||
}
|
||||
operation = "query"
|
||||
|
||||
@@ -4,8 +4,9 @@ package android.net.wifi
|
||||
class WifiManager {
|
||||
var failures = emptySet<String>()
|
||||
val locks = mutableListOf<MulticastLock>()
|
||||
fun createMulticastLock(tag: String): MulticastLock {
|
||||
fun createMulticastLock(tag: String): MulticastLock? {
|
||||
check("create" !in failures) { "multicast create unavailable" }
|
||||
if ("null_create" in failures) return null
|
||||
return MulticastLock(tag, failures).also { locks.add(it) }
|
||||
}
|
||||
class MulticastLock(val tag: String, var failures: Set<String>) {
|
||||
|
||||
+10
@@ -223,6 +223,16 @@ class LocalDiscoveryTest {
|
||||
wifi.failures = emptySet(); active(true); assertTrue(wifi.locks.single().held)
|
||||
}
|
||||
|
||||
@Test fun nullMulticastLockIsReportedAtCreationAndCanRetry() {
|
||||
val wifi = context.wifiManager!!
|
||||
wifi.failures = setOf("null_create")
|
||||
active(true)
|
||||
assertTrue(wifi.locks.isEmpty()); diagnostic("creation returned null")
|
||||
wifi.failures = emptySet()
|
||||
active(true)
|
||||
assertTrue(wifi.locks.single().held)
|
||||
}
|
||||
|
||||
@Test fun backgroundMutatorsAreRejectedBeforeChangingState() {
|
||||
LocalDiscovery.onEvent(61, devices(row(1, "kept".toByteArray())))
|
||||
LocalDiscovery.onEvent(62, invite()); LocalDiscovery.send(device, link)
|
||||
|
||||
Reference in new issue
Block a user