diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/CachedPublicKeyRing.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/CachedPublicKeyRing.java index ad3ebae5f..5a3770f2d 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/CachedPublicKeyRing.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/CachedPublicKeyRing.java @@ -125,9 +125,9 @@ public class CachedPublicKeyRing extends KeyRing { public boolean canCertify() throws PgpGeneralException { try { Object data = mProviderHelper.getGenericData(mUri, - KeychainContract.KeyRings.CAN_CERTIFY, - ProviderHelper.FIELD_TYPE_INTEGER); - return (Long) data > 0; + KeychainContract.KeyRings.HAS_CERTIFY, + ProviderHelper.FIELD_TYPE_NULL); + return !((Boolean) data); } catch(ProviderHelper.NotFoundException e) { throw new PgpGeneralException(e); } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/AddKeysActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/AddKeysActivity.java index e2393c722..791c44503 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/AddKeysActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/AddKeysActivity.java @@ -385,8 +385,9 @@ public class AddKeysActivity extends ActionBarActivity implements finish(); Intent certifyIntent = new Intent(AddKeysActivity.this, MultiCertifyKeyActivity.class); - certifyIntent.putExtra(ImportKeyResult.EXTRA_RESULT, result); + certifyIntent.putExtra(MultiCertifyKeyActivity.EXTRA_RESULT, result); certifyIntent.putExtra(MultiCertifyKeyActivity.EXTRA_KEY_IDS, result.getImportedMasterKeyIds()); + certifyIntent.putExtra(MultiCertifyKeyActivity.EXTRA_CERTIFY_KEY_ID, mExchangeMasterKeyId); startActivity(certifyIntent); result.createNotify(AddKeysActivity.this).show(); @@ -448,7 +449,7 @@ public class AddKeysActivity extends ActionBarActivity implements final ImportKeysListEntry keyEntry = new ImportKeysListEntry(); keyEntry.setFingerprintHex(fingerprint); - keyEntry.setBitStrength(1337); + keyEntry.setBitStrength(1337); // TODO: make optional! keyEntry.addOrigin(cloudPrefs.keyserver); ArrayList selectedEntries = new ArrayList(); selectedEntries.add(keyEntry); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/MultiCertifyKeyActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/MultiCertifyKeyActivity.java index 6b882f7ce..64853519d 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/MultiCertifyKeyActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/MultiCertifyKeyActivity.java @@ -28,7 +28,9 @@ import org.sufficientlysecure.keychain.R; */ public class MultiCertifyKeyActivity extends ActionBarActivity { + public static final String EXTRA_RESULT = "operation_result"; public static final String EXTRA_KEY_IDS = "extra_key_ids"; + public static final String EXTRA_CERTIFY_KEY_ID = "certify_key_id"; @Override public void onCreate(Bundle savedInstanceState) { diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/MultiCertifyKeyFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/MultiCertifyKeyFragment.java index 0b0fb0e04..026051715 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/MultiCertifyKeyFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/MultiCertifyKeyFragment.java @@ -45,14 +45,18 @@ import android.widget.ScrollView; import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.pgp.KeyRing; +import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException; +import org.sufficientlysecure.keychain.provider.CachedPublicKeyRing; import org.sufficientlysecure.keychain.provider.KeychainContract.UserIds; import org.sufficientlysecure.keychain.provider.KeychainDatabase.Tables; +import org.sufficientlysecure.keychain.provider.ProviderHelper; import org.sufficientlysecure.keychain.service.CertifyActionsParcel; import org.sufficientlysecure.keychain.service.CertifyActionsParcel.CertifyAction; import org.sufficientlysecure.keychain.service.KeychainIntentService; import org.sufficientlysecure.keychain.service.KeychainIntentServiceHandler; import org.sufficientlysecure.keychain.service.PassphraseCacheService; import org.sufficientlysecure.keychain.service.results.CertifyResult; +import org.sufficientlysecure.keychain.service.results.OperationResult; import org.sufficientlysecure.keychain.ui.adapter.MultiUserIdsAdapter; import org.sufficientlysecure.keychain.ui.dialog.PassphraseDialogFragment; import org.sufficientlysecure.keychain.ui.util.Notify; @@ -105,11 +109,29 @@ public class MultiCertifyKeyFragment extends LoaderFragment return; } + // preselect certify key id if given + long certifyKeyId = mActivity.getIntent().getLongExtra(MultiCertifyKeyActivity.EXTRA_CERTIFY_KEY_ID, Constants.key.none); + if (certifyKeyId != Constants.key.none) { + try { + CachedPublicKeyRing key = (new ProviderHelper(getActivity())).getCachedPublicKeyRing(certifyKeyId); + if (key.canCertify()) { + mCertifyKeySpinner.setSelectedKeyId(certifyKeyId); + } + } catch (PgpGeneralException e) { + Log.e(Constants.TAG, "certify certify check failed", e); + } + } + mUserIdsAdapter = new MultiUserIdsAdapter(mActivity, null, 0); mUserIds.setAdapter(mUserIdsAdapter); getLoaderManager().initLoader(0, null, this); + OperationResult result = mActivity.getIntent().getParcelableExtra(MultiCertifyKeyActivity.EXTRA_RESULT); + if (result != null) { + // display result from import + result.createNotify(mActivity).show(); + } } @Override @@ -189,14 +211,15 @@ public class MultiCertifyKeyFragment extends LoaderFragment return new CursorLoader(mActivity, uri, USER_IDS_PROJECTION, selection, ids, Tables.USER_IDS + "." + UserIds.MASTER_KEY_ID + " ASC" - + ", " + Tables.USER_IDS + "." + UserIds.USER_ID + " ASC"); + + ", " + Tables.USER_IDS + "." + UserIds.USER_ID + " ASC" + ); } @Override public void onLoadFinished(Loader loader, Cursor data) { - MatrixCursor matrix = new MatrixCursor(new String[] { - "_id", "user_data", "grouped" + MatrixCursor matrix = new MatrixCursor(new String[]{ + "_id", "user_data", "grouped" }); data.moveToFirst(); @@ -229,7 +252,7 @@ public class MultiCertifyKeyFragment extends LoaderFragment byte[] d = p.marshall(); p.recycle(); - matrix.addRow(new Object[] { + matrix.addRow(new Object[]{ lastMasterKeyId, d, header ? 1 : 0 }); // indicate that we have a header for this masterKeyId diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/CertifyKeySpinner.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/CertifyKeySpinner.java index 29273300a..0a1a1d75b 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/CertifyKeySpinner.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/CertifyKeySpinner.java @@ -88,7 +88,10 @@ public class CertifyKeySpinner extends KeySpinner { if (loader.getId() == LOADER_ID) { // If there is only one choice, pick it by default if (mAdapter.getCount() == 2) { - setSelection(1); + // preselect if key can certify + if (data.moveToPosition(1) && data.isNull(mIndexHasCertify)) { + setSelection(1); + } } mIndexHasCertify = data.getColumnIndex(KeychainContract.KeyRings.HAS_CERTIFY); mIndexIsRevoked = data.getColumnIndex(KeychainContract.KeyRings.IS_REVOKED); diff --git a/OpenKeychain/src/main/res/values/strings.xml b/OpenKeychain/src/main/res/values/strings.xml index 6c26ff2f9..eaac43f7e 100644 --- a/OpenKeychain/src/main/res/values/strings.xml +++ b/OpenKeychain/src/main/res/values/strings.xml @@ -50,7 +50,7 @@ "Actions" "Whole key" "Your Key used for certification" - "Upload Key" + "Synchronize Key" "Keyserver" "Fingerprint" "Key to be certified"