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

@@ -41,7 +41,8 @@ import org.sufficientlysecure.keychain.KeychainApplication;
import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.ui.SettingsActivity;
import org.sufficientlysecure.keychain.util.ContactHelper;
import org.sufficientlysecure.keychain.util.Log;
import timber.log.Timber;
public class ContactSyncAdapterService extends Service {
@@ -58,7 +59,7 @@ public class ContactSyncAdapterService extends Service {
@Override
public void onPerformSync(Account account, Bundle extras, String authority, ContentProviderClient provider,
final SyncResult syncResult) {
Log.d(Constants.TAG, "Performing a contact sync!");
Timber.d("Performing a contact sync!");
new ContactHelper(ContactSyncAdapterService.this).writeKeysToContacts();

View File

@@ -30,9 +30,9 @@ import android.os.IBinder;
import android.os.Message;
import android.widget.Toast;
import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.util.Log;
import timber.log.Timber;
/**
* This service actually does nothing, it's sole task is to show a Toast if the use tries to create an account.
@@ -75,7 +75,7 @@ public class DummyAccountService extends Service {
@Override
public Bundle editProperties(AccountAuthenticatorResponse response, String accountType) {
Log.d(Constants.TAG, "DummyAccountService.editProperties");
Timber.d("DummyAccountService.editProperties");
return null;
}
@@ -84,41 +84,41 @@ public class DummyAccountService extends Service {
String[] requiredFeatures, Bundle options) throws NetworkErrorException {
response.onResult(new Bundle());
toaster.toast(R.string.account_no_manual_account_creation);
Log.d(Constants.TAG, "DummyAccountService.addAccount");
Timber.d("DummyAccountService.addAccount");
return null;
}
@Override
public Bundle confirmCredentials(AccountAuthenticatorResponse response, Account account, Bundle options)
throws NetworkErrorException {
Log.d(Constants.TAG, "DummyAccountService.confirmCredentials");
Timber.d("DummyAccountService.confirmCredentials");
return null;
}
@Override
public Bundle getAuthToken(AccountAuthenticatorResponse response, Account account, String authTokenType,
Bundle options) throws NetworkErrorException {
Log.d(Constants.TAG, "DummyAccountService.getAuthToken");
Timber.d("DummyAccountService.getAuthToken");
return null;
}
@Override
public String getAuthTokenLabel(String authTokenType) {
Log.d(Constants.TAG, "DummyAccountService.getAuthTokenLabel");
Timber.d("DummyAccountService.getAuthTokenLabel");
return null;
}
@Override
public Bundle updateCredentials(AccountAuthenticatorResponse response, Account account, String authTokenType,
Bundle options) throws NetworkErrorException {
Log.d(Constants.TAG, "DummyAccountService.updateCredentials");
Timber.d("DummyAccountService.updateCredentials");
return null;
}
@Override
public Bundle hasFeatures(AccountAuthenticatorResponse response, Account account, String[] features)
throws NetworkErrorException {
Log.d(Constants.TAG, "DummyAccountService.hasFeatures");
Timber.d("DummyAccountService.hasFeatures");
return null;
}
}

View File

@@ -29,7 +29,6 @@ import android.os.Messenger;
import android.os.Parcelable;
import android.os.RemoteException;
import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.operations.BackupOperation;
import org.sufficientlysecure.keychain.operations.BaseOperation;
import org.sufficientlysecure.keychain.operations.BenchmarkOperation;
@@ -52,7 +51,8 @@ import org.sufficientlysecure.keychain.pgp.SignEncryptParcel;
import org.sufficientlysecure.keychain.provider.KeyWritableRepository;
import org.sufficientlysecure.keychain.service.ServiceProgressHandler.MessageStatus;
import org.sufficientlysecure.keychain.service.input.CryptoInputParcel;
import org.sufficientlysecure.keychain.util.Log;
import timber.log.Timber;
/**
* This Service contains all important long lasting operations for OpenKeychain. It receives Intents with
@@ -172,9 +172,9 @@ public class KeychainService extends Service implements Progressable {
try {
mMessenger.get().send(msg);
} catch (RemoteException e) {
Log.w(Constants.TAG, "Exception sending message, Is handler present?", e);
Timber.w(e, "Exception sending message, Is handler present?");
} catch (NullPointerException e) {
Log.w(Constants.TAG, "Messenger is null!", e);
Timber.w(e, "Messenger is null!");
}
}
@@ -193,7 +193,7 @@ public class KeychainService extends Service implements Progressable {
*/
@Override
public void setProgress(String message, int progress, int max) {
Log.d(Constants.TAG, "Send message by setProgress with progress=" + progress + ", max="
Timber.d("Send message by setProgress with progress=" + progress + ", max="
+ max);
Bundle data = new Bundle();

View File

@@ -66,9 +66,10 @@ import org.sufficientlysecure.keychain.provider.KeychainContract;
import org.sufficientlysecure.keychain.service.input.CryptoInputParcel;
import org.sufficientlysecure.keychain.ui.OrbotRequiredDialogActivity;
import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils;
import org.sufficientlysecure.keychain.util.Log;
import org.sufficientlysecure.keychain.util.ParcelableProxy;
import org.sufficientlysecure.keychain.util.Preferences;
import timber.log.Timber;
public class KeyserverSyncAdapterService extends Service {
@@ -215,7 +216,7 @@ public class KeyserverSyncAdapterService extends Service {
return;
}
}
Log.d(Constants.TAG, "Performing a keyserver sync!");
Timber.d("Performing a keyserver sync!");
PowerManager pm = (PowerManager) KeyserverSyncAdapterService.this
.getSystemService(Context.POWER_SERVICE);
@SuppressWarnings("deprecation") // our min is API 15, deprecated only in 20
@@ -249,7 +250,7 @@ public class KeyserverSyncAdapterService extends Service {
*/
private void handleUpdateResult(ImportKeyResult result, final int startId) {
if (result.isPending()) {
Log.d(Constants.TAG, "Orbot required for sync but not running, attempting to start");
Timber.d("Orbot required for sync but not running, attempting to start");
// result is pending due to Orbot not being started
// try to start it silently, if disabled show notifications
new OrbotHelper.SilentStartManager() {
@@ -275,13 +276,13 @@ public class KeyserverSyncAdapterService extends Service {
// if we're killed before we get a response from Orbot, we need the intent to be
// redelivered, so no stopSelf(int) here
} else if (isUpdateCancelled()) {
Log.d(Constants.TAG, "Keyserver sync cancelled, postponing by" + SYNC_POSTPONE_TIME
Timber.d("Keyserver sync cancelled, postponing by" + SYNC_POSTPONE_TIME
+ "ms");
postponeSync();
// postponeSync creates a new intent, so we don't need this to be redelivered
stopSelf(startId);
} else {
Log.d(Constants.TAG, "Keyserver sync completed: Updated: " + result.mUpdatedKeys
Timber.d("Keyserver sync completed: Updated: " + result.mUpdatedKeys
+ " Failed: " + result.mBadKeys);
// key sync completed successfully, we can stop
stopSelf(startId);
@@ -337,7 +338,7 @@ public class KeyserverSyncAdapterService extends Service {
private ImportKeyResult directUpdate(Context context, ArrayList<ParcelableKeyRing> keyList,
CryptoInputParcel cryptoInputParcel) {
Log.d(Constants.TAG, "Starting normal update");
Timber.d("Starting normal update");
ImportOperation importOp = new ImportOperation(context,
KeyWritableRepository.create(context), null);
return importOp.execute(
@@ -356,7 +357,7 @@ public class KeyserverSyncAdapterService extends Service {
*/
private ImportKeyResult staggeredUpdate(Context context, ArrayList<ParcelableKeyRing> keyList,
CryptoInputParcel cryptoInputParcel) {
Log.d(Constants.TAG, "Starting staggered update");
Timber.d("Starting staggered update");
// final int WEEK_IN_SECONDS = (int) TimeUnit.DAYS.toSeconds(7);
// we are limiting our randomness to ORBOT_CIRCUIT_TIMEOUT_SECONDS for now
final int WEEK_IN_SECONDS = 0;
@@ -383,11 +384,11 @@ public class KeyserverSyncAdapterService extends Service {
first = false;
}
Log.d(Constants.TAG, "Updating key with a wait time of " + waitTime + "s");
Timber.d("Updating key with a wait time of " + waitTime + "s");
try {
Thread.sleep(waitTime * 1000);
} catch (InterruptedException e) {
Log.e(Constants.TAG, "Exception during sleep between key updates", e);
Timber.e(e, "Exception during sleep between key updates");
// skip this one
continue;
}
@@ -445,7 +446,7 @@ public class KeyserverSyncAdapterService extends Service {
ArrayList<Long> ignoreMasterKeyIds = new ArrayList<>();
while (updatedKeysCursor != null && updatedKeysCursor.moveToNext()) {
long masterKeyId = updatedKeysCursor.getLong(INDEX_UPDATED_KEYS_MASTER_KEY_ID);
Log.d(Constants.TAG, "Keyserver sync: Ignoring {" + masterKeyId + "} last updated at {"
Timber.d("Keyserver sync: Ignoring {" + masterKeyId + "} last updated at {"
+ updatedKeysCursor.getLong(INDEX_LAST_UPDATED) + "}s");
ignoreMasterKeyIds.add(masterKeyId);
}
@@ -477,7 +478,7 @@ public class KeyserverSyncAdapterService extends Service {
if (ignoreMasterKeyIds.contains(keyId)) {
continue;
}
Log.d(Constants.TAG, "Keyserver sync: Updating {" + keyId + "}");
Timber.d("Keyserver sync: Updating {" + keyId + "}");
byte[] fingerprint = keyCursor.getBlob(INDEX_FINGERPRINT);
String hexKeyId = KeyFormattingUtils.convertKeyIdToHex(keyId);
// we aren't updating from keybase as of now

View File

@@ -42,9 +42,9 @@ import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKey.SecretKeyType;
import org.sufficientlysecure.keychain.provider.CachedPublicKeyRing;
import org.sufficientlysecure.keychain.provider.KeyRepository;
import org.sufficientlysecure.keychain.util.Log;
import org.sufficientlysecure.keychain.util.Passphrase;
import org.sufficientlysecure.keychain.util.Preferences;
import timber.log.Timber;
import java.util.Date;
@@ -122,7 +122,7 @@ public class PassphraseCacheService extends Service {
Passphrase passphrase,
String primaryUserId,
int timeToLiveSeconds) {
Log.d(Constants.TAG, "PassphraseCacheService.addCachedPassphrase() for " + masterKeyId);
Timber.d("PassphraseCacheService.addCachedPassphrase() for " + masterKeyId);
Intent intent = new Intent(context, PassphraseCacheService.class);
intent.setAction(ACTION_PASSPHRASE_CACHE_ADD);
@@ -137,7 +137,7 @@ public class PassphraseCacheService extends Service {
}
public static void clearCachedPassphrase(Context context, long masterKeyId, long subKeyId) {
Log.d(Constants.TAG, "PassphraseCacheService.clearCachedPassphrase() for " + masterKeyId);
Timber.d("PassphraseCacheService.clearCachedPassphrase() for " + masterKeyId);
Intent intent = new Intent(context, PassphraseCacheService.class);
intent.setAction(ACTION_PASSPHRASE_CACHE_CLEAR);
@@ -149,7 +149,7 @@ public class PassphraseCacheService extends Service {
}
public static void clearCachedPassphrases(Context context) {
Log.d(Constants.TAG, "PassphraseCacheService.clearCachedPassphrase()");
Timber.d("PassphraseCacheService.clearCachedPassphrase()");
Intent intent = new Intent(context, PassphraseCacheService.class);
intent.setAction(ACTION_PASSPHRASE_CACHE_CLEAR);
@@ -164,7 +164,7 @@ public class PassphraseCacheService extends Service {
* @return passphrase or null (if no passphrase is cached for this keyId)
*/
public static Passphrase getCachedPassphrase(Context context, long masterKeyId, long subKeyId) throws KeyNotFoundException {
Log.d(Constants.TAG, "PassphraseCacheService.getCachedPassphrase() for masterKeyId "
Timber.d("PassphraseCacheService.getCachedPassphrase() for masterKeyId "
+ masterKeyId + ", subKeyId " + subKeyId);
Intent intent = new Intent(context, PassphraseCacheService.class);
@@ -216,7 +216,7 @@ public class PassphraseCacheService extends Service {
case MSG_PASSPHRASE_CACHE_GET_KEY_NOT_FOUND:
throw new KeyNotFoundException();
default:
Log.e(Constants.TAG, "timeout case!");
Timber.e("timeout case!");
throw new KeyNotFoundException("should not happen!");
}
}
@@ -232,7 +232,7 @@ public class PassphraseCacheService extends Service {
// passphrase for symmetric encryption?
if (masterKeyId == Constants.key.symmetric) {
Log.d(Constants.TAG, "PassphraseCacheService.getCachedPassphraseImpl() for symmetric encryption");
Timber.d("PassphraseCacheService.getCachedPassphraseImpl() for symmetric encryption");
CachedPassphrase cachedPassphrase = mPassphraseCache.get(Constants.key.symmetric);
if (cachedPassphrase == null) {
return null;
@@ -241,7 +241,7 @@ public class PassphraseCacheService extends Service {
}
// try to get master key id which is used as an identifier for cached passphrases
Log.d(Constants.TAG, "PassphraseCacheService.getCachedPassphraseImpl() for masterKeyId "
Timber.d("PassphraseCacheService.getCachedPassphraseImpl() for masterKeyId "
+ masterKeyId + ", subKeyId " + subKeyId);
// get the type of key (from the database)
@@ -263,13 +263,13 @@ public class PassphraseCacheService extends Service {
// If we cache strictly by subkey, exit early
if (Preferences.getPreferences(mContext).getPassphraseCacheSubs()) {
Log.d(Constants.TAG, "PassphraseCacheService: specific subkey passphrase not (yet) cached, returning null");
Timber.d("PassphraseCacheService: specific subkey passphrase not (yet) cached, returning null");
// not really an error, just means the passphrase is not cached but not empty either
return null;
}
if (subKeyId == masterKeyId) {
Log.d(Constants.TAG, "PassphraseCacheService: masterkey passphrase not (yet) cached, returning null");
Timber.d("PassphraseCacheService: masterkey passphrase not (yet) cached, returning null");
// not really an error, just means the passphrase is not cached but not empty either
return null;
}
@@ -277,7 +277,7 @@ public class PassphraseCacheService extends Service {
cachedPassphrase = mPassphraseCache.get(masterKeyId);
// If we cache strictly by subkey, exit early
if (cachedPassphrase == null) {
Log.d(Constants.TAG, "PassphraseCacheService: keyring passphrase not (yet) cached, returning null");
Timber.d("PassphraseCacheService: keyring passphrase not (yet) cached, returning null");
// not really an error, just means the passphrase is not cached but not empty either
return null;
}
@@ -299,7 +299,7 @@ public class PassphraseCacheService extends Service {
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
Log.d(Constants.TAG, "PassphraseCacheService: Received broadcast...");
Timber.d("PassphraseCacheService: Received broadcast...");
if (action.equals(BROADCAST_ACTION_PASSPHRASE_CACHE_SERVICE)) {
long keyId = intent.getLongExtra(EXTRA_KEY_ID, -1);
@@ -335,7 +335,7 @@ public class PassphraseCacheService extends Service {
*/
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Log.d(Constants.TAG, "PassphraseCacheService.onStartCommand()");
Timber.d("PassphraseCacheService.onStartCommand()");
if (intent == null || intent.getAction() == null) {
updateService();
@@ -352,10 +352,10 @@ public class PassphraseCacheService extends Service {
Passphrase passphrase = intent.getParcelableExtra(EXTRA_PASSPHRASE);
String primaryUserID = intent.getStringExtra(EXTRA_USER_ID);
Log.d(Constants.TAG,
Timber.d(
"PassphraseCacheService: Received ACTION_PASSPHRASE_CACHE_ADD intent in onStartCommand() with masterkeyId: "
+ masterKeyId + ", subKeyId: " + subKeyId + ", ttl: " + timeoutTtl + ", usrId: " + primaryUserID
);
+ masterKeyId + ", subKeyId: " + subKeyId + ", ttl: " + timeoutTtl + ", usrId: " +
primaryUserID);
// if we don't cache by specific subkey id, or the requested subkey is the master key,
// just add master key id to the cache, otherwise, add this specific subkey to the cache
@@ -389,7 +389,7 @@ public class PassphraseCacheService extends Service {
try {
// If only one of these is symmetric, error out!
if (masterKeyId == Constants.key.symmetric ^ subKeyId == Constants.key.symmetric) {
Log.e(Constants.TAG, "PassphraseCacheService: Bad request, missing masterKeyId or subKeyId!");
Timber.e("PassphraseCacheService: Bad request, missing masterKeyId or subKeyId!");
msg.what = MSG_PASSPHRASE_CACHE_GET_KEY_NOT_FOUND;
} else {
Passphrase passphrase = getCachedPassphraseImpl(masterKeyId, subKeyId);
@@ -399,14 +399,14 @@ public class PassphraseCacheService extends Service {
msg.setData(bundle);
}
} catch (KeyRepository.NotFoundException e) {
Log.e(Constants.TAG, "PassphraseCacheService: Passphrase for unknown key was requested!");
Timber.e("PassphraseCacheService: Passphrase for unknown key was requested!");
msg.what = MSG_PASSPHRASE_CACHE_GET_KEY_NOT_FOUND;
}
try {
messenger.send(msg);
} catch (RemoteException e) {
Log.e(Constants.TAG, "PassphraseCacheService: Sending message failed", e);
Timber.e(e, "PassphraseCacheService: Sending message failed");
}
break;
}
@@ -440,7 +440,7 @@ public class PassphraseCacheService extends Service {
break;
}
default: {
Log.e(Constants.TAG, "PassphraseCacheService: Intent or Intent Action not supported!");
Timber.e("PassphraseCacheService: Intent or Intent Action not supported!");
break;
}
}
@@ -463,7 +463,7 @@ public class PassphraseCacheService extends Service {
mPassphraseCache.remove(keyId);
}
Log.d(Constants.TAG, "PassphraseCacheService Timeout of keyId " + keyId + ", removed from memory!");
Timber.d("PassphraseCacheService Timeout of keyId " + keyId + ", removed from memory!");
updateService();
}
@@ -481,7 +481,7 @@ public class PassphraseCacheService extends Service {
i += 1;
}
Log.d(Constants.TAG, "PassphraseCacheService Removing all cached-until-lock passphrases from memory!");
Timber.d("PassphraseCacheService Removing all cached-until-lock passphrases from memory!");
updateService();
}
@@ -491,7 +491,7 @@ public class PassphraseCacheService extends Service {
startForeground(Constants.Notification.PASSPHRASE_CACHE, getNotification());
} else {
// stop whole service if no cached passphrases remaining
Log.d(Constants.TAG, "PassphraseCacheService: No passphrases remaining in memory, stopping service!");
Timber.d("PassphraseCacheService: No passphrases remaining in memory, stopping service!");
stopForeground(true);
stopSelf();
}
@@ -544,7 +544,7 @@ public class PassphraseCacheService extends Service {
public void onCreate() {
super.onCreate();
mContext = this;
Log.d(Constants.TAG, "PassphraseCacheService, onCreate()");
Timber.d("PassphraseCacheService, onCreate()");
registerReceiver();
}
@@ -552,7 +552,7 @@ public class PassphraseCacheService extends Service {
@Override
public void onDestroy() {
super.onDestroy();
Log.d(Constants.TAG, "PassphraseCacheService, onDestroy()");
Timber.d("PassphraseCacheService, onDestroy()");
unregisterReceiver(mIntentReceiver);
}

View File

@@ -25,11 +25,11 @@ import android.os.Message;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.ui.dialog.ProgressDialogFragment;
import org.sufficientlysecure.keychain.ui.util.Notify;
import org.sufficientlysecure.keychain.util.Log;
import timber.log.Timber;
public class ServiceProgressHandler extends Handler {
@@ -144,7 +144,7 @@ public class ServiceProgressHandler extends Handler {
break;
default:
Log.e(Constants.TAG, "unknown handler message!");
Timber.e("unknown handler message!");
break;
}
}