diff options
author | Mikael Magnusson <mikma@users.sourceforge.net> | 2021-03-13 21:58:21 +0000 |
---|---|---|
committer | Mikael Magnusson <mikma@users.sourceforge.net> | 2023-02-10 21:30:04 +0100 |
commit | 6141eafb86c9dc72d39784b86d2136b25ea269f6 (patch) | |
tree | b8ad8a13fdaa784ef74eec08ef9b35148c30be80 /ui/src | |
parent | 8cd49f9a8d3e14568d7c0fda696fe62efb14d0e9 (diff) |
dhcp
WIP: implement wgOnEvent
WIP: debug
WIP: netstack: implement dhcp and ipvlan
WIP: implement dhcp in tunnel
WIP: add dhcp information to detail
Diffstat (limited to 'ui/src')
5 files changed, 71 insertions, 2 deletions
diff --git a/ui/src/main/java/com/wireguard/android/fragment/TunnelDetailFragment.kt b/ui/src/main/java/com/wireguard/android/fragment/TunnelDetailFragment.kt index fad1b5d4..f2cf9040 100644 --- a/ui/src/main/java/com/wireguard/android/fragment/TunnelDetailFragment.kt +++ b/ui/src/main/java/com/wireguard/android/fragment/TunnelDetailFragment.kt @@ -104,6 +104,10 @@ class TunnelDetailFragment : BaseFragment() { lastState = state var now = LocalDateTime.now(ZoneId.of("UTC")) try { + binding.dhcpInfoText.text = tunnel.getDhcpInfo().get() + binding.dhcpInfoLabel.visibility = View.VISIBLE + binding.dhcpInfoText.visibility = View.VISIBLE + val statistics = tunnel.getStatisticsAsync() for (i in 0 until binding.peersLayout.childCount) { val peer: TunnelDetailPeerBinding = DataBindingUtil.getBinding(binding.peersLayout.getChildAt(i)) diff --git a/ui/src/main/java/com/wireguard/android/model/ObservableTunnel.kt b/ui/src/main/java/com/wireguard/android/model/ObservableTunnel.kt index 252e8759..edf8feaf 100644 --- a/ui/src/main/java/com/wireguard/android/model/ObservableTunnel.kt +++ b/ui/src/main/java/com/wireguard/android/model/ObservableTunnel.kt @@ -8,6 +8,7 @@ import android.util.Log import androidx.databinding.BaseObservable import androidx.databinding.Bindable import com.wireguard.android.BR +import com.wireguard.android.backend.DhcpInfo import com.wireguard.android.backend.Statistics import com.wireguard.android.backend.Tunnel import com.wireguard.android.databinding.Keyed @@ -136,6 +137,35 @@ class ObservableTunnel internal constructor( return statistics } + @get:Bindable + var dhcpInfo: DhcpInfo? = null + get() { + if (field == null || field?.isStale != false) + applicationScope.launch { + try { + manager.getTunnelDhcpInfo(this@ObservableTunnel) + } catch (e: Throwable) { + Log.e(TAG, Log.getStackTraceString(e)) + } + } + return field + } + private set + + suspend fun getDhcpInfo(): DhcpInfo = withContext(Dispatchers.Main.immediate) { + dhcpInfo.let { + if (it == null || it.isStale) + manager.getTunnelDhcpInfo(this@ObservableTunnel) + else + it + } + } + + fun onDhcpInfoChanged(dhcpInfo: DhcpInfo?): DhcpInfo? { + this.dhcpInfo = dhcpInfo + notifyPropertyChanged(BR.dhcpInfo) + return dhcpInfo + } suspend fun deleteAsync() = manager.delete(this) diff --git a/ui/src/main/java/com/wireguard/android/model/TunnelManager.kt b/ui/src/main/java/com/wireguard/android/model/TunnelManager.kt index ec796164..ac39ac4a 100644 --- a/ui/src/main/java/com/wireguard/android/model/TunnelManager.kt +++ b/ui/src/main/java/com/wireguard/android/model/TunnelManager.kt @@ -17,6 +17,7 @@ import com.wireguard.android.Application.Companion.getBackend import com.wireguard.android.Application.Companion.getTunnelManager import com.wireguard.android.BR import com.wireguard.android.R +import com.wireguard.android.backend.DhcpInfo import com.wireguard.android.backend.Statistics import com.wireguard.android.backend.Tunnel import com.wireguard.android.configStore.ConfigStore @@ -240,6 +241,10 @@ class TunnelManager(private val configStore: ConfigStore) : BaseObservable() { } } + suspend fun getTunnelDhcpInfo(tunnel: ObservableTunnel): DhcpInfo = withContext(Dispatchers.Main.immediate) { + tunnel.onDhcpInfoChanged(withContext(Dispatchers.IO) { getBackend().getDhcpInfo(tunnel) })!! + } + suspend fun getTunnelState(tunnel: ObservableTunnel): Tunnel.State = withContext(Dispatchers.Main.immediate) { tunnel.onStateChanged(withContext(Dispatchers.IO) { getBackend().getState(tunnel) }) } diff --git a/ui/src/main/res/layout/tunnel_detail_fragment.xml b/ui/src/main/res/layout/tunnel_detail_fragment.xml index aef71e18..c004fc5a 100644 --- a/ui/src/main/res/layout/tunnel_detail_fragment.xml +++ b/ui/src/main/res/layout/tunnel_detail_fragment.xml @@ -322,14 +322,42 @@ android:layout_height="wrap_content" android:contentDescription="@string/applications" android:nextFocusUp="@id/mtu_text" - android:nextFocusDown="@id/peers_layout" - android:nextFocusForward="@id/peers_layout" + android:nextFocusDown="@id/dhcp_info_text" + android:nextFocusForward="@id/dhcp_info_text" android:onClick="@{ClipboardUtils::copyTextView}" android:text="@{config.interface.includedApplications.isEmpty() ? @plurals/n_excluded_applications(config.interface.excludedApplications.size(), config.interface.excludedApplications.size()) : @plurals/n_included_applications(config.interface.includedApplications.size(), config.interface.includedApplications.size())}" android:visibility="@{config.interface.includedApplications.isEmpty() && config.interface.excludedApplications.isEmpty() ? android.view.View.GONE : android.view.View.VISIBLE}" app:layout_constraintTop_toBottomOf="@+id/applications_label" app:layout_constraintStart_toStartOf="parent" tools:text="8 excluded" /> + + <TextView + android:id="@+id/dhcp_info_label" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_marginTop="8dp" + android:labelFor="@+id/dhcp_info_text" + android:text="@string/dhcp_info" + android:visibility="gone" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toBottomOf="@id/applications_text" /> + + <TextView + android:id="@+id/dhcp_info_text" + style="@style/DetailText" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:contentDescription="@string/dhcp_info" + android:nextFocusUp="@id/applications_text" + android:nextFocusDown="@id/peers_layout" + android:nextFocusForward="@id/peers_layout" + android:onClick="@{ClipboardUtils::copyTextView}" + android:visibility="gone" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toBottomOf="@+id/dhcp_info_label" + tools:text="Addresses: 192.0.2.123/24, 2001:db8::123/128" + tools:visibility="visible" /> + </androidx.constraintlayout.widget.ConstraintLayout> </com.google.android.material.card.MaterialCardView> diff --git a/ui/src/main/res/values/strings.xml b/ui/src/main/res/values/strings.xml index 3b32ab79..4da4e8fe 100644 --- a/ui/src/main/res/values/strings.xml +++ b/ui/src/main/res/values/strings.xml @@ -248,4 +248,6 @@ <string name="biometric_prompt_private_key_title">Authenticate to view private key</string> <string name="biometric_auth_error">Authentication failure</string> <string name="biometric_auth_error_reason">Authentication failure: %s</string> + <string name="dhcp_info">DHCP information</string> + <string name="dhcp_info_text">Addresses: %s\nIPv6 prefixes: %s\nDNS servers: %s</string> </resources> |