improve process id finding using android 'toolbox'

This commit is contained in:
Nathan Freitas 2014-06-11 07:51:22 -04:00
parent 2d6a7b35c0
commit b4fa943fe9
3 changed files with 14 additions and 7 deletions

View File

@ -966,9 +966,13 @@ public class TorService extends Service implements TorServiceConstants, TorConst
}
catch (Exception e)
catch (FileNotFoundException e)
{
logException("unable to get control port",e);
logNotice("unable to get control port: no file yet");
}
catch (IOException e)
{
logNotice("unable to get control port IOException");
}

View File

@ -35,7 +35,7 @@ public interface TorServiceConstants {
public final static String SHELL_CMD_CHMOD = "chmod";
public final static String SHELL_CMD_KILL = "kill -9";
public final static String SHELL_CMD_RM = "rm";
public final static String SHELL_CMD_PS = "ps";
public final static String SHELL_CMD_PS = "toolbox ps";
//public final static String SHELL_CMD_PIDOF = "pidof";
public final static String SHELL_CMD_LINK = "ln -s";
public final static String SHELL_CMD_CP = "cp";

View File

@ -78,16 +78,19 @@ public class TorServiceUtils implements TorServiceConstants {
Process procPs = null;
//String processKey = new File(command).getName();
String processKey = new File(command).getName();
procPs = r.exec(SHELL_CMD_PS); // this is the android ps <name> command
procPs = r.exec(SHELL_CMD_PS + ' ' + processKey); // this is the android ps <name> command
BufferedReader reader = new BufferedReader(new InputStreamReader(procPs.getInputStream()));
String line = reader.readLine(); //read first line "headers" USER PID PPID etc
String line = null;
while ((line = reader.readLine())!=null)
{
if (line.contains(command))
if (line.contains("PID"))
continue;
if (line.contains(processKey))
{
String[] lineParts = line.split("\\s+");