diff options
| -rw-r--r-- | AndroidManifest.xml | 13 | ||||
| -rw-r--r-- | src/de/blinkt/openvpn/OpenVpnManagementThread.java | 7 | ||||
| -rw-r--r-- | src/de/blinkt/openvpn/OpenVpnService.java | 51 | 
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; +		} +	}  } | 
