diff options
Diffstat (limited to 'OpenPGP-Keychain/src/main/java/org')
12 files changed, 132 insertions, 106 deletions
| diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/compatibility/DialogFragmentWorkaround.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/compatibility/DialogFragmentWorkaround.java index a209f16cf..36f7fd23b 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/compatibility/DialogFragmentWorkaround.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/compatibility/DialogFragmentWorkaround.java @@ -37,8 +37,9 @@ import android.os.Handler;   * </code>   */  public class DialogFragmentWorkaround { -    public static final SDKLevel17Interface INTERFACE = ((Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) ? new SDKLevel17Impl() -            : new SDKLevelPriorLevel17Impl()); +    public static final SDKLevel17Interface INTERFACE = +                ((Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) ? new SDKLevel17Impl() +                 : new SDKLevelPriorLevel17Impl());      private static final int RUNNABLE_DELAY = 300; diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpDecryptVerify.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpDecryptVerify.java index d4ce3d352..571729bc5 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpDecryptVerify.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpDecryptVerify.java @@ -288,9 +288,11 @@ public class PgpDecryptVerify {                          // if no passphrase was explicitly set try to get it from the cache service                          if (mPassphrase == null) {                              // returns "" if key has no passphrase -                            mPassphrase = PassphraseCacheService.getCachedPassphrase(mContext, encData.getKeyID()); +                            mPassphrase = +                                    PassphraseCacheService.getCachedPassphrase(mContext, encData.getKeyID()); -                            // if passphrase was not cached, return here indicating that a passphrase is missing! +                            // if passphrase was not cached, return here +                            // indicating that a passphrase is missing!                              if (mPassphrase == null) {                                  returnData.setKeyPassphraseNeeded(true);                                  return returnData; @@ -384,7 +386,8 @@ public class PgpDecryptVerify {              signatureResult.setKeyId(signatureKeyId);              if (signature != null) { -                JcaPGPContentVerifierBuilderProvider contentVerifierBuilderProvider = new JcaPGPContentVerifierBuilderProvider() +                JcaPGPContentVerifierBuilderProvider contentVerifierBuilderProvider = +                        new JcaPGPContentVerifierBuilderProvider()                          .setProvider(Constants.BOUNCY_CASTLE_PROVIDER_NAME);                  signature.init(contentVerifierBuilderProvider, signatureKey); @@ -613,7 +616,8 @@ public class PgpDecryptVerify {          return returnData;      } -    private static boolean verifyKeyBinding(Context context, PGPSignature signature, PGPPublicKey signatureKey) { +    private static boolean verifyKeyBinding(Context context, +                                            PGPSignature signature, PGPPublicKey signatureKey) {          long signatureKeyId = signature.getKeyID();          boolean validKeyBinding = false; @@ -648,7 +652,8 @@ public class PgpDecryptVerify {              //about keys without subkey signing. Can't get it to import a slightly broken one              //either, so we will err on bad subkey binding here.              PGPSignature sig = itr.next(); -            if (sig.getKeyID() == masterPublicKey.getKeyID() && sig.getSignatureType() == PGPSignature.SUBKEY_BINDING) { +            if (sig.getKeyID() == masterPublicKey.getKeyID() && +                    sig.getSignatureType() == PGPSignature.SUBKEY_BINDING) {                  //check and if ok, check primary key binding.                  try {                      sig.init(contentVerifierBuilderProvider, masterPublicKey); @@ -680,7 +685,7 @@ public class PgpDecryptVerify {      }      private static boolean verifyPrimaryKeyBinding(PGPSignatureSubpacketVector pkts, -                                                   PGPPublicKey masterPublicKey, PGPPublicKey signingPublicKey) { +                          PGPPublicKey masterPublicKey, PGPPublicKey signingPublicKey) {          boolean validPrimaryKeyBinding = false;          JcaPGPContentVerifierBuilderProvider contentVerifierBuilderProvider =                  new JcaPGPContentVerifierBuilderProvider() 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 4a97eb825..dbfa521e5 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 @@ -52,7 +52,8 @@ public class PgpImportExport {          this.mProgress = progress;      } -    public PgpImportExport(Context context, ProgressDialogUpdater progress, KeychainServiceListener keychainListener) { +    public PgpImportExport(Context context, +                           ProgressDialogUpdater progress, KeychainServiceListener keychainListener) {          super();          this.mContext = context;          this.mProgress = progress; @@ -252,8 +253,9 @@ public class PgpImportExport {                          }                          newPubRing = PGPPublicKeyRing.insertPublicKey(newPubRing, key);                      } -                    if (newPubRing != null) +                    if (newPubRing != null) {                          ProviderHelper.saveKeyRing(mContext, newPubRing); +                    }                      // TODO: remove status returns, use exceptions!                      status = Id.return_value.ok;                  } diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java index 84d772846..c7ec02d7d 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java @@ -287,7 +287,8 @@ public class PgpKeyOperation {              long numDays =                      (expiryDate.getTimeInMillis() / 86400000) - (creationDate.getTimeInMillis() / 86400000);              if (numDays <= 0) { -                throw new PgpGeneralException(mContext.getString(R.string.error_expiry_must_come_after_creation)); +                throw new PgpGeneralException( +                        mContext.getString(R.string.error_expiry_must_come_after_creation));              }              hashedPacketsGen.setKeyExpirationTime(false, numDays * 86400);          } else { @@ -336,8 +337,10 @@ public class PgpKeyOperation {              keyFlags = 0;              usageId = keysUsages.get(i); -            canSign = (usageId == Id.choice.usage.sign_only || usageId == Id.choice.usage.sign_and_encrypt); -            canEncrypt = (usageId == Id.choice.usage.encrypt_only || usageId == Id.choice.usage.sign_and_encrypt); +            canSign = +                    (usageId == Id.choice.usage.sign_only || usageId == Id.choice.usage.sign_and_encrypt); +            canEncrypt = +                    (usageId == Id.choice.usage.encrypt_only || usageId == Id.choice.usage.sign_and_encrypt);              if (canSign) {                  Date todayDate = new Date(); //both sig times the same                  keyFlags |= KeyFlags.SIGN_DATA; diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpToX509.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpToX509.java index 309f1dc15..54601173d 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpToX509.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpToX509.java @@ -258,10 +258,10 @@ public class PgpToX509 {       *       * @author Bruno Harbulot.       */ -    public final static class PredefinedPasswordCallbackHandler implements CallbackHandler { +    public static final class PredefinedPasswordCallbackHandler implements CallbackHandler { -        private char[] password; -        private String prompt; +        private char[] mPassword; +        private String mPrompt;          public PredefinedPasswordCallbackHandler(String password) {              this(password == null ? null : password.toCharArray(), null); @@ -276,16 +276,16 @@ public class PgpToX509 {          }          public PredefinedPasswordCallbackHandler(char[] password, String prompt) { -            this.password = password; -            this.prompt = prompt; +            this.mPassword = password; +            this.mPrompt = prompt;          }          public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {              for (Callback callback : callbacks) {                  if (callback instanceof PasswordCallback) {                      PasswordCallback pwCallback = (PasswordCallback) callback; -                    if ((this.prompt == null) || (this.prompt.equals(pwCallback.getPrompt()))) { -                        pwCallback.setPassword(this.password); +                    if ((this.mPrompt == null) || (this.mPrompt.equals(pwCallback.getPrompt()))) { +                        pwCallback.setPassword(this.mPassword);                      }                  } else {                      throw new UnsupportedCallbackException(callback, "Unrecognised callback."); 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 d9356951e..5f2354c24 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 @@ -17,10 +17,9 @@  package org.sufficientlysecure.keychain.provider; -import org.sufficientlysecure.keychain.Constants; -  import android.net.Uri;  import android.provider.BaseColumns; +import org.sufficientlysecure.keychain.Constants;  public class KeychainContract { @@ -94,10 +93,14 @@ public class KeychainContract {          public static final Uri CONTENT_URI = BASE_CONTENT_URI_INTERNAL.buildUpon()                  .appendPath(BASE_KEY_RINGS).build(); -        /** Use if multiple items get returned */ +        /** +         * Use if multiple items get returned +         */          public static final String CONTENT_TYPE = "vnd.android.cursor.dir/vnd.thialfihar.apg.key_ring"; -        /** Use if a single item is returned */ +        /** +         * Use if a single item is returned +         */          public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/vnd.thialfihar.apg.key_ring";          public static Uri buildUnifiedKeyRingsUri() { @@ -165,10 +168,14 @@ public class KeychainContract {          public static final Uri CONTENT_URI = BASE_CONTENT_URI_INTERNAL.buildUpon()                  .appendPath(BASE_KEY_RINGS).build(); -        /** Use if multiple items get returned */ +        /** +         * Use if multiple items get returned +         */          public static final String CONTENT_TYPE = "vnd.android.cursor.dir/vnd.thialfihar.apg.key"; -        /** Use if a single item is returned */ +        /** +         * Use if a single item is returned +         */          public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/vnd.thialfihar.apg.key";          public static Uri buildPublicKeysUri(String keyRingRowId) { @@ -204,10 +211,14 @@ public class KeychainContract {          public static final Uri CONTENT_URI = BASE_CONTENT_URI_INTERNAL.buildUpon()                  .appendPath(BASE_KEY_RINGS).build(); -        /** Use if multiple items get returned */ +        /** +         * Use if multiple items get returned +         */          public static final String CONTENT_TYPE = "vnd.android.cursor.dir/vnd.thialfihar.apg.user_id"; -        /** Use if a single item is returned */ +        /** +         * Use if a single item is returned +         */          public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/vnd.thialfihar.apg.user_id";          public static Uri buildPublicUserIdsUri(String keyRingRowId) { @@ -243,10 +254,14 @@ public class KeychainContract {          public static final Uri CONTENT_URI = BASE_CONTENT_URI_INTERNAL.buildUpon()                  .appendPath(BASE_API_APPS).build(); -        /** Use if multiple items get returned */ +        /** +         * Use if multiple items get returned +         */          public static final String CONTENT_TYPE = "vnd.android.cursor.dir/vnd.thialfihar.apg.api_apps"; -        /** Use if a single item is returned */ +        /** +         * Use if a single item is returned +         */          public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/vnd.thialfihar.apg.api_apps";          public static Uri buildIdUri(String rowId) { diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainDatabase.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainDatabase.java index 5f18ed6f9..031a7d5ae 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainDatabase.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainDatabase.java @@ -17,6 +17,10 @@  package org.sufficientlysecure.keychain.provider; +import android.content.Context; +import android.database.sqlite.SQLiteDatabase; +import android.database.sqlite.SQLiteOpenHelper; +import android.provider.BaseColumns;  import org.sufficientlysecure.keychain.Constants;  import org.sufficientlysecure.keychain.provider.KeychainContract.ApiAppsColumns;  import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRingsColumns; @@ -24,11 +28,6 @@ import org.sufficientlysecure.keychain.provider.KeychainContract.KeysColumns;  import org.sufficientlysecure.keychain.provider.KeychainContract.UserIdsColumns;  import org.sufficientlysecure.keychain.util.Log; -import android.content.Context; -import android.database.sqlite.SQLiteDatabase; -import android.database.sqlite.SQLiteOpenHelper; -import android.provider.BaseColumns; -  public class KeychainDatabase extends SQLiteOpenHelper {      private static final String DATABASE_NAME = "apg.db";      private static final int DATABASE_VERSION = 7; 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 fdc4b7bda..748aaeb1b 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 @@ -17,21 +17,6 @@  package org.sufficientlysecure.keychain.provider; -import java.util.Arrays; -import java.util.HashMap; - -import org.sufficientlysecure.keychain.Constants; -import org.sufficientlysecure.keychain.provider.KeychainContract.ApiApps; -import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; -import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRingsColumns; -import org.sufficientlysecure.keychain.provider.KeychainContract.KeyTypes; -import org.sufficientlysecure.keychain.provider.KeychainContract.Keys; -import org.sufficientlysecure.keychain.provider.KeychainContract.KeysColumns; -import org.sufficientlysecure.keychain.provider.KeychainContract.UserIds; -import org.sufficientlysecure.keychain.provider.KeychainContract.UserIdsColumns; -import org.sufficientlysecure.keychain.provider.KeychainDatabase.Tables; -import org.sufficientlysecure.keychain.util.Log; -  import android.content.ContentProvider;  import android.content.ContentValues;  import android.content.UriMatcher; @@ -43,6 +28,13 @@ import android.database.sqlite.SQLiteQueryBuilder;  import android.net.Uri;  import android.provider.BaseColumns;  import android.text.TextUtils; +import org.sufficientlysecure.keychain.Constants; +import org.sufficientlysecure.keychain.provider.KeychainContract.*; +import org.sufficientlysecure.keychain.provider.KeychainDatabase.Tables; +import org.sufficientlysecure.keychain.util.Log; + +import java.util.Arrays; +import java.util.HashMap;  public class KeychainProvider extends ContentProvider {      // public static final String ACTION_BROADCAST_DATABASE_CHANGE = Constants.PACKAGE_NAME @@ -367,7 +359,8 @@ public class KeychainProvider extends ContentProvider {          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); +        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); @@ -483,7 +476,8 @@ public class KeychainProvider extends ContentProvider {                  groupBy = Tables.KEY_RINGS + "." + KeyRingsColumns.MASTER_KEY_ID;                  if (TextUtils.isEmpty(sortOrder)) { -                    sortOrder = KeyRings.TYPE + " DESC, " + Tables.USER_IDS + "." + UserIdsColumns.USER_ID + " ASC"; +                    sortOrder = KeyRings.TYPE + " DESC, " + +                            Tables.USER_IDS + "." + UserIdsColumns.USER_ID + " ASC";                  }                  break; diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainServiceBlobContract.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainServiceBlobContract.java index a879d60a8..701ffc6af 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainServiceBlobContract.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainServiceBlobContract.java @@ -17,10 +17,9 @@  package org.sufficientlysecure.keychain.provider; -import org.sufficientlysecure.keychain.Constants; -  import android.net.Uri;  import android.provider.BaseColumns; +import org.sufficientlysecure.keychain.Constants;  public class KeychainServiceBlobContract { diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainServiceBlobDatabase.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainServiceBlobDatabase.java index fcee76fd7..da1bcb2d9 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainServiceBlobDatabase.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainServiceBlobDatabase.java @@ -22,7 +22,6 @@ import android.content.Context;  import android.database.sqlite.SQLiteDatabase;  import android.database.sqlite.SQLiteOpenHelper;  import android.provider.BaseColumns; -  import org.sufficientlysecure.keychain.provider.KeychainServiceBlobContract.BlobsColumns;  public class KeychainServiceBlobDatabase extends SQLiteOpenHelper { diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainServiceBlobProvider.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainServiceBlobProvider.java index 86eccbe37..6ac61e157 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainServiceBlobProvider.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainServiceBlobProvider.java @@ -18,11 +18,6 @@  package org.sufficientlysecure.keychain.provider; -import org.sufficientlysecure.keychain.Constants; -import org.sufficientlysecure.keychain.provider.KeychainServiceBlobContract.Blobs; -import org.sufficientlysecure.keychain.provider.KeychainServiceBlobContract.BlobsColumns; -import org.sufficientlysecure.keychain.util.Log; -  import android.content.ContentProvider;  import android.content.ContentUris;  import android.content.ContentValues; @@ -31,7 +26,10 @@ import android.database.sqlite.SQLiteDatabase;  import android.net.Uri;  import android.os.ParcelFileDescriptor;  import android.provider.BaseColumns; - +import org.sufficientlysecure.keychain.Constants; +import org.sufficientlysecure.keychain.provider.KeychainServiceBlobContract.Blobs; +import org.sufficientlysecure.keychain.provider.KeychainServiceBlobContract.BlobsColumns; +import org.sufficientlysecure.keychain.util.Log;  import java.io.File;  import java.io.FileNotFoundException; @@ -55,7 +53,9 @@ public class KeychainServiceBlobProvider extends ContentProvider {          return true;      } -    /** {@inheritDoc} */ +    /** +     * {@inheritDoc} +     */      @Override      public Uri insert(Uri uri, ContentValues ignored) {          // ContentValues are actually ignored, because we want to store a blob with no more @@ -74,7 +74,9 @@ public class KeychainServiceBlobProvider extends ContentProvider {          return Uri.withAppendedPath(insertedUri, password);      } -    /** {@inheritDoc} */ +    /** +     * {@inheritDoc} +     */      @Override      public ParcelFileDescriptor openFile(Uri uri, String mode) throws SecurityException,              FileNotFoundException { @@ -91,9 +93,9 @@ public class KeychainServiceBlobProvider extends ContentProvider {          // get the data          SQLiteDatabase db = mBlobDatabase.getReadableDatabase(); -        Cursor result = db.query(KeychainServiceBlobDatabase.TABLE, new String[] { BaseColumns._ID }, +        Cursor result = db.query(KeychainServiceBlobDatabase.TABLE, new String[]{BaseColumns._ID},                  BaseColumns._ID + " = ? and " + BlobsColumns.KEY + " = ?", -                new String[] { id, key }, null, null, null); +                new String[]{id, key}, null, null, null);          if (result.getCount() == 0) {              // either the key is wrong or no id exists @@ -124,26 +126,34 @@ public class KeychainServiceBlobProvider extends ContentProvider {          return null;      } -    /** {@inheritDoc} */ +    /** +     * {@inheritDoc} +     */      @Override      public String getType(Uri uri) {          return null;      } -    /** {@inheritDoc} */ +    /** +     * {@inheritDoc} +     */      @Override      public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, -            String sortOrder) { +                        String sortOrder) {          return null;      } -    /** {@inheritDoc} */ +    /** +     * {@inheritDoc} +     */      @Override      public int delete(Uri uri, String selection, String[] selectionArgs) {          return 0;      } -    /** {@inheritDoc} */ +    /** +     * {@inheritDoc} +     */      @Override      public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {          return 0; diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/provider/ProviderHelper.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/provider/ProviderHelper.java index 1c05344d6..db2c57207 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/provider/ProviderHelper.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/provider/ProviderHelper.java @@ -17,18 +17,13 @@  package org.sufficientlysecure.keychain.provider; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Date; - +import android.content.*; +import android.database.Cursor; +import android.database.DatabaseUtils; +import android.net.Uri; +import android.os.RemoteException;  import org.spongycastle.bcpg.ArmoredOutputStream; -import org.spongycastle.openpgp.PGPKeyRing; -import org.spongycastle.openpgp.PGPPublicKey; -import org.spongycastle.openpgp.PGPPublicKeyRing; -import org.spongycastle.openpgp.PGPSecretKey; -import org.spongycastle.openpgp.PGPSecretKeyRing; -import org.spongycastle.openpgp.PGPSignature; +import org.spongycastle.openpgp.*;  import org.sufficientlysecure.keychain.Constants;  import org.sufficientlysecure.keychain.pgp.PgpConversionHelper;  import org.sufficientlysecure.keychain.pgp.PgpHelper; @@ -42,15 +37,10 @@ import org.sufficientlysecure.keychain.service.remote.AppSettings;  import org.sufficientlysecure.keychain.util.IterableIterator;  import org.sufficientlysecure.keychain.util.Log; -import android.content.ContentProviderOperation; -import android.content.ContentResolver; -import android.content.ContentValues; -import android.content.Context; -import android.content.OperationApplicationException; -import android.database.Cursor; -import android.database.DatabaseUtils; -import android.net.Uri; -import android.os.RemoteException; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Date;  public class ProviderHelper { @@ -111,7 +101,7 @@ public class ProviderHelper {      public static PGPPublicKey getPGPPublicKeyByKeyId(Context context, long keyId) {          PGPPublicKeyRing keyRing = getPGPPublicKeyRingByKeyId(context, keyId); -        return (keyRing == null)? null : keyRing.getPublicKey(keyId); +        return (keyRing == null) ? null : keyRing.getPublicKey(keyId);      }      /** @@ -162,7 +152,8 @@ public class ProviderHelper {          // get current _ID of key          long currentRowId = -1; -        Cursor oldQuery = context.getContentResolver().query(deleteUri, new String[]{KeyRings._ID}, null, null, null); +        Cursor oldQuery = context.getContentResolver() +                .query(deleteUri, new String[]{KeyRings._ID}, null, null, null);          if (oldQuery != null && oldQuery.moveToFirst()) {              currentRowId = oldQuery.getLong(0);          } else { @@ -178,10 +169,12 @@ public class ProviderHelper {          ContentValues values = new ContentValues();          // use exactly the same _ID again to replace key in-place. -        // NOTE: If we would not use the same _ID again, getting back to the ViewKeyActivity would result in Nullpointer, +        // NOTE: If we would not use the same _ID again, +        // getting back to the ViewKeyActivity would result in Nullpointer,          // because the currently loaded key would be gone from the database -        if (currentRowId != -1) +        if (currentRowId != -1) {              values.put(KeyRings._ID, currentRowId); +        }          values.put(KeyRings.MASTER_KEY_ID, masterKeyId);          values.put(KeyRings.KEY_RING_DATA, keyRing.getEncoded()); @@ -205,8 +198,11 @@ public class ProviderHelper {              ++userIdRank;          } -        for (PGPSignature certification : new IterableIterator<PGPSignature>(masterKey.getSignaturesOfType(PGPSignature.POSITIVE_CERTIFICATION))) { -            //TODO: how to do this?? we need to verify the signatures again and again when they are displayed... +        for (PGPSignature certification : +                new IterableIterator<PGPSignature>( +                        masterKey.getSignaturesOfType(PGPSignature.POSITIVE_CERTIFICATION))) { +            // TODO: how to do this?? +            // we need to verify the signatures again and again when they are displayed...  //            if (certification.verify  //            operations.add(buildPublicKeyOperations(context, keyRingRowId, key, rank));          } @@ -233,7 +229,8 @@ public class ProviderHelper {          // get current _ID of key          long currentRowId = -1; -        Cursor oldQuery = context.getContentResolver().query(deleteUri, new String[]{KeyRings._ID}, null, null, null); +        Cursor oldQuery = context.getContentResolver() +                    .query(deleteUri, new String[]{KeyRings._ID}, null, null, null);          if (oldQuery != null && oldQuery.moveToFirst()) {              currentRowId = oldQuery.getLong(0);          } else { @@ -249,10 +246,12 @@ public class ProviderHelper {          ContentValues values = new ContentValues();          // use exactly the same _ID again to replace key in-place. -        // NOTE: If we would not use the same _ID again, getting back to the ViewKeyActivity would result in Nullpointer, +        // NOTE: If we would not use the same _ID again, +        // getting back to the ViewKeyActivity would result in Nullpointer,          // because the currently loaded key would be gone from the database -        if (currentRowId != -1) +        if (currentRowId != -1) {              values.put(KeyRings._ID, currentRowId); +        }          values.put(KeyRings.MASTER_KEY_ID, masterKeyId);          values.put(KeyRings.KEY_RING_DATA, keyRing.getEncoded()); @@ -289,7 +288,7 @@ public class ProviderHelper {       * Build ContentProviderOperation to add PGPPublicKey to database corresponding to a keyRing       */      private static ContentProviderOperation buildPublicKeyOperations(Context context, -                                                                     long keyRingRowId, PGPPublicKey key, int rank) throws IOException { +                        long keyRingRowId, PGPPublicKey key, int rank) throws IOException {          ContentValues values = new ContentValues();          values.put(Keys.KEY_ID, key.getKeyID());          values.put(Keys.IS_MASTER_KEY, key.isMasterKey()); @@ -317,7 +316,7 @@ public class ProviderHelper {       * Build ContentProviderOperation to add PublicUserIds to database corresponding to a keyRing       */      private static ContentProviderOperation buildPublicUserIdOperations(Context context, -                                                                        long keyRingRowId, String userId, int rank) { +                           long keyRingRowId, String userId, int rank) {          ContentValues values = new ContentValues();          values.put(UserIds.KEY_RING_ROW_ID, keyRingRowId);          values.put(UserIds.USER_ID, userId); @@ -332,7 +331,7 @@ public class ProviderHelper {       * Build ContentProviderOperation to add PGPSecretKey to database corresponding to a keyRing       */      private static ContentProviderOperation buildSecretKeyOperations(Context context, -                                                                     long keyRingRowId, PGPSecretKey key, int rank) throws IOException { +                                  long keyRingRowId, PGPSecretKey key, int rank) throws IOException {          ContentValues values = new ContentValues();          boolean hasPrivate = true; @@ -369,7 +368,7 @@ public class ProviderHelper {       * Build ContentProviderOperation to add SecretUserIds to database corresponding to a keyRing       */      private static ContentProviderOperation buildSecretUserIdOperations(Context context, -                                                                        long keyRingRowId, String userId, int rank) { +                                            long keyRingRowId, String userId, int rank) {          ContentValues values = new ContentValues();          values.put(UserIds.KEY_RING_ROW_ID, keyRingRowId);          values.put(UserIds.USER_ID, userId); @@ -413,10 +412,10 @@ public class ProviderHelper {          ArrayList<Long> rowIds = new ArrayList<Long>();          if (cursor != null) { -            int IdCol = cursor.getColumnIndex(KeyRings._ID); +            int idCol = cursor.getColumnIndex(KeyRings._ID);              if (cursor.moveToFirst()) {                  do { -                    rowIds.add(cursor.getLong(IdCol)); +                    rowIds.add(cursor.getLong(idCol));                  } while (cursor.moveToNext());              }          } @@ -496,7 +495,7 @@ public class ProviderHelper {                          + " AS sign_keys WHERE sign_keys." + Keys.KEY_RING_ROW_ID + " = "                          + KeychainDatabase.Tables.KEY_RINGS + "." + KeyRings._ID                          + " AND sign_keys." + Keys.CAN_SIGN + " = '1' AND " + Keys.IS_MASTER_KEY -                        + " = 1) AS sign",}; +                        + " = 1) AS sign", };          ContentResolver cr = context.getContentResolver();          Cursor cursor = cr.query(queryUri, projection, null, null, null); | 
