From b90e680ff91ae12e9ae31682b1ab118d6c49ab7e Mon Sep 17 00:00:00 2001 From: Bhargav Golla Date: Mon, 10 Mar 2014 14:59:15 -0400 Subject: [PATCH 01/35] Lint changes after testing --- .gitignore | 5 +++++ OpenPGP-Keychain/build.gradle | 2 ++ .../keychain/ui/dialog/ProgressDialogFragment.java | 1 - .../keychain/ui/widget/KeyEditor.java | 2 ++ .../src/main/res/layout/decrypt_activity.xml | 11 ++--------- .../src/main/res/layout/edit_key_user_id_item.xml | 3 ++- .../src/main/res/layout/key_server_editor.xml | 2 +- .../src/main/res/layout/key_server_preference.xml | 2 +- .../src/main/res/menu/key_list_secret.xml | 2 +- OpenPGP-Keychain/src/main/res/menu/key_view.xml | 2 +- OpenPGP-Keychain/src/main/res/values-de/strings.xml | 2 +- OpenPGP-Keychain/src/main/res/values/strings.xml | 6 +++--- 12 files changed, 21 insertions(+), 19 deletions(-) diff --git a/.gitignore b/.gitignore index c4f2c8ad0..74d516d1e 100644 --- a/.gitignore +++ b/.gitignore @@ -31,3 +31,8 @@ pom.xml.* #OS Specific [Tt]humbs.db + + +#Lint output +OpenPGP-Keychain/lint-report.html +OpenPGP-Keychain/lint-report_files/* \ No newline at end of file diff --git a/OpenPGP-Keychain/build.gradle b/OpenPGP-Keychain/build.gradle index 6338774eb..04ee46715 100644 --- a/OpenPGP-Keychain/build.gradle +++ b/OpenPGP-Keychain/build.gradle @@ -57,5 +57,7 @@ android { // Do not abort build if lint finds errors lintOptions { abortOnError false + htmlReport true + htmlOutput file("lint-report.html") } } diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/ProgressDialogFragment.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/ProgressDialogFragment.java index 6c62d14e0..d63d866fd 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/ProgressDialogFragment.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/ProgressDialogFragment.java @@ -120,7 +120,6 @@ public class ProgressDialogFragment extends DialogFragment { int messageId = getArguments().getInt(ARG_MESSAGE_ID); int style = getArguments().getInt(ARG_STYLE); boolean cancelable = getArguments().getBoolean(ARG_CANCELABLE); - dialog.setMessage(getString(messageId)); dialog.setProgressStyle(style); diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/KeyEditor.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/KeyEditor.java index 65461cb4f..9f25fac42 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/KeyEditor.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/KeyEditor.java @@ -30,6 +30,7 @@ import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.pgp.PgpKeyHelper; import org.sufficientlysecure.keychain.util.Choice; +import android.annotation.TargetApi; import android.app.DatePickerDialog; import android.app.Dialog; import android.content.Context; @@ -110,6 +111,7 @@ public class KeyEditor extends LinearLayout implements Editor, OnClickListener { setExpiryDate(null); mExpiryDateButton.setOnClickListener(new OnClickListener() { + @TargetApi(11) public void onClick(View v) { GregorianCalendar date = mExpiryDate; if (date == null) { diff --git a/OpenPGP-Keychain/src/main/res/layout/decrypt_activity.xml b/OpenPGP-Keychain/src/main/res/layout/decrypt_activity.xml index c56ba130e..a974f6ec0 100644 --- a/OpenPGP-Keychain/src/main/res/layout/decrypt_activity.xml +++ b/OpenPGP-Keychain/src/main/res/layout/decrypt_activity.xml @@ -5,16 +5,11 @@ android:layout_width="match_parent" android:layout_height="match_parent"> - - + android:fillViewport="true" + android:orientation="vertical"> - diff --git a/OpenPGP-Keychain/src/main/res/layout/edit_key_user_id_item.xml b/OpenPGP-Keychain/src/main/res/layout/edit_key_user_id_item.xml index 663949d8e..437e5ebaf 100644 --- a/OpenPGP-Keychain/src/main/res/layout/edit_key_user_id_item.xml +++ b/OpenPGP-Keychain/src/main/res/layout/edit_key_user_id_item.xml @@ -71,7 +71,8 @@ android:id="@+id/comment" android:layout_width="match_parent" android:layout_height="wrap_content" - android:layout_weight="1" /> + android:layout_weight="1" + android:inputType="text"/> diff --git a/OpenPGP-Keychain/src/main/res/layout/key_server_editor.xml b/OpenPGP-Keychain/src/main/res/layout/key_server_editor.xml index 058a43eaf..950978a0e 100644 --- a/OpenPGP-Keychain/src/main/res/layout/key_server_editor.xml +++ b/OpenPGP-Keychain/src/main/res/layout/key_server_editor.xml @@ -13,7 +13,7 @@ diff --git a/OpenPGP-Keychain/src/main/res/layout/key_server_preference.xml b/OpenPGP-Keychain/src/main/res/layout/key_server_preference.xml index 4a09e4240..eddbe3cbf 100644 --- a/OpenPGP-Keychain/src/main/res/layout/key_server_preference.xml +++ b/OpenPGP-Keychain/src/main/res/layout/key_server_preference.xml @@ -14,7 +14,7 @@ android:orientation="horizontal" > Für diese Benutzer-IDs wurden keine öffentlichen Schlüssel gefunden: Für diese Benutzer-IDs existieren mehrere öffentliche Schlüssel: Bitte die Liste der Empfänger überprüfen! - Signaturüberprüfung fehlgeschlagen! Haben Sie diese App von einer anderen Quelle installiert? Wenn Sie eine Attacke ausschliessen können, sollten Sie die Registrierung der App in OpenKeychain widerrufen und die App erneut registrieren. + Signaturüberprüfung fehlgeschlagen! Haben Sie diese App von einer anderen Quelle installiert? Wenn Sie eine Attacke ausschließen können, sollten Sie die Registrierung der App in OpenKeychain widerrufen und die App erneut registrieren. Über QR Code teilen Mit \'Weiter\' durch alle QR-Codes gehen und diese nacheinander scannen. diff --git a/OpenPGP-Keychain/src/main/res/values/strings.xml b/OpenPGP-Keychain/src/main/res/values/strings.xml index 3267115a2..5e2478bf5 100644 --- a/OpenPGP-Keychain/src/main/res/values/strings.xml +++ b/OpenPGP-Keychain/src/main/res/values/strings.xml @@ -310,8 +310,8 @@ - done. - cancel + Done. + Cancel saving… importing… exporting… @@ -326,7 +326,7 @@ exporting key… exporting keys… - + generating keys, this can take up to 3 minutes… generating key, this can take up to 3 minutes… generating keys, this can take up to 3 minutes… From b4022b9a24dca7914d1a008700373b773343dd47 Mon Sep 17 00:00:00 2001 From: Bhargav Golla Date: Mon, 10 Mar 2014 23:19:10 -0400 Subject: [PATCH 02/35] Removing unused string --- OpenPGP-Keychain/src/main/res/values/strings.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OpenPGP-Keychain/src/main/res/values/strings.xml b/OpenPGP-Keychain/src/main/res/values/strings.xml index 82dd05f1a..cd248c749 100644 --- a/OpenPGP-Keychain/src/main/res/values/strings.xml +++ b/OpenPGP-Keychain/src/main/res/values/strings.xml @@ -328,7 +328,7 @@ exporting key… exporting keys… - generating keys, this can take up to 3 minutes… + generating key, this can take up to 3 minutes… generating keys, this can take up to 3 minutes… From 15d94c51bb362898464baae0d99279b754ac9450 Mon Sep 17 00:00:00 2001 From: Bhargav Golla Date: Mon, 10 Mar 2014 23:20:30 -0400 Subject: [PATCH 03/35] Removing tab --- OpenPGP-Keychain/src/main/res/values/strings.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OpenPGP-Keychain/src/main/res/values/strings.xml b/OpenPGP-Keychain/src/main/res/values/strings.xml index cd248c749..07f402802 100644 --- a/OpenPGP-Keychain/src/main/res/values/strings.xml +++ b/OpenPGP-Keychain/src/main/res/values/strings.xml @@ -328,7 +328,7 @@ exporting key… exporting keys… - + generating key, this can take up to 3 minutes… generating keys, this can take up to 3 minutes… From e909b6bb9d582dd2fec767410d039a0cf3189635 Mon Sep 17 00:00:00 2001 From: uberspot Date: Wed, 12 Mar 2014 18:48:17 +0200 Subject: [PATCH 04/35] change colorizing of fingerprint to use SHA1 based on apg's commit 67ffc24526 --- .../keychain/helper/OtherHelper.java | 22 +++++++++ .../keychain/ui/ViewKeyMainFragment.java | 46 +++++++++++++++---- 2 files changed, 58 insertions(+), 10 deletions(-) diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/helper/OtherHelper.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/helper/OtherHelper.java index 34d90a17f..292b5bf3d 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/helper/OtherHelper.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/helper/OtherHelper.java @@ -17,6 +17,9 @@ package org.sufficientlysecure.keychain.helper; +import java.security.DigestException; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; import java.util.Iterator; import java.util.Set; @@ -58,4 +61,23 @@ public class OtherHelper { } } + /** + * Converts the given bytes to a unique RGB color using SHA1 algorithm + * @param bytes + * @return an integer array containing 3 numeric color representations (Red, Green, Black) + * @throws NoSuchAlgorithmException + * @throws DigestException + */ + public static int[] getRgbForData(byte[] bytes) throws NoSuchAlgorithmException, DigestException { + MessageDigest md = MessageDigest.getInstance("SHA1"); + + md.update(bytes); + byte[] digest = md.digest(); + + int[] result = {((int) digest[0] + 256) % 256, + ((int) digest[1] + 256) % 256, + ((int) digest[2] + 256) % 256}; + return result; + } + } diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyMainFragment.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyMainFragment.java index adb06a068..d223a259f 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyMainFragment.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyMainFragment.java @@ -29,6 +29,7 @@ import android.support.v4.content.Loader; import android.text.Spannable; import android.text.SpannableStringBuilder; import android.text.format.DateFormat; +import android.text.style.BackgroundColorSpan; import android.text.style.ForegroundColorSpan; import android.view.LayoutInflater; import android.view.View; @@ -40,6 +41,7 @@ import com.beardedhen.androidbootstrap.BootstrapButton; import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; +import org.sufficientlysecure.keychain.helper.OtherHelper; import org.sufficientlysecure.keychain.pgp.PgpKeyHelper; import org.sufficientlysecure.keychain.provider.KeychainContract; import org.sufficientlysecure.keychain.provider.ProviderHelper; @@ -47,6 +49,8 @@ import org.sufficientlysecure.keychain.ui.adapter.ViewKeyKeysAdapter; import org.sufficientlysecure.keychain.ui.adapter.ViewKeyUserIdsAdapter; import org.sufficientlysecure.keychain.util.Log; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; import java.util.Date; @@ -276,18 +280,40 @@ public class ViewKeyMainFragment extends Fragment implements private SpannableStringBuilder colorizeFingerprint(String fingerprint) { SpannableStringBuilder sb = new SpannableStringBuilder(fingerprint); - ForegroundColorSpan fcs = new ForegroundColorSpan(Color.BLACK); + try { + // for each 4 characters of the fingerprint + 1 space + for (int i = 0; i < fingerprint.length(); i += 5) { + int minFingLength = Math.min(i + 4, fingerprint.length()); + String fourChars = fingerprint.substring(i, minFingLength); - // for each 4 characters of the fingerprint + 1 space - for (int i = 0; i < fingerprint.length(); i += 5) { - int minFingLength = Math.min(i + 4, fingerprint.length()); - String fourChars = fingerprint.substring(i, minFingLength); + int raw = Integer.parseInt(fourChars, 16); + byte[] bytes = {(byte) ((raw >> 8) & 0xff - 128), (byte) (raw & 0xff - 128)}; + int[] color = OtherHelper.getRgbForData(bytes); - // Create a foreground color by converting the 4 fingerprint chars to an int hashcode - // and then converting that int to hex to use as a color - fcs = new ForegroundColorSpan( - Color.parseColor(String.format("#%06X", (0xFFFFFF & fourChars.hashCode())))); - sb.setSpan(fcs, i, minFingLength, Spannable.SPAN_INCLUSIVE_INCLUSIVE); + // Convert rgb to brightness + int brightness = (int) (0.2126*color[0] + 0.7152*color[1] + 0.0722*color[2]); + + // Detect dark colors and invert their background to white to make them more distinguishable + if (brightness < 40) { + sb.setSpan(new BackgroundColorSpan(Color.WHITE), + i, minFingLength, Spannable.SPAN_INCLUSIVE_INCLUSIVE); + + // Detect bright colors and invert their background to black to make them more distinguishable + } else if (brightness > 210) { + sb.setSpan(new BackgroundColorSpan(Color.BLACK), + i, minFingLength, Spannable.SPAN_INCLUSIVE_INCLUSIVE); + } + + // Create a foreground color with the 3 digest integers as RGB + // and then converting that int to hex to use as a color + sb.setSpan(new ForegroundColorSpan(Color.rgb(color[0], color[1], color[2])), + i, minFingLength, Spannable.SPAN_INCLUSIVE_INCLUSIVE); + } + } catch (Exception e) { + Log.e(Constants.TAG, "Colorization failed", e); + // if anything goes wrong, then just display the fingerprint without colour, + // instead of partially correct colour or wrong colours + return new SpannableStringBuilder(fingerprint); } return sb; From 5848172621fecf5fe7213e85540e3952d9445d25 Mon Sep 17 00:00:00 2001 From: Emantor Date: Wed, 12 Mar 2014 18:47:24 +0100 Subject: [PATCH 05/35] Reduce library installation overhead --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 54db1a965..df700368c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,7 +3,7 @@ jdk: oraclejdk7 before_install: # Install base Android SDK - sudo apt-get update -qq - - if [ `uname -m` = x86_64 ]; then sudo apt-get install -qq --force-yes libgd2-xpm ia32-libs; fi + - if [ `uname -m` = x86_64 ]; then sudo apt-get install -qq --force-yes libgd2-xpm lib32z1 lib32stdc++6; fi - wget http://dl.google.com/android/android-sdk_r22.3-linux.tgz - tar xzf android-sdk_r22.3-linux.tgz - export ANDROID_HOME=$PWD/android-sdk-linux From 1df4d4a9e047f70f284183185d81070e49097ad3 Mon Sep 17 00:00:00 2001 From: Daniel Hammann Date: Wed, 12 Mar 2014 21:33:13 +0100 Subject: [PATCH 06/35] Added Windows section to CheckStyle configuration information part (and splitted Linux and MacOSX up). --- README.md | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 4b997c59f..8954bdcda 100644 --- a/README.md +++ b/README.md @@ -156,12 +156,21 @@ See http://source.android.com/source/code-style.html See http://www.androidpolice.com/2009/11/04/auto-formatting-android-xml-files-with-eclipse/ ### Automated syntax check with CheckStyle -* Paste the tools/checkstyle.xml file to ~/.AndroidStudioPreview/config/codestyles/ (in Linux/Unix) - or ~/Library/Preferences/AndroidStudioPreview/codestyles (in Mac OSX) -* Go to Settings (or Preferences in Mac OS X) > Code Style > Java, select OpenPgpChecker, - as well as Code Style > XML and select OpenPgpChecker again. -* Start code inspection and see the results by selecting Analyze > Inspect Code from Android-Studio - or you can directly run checkstyle via cli with .tools/checkstyle. Make sure it's executable first. + +####Linux +1. Paste the `tools/checkstyle.xml` file to `~/.AndroidStudioPreview/config/codestyles/` +2. Go to Settings > Code Style > Java, select OpenPgpChecker, as well as Code Style > XML and select OpenPgpChecker again. +3. Start code inspection and see the results by selecting Analyze > Inspect Code from Android-Studio or you can directly run checkstyle via cli with `.tools/checkstyle`. Make sure it's executable first. + +####Mac OSX +1. Paste the `tools/checkstyle.xml` file to `~/Library/Preferences/AndroidStudioPreview/codestyles` +2. Go to Preferences > Code Style > Java, select OpenPgpChecker, as well as Code Style > XML and select OpenPgpChecker again. +3. Start code inspection and see the results by selecting Analyze > Inspect Code from Android-Studio or you can directly run checkstyle via cli with `.tools/checkstyle`. Make sure it's executable first. + +####Windows +1. Paste the `tools/checkstyle.xml` file to `C:\Users\\.AndroidStudioPreview\config\codestyles` +2. Go to File > Settings > Code Style > Java, select OpenPgpChecker, as well as Code Style > XML and select OpenPgpChecker again. +3. Start code inspection and see the results by selecting Analyze > Inspect Code from Android-Studio. ## Licenses OpenPGP Kechain is licensed under GPLv3+. From 0b0809ec17203ea14068b064360e45e435796829 Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Thu, 13 Mar 2014 00:16:11 +0100 Subject: [PATCH 07/35] keychainprovider cleanup, kindasorta removed code redundancy, and the query is in the switch thing now, I didn't put everything into its own separate sources (yet?). --- .../keychain/provider/KeychainProvider.java | 112 ++++++++---------- .../keychain/ui/KeyListFragment.java | 7 +- 2 files changed, 55 insertions(+), 64 deletions(-) diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainProvider.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainProvider.java index 8b0efdbbd..3782f85fd 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainProvider.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainProvider.java @@ -467,70 +467,53 @@ public class KeychainProvider extends ContentProvider { int match = mUriMatcher.match(uri); - // screw that switch - if(match == UNIFIED_KEY_RING) { - - // join keyrings with keys and userIds - // Only get user id and key with rank 0 (main user id and main key) - qb.setTables(Tables.KEY_RINGS + " INNER JOIN " + Tables.KEYS + " ON " + "(" - + Tables.KEY_RINGS + "." + BaseColumns._ID + " = " + Tables.KEYS + "." - + KeysColumns.KEY_RING_ROW_ID + " AND " + Tables.KEYS + "." - + KeysColumns.RANK + " = '0') " + " INNER JOIN " + Tables.USER_IDS + " ON " - + "(" + Tables.KEY_RINGS + "." + BaseColumns._ID + " = " + Tables.USER_IDS + "." - + UserIdsColumns.KEY_RING_ROW_ID + " AND " + Tables.USER_IDS + "." - + UserIdsColumns.RANK + " = '0')"); - - { - HashMap projectionMap = new HashMap(); - - projectionMap.put(KeyRingsColumns.TYPE, "MAX(" + Tables.KEY_RINGS + "." + KeyRingsColumns.TYPE + ")"); - - projectionMap.put(BaseColumns._ID, Tables.KEY_RINGS + "." + BaseColumns._ID); - projectionMap.put(KeyRingsColumns.KEY_RING_DATA, Tables.KEY_RINGS + "." - + KeyRingsColumns.KEY_RING_DATA); - projectionMap.put(KeyRingsColumns.MASTER_KEY_ID, Tables.KEY_RINGS + "." + KeyRingsColumns.MASTER_KEY_ID); - // TODO: deprecated master key id - //projectionMap.put(KeyRingsColumns.MASTER_KEY_ID, Tables.KEYS + "." + KeysColumns.KEY_ID); - - projectionMap.put(KeysColumns.FINGERPRINT, Tables.KEYS + "." + KeysColumns.FINGERPRINT); - projectionMap.put(KeysColumns.IS_REVOKED, Tables.KEYS + "." + KeysColumns.IS_REVOKED); - - projectionMap.put(UserIdsColumns.USER_ID, Tables.USER_IDS + "." + UserIdsColumns.USER_ID); - - qb.setProjectionMap(projectionMap); - } - - if (TextUtils.isEmpty(sortOrder)) { - sortOrder = Tables.USER_IDS + "." + UserIdsColumns.USER_ID + " ASC"; - } - - // If no sort order is specified use the default - String orderBy; - if (TextUtils.isEmpty(sortOrder)) { - orderBy = Tables.KEY_RINGS + "." + KeyRingsColumns.TYPE + " DESC"; - } else { - orderBy = Tables.KEY_RINGS + "." + KeyRingsColumns.TYPE + " DESC, " + sortOrder; - } - - Cursor c = qb.query(db, projection, selection, selectionArgs, - Tables.KEY_RINGS + "." + KeyRingsColumns.MASTER_KEY_ID, - null, orderBy); - - // Tell the cursor what uri to watch, so it knows when its source data changes - c.setNotificationUri(getContext().getContentResolver(), uri); - - if (Constants.DEBUG) { - Log.d(Constants.TAG, - "Query: " - + qb.buildQuery(projection, selection, selectionArgs, Tables.KEY_RINGS + "." + KeyRingsColumns.MASTER_KEY_ID, null, - orderBy, null)); - Log.d(Constants.TAG, "Cursor: " + DatabaseUtils.dumpCursorToString(c)); - } - - return c; - } + // all query() parameters, for good measure + String groupBy = null, having = null; switch (match) { + case UNIFIED_KEY_RING: + + { // SELECT + // todo: outsource into getprojectionmapforthingies? don't really see the point. + HashMap projectionMap = new HashMap(); + + // from keyrings table + projectionMap.put(BaseColumns._ID, Tables.KEY_RINGS + "." + BaseColumns._ID); + projectionMap.put(KeyRingsColumns.TYPE, + "MAX(" + Tables.KEY_RINGS + "." + KeyRingsColumns.TYPE + ")"); + projectionMap.put(KeyRingsColumns.KEY_RING_DATA, Tables.KEY_RINGS + "." + + KeyRingsColumns.KEY_RING_DATA); + projectionMap.put(KeyRingsColumns.MASTER_KEY_ID, + Tables.KEY_RINGS + "." + KeyRingsColumns.MASTER_KEY_ID); + + // from keys table + projectionMap.put(KeysColumns.FINGERPRINT, Tables.KEYS + "." + KeysColumns.FINGERPRINT); + projectionMap.put(KeysColumns.IS_REVOKED, Tables.KEYS + "." + KeysColumns.IS_REVOKED); + + // from user id table + projectionMap.put(UserIdsColumns.USER_ID, Tables.USER_IDS + "." + UserIdsColumns.USER_ID); + + qb.setProjectionMap(projectionMap); + } + + { // FROM + // todo: outsource into buildUnifiedQuery()? see above. + // join keyrings with keys and userIds + // Only get user id and key with rank 0 (main user id and main key) + qb.setTables(Tables.KEY_RINGS + " INNER JOIN " + Tables.KEYS + " ON " + "(" + + Tables.KEY_RINGS + "." + BaseColumns._ID + " = " + Tables.KEYS + "." + + KeysColumns.KEY_RING_ROW_ID + " AND " + Tables.KEYS + "." + + KeysColumns.RANK + " = '0') " + " INNER JOIN " + Tables.USER_IDS + " ON " + + "(" + Tables.KEY_RINGS + "." + BaseColumns._ID + " = " + Tables.USER_IDS + "." + + UserIdsColumns.KEY_RING_ROW_ID + " AND " + Tables.USER_IDS + "." + + UserIdsColumns.RANK + " = '0')"); + } + + // GROUP BY + groupBy = Tables.KEY_RINGS + "." + KeyRingsColumns.MASTER_KEY_ID; + + break; + case PUBLIC_KEY_RING: case SECRET_KEY_RING: qb = buildKeyRingQuery(qb, match); @@ -705,7 +688,7 @@ public class KeychainProvider extends ContentProvider { orderBy = sortOrder; } - Cursor c = qb.query(db, projection, selection, selectionArgs, null, null, orderBy); + Cursor c = qb.query(db, projection, selection, selectionArgs, groupBy, having, orderBy); // Tell the cursor what uri to watch, so it knows when its source data changes c.setNotificationUri(getContext().getContentResolver(), uri); @@ -855,6 +838,9 @@ public class KeychainProvider extends ContentProvider { // notify of changes in db getContext().getContentResolver().notifyChange(uri, null); + getContext().getContentResolver().notifyChange( + KeyRings.buildUnifiedKeyRingsUri().buildUpon().appendPath("lulz").build(), null + ); return count; } diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java index 5b57132d4..72af24717 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java @@ -31,6 +31,7 @@ import org.sufficientlysecure.keychain.provider.KeychainContract; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyTypes; import org.sufficientlysecure.keychain.provider.KeychainContract.UserIds; +import org.sufficientlysecure.keychain.provider.KeychainDatabase; import org.sufficientlysecure.keychain.provider.ProviderHelper; import org.sufficientlysecure.keychain.ui.dialog.DeleteKeyDialogFragment; import org.sufficientlysecure.keychain.util.Log; @@ -255,7 +256,11 @@ public class KeyListFragment extends Fragment implements SearchView.OnQueryTextL static final int INDEX_TYPE = 1; static final int INDEX_UID = 3; - static final String SORT_ORDER = UserIds.USER_ID + " ASC"; + static final String SORT_ORDER = + // show secret before public key + KeychainDatabase.Tables.KEY_RINGS + "." + KeyRings.TYPE + " DESC, " + // sort by user id otherwise + + UserIds.USER_ID + " ASC"; @Override public Loader onCreateLoader(int id, Bundle args) { From b9a907df0b305350c4ccf4f44d1178a0267c1062 Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Thu, 13 Mar 2014 00:29:28 +0100 Subject: [PATCH 08/35] remove special treatment for unified list query note: the unified query /will/ need special treatment once certs are joined in, so I am leaving this as an artifact commit for later reference or point to revert to. --- .../keychain/provider/KeychainProvider.java | 55 +++++-------------- 1 file changed, 15 insertions(+), 40 deletions(-) diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainProvider.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainProvider.java index 3782f85fd..cc08b26bd 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainProvider.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainProvider.java @@ -377,6 +377,10 @@ public class KeychainProvider extends ContentProvider { projectionMap.put(UserIdsColumns.USER_ID, Tables.USER_IDS + "." + UserIdsColumns.USER_ID); + // type attribute is special: if there is any grouping, choose secret over public type + projectionMap.put(KeyRingsColumns.TYPE, + "MAX(" + Tables.KEY_RINGS + "." + KeyRingsColumns.TYPE + ") AS " + KeyRingsColumns.TYPE); + return projectionMap; } @@ -411,9 +415,11 @@ public class KeychainProvider extends ContentProvider { * Builds default query for keyRings: KeyRings table is joined with UserIds and Keys */ private SQLiteQueryBuilder buildKeyRingQuery(SQLiteQueryBuilder qb, int match) { - // public or secret keyring - qb.appendWhere(Tables.KEY_RINGS + "." + KeyRingsColumns.TYPE + " = "); - qb.appendWhereEscapeString(Integer.toString(getKeyType(match))); + if(match != UNIFIED_KEY_RING) { + // public or secret keyring + qb.appendWhere(Tables.KEY_RINGS + "." + KeyRingsColumns.TYPE + " = "); + qb.appendWhereEscapeString(Integer.toString(getKeyType(match))); + } // join keyrings with keys and userIds // Only get user id and key with rank 0 (main user id and main key) @@ -472,46 +478,15 @@ public class KeychainProvider extends ContentProvider { switch (match) { case UNIFIED_KEY_RING: + qb = buildKeyRingQuery(qb, match); - { // SELECT - // todo: outsource into getprojectionmapforthingies? don't really see the point. - HashMap projectionMap = new HashMap(); - - // from keyrings table - projectionMap.put(BaseColumns._ID, Tables.KEY_RINGS + "." + BaseColumns._ID); - projectionMap.put(KeyRingsColumns.TYPE, - "MAX(" + Tables.KEY_RINGS + "." + KeyRingsColumns.TYPE + ")"); - projectionMap.put(KeyRingsColumns.KEY_RING_DATA, Tables.KEY_RINGS + "." - + KeyRingsColumns.KEY_RING_DATA); - projectionMap.put(KeyRingsColumns.MASTER_KEY_ID, - Tables.KEY_RINGS + "." + KeyRingsColumns.MASTER_KEY_ID); - - // from keys table - projectionMap.put(KeysColumns.FINGERPRINT, Tables.KEYS + "." + KeysColumns.FINGERPRINT); - projectionMap.put(KeysColumns.IS_REVOKED, Tables.KEYS + "." + KeysColumns.IS_REVOKED); - - // from user id table - projectionMap.put(UserIdsColumns.USER_ID, Tables.USER_IDS + "." + UserIdsColumns.USER_ID); - - qb.setProjectionMap(projectionMap); - } - - { // FROM - // todo: outsource into buildUnifiedQuery()? see above. - // join keyrings with keys and userIds - // Only get user id and key with rank 0 (main user id and main key) - qb.setTables(Tables.KEY_RINGS + " INNER JOIN " + Tables.KEYS + " ON " + "(" - + Tables.KEY_RINGS + "." + BaseColumns._ID + " = " + Tables.KEYS + "." - + KeysColumns.KEY_RING_ROW_ID + " AND " + Tables.KEYS + "." - + KeysColumns.RANK + " = '0') " + " INNER JOIN " + Tables.USER_IDS + " ON " - + "(" + Tables.KEY_RINGS + "." + BaseColumns._ID + " = " + Tables.USER_IDS + "." - + UserIdsColumns.KEY_RING_ROW_ID + " AND " + Tables.USER_IDS + "." - + UserIdsColumns.RANK + " = '0')"); - } - - // GROUP BY + // GROUP BY so we don't get duplicates groupBy = Tables.KEY_RINGS + "." + KeyRingsColumns.MASTER_KEY_ID; + if (TextUtils.isEmpty(sortOrder)) { + sortOrder = KeyRings.TYPE + " DESC, " + Tables.USER_IDS + "." + UserIdsColumns.USER_ID + " ASC"; + } + break; case PUBLIC_KEY_RING: From 3f649d4458ef08c03bb671f78f2a65478c829400 Mon Sep 17 00:00:00 2001 From: grait Date: Tue, 11 Mar 2014 01:37:16 +0530 Subject: [PATCH 09/35] Export is cancellable now --- .../keychain/helper/ExportHelper.java | 30 +++++++++++-------- .../keychain/pgp/PgpImportExport.java | 24 +++++++++++++-- .../service/KeychainIntentService.java | 14 +++++++-- 3 files changed, 52 insertions(+), 16 deletions(-) diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/helper/ExportHelper.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/helper/ExportHelper.java index 19dfccbde..245c5fda1 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/helper/ExportHelper.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/helper/ExportHelper.java @@ -16,6 +16,17 @@ package org.sufficientlysecure.keychain.helper; +import android.app.ProgressDialog; +import android.content.DialogInterface; +import android.content.Intent; +import android.net.Uri; +import android.os.Bundle; +import android.os.Handler; +import android.os.Message; +import android.os.Messenger; +import android.support.v7.app.ActionBarActivity; +import android.widget.Toast; + import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.Id; import org.sufficientlysecure.keychain.R; @@ -26,16 +37,6 @@ import org.sufficientlysecure.keychain.ui.dialog.DeleteKeyDialogFragment; import org.sufficientlysecure.keychain.ui.dialog.FileDialogFragment; import org.sufficientlysecure.keychain.util.Log; -import android.app.ProgressDialog; -import android.content.Intent; -import android.net.Uri; -import android.os.Bundle; -import android.os.Handler; -import android.os.Message; -import android.os.Messenger; -import android.support.v7.app.ActionBarActivity; -import android.widget.Toast; - public class ExportHelper { protected FileDialogFragment mFileDialog; protected String mExportFilename; @@ -115,7 +116,7 @@ public class ExportHelper { Log.d(Constants.TAG, "exportKeys started"); // Send all information needed to service to export key in other thread - Intent intent = new Intent(activity, KeychainIntentService.class); + final Intent intent = new Intent(activity, KeychainIntentService.class); intent.setAction(KeychainIntentService.ACTION_EXPORT_KEYRING); @@ -135,7 +136,12 @@ public class ExportHelper { // Message is received after exporting is done in ApgService KeychainIntentServiceHandler exportHandler = new KeychainIntentServiceHandler(activity, - activity.getString(R.string.progress_exporting), ProgressDialog.STYLE_HORIZONTAL) { + activity.getString(R.string.progress_exporting), ProgressDialog.STYLE_HORIZONTAL, true, new DialogInterface.OnCancelListener() { + @Override + public void onCancel(DialogInterface dialogInterface) { + activity.stopService(intent); + } + }) { public void handleMessage(Message message) { // handle messages by standard ApgHandler first super.handleMessage(message); diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpImportExport.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpImportExport.java index 138e54f71..0315650eb 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpImportExport.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpImportExport.java @@ -50,15 +50,28 @@ import android.os.Bundle; import android.os.Environment; public class PgpImportExport { + + public interface KeychainServiceListener{ + public boolean hasServiceStopped(); + } private Context mContext; private ProgressDialogUpdater mProgress; + private KeychainServiceListener mKeychainServiceListener; + public PgpImportExport(Context context, ProgressDialogUpdater progress) { super(); this.mContext = context; this.mProgress = progress; } + public PgpImportExport(Context context, ProgressDialogUpdater progress, KeychainServiceListener keychainListener){ + super(); + this.mContext = context; + this.mProgress = progress; + this.mKeychainServiceListener = keychainListener; + } + public void updateProgress(int message, int current, int total) { if (mProgress != null) { mProgress.setProgress(message, current, total); @@ -188,8 +201,10 @@ public class PgpImportExport { if (secretKeyRing != null) { secretKeyRing.encode(arOutStream); } - // Else if it's a public key get the PGPPublicKeyRing - // and encode that to the output + if(mKeychainServiceListener.hasServiceStopped()==true){ + arOutStream.close(); + return null; + } } else { updateProgress(i * 100 / rowIdsSize, 100); PGPPublicKeyRing publicKeyRing = @@ -198,6 +213,11 @@ public class PgpImportExport { if (publicKeyRing != null) { publicKeyRing.encode(arOutStream); } + + if(mKeychainServiceListener.hasServiceStopped() == true){ + arOutStream.close(); + return null; + } } arOutStream.close(); diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java index 93238349d..83531c8e2 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java @@ -73,7 +73,7 @@ import android.os.RemoteException; * data from the activities or other apps, queues these intents, executes them, and stops itself * after doing them. */ -public class KeychainIntentService extends IntentService implements ProgressDialogUpdater { +public class KeychainIntentService extends IntentService implements ProgressDialogUpdater, PgpImportExport.KeychainServiceListener { /* extras that can be given by intent */ public static final String EXTRA_MESSENGER = "messenger"; @@ -712,10 +712,15 @@ public class KeychainIntentService extends IntentService implements ProgressDial Bundle resultData; - PgpImportExport pgpImportExport = new PgpImportExport(this, this); + PgpImportExport pgpImportExport = new PgpImportExport(this, this, this); + resultData = pgpImportExport .exportKeyRings(keyRingRowIds, keyType, outStream); + if(mIsCanceled){ + boolean isDeleted = new File(outputFile).delete(); + } + sendMessageToHandler(KeychainIntentServiceHandler.MESSAGE_OKAY, resultData); } catch (Exception e) { sendErrorToHandler(e); @@ -903,4 +908,9 @@ public class KeychainIntentService extends IntentService implements ProgressDial public void setProgress(int progress, int max) { setProgress(null, progress, max); } + + @Override + public boolean hasServiceStopped() { + return mIsCanceled; + } } From ccdf646c199b000ac12ad2ca7ecaaf90a01d79c7 Mon Sep 17 00:00:00 2001 From: grait Date: Tue, 11 Mar 2014 04:49:52 +0530 Subject: [PATCH 10/35] Export cancellable - minor changes --- .../sufficientlysecure/keychain/pgp/PgpImportExport.java | 8 +++----- .../keychain/service/KeychainIntentService.java | 3 ++- .../keychain/util/KeychainServiceListener.java | 5 +++++ 3 files changed, 10 insertions(+), 6 deletions(-) create mode 100644 OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/util/KeychainServiceListener.java diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpImportExport.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpImportExport.java index 0315650eb..3ce9fa7c5 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpImportExport.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpImportExport.java @@ -42,6 +42,7 @@ import org.sufficientlysecure.keychain.ui.adapter.ImportKeysListEntry; import org.sufficientlysecure.keychain.util.HkpKeyServer; import org.sufficientlysecure.keychain.util.IterableIterator; import org.sufficientlysecure.keychain.util.KeyServer.AddKeyException; +import org.sufficientlysecure.keychain.util.KeychainServiceListener; import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.ProgressDialogUpdater; @@ -51,9 +52,6 @@ import android.os.Environment; public class PgpImportExport { - public interface KeychainServiceListener{ - public boolean hasServiceStopped(); - } private Context mContext; private ProgressDialogUpdater mProgress; @@ -201,7 +199,7 @@ public class PgpImportExport { if (secretKeyRing != null) { secretKeyRing.encode(arOutStream); } - if(mKeychainServiceListener.hasServiceStopped()==true){ + if(mKeychainServiceListener.hasServiceStopped()){ arOutStream.close(); return null; } @@ -214,7 +212,7 @@ public class PgpImportExport { publicKeyRing.encode(arOutStream); } - if(mKeychainServiceListener.hasServiceStopped() == true){ + if(mKeychainServiceListener.hasServiceStopped()){ arOutStream.close(); return null; } diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java index 83531c8e2..23f489d35 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java @@ -56,6 +56,7 @@ import org.sufficientlysecure.keychain.provider.ProviderHelper; import org.sufficientlysecure.keychain.ui.adapter.ImportKeysListEntry; import org.sufficientlysecure.keychain.util.HkpKeyServer; import org.sufficientlysecure.keychain.util.InputData; +import org.sufficientlysecure.keychain.util.KeychainServiceListener; import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.ProgressDialogUpdater; @@ -73,7 +74,7 @@ import android.os.RemoteException; * data from the activities or other apps, queues these intents, executes them, and stops itself * after doing them. */ -public class KeychainIntentService extends IntentService implements ProgressDialogUpdater, PgpImportExport.KeychainServiceListener { +public class KeychainIntentService extends IntentService implements ProgressDialogUpdater, KeychainServiceListener { /* extras that can be given by intent */ public static final String EXTRA_MESSENGER = "messenger"; diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/util/KeychainServiceListener.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/util/KeychainServiceListener.java new file mode 100644 index 000000000..0d7513057 --- /dev/null +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/util/KeychainServiceListener.java @@ -0,0 +1,5 @@ +package org.sufficientlysecure.keychain.util; + +public interface KeychainServiceListener { + boolean hasServiceStopped(); +} From 6af65a2a9b5f90b90bf8752820f40f89241d8014 Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Thu, 13 Mar 2014 13:06:23 +0100 Subject: [PATCH 11/35] merge fixes as per comments in merge https://github.com/openpgp-keychain/openpgp-keychain/pull/403/files#r10540753 --- .../keychain/ui/KeyListFragment.java | 49 +++++++------------ 1 file changed, 19 insertions(+), 30 deletions(-) diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java index 72af24717..ea5c60c53 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java @@ -33,6 +33,7 @@ import org.sufficientlysecure.keychain.provider.KeychainContract.KeyTypes; import org.sufficientlysecure.keychain.provider.KeychainContract.UserIds; import org.sufficientlysecure.keychain.provider.KeychainDatabase; import org.sufficientlysecure.keychain.provider.ProviderHelper; +import org.sufficientlysecure.keychain.ui.adapter.HighlightQueryCursorAdapter; import org.sufficientlysecure.keychain.ui.dialog.DeleteKeyDialogFragment; import org.sufficientlysecure.keychain.util.Log; @@ -203,6 +204,20 @@ public class KeyListFragment extends Fragment implements SearchView.OnQueryTextL showDeleteKeyDialog(mode, ids); break; } + case R.id.menu_key_list_multi_export: { + // todo: public/secret needs to be handled differently here + ids = mStickyList.getWrappedList().getCheckedItemIds(); + ExportHelper mExportHelper = new ExportHelper((ActionBarActivity) getActivity()); + mExportHelper.showExportKeysDialog(ids, Id.type.public_key, Constants.path.APP_DIR_FILE_PUB); + break; + } + case R.id.menu_key_list_multi_select_all: { + // select all + for (int i = 0; i < mStickyList.getCount(); i++) { + mStickyList.setItemChecked(i, true); + } + break; + } } return true; } @@ -455,7 +470,7 @@ public class KeyListFragment extends Fragment implements SearchView.OnQueryTextL /** * Implements StickyListHeadersAdapter from library */ - private class KeyListAdapter extends CursorAdapter implements StickyListHeadersAdapter { + private class KeyListAdapter extends HighlightQueryCursorAdapter implements StickyListHeadersAdapter { private LayoutInflater mInflater; private int mIndexUserId; private int mIndexIsRevoked; @@ -698,42 +713,16 @@ public class KeyListFragment extends Fragment implements SearchView.OnQueryTextL * Change color for multi-selection */ // default color - v.setBackgroundColor(Color.TRANSPARENT); if (mSelection.get(position) != null) { // this is a selected position, change color! v.setBackgroundColor(parent.getResources().getColor(R.color.emphasis)); + } else { + v.setBackgroundColor(Color.TRANSPARENT); } + return v; } - // search highlight methods - - public void setSearchQuery(String searchQuery) { - mCurQuery = searchQuery; - } - - public String getSearchQuery() { - return mCurQuery; - } - - protected Spannable highlightSearchQuery(String text) { - Spannable highlight = Spannable.Factory.getInstance().newSpannable(text); - - if (mCurQuery != null) { - Pattern pattern = Pattern.compile("(?i)" + mCurQuery); - Matcher matcher = pattern.matcher(text); - if (matcher.find()) { - highlight.setSpan( - new ForegroundColorSpan(mContext.getResources().getColor(R.color.emphasis)), - matcher.start(), - matcher.end(), - Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); - } - return highlight; - } else { - return highlight; - } - } } } From be3828c89ee7cd4775ba6b442adb59f1007619ca Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Thu, 13 Mar 2014 14:34:07 +0100 Subject: [PATCH 12/35] drop unified uri in favor of generic /key_rings this works well in the uri schema, and we get notifications back with no effort. ....also remove a line I committed accidentally oO --- .../keychain/provider/KeychainContract.java | 3 +-- .../keychain/provider/KeychainProvider.java | 22 ++++++++----------- 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainContract.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainContract.java index 706b30d05..d9356951e 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainContract.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainContract.java @@ -78,7 +78,6 @@ public class KeychainContract { public static final String PATH_PUBLIC = "public"; public static final String PATH_SECRET = "secret"; - public static final String PATH_UNIFIED = "unified"; public static final String PATH_BY_MASTER_KEY_ID = "master_key_id"; public static final String PATH_BY_KEY_ID = "key_id"; @@ -102,7 +101,7 @@ public class KeychainContract { public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/vnd.thialfihar.apg.key_ring"; public static Uri buildUnifiedKeyRingsUri() { - return CONTENT_URI.buildUpon().appendPath(PATH_UNIFIED).build(); + return CONTENT_URI; } public static Uri buildPublicKeyRingsUri() { diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainProvider.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainProvider.java index cc08b26bd..1a131a689 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainProvider.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainProvider.java @@ -96,6 +96,15 @@ public class KeychainProvider extends ContentProvider { String authority = KeychainContract.CONTENT_AUTHORITY; + /** + * unified key rings + * + *
+         * key_rings
+         * 
+ */ + matcher.addURI(authority, KeychainContract.BASE_KEY_RINGS, UNIFIED_KEY_RING); + /** * public key rings * @@ -228,16 +237,6 @@ public class KeychainProvider extends ContentProvider { matcher.addURI(authority, KeychainContract.BASE_API_APPS + "/" + KeychainContract.PATH_BY_PACKAGE_NAME + "/*", API_APPS_BY_PACKAGE_NAME); - /** - * unified key rings - *
-         *
-         * key_rings/unified
-         *
-         */
-        matcher.addURI(authority, KeychainContract.BASE_KEY_RINGS + "/"
-                + KeychainContract.PATH_UNIFIED, UNIFIED_KEY_RING);
-
         /**
          * data stream
          *
@@ -813,9 +812,6 @@ public class KeychainProvider extends ContentProvider {
 
         // notify of changes in db
         getContext().getContentResolver().notifyChange(uri, null);
-        getContext().getContentResolver().notifyChange(
-                KeyRings.buildUnifiedKeyRingsUri().buildUpon().appendPath("lulz").build(), null
-        );
 
         return count;
     }

From f055228e5bf9d43659238cef1652dc422d2690aa Mon Sep 17 00:00:00 2001
From: uberspot 
Date: Thu, 13 Mar 2014 16:09:37 +0200
Subject: [PATCH 13/35] add apg's change to colorizing, no more background
 changes needed

---
 .../keychain/ui/ViewKeyMainFragment.java      | 42 +++++++++++++------
 1 file changed, 29 insertions(+), 13 deletions(-)

diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyMainFragment.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyMainFragment.java
index d223a259f..a43e3f5b5 100644
--- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyMainFragment.java
+++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyMainFragment.java
@@ -283,31 +283,47 @@ public class ViewKeyMainFragment extends Fragment  implements
         try {
             // for each 4 characters of the fingerprint + 1 space
             for (int i = 0; i < fingerprint.length(); i += 5) {
-                int minFingLength = Math.min(i + 4, fingerprint.length());
-                String fourChars = fingerprint.substring(i, minFingLength);
+                int spanEnd = Math.min(i + 4, fingerprint.length());
+                String fourChars = fingerprint.substring(i, spanEnd);
 
                 int raw = Integer.parseInt(fourChars, 16);
                 byte[] bytes = {(byte) ((raw >> 8) & 0xff - 128), (byte) (raw & 0xff - 128)};
                 int[] color = OtherHelper.getRgbForData(bytes);
+                int r = color[0];
+                int g = color[1];
+                int b = color[2];
+
+                // we cannot change black by multiplication, so adjust it to an almost-black grey,
+                // which will then be brightened to the minimal brightness level
+                if (r == 0 && g == 0 && b == 0) {
+                    r = 1;
+                    g = 1;
+                    b = 1;
+                }
 
                 // Convert rgb to brightness
-                int brightness = (int) (0.2126*color[0] + 0.7152*color[1] + 0.0722*color[2]);
+                double brightness = 0.2126 * r + 0.7152 * g + 0.0722 * b;
 
-                // Detect dark colors and invert their background to white to make them more distinguishable
-                if (brightness < 40) {
-                    sb.setSpan(new BackgroundColorSpan(Color.WHITE),
-                            i, minFingLength, Spannable.SPAN_INCLUSIVE_INCLUSIVE);
+                // If a color is too dark to be seen on black,
+                // then brighten it up to a minimal brightness.
+                if (brightness < 80) {
+                    double factor = 80.0 / brightness;
+                    r = Math.min(255, (int) (r * factor));
+                    g = Math.min(255, (int) (g * factor));
+                    b = Math.min(255, (int) (b * factor));
 
-                // Detect bright colors and invert their background to black to make them more distinguishable
-                } else if (brightness > 210) {
-                    sb.setSpan(new BackgroundColorSpan(Color.BLACK),
-                            i, minFingLength, Spannable.SPAN_INCLUSIVE_INCLUSIVE);
+                // If it is too light, then darken it to a respective maximal brightness.
+                } else if (brightness > 180) {
+                    double factor = 180.0 / brightness;
+                    r = (int) (r * factor);
+                    g = (int) (g * factor);
+                    b = (int) (b * factor);
                 }
 
                 // Create a foreground color with the 3 digest integers as RGB
                 // and then converting that int to hex to use as a color
-                sb.setSpan(new ForegroundColorSpan(Color.rgb(color[0], color[1], color[2])),
-                                            i, minFingLength, Spannable.SPAN_INCLUSIVE_INCLUSIVE);
+                sb.setSpan(new ForegroundColorSpan(Color.rgb(r, g, b)),
+                                            i, spanEnd, Spannable.SPAN_INCLUSIVE_INCLUSIVE);
             }
         } catch (Exception e) {
             Log.e(Constants.TAG, "Colorization failed", e);

From f4370b3ac8378a92192d8d84496aa6ea1fb27b0c Mon Sep 17 00:00:00 2001
From: gogowitczak 
Date: Thu, 13 Mar 2014 15:39:38 +0100
Subject: [PATCH 14/35] Added possibility to specify port for KeyServer.

---
 .../keychain/util/HkpKeyServer.java           | 54 ++++++++++---------
 1 file changed, 30 insertions(+), 24 deletions(-)

diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/util/HkpKeyServer.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/util/HkpKeyServer.java
index 32266839c..b6ffa0ef0 100644
--- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/util/HkpKeyServer.java
+++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/util/HkpKeyServer.java
@@ -18,24 +18,7 @@
 
 package org.sufficientlysecure.keychain.util;
 
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.UnsupportedEncodingException;
-import java.net.HttpURLConnection;
-import java.net.InetAddress;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.net.URLEncoder;
-import java.net.UnknownHostException;
-import java.util.ArrayList;
-import java.util.GregorianCalendar;
-import java.util.List;
-import java.util.TimeZone;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-import java.util.Locale;
-
+import android.text.Html;
 import org.apache.http.HttpEntity;
 import org.apache.http.HttpResponse;
 import org.apache.http.HttpStatus;
@@ -51,7 +34,14 @@ import org.sufficientlysecure.keychain.pgp.PgpHelper;
 import org.sufficientlysecure.keychain.pgp.PgpKeyHelper;
 import org.sufficientlysecure.keychain.ui.adapter.ImportKeysListEntry;
 
-import android.text.Html;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.UnsupportedEncodingException;
+import java.net.*;
+import java.util.*;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 
 /**
  * TODO:
@@ -82,7 +72,7 @@ public class HkpKeyServer extends KeyServer {
     }
 
     private String mHost;
-    private short mPort = 11371;
+    private short mPort;
 
     // example:
     // pub 2048R/9F5C9090 2009-08-17 hostname" (eg. "pool.sks-keyservers.net"), then it will
+	 *                connect using {@link #PORT_DEFAULT}. However, port may be specified after colon
+	 *                ("hostname:port", eg. "p80.pool.sks-keyservers.net:80").
+	 */
+	public HkpKeyServer(String hostAndPort) {
+		String host = hostAndPort;
+		short port = PORT_DEFAULT;
+		final int colonPosition = hostAndPort.lastIndexOf(':');
+		if (colonPosition > 0) {
+			host = hostAndPort.substring(0, colonPosition);
+			final String portStr = hostAndPort.substring(colonPosition + 1);
+			port = Short.decode(portStr);
+		}
+		mHost = host;
+		mPort = port;
+	}
 
     public HkpKeyServer(String host, short port) {
         mHost = host;
@@ -226,7 +232,7 @@ public class HkpKeyServer extends KeyServer {
         HttpClient client = new DefaultHttpClient();
         try {
             HttpGet get = new HttpGet("http://" + mHost + ":" + mPort
-                    + "/pks/lookup?op=get&search=" + PgpKeyHelper.convertKeyIdToHex(keyId));
+                    + "/pks/lookup?op=get&search=0x" + PgpKeyHelper.convertKeyIdToHex(keyId));
 
             HttpResponse response = client.execute(get);
             if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {

From ccde4212e013ea5955cea26265423c84f4c74faf Mon Sep 17 00:00:00 2001
From: gogowitczak 
Date: Thu, 13 Mar 2014 15:53:43 +0100
Subject: [PATCH 15/35] Added possibility to specify port for KeyServer.

---
 .../java/org/sufficientlysecure/keychain/util/HkpKeyServer.java | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/util/HkpKeyServer.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/util/HkpKeyServer.java
index b6ffa0ef0..99cac1152 100644
--- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/util/HkpKeyServer.java
+++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/util/HkpKeyServer.java
@@ -232,7 +232,7 @@ public class HkpKeyServer extends KeyServer {
         HttpClient client = new DefaultHttpClient();
         try {
             HttpGet get = new HttpGet("http://" + mHost + ":" + mPort
-                    + "/pks/lookup?op=get&search=0x" + PgpKeyHelper.convertKeyIdToHex(keyId));
+                    + "/pks/lookup?op=get&search=" + PgpKeyHelper.convertKeyIdToHex(keyId));
 
             HttpResponse response = client.execute(get);
             if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {

From 471cefa71f3ea91b07d1c5f94c95e9b17cecb7a6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Dominik=20Sch=C3=BCrmann?= 
Date: Thu, 13 Mar 2014 18:27:08 +0100
Subject: [PATCH 16/35] Cleanup and simplification

---
 .../keychain/provider/KeychainProvider.java   |  2 +-
 .../keychain/ui/KeyListFragment.java          | 83 +++++--------------
 2 files changed, 24 insertions(+), 61 deletions(-)

diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainProvider.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainProvider.java
index 1a131a689..fdc4b7bda 100644
--- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainProvider.java
+++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainProvider.java
@@ -414,7 +414,7 @@ public class KeychainProvider extends ContentProvider {
      * Builds default query for keyRings: KeyRings table is joined with UserIds and Keys
      */
     private SQLiteQueryBuilder buildKeyRingQuery(SQLiteQueryBuilder qb, int match) {
-        if(match != UNIFIED_KEY_RING) {
+        if (match != UNIFIED_KEY_RING) {
             // public or secret keyring
             qb.appendWhere(Tables.KEY_RINGS + "." + KeyRingsColumns.TYPE + " = ");
             qb.appendWhereEscapeString(Integer.toString(getKeyType(match)));
diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java
index ea5c60c53..70ffe968d 100644
--- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java
+++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2013 Dominik Schürmann 
+ * Copyright (C) 2013-2014 Dominik Schürmann 
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -19,8 +19,6 @@ package org.sufficientlysecure.keychain.ui;
 
 import java.util.HashMap;
 import java.util.ArrayList;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
 
 import org.sufficientlysecure.keychain.Constants;
 import org.sufficientlysecure.keychain.Id;
@@ -32,7 +30,6 @@ import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings;
 import org.sufficientlysecure.keychain.provider.KeychainContract.KeyTypes;
 import org.sufficientlysecure.keychain.provider.KeychainContract.UserIds;
 import org.sufficientlysecure.keychain.provider.KeychainDatabase;
-import org.sufficientlysecure.keychain.provider.ProviderHelper;
 import org.sufficientlysecure.keychain.ui.adapter.HighlightQueryCursorAdapter;
 import org.sufficientlysecure.keychain.ui.dialog.DeleteKeyDialogFragment;
 import org.sufficientlysecure.keychain.util.Log;
@@ -57,13 +54,10 @@ import android.support.v4.app.Fragment;
 import android.support.v4.app.LoaderManager;
 import android.support.v4.content.CursorLoader;
 import android.support.v4.content.Loader;
-import android.support.v4.widget.CursorAdapter;
 import android.support.v4.view.MenuItemCompat;
 import android.support.v7.app.ActionBarActivity;
 import android.support.v7.widget.SearchView;
-import android.text.Spannable;
 import android.text.TextUtils;
-import android.text.style.ForegroundColorSpan;
 import android.view.ActionMode;
 import android.view.LayoutInflater;
 import android.view.Menu;
@@ -270,10 +264,13 @@ public class KeyListFragment extends Fragment implements SearchView.OnQueryTextL
     };
 
     static final int INDEX_TYPE = 1;
-    static final int INDEX_UID = 3;
+    static final int INDEX_MASTER_KEY_ID = 2;
+    static final int INDEX_USER_ID = 3;
+    static final int INDEX_IS_REVOKED = 4;
+
     static final String SORT_ORDER =
-                // show secret before public key
-                KeychainDatabase.Tables.KEY_RINGS + "." + KeyRings.TYPE + " DESC, "
+            // show secret before public key
+            KeychainDatabase.Tables.KEY_RINGS + "." + KeyRings.TYPE + " DESC, "
                     // sort by user id otherwise
                     + UserIds.USER_ID + " ASC";
 
@@ -472,43 +469,20 @@ public class KeyListFragment extends Fragment implements SearchView.OnQueryTextL
      */
     private class KeyListAdapter extends HighlightQueryCursorAdapter implements StickyListHeadersAdapter {
         private LayoutInflater mInflater;
-        private int mIndexUserId;
-        private int mIndexIsRevoked;
-        private int mMasterKeyId;
 
-        private String mCurQuery;
-
-        @SuppressLint("UseSparseArrays")
         private HashMap mSelection = new HashMap();
 
         public KeyListAdapter(Context context, Cursor c, int flags) {
             super(context, c, flags);
 
             mInflater = LayoutInflater.from(context);
-            initIndex(c);
         }
 
         @Override
         public Cursor swapCursor(Cursor newCursor) {
-            initIndex(newCursor);
-
             return super.swapCursor(newCursor);
         }
 
-        /**
-         * Get column indexes for performance reasons just once in constructor and swapCursor. For a
-         * performance comparison see http://stackoverflow.com/a/17999582
-         *
-         * @param cursor
-         */
-        private void initIndex(Cursor cursor) {
-            if (cursor != null) {
-                mIndexUserId = cursor.getColumnIndexOrThrow(KeychainContract.UserIds.USER_ID);
-                mIndexIsRevoked = cursor.getColumnIndexOrThrow(KeychainContract.Keys.IS_REVOKED);
-                mMasterKeyId = cursor.getColumnIndexOrThrow(KeychainContract.KeyRings.MASTER_KEY_ID);
-            }
-        }
-
         /**
          * Bind cursor data to the item list view
          * 

@@ -522,15 +496,15 @@ public class KeyListFragment extends Fragment implements SearchView.OnQueryTextL TextView mainUserId = (TextView) view.findViewById(R.id.mainUserId); TextView mainUserIdRest = (TextView) view.findViewById(R.id.mainUserIdRest); - String userId = cursor.getString(mIndexUserId); + String userId = cursor.getString(INDEX_USER_ID); String[] userIdSplit = PgpKeyHelper.splitUserId(userId); if (userIdSplit[0] != null) { - mainUserId.setText(highlightSearchQuery(userIdSplit[0])); + mainUserId.setText(highlightSearchQuery(userIdSplit[0])); } else { mainUserId.setText(R.string.user_id_no_name); } if (userIdSplit[1] != null) { - mainUserIdRest.setText(highlightSearchQuery(userIdSplit[1])); + mainUserIdRest.setText(highlightSearchQuery(userIdSplit[1])); mainUserIdRest.setVisibility(View.VISIBLE); } else { mainUserIdRest.setVisibility(View.GONE); @@ -541,12 +515,12 @@ public class KeyListFragment extends Fragment implements SearchView.OnQueryTextL Button button = (Button) view.findViewById(R.id.edit); TextView revoked = (TextView) view.findViewById(R.id.revoked); - if(cursor.getInt(KeyListFragment.INDEX_TYPE) == KeyTypes.SECRET) { + if (cursor.getInt(KeyListFragment.INDEX_TYPE) == KeyTypes.SECRET) { // this is a secret key - show the edit button revoked.setVisibility(View.GONE); button.setVisibility(View.VISIBLE); - final long id = cursor.getLong(mMasterKeyId); + final long id = cursor.getLong(INDEX_MASTER_KEY_ID); button.setOnClickListener(new OnClickListener() { public void onClick(View view) { Intent editIntent = new Intent(getActivity(), EditKeyActivity.class); @@ -559,7 +533,7 @@ public class KeyListFragment extends Fragment implements SearchView.OnQueryTextL // this is a public key - hide the edit button, show if it's revoked button.setVisibility(View.GONE); - boolean isRevoked = cursor.getInt(mIndexIsRevoked) > 0; + boolean isRevoked = cursor.getInt(INDEX_IS_REVOKED) > 0; revoked.setVisibility(isRevoked ? View.VISIBLE : View.GONE); } } @@ -567,23 +541,11 @@ public class KeyListFragment extends Fragment implements SearchView.OnQueryTextL } public long getMasterKeyId(int id) { - if (!mCursor.moveToPosition(id)) { throw new IllegalStateException("couldn't move cursor to position " + id); } - return mCursor.getLong(mMasterKeyId); - - } - - public int getKeyType(int position) { - - if (!mCursor.moveToPosition(position)) { - throw new IllegalStateException("couldn't move cursor to position " + position); - } - - return mCursor.getInt(KeyListFragment.INDEX_TYPE); - + return mCursor.getLong(INDEX_MASTER_KEY_ID); } @Override @@ -621,7 +583,7 @@ public class KeyListFragment extends Fragment implements SearchView.OnQueryTextL throw new IllegalStateException("couldn't move cursor to position " + position); } - if(mCursor.getInt(KeyListFragment.INDEX_TYPE) == KeyTypes.SECRET) { + if (mCursor.getInt(KeyListFragment.INDEX_TYPE) == KeyTypes.SECRET) { { // set contact count int num = mCursor.getCount(); String contactsTotal = getResources().getQuantityString(R.plurals.n_contacts, num, num); @@ -634,10 +596,10 @@ public class KeyListFragment extends Fragment implements SearchView.OnQueryTextL } // set header text as first char in user id - String userId = mCursor.getString(KeyListFragment.INDEX_UID); + String userId = mCursor.getString(KeyListFragment.INDEX_USER_ID); String headerText = convertView.getResources().getString(R.string.user_id_no_name); if (userId != null && userId.length() > 0) { - headerText = "" + mCursor.getString(KeyListFragment.INDEX_UID).subSequence(0, 1).charAt(0); + headerText = "" + mCursor.getString(KeyListFragment.INDEX_USER_ID).subSequence(0, 1).charAt(0); } holder.text.setText(headerText); holder.count.setVisibility(View.GONE); @@ -660,11 +622,11 @@ public class KeyListFragment extends Fragment implements SearchView.OnQueryTextL } // early breakout: all secret keys are assigned id 0 - if(mCursor.getInt(KeyListFragment.INDEX_TYPE) == KeyTypes.SECRET) + if (mCursor.getInt(KeyListFragment.INDEX_TYPE) == KeyTypes.SECRET) return 1L; // otherwise, return the first character of the name as ID - String userId = mCursor.getString(KeyListFragment.INDEX_UID); + String userId = mCursor.getString(KeyListFragment.INDEX_USER_ID); if (userId != null && userId.length() > 0) { return userId.charAt(0); } else { @@ -689,8 +651,9 @@ public class KeyListFragment extends Fragment implements SearchView.OnQueryTextL long[] ids = new long[mSelection.size()]; int i = 0; // get master key ids - for (int pos : mSelection.keySet()) + for (int pos : mSelection.keySet()) { ids[i++] = mAdapter.getMasterKeyId(pos); + } return ids; } @@ -712,11 +675,11 @@ public class KeyListFragment extends Fragment implements SearchView.OnQueryTextL /** * Change color for multi-selection */ - // default color if (mSelection.get(position) != null) { - // this is a selected position, change color! + // selected position color v.setBackgroundColor(parent.getResources().getColor(R.color.emphasis)); } else { + // default color v.setBackgroundColor(Color.TRANSPARENT); } From cf51e5ff56070bbec52c70b36f4109484e84adb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Sch=C3=BCrmann?= Date: Thu, 13 Mar 2014 18:53:21 +0100 Subject: [PATCH 17/35] XML cleanup and bigger filename EditText --- .../src/main/res/layout/decrypt_activity.xml | 361 +++++++++--------- .../src/main/res/layout/encrypt_activity.xml | 13 +- .../src/main/res/layout/file_dialog.xml | 4 +- 3 files changed, 195 insertions(+), 183 deletions(-) diff --git a/OpenPGP-Keychain/src/main/res/layout/decrypt_activity.xml b/OpenPGP-Keychain/src/main/res/layout/decrypt_activity.xml index a974f6ec0..25c7c000c 100644 --- a/OpenPGP-Keychain/src/main/res/layout/decrypt_activity.xml +++ b/OpenPGP-Keychain/src/main/res/layout/decrypt_activity.xml @@ -5,201 +5,206 @@ android:layout_width="match_parent" android:layout_height="match_parent"> - + - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + android:id="@+id/relativeLayout"> + + + + + + + + + + + + + + + + + + + + + + + - + android:layout_height="match_parent" + android:gravity="top" + android:inputType="text|textCapSentences|textMultiLine|textLongMessage" + android:scrollHorizontally="true" /> + + + + + + + + + + + + + + + + + + + + + + - + + diff --git a/OpenPGP-Keychain/src/main/res/layout/encrypt_activity.xml b/OpenPGP-Keychain/src/main/res/layout/encrypt_activity.xml index dc4cf0063..4fe65e341 100644 --- a/OpenPGP-Keychain/src/main/res/layout/encrypt_activity.xml +++ b/OpenPGP-Keychain/src/main/res/layout/encrypt_activity.xml @@ -238,7 +238,12 @@ android:layout_width="0dip" android:layout_height="wrap_content" android:layout_weight="1" - android:inputType="textNoSuggestions" /> + android:gravity="top|left" + android:inputType="textMultiLine|textUri" + android:lines="4" + android:maxLines="10" + android:minLines="2" + android:scrollbars="vertical" /> + + fontawesometext:fa_icon="fa-chevron-right" /> + + android:textColor="@color/emphasis" /> From 4c5ae3cdaa525ca925b5e7229a7c02b89b8cefd7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Sch=C3=BCrmann?= Date: Thu, 13 Mar 2014 19:01:24 +0100 Subject: [PATCH 18/35] Readd create key menu items --- .../keychain/ui/KeyListActivity.java | 46 +++++++++++++++---- .../src/main/res/menu/key_list.xml | 26 +++++++++-- .../src/main/res/values/strings.xml | 1 + 3 files changed, 59 insertions(+), 14 deletions(-) diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListActivity.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListActivity.java index 9eebbed64..684ee6959 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListActivity.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListActivity.java @@ -53,19 +53,45 @@ public class KeyListActivity extends DrawerActivity { @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { - case R.id.menu_key_list_import: - Intent intentImport = new Intent(this, ImportKeysActivity.class); - startActivityForResult(intentImport, 0); + case R.id.menu_key_list_import: + Intent intentImport = new Intent(this, ImportKeysActivity.class); + startActivityForResult(intentImport, 0); - return true; - case R.id.menu_key_list_export: - // TODO fix this for unified keylist - mExportHelper.showExportKeysDialog(null, Id.type.public_key, Constants.path.APP_DIR_FILE_PUB); + return true; + case R.id.menu_key_list_export: + // TODO fix this for unified keylist + mExportHelper.showExportKeysDialog(null, Id.type.public_key, Constants.path.APP_DIR_FILE_PUB); - return true; - default: - return super.onOptionsItemSelected(item); + return true; + case R.id.menu_key_list_create: + createKey(); + + return true; + case R.id.menu_key_list_create_expert: + createKeyExpert(); + + return true; + case R.id.menu_key_list_secret_export: + mExportHelper.showExportKeysDialog(null, Id.type.secret_key, Constants.path.APP_DIR_FILE_SEC); + + + default: + return super.onOptionsItemSelected(item); } } + private void createKey() { + Intent intent = new Intent(this, EditKeyActivity.class); + intent.setAction(EditKeyActivity.ACTION_CREATE_KEY); + intent.putExtra(EditKeyActivity.EXTRA_GENERATE_DEFAULT_KEYS, true); + intent.putExtra(EditKeyActivity.EXTRA_USER_IDS, ""); // show user id view + startActivityForResult(intent, 0); + } + + private void createKeyExpert() { + Intent intent = new Intent(this, EditKeyActivity.class); + intent.setAction(EditKeyActivity.ACTION_CREATE_KEY); + startActivityForResult(intent, 0); + } + } diff --git a/OpenPGP-Keychain/src/main/res/menu/key_list.xml b/OpenPGP-Keychain/src/main/res/menu/key_list.xml index addef0c2d..10223522c 100644 --- a/OpenPGP-Keychain/src/main/res/menu/key_list.xml +++ b/OpenPGP-Keychain/src/main/res/menu/key_list.xml @@ -7,14 +7,32 @@ app:showAsAction="ifRoom|withText" android:icon="@drawable/ic_action_add_person" android:title="@string/menu_import" /> - + + + + + + + + + +

diff --git a/OpenPGP-Keychain/src/main/res/values/strings.xml b/OpenPGP-Keychain/src/main/res/values/strings.xml index 1c7ead403..4b427917f 100644 --- a/OpenPGP-Keychain/src/main/res/values/strings.xml +++ b/OpenPGP-Keychain/src/main/res/values/strings.xml @@ -78,6 +78,7 @@ Import Import from NFC Export all keys + Export all secret keys Export to file Delete key Create key From 908cf8e7695b282760d7a790ae782346424e7ba8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Sch=C3=BCrmann?= Date: Thu, 13 Mar 2014 19:08:03 +0100 Subject: [PATCH 19/35] Add FAQ tab to help --- .../keychain/ui/HelpActivity.java | 19 +++++++++++-------- .../src/main/res/values/strings.xml | 1 + 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/HelpActivity.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/HelpActivity.java index ac8250bef..48068a6c4 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/HelpActivity.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/HelpActivity.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2012-2013 Dominik Schürmann + * Copyright (C) 2012-2014 Dominik Schürmann * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -17,8 +17,6 @@ package org.sufficientlysecure.keychain.ui; -import java.util.ArrayList; - import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.ui.adapter.TabsAdapter; @@ -29,7 +27,7 @@ import android.support.v7.app.ActionBar; import android.support.v7.app.ActionBarActivity; public class HelpActivity extends ActionBarActivity { - public static final String EXTRA_SELECTED_TAB = "selectedTab"; + public static final String EXTRA_SELECTED_TAB = "selected_tab"; ViewPager mViewPager; TabsAdapter mTabsAdapter; @@ -59,19 +57,24 @@ public class HelpActivity extends ActionBarActivity { Bundle startBundle = new Bundle(); startBundle.putInt(HelpHtmlFragment.ARG_HTML_FILE, R.raw.help_start); mTabsAdapter.addTab(actionBar.newTab().setText(getString(R.string.help_tab_start)), - HelpHtmlFragment.class, startBundle, (selectedTab == 0) ); + HelpHtmlFragment.class, startBundle, (selectedTab == 0)); + + Bundle faqBundle = new Bundle(); + faqBundle.putInt(HelpHtmlFragment.ARG_HTML_FILE, R.raw.help_faq); + mTabsAdapter.addTab(actionBar.newTab().setText(getString(R.string.help_tab_faq)), + HelpHtmlFragment.class, faqBundle, (selectedTab == 1)); Bundle nfcBundle = new Bundle(); nfcBundle.putInt(HelpHtmlFragment.ARG_HTML_FILE, R.raw.help_nfc_beam); mTabsAdapter.addTab(actionBar.newTab().setText(getString(R.string.help_tab_nfc_beam)), - HelpHtmlFragment.class, nfcBundle, (selectedTab == 1) ); + HelpHtmlFragment.class, nfcBundle, (selectedTab == 2)); Bundle changelogBundle = new Bundle(); changelogBundle.putInt(HelpHtmlFragment.ARG_HTML_FILE, R.raw.help_changelog); mTabsAdapter.addTab(actionBar.newTab().setText(getString(R.string.help_tab_changelog)), - HelpHtmlFragment.class, changelogBundle, (selectedTab == 2) ); + HelpHtmlFragment.class, changelogBundle, (selectedTab == 3)); mTabsAdapter.addTab(actionBar.newTab().setText(getString(R.string.help_tab_about)), - HelpAboutFragment.class, null, (selectedTab == 3) ); + HelpAboutFragment.class, null, (selectedTab == 4)); } } \ No newline at end of file diff --git a/OpenPGP-Keychain/src/main/res/values/strings.xml b/OpenPGP-Keychain/src/main/res/values/strings.xml index 4b427917f..77891d6c7 100644 --- a/OpenPGP-Keychain/src/main/res/values/strings.xml +++ b/OpenPGP-Keychain/src/main/res/values/strings.xml @@ -374,6 +374,7 @@ Start + FAQ NFC Beam Changelog About From 5c5e9d8e32619f47aa036b84db7196696700dba4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Sch=C3=BCrmann?= Date: Thu, 13 Mar 2014 19:09:54 +0100 Subject: [PATCH 20/35] Forgot faq file --- OpenPGP-Keychain/src/main/res/raw/help_faq.html | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 OpenPGP-Keychain/src/main/res/raw/help_faq.html diff --git a/OpenPGP-Keychain/src/main/res/raw/help_faq.html b/OpenPGP-Keychain/src/main/res/raw/help_faq.html new file mode 100644 index 000000000..b3d5b3a11 --- /dev/null +++ b/OpenPGP-Keychain/src/main/res/raw/help_faq.html @@ -0,0 +1,12 @@ + + + + + +

TODO

+

text

+ + + From 79a8528a630d192566496a401abbbdabbbcf5d79 Mon Sep 17 00:00:00 2001 From: uberspot Date: Thu, 13 Mar 2014 19:29:21 +0200 Subject: [PATCH 21/35] Optimize imports in all files, remove useless whitespace in some and fix indentation --- .../service/KeychainIntentService.java | 67 ++++++------------- .../service/KeychainIntentServiceHandler.java | 8 +-- .../service/PassphraseCacheService.java | 48 ++++++------- .../service/remote/AppSettingsActivity.java | 23 +++---- .../service/remote/AppSettingsFragment.java | 28 +++----- .../service/remote/OpenPgpService.java | 1 - .../service/remote/RegisteredAppsAdapter.java | 5 +- .../remote/RegisteredAppsListActivity.java | 3 +- .../remote/RegisteredAppsListFragment.java | 9 ++- .../service/remote/RemoteService.java | 21 +++--- .../service/remote/RemoteServiceActivity.java | 1 - tools/checkstyle.xml | 4 +- 12 files changed, 85 insertions(+), 133 deletions(-) diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java index 23f489d35..f893e3488 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java @@ -17,49 +17,6 @@ package org.sufficientlysecure.keychain.service; -import java.io.BufferedInputStream; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.util.ArrayList; -import java.util.GregorianCalendar; -import java.util.List; - -import org.spongycastle.openpgp.PGPKeyRing; -import org.spongycastle.openpgp.PGPObjectFactory; -import org.spongycastle.openpgp.PGPPublicKeyRing; -import org.spongycastle.openpgp.PGPSecretKey; -import org.spongycastle.openpgp.PGPUtil; -import org.sufficientlysecure.keychain.Constants; -import org.sufficientlysecure.keychain.Id; -import org.sufficientlysecure.keychain.R; -import org.sufficientlysecure.keychain.helper.FileHelper; -import org.sufficientlysecure.keychain.helper.OtherHelper; -import org.sufficientlysecure.keychain.helper.Preferences; -import org.sufficientlysecure.keychain.pgp.PgpConversionHelper; -import org.sufficientlysecure.keychain.pgp.PgpDecryptVerify; -import org.sufficientlysecure.keychain.pgp.PgpDecryptVerifyResult; -import org.sufficientlysecure.keychain.pgp.PgpHelper; -import org.sufficientlysecure.keychain.pgp.PgpImportExport; -import org.sufficientlysecure.keychain.pgp.PgpKeyOperation; -import org.sufficientlysecure.keychain.pgp.PgpSignEncrypt; -import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException; -import org.sufficientlysecure.keychain.provider.KeychainContract; -import org.sufficientlysecure.keychain.provider.KeychainContract.DataStream; -import org.sufficientlysecure.keychain.provider.ProviderHelper; -import org.sufficientlysecure.keychain.ui.adapter.ImportKeysListEntry; -import org.sufficientlysecure.keychain.util.HkpKeyServer; -import org.sufficientlysecure.keychain.util.InputData; -import org.sufficientlysecure.keychain.util.KeychainServiceListener; -import org.sufficientlysecure.keychain.util.Log; -import org.sufficientlysecure.keychain.util.ProgressDialogUpdater; - import android.app.IntentService; import android.content.Context; import android.content.Intent; @@ -68,6 +25,24 @@ import android.os.Bundle; import android.os.Message; import android.os.Messenger; import android.os.RemoteException; +import org.spongycastle.openpgp.*; +import org.sufficientlysecure.keychain.Constants; +import org.sufficientlysecure.keychain.Id; +import org.sufficientlysecure.keychain.R; +import org.sufficientlysecure.keychain.helper.FileHelper; +import org.sufficientlysecure.keychain.helper.OtherHelper; +import org.sufficientlysecure.keychain.helper.Preferences; +import org.sufficientlysecure.keychain.pgp.*; +import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException; +import org.sufficientlysecure.keychain.provider.KeychainContract.DataStream; +import org.sufficientlysecure.keychain.provider.ProviderHelper; +import org.sufficientlysecure.keychain.ui.adapter.ImportKeysListEntry; +import org.sufficientlysecure.keychain.util.*; + +import java.io.*; +import java.util.ArrayList; +import java.util.GregorianCalendar; +import java.util.List; /** * This Service contains all important long lasting operations for APG. It receives Intents with @@ -706,7 +681,7 @@ public class KeychainIntentService extends IntentService implements ProgressDial keyRingRowIds = ProviderHelper.getSecretKeyRingsRowIds(this); } } else { - for(long rowId : rowIds) { + for (long rowId : rowIds) { keyRingRowIds.add(rowId); } } @@ -718,8 +693,8 @@ public class KeychainIntentService extends IntentService implements ProgressDial resultData = pgpImportExport .exportKeyRings(keyRingRowIds, keyType, outStream); - if(mIsCanceled){ - boolean isDeleted = new File(outputFile).delete(); + if (mIsCanceled) { + boolean isDeleted = new File(outputFile).delete(); } sendMessageToHandler(KeychainIntentServiceHandler.MESSAGE_OKAY, resultData); diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentServiceHandler.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentServiceHandler.java index ebc002ceb..92d012c80 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentServiceHandler.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentServiceHandler.java @@ -17,9 +17,6 @@ package org.sufficientlysecure.keychain.service; -import org.sufficientlysecure.keychain.ui.dialog.ProgressDialogFragment; -import org.sufficientlysecure.keychain.R; - import android.app.Activity; import android.content.DialogInterface.OnCancelListener; import android.os.Bundle; @@ -28,6 +25,8 @@ import android.os.Message; import android.support.v4.app.FragmentActivity; import android.support.v4.app.FragmentManager; import android.widget.Toast; +import org.sufficientlysecure.keychain.R; +import org.sufficientlysecure.keychain.ui.dialog.ProgressDialogFragment; public class KeychainIntentServiceHandler extends Handler { @@ -73,7 +72,8 @@ public class KeychainIntentServiceHandler extends Handler { } public void showProgressDialog(FragmentActivity activity) { - // TODO: This is a hack!, see http://stackoverflow.com/questions/10114324/show-dialogfragment-from-onactivityresult + // TODO: This is a hack!, see + // http://stackoverflow.com/questions/10114324/show-dialogfragment-from-onactivityresult final FragmentManager manager = activity.getSupportFragmentManager(); Handler handler = new Handler(); handler.post(new Runnable() { diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/PassphraseCacheService.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/PassphraseCacheService.java index ce34d451d..134afbfdd 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/PassphraseCacheService.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/PassphraseCacheService.java @@ -17,10 +17,15 @@ package org.sufficientlysecure.keychain.service; -import java.util.Date; -import java.util.HashMap; -import java.util.Iterator; - +import android.app.AlarmManager; +import android.app.PendingIntent; +import android.app.Service; +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import android.content.IntentFilter; +import android.os.*; +import android.util.Log; import android.util.LongSparseArray; import org.spongycastle.openpgp.PGPException; import org.spongycastle.openpgp.PGPPrivateKey; @@ -34,28 +39,13 @@ import org.sufficientlysecure.keychain.helper.Preferences; import org.sufficientlysecure.keychain.pgp.PgpKeyHelper; import org.sufficientlysecure.keychain.provider.ProviderHelper; -import android.app.AlarmManager; -import android.app.PendingIntent; -import android.app.Service; -import android.content.BroadcastReceiver; -import android.content.Context; -import android.content.Intent; -import android.content.IntentFilter; -import android.os.Binder; -import android.os.Bundle; -import android.os.Handler; -import android.os.HandlerThread; -import android.os.IBinder; -import android.os.Message; -import android.os.Messenger; -import android.os.RemoteException; -import android.util.Log; +import java.util.Date; +import java.util.Iterator; /** * This service runs in its own process, but is available to all other processes as the main * passphrase cache. Use the static methods addCachedPassphrase and getCachedPassphrase for * convenience. - * */ public class PassphraseCacheService extends Service { public static final String TAG = Constants.TAG + ": PassphraseCacheService"; @@ -86,7 +76,7 @@ public class PassphraseCacheService extends Service { * This caches a new passphrase in memory by sending a new command to the service. An android * service is only run once. Thus, when the service is already started, new commands just add * new events to the alarm manager for new passphrases to let them timeout in the future. - * + * * @param context * @param keyId * @param passphrase @@ -106,7 +96,7 @@ public class PassphraseCacheService extends Service { /** * Gets a cached passphrase from memory by sending an intent to the service. This method is * designed to wait until the service returns the passphrase. - * + * * @param context * @param keyId * @return passphrase or null (if no passphrase is cached for this keyId) @@ -161,7 +151,7 @@ public class PassphraseCacheService extends Service { /** * Internal implementation to get cached passphrase. - * + * * @param keyId * @return */ @@ -205,7 +195,7 @@ public class PassphraseCacheService extends Service { /** * Checks if key has a passphrase. - * + * * @param secretKeyId * @return true if it has a passphrase */ @@ -216,8 +206,8 @@ public class PassphraseCacheService extends Service { .getPGPSecretKeyRingByKeyId(context, secretKeyId); PGPSecretKey secretKey = null; boolean foundValidKey = false; - for (Iterator keys = secRing.getSecretKeys(); keys.hasNext();) { - secretKey = (PGPSecretKey)keys.next(); + for (Iterator keys = secRing.getSecretKeys(); keys.hasNext(); ) { + secretKey = (PGPSecretKey) keys.next(); if (!secretKey.isPrivateKeyEmpty()) { foundValidKey = true; break; @@ -269,7 +259,7 @@ public class PassphraseCacheService extends Service { /** * Build pending intent that is executed by alarm manager to time out a specific passphrase - * + * * @param context * @param keyId * @return @@ -337,7 +327,7 @@ public class PassphraseCacheService extends Service { /** * Called when one specific passphrase for keyId timed out - * + * * @param context * @param keyId */ diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/remote/AppSettingsActivity.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/remote/AppSettingsActivity.java index 178b2fc67..abdfb775c 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/remote/AppSettingsActivity.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/remote/AppSettingsActivity.java @@ -17,12 +17,6 @@ package org.sufficientlysecure.keychain.service.remote; -import org.sufficientlysecure.keychain.Constants; -import org.sufficientlysecure.keychain.R; -import org.sufficientlysecure.keychain.helper.ActionBarHelper; -import org.sufficientlysecure.keychain.provider.ProviderHelper; -import org.sufficientlysecure.keychain.util.Log; - import android.content.Intent; import android.net.Uri; import android.os.Bundle; @@ -30,6 +24,11 @@ import android.support.v7.app.ActionBarActivity; import android.view.Menu; import android.view.MenuItem; import android.view.View; +import org.sufficientlysecure.keychain.Constants; +import org.sufficientlysecure.keychain.R; +import org.sufficientlysecure.keychain.helper.ActionBarHelper; +import org.sufficientlysecure.keychain.provider.ProviderHelper; +import org.sufficientlysecure.keychain.util.Log; public class AppSettingsActivity extends ActionBarActivity { private Uri mAppUri; @@ -77,12 +76,12 @@ public class AppSettingsActivity extends ActionBarActivity { @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { - case R.id.menu_api_settings_revoke: - revokeAccess(); - return true; - case R.id.menu_api_settings_cancel: - finish(); - return true; + case R.id.menu_api_settings_revoke: + revokeAccess(); + return true; + case R.id.menu_api_settings_cancel: + finish(); + return true; } return super.onOptionsItemSelected(item); } diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/remote/AppSettingsFragment.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/remote/AppSettingsFragment.java index 64c4c5e96..a042e97d6 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/remote/AppSettingsFragment.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/remote/AppSettingsFragment.java @@ -17,17 +17,6 @@ package org.sufficientlysecure.keychain.service.remote; -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; - -import org.spongycastle.util.encoders.Hex; -import org.sufficientlysecure.keychain.Constants; -import org.sufficientlysecure.keychain.R; -import org.sufficientlysecure.keychain.ui.SelectSecretKeyLayoutFragment; -import org.sufficientlysecure.keychain.ui.adapter.KeyValueSpinnerAdapter; -import org.sufficientlysecure.keychain.util.AlgorithmNames; -import org.sufficientlysecure.keychain.util.Log; - import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; import android.content.pm.PackageManager.NameNotFoundException; @@ -40,14 +29,19 @@ import android.view.View.OnClickListener; import android.view.ViewGroup; import android.view.animation.AlphaAnimation; import android.view.animation.Animation; -import android.widget.AdapterView; +import android.widget.*; import android.widget.AdapterView.OnItemSelectedListener; -import android.widget.ImageView; -import android.widget.LinearLayout; -import android.widget.Spinner; -import android.widget.TextView; - import com.beardedhen.androidbootstrap.BootstrapButton; +import org.spongycastle.util.encoders.Hex; +import org.sufficientlysecure.keychain.Constants; +import org.sufficientlysecure.keychain.R; +import org.sufficientlysecure.keychain.ui.SelectSecretKeyLayoutFragment; +import org.sufficientlysecure.keychain.ui.adapter.KeyValueSpinnerAdapter; +import org.sufficientlysecure.keychain.util.AlgorithmNames; +import org.sufficientlysecure.keychain.util.Log; + +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; public class AppSettingsFragment extends Fragment implements SelectSecretKeyLayoutFragment.SelectSecretKeyCallback { diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/remote/OpenPgpService.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/remote/OpenPgpService.java index f697faa6e..a94b19d44 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/remote/OpenPgpService.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/remote/OpenPgpService.java @@ -23,7 +23,6 @@ import android.database.Cursor; import android.net.Uri; import android.os.IBinder; import android.os.ParcelFileDescriptor; - import org.openintents.openpgp.IOpenPgpService; import org.openintents.openpgp.OpenPgpError; import org.openintents.openpgp.OpenPgpSignatureResult; diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/remote/RegisteredAppsAdapter.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/remote/RegisteredAppsAdapter.java index 477ee04d0..7a49bfefa 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/remote/RegisteredAppsAdapter.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/remote/RegisteredAppsAdapter.java @@ -17,9 +17,6 @@ package org.sufficientlysecure.keychain.service.remote; -import org.sufficientlysecure.keychain.R; -import org.sufficientlysecure.keychain.provider.KeychainContract.ApiApps; - import android.content.Context; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; @@ -31,6 +28,8 @@ import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; import android.widget.TextView; +import org.sufficientlysecure.keychain.R; +import org.sufficientlysecure.keychain.provider.KeychainContract.ApiApps; public class RegisteredAppsAdapter extends CursorAdapter { diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/remote/RegisteredAppsListActivity.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/remote/RegisteredAppsListActivity.java index 3c553fff5..f6f216efd 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/remote/RegisteredAppsListActivity.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/remote/RegisteredAppsListActivity.java @@ -17,11 +17,10 @@ package org.sufficientlysecure.keychain.service.remote; +import android.os.Bundle; import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.ui.DrawerActivity; -import android.os.Bundle; - public class RegisteredAppsListActivity extends DrawerActivity { @Override diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/remote/RegisteredAppsListFragment.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/remote/RegisteredAppsListFragment.java index fed267a44..1a49e2e74 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/remote/RegisteredAppsListFragment.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/remote/RegisteredAppsListFragment.java @@ -17,10 +17,6 @@ package org.sufficientlysecure.keychain.service.remote; -import org.sufficientlysecure.keychain.R; -import org.sufficientlysecure.keychain.provider.KeychainContract; -import org.sufficientlysecure.keychain.provider.KeychainContract.ApiApps; - import android.content.ContentUris; import android.content.Intent; import android.database.Cursor; @@ -33,6 +29,9 @@ import android.support.v4.content.Loader; import android.view.View; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; +import org.sufficientlysecure.keychain.R; +import org.sufficientlysecure.keychain.provider.KeychainContract; +import org.sufficientlysecure.keychain.provider.KeychainContract.ApiApps; public class RegisteredAppsListFragment extends ListFragment implements LoaderManager.LoaderCallbacks { @@ -71,7 +70,7 @@ public class RegisteredAppsListFragment extends ListFragment implements } // These are the Contacts rows that we will retrieve. - static final String[] PROJECTION = new String[] { ApiApps._ID, ApiApps.PACKAGE_NAME }; + static final String[] PROJECTION = new String[]{ApiApps._ID, ApiApps.PACKAGE_NAME}; public Loader onCreateLoader(int id, Bundle args) { // This is called when a new Loader needs to be created. This diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/remote/RemoteService.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/remote/RemoteService.java index cb556be39..365008c01 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/remote/RemoteService.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/remote/RemoteService.java @@ -17,17 +17,6 @@ package org.sufficientlysecure.keychain.service.remote; -import java.util.ArrayList; -import java.util.Arrays; - -import org.openintents.openpgp.OpenPgpError; -import org.openintents.openpgp.util.OpenPgpApi; -import org.sufficientlysecure.keychain.Constants; -import org.sufficientlysecure.keychain.R; -import org.sufficientlysecure.keychain.provider.KeychainContract; -import org.sufficientlysecure.keychain.provider.ProviderHelper; -import org.sufficientlysecure.keychain.util.Log; - import android.app.PendingIntent; import android.app.Service; import android.content.Context; @@ -38,6 +27,16 @@ import android.content.pm.PackageManager.NameNotFoundException; import android.content.pm.Signature; import android.net.Uri; import android.os.Binder; +import org.openintents.openpgp.OpenPgpError; +import org.openintents.openpgp.util.OpenPgpApi; +import org.sufficientlysecure.keychain.Constants; +import org.sufficientlysecure.keychain.R; +import org.sufficientlysecure.keychain.provider.KeychainContract; +import org.sufficientlysecure.keychain.provider.ProviderHelper; +import org.sufficientlysecure.keychain.util.Log; + +import java.util.ArrayList; +import java.util.Arrays; /** * Abstract service class for remote APIs that handle app registration and user input. diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/remote/RemoteServiceActivity.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/remote/RemoteServiceActivity.java index 8fb562884..88661c050 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/remote/RemoteServiceActivity.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/remote/RemoteServiceActivity.java @@ -24,7 +24,6 @@ import android.os.Message; import android.os.Messenger; import android.support.v7.app.ActionBarActivity; import android.view.View; - import org.openintents.openpgp.util.OpenPgpApi; import org.sufficientlysecure.htmltextview.HtmlTextView; import org.sufficientlysecure.keychain.Constants; diff --git a/tools/checkstyle.xml b/tools/checkstyle.xml index 95ef07a90..26a3f8c02 100644 --- a/tools/checkstyle.xml +++ b/tools/checkstyle.xml @@ -9,9 +9,9 @@ page at http://checkstyle.sourceforge.net/config.html --> - + + + + + \ No newline at end of file diff --git a/OpenPGP-Keychain/src/main/res/layout/key_list_item.xml b/OpenPGP-Keychain/src/main/res/layout/key_list_item.xml index f52693138..3f1b25cc0 100644 --- a/OpenPGP-Keychain/src/main/res/layout/key_list_item.xml +++ b/OpenPGP-Keychain/src/main/res/layout/key_list_item.xml @@ -1,63 +1,78 @@ - - + android:layout_gravity="center_vertical" + android:layout_weight="1" + android:focusable="true" + android:orientation="vertical" + android:paddingLeft="8dp" + android:paddingRight="4dp" + android:paddingTop="4dp" + android:paddingBottom="4dp"> - + -