add logging

This commit is contained in:
Vincent Breitmoser
2017-09-23 01:22:36 +02:00
parent a6f97cf46e
commit bf31d4f55d
5 changed files with 40 additions and 11 deletions

View File

@@ -95,10 +95,9 @@ public class DeleteOperation extends BaseReadWriteOperation<DeleteKeyringParcel>
}
if (isSecret && success > 0) {
log.add(LogType.MSG_DEL_CONSOLIDATE, 1);
UpdateTrustResult sub = mKeyWritableRepository.updateTrustDb(
Collections.singletonList(masterKeyIds[0]), mProgressable);
// log.add(sub, 2);
log.add(sub, 1);
}
int result = DeleteResult.RESULT_OK;

View File

@@ -264,11 +264,10 @@ public class ImportOperation extends BaseReadWriteOperation<ImportKeyringParcel>
// and re-inserts keys, which could conflict with a parallel db key update
if (!skipSave && !secretMasterKeyIds.isEmpty()) {
setPreventCancel();
UpdateTrustResult result;
synchronized (mKeyRepository) {
result = mKeyWritableRepository.updateTrustDb(secretMasterKeyIds, progressable);
UpdateTrustResult result = mKeyWritableRepository.updateTrustDb(secretMasterKeyIds, progressable);
log.add(result, 1);
}
// log.add(result, 1);
}
// Special: make sure new data is synced into contacts

View File

@@ -798,9 +798,8 @@ public abstract class OperationResult implements Parcelable {
MSG_DEL_ERROR_EMPTY (LogLevel.ERROR, R.string.msg_del_error_empty),
MSG_DEL_ERROR_MULTI_SECRET (LogLevel.ERROR, R.string.msg_del_error_multi_secret),
MSG_DEL (LogLevel.START, R.plurals.msg_del),
MSG_DEL_KEY (LogLevel.DEBUG, R.string.msg_del_key),
MSG_DEL_KEY (LogLevel.INFO, R.string.msg_del_key),
MSG_DEL_KEY_FAIL (LogLevel.WARN, R.string.msg_del_key_fail),
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),
@@ -910,6 +909,12 @@ public abstract class OperationResult implements Parcelable {
MSG_RET_URI_NULL (LogLevel.ERROR, R.string.msg_ret_uri_null),
MSG_RET_URI_TEST (LogLevel.DEBUG, R.string.msg_ret_uri_test),
MSG_TRUST (LogLevel.START, R.string.msg_trust),
MSG_TRUST_OK (LogLevel.OK, R.string.msg_trust_ok),
MSG_TRUST_KEY (LogLevel.INFO, R.string.msg_trust_key),
MSG_TRUST_INITIALIZE (LogLevel.INFO, R.string.msg_trust_initialize),
MSG_TRUST_COUNT_NONE (LogLevel.DEBUG, R.string.msg_trust_count_none),
MSG_TRUST_COUNT (LogLevel.DEBUG, R.plurals.msg_trust_count);
;
public final int mMsgId;

View File

@@ -40,6 +40,7 @@ import android.support.v4.util.LongSparseArray;
import org.openintents.openpgp.util.OpenPgpUtils;
import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.operations.results.OperationResult.LogType;
import org.sufficientlysecure.keychain.operations.results.OperationResult.OperationLog;
import org.sufficientlysecure.keychain.operations.results.SaveKeyringResult;
@@ -1019,16 +1020,20 @@ public class KeyWritableRepository extends KeyRepository {
public UpdateTrustResult updateTrustDb(List<Long> signerMasterKeyIds, Progressable progress) {
OperationLog log = new OperationLog();
log.add(LogType.MSG_TRUST, 0);
Cursor cursor;
Preferences preferences = Preferences.getPreferences(mContext);
boolean isTrustDbInitialized = preferences.isKeySignaturesTableInitialized();
if (!isTrustDbInitialized) {
log.add(LogType.MSG_TRUST_INITIALIZE, 1);
cursor = mContentResolver.query(KeyRings.buildUnifiedKeyRingsUri(),
new String[] { KeyRings.MASTER_KEY_ID }, null, null, null);
} else {
String[] signerMasterKeyIdStrings = new String[signerMasterKeyIds.size()];
int i = 0;
for (Long masterKeyId : signerMasterKeyIds) {
log.add(LogType.MSG_TRUST_KEY, 1, KeyFormattingUtils.beautifyKeyId(masterKeyId));
signerMasterKeyIdStrings[i++] = Long.toString(masterKeyId);
}
@@ -1040,6 +1045,16 @@ public class KeyWritableRepository extends KeyRepository {
throw new IllegalStateException();
}
int totalKeys = cursor.getCount();
int processedKeys = 0;
if (totalKeys == 0) {
log.add(LogType.MSG_TRUST_COUNT_NONE, 1);
} else {
progress.setProgress(R.string.progress_update_trust, 0, totalKeys);
log.add(LogType.MSG_TRUST_COUNT, 1, totalKeys);
}
try {
while (cursor.moveToNext()) {
try {
@@ -1047,9 +1062,12 @@ public class KeyWritableRepository extends KeyRepository {
byte[] pubKeyData = loadPublicKeyRingData(masterKeyId);
UncachedKeyRing uncachedKeyRing = UncachedKeyRing.decodeFromData(pubKeyData);
clearLog();
SaveKeyringResult result = savePublicKeyRing(uncachedKeyRing, true);
log.add(result, 1);
progress.setProgress(processedKeys++, totalKeys);
} catch (NotFoundException | PgpGeneralException | IOException e) {
Log.e(Constants.TAG, "Error updating trust database", e);
return new UpdateTrustResult(UpdateTrustResult.RESULT_ERROR, log);
@@ -1060,6 +1078,7 @@ public class KeyWritableRepository extends KeyRepository {
preferences.setKeySignaturesTableInitialized();
}
log.add(LogType.MSG_TRUST_OK, 1);
return new UpdateTrustResult(UpdateTrustResult.RESULT_OK, log);
} finally {
cursor.close();