diff options
5 files changed, 61 insertions, 5 deletions
diff --git a/main/src/main/aidl/de/blinkt/openvpn/core/IOpenVPNServiceInternal.aidl b/main/src/main/aidl/de/blinkt/openvpn/core/IOpenVPNServiceInternal.aidl index 3958bcf3..53da4aaf 100644 --- a/main/src/main/aidl/de/blinkt/openvpn/core/IOpenVPNServiceInternal.aidl +++ b/main/src/main/aidl/de/blinkt/openvpn/core/IOpenVPNServiceInternal.aidl @@ -20,4 +20,6 @@ interface IOpenVPNServiceInternal { * @return true if there was a process that has been send a stop signal */ boolean stopVPN(boolean replaceConnection); + + void addAllowedExternalApp(String packagename); } diff --git a/main/src/main/java/de/blinkt/openvpn/api/ConfirmDialog.java b/main/src/main/java/de/blinkt/openvpn/api/ConfirmDialog.java index 2355f83b..2547951f 100644 --- a/main/src/main/java/de/blinkt/openvpn/api/ConfirmDialog.java +++ b/main/src/main/java/de/blinkt/openvpn/api/ConfirmDialog.java @@ -19,11 +19,19 @@ package de.blinkt.openvpn.api; import android.app.Activity; import android.app.AlertDialog; import android.app.AlertDialog.Builder; +import android.content.ComponentName; +import android.content.Context; import android.content.DialogInterface; import android.content.DialogInterface.OnShowListener; import android.content.Intent; +import android.content.ServiceConnection; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; +import android.os.Bundle; +import android.os.IBinder; +import android.os.PersistableBundle; +import android.os.RemoteException; +import android.support.annotation.Nullable; import android.util.Log; import android.view.View; import android.widget.Button; @@ -32,6 +40,8 @@ import android.widget.ImageView; import android.widget.TextView; import de.blinkt.openvpn.R; +import de.blinkt.openvpn.core.IOpenVPNServiceInternal; +import de.blinkt.openvpn.core.OpenVPNService; public class ConfirmDialog extends Activity implements @@ -48,10 +58,29 @@ public class ConfirmDialog extends Activity implements private AlertDialog mAlert; + private IOpenVPNServiceInternal mService; + private ServiceConnection mConnection = new ServiceConnection() { + @Override + public void onServiceConnected(ComponentName className, + IBinder service) { + mService = IOpenVPNServiceInternal.Stub.asInterface(service); + } + + @Override + public void onServiceDisconnected(ComponentName arg0) { + mService = null; + } + + }; + @Override protected void onResume() { super.onResume(); + Intent serviceintent = new Intent(this, OpenVPNService.class); + serviceintent.setAction(OpenVPNService.START_SERVICE); + bindService(serviceintent, mConnection, Context.BIND_AUTO_CREATE); + Intent intent = getIntent(); if (intent.getStringExtra(EXTRA_PACKAGE_NAME) != null) { mPackage = intent.getStringExtra(EXTRA_PACKAGE_NAME); @@ -71,7 +100,7 @@ public class ConfirmDialog extends Activity implements } else { PackageManager pm = getPackageManager(); ApplicationInfo app = pm.getApplicationInfo(mPackage, 0); - appString = getString(R.string.prompt, app.loadLabel(pm) , getString(R.string.app)); + appString = getString(R.string.prompt, app.loadLabel(pm), getString(R.string.app)); ((ImageView) view.findViewById(R.id.icon)).setImageDrawable(app.loadIcon(pm)); } @@ -123,11 +152,22 @@ public class ConfirmDialog extends Activity implements } @Override + protected void onPause() { + super.onPause(); + unbindService(mConnection); + + } + + @Override public void onClick(DialogInterface dialog, int which) { if (which == DialogInterface.BUTTON_POSITIVE) { - ExternalAppDatabase extapps = new ExternalAppDatabase(this); - extapps.addApp(mPackage); + try { + mService.addAllowedExternalApp(mPackage); + } catch (RemoteException e) { + e.printStackTrace(); + throw new RuntimeException(e); + } setResult(RESULT_OK); finish(); } diff --git a/main/src/main/java/de/blinkt/openvpn/api/ExternalAppDatabase.java b/main/src/main/java/de/blinkt/openvpn/api/ExternalAppDatabase.java index e87b4c3a..07d77345 100644 --- a/main/src/main/java/de/blinkt/openvpn/api/ExternalAppDatabase.java +++ b/main/src/main/java/de/blinkt/openvpn/api/ExternalAppDatabase.java @@ -41,7 +41,7 @@ public class ExternalAppDatabase { return prefs.getStringSet(PREFERENCES_KEY, new HashSet<String>()); } - void addApp(String packagename) + public void addApp(String packagename) { Set<String> allowedapps = getExtAppList(); allowedapps.add(packagename); diff --git a/main/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java b/main/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java index 12b7fba5..c79a0b99 100644 --- a/main/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java +++ b/main/src/main/java/de/blinkt/openvpn/core/OpenVPNService.java @@ -53,6 +53,7 @@ import de.blinkt.openvpn.R; import de.blinkt.openvpn.VpnProfile; import de.blinkt.openvpn.activities.DisconnectVPN; import de.blinkt.openvpn.activities.MainActivity; +import de.blinkt.openvpn.api.ExternalAppDatabase; import de.blinkt.openvpn.core.VpnStatus.ByteCountListener; import de.blinkt.openvpn.core.VpnStatus.StateListener; @@ -118,8 +119,21 @@ public class OpenVPNService extends VpnService implements StateListener, Callbac public boolean stopVPN(boolean replaceConnection) throws RemoteException { return OpenVPNService.this.stopVPN(replaceConnection); } + + @Override + public void addAllowedExternalApp(String packagename) throws RemoteException { + OpenVPNService.this.addAllowedExternalApp(packagename); + } + + }; + @Override + public void addAllowedExternalApp(String packagename) throws RemoteException { + ExternalAppDatabase extapps = new ExternalAppDatabase(OpenVPNService.this); + extapps.addApp(packagename); + } + // From: http://stackoverflow.com/questions/3758606/how-to-convert-byte-size-into-human-readable-format-in-java public static String humanReadableByteCount(long bytes, boolean speed, Resources res) { if (speed) diff --git a/main/src/main/java/de/blinkt/openvpn/core/VPNLaunchHelper.java b/main/src/main/java/de/blinkt/openvpn/core/VPNLaunchHelper.java index bc32616e..84d6591a 100644 --- a/main/src/main/java/de/blinkt/openvpn/core/VPNLaunchHelper.java +++ b/main/src/main/java/de/blinkt/openvpn/core/VPNLaunchHelper.java @@ -48,7 +48,7 @@ public class VPNLaunchHelper { } } - return null; + throw new RuntimeException("Cannot find any execulte for this device's ABIs " + abis.toString()); } @TargetApi(Build.VERSION_CODES.LOLLIPOP) |