From 7e3671e2bd04c0695d8b5bbdb1fe33b888253552 Mon Sep 17 00:00:00 2001 From: Arne Schwabe Date: Tue, 16 Apr 2013 20:17:45 +0200 Subject: Add states when requiring user input --- src/de/blinkt/openvpn/LaunchVPN.java | 24 +++++++++++++++++------- src/de/blinkt/openvpn/core/OpenVPN.java | 3 ++- src/de/blinkt/openvpn/core/OpenVpnService.java | 6 +++++- 3 files changed, 24 insertions(+), 9 deletions(-) (limited to 'src/de/blinkt/openvpn') diff --git a/src/de/blinkt/openvpn/LaunchVPN.java b/src/de/blinkt/openvpn/LaunchVPN.java index f07a77b9..80075086 100644 --- a/src/de/blinkt/openvpn/LaunchVPN.java +++ b/src/de/blinkt/openvpn/LaunchVPN.java @@ -26,6 +26,7 @@ import android.widget.EditText; import android.widget.ListView; import android.widget.TextView; import de.blinkt.openvpn.core.OpenVPN; +import de.blinkt.openvpn.core.OpenVPN.ConnectionStatus; import de.blinkt.openvpn.core.ProfileManager; import de.blinkt.openvpn.core.VPNLaunchHelper; @@ -61,7 +62,7 @@ public class LaunchVPN extends ListActivity implements OnItemClickListener { public static final String EXTRA_HIDELOG = "de.blinkt.openvpn.showNoLogWindow";; private static final int START_VPN_PROFILE= 70; - + private ProfileManager mPM; private VpnProfile mSelectedProfile; @@ -74,7 +75,7 @@ public class LaunchVPN extends ListActivity implements OnItemClickListener { super.onCreate(icicle); mPM =ProfileManager.getInstance(this); - + } @Override @@ -84,10 +85,10 @@ public class LaunchVPN extends ListActivity implements OnItemClickListener { final Intent intent = getIntent(); final String action = intent.getAction(); - + // If the intent is a request to create a shortcut, we'll do that and exit - + if(Intent.ACTION_MAIN.equals(action)) { // we got called to be the starting point, most likely a shortcut String shortcutUUID = intent.getStringExtra( EXTRA_KEY); @@ -201,7 +202,7 @@ public class LaunchVPN extends ListActivity implements OnItemClickListener { } - + private void askForPW(final int type) { @@ -234,6 +235,8 @@ public class LaunchVPN extends ListActivity implements OnItemClickListener { new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { + OpenVPN.updateStateString("USER_VPN_PASSWORD_CANCELLED", "", R.string.state_user_vpn_password_cancelled, + ConnectionStatus.LEVEL_NOTCONNECTED); finish(); } }); @@ -242,24 +245,29 @@ public class LaunchVPN extends ListActivity implements OnItemClickListener { } @Override - protected void onActivityResult(int requestCode, int resultCode, Intent data) { + protected void onActivityResult (int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if(requestCode==START_VPN_PROFILE) { if(resultCode == Activity.RESULT_OK) { int needpw = mSelectedProfile.needUserPWInput(); if(needpw !=0) { + OpenVPN.updateStateString("USER_VPN_PASSWORD", "", R.string.state_user_vpn_password, + ConnectionStatus.LEVEL_WAITING_FOR_USER_INPUT); askForPW(needpw); } else { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); boolean showlogwindow = prefs.getBoolean("showlogwindow", true); - + if(!mhideLog && showlogwindow) showLogWindow(); new startOpenVpnThread().start(); } } else if (resultCode == Activity.RESULT_CANCELED) { // User does not want us to start, so we just vanish + OpenVPN.updateStateString("USER_VPN_PERMISSION_CANCELLED", "", R.string.state_user_vpn_permission_cancelled, + ConnectionStatus.LEVEL_NOTCONNECTED); + finish(); } } @@ -309,6 +317,8 @@ public class LaunchVPN extends ListActivity implements OnItemClickListener { if (intent != null) { + OpenVPN.updateStateString("USER_VPN_PERMISSION", "", R.string.state_user_vpn_password, + ConnectionStatus.LEVEL_WAITING_FOR_USER_INPUT); // Start the query try { startActivityForResult(intent, START_VPN_PROFILE); diff --git a/src/de/blinkt/openvpn/core/OpenVPN.java b/src/de/blinkt/openvpn/core/OpenVPN.java index 2bc4cf6b..982a1e62 100644 --- a/src/de/blinkt/openvpn/core/OpenVPN.java +++ b/src/de/blinkt/openvpn/core/OpenVPN.java @@ -44,7 +44,8 @@ public class OpenVPN { public enum ConnectionStatus { LEVEL_NONETWORK (3), LEVEL_NOTCONNECTED (4), - LEVEL_AUTH_FAILED ( 5), + LEVEL_AUTH_FAILED (5), + LEVEL_WAITING_FOR_USER_INPUT (6), LEVEL_CONNECTING_SERVER_REPLIED ( 1), LEVEL_CONNECTING_NO_SERVER_REPLY_YET (2), LEVEL_CONNECTED (0), UNKNOWN_LEVEL(-1); diff --git a/src/de/blinkt/openvpn/core/OpenVpnService.java b/src/de/blinkt/openvpn/core/OpenVpnService.java index 4dba80f1..d86ae92b 100644 --- a/src/de/blinkt/openvpn/core/OpenVpnService.java +++ b/src/de/blinkt/openvpn/core/OpenVpnService.java @@ -541,7 +541,11 @@ public class OpenVpnService extends VpnService implements StateListener, Callbac // Display byte count only after being connected { - if(level == ConnectionStatus.LEVEL_CONNECTED) { + if (level == ConnectionStatus.LEVEL_WAITING_FOR_USER_INPUT) { + // The user is presented a dialog of some kind, no need to inform the user + // with a notifcation + return; + } else if(level == ConnectionStatus.LEVEL_CONNECTED) { mDisplayBytecount = true; mConnecttime = System.currentTimeMillis(); } else { -- cgit v1.2.3