summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArne Schwabe <arne@rfc2549.org>2012-08-12 18:52:38 +0200
committerArne Schwabe <arne@rfc2549.org>2012-08-12 18:52:38 +0200
commit5e7b841c8d5111e6b63e74944903a168939ca723 (patch)
treef782a9d293893393ce9222a7fe9b29ae46ef91d9
parent5438e464aaf326973938fee31d91bfdd7ece8f63 (diff)
Implement starting a VPN on boot. (closes issue #62)
-rw-r--r--AndroidManifest.xml24
-rw-r--r--res/values-de/strings.xml2
-rw-r--r--res/values/strings.xml2
-rw-r--r--res/xml/general_settings.xml6
-rw-r--r--src/de/blinkt/openvpn/LaunchVPN.java19
-rw-r--r--src/de/blinkt/openvpn/LogWindow.java3
-rw-r--r--src/de/blinkt/openvpn/OnBootReceiver.java33
-rw-r--r--src/de/blinkt/openvpn/OpenVpnManagementThread.java1
-rw-r--r--src/de/blinkt/openvpn/OpenVpnService.java4
-rw-r--r--src/de/blinkt/openvpn/ProfileManager.java36
-rw-r--r--src/de/blinkt/openvpn/VpnProfile.java4
11 files changed, 110 insertions, 24 deletions
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 25c3fbdf..f63e6ffe 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -22,8 +22,9 @@
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
- <!-- <uses-permission android:name="com.android.vending.BILLING" /> -->
+ <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
+ <!-- <uses-permission android:name="com.android.vending.BILLING" /> -->
<uses-sdk android:minSdkVersion="14" />
@@ -31,8 +32,9 @@
android:icon="@drawable/icon"
android:label="@string/app" >
<activity android:name=".AboutFragment" />
- <activity android:name=".VPNPreferences"
- android:windowSoftInputMode="stateHidden"/>
+ <activity
+ android:name=".VPNPreferences"
+ android:windowSoftInputMode="stateHidden" />
<activity
android:name=".LogWindow"
android:label="OpenVPN Log" />
@@ -53,8 +55,12 @@
<action android:name="android.net.VpnService" />
</intent-filter>
</service>
+ <receiver android:name=".OnBootReceiver" >
+ <intent-filter>
+ <action android:name="android.intent.action.BOOT_COMPLETED" />
+ </intent-filter>
+ </receiver>
-
<activity
android:name=".ConfigConverter"
android:label="Convert Config File" >
@@ -63,19 +69,19 @@
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
+
<data android:mimeType="application/x-openvpn-profile" />
</intent-filter>
<intent-filter android:label="Import OpenVPN Config" >
- <action android:name="android.intent.action.VIEW" />
-
+ <action android:name="android.intent.action.VIEW" />
+
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:mimeType="application/ovpn" />
</intent-filter>
<intent-filter android:label="Import OpenVPN Config" >
-
- <action android:name="android.intent.action.VIEW" />
+ <action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
@@ -84,7 +90,7 @@
android:pathPattern=".*\\.ovpn"
android:scheme="content" />
</intent-filter>
- </activity>
+ </activity>
<activity
android:name=".LaunchVPN"
android:label="@string/vpn_launch_title" >
diff --git a/res/values-de/strings.xml b/res/values-de/strings.xml
index 8884b9e2..f5c9c1f8 100644
--- a/res/values-de/strings.xml
+++ b/res/values-de/strings.xml
@@ -196,4 +196,6 @@
<string name="importpkcs12fromconfig">Importiere die PKCS12 Datei, die in der Konfiguration angegeben ist, in den Android Keystore</string>
<string name="use_system_proxy">Benutze System Proxies</string>
<string name="use_system_proxy_summary">Benutze die System weiten Einstellungen für HTTP/HTTPS Proxies beim Verbinden.</string>
+ <string name="onbootrestartsummary">Openvpn wird bei einem Neustart des Telefon das beim herrunterfahren/neu starten aktive VPN weider verbinden. Bitte lesen Sie die FAQ &quot;Warnung beim Verbinden&quot; FAQ bevor Sie diese Option verwenden.</string>
+ <string name="onbootrestart">Nach Neustart verbinden</string>
</resources>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 3627f30a..d18c9563 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -242,4 +242,6 @@
<string name="use_system_proxy">Use system proxy</string>
<string name="use_system_proxy_summary">Use the system wide configuration for HTTP/HTTPS proxies to connect.</string>
<string name="donatewithpaypal">You can &lt;a href=\"https://www.paypal.com/cgi-bin/webscr?hosted_button_id=R2M6ZP9AF25LS&amp;amp;cmd=_s-xclick\">donate with PayPal&lt;/a> </string>
+ <string name="onbootrestartsummary">OpenVPN will reconnect a VPN if it was active on system reboot/shutdown. Please read the Connection warning FAQ before using this option.</string>
+ <string name="onbootrestart">Reconnect on reboot</string>
</resources>
diff --git a/res/xml/general_settings.xml b/res/xml/general_settings.xml
index 5a2be01d..3013963d 100644
--- a/res/xml/general_settings.xml
+++ b/res/xml/general_settings.xml
@@ -21,6 +21,11 @@
android:key="usesystemproxy"
android:summary="@string/use_system_proxy_summary"
android:title="@string/use_system_proxy" />
+ <CheckBoxPreference
+ android:defaultValue="false"
+ android:key="restartvpnonboot"
+ android:summary="@string/onbootrestartsummary"
+ android:title="@string/onbootrestart" />
<PreferenceCategory android:title="Device specifics Hacks" >
<CheckBoxPreference
@@ -35,4 +40,5 @@
android:title="@string/setting_loadtun" />
</PreferenceCategory>
+
</PreferenceScreen> \ No newline at end of file
diff --git a/src/de/blinkt/openvpn/LaunchVPN.java b/src/de/blinkt/openvpn/LaunchVPN.java
index bfc6256e..a2a0de3f 100644
--- a/src/de/blinkt/openvpn/LaunchVPN.java
+++ b/src/de/blinkt/openvpn/LaunchVPN.java
@@ -75,12 +75,14 @@ public class LaunchVPN extends ListActivity implements OnItemClickListener {
static final String EXTRA_KEY = "de.blinkt.openvpn.shortcutProfileUUID";
static final String EXTRA_NAME = "de.blinkt.openvpn.shortcutProfileName";
+ public static final String EXTRA_HIDELOG = "de.blinkt.openvpn.showNoLogWindow";;
private static final int START_VPN_PROFILE= 70;
+
private ProfileManager mPM;
private VpnProfile mSelectedProfile;
-
+ private boolean mhideLog=false;
private boolean mCmfixed=false;
@@ -102,10 +104,12 @@ public class LaunchVPN extends ListActivity implements OnItemClickListener {
// 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);
String shortcutName = intent.getStringExtra( EXTRA_NAME);
+ mhideLog = intent.getBooleanExtra(EXTRA_HIDELOG, false);
VpnProfile profileToConnect = ProfileManager.get(shortcutUUID);
if(shortcutName != null && profileToConnect ==null)
@@ -122,18 +126,9 @@ public class LaunchVPN extends ListActivity implements OnItemClickListener {
mSelectedProfile = profileToConnect;
launchVPN();
-
-
} else if (Intent.ACTION_CREATE_SHORTCUT.equals(action)) {
createListView();
}
-
-
-
-
-
-
-
}
private void createListView() {
@@ -318,7 +313,8 @@ public class LaunchVPN extends ListActivity implements OnItemClickListener {
} else {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
boolean showlogwindow = prefs.getBoolean("showlogwindow", true);
- if(showlogwindow)
+
+ if(!mhideLog && showlogwindow)
showLogWindow();
new startOpenVpnThread().start();
}
@@ -372,7 +368,6 @@ public class LaunchVPN extends ListActivity implements OnItemClickListener {
}
-
if (intent != null) {
// Start the query
try {
diff --git a/src/de/blinkt/openvpn/LogWindow.java b/src/de/blinkt/openvpn/LogWindow.java
index ae5277cd..6cc257a5 100644
--- a/src/de/blinkt/openvpn/LogWindow.java
+++ b/src/de/blinkt/openvpn/LogWindow.java
@@ -58,6 +58,8 @@ public class LogWindow extends ListActivity implements StateListener {
OpenVPN.addLogListener(this);
}
+
+
private void initLogBuffer() {
myEntries.clear();
for (LogItem litem : OpenVPN.getlogbuffer()) {
@@ -207,6 +209,7 @@ public class LogWindow extends ListActivity implements StateListener {
@Override
public void onClick(DialogInterface dialog, int which) {
+ ProfileManager.onBootDelete(getApplicationContext());
OpenVpnManagementThread.stopOpenVPN();
}
});
diff --git a/src/de/blinkt/openvpn/OnBootReceiver.java b/src/de/blinkt/openvpn/OnBootReceiver.java
new file mode 100644
index 00000000..032501b6
--- /dev/null
+++ b/src/de/blinkt/openvpn/OnBootReceiver.java
@@ -0,0 +1,33 @@
+package de.blinkt.openvpn;
+
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+
+
+public class OnBootReceiver extends BroadcastReceiver {
+
+ // Debug: am broadcast -a android.intent.action.BOOT_COMPLETED
+ @Override
+ public void onReceive(Context context, Intent intent) {
+
+ final String action = intent.getAction();
+
+ if(Intent.ACTION_BOOT_COMPLETED.equals(action)) {
+ VpnProfile bootProfile = ProfileManager.getOnBootProfile(context);
+ if(bootProfile != null) {
+ lauchVPN(bootProfile, context);
+ }
+ }
+ }
+
+ void lauchVPN(VpnProfile profile,Context context) {
+ Intent startVpnIntent = new Intent(Intent.ACTION_MAIN);
+ startVpnIntent.setClass(context, LaunchVPN.class);
+ startVpnIntent.putExtra(LaunchVPN.EXTRA_KEY,profile.getUUIDString());
+ startVpnIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ startVpnIntent.putExtra(LaunchVPN.EXTRA_HIDELOG, true);
+
+ context.startActivity(startVpnIntent);
+ }
+}
diff --git a/src/de/blinkt/openvpn/OpenVpnManagementThread.java b/src/de/blinkt/openvpn/OpenVpnManagementThread.java
index c42e7516..4e7729ec 100644
--- a/src/de/blinkt/openvpn/OpenVpnManagementThread.java
+++ b/src/de/blinkt/openvpn/OpenVpnManagementThread.java
@@ -18,7 +18,6 @@ import javax.crypto.Cipher;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
-import android.content.Context;
import android.content.SharedPreferences;
import android.net.LocalServerSocket;
import android.net.LocalSocket;
diff --git a/src/de/blinkt/openvpn/OpenVpnService.java b/src/de/blinkt/openvpn/OpenVpnService.java
index f56e873b..01def8eb 100644
--- a/src/de/blinkt/openvpn/OpenVpnService.java
+++ b/src/de/blinkt/openvpn/OpenVpnService.java
@@ -67,6 +67,7 @@ public class OpenVpnService extends VpnService implements StateListener {
OpenVpnManagementThread.stopOpenVPN();
mServiceThread=null;
stopSelf();
+ ProfileManager.onBootDelete(this);
};
private void hideNotification() {
@@ -200,9 +201,8 @@ public class OpenVpnService extends VpnService implements StateListener {
mServiceThread = new Thread(serviceThread, "OpenVPNServiceThread");
mServiceThread.start();
+ ProfileManager.setOnBootProfile(this, mProfile);
-
-
return START_NOT_STICKY;
}
diff --git a/src/de/blinkt/openvpn/ProfileManager.java b/src/de/blinkt/openvpn/ProfileManager.java
index b1321b97..5d498c67 100644
--- a/src/de/blinkt/openvpn/ProfileManager.java
+++ b/src/de/blinkt/openvpn/ProfileManager.java
@@ -14,12 +14,17 @@ import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
+import android.preference.PreferenceManager;
public class ProfileManager {
private static final String PREFS_NAME = "VPNList";
+ private static final String ONBOOTPROFILE = "onBootProfile";
+
+
+
private static ProfileManager instance;
private HashMap<String,VpnProfile> profiles=new HashMap<String, VpnProfile>();
@@ -47,6 +52,37 @@ public class ProfileManager {
return instance;
}
+ public static void onBootDelete(Context c) {
+ SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(c);
+ Editor prefsedit = prefs.edit();
+ prefsedit.putString(ONBOOTPROFILE, null);
+ prefsedit.apply();
+
+ }
+
+ public static void setOnBootProfile(Context c, VpnProfile bootprofile) {
+ SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(c);
+ Editor prefsedit = prefs.edit();
+
+ prefsedit.putString(ONBOOTPROFILE, bootprofile.getUUIDString());
+ prefsedit.apply();
+
+ }
+
+ public static VpnProfile getOnBootProfile(Context c) {
+ SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(c);
+
+ boolean useStartOnBoot = prefs.getBoolean("restartvpnonboot", false);
+
+
+ String mBootProfileUUID = prefs.getString(ONBOOTPROFILE,null);
+ if(useStartOnBoot && mBootProfileUUID!=null)
+ return get(c, mBootProfileUUID);
+ else
+ return null;
+ }
+
+
public Collection<VpnProfile> getProfiles() {
diff --git a/src/de/blinkt/openvpn/VpnProfile.java b/src/de/blinkt/openvpn/VpnProfile.java
index a6dfe053..024874a4 100644
--- a/src/de/blinkt/openvpn/VpnProfile.java
+++ b/src/de/blinkt/openvpn/VpnProfile.java
@@ -24,6 +24,7 @@ import org.spongycastle.util.io.pem.PemWriter;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
+import android.content.SharedPreferences.Editor;
import android.content.pm.ApplicationInfo;
import android.preference.PreferenceManager;
import android.security.KeyChain;
@@ -710,6 +711,9 @@ public class VpnProfile implements Serializable{
public PrivateKey getKeystoreKey() {
return mPrivateKey;
}
+
+
+
}