Skip to content

Commit 608b9a9

Browse files
committed
fix(android): show copyable gateway diagnostics
1 parent a2fa799 commit 608b9a9

3 files changed

Lines changed: 191 additions & 9 deletions

File tree

‎apps/android/app/src/main/java/ai/openclaw/app/ui/ConnectTabScreen.kt‎

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package ai.openclaw.app.ui
22

3-
import androidx.compose.animation.AnimatedVisibility
43
import androidx.compose.foundation.BorderStroke
4+
import androidx.compose.animation.AnimatedVisibility
55
import androidx.compose.foundation.background
66
import androidx.compose.foundation.layout.Arrangement
77
import androidx.compose.foundation.layout.Box
@@ -20,6 +20,7 @@ import androidx.compose.foundation.text.KeyboardOptions
2020
import androidx.compose.foundation.verticalScroll
2121
import androidx.compose.material.icons.Icons
2222
import androidx.compose.material.icons.filled.Cloud
23+
import androidx.compose.material.icons.filled.ContentCopy
2324
import androidx.compose.material.icons.filled.ExpandLess
2425
import androidx.compose.material.icons.filled.ExpandMore
2526
import androidx.compose.material.icons.filled.Link
@@ -49,6 +50,7 @@ import androidx.compose.ui.graphics.Color
4950
import androidx.compose.ui.text.font.FontFamily
5051
import androidx.compose.ui.text.font.FontWeight
5152
import androidx.compose.ui.text.input.KeyboardType
53+
import androidx.compose.ui.platform.LocalContext
5254
import androidx.compose.ui.unit.dp
5355
import ai.openclaw.app.MainViewModel
5456
import ai.openclaw.app.ui.mobileCardSurface
@@ -60,6 +62,7 @@ private enum class ConnectInputMode {
6062

6163
@Composable
6264
fun ConnectTabScreen(viewModel: MainViewModel) {
65+
val context = LocalContext.current
6366
val statusText by viewModel.statusText.collectAsState()
6467
val isConnected by viewModel.isConnected.collectAsState()
6568
val remoteAddress by viewModel.remoteAddress.collectAsState()
@@ -134,7 +137,8 @@ fun ConnectTabScreen(viewModel: MainViewModel) {
134137
}
135138
}
136139

137-
val primaryLabel = if (isConnected) "Disconnect Gateway" else "Connect Gateway"
140+
val showDiagnostics = !isConnected && gatewayStatusHasDiagnostics(statusText)
141+
val statusLabel = gatewayStatusForDisplay(statusText)
138142

139143
Column(
140144
modifier = Modifier.verticalScroll(rememberScrollState()).padding(horizontal = 20.dp, vertical = 16.dp),
@@ -279,6 +283,46 @@ fun ConnectTabScreen(viewModel: MainViewModel) {
279283
}
280284
}
281285

286+
if (showDiagnostics) {
287+
Surface(
288+
modifier = Modifier.fillMaxWidth(),
289+
shape = RoundedCornerShape(14.dp),
290+
color = mobileWarningSoft,
291+
border = BorderStroke(1.dp, mobileWarning.copy(alpha = 0.25f)),
292+
) {
293+
Column(
294+
modifier = Modifier.fillMaxWidth().padding(horizontal = 14.dp, vertical = 14.dp),
295+
verticalArrangement = Arrangement.spacedBy(10.dp),
296+
) {
297+
Text("Last gateway error", style = mobileHeadline, color = mobileWarning)
298+
Text(statusLabel, style = mobileBody.copy(fontFamily = FontFamily.Monospace), color = mobileText)
299+
Text("OpenClaw Android ${openClawAndroidVersionLabel()}", style = mobileCaption1, color = mobileTextSecondary)
300+
Button(
301+
onClick = {
302+
copyGatewayDiagnosticsReport(
303+
context = context,
304+
screen = "connect tab",
305+
gatewayAddress = activeEndpoint,
306+
statusText = statusLabel,
307+
)
308+
},
309+
modifier = Modifier.fillMaxWidth().height(46.dp),
310+
shape = RoundedCornerShape(12.dp),
311+
colors =
312+
ButtonDefaults.buttonColors(
313+
containerColor = mobileCardSurface,
314+
contentColor = mobileWarning,
315+
),
316+
border = BorderStroke(1.dp, mobileWarning.copy(alpha = 0.3f)),
317+
) {
318+
Icon(Icons.Default.ContentCopy, contentDescription = null, modifier = Modifier.size(18.dp))
319+
Spacer(modifier = Modifier.width(8.dp))
320+
Text("Copy Report for Claw", style = mobileCallout.copy(fontWeight = FontWeight.Bold))
321+
}
322+
}
323+
}
324+
}
325+
282326
Surface(
283327
modifier = Modifier.fillMaxWidth(),
284328
shape = RoundedCornerShape(14.dp),
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
package ai.openclaw.app.ui
2+
3+
import android.content.ClipData
4+
import android.content.ClipboardManager
5+
import android.content.Context
6+
import android.os.Build
7+
import android.widget.Toast
8+
import ai.openclaw.app.BuildConfig
9+
10+
internal fun openClawAndroidVersionLabel(): String {
11+
val versionName = BuildConfig.VERSION_NAME.trim().ifEmpty { "dev" }
12+
return if (BuildConfig.DEBUG && !versionName.contains("dev", ignoreCase = true)) {
13+
"$versionName-dev"
14+
} else {
15+
versionName
16+
}
17+
}
18+
19+
internal fun gatewayStatusForDisplay(statusText: String): String {
20+
return statusText.trim().ifEmpty { "Offline" }
21+
}
22+
23+
internal fun gatewayStatusHasDiagnostics(statusText: String): Boolean {
24+
val lower = gatewayStatusForDisplay(statusText).lowercase()
25+
return lower != "offline" && !lower.contains("connecting")
26+
}
27+
28+
internal fun gatewayStatusLooksLikePairing(statusText: String): Boolean {
29+
val lower = gatewayStatusForDisplay(statusText).lowercase()
30+
return lower.contains("pair") || lower.contains("approve")
31+
}
32+
33+
internal fun buildGatewayDiagnosticsReport(
34+
screen: String,
35+
gatewayAddress: String,
36+
statusText: String,
37+
): String {
38+
val device =
39+
listOfNotNull(Build.MANUFACTURER, Build.MODEL)
40+
.joinToString(" ")
41+
.trim()
42+
.ifEmpty { "Android" }
43+
val androidVersion = Build.VERSION.RELEASE?.trim().orEmpty().ifEmpty { Build.VERSION.SDK_INT.toString() }
44+
val endpoint = gatewayAddress.trim().ifEmpty { "unknown" }
45+
val status = gatewayStatusForDisplay(statusText)
46+
return """
47+
Help diagnose this OpenClaw Android gateway connection failure.
48+
49+
Please:
50+
- pick one route only: same machine, same LAN, Tailscale, or public URL
51+
- classify this as pairing/auth, TLS trust, wrong advertised route, wrong address/port, or gateway down
52+
- quote the exact app status/error below
53+
- tell me whether `openclaw devices list` should show a pending pairing request
54+
- if more signal is needed, ask for `openclaw qr --json`, `openclaw devices list`, and `openclaw nodes status`
55+
- give the next exact command or tap
56+
57+
Debug info:
58+
- screen: $screen
59+
- app version: ${openClawAndroidVersionLabel()}
60+
- device: $device
61+
- android: $androidVersion (SDK ${Build.VERSION.SDK_INT})
62+
- gateway address: $endpoint
63+
- status/error: $status
64+
""".trimIndent()
65+
}
66+
67+
internal fun copyGatewayDiagnosticsReport(
68+
context: Context,
69+
screen: String,
70+
gatewayAddress: String,
71+
statusText: String,
72+
) {
73+
val clipboard = context.getSystemService(ClipboardManager::class.java) ?: return
74+
val report = buildGatewayDiagnosticsReport(screen = screen, gatewayAddress = gatewayAddress, statusText = statusText)
75+
clipboard.setPrimaryClip(ClipData.newPlainText("OpenClaw gateway diagnostics", report))
76+
Toast.makeText(context, "Copied gateway diagnostics", Toast.LENGTH_SHORT).show()
77+
}

‎apps/android/app/src/main/java/ai/openclaw/app/ui/OnboardingFlow.kt‎

Lines changed: 68 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import android.hardware.SensorManager
99
import android.net.Uri
1010
import android.os.Build
1111
import android.provider.Settings
12+
import androidx.compose.foundation.BorderStroke
1213
import androidx.activity.compose.rememberLauncherForActivityResult
1314
import androidx.activity.result.contract.ActivityResultContracts
1415
import androidx.compose.animation.AnimatedVisibility
@@ -60,6 +61,7 @@ import androidx.compose.material.icons.automirrored.filled.ArrowBack
6061
import androidx.compose.material.icons.filled.ChatBubble
6162
import androidx.compose.material.icons.filled.CheckCircle
6263
import androidx.compose.material.icons.filled.Cloud
64+
import androidx.compose.material.icons.filled.ContentCopy
6365
import androidx.compose.material.icons.filled.ExpandLess
6466
import androidx.compose.material.icons.filled.ExpandMore
6567
import androidx.compose.material.icons.filled.Link
@@ -1519,6 +1521,12 @@ private fun FinalStep(
15191521
enabledPermissions: String,
15201522
methodLabel: String,
15211523
) {
1524+
val context = androidx.compose.ui.platform.LocalContext.current
1525+
val gatewayAddress = parsedGateway?.displayUrl ?: "Invalid gateway URL"
1526+
val statusLabel = gatewayStatusForDisplay(statusText)
1527+
val showDiagnostics = gatewayStatusHasDiagnostics(statusText)
1528+
val pairingRequired = gatewayStatusLooksLikePairing(statusText)
1529+
15221530
Column(verticalArrangement = Arrangement.spacedBy(10.dp)) {
15231531
Text("Review", style = onboardingTitle1Style, color = onboardingText)
15241532

@@ -1531,7 +1539,7 @@ private fun FinalStep(
15311539
SummaryCard(
15321540
icon = Icons.Default.Cloud,
15331541
label = "Gateway",
1534-
value = parsedGateway?.displayUrl ?: "Invalid gateway URL",
1542+
value = gatewayAddress,
15351543
accentColor = Color(0xFF7C5AC7),
15361544
)
15371545
SummaryCard(
@@ -1615,7 +1623,7 @@ private fun FinalStep(
16151623
modifier = Modifier.fillMaxWidth(),
16161624
shape = RoundedCornerShape(14.dp),
16171625
color = onboardingWarningSoft,
1618-
border = androidx.compose.foundation.BorderStroke(1.dp, onboardingWarning.copy(alpha = 0.2f)),
1626+
border = BorderStroke(1.dp, onboardingWarning.copy(alpha = 0.2f)),
16191627
) {
16201628
Column(
16211629
modifier = Modifier.padding(14.dp),
@@ -1640,13 +1648,66 @@ private fun FinalStep(
16401648
)
16411649
}
16421650
Column(verticalArrangement = Arrangement.spacedBy(2.dp)) {
1643-
Text("Pairing Required", style = onboardingHeadlineStyle, color = onboardingWarning)
1644-
Text("Run these on your gateway host:", style = onboardingCalloutStyle, color = onboardingTextSecondary)
1651+
Text(
1652+
if (pairingRequired) "Pairing Required" else "Connection Failed",
1653+
style = onboardingHeadlineStyle,
1654+
color = onboardingWarning,
1655+
)
1656+
Text(
1657+
if (pairingRequired) {
1658+
"Approve this phone on the gateway host, or copy the report below."
1659+
} else {
1660+
"Copy this report and give it to your Claw."
1661+
},
1662+
style = onboardingCalloutStyle,
1663+
color = onboardingTextSecondary,
1664+
)
1665+
}
1666+
}
1667+
if (showDiagnostics) {
1668+
Text("Error", style = onboardingCaption1Style.copy(fontWeight = FontWeight.Bold), color = onboardingTextSecondary)
1669+
Surface(
1670+
modifier = Modifier.fillMaxWidth(),
1671+
shape = RoundedCornerShape(12.dp),
1672+
color = onboardingCommandBg,
1673+
border = BorderStroke(1.dp, onboardingCommandBorder),
1674+
) {
1675+
Text(
1676+
statusLabel,
1677+
modifier = Modifier.padding(horizontal = 14.dp, vertical = 12.dp),
1678+
style = onboardingCalloutStyle.copy(fontFamily = FontFamily.Monospace),
1679+
color = onboardingCommandText,
1680+
)
16451681
}
1682+
Text(
1683+
"OpenClaw Android ${openClawAndroidVersionLabel()}",
1684+
style = onboardingCaption1Style,
1685+
color = onboardingTextSecondary,
1686+
)
1687+
Button(
1688+
onClick = {
1689+
copyGatewayDiagnosticsReport(
1690+
context = context,
1691+
screen = "onboarding final check",
1692+
gatewayAddress = gatewayAddress,
1693+
statusText = statusLabel,
1694+
)
1695+
},
1696+
modifier = Modifier.fillMaxWidth().height(48.dp),
1697+
shape = RoundedCornerShape(12.dp),
1698+
colors = ButtonDefaults.buttonColors(containerColor = onboardingSurface, contentColor = onboardingWarning),
1699+
border = BorderStroke(1.dp, onboardingWarning.copy(alpha = 0.3f)),
1700+
) {
1701+
Icon(Icons.Default.ContentCopy, contentDescription = null, modifier = Modifier.size(18.dp))
1702+
Spacer(modifier = Modifier.width(8.dp))
1703+
Text("Copy Report for Claw", style = onboardingCalloutStyle.copy(fontWeight = FontWeight.Bold))
1704+
}
1705+
}
1706+
if (pairingRequired) {
1707+
CommandBlock("openclaw devices list")
1708+
CommandBlock("openclaw devices approve <requestId>")
1709+
Text("Then tap Connect again.", style = onboardingCalloutStyle, color = onboardingTextSecondary)
16461710
}
1647-
CommandBlock("openclaw devices list")
1648-
CommandBlock("openclaw devices approve <requestId>")
1649-
Text("Then tap Connect again.", style = onboardingCalloutStyle, color = onboardingTextSecondary)
16501711
}
16511712
}
16521713
}

0 commit comments

Comments
 (0)