aboutsummaryrefslogtreecommitdiffstats
path: root/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/results/OperationResult.java
diff options
context:
space:
mode:
authorVincent Breitmoser <valodim@mugenguild.com>2015-03-05 12:10:51 +0100
committerVincent Breitmoser <valodim@mugenguild.com>2015-03-05 12:10:51 +0100
commit7b3bc4ca98c2be52bec996287c5997c3c52e3603 (patch)
tree861f5c7d329ea8c96e673b2c16f068d593a55fb9 /OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/results/OperationResult.java
parent98ce06dbc9bea56d2960df2d7b8e7a5bc9e9e43a (diff)
parent8c8fdd6c495bb12f5c76c9d1fc4a6a44f1c3808b (diff)
downloadopen-keychain-7b3bc4ca98c2be52bec996287c5997c3c52e3603.tar.gz
open-keychain-7b3bc4ca98c2be52bec996287c5997c3c52e3603.tar.bz2
open-keychain-7b3bc4ca98c2be52bec996287c5997c3c52e3603.zip
Merge branch 'development' into linked-identities
Conflicts: OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/results/OperationResult.java OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyFragment.java
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.java75
1 files changed, 69 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 ea4fedc56..a856a4fc3 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() {
@@ -723,6 +778,12 @@ public abstract class OperationResult implements Parcelable {
MSG_LV_FETCH_ERROR_URL (LogLevel.ERROR, R.string.msg_lv_fetch_error_url),
MSG_LV_FETCH_ERROR_IO (LogLevel.ERROR, R.string.msg_lv_fetch_error_io),
+ //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;
@@ -755,9 +816,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> {