惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Jina AI
Jina AI
Hugging Face - Blog
Hugging Face - Blog
博客园 - 三生石上(FineUI控件)
博客园 - 【当耐特】
大猫的无限游戏
大猫的无限游戏
IT之家
IT之家
宝玉的分享
宝玉的分享
WordPress大学
WordPress大学
有赞技术团队
有赞技术团队
Apple Machine Learning Research
Apple Machine Learning Research
酷 壳 – CoolShell
酷 壳 – CoolShell
阮一峰的网络日志
阮一峰的网络日志
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
爱范儿
爱范儿
小众软件
小众软件
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
The Cloudflare Blog
S
SegmentFault 最新的问题
博客园 - Franky
博客园_首页
T
Tailwind CSS Blog
雷峰网
雷峰网
罗磊的独立博客

Recent Commits to openclaw:main

test: merge chat side-result checks · openclaw/openclaw@ddd2c2a test: merge cron history checks · openclaw/openclaw@f7eb746 test: merge responsive navigation shell checks · openclaw/openclaw@c2e4b47 docs(changelog): add codex oauth fixes · openclaw/openclaw@628e6cd test: merge navigation routing cases · openclaw/openclaw@5d8cecb Tests: mock channel registry bundled fallback · openclaw/openclaw@2b08233 Secrets: avoid broad web search discovery for single plugin config · openclaw/openclaw@a464f59 test: merge config view browser checks · openclaw/openclaw@20cf511 fix(status): align oauth health with runtime · openclaw/openclaw@eed7116 feat: add macOS screen snapshots for monitor preview (#67954) thanks … · openclaw/openclaw@f377db1 fix: report shared auth scopes in hello-ok (#67810) thanks @BunsDev · openclaw/openclaw@0b6c39b Auto-reply: avoid eager bundled route fallback · openclaw/openclaw@3ea1bf4 Tests: narrow session binding contract setup · openclaw/openclaw@54e4e16 fix(macOS): enable undo/redo in webchat composer text input (#34962) · openclaw/openclaw@00951dc Tests: speed up channel setup promotion · openclaw/openclaw@82b529a Docs: refresh agent instructions · openclaw/openclaw@5775fe2 fix(auth): serialize OAuth refresh across agents to fix #26322 (#67876) · openclaw/openclaw@8e79080 test: allow ollama public surface boundary test · openclaw/openclaw@7d4f1a6 Docs: add test performance guardrails · openclaw/openclaw@89706d3 Tests: restore context-engine usage proof · openclaw/openclaw@e4c4f95 Tests: slim context engine runtime coverage · openclaw/openclaw@74c198f ci: retry failed custom checkouts · openclaw/openclaw@0ee5baf test: trim duplicate provider auth onboarding cases · openclaw/openclaw@1ffc02e matrix: fix sessions_spawn --thread subagent session spawning (#67643) · openclaw/openclaw@1ce2596 test: reduce auth choice fixture churn · openclaw/openclaw@857b9cd test: mock health status config boundaries · openclaw/openclaw@9d5ab4a test: mock onboard config io boundary · openclaw/openclaw@299694d test: mock legacy state plugin boundaries · openclaw/openclaw@2713089 test: mock channel install boundaries · openclaw/openclaw@b945248 test: mock doctor preview channel boundaries · openclaw/openclaw@b1a3ad4
test(android): add voice mode adb e2e harness · openclaw/...
obviyus · 2026-05-25 · via Recent Commits to openclaw:main

@@ -0,0 +1,188 @@

1+

package ai.openclaw.app

2+3+

import android.app.Service

4+

import android.content.BroadcastReceiver

5+

import android.content.Context

6+

import android.content.Intent

7+

import android.os.IBinder

8+

import android.util.Base64

9+

import android.util.Log

10+

import kotlinx.coroutines.CoroutineScope

11+

import kotlinx.coroutines.Dispatchers

12+

import kotlinx.coroutines.SupervisorJob

13+

import kotlinx.coroutines.cancel

14+

import kotlinx.coroutines.delay

15+

import kotlinx.coroutines.launch

16+

import kotlinx.coroutines.withTimeout

17+

import kotlinx.serialization.json.JsonNull

18+

import kotlinx.serialization.json.JsonPrimitive

19+

import kotlinx.serialization.json.buildJsonObject

20+

import java.io.File

21+22+

private const val tag = "VoiceE2E"

23+

private const val resultFileName = "voice_e2e_result.json"

24+25+

class VoiceE2eReceiver : BroadcastReceiver() {

26+

override fun onReceive(

27+

context: Context,

28+

intent: Intent,

29+

) {

30+

context.startService(

31+

Intent(context, VoiceE2eService::class.java)

32+

.putExtras(intent),

33+

)

34+

}

35+

}

36+37+

class VoiceE2eService : Service() {

38+

private val serviceScope = CoroutineScope(SupervisorJob() + Dispatchers.IO)

39+40+

override fun onBind(intent: Intent?): IBinder? = null

41+42+

override fun onStartCommand(

43+

intent: Intent?,

44+

flags: Int,

45+

startId: Int,

46+

): Int {

47+

val command = intent ?: return START_NOT_STICKY

48+

serviceScope.launch {

49+

try {

50+

runCommand(command)

51+

} finally {

52+

stopSelf(startId)

53+

}

54+

}

55+

return START_NOT_STICKY

56+

}

57+58+

override fun onDestroy() {

59+

serviceScope.cancel()

60+

super.onDestroy()

61+

}

62+63+

private suspend fun runCommand(intent: Intent) {

64+

try {

65+

val app = applicationContext as NodeApp

66+

val runtime = app.ensureRuntime()

67+

val mode =

68+

intent

69+

.getDecodedStringExtra("mode")

70+

?.trim()

71+

.orEmpty()

72+

.ifEmpty { "both" }

73+

if (mode == "stop") {

74+

runtime.cancelMicCapture()

75+

runtime.setTalkModeEnabled(false)

76+

writeResult("""{"ok":true,"mode":"stop"}""")

77+

return

78+

}

79+80+

val connect = !intent.getBooleanExtra("noConnect", false)

81+

val connectTimeoutMs = intent.getLongExtra("connectTimeoutMs", 20_000L)

82+

if (connect) {

83+

configureGateway(runtime = runtime, intent = intent)

84+

}

85+

if (connect || !runtime.isConnected.value) {

86+

awaitGateway(runtime = runtime, timeoutMs = connectTimeoutMs)

87+

}

88+89+

startActivity(

90+

Intent(actionOpenVoiceE2e)

91+

.setClass(this, MainActivity::class.java)

92+

.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_SINGLE_TOP or Intent.FLAG_ACTIVITY_CLEAR_TOP),

93+

)

94+95+

val transcript =

96+

intent

97+

.getDecodedStringExtra("transcript")

98+

?.trim()

99+

.orEmpty()

100+

.ifEmpty { "Reply exactly: Android voice e2e normal path ok." }

101+

val realtimeReply =

102+

intent

103+

.getDecodedStringExtra("realtimeAssistant")

104+

?.trim()

105+

.orEmpty()

106+

.ifEmpty { "Android realtime voice e2e relay path ok." }

107+

val timeoutMs = intent.getLongExtra("timeoutMs", 60_000L)

108+

val result =

109+

runtime.runVoiceE2e(

110+

mode = mode,

111+

transcript = transcript,

112+

realtimeAssistantText = realtimeReply,

113+

timeoutMs = timeoutMs,

114+

)

115+

val resultJson = encodeResult(result)

116+

writeResult(resultJson)

117+

Log.i(tag, "PASS $resultJson")

118+

} catch (err: Throwable) {

119+

val resultJson =

120+

buildJsonObject {

121+

put("ok", JsonPrimitive(false))

122+

put("error", JsonPrimitive(err.message ?: err::class.java.simpleName))

123+

}.toString()

124+

writeResult(resultJson)

125+

Log.e(tag, "FAIL $resultJson", err)

126+

}

127+

}

128+129+

private fun configureGateway(

130+

runtime: NodeRuntime,

131+

intent: Intent,

132+

) {

133+

val host =

134+

intent

135+

.getDecodedStringExtra("host")

136+

?.trim()

137+

.orEmpty()

138+

.ifEmpty { "127.0.0.1" }

139+

val port = intent.getIntExtra("port", 18789)

140+

runtime.setManualEnabled(true)

141+

runtime.setManualHost(host)

142+

runtime.setManualPort(port)

143+

runtime.setManualTls(intent.getBooleanExtra("tls", false))

144+

runtime.setGatewayToken(intent.getDecodedStringExtra("token").orEmpty())

145+

runtime.setGatewayBootstrapToken(intent.getDecodedStringExtra("bootstrapToken").orEmpty())

146+

runtime.setGatewayPassword(intent.getDecodedStringExtra("password").orEmpty())

147+

runtime.setOnboardingCompleted(true)

148+

runtime.connectManual()

149+

}

150+151+

private suspend fun awaitGateway(

152+

runtime: NodeRuntime,

153+

timeoutMs: Long,

154+

) {

155+

withTimeout(timeoutMs) {

156+

while (!runtime.isConnected.value) {

157+

delay(100L)

158+

}

159+

}

160+

}

161+162+

private fun encodeResult(result: NodeRuntime.VoiceE2eResult): String =

163+

buildJsonObject {

164+

put("ok", JsonPrimitive(true))

165+

put("normal", result.normal?.let(::encodeSlice) ?: JsonNull)

166+

put("realtime", result.realtime?.let(::encodeSlice) ?: JsonNull)

167+

}.toString()

168+169+

private fun encodeSlice(slice: NodeRuntime.VoiceE2eSliceResult) =

170+

buildJsonObject {

171+

put("mode", JsonPrimitive(slice.mode))

172+

put("status", JsonPrimitive(slice.status))

173+

put("userText", slice.userText?.let(::JsonPrimitive) ?: JsonNull)

174+

put("assistantText", slice.assistantText?.let(::JsonPrimitive) ?: JsonNull)

175+

}

176+177+

private fun writeResult(json: String) {

178+

File(cacheDir, resultFileName).writeText(json)

179+

}

180+

}

181+182+

private fun Intent.getDecodedStringExtra(name: String): String? {

183+

val encoded = getStringExtra("${name}Base64")

184+

if (!encoded.isNullOrBlank()) {

185+

return String(Base64.decode(encoded, Base64.NO_WRAP), Charsets.UTF_8)

186+

}

187+

return getStringExtra(name)

188+

}