feat(android): add isolated lvbu persona build and pinned asset selection
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
import android.os.Handler
|
||||
import com.gorios.lanvoice.net.*
|
||||
import okhttp3.*
|
||||
|
||||
private class Socket: WebSocket {
|
||||
val sent=mutableListOf<String>()
|
||||
var cancelled=false
|
||||
override fun request()=Request.Builder().url("https://localhost/ws/dialogue").build()
|
||||
override fun queueSize()=0L
|
||||
override fun send(text: String): Boolean {sent.add(text);return true}
|
||||
override fun send(bytes: okio.ByteString)=true
|
||||
override fun close(code: Int,reason: String?)=true
|
||||
override fun cancel() {cancelled=true}
|
||||
}
|
||||
private fun DialogueClient.field(name: String,value: Any?) {
|
||||
javaClass.getDeclaredField(name).apply {isAccessible=true}.set(this,value)
|
||||
}
|
||||
private fun DialogueClient.listener(epoch: Long)=javaClass.getDeclaredMethod("listener",Long::class.javaPrimitiveType)
|
||||
.apply {isAccessible=true}.invoke(this,epoch) as WebSocketListener
|
||||
|
||||
fun main() {
|
||||
val wires=mutableListOf<String>()
|
||||
val pin="208f703ed92bf795bfeb78a1cef89b67bed2e45da80038a56157fd1ecd4cfa93"
|
||||
for(persona in listOf("default","lvbu")) for(pending in listOf(false,true)) {
|
||||
var readyPin: String?=if(pending) null else pin
|
||||
val statuses=mutableListOf<ConnectionStatus>()
|
||||
val client=DialogueClient("localhost",5011,statuses::add,persona=persona,
|
||||
actionPackSha={readyPin},pendingActionPackSha={pin})
|
||||
val socket=Socket();client.field("socket",socket);val old=client.listener(0)
|
||||
fun receive(text: String) {old.onMessage(socket,text);Handler.drain()}
|
||||
receive("""{"type":"auth","state":"ok"}""")
|
||||
check(socket.sent.size==1 && "\"persona\":\"$persona\"" in socket.sent[0])
|
||||
check("voice_id" !in socket.sent[0] && "conversation_id" !in socket.sent[0])
|
||||
check(statuses.isEmpty());wires.add(socket.sent.single())
|
||||
receive("""{"type":"auth","state":"ok"}""");check(socket.sent.size==1)
|
||||
receive(if(pending) """{"type":"hello","action_pending":true,"action_available":false}"""
|
||||
else """{"type":"hello","action_available":true}""")
|
||||
check(statuses==listOf(ConnectionStatus.CONNECTED))
|
||||
if(pending) {
|
||||
check(client.actionNegotiation=="pending_pack")
|
||||
readyPin=pin;check(client.capabilitiesReady())
|
||||
check(socket.sent.last()==DialogueProtocol.capabilitiesReady(pin))
|
||||
} else check(client.actionNegotiation=="accepted")
|
||||
client.disconnect()
|
||||
old.onMessage(socket,"""{"type":"auth","state":"ok"}""")
|
||||
old.onMessage(socket,"""{"type":"hello","action_available":true}""");Handler.drain()
|
||||
check(socket.cancelled && statuses.last()==ConnectionStatus.DISCONNECTED)
|
||||
val count=socket.sent.size
|
||||
old.onMessage(Socket(),"""{"type":"auth","state":"ok"}""");Handler.drain()
|
||||
check(socket.sent.size==count)
|
||||
client.release();Handler.drain()
|
||||
}
|
||||
java.io.File(checkNotNull(System.getProperty("character.helloFile"))).writeText(wires.joinToString("\n")+"\n")
|
||||
println("PASS: four actual DialogueClient AUTH→production HELLO persona/media offers, pending readiness, duplicate AUTH and retired socket fences; transport/main/JSON adapters, device not_run")
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package org.json
|
||||
|
||||
// Bounded flat AUTH/HELLO response adapter. Outbound JSON uses production protocol.
|
||||
// This does not exercise Android's JSON parser, which the APK build compiles.
|
||||
class JSONObject() {
|
||||
private val fields=linkedMapOf<String,Any>()
|
||||
constructor(text: String):this() {
|
||||
check(text.length<2048 && text.startsWith("{") && text.endsWith("}"))
|
||||
val entries=Regex("\"([a-z_]+)\":(\"[a-z_]+\"|true|false|[0-9]+)").findAll(text)
|
||||
entries.forEach {
|
||||
val raw=it.groupValues[2]
|
||||
fields[it.groupValues[1]]=when {
|
||||
raw.startsWith("\"") -> raw.removeSurrounding("\"")
|
||||
raw=="true" -> true
|
||||
raw=="false" -> false
|
||||
else -> raw.toLong()
|
||||
}
|
||||
}
|
||||
}
|
||||
fun put(key: String,value: Any): JSONObject {fields[key]=value;return this}
|
||||
fun opt(key: String): Any?=fields[key]
|
||||
fun optString(key: String,fallback: String=""): String=fields[key] as? String ?: fallback
|
||||
fun optBoolean(key: String,fallback: Boolean=false): Boolean=fields[key] as? Boolean ?: fallback
|
||||
fun optLong(key: String,fallback: Long=0): Long=(fields[key] as? Number)?.toLong() ?: fallback
|
||||
override fun toString()=fields.entries.joinToString(",","{","}") { (k,v) ->
|
||||
"\"$k\":"+if(v is String) "\"$v\"" else v.toString()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user