commit 1f36689b90cf372ee5bc70ecf3b24b03c352a659 Author: n8fr8 nathan@guardianproject.info Date: Wed Jun 5 14:45:46 2019 -0400
make sure we set HOME env variable some devices don't have it for their sh commands --- .../src/main/java/org/torproject/android/service/TorService.java | 6 +++++- .../java/org/torproject/android/service/util/CustomShell.java | 9 ++++++++- 2 files changed, 13 insertions(+), 2 deletions(-)
diff --git a/orbotservice/src/main/java/org/torproject/android/service/TorService.java b/orbotservice/src/main/java/org/torproject/android/service/TorService.java index 7881339d..9eced17b 100644 --- a/orbotservice/src/main/java/org/torproject/android/service/TorService.java +++ b/orbotservice/src/main/java/org/torproject/android/service/TorService.java @@ -69,6 +69,7 @@ import java.text.Normalizer; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; +import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Random; @@ -986,7 +987,10 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
private int exec (String cmd, boolean wait) throws Exception { - CommandResult result = CustomShell.run("sh",wait, null, cmd); + HashMap<String,String> mapEnv = new HashMap(); + mapEnv.put("HOME",appBinHome.getAbsolutePath()); + + CommandResult result = CustomShell.run("sh",wait, mapEnv, cmd); debug("executing: " + cmd); debug("stdout: " + result.getStdout()); debug("stderr: " + result.getStderr()); diff --git a/orbotservice/src/main/java/org/torproject/android/service/util/CustomShell.java b/orbotservice/src/main/java/org/torproject/android/service/util/CustomShell.java index 8bd5fe6f..b959405d 100644 --- a/orbotservice/src/main/java/org/torproject/android/service/util/CustomShell.java +++ b/orbotservice/src/main/java/org/torproject/android/service/util/CustomShell.java @@ -13,13 +13,15 @@ import java.io.DataOutputStream; import java.io.IOException; import java.util.ArrayList; import java.util.Collections; +import java.util.Iterator; import java.util.List; +import java.util.Map;
public class CustomShell extends Shell {
@WorkerThread - public static CommandResult run(@NonNull String shell, boolean waitFor, @Nullable String[] env, @NonNull String command) { + public static CommandResult run(@NonNull String shell, boolean waitFor, @Nullable Map<String,String> env, @NonNull String command) { List<String> stdout = Collections.synchronizedList(new ArrayList<String>()); List<String> stderr = Collections.synchronizedList(new ArrayList<String>()); int exitCode = -1; @@ -29,6 +31,11 @@ public class CustomShell extends Shell { // setup our process, retrieve stdin stream, and stdout/stderr gobblers //Process process = runWithEnv(command, env); ProcessBuilder builder = new ProcessBuilder(); + + + if (env != null && (!env.isEmpty())) + builder.environment().putAll(env); + builder.command("/system/bin/sh", "-c", command); Process process = builder.start();
tor-commits@lists.torproject.org