[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[or-cvs] r22685: {projects} fixed issue with force close crash on install (projects/android/trunk/Orbot/src/org/torproject/android/service)
Author: n8fr8
Date: 2010-07-24 03:24:30 +0000 (Sat, 24 Jul 2010)
New Revision: 22685
Modified:
projects/android/trunk/Orbot/src/org/torproject/android/service/TorBinaryInstaller.java
projects/android/trunk/Orbot/src/org/torproject/android/service/TorService.java
projects/android/trunk/Orbot/src/org/torproject/android/service/TorServiceConstants.java
Log:
fixed issue with force close crash on install
Modified: projects/android/trunk/Orbot/src/org/torproject/android/service/TorBinaryInstaller.java
===================================================================
--- projects/android/trunk/Orbot/src/org/torproject/android/service/TorBinaryInstaller.java 2010-07-23 23:21:25 UTC (rev 22684)
+++ projects/android/trunk/Orbot/src/org/torproject/android/service/TorBinaryInstaller.java 2010-07-24 03:24:30 UTC (rev 22685)
@@ -17,8 +17,13 @@
public class TorBinaryInstaller implements TorServiceConstants {
- public TorBinaryInstaller ()
+ String installPath = null;
+ String apkPath = null;
+
+ public TorBinaryInstaller (String installPath, String apkPath)
{
+ this.installPath = installPath;
+ this.apkPath = apkPath;
}
/*
@@ -26,10 +31,11 @@
*/
public void start (boolean force)
{
- boolean torBinaryExists = new File(TOR_BINARY_INSTALL_PATH).exists();
+
+ boolean torBinaryExists = new File(installPath + TOR_BINARY_ASSET_KEY).exists();
Log.i(TAG,"Tor binary exists=" + torBinaryExists);
- boolean privoxyBinaryExists = new File(PRIVOXY_INSTALL_PATH).exists();
+ boolean privoxyBinaryExists = new File(installPath + PRIVOXY_ASSET_KEY).exists();
Log.i(TAG,"Privoxy binary exists=" + privoxyBinaryExists);
if (!(torBinaryExists && privoxyBinaryExists) || force)
@@ -45,7 +51,7 @@
try
{
-
+ /*
String apkPath = APK_PATH;
int apkIdx = 1;
@@ -56,21 +62,23 @@
Log.i(TAG,"Could not find APK. Trying new path: " + apkPath);
}
+ */
+
ZipFile zip = new ZipFile(apkPath);
ZipEntry zipen = zip.getEntry(TOR_BINARY_ZIP_KEY);
- streamToFile(zip.getInputStream(zipen),TOR_BINARY_INSTALL_PATH);
+ streamToFile(zip.getInputStream(zipen),installPath + TOR_BINARY_ASSET_KEY);
zipen = zip.getEntry(TORRC_ZIP_KEY);
- streamToFile(zip.getInputStream(zipen),TORRC_INSTALL_PATH);
+ streamToFile(zip.getInputStream(zipen),installPath + TORRC_ASSET_KEY);
zipen = zip.getEntry(PRIVOXY_ZIP_KEY);
- streamToFile(zip.getInputStream(zipen),PRIVOXY_INSTALL_PATH);
+ streamToFile(zip.getInputStream(zipen),installPath + PRIVOXY_ASSET_KEY);
zipen = zip.getEntry(PRIVOXYCONFIG_ZIP_KEY);
- streamToFile(zip.getInputStream(zipen),PRIVOXYCONFIG_INSTALL_PATH);
+ streamToFile(zip.getInputStream(zipen),installPath + PRIVOXYCONFIG_ASSET_KEY);
zip.close();
Modified: projects/android/trunk/Orbot/src/org/torproject/android/service/TorService.java
===================================================================
--- projects/android/trunk/Orbot/src/org/torproject/android/service/TorService.java 2010-07-23 23:21:25 UTC (rev 22684)
+++ projects/android/trunk/Orbot/src/org/torproject/android/service/TorService.java 2010-07-24 03:24:30 UTC (rev 22685)
@@ -51,25 +51,25 @@
private boolean hasRoot = false;
+ private String appHome = null;
+ private String torBinaryPath = null;
+ private String privoxyPath = null;
+
/** Called when the activity is first created. */
public void onCreate() {
super.onCreate();
Log.i(TAG,"TorService: onCreate");
-
- checkTorBinaries();
-
- findExistingProc ();
-
- _torInstance = this;
- hasRoot = TorServiceUtils.hasRoot();
-
+
+
+
}
+
private boolean findExistingProc ()
{
- int procId = TorServiceUtils.findProcessId(TorServiceConstants.TOR_BINARY_INSTALL_PATH);
+ int procId = TorServiceUtils.findProcessId(torBinaryPath);
if (procId != -1)
{
@@ -274,7 +274,7 @@
StringBuilder log = new StringBuilder();
- int procId = TorServiceUtils.findProcessId(TorServiceConstants.TOR_BINARY_INSTALL_PATH);
+ int procId = TorServiceUtils.findProcessId(torBinaryPath);
while (procId != -1)
{
@@ -284,10 +284,10 @@
String[] cmd = { SHELL_CMD_KILL + ' ' + procId + "" };
TorServiceUtils.doShellCommand(cmd,log, false, false);
- procId = TorServiceUtils.findProcessId(TorServiceConstants.TOR_BINARY_INSTALL_PATH);
+ procId = TorServiceUtils.findProcessId(torBinaryPath);
}
- procId = TorServiceUtils.findProcessId(TorServiceConstants.PRIVOXY_INSTALL_PATH);
+ procId = TorServiceUtils.findProcessId(privoxyPath);
while (procId != -1)
{
@@ -297,7 +297,7 @@
TorServiceUtils.doShellCommand(cmd,log, false, false);
- procId = TorServiceUtils.findProcessId(TorServiceConstants.PRIVOXY_INSTALL_PATH);
+ procId = TorServiceUtils.findProcessId(privoxyPath);
}
}
@@ -311,22 +311,77 @@
}
+ private String findAPK ()
+ {
+
+ String apkBase = "/data/app/";
+
+ String APK_EXT = ".apk";
+
+
+ String buildPath = apkBase + TOR_APP_USERNAME + APK_EXT;
+ Log.i(TAG, "Checking APK location: " + buildPath);
+
+ File fileApk = new File(buildPath);
+
+ if (fileApk.exists())
+ return fileApk.getAbsolutePath();
+
+ for (int i = 0; i < 10; i++)
+ {
+ buildPath = apkBase + TOR_APP_USERNAME + '-' + i + APK_EXT;
+ fileApk = new File(buildPath);
+
+ Log.i(TAG, "Checking APK location: " + buildPath);
+
+ if (fileApk.exists())
+ return fileApk.getAbsolutePath();
+ }
+
+ return null;
+ }
+
private boolean checkTorBinaries ()
{
+ //android.os.Debug.waitForDebugger();
+
+
+ Log.i(TAG,"checking Tor binaries");
+
+ //appHome = getApplicationContext().getFilesDir().getAbsolutePath();
+ appHome = "/data/data/" + TOR_APP_USERNAME + "/";
+
+ Log.i(TAG,"appHome=" + appHome);
+
+ String apkPath = findAPK();
+
+ Log.i(TAG,"found apk at: " + apkPath);
+
+ boolean apkExists = new File(apkPath).exists();
+
+ if (!apkExists)
+ {
+ Log.w(TAG,"APK file not found at: " + apkPath);
+ Log.w(TAG,"Binary installation aborted");
+ return false;
+ }
+
+ torBinaryPath = appHome + '/' + TOR_BINARY_ASSET_KEY;
+ privoxyPath = appHome + '/' + PRIVOXY_ASSET_KEY;
+
+ boolean torBinaryExists = new File(torBinaryPath).exists();
+ boolean privoxyBinaryExists = new File(privoxyPath).exists();
- boolean torBinaryExists = new File(TOR_BINARY_INSTALL_PATH).exists();
- boolean privoxyBinaryExists = new File(PRIVOXY_INSTALL_PATH).exists();
-
if (!(torBinaryExists && privoxyBinaryExists))
{
killTorProcess ();
- TorBinaryInstaller installer = new TorBinaryInstaller();
+ TorBinaryInstaller installer = new TorBinaryInstaller(appHome, apkPath);
installer.start(true);
-
- torBinaryExists = new File(TOR_BINARY_INSTALL_PATH).exists();
- privoxyBinaryExists = new File(PRIVOXY_INSTALL_PATH).exists();
+ torBinaryExists = new File(torBinaryPath).exists();
+ privoxyBinaryExists = new File(privoxyPath).exists();
+
if (torBinaryExists && privoxyBinaryExists)
{
logNotice(getString(R.string.status_install_success));
@@ -339,7 +394,9 @@
logNotice(getString(R.string.status_install_fail));
- showAlert(getString(R.string.title_error),getString(R.string.status_install_fail));
+ sendCallbackMessage(getString(R.string.status_install_fail));
+
+ //showAlert(getString(R.string.title_error),getString(R.string.status_install_fail));
return false;
}
@@ -349,11 +406,11 @@
StringBuilder log = new StringBuilder ();
logNotice("Setting permission on Tor binary");
- String[] cmd1 = {SHELL_CMD_CHMOD + ' ' + CHMOD_EXE_VALUE + ' ' + TOR_BINARY_INSTALL_PATH};
+ String[] cmd1 = {SHELL_CMD_CHMOD + ' ' + CHMOD_EXE_VALUE + ' ' + torBinaryPath};
TorServiceUtils.doShellCommand(cmd1, log, false, true);
logNotice("Setting permission on Privoxy binary");
- String[] cmd2 = {SHELL_CMD_CHMOD + ' ' + CHMOD_EXE_VALUE + ' ' + PRIVOXY_INSTALL_PATH};
+ String[] cmd2 = {SHELL_CMD_CHMOD + ' ' + CHMOD_EXE_VALUE + ' ' + privoxyPath};
TorServiceUtils.doShellCommand(cmd2, log, false, true);
return true;
@@ -363,6 +420,9 @@
{
// android.os.Debug.waitForDebugger();
+
+
+
currentStatus = STATUS_CONNECTING;
logNotice(getString(R.string.status_starting_up));
@@ -417,11 +477,13 @@
Log.i(TAG,"Starting tor process");
- String[] torCmd = {TOR_BINARY_INSTALL_PATH + ' ' + TOR_COMMAND_LINE_ARGS};
+ String torrcPath = appHome + TORRC_ASSET_KEY;
+
+ String[] torCmd = {torBinaryPath + " -f " + torrcPath + " || exit\n"};
TorServiceUtils.doShellCommand(torCmd, log, false, false);
Thread.sleep(1000);
- int procId = TorServiceUtils.findProcessId(TorServiceConstants.TOR_BINARY_INSTALL_PATH);
+ int procId = TorServiceUtils.findProcessId(torBinaryPath);
int attempts = 0;
@@ -432,7 +494,7 @@
logNotice(torCmd[0]);
TorServiceUtils.doShellCommand(torCmd, log, false, false);
- procId = TorServiceUtils.findProcessId(TorServiceConstants.TOR_BINARY_INSTALL_PATH);
+ procId = TorServiceUtils.findProcessId(torBinaryPath);
if (procId == -1)
{
@@ -463,7 +525,7 @@
private void runPrivoxyShellCmd () throws Exception
{
- int privoxyProcId = TorServiceUtils.findProcessId(TorServiceConstants.PRIVOXY_INSTALL_PATH);
+ int privoxyProcId = TorServiceUtils.findProcessId(privoxyPath);
StringBuilder log = null;
@@ -473,8 +535,10 @@
{
log = new StringBuilder();
+ String privoxyConfigPath = appHome + PRIVOXYCONFIG_ASSET_KEY;
+
String[] cmds =
- { PRIVOXY_INSTALL_PATH + " " + PRIVOXY_COMMAND_LINE_ARGS };
+ { privoxyPath + " " + privoxyConfigPath };
logNotice (cmds[0]);
@@ -483,7 +547,7 @@
//wait one second to make sure it has started up
Thread.sleep(1000);
- privoxyProcId = TorServiceUtils.findProcessId(TorServiceConstants.PRIVOXY_INSTALL_PATH);
+ privoxyProcId = TorServiceUtils.findProcessId(privoxyPath);
if (privoxyProcId == -1)
{
@@ -534,9 +598,11 @@
Log.i(TAG,"SUCCESS connected to control port");
- File fileCookie = new File(TOR_CONTROL_AUTH_COOKIE);
+ String torAuthCookie = appHome + "data/control_auth_cookie";
+
+ File fileCookie = new File(torAuthCookie);
byte[] cookie = new byte[(int)fileCookie.length()];
- new FileInputStream(new File(TOR_CONTROL_AUTH_COOKIE)).read(cookie);
+ new FileInputStream(new File(torAuthCookie)).read(cookie);
conn.authenticate(cookie);
Log.i(TAG,"SUCCESS authenticated to control port");
@@ -772,16 +838,27 @@
}
- private Intent launchContext = null;
-
public IBinder onBind(Intent intent) {
// Select the interface to return. If your service only implements
// a single interface, you can just return it here without checking
// the Intent.
- if (ITorService.class.getName().equals(intent.getAction())) {
+
+ if (appHome == null)
+ {
+ checkTorBinaries();
+
+ findExistingProc ();
+
+ _torInstance = this;
+
+ hasRoot = TorServiceUtils.hasRoot();
+ }
+
+ if (ITorService.class.getName().equals(intent.getAction())) {
return mBinder;
}
-
+
+
return null;
}
Modified: projects/android/trunk/Orbot/src/org/torproject/android/service/TorServiceConstants.java
===================================================================
--- projects/android/trunk/Orbot/src/org/torproject/android/service/TorServiceConstants.java 2010-07-23 23:21:25 UTC (rev 22684)
+++ projects/android/trunk/Orbot/src/org/torproject/android/service/TorServiceConstants.java 2010-07-24 03:24:30 UTC (rev 22685)
@@ -9,40 +9,40 @@
public final static String TOR_APP_USERNAME = "org.torproject.android";
//home directory of Android application
- public final static String TOR_HOME = "/data/data/" + TOR_APP_USERNAME + "/";
+// public final static String TOR_HOME = "/data/data/" + TOR_APP_USERNAME + "/";
- public final static String TOR_HOME_DATA_DIR = TOR_HOME + "data/";
+ //public final static String TOR_HOME_DATA_DIR = TOR_HOME + "data/";
//name of the tor C binary
public final static String TOR_BINARY_ASSET_KEY = "tor";
- public final static String TOR_BINARY_INSTALL_PATH = TOR_HOME + TOR_BINARY_ASSET_KEY; //path to install the Tor binary too
+// public final static String TOR_BINARY_INSTALL_PATH = TOR_HOME + TOR_BINARY_ASSET_KEY; //path to install the Tor binary too
public final static String TOR_BINARY_ZIP_KEY = "assets/" + TOR_BINARY_ASSET_KEY;//key of the tor binary in the Zip file
//torrc (tor config file)
public final static String TORRC_ASSET_KEY = "torrc";
- public final static String TORRC_INSTALL_PATH = TOR_HOME + TORRC_ASSET_KEY; //path to install torrc to within the android app data folder
+// public final static String TORRC_INSTALL_PATH = TOR_HOME + TORRC_ASSET_KEY; //path to install torrc to within the android app data folder
public final static String TORRC_ZIP_KEY = "assets/" + TORRC_ASSET_KEY; //key of the torrc file in the Zip file
//how to launch tor
- public final static String TOR_COMMAND_LINE_ARGS = "-f " + TORRC_INSTALL_PATH + " || exit\n";
+// public final static String TOR_COMMAND_LINE_ARGS = "-f " + TORRC_INSTALL_PATH + " || exit\n";
//privoxy
public final static String PRIVOXY_ASSET_KEY = "privoxy";
- public final static String PRIVOXY_INSTALL_PATH = TOR_HOME + PRIVOXY_ASSET_KEY; //path to install privoxy to within the android app data folder
+// public final static String PRIVOXY_INSTALL_PATH = TOR_HOME + PRIVOXY_ASSET_KEY; //path to install privoxy to within the android app data folder
public final static String PRIVOXY_ZIP_KEY = "assets/" + PRIVOXY_ASSET_KEY; //key of the privoxy file in the Zip file
//privoxy.config
public final static String PRIVOXYCONFIG_ASSET_KEY = "privoxy.config";
- public final static String PRIVOXYCONFIG_INSTALL_PATH = TOR_HOME + PRIVOXYCONFIG_ASSET_KEY; //path to install privoxy to within the android app data folder
+// public final static String PRIVOXYCONFIG_INSTALL_PATH = TOR_HOME + PRIVOXYCONFIG_ASSET_KEY; //path to install privoxy to within the android app data folder
public final static String PRIVOXYCONFIG_ZIP_KEY = "assets/" + PRIVOXYCONFIG_ASSET_KEY; //key of the privoxy file in the Zip file
//how to launch privoxy
- public final static String PRIVOXY_COMMAND_LINE_ARGS = ' ' + PRIVOXYCONFIG_INSTALL_PATH + " || exit\n";
+// public final static String PRIVOXY_COMMAND_LINE_ARGS = ' ' + PRIVOXYCONFIG_INSTALL_PATH + " || exit\n";
//where to send the notices log
- public final static String TOR_LOG_PATH = TOR_HOME + "notices.log";
+// public final static String TOR_LOG_PATH = TOR_HOME + "notices.log";
//control port cookie path
- public final static String TOR_CONTROL_AUTH_COOKIE = TOR_HOME_DATA_DIR + "control_auth_cookie";
+// public final static String TOR_CONTROL_AUTH_COOKIE = TOR_HOME_DATA_DIR + "control_auth_cookie";
//various console cmds
@@ -56,7 +56,7 @@
//path of the installed APK file
public final static String APK_PATH = "/data/app/org.torproject.android.apk";
- public final static String APK_PATH_BASE = "/data/app/org.torproject.android";
+ public final static String APK_PATH_BASE = "/data/app";