WgQuickBackend: properly report exception so alert shows
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
parent
df3062c7ad
commit
dfa4a2eb9d
@ -103,18 +103,27 @@ public final class WgQuickBackend implements Backend {
|
|||||||
state = originalState == State.UP ? State.DOWN : State.UP;
|
state = originalState == State.UP ? State.DOWN : State.UP;
|
||||||
if (state == originalState)
|
if (state == originalState)
|
||||||
return originalState;
|
return originalState;
|
||||||
|
if (state == State.UP && !new File("/sys/module/wireguard").exists())
|
||||||
|
throw new ModuleNotLoadedException("WireGuard module not loaded");
|
||||||
Log.d(TAG, "Changing tunnel " + tunnel.getName() + " to state " + state);
|
Log.d(TAG, "Changing tunnel " + tunnel.getName() + " to state " + state);
|
||||||
toolsInstaller.ensureToolsAvailable();
|
toolsInstaller.ensureToolsAvailable();
|
||||||
final int result;
|
final int result;
|
||||||
if (state == State.UP) {
|
if (state == State.UP)
|
||||||
if (!new File("/sys/module/wireguard").exists())
|
|
||||||
throw new ErrnoException("WireGuard module not loaded", OsConstants.ENODEV);
|
|
||||||
result = bringUpTunnel(tunnel, tunnel.getConfig());
|
result = bringUpTunnel(tunnel, tunnel.getConfig());
|
||||||
} else {
|
else
|
||||||
result = rootShell.run(null, "wg-quick down '" + tunnel.getName() + '\'');
|
result = rootShell.run(null, "wg-quick down '" + tunnel.getName() + '\'');
|
||||||
}
|
|
||||||
if (result != 0)
|
if (result != 0)
|
||||||
throw new Exception("wg-quick failed");
|
throw new Exception("Unable to configure tunnel");
|
||||||
return getState(tunnel);
|
return getState(tunnel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class ModuleNotLoadedException extends Exception {
|
||||||
|
public ModuleNotLoadedException(final String message, final Throwable cause) {
|
||||||
|
super(message, cause);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ModuleNotLoadedException(final String message) {
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,8 +4,6 @@ import android.app.AlertDialog;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.databinding.DataBindingUtil;
|
import android.databinding.DataBindingUtil;
|
||||||
import android.databinding.ViewDataBinding;
|
import android.databinding.ViewDataBinding;
|
||||||
import android.system.ErrnoException;
|
|
||||||
import android.system.OsConstants;
|
|
||||||
import android.text.Html;
|
import android.text.Html;
|
||||||
import android.text.method.LinkMovementMethod;
|
import android.text.method.LinkMovementMethod;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
@ -14,6 +12,7 @@ import android.widget.TextView;
|
|||||||
|
|
||||||
import com.commonsware.cwac.crossport.design.widget.Snackbar;
|
import com.commonsware.cwac.crossport.design.widget.Snackbar;
|
||||||
import com.wireguard.android.R;
|
import com.wireguard.android.R;
|
||||||
|
import com.wireguard.android.backend.WgQuickBackend;
|
||||||
import com.wireguard.android.databinding.TunnelDetailFragmentBinding;
|
import com.wireguard.android.databinding.TunnelDetailFragmentBinding;
|
||||||
import com.wireguard.android.databinding.TunnelListItemBinding;
|
import com.wireguard.android.databinding.TunnelListItemBinding;
|
||||||
import com.wireguard.android.model.Tunnel;
|
import com.wireguard.android.model.Tunnel;
|
||||||
@ -48,8 +47,8 @@ public final class TunnelController {
|
|||||||
if (throwable == null)
|
if (throwable == null)
|
||||||
return;
|
return;
|
||||||
final Context context = view.getContext();
|
final Context context = view.getContext();
|
||||||
if (throwable instanceof ErrnoException
|
if (throwable instanceof WgQuickBackend.ModuleNotLoadedException ||
|
||||||
&& ((ErrnoException) throwable).errno == OsConstants.ENODEV) {
|
throwable.getCause() instanceof WgQuickBackend.ModuleNotLoadedException) {
|
||||||
final String message = context.getString(R.string.not_supported_message);
|
final String message = context.getString(R.string.not_supported_message);
|
||||||
final String title = context.getString(R.string.not_supported_title);
|
final String title = context.getString(R.string.not_supported_title);
|
||||||
final AlertDialog dialog = new AlertDialog.Builder(context)
|
final AlertDialog dialog = new AlertDialog.Builder(context)
|
||||||
|
Loading…
Reference in New Issue
Block a user