diff options
Diffstat (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/orbot')
2 files changed, 26 insertions, 42 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/orbot/OrbotHelper.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/orbot/OrbotHelper.java index 5e0e393c5..f57496767 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/orbot/OrbotHelper.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/orbot/OrbotHelper.java @@ -77,15 +77,13 @@ public class OrbotHelper { public final static String ACTION_START_TOR = "org.torproject.android.START_TOR"; - public static boolean isOrbotRunning() - { + public static boolean isOrbotRunning() { int procId = TorServiceUtils.findProcessId(TOR_BIN_PATH); return (procId != -1); } - public static boolean isOrbotInstalled(Context context) - { + public static boolean isOrbotInstalled(Context context) { return isAppInstalled(ORBOT_PACKAGE_NAME, context); } @@ -102,30 +100,28 @@ public class OrbotHelper { } /** - * hack to get around teh fact that PreferenceActivity still supports only android.app.DialogFragment + * hack to get around the fact that PreferenceActivity still supports only android.app.DialogFragment * * @return */ - public static android.app.DialogFragment getPreferenceInstallDialogFragment() - { + public static android.app.DialogFragment getPreferenceInstallDialogFragment() { return PreferenceInstallDialogFragment.newInstance(R.string.orbot_install_dialog_title, R.string.orbot_install_dialog_content, ORBOT_PACKAGE_NAME); } - public static DialogFragment getInstallDialogFragment() - { + public static DialogFragment getInstallDialogFragment() { return InstallDialogFragment.newInstance(R.string.orbot_install_dialog_title, R.string.orbot_install_dialog_content, ORBOT_PACKAGE_NAME); } - public static DialogFragment getInstallDialogFragmentWithThirdButton(Messenger messenger, int middleButton) - { + public static DialogFragment getInstallDialogFragmentWithThirdButton(Messenger messenger, int middleButton) { return InstallDialogFragment.newInstance(messenger, R.string.orbot_install_dialog_title, R.string.orbot_install_dialog_content, ORBOT_PACKAGE_NAME, middleButton, true); } public static DialogFragment getOrbotStartDialogFragment(Messenger messenger, int middleButton) { - return OrbotStartDialogFragment.newInstance(messenger, R.string.orbot_start_dialog_title, R.string.orbot_start_dialog_content, + return OrbotStartDialogFragment.newInstance(messenger, R.string.orbot_start_dialog_title, R.string + .orbot_start_dialog_content, middleButton); } @@ -139,7 +135,7 @@ public class OrbotHelper { /** * checks if Tor is enabled and if it is, that Orbot is installed and runnign. Generates appropriate dialogs. * - * @param middleButton resourceId of string to display as the middle button of install and enable dialogs + * @param middleButton resourceId of string to display as the middle button of install and enable dialogs * @param middleButtonRunnable runnable to be executed if the user clicks on the middle button * @param proxyPrefs * @param fragmentActivity @@ -159,7 +155,7 @@ public class OrbotHelper { return true; } - if(!OrbotHelper.isOrbotInstalled(fragmentActivity)) { + if (!OrbotHelper.isOrbotInstalled(fragmentActivity)) { OrbotHelper.getInstallDialogFragmentWithThirdButton( new Messenger(ignoreTorHandler), @@ -167,7 +163,7 @@ public class OrbotHelper { ).show(fragmentActivity.getSupportFragmentManager(), "OrbotHelperOrbotInstallDialog"); return false; - } else if(!OrbotHelper.isOrbotRunning()) { + } else if (!OrbotHelper.isOrbotRunning()) { OrbotHelper.getOrbotStartDialogFragment(new Messenger(ignoreTorHandler), R.string.orbot_install_dialog_ignore_tor) diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/orbot/TorServiceUtils.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/orbot/TorServiceUtils.java index 127e9d43f..b1d8327fb 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/orbot/TorServiceUtils.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/orbot/TorServiceUtils.java @@ -49,14 +49,14 @@ package org.sufficientlysecure.keychain.util.orbot; +import android.util.Log; + import java.io.BufferedReader; import java.io.File; import java.io.InputStreamReader; import java.net.URLEncoder; import java.util.StringTokenizer; -import android.util.Log; - /** * This class is taken from the NetCipher library: https://github.com/guardianproject/NetCipher/ */ @@ -68,23 +68,18 @@ public class TorServiceUtils { public final static String SHELL_CMD_PS = "ps"; public final static String SHELL_CMD_PIDOF = "pidof"; - public static int findProcessId(String command) - { + public static int findProcessId(String command) { int procId = -1; - try - { + try { procId = findProcessIdWithPidOf(command); if (procId == -1) procId = findProcessIdWithPS(command); - } catch (Exception e) - { - try - { + } catch (Exception e) { + try { procId = findProcessIdWithPS(command); - } catch (Exception e2) - { + } catch (Exception e2) { Log.e(TAG, "Unable to get proc id for command: " + URLEncoder.encode(command), e2); } } @@ -93,8 +88,7 @@ public class TorServiceUtils { } // use 'pidof' command - public static int findProcessIdWithPidOf(String command) throws Exception - { + public static int findProcessIdWithPidOf(String command) throws Exception { int procId = -1; @@ -104,7 +98,7 @@ public class TorServiceUtils { String baseName = new File(command).getName(); // fix contributed my mikos on 2010.12.10 - procPs = r.exec(new String[] { + procPs = r.exec(new String[]{ SHELL_CMD_PIDOF, baseName }); // procPs = r.exec(SHELL_CMD_PIDOF); @@ -112,16 +106,13 @@ public class TorServiceUtils { BufferedReader reader = new BufferedReader(new InputStreamReader(procPs.getInputStream())); String line = null; - while ((line = reader.readLine()) != null) - { + while ((line = reader.readLine()) != null) { - try - { + try { // this line should just be the process id procId = Integer.parseInt(line.trim()); break; - } catch (NumberFormatException e) - { + } catch (NumberFormatException e) { Log.e("TorServiceUtils", "unable to parse process pid: " + line, e); } } @@ -131,8 +122,7 @@ public class TorServiceUtils { } // use 'ps' command - public static int findProcessIdWithPS(String command) throws Exception - { + public static int findProcessIdWithPS(String command) throws Exception { int procId = -1; @@ -145,10 +135,8 @@ public class TorServiceUtils { BufferedReader reader = new BufferedReader(new InputStreamReader(procPs.getInputStream())); String line = null; - while ((line = reader.readLine()) != null) - { - if (line.indexOf(' ' + command) != -1) - { + while ((line = reader.readLine()) != null) { + if (line.indexOf(' ' + command) != -1) { StringTokenizer st = new StringTokenizer(line, " "); st.nextToken(); // proc owner |