diff options
author | Arne Schwabe <arne@rfc2549.org> | 2013-06-05 14:39:48 +0200 |
---|---|---|
committer | Arne Schwabe <arne@rfc2549.org> | 2013-06-05 14:39:48 +0200 |
commit | 1e57ad0ef473917864ea1f5983e2ca79932b30c6 (patch) | |
tree | 7694f21563e50f95a75704758ea8752e69fabdb0 /src | |
parent | 1c900c0ee6de4af5d5fb46ebdaf7ed1929804f5a (diff) |
Add support for asking username/password if none is set (closes issue #174)
Diffstat (limited to 'src')
-rw-r--r-- | src/de/blinkt/openvpn/LaunchVPN.java | 57 | ||||
-rw-r--r-- | src/de/blinkt/openvpn/VpnProfile.java | 7 | ||||
-rw-r--r-- | src/de/blinkt/openvpn/core/DeviceStateReceiver.java | 1 |
3 files changed, 42 insertions, 23 deletions
diff --git a/src/de/blinkt/openvpn/LaunchVPN.java b/src/de/blinkt/openvpn/LaunchVPN.java index 80075086..074bd235 100644 --- a/src/de/blinkt/openvpn/LaunchVPN.java +++ b/src/de/blinkt/openvpn/LaunchVPN.java @@ -17,12 +17,16 @@ import android.os.Bundle; import android.os.Parcelable; import android.preference.PreferenceManager; import android.text.InputType; +import android.text.Layout; +import android.text.TextUtils; import android.text.method.PasswordTransformationMethod; import android.view.View; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.ArrayAdapter; +import android.widget.CheckBox; import android.widget.EditText; +import android.widget.LinearLayout; import android.widget.ListView; import android.widget.TextView; import de.blinkt.openvpn.core.OpenVPN; @@ -207,6 +211,8 @@ public class LaunchVPN extends ListActivity implements OnItemClickListener { private void askForPW(final int type) { final EditText entry = new EditText(this); + final View userpwlayout = getLayoutInflater().inflate(R.layout.userpass, null); + entry.setSingleLine(); entry.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD); entry.setTransformationMethod(new PasswordTransformationMethod()); @@ -214,24 +220,41 @@ public class LaunchVPN extends ListActivity implements OnItemClickListener { AlertDialog.Builder dialog = new AlertDialog.Builder(this); dialog.setTitle("Need " + getString(type)); dialog.setMessage("Enter the password for profile " + mSelectedProfile.mName); - dialog.setView(entry); - - dialog.setPositiveButton(android.R.string.ok, - new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - String pw = entry.getText().toString(); - if(type == R.string.password) { - mSelectedProfile.mTransientPW = pw; - } else { - mSelectedProfile.mTransientPCKS12PW = pw; - } - onActivityResult(START_VPN_PROFILE, Activity.RESULT_OK, null); - } - - }); - dialog.setNegativeButton(android.R.string.cancel, + if (type == R.string.password) { + ((EditText)userpwlayout.findViewById(R.id.username)).setText(mSelectedProfile.mUsername); + ((EditText)userpwlayout.findViewById(R.id.password)).setText(mSelectedProfile.mPassword); + dialog.setView(userpwlayout); + } else { + dialog.setView(entry); + } + + AlertDialog.Builder builder = dialog.setPositiveButton(android.R.string.ok, + new OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + + if (type == R.string.password) { + String pw = ((EditText) userpwlayout.findViewById(R.id.password)).getText().toString(); + String username = ((EditText) userpwlayout.findViewById(R.id.username)).getText().toString(); + mSelectedProfile.mUsername = username; + if (((CheckBox) userpwlayout.findViewById(R.id.save_password)).isChecked()) { + if (pw !=null && !("".equals(pw))) + mSelectedProfile.mPassword=pw; + } else { + mSelectedProfile.mPassword=null; + mSelectedProfile.mTransientPW = pw; + } + } else { + String pw = entry.getText().toString(); + mSelectedProfile.mTransientPCKS12PW = pw; + } + onActivityResult(START_VPN_PROFILE, Activity.RESULT_OK, null); + + } + + }); + dialog.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { diff --git a/src/de/blinkt/openvpn/VpnProfile.java b/src/de/blinkt/openvpn/VpnProfile.java index 03fcbc1b..dcca334c 100644 --- a/src/de/blinkt/openvpn/VpnProfile.java +++ b/src/de/blinkt/openvpn/VpnProfile.java @@ -659,9 +659,6 @@ public class VpnProfile implements Serializable{ if(mIPv4Address == null || cidrToIPAndNetmask(mIPv4Address) == null) return R.string.ipv4_format_error; } - if(isUserPWAuth() && !nonNull(mUsername)) { - return R.string.error_empty_username; - } if(!mUseDefaultRoute && getCustomRoutes()==null) return R.string.custom_route_format_error; @@ -757,10 +754,8 @@ public class VpnProfile implements Serializable{ } } - if(isUserPWAuth() && (mPassword.equals("") || mPassword == null)) { - if(mTransientPW==null) + if (isUserPWAuth() && !(nonNull(mUsername) && (nonNull(mPassword) || mTransientPW!=null))) { return R.string.password; - } return 0; } diff --git a/src/de/blinkt/openvpn/core/DeviceStateReceiver.java b/src/de/blinkt/openvpn/core/DeviceStateReceiver.java index 7d6e80db..b27ea00f 100644 --- a/src/de/blinkt/openvpn/core/DeviceStateReceiver.java +++ b/src/de/blinkt/openvpn/core/DeviceStateReceiver.java @@ -70,6 +70,7 @@ public class DeviceStateReceiver extends BroadcastReceiver implements ByteCountL screen = connectState.DISCONNECTED;
OpenVPN.logInfo(R.string.screenoff_pause,
OpenVpnService.humanReadableByteCount(TRAFFIC_LIMIT, false), TRAFFIC_WINDOW);
+
mManangement.pause();
}
Log.i("OpenVPN", String.format("State: %s %s total %d last %d time %d",network.name(), screen.name(),windowtraffic/1024,
|