summaryrefslogtreecommitdiff
path: root/src/de
diff options
context:
space:
mode:
authorArne Schwabe <arne@rfc2549.org>2013-10-13 18:20:23 +0200
committerArne Schwabe <arne@rfc2549.org>2013-10-13 18:20:23 +0200
commit313775ae54d11aae34d5b7137c70d284afd59acd (patch)
tree863d33d80d66503c7cdba826e7feb9fa6516b0a2 /src/de
parent1295b8f844f914feeeef245229ca166b93ca37cd (diff)
Make disconnect option work again, add compat Logwindow class
Diffstat (limited to 'src/de')
-rw-r--r--src/de/blinkt/openvpn/DisconnectVPN.java80
-rw-r--r--src/de/blinkt/openvpn/LogWindow.java15
-rw-r--r--src/de/blinkt/openvpn/core/OpenVpnService.java3
-rw-r--r--src/de/blinkt/openvpn/fragments/LogFragment.java33
4 files changed, 100 insertions, 31 deletions
diff --git a/src/de/blinkt/openvpn/DisconnectVPN.java b/src/de/blinkt/openvpn/DisconnectVPN.java
new file mode 100644
index 00000000..0f9e83aa
--- /dev/null
+++ b/src/de/blinkt/openvpn/DisconnectVPN.java
@@ -0,0 +1,80 @@
+package de.blinkt.openvpn;
+
+import android.app.Activity;
+import android.app.AlertDialog;
+import android.content.*;
+import android.os.IBinder;
+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{
+ 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 onStop() {
+ super.onStop();
+ 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.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();
+ }
+}
diff --git a/src/de/blinkt/openvpn/LogWindow.java b/src/de/blinkt/openvpn/LogWindow.java
new file mode 100644
index 00000000..82a2f4b6
--- /dev/null
+++ b/src/de/blinkt/openvpn/LogWindow.java
@@ -0,0 +1,15 @@
+package de.blinkt.openvpn;
+
+import android.app.Activity;
+import android.os.Bundle;
+
+/**
+ * Created by arne on 13.10.13.
+ */
+public class LogWindow extends Activity {
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.log_window);
+ }
+}
diff --git a/src/de/blinkt/openvpn/core/OpenVpnService.java b/src/de/blinkt/openvpn/core/OpenVpnService.java
index b24bfc34..92e44e53 100644
--- a/src/de/blinkt/openvpn/core/OpenVpnService.java
+++ b/src/de/blinkt/openvpn/core/OpenVpnService.java
@@ -14,6 +14,7 @@ import android.net.VpnService;
import android.os.*;
import android.os.Handler.Callback;
import android.preference.PreferenceManager;
+import de.blinkt.openvpn.DisconnectVPN;
import de.blinkt.openvpn.LogWindow;
import de.blinkt.openvpn.R;
import de.blinkt.openvpn.VpnProfile;
@@ -182,7 +183,7 @@ public class OpenVpnService extends VpnService implements StateListener, Callbac
}
- Intent disconnectVPN = new Intent(this, LogWindow.class);
+ Intent disconnectVPN = new Intent(this, DisconnectVPN.class);
disconnectVPN.setAction(DISCONNECT_VPN);
PendingIntent disconnectPendingIntent = PendingIntent.getActivity(this, 0, disconnectVPN, 0);
diff --git a/src/de/blinkt/openvpn/fragments/LogFragment.java b/src/de/blinkt/openvpn/fragments/LogFragment.java
index ce63d166..9508f158 100644
--- a/src/de/blinkt/openvpn/fragments/LogFragment.java
+++ b/src/de/blinkt/openvpn/fragments/LogFragment.java
@@ -385,23 +385,7 @@ public class LogFragment extends ListFragment implements StateListener, SeekBar.
private LogWindowListAdapter ladapter;
private TextView mSpeedView;
- private void showDisconnectDialog() {
- AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
- builder.setTitle(R.string.title_cancel);
- builder.setMessage(R.string.cancel_connection_query);
- builder.setNegativeButton(android.R.string.no, null);
- builder.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- ProfileManager.setConntectedVpnProfileDisconnected(getActivity());
- if (mService != null && mService.getManagement() != null)
- mService.getManagement().stopVPN();
- }
- });
-
- builder.show();
- }
@Override
@@ -410,7 +394,8 @@ public class LogFragment extends ListFragment implements StateListener, SeekBar.
ladapter.clearLog();
return true;
} else if(item.getItemId()==R.id.cancel){
- showDisconnectDialog();
+ Intent intent = new Intent(getActivity(),DisconnectVPN.class);
+ startActivity(intent);
return true;
} else if(item.getItemId()==R.id.send) {
ladapter.shareLog();
@@ -492,19 +477,7 @@ public class LogFragment extends ListFragment implements StateListener, SeekBar.
getActivity().bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
- // TODO: FIXME: Restore disconnect ability, own Activity?!
- /*
- if (getIntent() !=null && OpenVpnService.DISCONNECT_VPN.equals(getIntent().getAction()))
- showDisconnectDialog();
-
- setIntent(null);
- @Override
- protected void onNewIntent(Intent intent) {
- super.onNewIntent(intent);
- setIntent(intent);
- }
- */
}
@@ -575,7 +548,7 @@ public class LogFragment extends ListFragment implements StateListener, SeekBar.
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
- View v = inflater.inflate(R.layout.log_fragment,container,false);
+ View v = inflater.inflate(R.layout.log_fragment, container, false);
setHasOptionsMenu(true);