mirror of
https://github.com/moparisthebest/open-keychain
synced 2025-02-08 02:50:12 -05:00
import-log: improve operationresultparcel, add indentation
This commit is contained in:
parent
c84a1ecfff
commit
b995b836a3
@ -1,9 +1,10 @@
|
|||||||
package org.sufficientlysecure.keychain.pgp;
|
package org.sufficientlysecure.keychain.pgp;
|
||||||
|
|
||||||
import android.R;
|
|
||||||
import android.os.Parcel;
|
import android.os.Parcel;
|
||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
|
|
||||||
|
import org.sufficientlysecure.keychain.R;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
/** Represent the result of an operation.
|
/** Represent the result of an operation.
|
||||||
@ -39,20 +40,26 @@ public class OperationResultParcel implements Parcelable {
|
|||||||
|
|
||||||
/** One entry in the log. */
|
/** One entry in the log. */
|
||||||
public static class LogEntryParcel implements Parcelable {
|
public static class LogEntryParcel implements Parcelable {
|
||||||
final LogType mType;
|
|
||||||
final LogLevel mLevel;
|
final LogLevel mLevel;
|
||||||
|
final LogType mType;
|
||||||
final String[] mParameters;
|
final String[] mParameters;
|
||||||
|
final int mIndent;
|
||||||
|
|
||||||
public LogEntryParcel(LogType type, LogLevel level, String[] parameters) {
|
public LogEntryParcel(LogLevel level, LogType type, String[] parameters, int indent) {
|
||||||
mType = type;
|
|
||||||
mLevel = level;
|
mLevel = level;
|
||||||
|
mType = type;
|
||||||
mParameters = parameters;
|
mParameters = parameters;
|
||||||
|
mIndent = indent;
|
||||||
|
}
|
||||||
|
public LogEntryParcel(LogLevel level, LogType type, String[] parameters) {
|
||||||
|
this(level, type, parameters, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public LogEntryParcel(Parcel source) {
|
public LogEntryParcel(Parcel source) {
|
||||||
mType = LogType.values()[source.readInt()];
|
|
||||||
mLevel = LogLevel.values()[source.readInt()];
|
mLevel = LogLevel.values()[source.readInt()];
|
||||||
|
mType = LogType.values()[source.readInt()];
|
||||||
mParameters = source.createStringArray();
|
mParameters = source.createStringArray();
|
||||||
|
mIndent = source.readInt();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -62,9 +69,10 @@ public class OperationResultParcel implements Parcelable {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeToParcel(Parcel dest, int flags) {
|
public void writeToParcel(Parcel dest, int flags) {
|
||||||
dest.writeInt(mType.ordinal());
|
|
||||||
dest.writeInt(mLevel.ordinal());
|
dest.writeInt(mLevel.ordinal());
|
||||||
|
dest.writeInt(mType.ordinal());
|
||||||
dest.writeStringArray(mParameters);
|
dest.writeStringArray(mParameters);
|
||||||
|
dest.writeInt(mIndent);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final Creator<LogEntryParcel> CREATOR = new Creator<LogEntryParcel>() {
|
public static final Creator<LogEntryParcel> CREATOR = new Creator<LogEntryParcel>() {
|
||||||
|
@ -29,6 +29,9 @@ import android.support.v4.util.LongSparseArray;
|
|||||||
|
|
||||||
import org.sufficientlysecure.keychain.Constants;
|
import org.sufficientlysecure.keychain.Constants;
|
||||||
import org.sufficientlysecure.keychain.pgp.KeyRing;
|
import org.sufficientlysecure.keychain.pgp.KeyRing;
|
||||||
|
import org.sufficientlysecure.keychain.pgp.OperationResultParcel;
|
||||||
|
import org.sufficientlysecure.keychain.pgp.OperationResultParcel.LogType;
|
||||||
|
import org.sufficientlysecure.keychain.pgp.OperationResultParcel.LogLevel;
|
||||||
import org.sufficientlysecure.keychain.pgp.PgpHelper;
|
import org.sufficientlysecure.keychain.pgp.PgpHelper;
|
||||||
import org.sufficientlysecure.keychain.pgp.PgpKeyHelper;
|
import org.sufficientlysecure.keychain.pgp.PgpKeyHelper;
|
||||||
import org.sufficientlysecure.keychain.pgp.UncachedKeyRing;
|
import org.sufficientlysecure.keychain.pgp.UncachedKeyRing;
|
||||||
@ -59,12 +62,21 @@ import java.util.List;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public class ProviderHelper {
|
public class ProviderHelper {
|
||||||
private Context mContext;
|
private final Context mContext;
|
||||||
private ContentResolver mContentResolver;
|
private final ContentResolver mContentResolver;
|
||||||
|
private final ArrayList<OperationResultParcel.LogEntryParcel> mLog;
|
||||||
|
private int mIndent;
|
||||||
|
|
||||||
public ProviderHelper(Context context) {
|
public ProviderHelper(Context context) {
|
||||||
this.mContext = context;
|
this(context, null, 0);
|
||||||
this.mContentResolver = context.getContentResolver();
|
}
|
||||||
|
|
||||||
|
public ProviderHelper(Context context, ArrayList<OperationResultParcel.LogEntryParcel> log,
|
||||||
|
int indent) {
|
||||||
|
mContext = context;
|
||||||
|
mContentResolver = context.getContentResolver();
|
||||||
|
mLog = log;
|
||||||
|
mIndent = indent;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class NotFoundException extends Exception {
|
public static class NotFoundException extends Exception {
|
||||||
@ -76,6 +88,13 @@ public class ProviderHelper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void log(LogLevel level, LogType type) {
|
||||||
|
mLog.add(new OperationResultParcel.LogEntryParcel(level, type, null, mIndent));
|
||||||
|
}
|
||||||
|
public void log(LogLevel level, LogType type, String[] parameters) {
|
||||||
|
mLog.add(new OperationResultParcel.LogEntryParcel(level, type, parameters, mIndent));
|
||||||
|
}
|
||||||
|
|
||||||
// If we ever switch to api level 11, we can ditch this whole mess!
|
// If we ever switch to api level 11, we can ditch this whole mess!
|
||||||
public static final int FIELD_TYPE_NULL = 1;
|
public static final int FIELD_TYPE_NULL = 1;
|
||||||
// this is called integer to stay coherent with the constants in Cursor (api level 11)
|
// this is called integer to stay coherent with the constants in Cursor (api level 11)
|
||||||
|
Loading…
Reference in New Issue
Block a user