summaryrefslogtreecommitdiff
path: root/src/de
diff options
context:
space:
mode:
authorArne Schwabe <arne@rfc2549.org>2013-01-04 20:54:50 +0100
committerArne Schwabe <arne@rfc2549.org>2013-01-04 20:54:50 +0100
commitd89b7ab6b1ad44812d358819b9965b48f23031fc (patch)
treeeac76b4b7ceea0550899f7cab3bee787724636f7 /src/de
parent182242f017c752240f501be3f5027460365bf71f (diff)
Some more changes making external API possible
Diffstat (limited to 'src/de')
-rw-r--r--src/de/blinkt/openvpn/OpenVpnManagementThread.java7
-rw-r--r--src/de/blinkt/openvpn/OpenVpnService.java51
2 files changed, 49 insertions, 9 deletions
diff --git a/src/de/blinkt/openvpn/OpenVpnManagementThread.java b/src/de/blinkt/openvpn/OpenVpnManagementThread.java
index c6a4c73e..3d68d943 100644
--- a/src/de/blinkt/openvpn/OpenVpnManagementThread.java
+++ b/src/de/blinkt/openvpn/OpenVpnManagementThread.java
@@ -573,11 +573,4 @@ public class OpenVpnManagementThread implements Runnable {
}
}
- public static boolean protectFD(ParcelFileDescriptor fd) {
- boolean hasBeenProtected=false;
- for (OpenVpnManagementThread mt : active) {
- hasBeenProtected = hasBeenProtected || mt.mOpenVPNService.protect(fd.getFd());
- }
- return hasBeenProtected;
- }
}
diff --git a/src/de/blinkt/openvpn/OpenVpnService.java b/src/de/blinkt/openvpn/OpenVpnService.java
index 908224e5..4dff943b 100644
--- a/src/de/blinkt/openvpn/OpenVpnService.java
+++ b/src/de/blinkt/openvpn/OpenVpnService.java
@@ -21,6 +21,7 @@ import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Vector;
+import android.annotation.TargetApi;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
@@ -32,10 +33,18 @@ import android.net.LocalServerSocket;
import android.net.LocalSocket;
import android.net.LocalSocketAddress;
import android.net.VpnService;
+import android.os.Binder;
+import android.os.Handler;
+import android.os.Handler.Callback;
+import android.os.Build;
+import android.os.IBinder;
+import android.os.Message;
import android.os.ParcelFileDescriptor;
import de.blinkt.openvpn.OpenVPN.StateListener;
-public class OpenVpnService extends VpnService implements StateListener {
+public class OpenVpnService extends VpnService implements StateListener, Callback {
+ public static final String START_SERVICE = "de.blinkt.openvpn.START_SERVICE";
+
private Thread mProcessThread=null;
private Vector<String> mDnslist=new Vector<String>();
@@ -62,8 +71,29 @@ public class OpenVpnService extends VpnService implements StateListener {
private long mConnecttime;
+
private static final int OPENVPN_STATUS = 1;
+ public static final int PROTECT_FD = 0;
+
+ private final IBinder mBinder = new LocalBinder();
+
+ public class LocalBinder extends Binder {
+ public OpenVpnService getService() {
+ // Return this instance of LocalService so clients can call public methods
+ return OpenVpnService.this;
+ }
+ }
+
+ @Override
+ public IBinder onBind(Intent intent) {
+ String action = intent.getAction();
+ if( action !=null && action.equals(START_SERVICE))
+ return mBinder;
+ else
+ return super.onBind(intent);
+ }
+
@Override
public void onRevoke() {
OpenVpnManagementThread.stopOpenVPN();
@@ -116,6 +146,7 @@ public class OpenVpnService extends VpnService implements StateListener {
startForeground(OPENVPN_STATUS, notification);
}
+ @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
private void jbNotificationExtras(boolean lowpriority,
android.app.Notification.Builder nbuilder) {
try {
@@ -124,6 +155,7 @@ public class OpenVpnService extends VpnService implements StateListener {
// PRIORITY_MIN == -2
setpriority.invoke(nbuilder, -2 );
+ nbuilder.setUsesChronometer(true);
/* PendingIntent cancelconnet=null;
nbuilder.addAction(android.R.drawable.ic_menu_close_clear_cancel,
@@ -188,7 +220,11 @@ public class OpenVpnService extends VpnService implements StateListener {
@Override
- public int onStartCommand(Intent intent, int flags, int startId) {
+ public int onStartCommand(Intent intent, int flags, int startId) {
+
+ if(intent != null && intent.getAction() !=null &&intent.getAction().equals(START_SERVICE))
+ return START_NOT_STICKY;
+
// Extract information from the intent.
String prefix = getPackageName();
@@ -458,4 +494,15 @@ public class OpenVpnService extends VpnService implements StateListener {
}
}
+
+ @Override
+ public boolean handleMessage(Message msg) {
+ Runnable r = msg.getCallback();
+ if(r!=null){
+ r.run();
+ return true;
+ } else {
+ return false;
+ }
+ }
}