From a3354eb8ca16240ae869e8a86611528c6ab651d3 Mon Sep 17 00:00:00 2001 From: Arne Schwabe Date: Thu, 7 Jan 2016 15:29:37 +0100 Subject: Show VPN Status in profile list, tweak Status reporting --- .../java/de/blinkt/openvpn/core/ConfigParser.java | 2 +- .../de/blinkt/openvpn/core/OpenVPNService.java | 2 +- .../de/blinkt/openvpn/core/VPNLaunchHelper.java | 5 ++- .../java/de/blinkt/openvpn/core/VpnStatus.java | 30 +++++++++----- .../de/blinkt/openvpn/fragments/LogFragment.java | 9 +--- .../blinkt/openvpn/fragments/VPNProfileList.java | 44 ++++++++++++++++++-- main/src/main/res/layout/vpn_list_item.xml | 48 ++++++++++++++-------- 7 files changed, 97 insertions(+), 43 deletions(-) (limited to 'main/src') diff --git a/main/src/main/java/de/blinkt/openvpn/core/ConfigParser.java b/main/src/main/java/de/blinkt/openvpn/core/ConfigParser.java index 0438022b..5b8cb2dd 100644 --- a/main/src/main/java/de/blinkt/openvpn/core/ConfigParser.java +++ b/main/src/main/java/de/blinkt/openvpn/core/ConfigParser.java @@ -398,7 +398,7 @@ public class ConfigParser { np.mCustomRoutesv6 = customIPv6Routes; } - + Vector routeNoPull = getOption("route-nopull", 1, 1); np.mRoutenopull=true; 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 f0c788ee..cbe92460 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,7 @@ public class OpenVPNService extends VpnService implements StateListener, Callbac // CONNECTED // Does not work :( String msg = getString(resid); - showNotification(msg + " " + VpnStatus.getCleanLogMessage(level, logmessage), + showNotification(VpnStatus.getLastCleanLogMessage(this), msg, lowpriority, 0, level); } diff --git a/main/src/main/java/de/blinkt/openvpn/core/VPNLaunchHelper.java b/main/src/main/java/de/blinkt/openvpn/core/VPNLaunchHelper.java index 72f21ce3..73a1c3f0 100644 --- a/main/src/main/java/de/blinkt/openvpn/core/VPNLaunchHelper.java +++ b/main/src/main/java/de/blinkt/openvpn/core/VPNLaunchHelper.java @@ -126,12 +126,13 @@ public class VPNLaunchHelper { public static void startOpenVpn(VpnProfile startprofile, Context context) { - if(writeMiniVPN(context)==null) { + VpnStatus.logInfo(R.string.building_configration); + VpnStatus.updateStateString("VPN_GENERATE_CONFIG", "", R.string.building_configration, VpnStatus.ConnectionStatus.LEVEL_START); + if(writeMiniVPN(context)==null) { VpnStatus.logError("Error writing minivpn binary"); return; } - VpnStatus.logInfo(R.string.building_configration); Intent startVPN = startprofile.prepareStartService(context); if(startVPN!=null) 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 1f866ab7..c0f958c4 100644 --- a/main/src/main/java/de/blinkt/openvpn/core/VpnStatus.java +++ b/main/src/main/java/de/blinkt/openvpn/core/VpnStatus.java @@ -73,10 +73,12 @@ public class VpnStatus { private static final int MAXLOGENTRIES = 1000; - public static String getCleanLogMessage(ConnectionStatus level, String logMessage) { - switch (level) { + + public static String getLastCleanLogMessage(Context c) { + String message = mLaststatemsg; + switch (mLastLevel) { case LEVEL_CONNECTED: - String[] parts = logMessage.split(","); + String[] parts = mLaststatemsg.split(","); /* (a) the integer unix date/time, (b) the state name, @@ -90,14 +92,21 @@ public class VpnStatus { 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; + // Return only the assigned IP addresses in the UI + if (parts.length >= 7) + message = String.format(Locale.US, "%s %s", parts[1], parts[6]); + break; } + String prefix = c.getString(mLastStateresid) + ":"; + String status = mLaststate; + if (status.equals("NOPROCESS")) + prefix = ""; + if (mLastStateresid == R.string.unknown_state) + prefix += status; + + return prefix + message; + } public enum ConnectionStatus { @@ -107,9 +116,10 @@ public class VpnStatus { LEVEL_CONNECTING_NO_SERVER_REPLY_YET, LEVEL_NONETWORK, LEVEL_NOTCONNECTED, + LEVEL_START, LEVEL_AUTH_FAILED, LEVEL_WAITING_FOR_USER_INPUT, - UNKNOWN_LEVEL + UNKNOWN_LEVEL; } public enum LogLevel { 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 fb6f8371..d197efd9 100644 --- a/main/src/main/java/de/blinkt/openvpn/fragments/LogFragment.java +++ b/main/src/main/java/de/blinkt/openvpn/fragments/LogFragment.java @@ -650,20 +650,15 @@ 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); + final String cleanLogMessage = VpnStatus.getLastCleanLogMessage(getActivity()); getActivity().runOnUiThread(new Runnable() { @Override public void run() { if (isAdded()) { - String prefix = getString(resId) + ":"; - if (status.equals("BYTECOUNT") || status.equals("NOPROCESS")) - prefix = ""; - if (resId == R.string.unknown_state) - prefix += status; if (mSpeedView != null) { - mSpeedView.setText(prefix + cleanLogMessage); + mSpeedView.setText(cleanLogMessage); } if (mConnectStatus != null) mConnectStatus.setText(getString(resId)); diff --git a/main/src/main/java/de/blinkt/openvpn/fragments/VPNProfileList.java b/main/src/main/java/de/blinkt/openvpn/fragments/VPNProfileList.java index cf712e7c..0b161615 100644 --- a/main/src/main/java/de/blinkt/openvpn/fragments/VPNProfileList.java +++ b/main/src/main/java/de/blinkt/openvpn/fragments/VPNProfileList.java @@ -31,12 +31,14 @@ import de.blinkt.openvpn.activities.ConfigConverter; import de.blinkt.openvpn.activities.FileSelect; import de.blinkt.openvpn.activities.VPNPreferences; import de.blinkt.openvpn.core.ProfileManager; +import de.blinkt.openvpn.core.VpnStatus; import java.util.Collection; import java.util.Comparator; import java.util.TreeSet; -public class VPNProfileList extends ListFragment implements OnClickListener { + +public class VPNProfileList extends ListFragment implements OnClickListener, VpnStatus.StateListener { public final static int RESULT_VPN_DELETED = Activity.RESULT_FIRST_USER; public final static int RESULT_VPN_DUPLICATE = Activity.RESULT_FIRST_USER + 1; @@ -49,6 +51,18 @@ public class VPNProfileList extends ListFragment implements OnClickListener { private static final int FILE_PICKER_RESULT_KITKAT = 392; private static final int MENU_IMPORT_PROFILE = Menu.FIRST + 1; + private String mLastStatusMessage; + + @Override + public void updateState(String state, String logmessage, final int localizedResId, VpnStatus.ConnectionStatus level) { + getActivity().runOnUiThread(new Runnable() { + @Override + public void run() { + mLastStatusMessage = getString(localizedResId); + mArrayadapter.notifyDataSetChanged(); + } + }); + } class VPNArrayAdapter extends ArrayAdapter { @@ -62,11 +76,12 @@ public class VPNProfileList extends ListFragment implements OnClickListener { public View getView(final int position, View convertView, ViewGroup parent) { View v = super.getView(position, convertView, parent); + final VpnProfile profile = (VpnProfile) getListAdapter().getItem(position); + View titleview = v.findViewById(R.id.vpn_list_item_left); titleview.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { - VpnProfile profile = (VpnProfile) getListAdapter().getItem(position); startVPN(profile); } }); @@ -76,12 +91,21 @@ public class VPNProfileList extends ListFragment implements OnClickListener { @Override public void onClick(View v) { - VpnProfile editProfile = (VpnProfile) getListAdapter().getItem(position); - editVPN(editProfile); + editVPN(profile); } }); + TextView subtitle = (TextView) v.findViewById(R.id.vpn_item_subtitle); + if (ProfileManager.getLastConnectedVpn() == profile) { + subtitle.setText(mLastStatusMessage); + subtitle.setVisibility(View.VISIBLE); + } else { + subtitle.setText(""); + subtitle.setVisibility(View.GONE); + } + + return v; } } @@ -122,6 +146,18 @@ public class VPNProfileList extends ListFragment implements OnClickListener { } + @Override + public void onResume() { + super.onResume(); + VpnStatus.addStateListener(this); + } + + @Override + public void onPause() { + super.onPause(); + VpnStatus.removeStateListener(this); + } + @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { diff --git a/main/src/main/res/layout/vpn_list_item.xml b/main/src/main/res/layout/vpn_list_item.xml index c385166c..5f2e8d0b 100644 --- a/main/src/main/res/layout/vpn_list_item.xml +++ b/main/src/main/res/layout/vpn_list_item.xml @@ -1,5 +1,4 @@ - - + android:minHeight="?android:attr/listPreferredItemHeight"> + android:focusable="true" + android:layout_weight="1" + android:gravity="center_vertical"> + android:orientation="vertical"> - + android:textAppearance="?android:attr/textAppearanceMedium" + tools:text="Vpn Name" /> + + + @@ -55,9 +65,9 @@ android:layout_width="2dip" android:layout_height="match_parent" android:layout_marginBottom="5dip" - android:focusable="false" android:layout_marginTop="5dip" - android:background="@android:drawable/divider_horizontal_dark" /> + android:background="@android:drawable/divider_horizontal_dark" + android:focusable="false" /> + android:paddingStart="15dip" + android:src="@drawable/vpn_item_edit" /> \ No newline at end of file -- cgit v1.2.3