From 4efa4da4839e61e20eb42e6d0c9b77af61347665 Mon Sep 17 00:00:00 2001 From: Arne Schwabe Date: Mon, 13 Aug 2012 23:09:21 +0200 Subject: Allow editing the VPN Config from the log screen to ease configuration iterations --- res/menu/logmenu.xml | 8 +++- res/values-de/strings.xml | 7 +++- res/values/strings.xml | 5 +++ src/de/blinkt/openvpn/LogWindow.java | 68 ++++++++++++++++++++++++++----- src/de/blinkt/openvpn/OpenVpnService.java | 4 +- src/de/blinkt/openvpn/ProfileManager.java | 19 +++++++-- 6 files changed, 93 insertions(+), 18 deletions(-) diff --git a/res/menu/logmenu.xml b/res/menu/logmenu.xml index 1ab982d8..4b55e73b 100644 --- a/res/menu/logmenu.xml +++ b/res/menu/logmenu.xml @@ -25,5 +25,11 @@ android:showAsAction="ifRoom|withText" android:title="@string/send_logfile" android:titleCondensed="@string/send"/> - + + \ No newline at end of file diff --git a/res/values-de/strings.xml b/res/values-de/strings.xml index 0bc0577d..2256caff 100644 --- a/res/values-de/strings.xml +++ b/res/values-de/strings.xml @@ -189,7 +189,7 @@ Schnellstart Versuche das tun.ko Kernel Modul zu laden. Benötigt root. Lade tun Modul - + Warnung beim Verbinden und Benachrichtigungston Auf manchen ROM Version sind eventuell die Zugriffsrechte von /dev/tun falsch oder das tun Kernel Modul fehlt. Für Cyanogenmod 9 ROMs mit root gibt einen provisorischen Fix in den generellen Einstellungen. @@ -200,4 +200,9 @@ Nach Neustart verbinden Sie können ein Shortcut zum Starten des VPN auf Ihren Startbildschirm legen. Abhängig davon welches Home/Launcher Programm Sie verwenden müssen ein Widget, Shortcut oder Verknüpfung hinzufügen <a href=\"https://www.paypal.com/cgi-bin/webscr?hosted_button_id=R2M6ZP9AF25LS&amp;cmd=_s-xclick\">Spenden mit PayPal</a> + Ignorieren + Neu verbinden + Konfigurationsänderungen werden erst nach einem VPN Neustart aktiv. Jetzt neu verbinden? + Konfiguration geändert + Konnte das zuletzt verbundene Profile beim Versuch des Editieren nicht ermitteln. diff --git a/res/values/strings.xml b/res/values/strings.xml index d18c9563..29b7069d 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -244,4 +244,9 @@ You can <a href=\"https://www.paypal.com/cgi-bin/webscr?hosted_button_id=R2M6ZP9AF25LS&amp;cmd=_s-xclick\">donate with PayPal</a> OpenVPN will reconnect a VPN if it was active on system reboot/shutdown. Please read the Connection warning FAQ before using this option. Reconnect on reboot + Ignore + Restart + Configuration changes are applied after restarting the VPN. (Re)start the VPN now? + Configuration changed + Could not determine last connected profile for editing diff --git a/src/de/blinkt/openvpn/LogWindow.java b/src/de/blinkt/openvpn/LogWindow.java index 6cc257a5..94425fa8 100644 --- a/src/de/blinkt/openvpn/LogWindow.java +++ b/src/de/blinkt/openvpn/LogWindow.java @@ -32,6 +32,7 @@ import de.blinkt.openvpn.OpenVPN.LogListener; import de.blinkt.openvpn.OpenVPN.StateListener; public class LogWindow extends ListActivity implements StateListener { + private static final int START_VPN_CONFIG = 0; private String[] mBconfig=null; @@ -58,8 +59,8 @@ public class LogWindow extends ListActivity implements StateListener { OpenVPN.addLogListener(this); } - - + + private void initLogBuffer() { myEntries.clear(); for (LogItem litem : OpenVPN.getlogbuffer()) { @@ -70,7 +71,7 @@ public class LogWindow extends ListActivity implements StateListener { String getLogStr() { String str = ""; for(String entry:myEntries) { - str+=entry + '\n'; + str+=entry + '\n'; } return str; } @@ -205,15 +206,16 @@ public class LogWindow extends ListActivity implements StateListener { Builder builder = new AlertDialog.Builder(this); builder.setTitle(R.string.title_cancel); builder.setMessage(R.string.cancel_connection_query); + builder.setNegativeButton(android.R.string.no, null); builder.setPositiveButton(android.R.string.yes, new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { - ProfileManager.onBootDelete(getApplicationContext()); + ProfileManager.setConntectedVpnProfileDisconnected(getApplicationContext()); OpenVpnManagementThread.stopOpenVPN(); } }); - builder.setNegativeButton(android.R.string.no, null); + builder.show(); return true; } else if(item.getItemId()==R.id.info) { @@ -221,6 +223,18 @@ public class LogWindow extends ListActivity implements StateListener { OpenVPN.triggerLogBuilderConfig(); } else if(item.getItemId()==R.id.send) { ladapter.shareLog(); + } else if(item.getItemId()==R.id.edit_vpn) { + VpnProfile lastConnectedprofile = ProfileManager.getLastConnectedVpn(); + + if(lastConnectedprofile!=null) { + Intent vprefintent = new Intent(this,VPNPreferences.class) + .putExtra(VpnProfile.EXTRA_PROFILEUUID,lastConnectedprofile.getUUIDString()); + startActivityForResult(vprefintent,START_VPN_CONFIG); + } else { + Toast.makeText(this, R.string.log_no_last_vpn, Toast.LENGTH_LONG).show(); + } + + } return super.onOptionsItemSelected(item); @@ -240,6 +254,38 @@ public class LogWindow extends ListActivity implements StateListener { OpenVPN.addSpeedListener(this); } + @Override + protected void onActivityResult(int requestCode, int resultCode, Intent data) { + if (requestCode == START_VPN_CONFIG && resultCode==RESULT_OK) { + String configuredVPN = data.getStringExtra(VpnProfile.EXTRA_PROFILEUUID); + + final VpnProfile profile = ProfileManager.get(configuredVPN); + ProfileManager.getInstance(this).saveProfile(this, profile); + // Name could be modified, reset List adapter + + AlertDialog.Builder dialog = new AlertDialog.Builder(this); + dialog.setTitle(R.string.configuration_changed); + dialog.setMessage(R.string.restart_vpn_after_change); + + + dialog.setPositiveButton(R.string.restart, + new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + Intent intent = new Intent(getBaseContext(), LaunchVPN.class); + intent.putExtra(LaunchVPN.EXTRA_KEY, profile.getUUIDString()); + intent.setAction(Intent.ACTION_MAIN); + startActivity(intent); + } + + + }); + dialog.setNegativeButton(R.string.ignore, null); + dialog.create().show(); + } + super.onActivityResult(requestCode, resultCode, data); + } + @Override protected void onStop() { super.onStop(); @@ -252,14 +298,14 @@ public class LogWindow extends ListActivity implements StateListener { setContentView(R.layout.logwindow); ListView lv = getListView(); - + lv.setOnItemLongClickListener(new OnItemLongClickListener() { - + @Override public boolean onItemLongClick(AdapterView parent, View view, int position, long id) { ClipboardManager clipboard = (ClipboardManager) - getSystemService(Context.CLIPBOARD_SERVICE); + getSystemService(Context.CLIPBOARD_SERVICE); ClipData clip = ClipData.newPlainText("Log Entry",((TextView) view).getText()); clipboard.setPrimaryClip(clip); Toast.makeText(getBaseContext(), R.string.copied_entry, Toast.LENGTH_SHORT).show(); @@ -276,7 +322,7 @@ public class LogWindow extends ListActivity implements StateListener { @Override public void updateState(final String status,final String logmessage) { runOnUiThread(new Runnable() { - + @Override public void run() { String prefix=status+ ":"; @@ -285,9 +331,9 @@ public class LogWindow extends ListActivity implements StateListener { mSpeedView.setText(prefix + logmessage); } }); - + } - + @Override protected void onDestroy() { super.onDestroy(); diff --git a/src/de/blinkt/openvpn/OpenVpnService.java b/src/de/blinkt/openvpn/OpenVpnService.java index 01def8eb..594b07d4 100644 --- a/src/de/blinkt/openvpn/OpenVpnService.java +++ b/src/de/blinkt/openvpn/OpenVpnService.java @@ -67,7 +67,7 @@ public class OpenVpnService extends VpnService implements StateListener { OpenVpnManagementThread.stopOpenVPN(); mServiceThread=null; stopSelf(); - ProfileManager.onBootDelete(this); + ProfileManager.setConntectedVpnProfileDisconnected(this); }; private void hideNotification() { @@ -201,7 +201,7 @@ public class OpenVpnService extends VpnService implements StateListener { mServiceThread = new Thread(serviceThread, "OpenVPNServiceThread"); mServiceThread.start(); - ProfileManager.setOnBootProfile(this, mProfile); + ProfileManager.setConnectedVpnProfile(this, mProfile); return START_NOT_STICKY; } diff --git a/src/de/blinkt/openvpn/ProfileManager.java b/src/de/blinkt/openvpn/ProfileManager.java index 5d498c67..a40e6fcb 100644 --- a/src/de/blinkt/openvpn/ProfileManager.java +++ b/src/de/blinkt/openvpn/ProfileManager.java @@ -26,6 +26,10 @@ public class ProfileManager { private static ProfileManager instance; + + + + private static VpnProfile mLastConnectedVpn=null; private HashMap profiles=new HashMap(); @@ -52,7 +56,7 @@ public class ProfileManager { return instance; } - public static void onBootDelete(Context c) { + public static void setConntectedVpnProfileDisconnected(Context c) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(c); Editor prefsedit = prefs.edit(); prefsedit.putString(ONBOOTPROFILE, null); @@ -60,12 +64,13 @@ public class ProfileManager { } - public static void setOnBootProfile(Context c, VpnProfile bootprofile) { + public static void setConnectedVpnProfile(Context c, VpnProfile connectedrofile) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(c); Editor prefsedit = prefs.edit(); - prefsedit.putString(ONBOOTPROFILE, bootprofile.getUUIDString()); + prefsedit.putString(ONBOOTPROFILE, connectedrofile.getUUIDString()); prefsedit.apply(); + mLastConnectedVpn=connectedrofile; } @@ -183,6 +188,8 @@ public class ProfileManager { profiles.remove(vpnentry); saveProfileList(context); context.deleteFile(vpnentry + ".vp"); + if(mLastConnectedVpn==profile) + mLastConnectedVpn=null; } @@ -193,4 +200,10 @@ public class ProfileManager { return get(profileUUID); } + + + public static VpnProfile getLastConnectedVpn() { + return mLastConnectedVpn; + } + } -- cgit v1.2.3