summaryrefslogtreecommitdiff
path: root/src/org/xapek
diff options
context:
space:
mode:
authorYves Fischer <yvesf-git@xapek.org>2014-08-17 00:32:47 +0200
committerYves Fischer <yvesf-git@xapek.org>2014-08-17 00:32:47 +0200
commitfc07e620e834dfa3495323e29ae10e21c3621804 (patch)
treeaeed1e644019edcec88ebb65ddf69323abc12860 /src/org/xapek
parent5d8801d4687035ae45143f0f3bc3eeaf75dc17ec (diff)
downloadandiodine-fc07e620e834dfa3495323e29ae10e21c3621804.tar.gz
andiodine-fc07e620e834dfa3495323e29ae10e21c3621804.zip
Detect issue #4 and display specific error message
Diffstat (limited to 'src/org/xapek')
-rw-r--r--src/org/xapek/andiodine/FragmentList.java2
-rw-r--r--src/org/xapek/andiodine/FragmentStatus.java18
-rw-r--r--src/org/xapek/andiodine/IodineVpnService.java42
3 files changed, 40 insertions, 22 deletions
diff --git a/src/org/xapek/andiodine/FragmentList.java b/src/org/xapek/andiodine/FragmentList.java
index e07aee4..10a0875 100644
--- a/src/org/xapek/andiodine/FragmentList.java
+++ b/src/org/xapek/andiodine/FragmentList.java
@@ -17,8 +17,6 @@ import android.view.MenuInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
-import android.widget.ImageButton;
-import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
diff --git a/src/org/xapek/andiodine/FragmentStatus.java b/src/org/xapek/andiodine/FragmentStatus.java
index aaa64fb..198271a 100644
--- a/src/org/xapek/andiodine/FragmentStatus.java
+++ b/src/org/xapek/andiodine/FragmentStatus.java
@@ -21,19 +21,19 @@ public class FragmentStatus extends Fragment {
private TextView mStatus;
private TextView mLogmessages;
private ScrollView mScrollview;
- private Button mCancel;
+ private Button mClose;
private final BroadcastReceiver broadcastReceiverStatusUpdates = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
Log.d(TAG, "Got intent: " + intent);
if (IodineVpnService.ACTION_STATUS_ERROR.equals(intent.getAction())) {
- new AlertDialog.Builder(FragmentStatus.this.getActivity())//
- .setIcon(R.drawable.error) //
- .setTitle(intent.getStringExtra(IodineVpnService.EXTRA_ERROR_MESSAGE)) //
- .setMessage(mLogmessages.getText()) //
- .create() //
- .show();
+ new AlertDialog.Builder(FragmentStatus.this.getActivity())//
+ .setIcon(R.drawable.error) //
+ .setTitle("Error") //
+ .setMessage(intent.getStringExtra(IodineVpnService.EXTRA_ERROR_MESSAGE)) //
+ .create() //
+ .show();
} else if (IodineVpnService.ACTION_STATUS_CONNECT.equals(intent.getAction())) {
mStatus.setText("Connect");
} else if (IodineVpnService.ACTION_STATUS_CONNECTED.equals(intent.getAction())) {
@@ -61,8 +61,8 @@ public class FragmentStatus extends Fragment {
mStatus = (TextView) getActivity().findViewById(R.id.status_message);
mLogmessages = (TextView) getActivity().findViewById(R.id.status_logmessages);
mScrollview = (ScrollView) getActivity().findViewById(R.id.status_scrollview);
- mCancel = (Button) getActivity().findViewById(R.id.status_cancel);
- mCancel.setOnClickListener(new View.OnClickListener() {
+ mClose = (Button) getActivity().findViewById(R.id.status_cancel);
+ mClose.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
requestDisconnect();
diff --git a/src/org/xapek/andiodine/IodineVpnService.java b/src/org/xapek/andiodine/IodineVpnService.java
index 971b757..7c4443e 100644
--- a/src/org/xapek/andiodine/IodineVpnService.java
+++ b/src/org/xapek/andiodine/IodineVpnService.java
@@ -11,6 +11,7 @@ import android.util.Log;
import org.xapek.andiodine.config.ConfigDatabase;
import org.xapek.andiodine.config.IodineConfiguration;
+import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;
@@ -151,7 +152,10 @@ public class IodineVpnService extends VpnService implements Runnable {
}
private void shutdown() {
- setStatus(ACTION_STATUS_DISCONNECT, mConfiguration.getId(), null);
+ if (mConfiguration != null)
+ setStatus(ACTION_STATUS_DISCONNECT, mConfiguration.getId(), null);
+ else
+ setStatus(ACTION_STATUS_IDLE, null, null);
if (mThread != null) {
mThread.interrupt();
@@ -221,7 +225,7 @@ public class IodineVpnService extends VpnService implements Runnable {
case 0:
Log.d(TAG, "Handshake successful");
setStatus(ACTION_STATUS_CONNECTED, currentConfigurationId, null);
- runTunnel();
+ runTunnel(); // this blocks until connection is closed
setStatus(ACTION_STATUS_IDLE, null, null);
break;
case 1:
@@ -311,12 +315,22 @@ public class IodineVpnService extends VpnService implements Runnable {
Log.d(TAG, "Set default route");
b.addRoute("0.0.0.0", 0); // Default Route
}
- b.setMtu(mtu); // bug https://github.com/yvesf/andiodine/issues/4
- // the VPN framework fails if mtu < 1280
- // b.setMtu(1280);
-
- Log.d(TAG, "Build tunnel interface");
- ParcelFileDescriptor parcelFD = b.establish();
+ b.setMtu(mtu);
+
+ Log.d(TAG, "Build tunnel interface");
+ ParcelFileDescriptor parcelFD;
+ try {
+ parcelFD = b.establish();
+ } catch (Exception e) {
+ if (e.getMessage().contains("fwmark") || e.getMessage().contains("iptables")) {
+ // bug https://github.com/yvesf/andiodine/issues/4
+ throw new IodineVpnException(
+ "Error while creating interface, please check issue #4 at https://github.com/yvesf/andiodine/issues/4");
+ } else {
+ throw new IodineVpnException("Error while creating interface: "
+ + e.getMessage());
+ }
+ }
protect(IodineClient.getDnsFd());
@@ -324,7 +338,13 @@ public class IodineVpnService extends VpnService implements Runnable {
setStatus(ACTION_STATUS_CONNECTED, mConfiguration.getId(), null);
- Log.d(TAG, "Tunnel active");
- IodineClient.tunnel(tun_fd);
- }
+ Log.d(TAG, "Tunnel active");
+ IodineClient.tunnel(tun_fd);
+ try {
+ ParcelFileDescriptor.adoptFd(tun_fd).close();
+ } catch (IOException e) {
+ throw new IodineVpnException(
+ "Failed to close fd after tunnel exited");
+ }
+ }
}