summaryrefslogtreecommitdiff
path: root/main/src/main/java/de/blinkt/openvpn/activities/DisconnectVPN.java
diff options
context:
space:
mode:
Diffstat (limited to 'main/src/main/java/de/blinkt/openvpn/activities/DisconnectVPN.java')
-rw-r--r--main/src/main/java/de/blinkt/openvpn/activities/DisconnectVPN.java25
1 files changed, 17 insertions, 8 deletions
diff --git a/main/src/main/java/de/blinkt/openvpn/activities/DisconnectVPN.java b/main/src/main/java/de/blinkt/openvpn/activities/DisconnectVPN.java
index e832c527..f63f5ed2 100644
--- a/main/src/main/java/de/blinkt/openvpn/activities/DisconnectVPN.java
+++ b/main/src/main/java/de/blinkt/openvpn/activities/DisconnectVPN.java
@@ -9,33 +9,36 @@ import android.app.Activity;
import android.app.AlertDialog;
import android.content.*;
import android.os.IBinder;
+import android.os.Message;
+import android.os.Messenger;
+import android.os.RemoteException;
import de.blinkt.openvpn.LaunchVPN;
import de.blinkt.openvpn.R;
import de.blinkt.openvpn.VpnProfile;
import de.blinkt.openvpn.core.OpenVPNService;
import de.blinkt.openvpn.core.ProfileManager;
+import de.blinkt.openvpn.core.VpnStatus;
/**
* Created by arne on 13.10.13.
*/
public class DisconnectVPN extends Activity implements DialogInterface.OnClickListener, DialogInterface.OnCancelListener {
- protected OpenVPNService mService;
-
+ private Messenger mMessenger;
private ServiceConnection mConnection = new ServiceConnection() {
+
@Override
public void onServiceConnected(ComponentName className,
IBinder service) {
- // We've bound to LocalService, cast the IBinder and get LocalService instance
- OpenVPNService.LocalBinder binder = (OpenVPNService.LocalBinder) service;
- mService = binder.getService();
+ mMessenger = new Messenger(service);
+
}
@Override
public void onServiceDisconnected(ComponentName arg0) {
- mService =null;
+ mMessenger = null;
}
};
@@ -72,8 +75,14 @@ public class DisconnectVPN extends Activity implements DialogInterface.OnClickLi
VpnProfile lastVPN = ProfileManager.getLastConnectedVpn();
if (which == DialogInterface.BUTTON_POSITIVE) {
ProfileManager.setConntectedVpnProfileDisconnected(this);
- if (mService != null && mService.getManagement() != null)
- mService.getManagement().stopVPN(false);
+ if (mMessenger != null) {
+ Message msg = Message.obtain(null, OpenVPNService.DISCONNECT_VPN_MSG);
+ try {
+ mMessenger.send(msg);
+ } catch (RemoteException e) {
+ VpnStatus.logException(e);
+ }
+ }
} else if (which == DialogInterface.BUTTON_NEUTRAL && lastVPN !=null) {
Intent intent = new Intent(this, LaunchVPN.class);
intent.putExtra(LaunchVPN.EXTRA_KEY, lastVPN.getUUID().toString());