diff options
author | Vincent Breitmoser <valodim@mugenguild.com> | 2014-06-10 15:27:26 +0200 |
---|---|---|
committer | Vincent Breitmoser <valodim@mugenguild.com> | 2014-06-10 15:27:26 +0200 |
commit | e41e6ea0deec06703c5b9c80e429aff8ab110534 (patch) | |
tree | ba1051416937083879fb4a4f8d7234b175030837 /OpenKeychain/src/main/java/org/sufficientlysecure | |
parent | eac582a313c779e77b0fd67358417d512680facd (diff) | |
download | open-keychain-e41e6ea0deec06703c5b9c80e429aff8ab110534.tar.gz open-keychain-e41e6ea0deec06703c5b9c80e429aff8ab110534.tar.bz2 open-keychain-e41e6ea0deec06703c5b9c80e429aff8ab110534.zip |
import-log: more interface work
Diffstat (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure')
6 files changed, 71 insertions, 40 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpImportExport.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpImportExport.java index ebc5a7868..4cb41708d 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpImportExport.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpImportExport.java @@ -171,8 +171,6 @@ public class PgpImportExport { if (newKeys > 0 || oldKeys > 0) { if (badKeys > 0) { resultType = ImportResult.RESULT_PARTIAL_WITH_ERRORS; - } else if (log.containsWarnings()) { - resultType = ImportResult.RESULT_OK_WITH_WARNINGS; } else if (newKeys > 0 && oldKeys > 0) { resultType = ImportResult.RESULT_OK_BOTHKEYS; } else if (newKeys > 0) { diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/ProviderHelper.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/ProviderHelper.java index ab4672a98..cbaf72270 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/ProviderHelper.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/ProviderHelper.java @@ -49,7 +49,6 @@ import org.sufficientlysecure.keychain.provider.KeychainContract.Keys; import org.sufficientlysecure.keychain.provider.KeychainContract.UserIds; import org.sufficientlysecure.keychain.remote.AccountSettings; import org.sufficientlysecure.keychain.remote.AppSettings; -import org.sufficientlysecure.keychain.service.OperationResults; import org.sufficientlysecure.keychain.util.IterableIterator; import org.sufficientlysecure.keychain.util.Log; @@ -252,7 +251,7 @@ public class ProviderHelper { throw new NotFoundException("Secret key not available!"); } return secret - ? new WrappedSecretKeyRing(blob, hasAnySecret, verified) + ? new WrappedSecretKeyRing(blob, true, verified) : new WrappedPublicKeyRing(blob, hasAnySecret, verified); } else { throw new NotFoundException("Key not found!"); @@ -274,14 +273,15 @@ public class ProviderHelper { return new OperationResultParcel(1, mLog); } - // Canonicalize this key, to assert a number of assumptions made about the key. + long masterKeyId = keyRing.getMasterKeyId(); + log(LogLevel.START, LogType.MSG_IP, + new String[]{ PgpKeyHelper.convertKeyIdToHex(masterKeyId) }); + mIndent += 1; + + // Canonicalize this key, to assert a number of assumptions made about it. keyRing = keyRing.canonicalize(mLog); UncachedPublicKey masterKey = keyRing.getPublicKey(); - long masterKeyId = masterKey.getKeyId(); - log(LogLevel.INFO, LogType.MSG_IP_IMPORTING, - new String[]{Long.toString(masterKeyId)}); - mIndent += 1; // IF there is a secret key, preserve it! UncachedKeyRing secretRing; @@ -342,12 +342,28 @@ public class ProviderHelper { values.put(Keys.ALGORITHM, key.getAlgorithm()); values.put(Keys.FINGERPRINT, key.getFingerprint()); - boolean c = key.canCertify(), s = key.canSign(), e = key.canEncrypt(); + boolean c = key.canCertify(), e = key.canEncrypt(), s = key.canSign(); values.put(Keys.CAN_CERTIFY, c); - values.put(Keys.CAN_SIGN, s); values.put(Keys.CAN_ENCRYPT, e); + values.put(Keys.CAN_SIGN, s); values.put(Keys.IS_REVOKED, key.isRevoked()); - log(LogLevel.DEBUG, LogType.MSG_IP_SUBKEY_FLAGS, new String[] { "X" }); + if (c) { + if (e) { + log(LogLevel.DEBUG,s ? LogType.MSG_IP_SUBKEY_FLAGS_CES + : LogType.MSG_IP_SUBKEY_FLAGS_CEX, null); + } else { + log(LogLevel.DEBUG, s ? LogType.MSG_IP_SUBKEY_FLAGS_CXS + : LogType.MSG_IP_SUBKEY_FLAGS_CXX, null); + } + } else { + if (e) { + log(LogLevel.DEBUG, s ? LogType.MSG_IP_SUBKEY_FLAGS_XES + : LogType.MSG_IP_SUBKEY_FLAGS_XEX, null); + } else { + log(LogLevel.DEBUG, s ? LogType.MSG_IP_SUBKEY_FLAGS_XXS + : LogType.MSG_IP_SUBKEY_FLAGS_XXX, null); + } + } Date creation = key.getCreationTime(); values.put(Keys.CREATION, creation.getTime() / 1000); @@ -531,7 +547,7 @@ public class ProviderHelper { mIndent -= 1; } - log(LogLevel.INFO, LogType.MSG_IP_SUCCESS); + log(LogLevel.OK, LogType.MSG_IP_SUCCESS); mIndent -= 1; return new OperationResultParcel(0, mLog); @@ -569,8 +585,8 @@ public class ProviderHelper { } long masterKeyId = keyRing.getMasterKeyId(); - log(LogLevel.INFO, LogType.MSG_IS_IMPORTING, - new String[]{Long.toString(masterKeyId)}); + log(LogLevel.START, LogType.MSG_IS, + new String[]{PgpKeyHelper.convertKeyIdToHex(masterKeyId)}); // save secret keyring try { @@ -626,7 +642,7 @@ public class ProviderHelper { // with has_secret = 0 } - log(LogLevel.INFO, LogType.MSG_IS_SUCCESS); + log(LogLevel.OK, LogType.MSG_IS_SUCCESS); return new OperationResultParcel(0, mLog); } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/OperationResultParcel.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/OperationResultParcel.java index a1a1d0067..85b7c456f 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/OperationResultParcel.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/OperationResultParcel.java @@ -101,6 +101,9 @@ public class OperationResultParcel implements Parcelable { } public static enum LogType { + + // import public + MSG_IP(R.string.msg_ip), MSG_IP_APPLY_BATCH (R.string.msg_ip_apply_batch), MSG_IP_BAD_TYPE_SECRET (R.string.msg_ip_bad_type_secret), MSG_IP_DELETE_OLD_FAIL (R.string.msg_ip_delete_old_fail), @@ -109,7 +112,6 @@ public class OperationResultParcel implements Parcelable { MSG_IP_FAIL_IO_EXC (R.string.msg_ip_fail_io_exc), MSG_IP_FAIL_OP_EX (R.string.msg_ip_fail_op_ex), MSG_IP_FAIL_REMOTE_EX (R.string.msg_ip_fail_remote_ex), - MSG_IP_IMPORTING (R.string.msg_ip_importing), MSG_IP_INSERT_KEYRING (R.string.msg_ip_insert_keyring), MSG_IP_INSERT_SUBKEYS (R.string.msg_ip_insert_subkeys), MSG_IP_PRESERVING_SECRET (R.string.msg_ip_preserving_secret), @@ -118,6 +120,14 @@ public class OperationResultParcel implements Parcelable { MSG_IP_SUBKEY_EXPIRED (R.string.msg_ip_subkey_expired), MSG_IP_SUBKEY_EXPIRES (R.string.msg_ip_subkey_expires), MSG_IP_SUBKEY_FLAGS (R.string.msg_ip_subkey_flags), + MSG_IP_SUBKEY_FLAGS_CES (R.string.msg_ip_subkey_flags_ces), + MSG_IP_SUBKEY_FLAGS_CEX (R.string.msg_ip_subkey_flags_cex), + MSG_IP_SUBKEY_FLAGS_CXS (R.string.msg_ip_subkey_flags_cxs), + MSG_IP_SUBKEY_FLAGS_XES (R.string.msg_ip_subkey_flags_xes), + MSG_IP_SUBKEY_FLAGS_CXX (R.string.msg_ip_subkey_flags_cxx), + MSG_IP_SUBKEY_FLAGS_XEX (R.string.msg_ip_subkey_flags_xex), + MSG_IP_SUBKEY_FLAGS_XXS (R.string.msg_ip_subkey_flags_xxs), + MSG_IP_SUBKEY_FLAGS_XXX (R.string.msg_ip_subkey_flags_xxx), MSG_IP_SUBKEY_FUTURE (R.string.msg_ip_subkey_future), MSG_IP_SUCCESS (R.string.msg_ip_success), MSG_IP_TRUST_RETRIEVE (R.string.msg_ip_trust_retrieve), @@ -135,14 +145,20 @@ public class OperationResultParcel implements Parcelable { MSG_IP_UID_SELF_GOOD (R.string.msg_ip_uid_self_good), MSG_IP_UID_SELF_IGNORING_OLD (R.string.msg_ip_uid_self_ignoring_old), MSG_IP_UID_SELF_NEWER (R.string.msg_ip_uid_self_newer), + + // import secret + MSG_IS(R.string.msg_is), MSG_IS_BAD_TYPE_PUBLIC (R.string.msg_is_bad_type_public), - MSG_IS_IMPORTING (R.string.msg_is_importing), MSG_IS_IMPORTING_SUBKEYS (R.string.msg_is_importing_subkeys), MSG_IS_IO_EXCPTION (R.string.msg_is_io_excption), MSG_IS_SUBKEY_NONEXISTENT (R.string.msg_is_subkey_nonexistent), MSG_IS_SUBKEY_OK (R.string.msg_is_subkey_ok), MSG_IS_SUBKEY_STRIPPED (R.string.msg_is_subkey_stripped), MSG_IS_SUCCESS (R.string.msg_is_success), + + // keyring canonicalization + MSG_KC(R.string.msg_kc), + MSG_KC_SUCCESS(R.string.msg_kc_success), ; private final int mMsgId; @@ -156,12 +172,12 @@ public class OperationResultParcel implements Parcelable { /** Enumeration of possible log levels. */ public static enum LogLevel { - OK, + START, // should occur once at the start of each independent operation + OK, // should occur once at the end of a successful operation + ERROR, // should occur once at the end of a failed operation DEBUG, INFO, WARN, - /** If any ERROR log entry is included in the result, the overall operation should have failed. */ - ERROR, } @Override diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/OperationResults.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/OperationResults.java index e08b50500..bee6917be 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/OperationResults.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/OperationResults.java @@ -14,8 +14,6 @@ public abstract class OperationResults { public static final int RESULT_OK_BOTHKEYS = 2; // Operation ok, no new keys but upated ones (no warnings) public static final int RESULT_OK_UPDATED = 3; - // Operation ok, but with warnings - public static final int RESULT_OK_WITH_WARNINGS = 4; // Operation partially ok, but at least one key failed! public static final int RESULT_PARTIAL_WITH_ERRORS = 50; diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysActivity.java index 9932e3e18..61d7e7949 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysActivity.java @@ -378,37 +378,37 @@ public class ImportKeysActivity extends ActionBarActivity implements ActionBar.O final ImportResult result = returnData.<ImportResult>getParcelable(KeychainIntentService.RESULT); - // , make pessimistic assumptions - String str = Integer.toString(result.getResult()); - int duration = 0, color = Style.RED; + String str = ""; + boolean hasWarnings = result.getLog().containsWarnings(); + int duration = 0, color = hasWarnings ? Style.ORANGE : Style.GREEN; + String withWarnings = hasWarnings + ? getResources().getString(R.string.with_warnings) : ""; switch(result.getResult()) { case ImportResult.RESULT_OK_NEWKEYS: - color = Style.GREEN; - duration = SuperToast.Duration.LONG; + if (!hasWarnings) { + duration = SuperToast.Duration.LONG; + } str = getResources().getQuantityString( - R.plurals.keys_added, result.mNewKeys, result.mNewKeys); + R.plurals.keys_added, result.mNewKeys, result.mNewKeys, withWarnings); break; case ImportResult.RESULT_OK_UPDATED: - color = Style.GREEN; - duration = SuperToast.Duration.LONG; + if (!hasWarnings) { + duration = SuperToast.Duration.LONG; + } str = getResources().getQuantityString( - R.plurals.keys_updated, result.mNewKeys, result.mNewKeys); + R.plurals.keys_updated, result.mNewKeys, result.mNewKeys, withWarnings); break; case ImportResult.RESULT_OK_BOTHKEYS: - color = Style.GREEN; - duration = SuperToast.Duration.LONG; + if (!hasWarnings) { + duration = SuperToast.Duration.LONG; + } str = getResources().getQuantityString( R.plurals.keys_added_and_updated_1, result.mNewKeys, result.mNewKeys); str += getResources().getQuantityString( - R.plurals.keys_added_and_updated_2, result.mUpdatedKeys, result.mUpdatedKeys); - break; - - case ImportResult.RESULT_OK_WITH_WARNINGS: - str = "ok with warnings"; - color = Style.ORANGE; + R.plurals.keys_added_and_updated_2, result.mUpdatedKeys, result.mUpdatedKeys, withWarnings); break; case ImportResult.RESULT_PARTIAL_WITH_ERRORS: @@ -435,6 +435,8 @@ public class ImportKeysActivity extends ActionBarActivity implements ActionBar.O toast.setSwipeToDismiss(true); toast.setButtonIcon(R.drawable.ic_action_view_as_list, getResources().getString(R.string.view_log)); + toast.setButtonTextColor(R.color.emphasis_dark); + toast.setTextColor(R.color.emphasis_dark); toast.setOnClickWrapper(new OnClickWrapper("supercardtoast", new SuperToast.OnClickListener() { @Override diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/LogDisplayFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/LogDisplayFragment.java index 5e038d3f6..275c9ac18 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/LogDisplayFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/LogDisplayFragment.java @@ -73,6 +73,7 @@ public class LogDisplayFragment extends ListFragment { text.setPadding(entry.mIndent*dipFactor, 0, 0, 0); text.setText(getResources().getString(entry.mType.getMsgId(), (Object[]) entry.mParameters)); switch (entry.mLevel) { + case OK: text.setTextColor(Color.GREEN); break; case DEBUG: text.setTextColor(Color.GRAY); break; case INFO: text.setTextColor(Color.BLACK); break; case WARN: text.setTextColor(Color.YELLOW); break; |