ensuring code style is preserved

This commit is contained in:
Adithya Abraham Philip
2015-06-16 14:36:18 +05:30
parent f6d0f88ac9
commit 2402c6d3c7
23 changed files with 112 additions and 146 deletions

View File

@@ -54,7 +54,7 @@ public class ParcelableProxy implements Parcelable {
}
public Proxy getProxy() {
if(mProxyHost == null) return null;
if (mProxyHost == null) return null;
Proxy.Type type = null;
switch (mProxyType) {

View File

@@ -296,8 +296,7 @@ public class Preferences {
if (useTor) {
return new ProxyPrefs(true, false, Constants.Orbot.PROXY_HOST, Constants.Orbot.PROXY_PORT,
Constants.Orbot.PROXY_TYPE);
}
else if (useNormalProxy) {
} else if (useNormalProxy) {
return new ProxyPrefs(useTor, useNormalProxy, getProxyHost(), getProxyPort(), getProxyType());
} else {
return new ProxyPrefs(false, false, null, -1, null);
@@ -318,7 +317,7 @@ public class Preferences {
public ProxyPrefs(boolean torEnabled, boolean normalPorxyEnabled, String hostName, int port, Proxy.Type type) {
this.torEnabled = torEnabled;
this.normalPorxyEnabled = normalPorxyEnabled;
if(!torEnabled && !normalPorxyEnabled) this.parcelableProxy = new ParcelableProxy(null, -1, null);
if (!torEnabled && !normalPorxyEnabled) this.parcelableProxy = new ParcelableProxy(null, -1, null);
else this.parcelableProxy = new ParcelableProxy(hostName, port, type);
}
}

View File

@@ -27,7 +27,6 @@ import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
import java.security.KeyManagementException;
import java.security.KeyStore;
import java.security.KeyStoreException;
@@ -62,7 +61,7 @@ public class TlsHelper {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
int reads = is.read();
while(reads != -1){
while (reads != -1) {
baos.write(reads);
reads = is.read();
}
@@ -75,17 +74,6 @@ public class TlsHelper {
}
}
public static URLConnection opeanConnection(URL url) throws IOException, TlsHelperException {
if (url.getProtocol().equals("https")) {
for (String domain : sStaticCA.keySet()) {
if (url.getHost().endsWith(domain)) {
return openCAConnection(sStaticCA.get(domain), url);
}
}
}
return url.openConnection();
}
public static void pinCertificateIfNecessary(OkHttpClient client, URL url) throws TlsHelperException, IOException {
if (url.getProtocol().equals("https")) {
for (String domain : sStaticCA.keySet()) {
@@ -103,7 +91,7 @@ public class TlsHelper {
* TODO: Refactor - More like SSH StrictHostKeyChecking than pinning?
*
* @param certificate certificate to pin
* @param client OkHttpClient to enforce pinning on
* @param client OkHttpClient to enforce pinning on
* @throws TlsHelperException
* @throws IOException
*/

View File

@@ -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)

View File

@@ -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