From c3289433eeb53635dc27a7222e827008e4de645d Mon Sep 17 00:00:00 2001 From: Arne Schwabe Date: Mon, 7 Dec 2015 11:10:05 +0100 Subject: Use new status message and make connected status a bit nicer --- .../de/blinkt/openvpn/core/OpenVPNService.java | 3 ++- .../java/de/blinkt/openvpn/core/VpnStatus.java | 27 ++++++++++++++++++++++ .../de/blinkt/openvpn/fragments/LogFragment.java | 8 ++++--- main/src/main/res/values/strings.xml | 2 +- 4 files changed, 35 insertions(+), 5 deletions(-) (limited to 'main') diff --git a/main/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java b/main/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java index 7637df95..f0c788ee 100644 --- a/main/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java +++ b/main/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java @@ -860,7 +860,8 @@ public class OpenVPNService extends VpnService implements StateListener, Callbac // CONNECTED // Does not work :( String msg = getString(resid); - showNotification(msg + " " + logmessage, msg, lowpriority, 0, level); + showNotification(msg + " " + VpnStatus.getCleanLogMessage(level, logmessage), + msg, lowpriority, 0, level); } } diff --git a/main/src/main/java/de/blinkt/openvpn/core/VpnStatus.java b/main/src/main/java/de/blinkt/openvpn/core/VpnStatus.java index 78deb7d3..1f866ab7 100644 --- a/main/src/main/java/de/blinkt/openvpn/core/VpnStatus.java +++ b/main/src/main/java/de/blinkt/openvpn/core/VpnStatus.java @@ -73,6 +73,33 @@ public class VpnStatus { private static final int MAXLOGENTRIES = 1000; + public static String getCleanLogMessage(ConnectionStatus level, String logMessage) { + switch (level) { + case LEVEL_CONNECTED: + String[] parts = logMessage.split(","); + /* + (a) the integer unix date/time, + (b) the state name, + 0 (c) optional descriptive string (used mostly on RECONNECTING + and EXITING to show the reason for the disconnect), + + 1 (d) optional TUN/TAP local IPv4 address + 2 (e) optional address of remote server, + 3 (f) optional port of remote server, + 4 (g) optional local address, + 5 (h) optional local port, and + 6 (i) optional TUN/TAP local IPv6 address. +*/ + // Return only the assigned IP addresses in the UI + if (parts.length < 7) + return logMessage; + return String.format(Locale.US, "%s %s", parts[1], parts[6]); + default: + return logMessage; + } + + } + public enum ConnectionStatus { LEVEL_CONNECTED, LEVEL_VPNPAUSED, diff --git a/main/src/main/java/de/blinkt/openvpn/fragments/LogFragment.java b/main/src/main/java/de/blinkt/openvpn/fragments/LogFragment.java index e1031e33..fb6f8371 100644 --- a/main/src/main/java/de/blinkt/openvpn/fragments/LogFragment.java +++ b/main/src/main/java/de/blinkt/openvpn/fragments/LogFragment.java @@ -650,6 +650,8 @@ public class LogFragment extends ListFragment implements StateListener, SeekBar. @Override public void updateState(final String status, final String logMessage, final int resId, final ConnectionStatus level) { if (isAdded()) { + final String cleanLogMessage = VpnStatus.getCleanLogMessage(level, logMessage); + getActivity().runOnUiThread(new Runnable() { @Override @@ -660,9 +662,9 @@ public class LogFragment extends ListFragment implements StateListener, SeekBar. prefix = ""; if (resId == R.string.unknown_state) prefix += status; - if (mSpeedView != null) - mSpeedView.setText(prefix + logMessage); - + if (mSpeedView != null) { + mSpeedView.setText(prefix + cleanLogMessage); + } if (mConnectStatus != null) mConnectStatus.setText(getString(resId)); } diff --git a/main/src/main/res/values/strings.xml b/main/src/main/res/values/strings.xml index 5bafcc04..251c1e8e 100755 --- a/main/src/main/res/values/strings.xml +++ b/main/src/main/res/values/strings.xml @@ -192,7 +192,7 @@ No DNS servers being used. Name resolution may not work. Consider setting custom DNS Servers. Please also note that Android will keep using your proxy settings specified for your mobile/Wi-Fi connection when no DNS servers are set. Could not add DNS Server \"%1$s\", rejected by the system: %2$s Could not configure IP Address \"%1$s\", rejected by the system: %2$s - <p>Get a working config (tested on your computer or download from your provider/organisation)</p><p>If it is a single file with no extra pem/pks12 files you can email the file yourself and open the attachment. If you have multiple files put them on your sd card.</p><p>Click on the email attachment/Use the folder icon in the vpn list to import the config file</p><p>If there are errors about missing files put the missing files on your sd card.</p><p>Click on the save symbol to add the imported VPN to your VPN list</p><p>Connect the VPN by clicking on the name of the VPN</p><p>If there are error or warnings in the log try to understand the warnings/error and try to fix them</p> + <p>Get a working config (tested on your computer or download from your provider/organisation)</p><p>If it is a single file with no extra pem/pkcs12 files you can email the file yourself and open the attachment. If you have multiple files put them on your sd card.</p><p>Click on the email attachment/Use the folder icon in the vpn list to import the config file</p><p>If there are errors about missing files put the missing files on your sd card.</p><p>Click on the save symbol to add the imported VPN to your VPN list</p><p>Connect the VPN by clicking on the name of the VPN</p><p>If there are error or warnings in the log try to understand the warnings/error and try to fix them</p> Quick Start Try to load the tun.ko kernel module before trying to connect. Needs rooted devices. Load tun module -- cgit v1.2.3