Use Timber instead of Android.Log

This commit is contained in:
Vincent Breitmoser
2018-01-20 02:12:43 +01:00
parent 73b65bf50b
commit 22c65f2ab8
161 changed files with 782 additions and 947 deletions

View File

@@ -20,14 +20,14 @@ package org.sufficientlysecure.keychain.provider;
import android.net.Uri;
import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKey.SecretKeyType;
import org.sufficientlysecure.keychain.pgp.KeyRing;
import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException;
import org.sufficientlysecure.keychain.provider.KeyRepository.NotFoundException;
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings;
import org.sufficientlysecure.keychain.provider.KeychainContract.Keys;
import org.sufficientlysecure.keychain.util.Log;
import timber.log.Timber;
/** This implementation of KeyRing provides a cached view of PublicKeyRing
* objects based on database queries exclusively.
@@ -77,7 +77,7 @@ public class CachedPublicKeyRing extends KeyRing {
return Long.parseLong(firstSegment);
} catch (NumberFormatException e) {
// didn't work? oh well.
Log.d(Constants.TAG, "Couldn't get masterKeyId from URI, querying...");
Timber.d("Couldn't get masterKeyId from URI, querying...");
}
return getMasterKeyId();
}

View File

@@ -28,10 +28,8 @@ import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
import android.support.annotation.Nullable;
import android.util.Log;
import org.bouncycastle.bcpg.ArmoredOutputStream;
import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.operations.results.OperationResult.LogType;
import org.sufficientlysecure.keychain.operations.results.OperationResult.OperationLog;
import org.sufficientlysecure.keychain.pgp.CanonicalizedPublicKeyRing;
@@ -43,6 +41,7 @@ import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRingData;
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings;
import org.sufficientlysecure.keychain.provider.KeychainContract.UpdatedKeys;
import org.sufficientlysecure.keychain.provider.KeychainContract.UserPackets;
import timber.log.Timber;
public class KeyRepository {
@@ -339,7 +338,7 @@ public class KeyRepository {
try {
data = mLocalPublicKeyStorage.readPublicKey(masterKeyId);
} catch (IOException e) {
Log.e(Constants.TAG, "Error reading public key from storage!", e);
Timber.e(e, "Error reading public key from storage!");
throw new NotFoundException();
}
}

View File

@@ -38,7 +38,6 @@ import android.support.annotation.VisibleForTesting;
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;
@@ -67,9 +66,10 @@ import org.sufficientlysecure.keychain.provider.KeychainContract.UpdatedKeys;
import org.sufficientlysecure.keychain.provider.KeychainContract.UserPackets;
import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils;
import org.sufficientlysecure.keychain.util.IterableIterator;
import org.sufficientlysecure.keychain.util.Log;
import org.sufficientlysecure.keychain.util.Preferences;
import org.sufficientlysecure.keychain.util.Utf8Util;
import timber.log.Timber;
/**
* This class contains high level methods for database access. Despite its
@@ -514,7 +514,7 @@ public class KeyWritableRepository extends KeyRepository {
} catch (IOException e) {
log(LogType.MSG_IP_ERROR_IO_EXC);
Log.e(Constants.TAG, "IOException during import", e);
Timber.e(e, "IOException during import");
return SaveKeyringResult.RESULT_ERROR;
} finally {
mIndent -= 1;
@@ -544,11 +544,11 @@ public class KeyWritableRepository extends KeyRepository {
} catch (RemoteException e) {
log(LogType.MSG_IP_ERROR_REMOTE_EX);
Log.e(Constants.TAG, "RemoteException during import", e);
Timber.e(e, "RemoteException during import");
return SaveKeyringResult.RESULT_ERROR;
} catch (OperationApplicationException e) {
log(LogType.MSG_IP_ERROR_OP_EXC);
Log.e(Constants.TAG, "OperationApplicationException during import", e);
Timber.e(e, "OperationApplicationException during import");
return SaveKeyringResult.RESULT_ERROR;
}
@@ -602,7 +602,7 @@ public class KeyWritableRepository extends KeyRepository {
try {
mLocalPublicKeyStorage.deletePublicKey(masterKeyId);
} catch (IOException e) {
android.util.Log.e(Constants.TAG, "Could not delete file!", e);
Timber.e(e, "Could not delete file!");
return false;
}
mContentResolver.delete(ApiAutocryptPeer.buildByMasterKeyId(masterKeyId),null, null);
@@ -671,7 +671,7 @@ public class KeyWritableRepository extends KeyRepository {
return SaveKeyringResult.RESULT_ERROR;
}
} catch (IOException e) {
Log.e(Constants.TAG, "Failed to encode key!", e);
Timber.e(e, "Failed to encode key!");
log(LogType.MSG_IS_ERROR_IO_EXC);
return SaveKeyringResult.RESULT_ERROR;
}
@@ -1068,7 +1068,7 @@ public class KeyWritableRepository extends KeyRepository {
log.add(result, 1);
progress.setProgress(processedKeys++, totalKeys);
} catch (NotFoundException | PgpGeneralException | IOException e) {
Log.e(Constants.TAG, "Error updating trust database", e);
Timber.e(e, "Error updating trust database");
return new UpdateTrustResult(UpdateTrustResult.RESULT_ERROR, log);
}
}

View File

@@ -40,8 +40,8 @@ import org.sufficientlysecure.keychain.provider.KeychainContract.KeysColumns;
import org.sufficientlysecure.keychain.provider.KeychainContract.OverriddenWarnings;
import org.sufficientlysecure.keychain.provider.KeychainContract.UpdatedKeysColumns;
import org.sufficientlysecure.keychain.provider.KeychainContract.UserPacketsColumns;
import org.sufficientlysecure.keychain.util.Log;
import org.sufficientlysecure.keychain.util.Preferences;
import timber.log.Timber;
/**
@@ -215,7 +215,7 @@ public class KeychainDatabase extends SQLiteOpenHelper {
@Override
public void onCreate(SQLiteDatabase db) {
Log.w(Constants.TAG, "Creating database...");
Timber.w("Creating database...");
db.execSQL(CREATE_KEYRINGS_PUBLIC);
db.execSQL(CREATE_KEYRINGS_SECRET);
@@ -249,7 +249,7 @@ public class KeychainDatabase extends SQLiteOpenHelper {
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
Log.d(Constants.TAG, "Upgrading db from " + oldVersion + " to " + newVersion);
Timber.d("Upgrading db from " + oldVersion + " to " + newVersion);
switch (oldVersion) {
case 1:

View File

@@ -50,7 +50,10 @@ import org.sufficientlysecure.keychain.provider.KeychainContract.UpdatedKeys;
import org.sufficientlysecure.keychain.provider.KeychainContract.UserPackets;
import org.sufficientlysecure.keychain.provider.KeychainContract.UserPacketsColumns;
import org.sufficientlysecure.keychain.provider.KeychainDatabase.Tables;
import org.sufficientlysecure.keychain.util.Log;
import timber.log.Timber;
import static android.database.DatabaseUtils.dumpCursorToString;
public class KeychainProvider extends ContentProvider {
@@ -296,7 +299,7 @@ public class KeychainProvider extends ContentProvider {
@Override
public Cursor query(@NonNull Uri uri, String[] projection, String selection, String[] selectionArgs,
String sortOrder) {
Log.v(Constants.TAG, "query(uri=" + uri + ", proj=" + Arrays.toString(projection) + ")");
Timber.v("query(uri=" + uri + ", proj=" + Arrays.toString(projection) + ")");
SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
@@ -457,7 +460,7 @@ public class KeychainProvider extends ContentProvider {
+ " AND tmp." + Keys.KEY_ID + " = " + subkey + ""
+ ")");
} catch(NumberFormatException e) {
Log.e(Constants.TAG, "Malformed find by subkey query!", e);
Timber.e(e, "Malformed find by subkey query!");
qb.appendWhere(" AND 0");
}
break;
@@ -510,7 +513,7 @@ public class KeychainProvider extends ContentProvider {
+ ")");
} else {
// TODO better way to do this?
Log.e(Constants.TAG, "Malformed find by email query!");
Timber.e("Malformed find by email query!");
qb.appendWhere(" AND 0");
}
break;
@@ -795,11 +798,10 @@ public class KeychainProvider extends ContentProvider {
cursor.setNotificationUri(getContext().getContentResolver(), uri);
}
Log.d(Constants.TAG,
"Query: " + qb.buildQuery(projection, selection, null, null, orderBy, null));
Timber.d("Query: " + qb.buildQuery(projection, selection, null, null, orderBy, null));
if (Constants.DEBUG && Constants.DEBUG_LOG_DB_QUERIES) {
Log.d(Constants.TAG, "Cursor: " + DatabaseUtils.dumpCursorToString(cursor));
Timber.d("Cursor: " + dumpCursorToString(cursor));
}
if (Constants.DEBUG && Constants.DEBUG_EXPLAIN_QUERIES) {
@@ -813,14 +815,14 @@ public class KeychainProvider extends ContentProvider {
for (int i = 0; i < explainCursor.getColumnCount(); i++) {
line.append(explainCursor.getColumnName(i)).append(", ");
}
Log.d(Constants.TAG, line.toString());
Timber.d(line.toString());
while (!explainCursor.isAfterLast()) {
line = new StringBuilder();
for (int i = 0; i < explainCursor.getColumnCount(); i++) {
line.append(explainCursor.getString(i)).append(", ");
}
Log.d(Constants.TAG, line.toString());
Timber.d(line.toString());
explainCursor.moveToNext();
}
@@ -835,7 +837,7 @@ public class KeychainProvider extends ContentProvider {
*/
@Override
public Uri insert(Uri uri, ContentValues values) {
Log.d(Constants.TAG, "insert(uri=" + uri + ", values=" + values.toString() + ")");
Timber.d("insert(uri=" + uri + ", values=" + values.toString() + ")");
final SQLiteDatabase db = getDb().getWritableDatabase();
@@ -925,7 +927,7 @@ public class KeychainProvider extends ContentProvider {
getContext().getContentResolver().notifyChange(uri, null);
} catch (SQLiteConstraintException e) {
Log.d(Constants.TAG, "Constraint exception on insert! Entry already existing?", e);
Timber.d(e, "Constraint exception on insert! Entry already existing?");
}
return rowUri;
@@ -936,7 +938,7 @@ public class KeychainProvider extends ContentProvider {
*/
@Override
public int delete(Uri uri, String additionalSelection, String[] selectionArgs) {
Log.v(Constants.TAG, "delete(uri=" + uri + ")");
Timber.v("delete(uri=" + uri + ")");
final SQLiteDatabase db = getDb().getWritableDatabase();
@@ -1028,7 +1030,7 @@ public class KeychainProvider extends ContentProvider {
*/
@Override
public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
Log.v(Constants.TAG, "update(uri=" + uri + ", values=" + values.toString() + ")");
Timber.v("update(uri=" + uri + ", values=" + values.toString() + ")");
final SQLiteDatabase db = getDb().getWritableDatabase();
ContentResolver contentResolver = getContext().getContentResolver();
@@ -1109,7 +1111,7 @@ public class KeychainProvider extends ContentProvider {
contentResolver.notifyChange(uri, null);
} catch (SQLiteConstraintException e) {
Log.d(Constants.TAG, "Constraint exception on update! Entry already existing?", e);
Timber.d(e, "Constraint exception on update! Entry already existing?");
}
return count;

View File

@@ -32,7 +32,7 @@ import android.provider.MediaStore;
import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.util.DatabaseUtil;
import org.sufficientlysecure.keychain.util.Log;
import timber.log.Timber;
import java.io.File;
import java.io.FileNotFoundException;
@@ -136,7 +136,7 @@ public class TemporaryFileProvider extends ContentProvider {
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
Log.d(Constants.TAG, "Upgrading files db from " + oldVersion + " to " + newVersion);
Timber.d("Upgrading files db from %s to %s", oldVersion, newVersion);
switch (oldVersion) {
case 1:
@@ -188,7 +188,7 @@ public class TemporaryFileProvider extends ContentProvider {
try {
file = getFile(uri);
} catch (FileNotFoundException e) {
Log.e(Constants.TAG, "file not found!");
Timber.e("file not found!");
return null;
}
@@ -253,13 +253,13 @@ public class TemporaryFileProvider extends ContentProvider {
values.put(TemporaryFileColumns.COLUMN_UUID, uuid);
int insert = (int) db.getWritableDatabase().insert(TABLE_FILES, null, values);
if (insert == -1) {
Log.e(Constants.TAG, "Insert failed!");
Timber.e("Insert failed!");
return null;
}
try {
getFile(uuid).createNewFile();
} catch (IOException e) {
Log.e(Constants.TAG, "File creation failed!");
Timber.e("File creation failed!");
return null;
}
return Uri.withAppendedPath(CONTENT_URI, uuid);