summaryrefslogtreecommitdiffhomepage
path: root/app/src/main/java/com/wireguard
diff options
context:
space:
mode:
authorSamuel Holland <samuel@sholland.org>2018-01-16 05:47:10 -0600
committerSamuel Holland <samuel@sholland.org>2018-01-17 14:35:39 -0600
commit4695407449ce66e49c5a647926c19d2b77064c2d (patch)
treefb822447f4cd51706b81503c765a649bb354afcd /app/src/main/java/com/wireguard
parenta66ca3fe21ebde9630789fb48404715d6876b470 (diff)
ToolsInstaller: Remove double-checked locking
It can't work and may be crashing the runtime. Use a lock object to avoid exposing the synchronization in the class's interface. Signed-off-by: Samuel Holland <samuel@sholland.org>
Diffstat (limited to 'app/src/main/java/com/wireguard')
-rw-r--r--app/src/main/java/com/wireguard/android/util/ToolsInstaller.java31
1 files changed, 15 insertions, 16 deletions
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 dca410f0..2aa35957 100644
--- a/app/src/main/java/com/wireguard/android/util/ToolsInstaller.java
+++ b/app/src/main/java/com/wireguard/android/util/ToolsInstaller.java
@@ -34,6 +34,7 @@ public final class ToolsInstaller {
private static final String TAG = "WireGuard/" + ToolsInstaller.class.getSimpleName();
private final File localBinaryDir;
+ private final Object lock = new Object();
private final File nativeLibraryDir;
private final RootShell rootShell;
private Boolean areToolsAvailable;
@@ -74,25 +75,23 @@ public final class ToolsInstaller {
}
public void ensureToolsAvailable() throws FileNotFoundException, NoRootException {
- if (areToolsAvailable == null) {
- synchronized (this) {
- if (areToolsAvailable == null) {
- int ret = symlink();
- if (ret == OsConstants.EALREADY) {
- Log.d(TAG, "Tools were already symlinked into our private binary dir");
- areToolsAvailable = true;
- } else if (ret == OsConstants.EXIT_SUCCESS) {
- Log.d(TAG, "Tools are now symlinked into our private binary dir");
- areToolsAvailable = true;
- } else {
- Log.e(TAG, "For some reason, wg and wg-quick are not available at all");
- areToolsAvailable = false;
- }
+ synchronized (lock) {
+ if (areToolsAvailable == null) {
+ final int ret = symlink();
+ if (ret == OsConstants.EALREADY) {
+ Log.d(TAG, "Tools were already symlinked into our private binary dir");
+ areToolsAvailable = true;
+ } else if (ret == OsConstants.EXIT_SUCCESS) {
+ Log.d(TAG, "Tools are now symlinked into our private binary dir");
+ areToolsAvailable = true;
+ } else {
+ Log.e(TAG, "For some reason, wg and wg-quick are not available at all");
+ areToolsAvailable = false;
}
}
+ if (!areToolsAvailable)
+ throw new FileNotFoundException("Required tools unavailable");
}
- if (!areToolsAvailable)
- throw new FileNotFoundException("Required tools unavailable");
}
public int install() throws NoRootException {