blob: 3ba4f5852427c756658b5a02219e0a768785a615 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
/*
* Copyright (c) 2012-2016 Arne Schwabe
* Distributed under the GNU GPL v2 with additional terms. For full terms see the file doc/LICENSE.txt
*/
package de.blinkt.openvpn.activities;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.*;
import android.os.IBinder;
import de.blinkt.openvpn.R;
import de.blinkt.openvpn.core.OpenVPNService;
import de.blinkt.openvpn.core.ProfileManager;
/**
* Created by arne on 13.10.13.
*/
public class DisconnectVPN extends Activity implements DialogInterface.OnClickListener, DialogInterface.OnCancelListener {
protected OpenVPNService mService;
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();
}
@Override
public void onServiceDisconnected(ComponentName arg0) {
mService =null;
}
};
@Override
protected void onResume() {
super.onResume();
Intent intent = new Intent(this, OpenVPNService.class);
intent.setAction(OpenVPNService.START_SERVICE);
bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
showDisconnectDialog();
}
@Override
protected void onPause() {
super.onPause();
unbindService(mConnection);
}
// if (getIntent() !=null && OpenVpnService.DISCONNECT_VPN.equals(getIntent().getAction()))
// setIntent(null);
/*
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
setIntent(intent);
}
*/
private void showDisconnectDialog() {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(R.string.title_cancel);
builder.setMessage(R.string.cancel_connection_query);
builder.setNegativeButton(android.R.string.no, this);
builder.setPositiveButton(android.R.string.yes,this);
builder.setOnCancelListener(this);
builder.show();
}
@Override
public void onClick(DialogInterface dialog, int which) {
if (which == DialogInterface.BUTTON_POSITIVE) {
ProfileManager.setConntectedVpnProfileDisconnected(this);
if (mService != null && mService.getManagement() != null)
mService.getManagement().stopVPN();
}
finish();
}
@Override
public void onCancel(DialogInterface dialog) {
finish();
}
}
|