Use Timber instead of Android.Log
This commit is contained in:
@@ -7,9 +7,8 @@ import android.database.sqlite.SQLiteCursorDriver;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.database.sqlite.SQLiteDatabase.CursorFactory;
|
||||
import android.database.sqlite.SQLiteQuery;
|
||||
import android.util.Log;
|
||||
|
||||
import org.sufficientlysecure.keychain.Constants;
|
||||
import timber.log.Timber;
|
||||
|
||||
|
||||
public class CloseDatabaseCursorFactory implements CursorFactory {
|
||||
@@ -23,11 +22,11 @@ public class CloseDatabaseCursorFactory implements CursorFactory {
|
||||
final SQLiteDatabase db = getDatabase();
|
||||
super.close();
|
||||
if (db != null) {
|
||||
Log.d(Constants.TAG, "Closing cursor: " + db.getPath());
|
||||
Timber.d("Closing cursor: " + db.getPath());
|
||||
try {
|
||||
db.close();
|
||||
} catch (Exception e) {
|
||||
Log.e(Constants.TAG, "Error closing db", e);
|
||||
Timber.e(e, "Error closing db");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,17 @@
|
||||
|
||||
package org.sufficientlysecure.keychain.util;
|
||||
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Matcher;
|
||||
|
||||
import android.Manifest;
|
||||
import android.accounts.Account;
|
||||
import android.accounts.AccountManager;
|
||||
@@ -40,16 +51,7 @@ import org.sufficientlysecure.keychain.R;
|
||||
import org.sufficientlysecure.keychain.pgp.KeyRing;
|
||||
import org.sufficientlysecure.keychain.provider.KeychainContract;
|
||||
import org.sufficientlysecure.keychain.provider.KeychainContract.UserPackets;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Matcher;
|
||||
import timber.log.Timber;
|
||||
|
||||
public class ContactHelper {
|
||||
|
||||
@@ -490,7 +492,7 @@ public class ContactHelper {
|
||||
return true;
|
||||
}
|
||||
|
||||
Log.w(Constants.TAG, "READ_CONTACTS permission denied!");
|
||||
Timber.w("READ_CONTACTS permission denied!");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -515,7 +517,7 @@ public class ContactHelper {
|
||||
boolean isRevoked = cursor.getInt(INDEX_IS_REVOKED) > 0;
|
||||
boolean isVerified = cursor.getInt(INDEX_VERIFIED) > 0;
|
||||
|
||||
Log.d(Constants.TAG, "masterKeyId: " + masterKeyId);
|
||||
Timber.d("masterKeyId: " + masterKeyId);
|
||||
|
||||
deletedKeys.remove(masterKeyId);
|
||||
|
||||
@@ -524,7 +526,7 @@ public class ContactHelper {
|
||||
// Do not store expired or revoked or unverified keys in contact db - and
|
||||
// remove them if they already exist. Secret keys do not reach this point
|
||||
if (isExpired || isRevoked || !isVerified) {
|
||||
Log.d(Constants.TAG, "Expired or revoked or unverified: Deleting masterKeyId "
|
||||
Timber.d("Expired or revoked or unverified: Deleting masterKeyId "
|
||||
+ masterKeyId);
|
||||
if (masterKeyId != -1) {
|
||||
deleteRawContactByMasterKeyId(masterKeyId);
|
||||
@@ -533,11 +535,11 @@ public class ContactHelper {
|
||||
|
||||
// get raw contact to this master key id
|
||||
long rawContactId = findRawContactId(masterKeyId);
|
||||
Log.d(Constants.TAG, "rawContactId: " + rawContactId);
|
||||
Timber.d("rawContactId: " + rawContactId);
|
||||
|
||||
// Create a new rawcontact with corresponding key if it does not exist yet
|
||||
if (rawContactId == -1) {
|
||||
Log.d(Constants.TAG, "Insert new raw contact with masterKeyId " + masterKeyId);
|
||||
Timber.d("Insert new raw contact with masterKeyId " + masterKeyId);
|
||||
|
||||
insertContact(ops, masterKeyId);
|
||||
writeContactKey(ops, rawContactId, masterKeyId, name);
|
||||
@@ -550,7 +552,7 @@ public class ContactHelper {
|
||||
try {
|
||||
mContentResolver.applyBatch(ContactsContract.AUTHORITY, ops);
|
||||
} catch (Exception e) {
|
||||
Log.w(Constants.TAG, e);
|
||||
Timber.w(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -559,7 +561,7 @@ public class ContactHelper {
|
||||
|
||||
// Delete master key ids that are no longer present in OK
|
||||
for (Long masterKeyId : deletedKeys) {
|
||||
Log.d(Constants.TAG, "Delete raw contact with masterKeyId " + masterKeyId);
|
||||
Timber.d("Delete raw contact with masterKeyId " + masterKeyId);
|
||||
deleteRawContactByMasterKeyId(masterKeyId);
|
||||
}
|
||||
}
|
||||
@@ -594,7 +596,7 @@ public class ContactHelper {
|
||||
if (!existsInMainProfile) {
|
||||
long rawContactId = -1;//new raw contact
|
||||
|
||||
Log.d(Constants.TAG, "masterKeyId with secret " + masterKeyId);
|
||||
Timber.d("masterKeyId with secret " + masterKeyId);
|
||||
|
||||
ArrayList<ContentProviderOperation> ops = new ArrayList<>();
|
||||
insertMainProfileRawContact(ops, masterKeyId);
|
||||
@@ -603,7 +605,7 @@ public class ContactHelper {
|
||||
try {
|
||||
mContentResolver.applyBatch(ContactsContract.AUTHORITY, ops);
|
||||
} catch (Exception e) {
|
||||
Log.w(Constants.TAG, e);
|
||||
Timber.w(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -614,7 +616,7 @@ public class ContactHelper {
|
||||
|
||||
for (long masterKeyId : keysToDelete) {
|
||||
deleteMainProfileRawContactByMasterKeyId(masterKeyId);
|
||||
Log.d(Constants.TAG, "Delete main profile raw contact with masterKeyId " + masterKeyId);
|
||||
Timber.d("Delete main profile raw contact with masterKeyId " + masterKeyId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -684,7 +686,7 @@ public class ContactHelper {
|
||||
Uri deleteUri = ContactsContract.RawContacts.CONTENT_URI.buildUpon().
|
||||
appendQueryParameter(ContactsContract.CALLER_IS_SYNCADAPTER, "true").build();
|
||||
|
||||
Log.d(Constants.TAG, "Deleting all raw contacts associated to OK...");
|
||||
Timber.d("Deleting all raw contacts associated to OK...");
|
||||
int delete = mContentResolver.delete(deleteUri,
|
||||
ContactsContract.RawContacts.ACCOUNT_TYPE + "=?",
|
||||
new String[]{
|
||||
|
||||
@@ -54,6 +54,8 @@ import android.widget.Toast;
|
||||
|
||||
import org.sufficientlysecure.keychain.Constants;
|
||||
import org.sufficientlysecure.keychain.R;
|
||||
import timber.log.Timber;
|
||||
|
||||
|
||||
/** This class offers a number of helper functions for saving documents.
|
||||
*
|
||||
@@ -241,7 +243,7 @@ public class FileHelper {
|
||||
if (br != null)
|
||||
br.close();
|
||||
} catch (IOException e) {
|
||||
Log.e(Constants.TAG, "Error closing file", e);
|
||||
Timber.e(e, "Error closing file");
|
||||
}
|
||||
}
|
||||
return isEncrypted;
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
|
||||
package org.sufficientlysecure.keychain.util;
|
||||
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
@@ -32,7 +33,8 @@ import android.system.ErrnoException;
|
||||
import android.system.Os;
|
||||
import android.system.StructStat;
|
||||
|
||||
import org.sufficientlysecure.keychain.Constants;
|
||||
import timber.log.Timber;
|
||||
|
||||
|
||||
/**
|
||||
* FileHelper methods which use Lollipop-exclusive API.
|
||||
@@ -67,11 +69,11 @@ class FileHelperLollipop {
|
||||
try {
|
||||
final StructStat st = Os.fstat(pfd.getFileDescriptor());
|
||||
if (st.st_uid == android.os.Process.myUid()) {
|
||||
Log.e(Constants.TAG, "File is owned by the application itself, aborting!");
|
||||
Timber.e("File is owned by the application itself, aborting!");
|
||||
throw new FileNotFoundException("Unable to create stream");
|
||||
}
|
||||
} catch (ErrnoException e) {
|
||||
Log.e(Constants.TAG, "fstat() failed: " + e);
|
||||
Timber.e("fstat() failed: " + e);
|
||||
throw new FileNotFoundException("fstat() failed");
|
||||
}
|
||||
|
||||
|
||||
@@ -1,161 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2017 Schürmann & Breitmoser GbR
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.sufficientlysecure.keychain.util;
|
||||
|
||||
import android.os.Bundle;
|
||||
|
||||
import org.sufficientlysecure.keychain.Constants;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Wraps Android Logging to enable or disable debug output using Constants
|
||||
*/
|
||||
public final class Log {
|
||||
|
||||
public static void v(String tag, String msg) {
|
||||
if (Constants.DEBUG) {
|
||||
android.util.Log.v(tag, msg);
|
||||
}
|
||||
}
|
||||
|
||||
public static void v(String tag, String msg, Throwable tr) {
|
||||
if (Constants.DEBUG) {
|
||||
android.util.Log.v(tag, msg, tr);
|
||||
}
|
||||
}
|
||||
|
||||
public static void d(String tag, String msg) {
|
||||
if (Constants.DEBUG) {
|
||||
android.util.Log.d(tag, msg);
|
||||
}
|
||||
}
|
||||
|
||||
public static void d(String tag, String msg, Throwable tr) {
|
||||
if (Constants.DEBUG) {
|
||||
android.util.Log.d(tag, msg, tr);
|
||||
}
|
||||
}
|
||||
|
||||
public static void dEscaped(String tag, String msg) {
|
||||
if (Constants.DEBUG) {
|
||||
android.util.Log.d(tag, removeUnicodeAndEscapeChars(msg));
|
||||
}
|
||||
}
|
||||
|
||||
public static void dEscaped(String tag, String msg, Throwable tr) {
|
||||
if (Constants.DEBUG) {
|
||||
android.util.Log.d(tag, removeUnicodeAndEscapeChars(msg), tr);
|
||||
}
|
||||
}
|
||||
|
||||
public static void i(String tag, String msg) {
|
||||
if (Constants.DEBUG) {
|
||||
android.util.Log.i(tag, msg);
|
||||
}
|
||||
}
|
||||
|
||||
public static void i(String tag, String msg, Throwable tr) {
|
||||
if (Constants.DEBUG) {
|
||||
android.util.Log.i(tag, msg, tr);
|
||||
}
|
||||
}
|
||||
|
||||
public static void w(String tag, String msg) {
|
||||
android.util.Log.w(tag, msg);
|
||||
}
|
||||
|
||||
public static void w(String tag, String msg, Throwable tr) {
|
||||
android.util.Log.w(tag, msg, tr);
|
||||
}
|
||||
|
||||
public static void w(String tag, Throwable tr) {
|
||||
android.util.Log.w(tag, tr);
|
||||
}
|
||||
|
||||
public static void e(String tag, String msg) {
|
||||
android.util.Log.e(tag, msg);
|
||||
}
|
||||
|
||||
public static void e(String tag, String msg, Throwable tr) {
|
||||
android.util.Log.e(tag, msg, tr);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Logs bundle content to debug for inspecting the content
|
||||
*
|
||||
* @param bundle
|
||||
* @param bundleName
|
||||
*/
|
||||
public static void logDebugBundle(Bundle bundle, String bundleName) {
|
||||
if (Constants.DEBUG) {
|
||||
if (bundle != null) {
|
||||
Set<String> ks = bundle.keySet();
|
||||
Iterator<String> iterator = ks.iterator();
|
||||
|
||||
Log.d(Constants.TAG, "Bundle " + bundleName + ":");
|
||||
Log.d(Constants.TAG, "------------------------------");
|
||||
while (iterator.hasNext()) {
|
||||
String key = iterator.next();
|
||||
Object value = bundle.get(key);
|
||||
|
||||
if (value != null) {
|
||||
Log.d(Constants.TAG, key + " : " + value.toString());
|
||||
} else {
|
||||
Log.d(Constants.TAG, key + " : null");
|
||||
}
|
||||
}
|
||||
Log.d(Constants.TAG, "------------------------------");
|
||||
} else {
|
||||
Log.d(Constants.TAG, "Bundle " + bundleName + ": null");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static String removeUnicodeAndEscapeChars(String input) {
|
||||
StringBuilder buffer = new StringBuilder(input.length());
|
||||
for (int i = 0; i < input.length(); i++) {
|
||||
if ((int) input.charAt(i) > 256) {
|
||||
buffer.append("\\u").append(Integer.toHexString((int) input.charAt(i)));
|
||||
} else {
|
||||
if (input.charAt(i) == '\n') {
|
||||
buffer.append("\\n");
|
||||
} else if (input.charAt(i) == '\t') {
|
||||
buffer.append("\\t");
|
||||
} else if (input.charAt(i) == '\r') {
|
||||
buffer.append("\\r");
|
||||
} else if (input.charAt(i) == '\b') {
|
||||
buffer.append("\\b");
|
||||
} else if (input.charAt(i) == '\f') {
|
||||
buffer.append("\\f");
|
||||
} else if (input.charAt(i) == '\'') {
|
||||
buffer.append("\\'");
|
||||
} else if (input.charAt(i) == '\"') {
|
||||
buffer.append("\\");
|
||||
} else if (input.charAt(i) == '\\') {
|
||||
buffer.append("\\\\");
|
||||
} else {
|
||||
buffer.append(input.charAt(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
return buffer.toString();
|
||||
}
|
||||
}
|
||||
@@ -29,6 +29,9 @@ import java.security.SecureRandom;
|
||||
import java.security.SecureRandomSpi;
|
||||
import java.security.Security;
|
||||
|
||||
import timber.log.Timber;
|
||||
|
||||
|
||||
/**
|
||||
* Fixes for the output of the default PRNG having low entropy.
|
||||
* <p/>
|
||||
@@ -245,8 +248,7 @@ public final class PRNGFixes {
|
||||
} catch (IOException e) {
|
||||
// On a small fraction of devices /dev/urandom is not writable.
|
||||
// Log and ignore.
|
||||
Log.w(PRNGFixes.class.getSimpleName(),
|
||||
"Failed to mix seed into " + URANDOM_FILE);
|
||||
Timber.w("Failed to mix seed into " + URANDOM_FILE);
|
||||
} finally {
|
||||
mSeeded = true;
|
||||
}
|
||||
|
||||
@@ -17,12 +17,6 @@
|
||||
|
||||
package org.sufficientlysecure.keychain.util;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
|
||||
import org.sufficientlysecure.keychain.Constants;
|
||||
import org.sufficientlysecure.keychain.KeychainApplication;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
@@ -34,6 +28,13 @@ import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Iterator;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
|
||||
import org.sufficientlysecure.keychain.KeychainApplication;
|
||||
import timber.log.Timber;
|
||||
|
||||
/**
|
||||
* When sending large data (over 1MB) through Androids Binder IPC you get
|
||||
* JavaBinder E !!! FAILED BINDER TRANSACTION !!!
|
||||
@@ -127,7 +128,7 @@ public class ParcelableFileCache<E extends Parcelable> {
|
||||
try {
|
||||
ois = new DataInputStream(new FileInputStream(tempFile));
|
||||
} catch (FileNotFoundException e) {
|
||||
Log.e(Constants.TAG, "parcel import file not existing", e);
|
||||
Timber.e(e, "parcel import file not existing");
|
||||
throw new IOException(e);
|
||||
}
|
||||
|
||||
@@ -165,7 +166,7 @@ public class ParcelableFileCache<E extends Parcelable> {
|
||||
// aight
|
||||
close();
|
||||
} catch (IOException e) {
|
||||
Log.e(Constants.TAG, "Encountered IOException during cache read!", e);
|
||||
Timber.e(e, "Encountered IOException during cache read!");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -37,6 +37,8 @@ import org.sufficientlysecure.keychain.Constants.Pref;
|
||||
import org.sufficientlysecure.keychain.KeychainApplication;
|
||||
import org.sufficientlysecure.keychain.keyimport.HkpKeyserverAddress;
|
||||
import org.sufficientlysecure.keychain.service.KeyserverSyncAdapterService;
|
||||
import timber.log.Timber;
|
||||
|
||||
|
||||
/**
|
||||
* Singleton Implementation of a Preference Helper
|
||||
@@ -279,7 +281,7 @@ public class Preferences {
|
||||
case typeSocks:
|
||||
return Proxy.Type.SOCKS;
|
||||
default: // shouldn't happen
|
||||
Log.e(Constants.TAG, "Invalid Proxy Type in preferences");
|
||||
Timber.e("Invalid Proxy Type in preferences");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -422,7 +424,7 @@ public class Preferences {
|
||||
}
|
||||
|
||||
public void upgradePreferences(Context context) {
|
||||
Log.d(Constants.TAG, "Upgrading preferences…");
|
||||
Timber.d("Upgrading preferences…");
|
||||
int oldVersion = mSharedPreferences.getInt(Constants.Pref.PREF_VERSION, 0);
|
||||
boolean requiresUpgrade = oldVersion < Constants.Defaults.PREF_CURRENT_VERSION;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user