diff options
author | Mikael Magnusson <mikma@users.sourceforge.net> | 2021-03-15 22:39:56 +0000 |
---|---|---|
committer | Mikael Magnusson <mikma@users.sourceforge.net> | 2023-02-07 22:43:23 +0100 |
commit | 279e9297b9700c6db9cef22d86755f5f8337ad35 (patch) | |
tree | 3ef226c1c23c9e37ea2918c7a110098d517de443 /ui/src/main | |
parent | 421bae85375dbef7fb64759eae22134d3c42a1fe (diff) |
WIP: add dhcp information to detail
Diffstat (limited to 'ui/src/main')
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 7046cb96..1f0eca5d 100644 --- a/ui/src/main/java/com/wireguard/android/fragment/TunnelDetailFragment.kt +++ b/ui/src/main/java/com/wireguard/android/fragment/TunnelDetailFragment.kt @@ -100,6 +100,10 @@ class TunnelDetailFragment : BaseFragment() { if (state != Tunnel.State.UP && lastState == state) return lastState = state 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 164fabf0..b8ffd8c5 100644 --- a/ui/src/main/res/layout/tunnel_detail_fragment.xml +++ b/ui/src/main/res/layout/tunnel_detail_fragment.xml @@ -293,14 +293,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 6c090199..515ef67d 100644 --- a/ui/src/main/res/values/strings.xml +++ b/ui/src/main/res/values/strings.xml @@ -237,4 +237,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> |