From 79fc0f97eafd6a70bd40bb8cddd50de52ef84f7c Mon Sep 17 00:00:00 2001 From: Adithya Abraham Philip Date: Thu, 11 Jun 2015 05:33:31 +0530 Subject: added proxy to all import operations using KeychainService --- .../keychain/util/orbot/OrbotHelper.java | 48 ++++++++++++++++++++++ 1 file changed, 48 insertions(+) (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/orbot/OrbotHelper.java') 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 fb016f9e6..5e0e393c5 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 @@ -55,12 +55,17 @@ import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.content.pm.PackageManager; +import android.os.Handler; +import android.os.Message; import android.os.Messenger; import android.support.v4.app.DialogFragment; +import android.support.v4.app.FragmentActivity; +import android.support.v4.app.FragmentManager; import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.ui.dialog.InstallDialogFragment; import org.sufficientlysecure.keychain.ui.dialog.OrbotStartDialogFragment; import org.sufficientlysecure.keychain.ui.dialog.PreferenceInstallDialogFragment; +import org.sufficientlysecure.keychain.util.Preferences; /** * This class is taken from the NetCipher library: https://github.com/guardianproject/NetCipher/ @@ -130,4 +135,47 @@ public class OrbotHelper { intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); return intent; } + + /** + * 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 middleButtonRunnable runnable to be executed if the user clicks on the middle button + * @param proxyPrefs + * @param fragmentActivity + * @return true if Tor is not enabled or Tor is enabled and Orbot is installed and running, else false + */ + public static boolean isOrbotInRequiredState(int middleButton, final Runnable middleButtonRunnable, + Preferences.ProxyPrefs proxyPrefs, FragmentActivity fragmentActivity) { + Handler ignoreTorHandler = new Handler() { + @Override + public void handleMessage(Message msg) { + // every message received by this handler will mean the middle button was pressed + middleButtonRunnable.run(); + } + }; + + if (!proxyPrefs.torEnabled) { + return true; + } + + if(!OrbotHelper.isOrbotInstalled(fragmentActivity)) { + + OrbotHelper.getInstallDialogFragmentWithThirdButton( + new Messenger(ignoreTorHandler), + R.string.orbot_install_dialog_ignore_tor + ).show(fragmentActivity.getSupportFragmentManager(), "OrbotHelperOrbotInstallDialog"); + + return false; + } else if(!OrbotHelper.isOrbotRunning()) { + + OrbotHelper.getOrbotStartDialogFragment(new Messenger(ignoreTorHandler), + R.string.orbot_install_dialog_ignore_tor) + .show(fragmentActivity.getSupportFragmentManager(), "OrbotHelperOrbotStartDialog"); + + return false; + } else { + return true; + } + } } -- cgit v1.2.3