summaryrefslogtreecommitdiff
path: root/main
diff options
context:
space:
mode:
authorArne Schwabe <arne@rfc2549.org>2016-01-07 15:29:37 +0100
committerArne Schwabe <arne@rfc2549.org>2016-01-07 15:29:37 +0100
commita3354eb8ca16240ae869e8a86611528c6ab651d3 (patch)
treee8c41d6376f714fb2cb60227b8743e46f54e0001 /main
parent7dc3bb722082ffd3b8d8e375c5dd98f981aa0022 (diff)
Show VPN Status in profile list, tweak Status reporting
Diffstat (limited to 'main')
-rw-r--r--main/src/main/java/de/blinkt/openvpn/core/ConfigParser.java2
-rw-r--r--main/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java2
-rw-r--r--main/src/main/java/de/blinkt/openvpn/core/VPNLaunchHelper.java5
-rw-r--r--main/src/main/java/de/blinkt/openvpn/core/VpnStatus.java30
-rw-r--r--main/src/main/java/de/blinkt/openvpn/fragments/LogFragment.java9
-rw-r--r--main/src/main/java/de/blinkt/openvpn/fragments/VPNProfileList.java44
-rw-r--r--main/src/main/res/layout/vpn_list_item.xml48
7 files changed, 97 insertions, 43 deletions
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<String> 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<VpnProfile> {
@@ -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;
}
}
@@ -123,6 +147,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) {
View v = inflater.inflate(R.layout.vpn_profile_list, container, false);
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 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
+<?xml version="1.0" encoding="utf-8"?><!--
Copyright (C) 2011 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
@@ -16,38 +15,49 @@
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:tools="http://schemas.android.com/tools"
- android:layout_width="match_parent"
+ xmlns:tools="http://schemas.android.com/tools"
+ android:layout_width="match_parent"
android:layout_height="wrap_content"
+ android:focusable="false"
android:gravity="center_vertical"
- android:minHeight="?android:attr/listPreferredItemHeight"
- android:focusable="false">
+ android:minHeight="?android:attr/listPreferredItemHeight">
<LinearLayout
android:id="@+id/vpn_list_item_left"
- android:layout_width="0dp"
android:layout_height="match_parent"
- android:layout_weight="1"
+ android:layout_width="wrap_content"
android:background="?android:attr/selectableItemBackground"
- android:gravity="center_vertical"
- android:focusable="true">
+ android:focusable="true"
+ android:layout_weight="1"
+ android:gravity="center_vertical">
<LinearLayout
android:id="@android:id/widget_frame"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center_vertical"
- android:orientation="vertical" />
+ android:orientation="vertical">
- <TextView
+ <TextView
android:id="@+id/vpn_item_title"
- tools:text="Vpn Name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:fadingEdge="horizontal"
android:singleLine="true"
- android:textAppearance="?android:attr/textAppearanceMedium" />
+ android:textAppearance="?android:attr/textAppearanceMedium"
+ tools:text="Vpn Name" />
+
+ <TextView
+ android:id="@+id/vpn_item_subtitle"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:ellipsize="marquee"
+ android:fadingEdge="horizontal"
+ android:singleLine="true"
+ android:textAppearance="?android:attr/textAppearanceSmall"
+ tools:text="Not connected!" />
+ </LinearLayout>
</LinearLayout>
@@ -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" />
<ImageView
android:id="@+id/quickedit_settings"
@@ -66,9 +76,11 @@
android:layout_gravity="center"
android:background="?android:attr/selectableItemBackground"
android:contentDescription="@string/configure_the_vpn"
+ android:focusable="true"
+ android:paddingEnd="?android:attr/scrollbarSize"
android:paddingLeft="15dip"
android:paddingRight="?android:attr/scrollbarSize"
- android:src="@drawable/vpn_item_edit"
- android:focusable="true"/>
+ android:paddingStart="15dip"
+ android:src="@drawable/vpn_item_edit" />
</LinearLayout> \ No newline at end of file