Skip to content
This repository was archived by the owner on Sep 3, 2024. It is now read-only.

Commit

Permalink
Detect issue #4 and display specific error message
Browse files Browse the repository at this point in the history
  • Loading branch information
yvesf committed Aug 16, 2014
1 parent 5d8801d commit fc07e62
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 26 deletions.
2 changes: 1 addition & 1 deletion res/layout/fragment_status.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

<Button
android:drawableLeft="@drawable/cancel"
android:text="Cancel"
android:text="Close"
android:id="@+id/status_cancel"
android:layout_width="match_parent"
android:layout_height="50dp"
Expand Down
2 changes: 0 additions & 2 deletions src/org/xapek/andiodine/FragmentList.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
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;

Expand Down
18 changes: 9 additions & 9 deletions src/org/xapek/andiodine/FragmentStatus.java
Original file line number Diff line number Diff line change
Expand Up @@ -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())) {
Expand Down Expand Up @@ -61,8 +61,8 @@ public void onActivityCreated(Bundle savedInstanceState) {
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();
Expand Down
42 changes: 31 additions & 11 deletions src/org/xapek/andiodine/IodineVpnService.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.xapek.andiodine.config.ConfigDatabase;
import org.xapek.andiodine.config.IodineConfiguration;

import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;

Expand Down Expand Up @@ -151,7 +152,10 @@ public int onStartCommand(Intent intent, int flags, int startId) {
}

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();
Expand Down Expand Up @@ -221,7 +225,7 @@ public void run() {
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:
Expand Down Expand Up @@ -311,20 +315,36 @@ private void runTunnel() throws IodineVpnException {
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());

int tun_fd = parcelFD.detachFd();

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");
}
}
}
6 changes: 3 additions & 3 deletions tests/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- package name must be unique so suffix with "tests" so package loader doesn't ignore us -->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.HelloJni.tests"
package="org.xapek.andiodine.tests"
android:versionCode="1"
android:versionName="1.0" >

Expand All @@ -24,7 +24,7 @@
-->
<instrumentation
android:name="android.test.InstrumentationTestRunner"
android:label="Tests for HelloJni"
android:targetPackage="com.example.HelloJni" />
android:label="Tests for Andiodine"
android:targetPackage="org.xapek.andiodine" />

</manifest>

0 comments on commit fc07e62

Please sign in to comment.