fix(android): retain action layer and idle rotation across turns

This commit is contained in:
zenord
2026-10-13 09:36:29 +08:00
parent 24ec3ab044
commit a68988e0ba
21 changed files with 554 additions and 58 deletions
+1
View File
@@ -6,6 +6,7 @@ import android.media.MediaPlayer
import android.view.TextureView
fun main() {
boundedRuntimeDiagnosticCheck()
dynamicBodyCheck()
actionCheck()
emotionActionCheck()
+12 -2
View File
@@ -1,2 +1,12 @@
package com.gorios.lanvoice.diag
object DiagnosticLog { fun record(tag: String,msg: String) {} }
import com.gorios.lanvoice.diag.DiagnosticLog
fun boundedRuntimeDiagnosticCheck() {
val before=DiagnosticLog.snapshot().size
repeat(501) { DiagnosticLog.state("bounded_test","action","owner=action frame=$it",it.toLong()) }
check(DiagnosticLog.snapshot().size==before+1)
DiagnosticLog.state("bounded_test","action","owner=action frame=240",10_000)
DiagnosticLog.state("bounded_test","conversation","owner=conversation frame=96",10_001)
check(DiagnosticLog.snapshot().size==before+3)
repeat(600) { DiagnosticLog.record("bounded_ring","fixed_enum=sample") }
check(DiagnosticLog.snapshot().size==500)
println("PASS: bounded runtime diagnostics: state changes +10s monotonic summaries, no per-frame churn,500-entry ring")
}
+53 -2
View File
@@ -138,6 +138,53 @@ fun actualMediaViewCheck() {
check(statuses.size==before);cases++
actionView.dispose();TestScheduler.advanceBy(100)
}
// Ten seconds of real production held-renderer callbacks must never steal
// the movie TextureView. Native/codec/record ports remain deterministic doubles.
for(mode in listOf("complete", "cancel", "failed", "background", "newturn")) {
reset()
val base=mediaFixtureIndex()
val original=base.actionPack!!.assets.first()
val media=original.media!!.copy(ptsUs=List(241) { it*1_000_000L/24 },durationUs=10_041_667,
sourceFrame=0,returnFrame=96)
val asset=original.copy(durationMs=10_042,media=media)
val index=base.copy(actionPack=base.actionPack.copy(assets=listOf(asset,asset.copy(id="asset_02"))))
val (v,b,trace)=rig(index)
var confirmation: ((Boolean)->Unit)?=null
val statuses=mutableListOf<ActionStatus>()
val controller=ActionController(index.actionPack,b,{TestScheduler.now},{confirmation=it},statuses::add)
check(controller.offer(ActionPlan("z".repeat(24),7,"a".repeat(64),25000)))
confirmation!!(true);val player=MediaPlayer.created.single();val prepared=player.prepared!!
prepared(player);TestScheduler.until { player.started }
val textures=v.children.filterIsInstance<TextureView>()
fun latch(pts: Long) { val t=textures[3].surfaceTexture!!;t.timestamp=pts*1000;textures[3].surfaceTextureListener!!.onSurfaceTextureUpdated(t) }
val owner=driverField.get(v) as ConversationMediaDriver
// Delayed first frame leaves the last valid body visible, with ACTION owning it.
TestScheduler.advanceBy(80);check(owner.layerOwner==ConversationMediaDriver.LayerOwner.ACTION && textures[3].alpha==0f);cases++
latch(0);TestScheduler.advanceBy(21)
check(textures[3].alpha==1f && textures.take(3).all { it.alpha==0f } && player.started);cases++
prepared(player) // Duplicated ready cannot start/reclaim again.
for(i in 1..240) {
TestScheduler.advanceBy(42);latch(media.ptsUs[i])
check(textures[3].alpha==1f && textures.take(3).all { it.alpha==0f } && owner.layerOwner==ConversationMediaDriver.LayerOwner.ACTION);cases++
if(i==120) { v.render(true);check(driverField.get(v)===owner);cases++ } // Settings continuity.
}
check(statuses.none { it.status=="completed" });cases++ // Time alone is insufficient.
when(mode) {
"complete" -> { player.completion!!(player);player.completion!!(player)
TestScheduler.until { statuses.last().status=="completed" }
check(player.released && owner.layerOwner==ConversationMediaDriver.LayerOwner.CONVERSATION && trace.last().clipId.startsWith("f96_"));cases++ }
"failed" -> { player.error!!(player,1,2);TestScheduler.until { !controller.active } }
"background" -> { controller.cancel();v.render(false);TestScheduler.until { !controller.active } }
"newturn" -> { b.beginTurn(8);controller.cancel();TestScheduler.until { !controller.active } }
else -> { controller.cancel();TestScheduler.until { !controller.active } }
}
val before=statuses.size;val alphas=textures.map { it.alpha }
prepared(player);player.completion!!(player);player.error!!(player,1,2)
check(statuses.size==before && textures.map { it.alpha }==alphas && player.released);cases++
v.dispose();TestScheduler.advanceBy(100)
check(owner.layerOwner==ConversationMediaDriver.LayerOwner.STOPPED);cases++
}
// New idle rows use the actual view/renderer/codec path and reviewed graph.
reset()
val idleIndex=mediaFixtureIndex().let { it.copy(actionPack=null,visuals=it.visuals.map { p->p.copy(emotion=RoleEmotion.NEUTRAL) }) }
@@ -146,11 +193,15 @@ fun actualMediaViewCheck() {
check(idleTrace.all { it.actual=="body_neutral" });cases++
TestScheduler.until(15_000) { idleBinding.currentPackageId in setOf("happy","sad") }
val firstIdle=idleBinding.currentPackageId
// New turns on the actual displayed variant must retain its legal rotation.
val turnBefore=idleTrace.size
repeat(4) { i -> idleBinding.beginTurn(8L+i);idleBinding.intent(null,false);TestScheduler.advanceBy(200) }
check(idleBinding.currentPackageId==firstIdle && idleTrace.drop(turnBefore).none { it.actual=="body_neutral" });cases++
check(idleTrace.any { it.actual=="bridge" } && idleBinding.visualStatus=="neutral_idle_variant");cases++
TestScheduler.until(15_000) { idleBinding.currentPackageId=="neutral" }
TestScheduler.until(15_000) { idleBinding.currentPackageId in setOf("happy","sad") }
check(idleBinding.currentPackageId!=firstIdle && idleTrace.none { it.actual=="media_failed" });cases++
idleBinding.intent(mediaReply(RoleEmotion.NEUTRAL),true)
idleBinding.intent(mediaReply(RoleEmotion.NEUTRAL,turn=11),true)
TestScheduler.until(15_000) { idleBinding.currentPackageId=="neutral" }
val speechStart=idleTrace.size;TestScheduler.advanceBy(9000)
check(idleTrace.drop(speechStart).all { it.actual=="body_neutral" });cases++
@@ -177,5 +228,5 @@ fun actualMediaViewCheck() {
renderer.close();TestScheduler.advanceBy(50)
check(GLFixture.deleted>=126 && CodecFixture.releases==1);cases++
CodecFixture.reset();MediaPlayer.created.clear()
println("PASS: $cases actual EmotionActionAvatarView/binding/held GLES renderer/MediaPlayer callback cases: hidden header/final mismatch, final slight,97→49→121 and24→30fps/native loops, real bridge frames/latest turn, settings continuity, mic-confirm/cancel-pending/failure gate, safe exit/music first+last PTS/native end/release/idle-A, completion order, cancel/error/background/stale callbacks; deterministic Android doubles, device/naturalness not_run")
println("PASS: $cases actual EmotionActionAvatarView/binding/held GLES renderer/MediaPlayer callback assertions: hidden header/final mismatch, final slight,97→49→121 and24→30fps/native loops, real bridge frames/latest turn, settings continuity, mic-confirm/cancel-pending/failure gate, safe exit/music first+last PTS/native end/release/idle-A, completion order, cancel/error/background/stale callbacks; deterministic Android doubles, device/naturalness not_run")
}