mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-11-27 11:12:15 -05:00
Cleanup tor code
This commit is contained in:
parent
efcf045c46
commit
49d544d558
@ -19,7 +19,6 @@
|
||||
package org.sufficientlysecure.keychain.ui;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.Intent;
|
||||
import android.database.Cursor;
|
||||
import android.database.MatrixCursor;
|
||||
@ -53,16 +52,13 @@ import org.sufficientlysecure.keychain.provider.KeychainDatabase.Tables;
|
||||
import org.sufficientlysecure.keychain.provider.ProviderHelper;
|
||||
import org.sufficientlysecure.keychain.service.CertifyActionsParcel;
|
||||
import org.sufficientlysecure.keychain.service.CertifyActionsParcel.CertifyAction;
|
||||
import org.sufficientlysecure.keychain.service.KeychainService;
|
||||
import org.sufficientlysecure.keychain.service.ServiceProgressHandler;
|
||||
import org.sufficientlysecure.keychain.service.input.CryptoInputParcel;
|
||||
import org.sufficientlysecure.keychain.ui.adapter.MultiUserIdsAdapter;
|
||||
import org.sufficientlysecure.keychain.ui.base.CachingCryptoOperationFragment;
|
||||
import org.sufficientlysecure.keychain.ui.util.Notify;
|
||||
import org.sufficientlysecure.keychain.ui.widget.CertifyKeySpinner;
|
||||
import org.sufficientlysecure.keychain.util.Log;
|
||||
import org.sufficientlysecure.keychain.util.Preferences;
|
||||
import org.sufficientlysecure.keychain.util.orbot.OrbotHelper;
|
||||
import org.sufficientlysecure.keychain.util.tor.OrbotHelper;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
|
@ -47,7 +47,7 @@ import org.sufficientlysecure.keychain.ui.CreateKeyActivity.NfcListenerFragment;
|
||||
import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils;
|
||||
import org.sufficientlysecure.keychain.util.ParcelableProxy;
|
||||
import org.sufficientlysecure.keychain.util.Preferences;
|
||||
import org.sufficientlysecure.keychain.util.orbot.OrbotHelper;
|
||||
import org.sufficientlysecure.keychain.util.tor.OrbotHelper;
|
||||
|
||||
|
||||
public class CreateKeyYubiKeyImportFragment extends Fragment implements NfcListenerFragment {
|
||||
|
@ -51,14 +51,13 @@ import org.sufficientlysecure.keychain.provider.ProviderHelper;
|
||||
import org.sufficientlysecure.keychain.service.KeychainService;
|
||||
import org.sufficientlysecure.keychain.service.ServiceProgressHandler;
|
||||
import org.sufficientlysecure.keychain.ui.base.CachingCryptoOperationFragment;
|
||||
import org.sufficientlysecure.keychain.ui.base.CryptoOperationFragment;
|
||||
import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils;
|
||||
import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils.State;
|
||||
import org.sufficientlysecure.keychain.ui.util.Notify;
|
||||
import org.sufficientlysecure.keychain.ui.util.Notify.Style;
|
||||
import org.sufficientlysecure.keychain.util.ParcelableProxy;
|
||||
import org.sufficientlysecure.keychain.util.Preferences;
|
||||
import org.sufficientlysecure.keychain.util.orbot.OrbotHelper;
|
||||
import org.sufficientlysecure.keychain.util.tor.OrbotHelper;
|
||||
|
||||
public abstract class DecryptFragment
|
||||
extends CachingCryptoOperationFragment<PgpDecryptVerifyInputParcel, DecryptVerifyResult>
|
||||
|
@ -44,7 +44,7 @@ import org.sufficientlysecure.keychain.util.Log;
|
||||
import org.sufficientlysecure.keychain.util.ParcelableFileCache;
|
||||
import org.sufficientlysecure.keychain.util.ParcelableFileCache.IteratorWithSize;
|
||||
import org.sufficientlysecure.keychain.util.Preferences;
|
||||
import org.sufficientlysecure.keychain.util.orbot.OrbotHelper;
|
||||
import org.sufficientlysecure.keychain.util.tor.OrbotHelper;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
|
@ -49,7 +49,7 @@ import org.sufficientlysecure.keychain.util.IntentIntegratorSupportV4;
|
||||
import org.sufficientlysecure.keychain.util.Log;
|
||||
import org.sufficientlysecure.keychain.util.ParcelableProxy;
|
||||
import org.sufficientlysecure.keychain.util.Preferences;
|
||||
import org.sufficientlysecure.keychain.util.orbot.OrbotHelper;
|
||||
import org.sufficientlysecure.keychain.util.tor.OrbotHelper;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Locale;
|
||||
|
@ -81,7 +81,7 @@ import org.sufficientlysecure.keychain.util.FabContainer;
|
||||
import org.sufficientlysecure.keychain.util.Log;
|
||||
import org.sufficientlysecure.keychain.util.ParcelableProxy;
|
||||
import org.sufficientlysecure.keychain.util.Preferences;
|
||||
import org.sufficientlysecure.keychain.util.orbot.OrbotHelper;
|
||||
import org.sufficientlysecure.keychain.util.tor.OrbotHelper;
|
||||
import se.emilsjolander.stickylistheaders.StickyListHeadersAdapter;
|
||||
import se.emilsjolander.stickylistheaders.StickyListHeadersListView;
|
||||
|
||||
|
@ -43,7 +43,7 @@ import org.sufficientlysecure.keychain.ui.util.Notify;
|
||||
import org.sufficientlysecure.keychain.ui.widget.IntegerListPreference;
|
||||
import org.sufficientlysecure.keychain.util.Log;
|
||||
import org.sufficientlysecure.keychain.util.Preferences;
|
||||
import org.sufficientlysecure.keychain.util.orbot.OrbotHelper;
|
||||
import org.sufficientlysecure.keychain.util.tor.OrbotHelper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
@ -41,7 +41,7 @@ import org.sufficientlysecure.keychain.service.ServiceProgressHandler;
|
||||
import org.sufficientlysecure.keychain.util.Log;
|
||||
import org.sufficientlysecure.keychain.util.ParcelableProxy;
|
||||
import org.sufficientlysecure.keychain.util.Preferences;
|
||||
import org.sufficientlysecure.keychain.util.orbot.OrbotHelper;
|
||||
import org.sufficientlysecure.keychain.util.tor.OrbotHelper;
|
||||
|
||||
/**
|
||||
* Sends the selected public key to a keyserver
|
||||
|
@ -84,7 +84,7 @@ import org.sufficientlysecure.keychain.util.Log;
|
||||
import org.sufficientlysecure.keychain.util.NfcHelper;
|
||||
import org.sufficientlysecure.keychain.util.ParcelableProxy;
|
||||
import org.sufficientlysecure.keychain.util.Preferences;
|
||||
import org.sufficientlysecure.keychain.util.orbot.OrbotHelper;
|
||||
import org.sufficientlysecure.keychain.util.tor.OrbotHelper;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
|
@ -55,7 +55,7 @@ import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils;
|
||||
import org.sufficientlysecure.keychain.util.Log;
|
||||
import org.sufficientlysecure.keychain.util.ParcelableProxy;
|
||||
import org.sufficientlysecure.keychain.util.Preferences;
|
||||
import org.sufficientlysecure.keychain.util.orbot.OrbotHelper;
|
||||
import org.sufficientlysecure.keychain.util.tor.OrbotHelper;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Hashtable;
|
||||
|
@ -49,7 +49,7 @@ import org.sufficientlysecure.keychain.keyimport.HkpKeyserver;
|
||||
import org.sufficientlysecure.keychain.util.Log;
|
||||
import org.sufficientlysecure.keychain.util.Preferences;
|
||||
import org.sufficientlysecure.keychain.util.TlsHelper;
|
||||
import org.sufficientlysecure.keychain.util.orbot.OrbotHelper;
|
||||
import org.sufficientlysecure.keychain.util.tor.OrbotHelper;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.MalformedURLException;
|
||||
|
@ -29,7 +29,7 @@ import android.support.v4.app.DialogFragment;
|
||||
import org.sufficientlysecure.keychain.Constants;
|
||||
import org.sufficientlysecure.keychain.R;
|
||||
import org.sufficientlysecure.keychain.util.Log;
|
||||
import org.sufficientlysecure.keychain.util.orbot.OrbotHelper;
|
||||
import org.sufficientlysecure.keychain.util.tor.OrbotHelper;
|
||||
|
||||
/**
|
||||
* displays a dialog asking the user to enable Tor
|
||||
|
@ -47,12 +47,9 @@
|
||||
*****
|
||||
*/
|
||||
|
||||
package org.sufficientlysecure.keychain.util.orbot;
|
||||
package org.sufficientlysecure.keychain.util.tor;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.Handler;
|
||||
@ -60,7 +57,7 @@ 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;
|
||||
@ -89,7 +86,8 @@ public class OrbotHelper {
|
||||
|
||||
private static boolean isAppInstalled(String uri, Context context) {
|
||||
PackageManager pm = context.getPackageManager();
|
||||
boolean installed = false;
|
||||
|
||||
boolean installed;
|
||||
try {
|
||||
pm.getPackageInfo(uri, PackageManager.GET_ACTIVITIES);
|
||||
installed = true;
|
@ -47,9 +47,10 @@
|
||||
*****
|
||||
*/
|
||||
|
||||
package org.sufficientlysecure.keychain.util.orbot;
|
||||
package org.sufficientlysecure.keychain.util.tor;
|
||||
|
||||
import android.util.Log;
|
||||
import org.sufficientlysecure.keychain.Constants;
|
||||
import org.sufficientlysecure.keychain.util.Log;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
@ -60,10 +61,7 @@ import java.util.StringTokenizer;
|
||||
/**
|
||||
* This class is taken from the NetCipher library: https://github.com/guardianproject/NetCipher/
|
||||
*/
|
||||
|
||||
public class TorServiceUtils {
|
||||
|
||||
private final static String TAG = "TorUtils";
|
||||
// various console cmds
|
||||
public final static String SHELL_CMD_PS = "ps";
|
||||
public final static String SHELL_CMD_PIDOF = "pidof";
|
||||
@ -74,13 +72,14 @@ public class TorServiceUtils {
|
||||
try {
|
||||
procId = findProcessIdWithPidOf(command);
|
||||
|
||||
if (procId == -1)
|
||||
if (procId == -1) {
|
||||
procId = findProcessIdWithPS(command);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
try {
|
||||
procId = findProcessIdWithPS(command);
|
||||
} catch (Exception e2) {
|
||||
Log.e(TAG, "Unable to get proc id for command: " + URLEncoder.encode(command), e2);
|
||||
Log.e(Constants.TAG, "Unable to get proc id for command: " + URLEncoder.encode(command), e2);
|
||||
}
|
||||
}
|
||||
|
||||
@ -91,10 +90,8 @@ public class TorServiceUtils {
|
||||
public static int findProcessIdWithPidOf(String command) throws Exception {
|
||||
|
||||
int procId = -1;
|
||||
|
||||
Runtime r = Runtime.getRuntime();
|
||||
|
||||
Process procPs = null;
|
||||
Process procPs;
|
||||
|
||||
String baseName = new File(command).getName();
|
||||
// fix contributed my mikos on 2010.12.10
|
||||
@ -104,7 +101,7 @@ public class TorServiceUtils {
|
||||
// procPs = r.exec(SHELL_CMD_PIDOF);
|
||||
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(procPs.getInputStream()));
|
||||
String line = null;
|
||||
String line;
|
||||
|
||||
while ((line = reader.readLine()) != null) {
|
||||
|
||||
@ -118,25 +115,20 @@ public class TorServiceUtils {
|
||||
}
|
||||
|
||||
return procId;
|
||||
|
||||
}
|
||||
|
||||
// use 'ps' command
|
||||
public static int findProcessIdWithPS(String command) throws Exception {
|
||||
|
||||
int procId = -1;
|
||||
|
||||
Runtime r = Runtime.getRuntime();
|
||||
|
||||
Process procPs = null;
|
||||
Process procPs;
|
||||
|
||||
procPs = r.exec(SHELL_CMD_PS);
|
||||
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(procPs.getInputStream()));
|
||||
String line = null;
|
||||
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
if (line.indexOf(' ' + command) != -1) {
|
||||
if (line.contains(' ' + command)) {
|
||||
|
||||
StringTokenizer st = new StringTokenizer(line, " ");
|
||||
st.nextToken(); // proc owner
|
||||
@ -148,6 +140,5 @@ public class TorServiceUtils {
|
||||
}
|
||||
|
||||
return procId;
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user