From 313775ae54d11aae34d5b7137c70d284afd59acd Mon Sep 17 00:00:00 2001 From: Arne Schwabe Date: Sun, 13 Oct 2013 18:20:23 +0200 Subject: Make disconnect option work again, add compat Logwindow class --- src/de/blinkt/openvpn/DisconnectVPN.java | 80 ++++++++++++++++++++++++ src/de/blinkt/openvpn/LogWindow.java | 15 +++++ src/de/blinkt/openvpn/core/OpenVpnService.java | 3 +- src/de/blinkt/openvpn/fragments/LogFragment.java | 33 +--------- 4 files changed, 100 insertions(+), 31 deletions(-) create mode 100644 src/de/blinkt/openvpn/DisconnectVPN.java create mode 100644 src/de/blinkt/openvpn/LogWindow.java (limited to 'src/de/blinkt/openvpn') 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); -- cgit v1.2.3