diff options
Diffstat (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/results/OperationResult.java')
-rw-r--r-- | OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/results/OperationResult.java | 78 |
1 files changed, 72 insertions, 6 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/results/OperationResult.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/results/OperationResult.java index f79900aab..a96cec8cf 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/results/OperationResult.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/results/OperationResult.java @@ -38,6 +38,8 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Iterator; import java.util.List; +import java.util.UUID; +import java.util.concurrent.ConcurrentHashMap; /** Represent the result of an operation. * @@ -51,6 +53,56 @@ import java.util.List; public abstract class OperationResult implements Parcelable { public static final String EXTRA_RESULT = "operation_result"; + public static final UUID NULL_UUID = new UUID(0,0); + + /** + * A HashMap of UUID:OperationLog which contains logs that we don't need + * to care about. This is used such that when we become parceled, we are + * well below the 1Mbit boundary that is specified. + */ + private static ConcurrentHashMap<UUID, OperationLog> dehydratedLogs; + static { + // Static initializer for ConcurrentHashMap + dehydratedLogs = new ConcurrentHashMap<UUID,OperationLog>(); + } + + /** + * Dehydrate a log (such that it is available after deparcelization) + * + * Returns the NULL uuid (0) if you hand it null. + * @param log An OperationLog to dehydrate + * @return a UUID, the ticket for your dehydrated log + * + */ + private static UUID dehydrateLog(OperationLog log) { + if(log == null) { + return NULL_UUID; + } + else { + UUID ticket = UUID.randomUUID(); + dehydratedLogs.put(ticket, log); + return ticket; + } + } + + /*** + * Rehydrate a log after going through parcelization, invalidating its place in the + * dehydration pool. + * This is used such that when parcelized, the parcel is no larger than 1mbit. + * @param ticket A UUID ticket that identifies the log in question. + * @return An OperationLog. + */ + private static OperationLog rehydrateLog(UUID ticket) { + // UUID.equals isn't well documented; we use compareTo instead. + if( NULL_UUID.compareTo(ticket) == 0 ) { + return null; + } + else { + OperationLog log = dehydratedLogs.get(ticket); + dehydratedLogs.remove(ticket); + return log; + } + } /** Holds the overall result, the number specifying varying degrees of success: * - The first bit is 0 on overall success, 1 on overall failure @@ -65,7 +117,7 @@ public abstract class OperationResult implements Parcelable { public static final int RESULT_WARNINGS = 4; /// A list of log entries tied to the operation result. - final OperationLog mLog; + protected OperationLog mLog; public OperationResult(int result, OperationLog log) { mResult = result; @@ -74,8 +126,11 @@ public abstract class OperationResult implements Parcelable { public OperationResult(Parcel source) { mResult = source.readInt(); - mLog = new OperationLog(); - mLog.addAll(source.createTypedArrayList(LogEntryParcel.CREATOR)); + long mostSig = source.readLong(); + long leastSig = source.readLong(); + UUID mTicket = new UUID(mostSig, leastSig); + // fetch the dehydrated log out of storage (this removes it from the dehydration pool) + mLog = rehydrateLog(mTicket); } public int getResult() { @@ -571,6 +626,7 @@ public abstract class OperationResult implements Parcelable { MSG_DC_ERROR_NO_DATA (LogLevel.ERROR, R.string.msg_dc_error_no_data), MSG_DC_ERROR_NO_KEY (LogLevel.ERROR, R.string.msg_dc_error_no_key), MSG_DC_ERROR_PGP_EXCEPTION (LogLevel.ERROR, R.string.msg_dc_error_pgp_exception), + MSG_DC_ERROR_UNSUPPORTED_HASH_ALGO (LogLevel.ERROR, R.string.msg_dc_error_unsupported_hash_algo), MSG_DC_INTEGRITY_CHECK_OK (LogLevel.INFO, R.string.msg_dc_integrity_check_ok), MSG_DC_OK_META_ONLY (LogLevel.OK, R.string.msg_dc_ok_meta_only), MSG_DC_OK (LogLevel.OK, R.string.msg_dc_ok), @@ -585,6 +641,7 @@ public abstract class OperationResult implements Parcelable { MSG_DC_TRAIL_SYM (LogLevel.DEBUG, R.string.msg_dc_trail_sym), MSG_DC_TRAIL_UNKNOWN (LogLevel.DEBUG, R.string.msg_dc_trail_unknown), MSG_DC_UNLOCKING (LogLevel.INFO, R.string.msg_dc_unlocking), + MSG_DC_OLD_SYMMETRIC_ENCRYPTION_ALGO (LogLevel.WARN, R.string.msg_dc_old_symmetric_encryption_algo), // verify signed literal data MSG_VL (LogLevel.INFO, R.string.msg_vl), @@ -707,6 +764,13 @@ public abstract class OperationResult implements Parcelable { MSG_DEL_CONSOLIDATE (LogLevel.DEBUG, R.string.msg_del_consolidate), MSG_DEL_OK (LogLevel.OK, R.plurals.msg_del_ok), MSG_DEL_FAIL (LogLevel.WARN, R.plurals.msg_del_fail), + + //export log + MSG_EXPORT_LOG(LogLevel.START,R.string.msg_export_log_start), + MSG_EXPORT_LOG_EXPORT_ERROR_NO_FILE(LogLevel.ERROR,R.string.msg_export_log_error_no_file), + MSG_EXPORT_LOG_EXPORT_ERROR_FOPEN(LogLevel.ERROR,R.string.msg_export_log_error_fopen), + MSG_EXPORT_LOG_EXPORT_ERROR_WRITING(LogLevel.ERROR,R.string.msg_export_log_error_writing), + MSG_EXPORT_LOG_EXPORT_SUCCESS (LogLevel.OK, R.string.msg_export_log_success), ; public final int mMsgId; @@ -739,9 +803,11 @@ public abstract class OperationResult implements Parcelable { @Override public void writeToParcel(Parcel dest, int flags) { dest.writeInt(mResult); - if (mLog != null) { - dest.writeTypedList(mLog.toList()); - } + // Get a ticket for our log. + UUID mTicket = dehydrateLog(mLog); + // And write out the UUID most and least significant bits. + dest.writeLong(mTicket.getMostSignificantBits()); + dest.writeLong(mTicket.getLeastSignificantBits()); } public static class OperationLog implements Iterable<LogEntryParcel> { |