Localize exception messages
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
committed by
Jason A. Donenfeld
parent
e1965f121c
commit
9de711a4f5
@@ -57,7 +57,7 @@ public interface Backend {
|
||||
*
|
||||
* @return Type name
|
||||
*/
|
||||
String getTypeName();
|
||||
String getTypePrettyName();
|
||||
|
||||
/**
|
||||
* Determine version of underlying backend.
|
||||
|
||||
@@ -14,6 +14,7 @@ import android.support.v4.util.ArraySet;
|
||||
import android.util.Log;
|
||||
|
||||
import com.wireguard.android.Application;
|
||||
import com.wireguard.android.R;
|
||||
import com.wireguard.android.activity.MainActivity;
|
||||
import com.wireguard.android.model.Tunnel;
|
||||
import com.wireguard.android.model.Tunnel.State;
|
||||
@@ -26,6 +27,7 @@ import com.wireguard.config.Peer;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.util.Collections;
|
||||
import java.util.Locale;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
@@ -93,8 +95,8 @@ public final class GoBackend implements Backend {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTypeName() {
|
||||
return "Go userspace";
|
||||
public String getTypePrettyName() {
|
||||
return context.getResources().getString(R.string.type_name_go_userspace);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -110,7 +112,7 @@ public final class GoBackend implements Backend {
|
||||
if (state == originalState)
|
||||
return originalState;
|
||||
if (state == State.UP && currentTunnel != null)
|
||||
throw new IllegalStateException("Only one userspace tunnel can run at a time");
|
||||
throw new IllegalStateException(context.getResources().getString(R.string.multiple_tunnels_error));
|
||||
Log.d(TAG, "Changing tunnel " + tunnel.getName() + " to state " + state);
|
||||
setStateInternal(tunnel, tunnel.getConfig(), state);
|
||||
return getState(tunnel);
|
||||
@@ -122,10 +124,10 @@ public final class GoBackend implements Backend {
|
||||
if (state == State.UP) {
|
||||
Log.i(TAG, "Bringing tunnel up");
|
||||
|
||||
Objects.requireNonNull(config, "Trying to bring up a tunnel with no config");
|
||||
Objects.requireNonNull(config, context.getResources().getString(R.string.no_config_error));
|
||||
|
||||
if (VpnService.prepare(context) != null)
|
||||
throw new Exception("VPN service not authorized by user");
|
||||
throw new Exception(context.getResources().getString(R.string.vpn_not_authed_error));
|
||||
|
||||
final VpnService service;
|
||||
if (!vpnService.isDone())
|
||||
@@ -134,7 +136,7 @@ public final class GoBackend implements Backend {
|
||||
try {
|
||||
service = vpnService.get(2, TimeUnit.SECONDS);
|
||||
} catch (final TimeoutException e) {
|
||||
throw new Exception("Unable to start Android VPN service", e);
|
||||
throw new Exception(context.getResources().getString(R.string.vpn_start_error), e);
|
||||
}
|
||||
|
||||
if (currentTunnelHandle != -1) {
|
||||
@@ -172,12 +174,12 @@ public final class GoBackend implements Backend {
|
||||
builder.setBlocking(true);
|
||||
try (final ParcelFileDescriptor tun = builder.establish()) {
|
||||
if (tun == null)
|
||||
throw new Exception("Unable to create tun device");
|
||||
throw new Exception(context.getResources().getString(R.string.tun_create_error));
|
||||
Log.d(TAG, "Go backend v" + wgVersion());
|
||||
currentTunnelHandle = wgTurnOn(tunnel.getName(), tun.detachFd(), goConfig);
|
||||
}
|
||||
if (currentTunnelHandle < 0)
|
||||
throw new Exception("Unable to turn tunnel on (wgTurnOn return " + currentTunnelHandle + ')');
|
||||
throw new Exception(String.format(Locale.getDefault(), context.getResources().getString(R.string.tunnel_on_error), currentTunnelHandle));
|
||||
|
||||
currentTunnel = tunnel;
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ import android.support.annotation.Nullable;
|
||||
import android.util.Log;
|
||||
|
||||
import com.wireguard.android.Application;
|
||||
import com.wireguard.android.R;
|
||||
import com.wireguard.android.model.Tunnel;
|
||||
import com.wireguard.android.model.Tunnel.State;
|
||||
import com.wireguard.android.model.Tunnel.Statistics;
|
||||
@@ -36,9 +37,11 @@ public final class WgQuickBackend implements Backend {
|
||||
private static final String TAG = "WireGuard/" + WgQuickBackend.class.getSimpleName();
|
||||
|
||||
private final File localTemporaryDir;
|
||||
private final Context context;
|
||||
|
||||
public WgQuickBackend(final Context context) {
|
||||
localTemporaryDir = new File(context.getCacheDir(), "tmp");
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -84,8 +87,8 @@ public final class WgQuickBackend implements Backend {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTypeName() {
|
||||
return "Kernel module";
|
||||
public String getTypePrettyName() {
|
||||
return context.getResources().getString(R.string.type_name_kernel_module);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -93,7 +96,7 @@ public final class WgQuickBackend implements Backend {
|
||||
final List<String> output = new ArrayList<>();
|
||||
if (Application.getRootShell()
|
||||
.run(output, "cat /sys/module/wireguard/version") != 0 || output.isEmpty())
|
||||
throw new Exception("Unable to determine kernel module version");
|
||||
throw new Exception(context.getResources().getString(R.string.module_version_error));
|
||||
return output.get(0);
|
||||
}
|
||||
|
||||
@@ -125,6 +128,6 @@ public final class WgQuickBackend implements Backend {
|
||||
// noinspection ResultOfMethodCallIgnored
|
||||
tempFile.delete();
|
||||
if (result != 0)
|
||||
throw new Exception("Unable to configure tunnel (wg-quick returned " + result + ')');
|
||||
throw new Exception(context.getResources().getString(R.string.tunnel_config_error));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user