re-enabled root permission request and shell

This commit is contained in:
Nathan Freitas 2016-10-29 11:33:26 -04:00
parent f4638873f8
commit ef57341c6e
2 changed files with 50 additions and 23 deletions

View File

@ -805,8 +805,9 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
} }
private boolean flushTransparentProxyRules () { private boolean flushTransparentProxyRules () {
if (Prefs.useRoot())
{ try {
if (Prefs.useRoot()) {
if (mTransProxy == null) if (mTransProxy == null)
mTransProxy = new TorTransProxy(this, fileXtables); mTransProxy = new TorTransProxy(this, fileXtables);
@ -818,8 +819,11 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
} }
return true; return true;
} else {
return false;
} }
else }
catch (IOException ioe)
{ {
return false; return false;
} }

View File

@ -1,6 +1,8 @@
package org.torproject.android.service.transproxy; package org.torproject.android.service.transproxy;
import java.io.DataOutputStream;
import java.io.File; import java.io.File;
import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
@ -30,10 +32,25 @@ public class TorTransProxy implements TorServiceConstants {
private int mTransProxyPort = TOR_TRANSPROXY_PORT_DEFAULT; private int mTransProxyPort = TOR_TRANSPROXY_PORT_DEFAULT;
private int mDNSPort = TOR_DNS_PORT_DEFAULT; private int mDNSPort = TOR_DNS_PORT_DEFAULT;
public TorTransProxy (TorService torService, File fileXTables) private Process mProcess = null;
private DataOutputStream mProcessOutput = null;
public TorTransProxy (TorService torService, File fileXTables) throws IOException
{ {
mTorService = torService; mTorService = torService;
mFileXtables = fileXTables; mFileXtables = fileXTables;
mProcess = Runtime.getRuntime().exec("su");
mProcessOutput = new DataOutputStream(mProcess.getOutputStream());
}
public static boolean testRoot () throws IOException
{
Runtime.getRuntime().exec("su");
return true;
} }
public void setTransProxyPort (int transProxyPort) public void setTransProxyPort (int transProxyPort)
@ -545,15 +562,21 @@ public class TorTransProxy implements TorServiceConstants {
private int executeCommand (String cmdString) throws Exception { private int executeCommand (String cmdString) throws Exception {
Process proc = Runtime.getRuntime().exec(cmdString); mProcessOutput.writeBytes(cmdString + "\n");
proc.waitFor(); mProcessOutput.flush();
int exitCode = proc.exitValue();
//String output = cmd.getOutput();
logMessage(cmdString);
logMessage(cmdString + "; exit=" + exitCode); return 0;
}
public int doExit () throws Exception
{
mProcessOutput.writeBytes("exit\n");
mProcessOutput.flush();
return mProcess.waitFor();
return exitCode;
} }