summaryrefslogtreecommitdiff
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
commit5350c37c79e7fc3561c0bda068565ef19630131a (patch)
tree412831be8a00d8651681a6bd1cf0c7b9f5196219
parentc767a06a53230ec3829a6ad76b1201a20fae76fa (diff)
Some more changes making external API possible
--HG-- extra : rebase_source : a62d022b917c997a5e116c34802fecfb1f066459
-rw-r--r--AndroidManifest.xml13
-rw-r--r--src/de/blinkt/openvpn/OpenVpnManagementThread.java7
-rw-r--r--src/de/blinkt/openvpn/OpenVpnService.java51
3 files changed, 60 insertions, 11 deletions
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 2bd0be0e..07fbde8a 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -68,13 +68,22 @@
<action android:name="android.net.VpnService" />
</intent-filter>
</service>
- <service android:name=".api.ExternalOpenVPNService"
- android:permission="de.blinkt.openvpn.REMOTE_API">
+ <service
+ android:name=".api.ExternalOpenVPNService"
+ android:permission="de.blinkt.openvpn.REMOTE_API" >
<intent-filter>
<action android:name="de.blinkt.openvpn.api.IOpenVPNAPIService" />
</intent-filter>
</service>
+ <activity
+ android:name=".api.GrantPermissionsActivity"
+ android:permission="de.blinkt.openvpn.REMOTE_API" >
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ </intent-filter>
+ </activity>
+
<receiver android:name=".OnBootReceiver" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
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;
+ }
+ }
}