diff options
author | Zachary Wander <zachary.wander@gmail.com> | 2018-12-10 19:05:53 -0500 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2018-12-11 02:21:23 +0100 |
commit | d55c358256f301b59c4fccc1bbe1fee49d507389 (patch) | |
tree | 198b094cf6e0bb92508a738924cfc69ebc0e2c81 /app/src/main/java/com/wireguard/android/util | |
parent | Lowercase endpoint in exception message (diff) | |
download | wireguard-android-d55c358256f301b59c4fccc1bbe1fee49d507389.tar.xz wireguard-android-d55c358256f301b59c4fccc1bbe1fee49d507389.zip |
Localize exception messages
Diffstat (limited to 'app/src/main/java/com/wireguard/android/util')
-rw-r--r-- | app/src/main/java/com/wireguard/android/util/RootShell.java | 15 | ||||
-rw-r--r-- | app/src/main/java/com/wireguard/android/util/ToolsInstaller.java | 6 |
2 files changed, 15 insertions, 6 deletions
diff --git a/app/src/main/java/com/wireguard/android/util/RootShell.java b/app/src/main/java/com/wireguard/android/util/RootShell.java index 00d54ab5..0e04185a 100644 --- a/app/src/main/java/com/wireguard/android/util/RootShell.java +++ b/app/src/main/java/com/wireguard/android/util/RootShell.java @@ -20,6 +20,7 @@ import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.nio.charset.StandardCharsets; import java.util.Collection; +import java.util.Locale; import java.util.UUID; /** @@ -30,6 +31,7 @@ public class RootShell { private static final String SU = "su"; private static final String TAG = "WireGuard/" + RootShell.class.getSimpleName(); + private final Context context; private final String deviceNotRootedMessage; private final File localBinaryDir; private final File localTemporaryDir; @@ -47,6 +49,7 @@ public class RootShell { localTemporaryDir = new File(cacheDir, "tmp"); preamble = String.format("export CALLING_PACKAGE=%s PATH=\"%s:$PATH\" TMPDIR='%s'; id -u\n", BuildConfig.APPLICATION_ID, localBinaryDir, localTemporaryDir); + this.context = context; } private static boolean isExecutableInPath(final String name) { @@ -121,9 +124,10 @@ public class RootShell { } } if (markersSeen != 4) - throw new IOException("Expected 4 markers, received " + markersSeen); + throw new IOException(String.format(Locale.getDefault(), + context.getResources().getString(R.string.marker_count_error), markersSeen)); if (errnoStdout != errnoStderr) - throw new IOException("Unable to read exit status"); + throw new IOException(context.getResources().getString(R.string.exit_status_read_error)); Log.v(TAG, "exit: " + errnoStdout); return errnoStdout; } @@ -136,9 +140,9 @@ public class RootShell { if (isRunning()) return; if (!localBinaryDir.isDirectory() && !localBinaryDir.mkdirs()) - throw new FileNotFoundException("Could not create local binary directory"); + throw new FileNotFoundException(context.getResources().getString(R.string.create_bin_dir_error)); if (!localTemporaryDir.isDirectory() && !localTemporaryDir.mkdirs()) - throw new FileNotFoundException("Could not create local temporary directory"); + throw new FileNotFoundException(context.getResources().getString(R.string.create_temp_dir_error)); try { final ProcessBuilder builder = new ProcessBuilder().command(SU); builder.environment().put("LC_ALL", "C"); @@ -168,7 +172,8 @@ public class RootShell { if (line.contains("Permission denied")) throw new NoRootException(deviceNotRootedMessage); } - throw new IOException("Shell failed to start: " + process.exitValue()); + throw new IOException(String.format(Locale.getDefault(), + context.getResources().getString(R.string.shell_start_error), process.exitValue())); } } catch (final IOException | NoRootException e) { stop(); diff --git a/app/src/main/java/com/wireguard/android/util/ToolsInstaller.java b/app/src/main/java/com/wireguard/android/util/ToolsInstaller.java index 143a8724..ebdfd3d3 100644 --- a/app/src/main/java/com/wireguard/android/util/ToolsInstaller.java +++ b/app/src/main/java/com/wireguard/android/util/ToolsInstaller.java @@ -12,6 +12,7 @@ import android.util.Log; import com.wireguard.android.Application; import com.wireguard.android.BuildConfig; +import com.wireguard.android.R; import com.wireguard.android.util.RootShell.NoRootException; import java.io.File; @@ -41,6 +42,7 @@ public final class ToolsInstaller { @Nullable private static final File INSTALL_DIR = getInstallDir(); private static final String TAG = "WireGuard/" + ToolsInstaller.class.getSimpleName(); + private final Context context; private final File localBinaryDir; private final Object lock = new Object(); private final File nativeLibraryDir; @@ -50,6 +52,7 @@ public final class ToolsInstaller { public ToolsInstaller(final Context context) { localBinaryDir = new File(context.getCacheDir(), "bin"); nativeLibraryDir = new File(context.getApplicationInfo().nativeLibraryDir); + this.context = context; } @Nullable @@ -102,7 +105,8 @@ public final class ToolsInstaller { } } if (!areToolsAvailable) - throw new FileNotFoundException("Required tools unavailable"); + throw new FileNotFoundException( + context.getResources().getString(R.string.tools_unavailable_error)); } } |