fix: preserve camera permission intent and distinguish unknown reply expression
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
import com.gorios.lanvoice.expression.CameraPermissionGate
|
||||
import com.gorios.lanvoice.expression.CameraPermissionGate.Action
|
||||
|
||||
fun main() {
|
||||
fun gate() = CameraPermissionGate().apply { check(onForeground() == Action.NONE) }
|
||||
check(CameraPermissionGate().click(false, false) == Action.NONE)
|
||||
for (resultBeforeForeground in listOf(true, false)) {
|
||||
val g=gate();check(g.click(false,false)==Action.REQUEST_PERMISSION)
|
||||
g.onBackground();check(g.permissionPending)
|
||||
if (resultBeforeForeground) {
|
||||
check(g.permissionResult(true)==Action.NONE)
|
||||
check(g.onForeground()==Action.START)
|
||||
} else {
|
||||
check(g.onForeground()==Action.NONE)
|
||||
check(g.permissionResult(true)==Action.START)
|
||||
}
|
||||
check(g.onForeground()==Action.NONE) // one-shot continuation
|
||||
g.onBackground();check(g.onForeground()==Action.NONE) // no auto-resume of active camera
|
||||
}
|
||||
val denied=gate();check(denied.click(false,false)==Action.REQUEST_PERMISSION)
|
||||
denied.onBackground();check(denied.permissionResult(false)==Action.DENIED)
|
||||
check(denied.onForeground()==Action.NONE)
|
||||
val cancel=gate();check(cancel.click(false,false)==Action.REQUEST_PERMISSION)
|
||||
check(cancel.click(false,false)==Action.STOP);check(cancel.permissionResult(true)==Action.NONE)
|
||||
val released=gate();released.click(false,false);released.release()
|
||||
check(released.permissionResult(true)==Action.NONE);check(released.onForeground()==Action.NONE)
|
||||
val granted=gate();check(granted.click(false,true)==Action.START)
|
||||
check(granted.click(true,true)==Action.STOP)
|
||||
check(granted.permissionResult(true)==Action.NONE) // duplicate/stale result
|
||||
println("PASS: camera authorization survives onStop in both callback orders; foreground-only, denial/cancel/release, default off, no automatic resume")
|
||||
}
|
||||
@@ -8,11 +8,11 @@ fun main() {
|
||||
}
|
||||
listOf("other" to 1, "neutral" to 2, "happy" to 0, "sad" to 3).forEach { (kind, strength) ->
|
||||
val parsed = checkNotNull(com.gorios.lanvoice.dialogue.ReplyEmotion.fromWire(7L, 10L, kind, strength, "model"))
|
||||
check(parsed.label == "中立" && parsed.source == com.gorios.lanvoice.dialogue.EmotionSource.FALLBACK)
|
||||
check(parsed.label == "表达未判定(格式回退)" && parsed.source == com.gorios.lanvoice.dialogue.EmotionSource.FALLBACK)
|
||||
}
|
||||
check(com.gorios.lanvoice.dialogue.ReplyEmotion.fromWire(null, 1, "happy", 2, "model") == null)
|
||||
check(com.gorios.lanvoice.dialogue.ReplyEmotion.fromWire(1, 1, "happy", true, "model")?.label == "中立")
|
||||
check(com.gorios.lanvoice.dialogue.ReplyEmotion.fromWire(1, 1, "happy", 2.0, "model")?.label == "中立")
|
||||
check(com.gorios.lanvoice.dialogue.ReplyEmotion.fromWire(1, 1, "happy", true, "model")?.label == "表达未判定(格式回退)")
|
||||
check(com.gorios.lanvoice.dialogue.ReplyEmotion.fromWire(1, 1, "happy", 2.0, "model")?.label == "表达未判定(格式回退)")
|
||||
|
||||
val pcm = ByteArray(640) { (it % 256).toByte() }
|
||||
val uplink = DialogueProtocol.uplink(pcm, 0x81234567L, 0xffffffffL)
|
||||
|
||||
@@ -412,13 +412,17 @@ fun runChecks() {
|
||||
Payload(turn=turn, fields=mapOf("seq" to seq, "emotion" to kind, "intensity" to strength, "source" to "model"))))
|
||||
}
|
||||
emotion(3, 100)
|
||||
check(states.last().roleLabel == "高兴·明显")
|
||||
check(states.last().replyEmotion.label == "高兴·明显")
|
||||
emotion(3, 99, "angry") // out-of-order same-turn event
|
||||
emotion(2, 101, "angry") // retired turn
|
||||
emotion(99, 102, "angry") // unannounced turn must not advance current turn
|
||||
for (reason in listOf("old_seq", "old_turn", "unannounced_turn")) {
|
||||
check(DebugLogUpload.records.any { it.second.startsWith("role ignore reason=$reason ") })
|
||||
}
|
||||
check(states.last().replyEmotion.label == "高兴·明显")
|
||||
emotion(3, 103, "invalid")
|
||||
check(states.last().replyEmotion.label == "中立")
|
||||
check(states.last().replyEmotion.label == "表达未判定(格式回退)")
|
||||
emotion(3, 104, "sad", 1)
|
||||
check(states.last().replyEmotion.label == "难过·轻度")
|
||||
event(EventKind.TTS, 3, state="stop")
|
||||
@@ -426,16 +430,22 @@ fun runChecks() {
|
||||
check(states.last().replyEmotion.label == "难过·轻度") // tts.stop does not mean native drain
|
||||
checkNotNull(com.gorios.lanvoice.audio.AudioPlayback.lastDrained)(3, 0)
|
||||
Handler.drain()
|
||||
check(states.last().replyEmotion.label == "中立")
|
||||
check(states.last().replyEmotion.turnId == null)
|
||||
check(states.last().roleLabel == "当前未播放")
|
||||
check(states.last().previousReplyEmotion?.label == "难过·轻度")
|
||||
emotion(3, 105) // a late event after drained cannot reanimate the expression
|
||||
check(states.last().replyEmotion.label == "中立")
|
||||
check(DebugLogUpload.records.any { it.second.startsWith("role ignore reason=drained ") })
|
||||
check(states.last().previousReplyEmotion?.label == "难过·轻度")
|
||||
check(states.last().replyEmotion.turnId == null)
|
||||
event(EventKind.ABORT, 4, reason="new_turn")
|
||||
check(states.last().previousReplyEmotion?.label == "难过·轻度")
|
||||
emotion(4, 106)
|
||||
check(states.last().roleLabel == "当前未播放") // accepted expression before PCM is not displayed as playing
|
||||
check(states.last().replyEmotion.label == "高兴·明显")
|
||||
session.interrupt()
|
||||
check(states.last().replyEmotion.label == "中立")
|
||||
check(states.last().replyEmotion.turnId == null)
|
||||
event(EventKind.ABORT, 4, reason="client_abort")
|
||||
check(states.last().replyEmotion.label == "中立")
|
||||
check(states.last().replyEmotion.turnId == null)
|
||||
event(EventKind.UNKNOWN, 4)
|
||||
event(EventKind.ABORT, 4, reason="new_turn")
|
||||
check(blockedField.get(session) == null)
|
||||
@@ -471,6 +481,17 @@ fun runChecks() {
|
||||
}
|
||||
|
||||
fun main() {
|
||||
run {
|
||||
val normal = com.gorios.lanvoice.dialogue.ReplyEmotion.fromWire(2L, 1L, "neutral", 0, "model")!!
|
||||
val fallback = com.gorios.lanvoice.dialogue.ReplyEmotion.fromWire(2L, 1L, "neutral", 0, "fallback", "invalid_intensity")!!
|
||||
val empty = com.gorios.lanvoice.audio.VoiceUiState()
|
||||
check(empty.roleLabel == "当前未播放")
|
||||
check(empty.copy(voiceActive=true, phase=com.gorios.lanvoice.audio.VoicePhase.THINKING, replyEmotion=normal).roleLabel == "等待回复")
|
||||
check(empty.copy(phase=com.gorios.lanvoice.audio.VoicePhase.ANSWERING, replyEmotion=normal).roleLabel == "中立")
|
||||
check(empty.copy(phase=com.gorios.lanvoice.audio.VoicePhase.ANSWERING, replyEmotion=fallback).roleLabel == "表达未判定(格式回退)")
|
||||
check(fallback.reason.wire == "invalid_intensity")
|
||||
}
|
||||
|
||||
try { runChecks() } catch (error: Throwable) {
|
||||
error.printStackTrace()
|
||||
kotlin.system.exitProcess(1)
|
||||
|
||||
@@ -4,7 +4,7 @@ package com.gorios.lanvoice.net
|
||||
// Production DialogueProtocol/JSONObject were compiled separately with actual dependencies.
|
||||
class Payload(private val ok: Boolean = true, private val turn: Long? = null, private val state: String = "", private val reason: String = "", private val fields: Map<String, Any> = emptyMap()) {
|
||||
fun optBoolean(key: String, fallback: Boolean) = if (key == "ok") ok else fallback
|
||||
fun optString(key: String, fallback: String = "") = when (key) { "state" -> state; "reason" -> reason; else -> fallback }
|
||||
fun optString(key: String, fallback: String = "") = when (key) { "state" -> state; "reason" -> reason; else -> fields[key] as? String ?: fallback }
|
||||
fun optInt(key: String, fallback: Int) = if (key == "context_face_cue_version") 1 else fallback
|
||||
fun opt(key: String): Any? = if (key == "turn_id") turn else fields[key]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user