diff options
6 files changed, 61 insertions, 97 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java index 4fbdfab76..c4c31bdad 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java @@ -348,6 +348,7 @@ public class KeychainIntentService extends IntentService providerHelper.saveSecretKeyRing(ring, new ProgressScaler(this, 10, 95, 100)); + // cache new passphrase if (saveParcel.newPassphrase != null) { PassphraseCacheService.addCachedPassphrase(this, ring.getMasterKeyId(), saveParcel.newPassphrase); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyFragment.java index 1defa4034..b00049ac7 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyFragment.java @@ -65,7 +65,7 @@ public class EditKeyFragment extends LoaderFragment implements public static final String ARG_DATA_URI = "uri"; private ListView mUserIdsList; - private ListView mKeysList; + private ListView mSubkeysList; private ListView mUserIdsAddedList; private ListView mKeysAddedList; private View mChangePassphrase; @@ -73,10 +73,10 @@ public class EditKeyFragment extends LoaderFragment implements private View mAddKey; private static final int LOADER_ID_USER_IDS = 0; - private static final int LOADER_ID_KEYS = 1; + private static final int LOADER_ID_SUBKEYS = 1; private UserIdsAdapter mUserIdsAdapter; - private SubkeysAdapter mKeysAdapter; + private SubkeysAdapter mSubkeysAdapter; private UserIdsAddedAdapter mUserIdsAddedAdapter; private ArrayList<UserIdsAddedAdapter.UserIdModel> mUserIdsAddedData; @@ -104,7 +104,7 @@ public class EditKeyFragment extends LoaderFragment implements View view = inflater.inflate(R.layout.edit_key_fragment, getContainer()); mUserIdsList = (ListView) view.findViewById(R.id.edit_key_user_ids); - mKeysList = (ListView) view.findViewById(R.id.edit_key_keys); + mSubkeysList = (ListView) view.findViewById(R.id.edit_key_keys); mUserIdsAddedList = (ListView) view.findViewById(R.id.edit_key_user_ids_added); mKeysAddedList = (ListView) view.findViewById(R.id.edit_key_keys_added); mChangePassphrase = view.findViewById(R.id.edit_key_action_change_passphrase); @@ -191,18 +191,18 @@ public class EditKeyFragment extends LoaderFragment implements } }); - // TODO: from savedInstance?! + // TODO: mUserIdsAddedData and SaveParcel from savedInstance?! mUserIdsAddedData = new ArrayList<UserIdsAddedAdapter.UserIdModel>(); mUserIdsAddedAdapter = new UserIdsAddedAdapter(getActivity(), mUserIdsAddedData); mUserIdsAddedList.setAdapter(mUserIdsAddedAdapter); - mKeysAdapter = new SubkeysAdapter(getActivity(), null, 0); - mKeysList.setAdapter(mKeysAdapter); + mSubkeysAdapter = new SubkeysAdapter(getActivity(), null, 0); + mSubkeysList.setAdapter(mSubkeysAdapter); // Prepare the loaders. Either re-connect with an existing ones, // or start new ones. getLoaderManager().initLoader(LOADER_ID_USER_IDS, null, this); - getLoaderManager().initLoader(LOADER_ID_KEYS, null, this); + getLoaderManager().initLoader(LOADER_ID_SUBKEYS, null, this); } public Loader<Cursor> onCreateLoader(int id, Bundle args) { @@ -215,10 +215,10 @@ public class EditKeyFragment extends LoaderFragment implements UserIdsAdapter.USER_IDS_PROJECTION, null, null, null); } - case LOADER_ID_KEYS: { + case LOADER_ID_SUBKEYS: { Uri baseUri = KeychainContract.Keys.buildKeysUri(mDataUri); return new CursorLoader(getActivity(), baseUri, - SubkeysAdapter.KEYS_PROJECTION, null, null, null); + SubkeysAdapter.SUBKEYS_PROJECTION, null, null, null); } default: @@ -234,8 +234,8 @@ public class EditKeyFragment extends LoaderFragment implements mUserIdsAdapter.swapCursor(data); break; - case LOADER_ID_KEYS: - mKeysAdapter.swapCursor(data); + case LOADER_ID_SUBKEYS: + mSubkeysAdapter.swapCursor(data); break; } @@ -251,8 +251,8 @@ public class EditKeyFragment extends LoaderFragment implements case LOADER_ID_USER_IDS: mUserIdsAdapter.swapCursor(null); break; - case LOADER_ID_KEYS: - mKeysAdapter.swapCursor(null); + case LOADER_ID_SUBKEYS: + mSubkeysAdapter.swapCursor(null); break; } } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyKeysFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyKeysFragment.java index 4be572b4e..e46637871 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyKeysFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyKeysFragment.java @@ -87,7 +87,7 @@ public class ViewKeyKeysFragment extends LoaderFragment implements setContentShown(false); Uri baseUri = Keys.buildKeysUri(mDataUri); return new CursorLoader(getActivity(), baseUri, - SubkeysAdapter.KEYS_PROJECTION, null, null, null); + SubkeysAdapter.SUBKEYS_PROJECTION, null, null, null); } public void onLoadFinished(Loader<Cursor> loader, Cursor data) { diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/SubkeysAdapter.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/SubkeysAdapter.java index 6d8455589..02b1f31e2 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/SubkeysAdapter.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/SubkeysAdapter.java @@ -38,22 +38,11 @@ import java.util.Date; public class SubkeysAdapter extends CursorAdapter { private LayoutInflater mInflater; - private int mIndexKeyId; - private int mIndexAlgorithm; - private int mIndexKeySize; - private int mIndexRank; - private int mIndexCanCertify; - private int mIndexCanEncrypt; - private int mIndexCanSign; - private int mIndexHasSecret; - private int mIndexRevokedKey; - private int mIndexExpiry; - private boolean hasAnySecret; private ColorStateList mDefaultTextColor; - public static final String[] KEYS_PROJECTION = new String[] { + public static final String[] SUBKEYS_PROJECTION = new String[]{ Keys._ID, Keys.KEY_ID, Keys.RANK, @@ -68,24 +57,32 @@ public class SubkeysAdapter extends CursorAdapter { Keys.EXPIRY, Keys.FINGERPRINT }; + private static final int INDEX_ID = 0; + private static final int INDEX_KEY_ID = 1; + private static final int INDEX_RANK = 2; + private static final int INDEX_ALGORITHM = 3; + private static final int INDEX_KEY_SIZE = 4; + private static final int INDEX_HAS_SECRET = 5; + private static final int INDEX_CAN_CERTIFY = 6; + private static final int INDEX_CAN_ENCRYPT = 7; + private static final int INDEX_CAN_SIGN = 8; + private static final int INDEX_IS_REVOKED = 9; + private static final int INDEX_CREATION = 10; + private static final int INDEX_EXPIRY = 11; + private static final int INDEX_FINGERPRINT = 12; public SubkeysAdapter(Context context, Cursor c, int flags) { super(context, c, flags); mInflater = LayoutInflater.from(context); - - initIndex(c); } @Override public Cursor swapCursor(Cursor newCursor) { - initIndex(newCursor); - hasAnySecret = false; - if (newCursor != null) { - newCursor.moveToFirst(); + if (newCursor != null && newCursor.moveToFirst()) { do { - if (newCursor.getInt(mIndexHasSecret) != 0) { + if (newCursor.getInt(INDEX_HAS_SECRET) != 0) { hasAnySecret = true; break; } @@ -95,27 +92,6 @@ public class SubkeysAdapter extends CursorAdapter { 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) { - mIndexKeyId = cursor.getColumnIndexOrThrow(Keys.KEY_ID); - mIndexAlgorithm = cursor.getColumnIndexOrThrow(Keys.ALGORITHM); - mIndexKeySize = cursor.getColumnIndexOrThrow(Keys.KEY_SIZE); - mIndexRank = cursor.getColumnIndexOrThrow(Keys.RANK); - mIndexCanCertify = cursor.getColumnIndexOrThrow(Keys.CAN_CERTIFY); - mIndexCanEncrypt = cursor.getColumnIndexOrThrow(Keys.CAN_ENCRYPT); - mIndexCanSign = cursor.getColumnIndexOrThrow(Keys.CAN_SIGN); - mIndexHasSecret = cursor.getColumnIndexOrThrow(Keys.HAS_SECRET); - mIndexRevokedKey = cursor.getColumnIndexOrThrow(Keys.IS_REVOKED); - mIndexExpiry = cursor.getColumnIndexOrThrow(Keys.EXPIRY); - } - } - @Override public void bindView(View view, Context context, Cursor cursor) { TextView keyId = (TextView) view.findViewById(R.id.keyId); @@ -127,16 +103,16 @@ public class SubkeysAdapter extends CursorAdapter { ImageView signIcon = (ImageView) view.findViewById(R.id.ic_signKey); ImageView revokedKeyIcon = (ImageView) view.findViewById(R.id.ic_revokedKey); - String keyIdStr = PgpKeyHelper.convertKeyIdToHex(cursor.getLong(mIndexKeyId)); + String keyIdStr = PgpKeyHelper.convertKeyIdToHex(cursor.getLong(INDEX_KEY_ID)); String algorithmStr = PgpKeyHelper.getAlgorithmInfo( context, - cursor.getInt(mIndexAlgorithm), - cursor.getInt(mIndexKeySize) + cursor.getInt(INDEX_ALGORITHM), + cursor.getInt(INDEX_KEY_SIZE) ); keyId.setText(keyIdStr); // may be set with additional "stripped" later on - if (hasAnySecret && cursor.getInt(mIndexHasSecret) == 0) { + if (hasAnySecret && cursor.getInt(INDEX_HAS_SECRET) == 0) { keyDetails.setText(algorithmStr + ", " + context.getString(R.string.key_stripped)); } else { @@ -144,13 +120,13 @@ public class SubkeysAdapter extends CursorAdapter { } // Set icons according to properties - masterKeyIcon.setVisibility(cursor.getInt(mIndexRank) == 0 ? View.VISIBLE : View.INVISIBLE); - certifyIcon.setVisibility(cursor.getInt(mIndexCanCertify) != 0 ? View.VISIBLE : View.GONE); - encryptIcon.setVisibility(cursor.getInt(mIndexCanEncrypt) != 0 ? View.VISIBLE : View.GONE); - signIcon.setVisibility(cursor.getInt(mIndexCanSign) != 0 ? View.VISIBLE : View.GONE); + masterKeyIcon.setVisibility(cursor.getInt(INDEX_RANK) == 0 ? View.VISIBLE : View.INVISIBLE); + certifyIcon.setVisibility(cursor.getInt(INDEX_CAN_CERTIFY) != 0 ? View.VISIBLE : View.GONE); + encryptIcon.setVisibility(cursor.getInt(INDEX_CAN_ENCRYPT) != 0 ? View.VISIBLE : View.GONE); + signIcon.setVisibility(cursor.getInt(INDEX_CAN_SIGN) != 0 ? View.VISIBLE : View.GONE); boolean valid = true; - if (cursor.getInt(mIndexRevokedKey) > 0) { + if (cursor.getInt(INDEX_IS_REVOKED) > 0) { revokedKeyIcon.setVisibility(View.VISIBLE); valid = false; @@ -162,17 +138,19 @@ public class SubkeysAdapter extends CursorAdapter { revokedKeyIcon.setVisibility(View.GONE); } - if (!cursor.isNull(mIndexExpiry)) { - Date expiryDate = new Date(cursor.getLong(mIndexExpiry) * 1000); + if (!cursor.isNull(INDEX_EXPIRY)) { + Date expiryDate = new Date(cursor.getLong(INDEX_EXPIRY) * 1000); valid = valid && expiryDate.after(new Date()); keyExpiry.setText( context.getString(R.string.label_expiry) + ": " + - DateFormat.getDateFormat(context).format(expiryDate)); + DateFormat.getDateFormat(context).format(expiryDate) + ); } else { keyExpiry.setText( context.getString(R.string.label_expiry) + ": " + - context.getString(R.string.none)); + context.getString(R.string.none) + ); } // if key is expired or revoked, strike through text diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/UserIdsAdapter.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/UserIdsAdapter.java index 7bf9334b8..47f17357a 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/UserIdsAdapter.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/UserIdsAdapter.java @@ -41,9 +41,6 @@ import java.util.ArrayList; public class UserIdsAdapter extends CursorAdapter implements AdapterView.OnItemClickListener { private LayoutInflater mInflater; - private int mIndexUserId, mIndexRank; - private int mVerifiedId, mIsRevoked, mIsPrimary; - private final ArrayList<Boolean> mCheckStates; private SaveKeyringParcel mSaveKeyringParcel; @@ -56,6 +53,13 @@ public class UserIdsAdapter extends CursorAdapter implements AdapterView.OnItemC UserIds.IS_PRIMARY, UserIds.IS_REVOKED }; + private static final int INDEX_ID = 0; + private static final int INDEX_USER_ID = 1; + private static final int INDEX_RANK = 2; + private static final int INDEX_VERIFIED = 3; + private static final int INDEX_IS_PRIMARY = 4; + private static final int INDEX_IS_REVOKED = 5; + public UserIdsAdapter(Context context, Cursor c, int flags, boolean showCheckBoxes, SaveKeyringParcel saveKeyringParcel) { @@ -64,8 +68,6 @@ public class UserIdsAdapter extends CursorAdapter implements AdapterView.OnItemC mCheckStates = showCheckBoxes ? new ArrayList<Boolean>() : null; mSaveKeyringParcel = saveKeyringParcel; - - initIndex(c); } public UserIdsAdapter(Context context, Cursor c, int flags, boolean showCheckBoxes) { @@ -82,7 +84,6 @@ public class UserIdsAdapter extends CursorAdapter implements AdapterView.OnItemC @Override public Cursor swapCursor(Cursor newCursor) { - initIndex(newCursor); if (mCheckStates != null) { mCheckStates.clear(); if (newCursor != null) { @@ -91,7 +92,7 @@ public class UserIdsAdapter extends CursorAdapter implements AdapterView.OnItemC // initialize to true (use case knowledge: we usually want to sign all uids) for (int i = 0; i < count; i++) { newCursor.moveToPosition(i); - int verified = newCursor.getInt(mVerifiedId); + int verified = newCursor.getInt(INDEX_VERIFIED); mCheckStates.add(verified != Certs.VERIFIED_SECRET); } } @@ -100,22 +101,6 @@ public class UserIdsAdapter extends CursorAdapter implements AdapterView.OnItemC 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(UserIds.USER_ID); - mIndexRank = cursor.getColumnIndexOrThrow(UserIds.RANK); - mVerifiedId = cursor.getColumnIndexOrThrow(UserIds.VERIFIED); - mIsRevoked = cursor.getColumnIndexOrThrow(UserIds.IS_REVOKED); - mIsPrimary = cursor.getColumnIndexOrThrow(UserIds.IS_PRIMARY); - } - } - @Override public void bindView(View view, Context context, Cursor cursor) { TextView vName = (TextView) view.findViewById(R.id.userId); @@ -125,7 +110,7 @@ public class UserIdsAdapter extends CursorAdapter implements AdapterView.OnItemC ImageView vHasChanges = (ImageView) view.findViewById(R.id.has_changes); ImageView vEditImage = (ImageView) view.findViewById(R.id.edit_image); - String userId = cursor.getString(mIndexUserId); + String userId = cursor.getString(INDEX_USER_ID); String[] splitUserId = KeyRing.splitUserId(userId); if (splitUserId[0] != null) { vName.setText(splitUserId[0]); @@ -145,8 +130,8 @@ public class UserIdsAdapter extends CursorAdapter implements AdapterView.OnItemC vComment.setVisibility(View.GONE); } - boolean isPrimary = cursor.getInt(mIsPrimary) != 0; - boolean isRevoked = cursor.getInt(mIsRevoked) > 0; + boolean isPrimary = cursor.getInt(INDEX_IS_PRIMARY) != 0; + boolean isRevoked = cursor.getInt(INDEX_IS_REVOKED) > 0; // for edit key if (mSaveKeyringParcel != null) { @@ -189,7 +174,7 @@ public class UserIdsAdapter extends CursorAdapter implements AdapterView.OnItemC // verified: has been verified // isPrimary: show small star icon for primary user ids - int verified = cursor.getInt(mVerifiedId); + int verified = cursor.getInt(INDEX_VERIFIED); switch (verified) { case Certs.VERIFIED_SECRET: vVerified.setImageResource(isPrimary @@ -237,7 +222,7 @@ public class UserIdsAdapter extends CursorAdapter implements AdapterView.OnItemC for (int i = 0; i < mCheckStates.size(); i++) { if (mCheckStates.get(i)) { mCursor.moveToPosition(i); - result.add(mCursor.getString(mIndexUserId)); + result.add(mCursor.getString(INDEX_USER_ID)); } } return result; @@ -245,7 +230,7 @@ public class UserIdsAdapter extends CursorAdapter implements AdapterView.OnItemC public String getUserId(int position) { mCursor.moveToPosition(position); - return mCursor.getString(mIndexUserId); + return mCursor.getString(INDEX_USER_ID); } @Override diff --git a/extern/spongycastle b/extern/spongycastle -Subproject 968405ee5d4272330cffdf75f7eee4cd9f5c864 +Subproject 09d85b7d7a64b3003210d065c4210ff7fb7a8c6 |