From 2402c6d3c72b19b8eded017ff3fbeb83c30ae0a8 Mon Sep 17 00:00:00 2001 From: Adithya Abraham Philip Date: Tue, 16 Jun 2015 14:36:18 +0530 Subject: ensuring code style is preserved --- .../keychain/keyimport/CloudSearch.java | 2 +- .../keychain/keyimport/HkpKeyserver.java | 31 +++++++--------- .../keychain/keyimport/Keyserver.java | 1 + .../keychain/operations/CertifyOperation.java | 22 ++++++------ .../operations/results/OperationResult.java | 2 +- .../keychain/provider/ProviderHelper.java | 10 +++--- .../keychain/service/CertifyActionsParcel.java | 6 +--- .../keychain/ui/CreateYubiKeyImportFragment.java | 2 +- .../keychain/ui/ImportKeysActivity.java | 4 +-- .../keychain/ui/KeyListFragment.java | 18 +++++----- .../keychain/ui/SettingsActivity.java | 12 +++---- .../keychain/ui/ViewKeyActivity.java | 23 +++++++----- .../keychain/ui/ViewKeyTrustFragment.java | 4 +-- .../ui/adapter/ImportKeysListCloudLoader.java | 1 - .../ui/dialog/AddEditKeyserverDialogFragment.java | 3 +- .../keychain/ui/dialog/InstallDialogFragment.java | 11 +++--- .../ui/dialog/OrbotStartDialogFragment.java | 1 + .../ui/dialog/PreferenceInstallDialogFragment.java | 14 ++++---- .../keychain/util/ParcelableProxy.java | 2 +- .../keychain/util/Preferences.java | 5 ++- .../keychain/util/TlsHelper.java | 16 ++------- .../keychain/util/orbot/OrbotHelper.java | 26 ++++++-------- .../keychain/util/orbot/TorServiceUtils.java | 42 ++++++++-------------- 23 files changed, 112 insertions(+), 146 deletions(-) (limited to 'OpenKeychain/src/main/java/org') diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/keyimport/CloudSearch.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/keyimport/CloudSearch.java index c089db17f..d91dd28bc 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/keyimport/CloudSearch.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/keyimport/CloudSearch.java @@ -70,7 +70,7 @@ public class CloudSearch { try { if (proxy != null) { results.wait(30 * SECONDS); - } else{ + } else { results.wait(10 * SECONDS); } for (Thread thread : searchThreads) { diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/keyimport/HkpKeyserver.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/keyimport/HkpKeyserver.java index 26f4da4e5..33565803b 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/keyimport/HkpKeyserver.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/keyimport/HkpKeyserver.java @@ -18,20 +18,23 @@ package org.sufficientlysecure.keychain.keyimport; -import com.squareup.okhttp.*; -import okio.BufferedSink; +import com.squareup.okhttp.MediaType; +import com.squareup.okhttp.OkHttpClient; +import com.squareup.okhttp.Request; +import com.squareup.okhttp.RequestBody; +import com.squareup.okhttp.Response; import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.pgp.PgpHelper; import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils; import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.TlsHelper; -import java.io.BufferedWriter; import java.io.IOException; -import java.io.OutputStream; -import java.io.OutputStreamWriter; import java.io.UnsupportedEncodingException; -import java.net.*; +import java.net.Proxy; +import java.net.URL; +import java.net.URLDecoder; +import java.net.URLEncoder; import java.util.ArrayList; import java.util.Arrays; import java.util.Comparator; @@ -197,7 +200,7 @@ public class HkpKeyserver extends Keyserver { * @param proxy * @return */ - public static OkHttpClient getClient(URL url, Proxy proxy) throws IOException { + public static OkHttpClient getClient(URL url, Proxy proxy) throws IOException { OkHttpClient client = new OkHttpClient(); try { @@ -207,7 +210,6 @@ public class HkpKeyserver extends Keyserver { } client.setProxy(proxy); - // TODO: PHILIP if proxy !=null increase timeout? client.setConnectTimeout(proxy != null ? 30000 : 5000, TimeUnit.MILLISECONDS); client.setReadTimeout(45000, TimeUnit.MILLISECONDS); @@ -222,8 +224,6 @@ public class HkpKeyserver extends Keyserver { OkHttpClient client = getClient(url, proxy); Response response = client.newCall(new Request.Builder().url(url).build()).execute(); - tempIpTest(proxy); - String responseBody = response.body().string();// contains body both in case of success or failure if (response.isSuccessful()) { @@ -237,12 +237,6 @@ public class HkpKeyserver extends Keyserver { } } - private void tempIpTest(Proxy proxy) throws IOException { - URL url = new URL("https://wtfismyip.com/text"); - Response response = getClient(url, proxy).newCall(new Request.Builder().url(url).build()).execute(); - Log.e("PHILIP", "proxy Test: " + response.body().string()); - } - /** * Results are sorted by creation date of key! * @@ -388,8 +382,6 @@ public class HkpKeyserver extends Keyserver { RequestBody body = RequestBody.create(MediaType.parse("application/x-www-form-urlencoded"), params); - Log.e("PHILIP", "Media Type charset: "+body.contentType().charset()); - Request request = new Request.Builder() .url(url) .addHeader("Content-Type", "application/x-www-form-urlencoded") @@ -397,10 +389,11 @@ public class HkpKeyserver extends Keyserver { .post(body) .build(); - Response response = new OkHttpClient().setProxy(proxy).newCall(request).execute(); + Response response = getClient(url, proxy).newCall(request).execute(); Log.d(Constants.TAG, "response code: " + response.code()); Log.d(Constants.TAG, "answer: " + response.body().string()); + } catch (IOException e) { Log.e(Constants.TAG, "IOException", e); throw new AddKeyException(); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/keyimport/Keyserver.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/keyimport/Keyserver.java index 260e2af40..640b39f44 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/keyimport/Keyserver.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/keyimport/Keyserver.java @@ -32,6 +32,7 @@ public abstract class Keyserver { public CloudSearchFailureException(String message) { super(message); } + public CloudSearchFailureException() { super(); } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/CertifyOperation.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/CertifyOperation.java index 9092a7354..07aeeaff6 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/CertifyOperation.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/CertifyOperation.java @@ -19,12 +19,9 @@ package org.sufficientlysecure.keychain.operations; import android.content.Context; -import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.keyimport.HkpKeyserver; -import org.sufficientlysecure.keychain.keyimport.Keyserver.AddKeyException; import org.sufficientlysecure.keychain.operations.results.CertifyResult; import org.sufficientlysecure.keychain.operations.results.ExportResult; -import org.sufficientlysecure.keychain.operations.results.OperationResult; import org.sufficientlysecure.keychain.operations.results.OperationResult.LogType; import org.sufficientlysecure.keychain.operations.results.OperationResult.OperationLog; import org.sufficientlysecure.keychain.operations.results.SaveKeyringResult; @@ -45,26 +42,25 @@ import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; import org.sufficientlysecure.keychain.service.input.RequiredInputParcel; import org.sufficientlysecure.keychain.service.input.RequiredInputParcel.NfcSignOperationsBuilder; import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils; -import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.ParcelableProxy; import org.sufficientlysecure.keychain.util.Passphrase; -import java.net.Proxy; import java.util.ArrayList; import java.util.concurrent.atomic.AtomicBoolean; -/** An operation which implements a high level user id certification operation. - * +/** + * An operation which implements a high level user id certification operation. + *

* This operation takes a specific CertifyActionsParcel as its input. These * contain a masterKeyId to be used for certification, and a list of * masterKeyIds and related user ids to certify. * * @see CertifyActionsParcel - * */ public class CertifyOperation extends BaseOperation { - public CertifyOperation(Context context, ProviderHelper providerHelper, Progressable progressable, AtomicBoolean cancelled) { + public CertifyOperation(Context context, ProviderHelper providerHelper, Progressable progressable, AtomicBoolean + cancelled) { super(context, providerHelper, progressable, cancelled); } @@ -178,7 +174,7 @@ public class CertifyOperation extends BaseOperation { } - if ( ! allRequiredInput.isEmpty()) { + if (!allRequiredInput.isEmpty()) { log.add(LogType.MSG_CRT_NFC_RETURN, 1); return new CertifyResult(log, allRequiredInput.build()); } @@ -204,7 +200,8 @@ public class CertifyOperation extends BaseOperation { // Check if we were cancelled if (checkCancelled()) { log.add(LogType.MSG_OPERATION_CANCELLED, 0); - return new CertifyResult(CertifyResult.RESULT_CANCELLED, log, certifyOk, certifyError, uploadOk, uploadError); + return new CertifyResult(CertifyResult.RESULT_CANCELLED, log, certifyOk, certifyError, uploadOk, + uploadError); } log.add(LogType.MSG_CRT_SAVE, 2, @@ -245,7 +242,8 @@ public class CertifyOperation extends BaseOperation { log.add(LogType.MSG_CRT_SUCCESS, 0); if (uploadError != 0) { - return new CertifyResult(CertifyResult.RESULT_WARNINGS, log, certifyOk, certifyError, uploadOk, uploadError); + return new CertifyResult(CertifyResult.RESULT_WARNINGS, log, certifyOk, certifyError, uploadOk, + uploadError); } else { return new CertifyResult(CertifyResult.RESULT_OK, log, certifyOk, certifyError, uploadOk, uploadError); } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/results/OperationResult.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/results/OperationResult.java index 2dd493c81..1ae5aaefb 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/results/OperationResult.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/results/OperationResult.java @@ -713,7 +713,7 @@ public abstract class OperationResult implements Parcelable { MSG_IMPORT_SUCCESS (LogLevel.OK, R.string.msg_import_success), MSG_EXPORT (LogLevel.START, R.plurals.msg_export), - MSG_EXPORT_UPLOAD_PUBLIC(LogLevel.START, R.string.msg_export_upload_public), + MSG_EXPORT_UPLOAD_PUBLIC (LogLevel.START, R.string.msg_export_upload_public), MSG_EXPORT_PUBLIC (LogLevel.DEBUG, R.string.msg_export_public), MSG_EXPORT_SECRET (LogLevel.DEBUG, R.string.msg_export_secret), MSG_EXPORT_ALL (LogLevel.START, R.string.msg_export_all), diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/ProviderHelper.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/ProviderHelper.java index 590c58f97..353c3fcca 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/ProviderHelper.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/ProviderHelper.java @@ -906,7 +906,8 @@ public class ProviderHelper { // If there is a secret key, merge new data (if any) and save the key for later CanonicalizedSecretKeyRing canSecretRing; try { - UncachedKeyRing secretRing = getCanonicalizedSecretKeyRing(publicRing.getMasterKeyId()).getUncachedKeyRing(); + UncachedKeyRing secretRing = getCanonicalizedSecretKeyRing(publicRing.getMasterKeyId()) + .getUncachedKeyRing(); // Merge data from new public ring into secret one log(LogType.MSG_IP_MERGE_SECRET); @@ -1031,7 +1032,8 @@ public class ProviderHelper { publicRing = secretRing.extractPublicKeyRing(); } - CanonicalizedPublicKeyRing canPublicRing = (CanonicalizedPublicKeyRing) publicRing.canonicalize(mLog, mIndent); + CanonicalizedPublicKeyRing canPublicRing = (CanonicalizedPublicKeyRing) publicRing.canonicalize(mLog, + mIndent); if (canPublicRing == null) { return new SaveKeyringResult(SaveKeyringResult.RESULT_ERROR, mLog, null); } @@ -1082,7 +1084,7 @@ public class ProviderHelper { indent += 1; final Cursor cursor = mContentResolver.query(KeyRingData.buildSecretKeyRingUri(), - new String[]{ KeyRingData.KEY_RING_DATA }, null, null, null); + new String[]{KeyRingData.KEY_RING_DATA}, null, null, null); if (cursor == null) { log.add(LogType.MSG_CON_ERROR_DB, indent); @@ -1143,7 +1145,7 @@ public class ProviderHelper { final Cursor cursor = mContentResolver.query( KeyRingData.buildPublicKeyRingUri(), - new String[]{ KeyRingData.KEY_RING_DATA }, null, null, null); + new String[]{KeyRingData.KEY_RING_DATA}, null, null, null); if (cursor == null) { log.add(LogType.MSG_CON_ERROR_DB, indent); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/CertifyActionsParcel.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/CertifyActionsParcel.java index 05d5546f6..d32d75279 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/CertifyActionsParcel.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/CertifyActionsParcel.java @@ -22,13 +22,9 @@ import android.os.Parcel; import android.os.Parcelable; import java.io.Serializable; -import java.nio.ByteBuffer; import java.util.ArrayList; -import java.util.Date; -import java.util.Map; import org.sufficientlysecure.keychain.pgp.WrappedUserAttribute; -import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; import org.sufficientlysecure.keychain.util.ParcelableProxy; @@ -100,7 +96,7 @@ public class CertifyActionsParcel implements Parcelable { } public CertifyAction(long masterKeyId, ArrayList userIds, - ArrayList attributes) { + ArrayList attributes) { mMasterKeyId = masterKeyId; mUserIds = userIds; mUserAttributes = attributes; diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateYubiKeyImportFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateYubiKeyImportFragment.java index 4d85255ca..39dea6f0d 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateYubiKeyImportFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateYubiKeyImportFragment.java @@ -131,7 +131,7 @@ public class CreateYubiKeyImportFragment } }; - if(OrbotHelper.isOrbotInRequiredState(R.string.orbot_ignore_tor, ignoreTor, proxyPrefs, + if (OrbotHelper.isOrbotInRequiredState(R.string.orbot_ignore_tor, ignoreTor, proxyPrefs, getActivity())) { importKey(proxyPrefs.parcelableProxy); } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysActivity.java index b61e94c6d..e2b90056d 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysActivity.java @@ -46,7 +46,6 @@ import org.sufficientlysecure.keychain.util.Preferences; import org.sufficientlysecure.keychain.util.orbot.OrbotHelper; import java.io.IOException; -import java.net.Proxy; import java.util.ArrayList; public class ImportKeysActivity extends BaseNfcActivity @@ -322,7 +321,8 @@ public class ImportKeysActivity extends BaseNfcActivity * specified in user preferences */ - private void startCloudFragment(Bundle savedInstanceState, String query, boolean disableQueryEdit, String keyserver) { + private void startCloudFragment(Bundle savedInstanceState, String query, boolean disableQueryEdit, String + keyserver) { // However, if we're being restored from a previous state, // then we don't need to do anything and should return or else // we could end up with overlapping fragments. diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java index 76ae147a2..da181711e 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java @@ -51,6 +51,8 @@ import android.widget.TextView; import com.getbase.floatingactionbutton.FloatingActionButton; import com.getbase.floatingactionbutton.FloatingActionsMenu; +import se.emilsjolander.stickylistheaders.StickyListHeadersAdapter; +import se.emilsjolander.stickylistheaders.StickyListHeadersListView; import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; @@ -81,10 +83,8 @@ import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; -import org.sufficientlysecure.keychain.util.orbot.OrbotHelper; -import se.emilsjolander.stickylistheaders.StickyListHeadersAdapter; -import se.emilsjolander.stickylistheaders.StickyListHeadersListView; - +/** + * Public key list with sticky list headers. It does _not_ exte /** * Public key list with sticky list headers. It does _not_ extend ListFragment because it uses * StickyListHeaders library which does not extend upon ListView. @@ -472,15 +472,13 @@ public class KeyListFragment extends LoaderFragment return true; case R.id.menu_key_list_export: - mExportHelper.showExportKeysDialog(null, Constants.Path.APP_DIR_FILE, true); + ); return true; - case R.id.menu_key_list_update_all_keys: - updateAllKeys(); - return true; + case R.id.menu_key_list_debug +_cons return true; - case R.id.menu_key_list_debug_cons: - consolidate(); + consolidate(case R.id.menu_key_list_debug_cons:); return true; case R.id.menu_key_list_debug_read: diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/SettingsActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/SettingsActivity.java index 6605995eb..1b8d71d23 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/SettingsActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/SettingsActivity.java @@ -245,7 +245,7 @@ public class SettingsActivity extends AppCompatPreferenceActivity { } public Preference automaticallyFindPreference(String key) { - if(mFragment != null) { + if (mFragment != null) { return mFragment.findPreference(key); } else { return mActivity.findPreference(key); @@ -259,8 +259,7 @@ public class SettingsActivity extends AppCompatPreferenceActivity { Preferences.setPreferenceManagerFileAndMode(mFragment.getPreferenceManager()); // Load the preferences from an XML resource mFragment.addPreferencesFromResource(R.xml.proxy_prefs); - } - else { + } else { Preferences.setPreferenceManagerFileAndMode(mActivity.getPreferenceManager()); // Load the preferences from an XML resource mActivity.addPreferencesFromResource(R.xml.proxy_prefs); @@ -285,7 +284,7 @@ public class SettingsActivity extends AppCompatPreferenceActivity { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { Activity activity = mFragment != null ? mFragment.getActivity() : mActivity; - if ((Boolean)newValue) { + if ((Boolean) newValue) { boolean installed = OrbotHelper.isOrbotInstalled(activity); if (!installed) { Log.d(Constants.TAG, "Prompting to install Tor"); @@ -298,8 +297,7 @@ public class SettingsActivity extends AppCompatPreferenceActivity { // let the enable tor box be checked return true; } - } - else { + } else { // we're unchecking Tor, so enable other proxy enableNormalProxyPrefs(); return true; @@ -350,7 +348,7 @@ public class SettingsActivity extends AppCompatPreferenceActivity { Activity activity = mFragment != null ? mFragment.getActivity() : mActivity; try { int port = Integer.parseInt((String) newValue); - if(port < 0 || port > 65535) { + if (port < 0 || port > 65535) { Notify.create( activity, R.string.pref_proxy_port_err_invalid, diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyActivity.java index da00748e4..ce8935bce 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyActivity.java @@ -53,7 +53,6 @@ import android.widget.RelativeLayout; import android.widget.TextView; import android.widget.Toast; import com.getbase.floatingactionbutton.FloatingActionButton; -import edu.cmu.cylab.starslinger.exchange.ExchangeActivity; import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.keyimport.ParcelableKeyRing; @@ -81,6 +80,13 @@ import org.sufficientlysecure.keychain.ui.util.Notify; import org.sufficientlysecure.keychain.ui.util.Notify.ActionListener; import org.sufficientlysecure.keychain.ui.util.Notify.Style; import org.sufficientlysecure.keychain.ui.util.QrCodeUtils; +import org.sufficientlysecure.keychain.util.ContactHelper; +import org.sufficientlysecure.keychain.util.ExportHelper; +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 java.io.IOException; import java.util.ArrayList; @@ -460,11 +466,11 @@ public class ViewKeyActivity extends BaseNfcActivity implements HashMap data = providerHelper.getGenericData( baseUri, - new String[] {KeychainContract.Keys.MASTER_KEY_ID, KeychainContract.KeyRings.HAS_SECRET}, - new int[] {ProviderHelper.FIELD_TYPE_INTEGER, ProviderHelper.FIELD_TYPE_INTEGER}); + new String[]{KeychainContract.Keys.MASTER_KEY_ID, KeychainContract.KeyRings.HAS_SECRET}, + new int[]{ProviderHelper.FIELD_TYPE_INTEGER, ProviderHelper.FIELD_TYPE_INTEGER}); exportHelper.showExportKeysDialog( - new long[] {(Long) data.get(KeychainContract.KeyRings.MASTER_KEY_ID)}, + new long[]{(Long) data.get(KeychainContract.KeyRings.MASTER_KEY_ID)}, Constants.Path.APP_DIR_FILE, ((Long) data.get(KeychainContract.KeyRings.HAS_SECRET) != 0) ); } catch (ProviderHelper.NotFoundException e) { @@ -488,7 +494,7 @@ public class ViewKeyActivity extends BaseNfcActivity implements // Create a new Messenger for the communication back Messenger messenger = new Messenger(returnHandler); DeleteKeyDialogFragment deleteKeyDialog = DeleteKeyDialogFragment.newInstance(messenger, - new long[] {mMasterKeyId}); + new long[]{mMasterKeyId}); deleteKeyDialog.show(getSupportFragmentManager(), "deleteKeyDialog"); } @@ -632,7 +638,7 @@ public class ViewKeyActivity extends BaseNfcActivity implements long keyId = new ProviderHelper(this) .getCachedPublicKeyRing(dataUri) .extractOrGetMasterKeyId(); - long[] encryptionKeyIds = new long[] {keyId}; + long[] encryptionKeyIds = new long[]{keyId}; Intent intent; if (text) { intent = new Intent(this, EncryptTextActivity.class); @@ -738,7 +744,7 @@ public class ViewKeyActivity extends BaseNfcActivity implements // These are the rows that we will retrieve. - static final String[] PROJECTION = new String[] { + static final String[] PROJECTION = new String[]{ KeychainContract.KeyRings._ID, KeychainContract.KeyRings.MASTER_KEY_ID, KeychainContract.KeyRings.USER_ID, @@ -826,7 +832,8 @@ public class ViewKeyActivity extends BaseNfcActivity implements AsyncTask photoTask = new AsyncTask() { protected Bitmap doInBackground(Long... mMasterKeyId) { - return ContactHelper.loadPhotoByMasterKeyId(getContentResolver(), mMasterKeyId[0], true); + return ContactHelper.loadPhotoByMasterKeyId(getContentResolver(), + mMasterKeyId[0], true); } protected void onPostExecute(Bitmap photo) { diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyTrustFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyTrustFragment.java index 32e8b4fc1..f6b580b01 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyTrustFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyTrustFragment.java @@ -55,7 +55,6 @@ import org.sufficientlysecure.keychain.util.ParcelableProxy; import org.sufficientlysecure.keychain.util.Preferences; import org.sufficientlysecure.keychain.util.orbot.OrbotHelper; -import java.net.Proxy; import java.util.ArrayList; import java.util.Hashtable; import java.util.List; @@ -201,7 +200,8 @@ public class ViewKeyTrustFragment extends LoaderFragment implements mStartSearch.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { - final Preferences.ProxyPrefs proxyPrefs = Preferences.getPreferences(getActivity()).getProxyPrefs(); + final Preferences.ProxyPrefs proxyPrefs = Preferences.getPreferences(getActivity()) + .getProxyPrefs(); Runnable ignoreTor = new Runnable() { @Override diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysListCloudLoader.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysListCloudLoader.java index a4f8f22e0..c7f69207c 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysListCloudLoader.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysListCloudLoader.java @@ -30,7 +30,6 @@ import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.ParcelableProxy; import org.sufficientlysecure.keychain.util.Preferences; -import java.net.Proxy; import java.util.ArrayList; public class ImportKeysListCloudLoader diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/AddEditKeyserverDialogFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/AddEditKeyserverDialogFragment.java index 056d82fd3..e5ab3a228 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/AddEditKeyserverDialogFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/AddEditKeyserverDialogFragment.java @@ -59,14 +59,13 @@ import org.sufficientlysecure.keychain.util.TlsHelper; import java.io.IOException; import java.net.HttpURLConnection; import java.net.MalformedURLException; +import java.net.Proxy; import java.net.URI; import java.net.URISyntaxException; import java.net.URL; import javax.net.ssl.HttpsURLConnection; import java.io.IOException; -import java.net.*; -import javax.net.ssl.HttpsURLConnection; public class AddEditKeyserverDialogFragment extends DialogFragment implements OnEditorActionListener { private static final String ARG_MESSENGER = "arg_messenger"; diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/InstallDialogFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/InstallDialogFragment.java index 01ff4715d..7b3f9ad28 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/InstallDialogFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/InstallDialogFragment.java @@ -48,15 +48,16 @@ public class InstallDialogFragment extends DialogFragment { * Creates a dialog which prompts the user to install an application. Consists of two default buttons ("Install" * and "Cancel") and an optional third button. Callbacks are provided only for the middle button, if set. * - * @param messenger required only for callback from middle button if it has been set + * @param messenger required only for callback from middle button if it has been set * @param title - * @param message content of dialog + * @param message content of dialog * @param packageToInstall package name of application to install - * @param middleButton if not null, adds a third button to the app with a call back + * @param middleButton if not null, adds a third button to the app with a call back * @return The dialog to display */ public static InstallDialogFragment newInstance(Messenger messenger, int title, int message, - String packageToInstall, int middleButton, boolean useMiddleButton) { + String packageToInstall, int middleButton, boolean + useMiddleButton) { InstallDialogFragment frag = new InstallDialogFragment(); Bundle args = new Bundle(); args.putParcelable(ARG_MESSENGER, messenger); @@ -125,7 +126,7 @@ public class InstallDialogFragment extends DialogFragment { @Override public void onClick(DialogInterface dialog, int which) { Message msg = new Message(); - msg.what=MESSAGE_MIDDLE_CLICKED; + msg.what = MESSAGE_MIDDLE_CLICKED; try { messenger.send(msg); } catch (RemoteException e) { diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/OrbotStartDialogFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/OrbotStartDialogFragment.java index e9092b14a..4736eddca 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/OrbotStartDialogFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/OrbotStartDialogFragment.java @@ -25,6 +25,7 @@ import android.os.Message; import android.os.Messenger; import android.os.RemoteException; import android.support.v4.app.DialogFragment; + import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.util.Log; diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/PreferenceInstallDialogFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/PreferenceInstallDialogFragment.java index 8236ff9d7..b9b4da83a 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/PreferenceInstallDialogFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/PreferenceInstallDialogFragment.java @@ -27,6 +27,7 @@ import android.os.Message; import android.os.Messenger; import android.os.RemoteException; import android.app.DialogFragment; + import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.util.Log; @@ -47,15 +48,16 @@ public class PreferenceInstallDialogFragment extends DialogFragment { * Creates a dialog which prompts the user to install an application. Consists of two default buttons ("Install" * and "Cancel") and an optional third button. Callbacks are provided only for the middle button, if set. * - * @param messenger required only for callback from middle button if it has been set + * @param messenger required only for callback from middle button if it has been set * @param title - * @param message content of dialog + * @param message content of dialog * @param packageToInstall package name of application to install - * @param middleButton if not null, adds a third button to the app with a call back + * @param middleButton if not null, adds a third button to the app with a call back * @return The dialog to display */ public static PreferenceInstallDialogFragment newInstance(Messenger messenger, int title, int message, - String packageToInstall, int middleButton, boolean useMiddleButton) { + String packageToInstall, int middleButton, boolean + useMiddleButton) { PreferenceInstallDialogFragment frag = new PreferenceInstallDialogFragment(); Bundle args = new Bundle(); args.putParcelable(ARG_MESSENGER, messenger); @@ -80,7 +82,7 @@ public class PreferenceInstallDialogFragment extends DialogFragment { * @return */ public static PreferenceInstallDialogFragment newInstance(int title, int message, - String packageToInstall) { + String packageToInstall) { return newInstance(null, title, message, packageToInstall, -1, false); } @@ -125,7 +127,7 @@ public class PreferenceInstallDialogFragment extends DialogFragment { @Override public void onClick(DialogInterface dialog, int which) { Message msg = new Message(); - msg.what=MESSAGE_MIDDLE_CLICKED; + msg.what = MESSAGE_MIDDLE_CLICKED; try { messenger.send(msg); } catch (RemoteException e) { diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/ParcelableProxy.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/ParcelableProxy.java index 601547fa9..4898e7f1a 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/ParcelableProxy.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/ParcelableProxy.java @@ -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) { diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/Preferences.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/Preferences.java index f54eac867..c13c07503 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/Preferences.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/Preferences.java @@ -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); } } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/TlsHelper.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/TlsHelper.java index 58c250cab..d1d1ada2a 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/TlsHelper.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/TlsHelper.java @@ -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 */ 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 -- cgit v1.2.3