Skip to content

Commit be50a28

Browse files
authored
android: make ping peer relay aware (#714)
Updates tailscale/tailscale#17743 Signed-off-by: Jordan Whited <[email protected]>
1 parent 9b7885a commit be50a28

File tree

6 files changed

+34
-1
lines changed

6 files changed

+34
-1
lines changed

android/src/main/java/com/tailscale/ipn/ui/model/IpnState.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class IpnState {
2626
val Addrs: List<String>? = null,
2727
val CurAddr: String? = null,
2828
val Relay: String? = null,
29+
val PeerRelay: String? = null,
2930
val Online: Boolean,
3031
val ExitNode: Boolean,
3132
val ExitNodeOption: Boolean,

android/src/main/java/com/tailscale/ipn/ui/util/ConnectionMode.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,15 @@ sealed class ConnectionMode {
1717

1818
class Direct : ConnectionMode()
1919

20+
class PeerRelay : ConnectionMode()
21+
2022
@Composable
2123
fun titleString(): String {
2224
return when (this) {
2325
is NotConnected -> stringResource(id = R.string.not_connected)
2426
is Derp -> stringResource(R.string.relayed_connection, relayName)
2527
is Direct -> stringResource(R.string.direct_connection)
28+
is PeerRelay -> stringResource(R.string.peer_relayed_connection)
2629
}
2730
}
2831

@@ -31,14 +34,16 @@ sealed class ConnectionMode {
3134
is NotConnected -> "NotConnected"
3235
is Derp -> "Derp($relayName)"
3336
is Direct -> "Direct"
37+
is PeerRelay -> "PeerRelay"
3438
}
3539
}
3640

3741
fun iconDrawable(): Int {
3842
return when (this) {
3943
is NotConnected -> R.drawable.xmark_circle
4044
is Derp -> R.drawable.link_off
41-
is Direct -> R.drawable.link
45+
is Direct -> R.drawable.arrow_right_alt_24px
46+
is PeerRelay -> R.drawable.redo_24px
4247
}
4348
}
4449

@@ -48,6 +53,7 @@ sealed class ConnectionMode {
4853
is NotConnected -> MaterialTheme.colorScheme.onPrimary
4954
is Derp -> MaterialTheme.colorScheme.error
5055
is Direct -> MaterialTheme.colorScheme.on
56+
is PeerRelay -> MaterialTheme.colorScheme.on
5157
}
5258
}
5359
}

android/src/main/java/com/tailscale/ipn/ui/viewModel/PingViewModel.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,12 @@ class PingViewModel : ViewModel() {
116116
result.Peer?.let { map ->
117117
map[peer.value?.Key]?.let { peerStatus ->
118118
val curAddr = peerStatus.CurAddr.orEmpty()
119+
val peerRelay = peerStatus.PeerRelay.orEmpty()
119120
val relay = peerStatus.Relay.orEmpty()
120121
if (curAddr.isNotEmpty()) {
121122
this.connectionMode.set(ConnectionMode.Direct())
123+
} else if (peerRelay.isNotEmpty()) {
124+
this.connectionMode.set(ConnectionMode.PeerRelay())
122125
} else if (relay.isNotEmpty()) {
123126
this.connectionMode.set(ConnectionMode.Derp(relayName = relay.uppercase()))
124127
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
2+
android:width="24dp"
3+
android:height="24dp"
4+
android:viewportWidth="960"
5+
android:viewportHeight="960"
6+
android:tint="?attr/colorControlNormal"
7+
android:autoMirrored="true">
8+
<path
9+
android:fillColor="@android:color/white"
10+
android:pathData="M560,720L504,662L646,520L160,520L160,440L646,440L504,298L560,240L800,480L560,720Z"/>
11+
</vector>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
2+
android:width="24dp"
3+
android:height="24dp"
4+
android:viewportWidth="960"
5+
android:viewportHeight="960"
6+
android:tint="?attr/colorControlNormal"
7+
android:autoMirrored="true">
8+
<path
9+
android:fillColor="@android:color/white"
10+
android:pathData="M396,760Q299,760 229.5,697Q160,634 160,540Q160,446 229.5,383Q299,320 396,320L648,320L544,216L600,160L800,360L600,560L544,504L648,400L396,400Q333,400 286.5,440Q240,480 240,540Q240,600 286.5,640Q333,680 396,680L680,680L680,760L396,760Z"/>
11+
</vector>

android/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,7 @@
303303
<string name="ping">Ping</string>
304304
<string name="relayed_connection">Relayed connection (%1$s)</string>
305305
<string name="direct_connection">Direct connection</string>
306+
<string name="peer_relayed_connection">Peer relayed connection</string>
306307
<string name="pinging_node_name">Pinging %1$s</string>
307308
<string name="pingFailed">Ping failed</string>
308309
<string name="an_unknown_error_occurred_please_try_again">An unknown error occurred. Please try again.</string>

0 commit comments

Comments
 (0)