1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-11-24 10:22:15 -05:00

Log message cleanup

This commit is contained in:
Jesse Vincent 2010-01-03 01:50:32 +00:00
parent f9e8c877ff
commit 875dc31d5a
6 changed files with 72 additions and 60 deletions

View File

@ -54,6 +54,7 @@ public class BootReceiver extends BroadcastReceiver
} }
else else
{ {
if (K9.DEBUG)
Log.w(K9.LOG_TAG, "BootReceiver WakeLock " + wakeLockId + " doesn't exist"); Log.w(K9.LOG_TAG, "BootReceiver WakeLock " + wakeLockId + " doesn't exist");
} }
} }
@ -64,6 +65,7 @@ public class BootReceiver extends BroadcastReceiver
Integer tmpWakeLockId = getWakeLock(context); Integer tmpWakeLockId = getWakeLock(context);
try try
{ {
if (K9.DEBUG)
Log.i(K9.LOG_TAG, "BootReceiver.onReceive" + intent); Log.i(K9.LOG_TAG, "BootReceiver.onReceive" + intent);
if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction()))
@ -97,6 +99,7 @@ public class BootReceiver extends BroadcastReceiver
Intent alarmedIntent = intent.getParcelableExtra(ALARMED_INTENT); Intent alarmedIntent = intent.getParcelableExtra(ALARMED_INTENT);
String alarmedAction = alarmedIntent.getAction(); String alarmedAction = alarmedIntent.getAction();
if (K9.DEBUG)
Log.i(K9.LOG_TAG, "BootReceiver Got alarm to fire alarmedIntent " + alarmedAction); Log.i(K9.LOG_TAG, "BootReceiver Got alarm to fire alarmedIntent " + alarmedAction);
alarmedIntent.putExtra(WAKE_LOCK_ID, tmpWakeLockId); alarmedIntent.putExtra(WAKE_LOCK_ID, tmpWakeLockId);
tmpWakeLockId = null; tmpWakeLockId = null;
@ -109,6 +112,7 @@ public class BootReceiver extends BroadcastReceiver
{ {
long atTime = intent.getLongExtra(AT_TIME, -1); long atTime = intent.getLongExtra(AT_TIME, -1);
Intent alarmedIntent = intent.getParcelableExtra(ALARMED_INTENT); Intent alarmedIntent = intent.getParcelableExtra(ALARMED_INTENT);
if (K9.DEBUG)
Log.i(K9.LOG_TAG,"BootReceiver Scheduling intent " + alarmedIntent + " for " + new Date(atTime)); Log.i(K9.LOG_TAG,"BootReceiver Scheduling intent " + alarmedIntent + " for " + new Date(atTime));
PendingIntent pi = buildPendingIntent(context, intent); PendingIntent pi = buildPendingIntent(context, intent);
@ -119,6 +123,7 @@ public class BootReceiver extends BroadcastReceiver
else if (CANCEL_INTENT.equals(intent.getAction())) else if (CANCEL_INTENT.equals(intent.getAction()))
{ {
Intent alarmedIntent = intent.getParcelableExtra(ALARMED_INTENT); Intent alarmedIntent = intent.getParcelableExtra(ALARMED_INTENT);
if (K9.DEBUG)
Log.i(K9.LOG_TAG, "BootReceiver Canceling alarmedIntent " + alarmedIntent); Log.i(K9.LOG_TAG, "BootReceiver Canceling alarmedIntent " + alarmedIntent);
PendingIntent pi = buildPendingIntent(context, intent); PendingIntent pi = buildPendingIntent(context, intent);
@ -131,6 +136,7 @@ public class BootReceiver extends BroadcastReceiver
Integer wakeLockId = intent.getIntExtra(WAKE_LOCK_ID, -1); Integer wakeLockId = intent.getIntExtra(WAKE_LOCK_ID, -1);
if (wakeLockId != -1) if (wakeLockId != -1)
{ {
if (K9.DEBUG)
Log.i(K9.LOG_TAG, "BootReceiver Release wakeLock " + wakeLockId); Log.i(K9.LOG_TAG, "BootReceiver Release wakeLock " + wakeLockId);
releaseWakeLock(wakeLockId); releaseWakeLock(wakeLockId);
} }
@ -158,6 +164,7 @@ public class BootReceiver extends BroadcastReceiver
public static void scheduleIntent(Context context, long atTime, Intent alarmedIntent) public static void scheduleIntent(Context context, long atTime, Intent alarmedIntent)
{ {
if (K9.DEBUG)
Log.i(K9.LOG_TAG, "BootReceiver Got request to schedule alarmedIntent " + alarmedIntent.getAction()); Log.i(K9.LOG_TAG, "BootReceiver Got request to schedule alarmedIntent " + alarmedIntent.getAction());
Intent i = new Intent(); Intent i = new Intent();
i.setClass(context, BootReceiver.class); i.setClass(context, BootReceiver.class);
@ -169,6 +176,7 @@ public class BootReceiver extends BroadcastReceiver
public static void cancelIntent(Context context, Intent alarmedIntent) public static void cancelIntent(Context context, Intent alarmedIntent)
{ {
if (K9.DEBUG)
Log.i(K9.LOG_TAG, "BootReceiver Got request to cancel alarmedIntent " + alarmedIntent.getAction()); Log.i(K9.LOG_TAG, "BootReceiver Got request to cancel alarmedIntent " + alarmedIntent.getAction());
Intent i = new Intent(); Intent i = new Intent();
i.setClass(context, BootReceiver.class); i.setClass(context, BootReceiver.class);
@ -179,6 +187,7 @@ public class BootReceiver extends BroadcastReceiver
public static void releaseWakeLock(Context context, int wakeLockId) public static void releaseWakeLock(Context context, int wakeLockId)
{ {
if (K9.DEBUG)
Log.i(K9.LOG_TAG, "BootReceiver Got request to release wakeLock " + wakeLockId); Log.i(K9.LOG_TAG, "BootReceiver Got request to release wakeLock " + wakeLockId);
Intent i = new Intent(); Intent i = new Intent();
i.setClass(context, BootReceiver.class); i.setClass(context, BootReceiver.class);

View File

@ -49,6 +49,7 @@ public abstract class CoreService extends Service
wakeLock.setReferenceCounted(false); wakeLock.setReferenceCounted(false);
wakeLock.acquire(K9.MAIL_SERVICE_WAKE_LOCK_TIMEOUT); wakeLock.acquire(K9.MAIL_SERVICE_WAKE_LOCK_TIMEOUT);
if (K9.DEBUG)
Log.i(K9.LOG_TAG, "CoreService: " + this.getClass().getName() + ".onStart(" + intent + ", " + startId); Log.i(K9.LOG_TAG, "CoreService: " + this.getClass().getName() + ".onStart(" + intent + ", " + startId);
int wakeLockId = intent.getIntExtra(BootReceiver.WAKE_LOCK_ID, -1); int wakeLockId = intent.getIntExtra(BootReceiver.WAKE_LOCK_ID, -1);
@ -60,16 +61,12 @@ public abstract class CoreService extends Service
if (coreWakeLockId != null && coreWakeLockId != -1) if (coreWakeLockId != null && coreWakeLockId != -1)
{ {
if (K9.DEBUG) if (K9.DEBUG)
{
Log.d(K9.LOG_TAG, "Got core wake lock id " + coreWakeLockId); Log.d(K9.LOG_TAG, "Got core wake lock id " + coreWakeLockId);
}
WakeLock coreWakeLock = wakeLocks.remove(coreWakeLockId); WakeLock coreWakeLock = wakeLocks.remove(coreWakeLockId);
if (coreWakeLock != null) if (coreWakeLock != null)
{ {
if (K9.DEBUG) if (K9.DEBUG)
{
Log.d(K9.LOG_TAG, "Found core wake lock with id " + coreWakeLockId + ", releasing"); Log.d(K9.LOG_TAG, "Found core wake lock with id " + coreWakeLockId + ", releasing");
}
coreWakeLock.release(); coreWakeLock.release();
} }
} }
@ -102,6 +99,7 @@ public abstract class CoreService extends Service
@Override @Override
public void onDestroy() public void onDestroy()
{ {
if (K9.DEBUG)
Log.i(K9.LOG_TAG, "CoreService: " + this.getClass().getName() + ".onDestroy()"); Log.i(K9.LOG_TAG, "CoreService: " + this.getClass().getName() + ".onDestroy()");
super.onDestroy(); super.onDestroy();
// MessagingController.getInstance(getApplication()).removeListener(mListener); // MessagingController.getInstance(getApplication()).removeListener(mListener);

View File

@ -90,6 +90,7 @@ public class MailService extends CoreService
public void onCreate() public void onCreate()
{ {
super.onCreate(); super.onCreate();
if (K9.DEBUG)
Log.v(K9.LOG_TAG, "***** MailService *****: onCreate"); Log.v(K9.LOG_TAG, "***** MailService *****: onCreate");
} }
@ -121,12 +122,14 @@ public class MailService extends CoreService
} }
setForeground(true); // if it gets killed once, it'll never restart setForeground(true); // if it gets killed once, it'll never restart
if (K9.DEBUG)
Log.i(K9.LOG_TAG, "MailService.onStart(" + intent + ", " + startId Log.i(K9.LOG_TAG, "MailService.onStart(" + intent + ", " + startId
+ "), hasConnectivity = " + hasConnectivity + ", doBackground = " + doBackground); + "), hasConnectivity = " + hasConnectivity + ", doBackground = " + doBackground);
// MessagingController.getInstance(getApplication()).addListener(mListener); // MessagingController.getInstance(getApplication()).addListener(mListener);
if (ACTION_CHECK_MAIL.equals(intent.getAction())) if (ACTION_CHECK_MAIL.equals(intent.getAction()))
{ {
if (K9.DEBUG)
Log.i(K9.LOG_TAG, "***** MailService *****: checking mail"); Log.i(K9.LOG_TAG, "***** MailService *****: checking mail");
if (hasConnectivity && doBackground) if (hasConnectivity && doBackground)
@ -181,6 +184,7 @@ public class MailService extends CoreService
notifyConnectionStatus(hasConnectivity); notifyConnectionStatus(hasConnectivity);
rescheduleAll(hasConnectivity, doBackground, startIdObj); rescheduleAll(hasConnectivity, doBackground, startIdObj);
startIdObj = null; startIdObj = null;
if (K9.DEBUG)
Log.i(K9.LOG_TAG, "Got connectivity action with hasConnectivity = " + hasConnectivity + ", doBackground = " + doBackground); Log.i(K9.LOG_TAG, "Got connectivity action with hasConnectivity = " + hasConnectivity + ", doBackground = " + doBackground);
} }
else if (CANCEL_CONNECTIVITY_NOTICE.equals(intent.getAction())) else if (CANCEL_CONNECTIVITY_NOTICE.equals(intent.getAction()))
@ -195,8 +199,8 @@ public class MailService extends CoreService
stopSelf(startId); stopSelf(startId);
} }
} }
long endTime = System.currentTimeMillis(); if (K9.DEBUG)
Log.i(K9.LOG_TAG, "MailService.onStart took " + (endTime - startTime) + "ms"); Log.i(K9.LOG_TAG, "MailService.onStart took " + (System.currentTimeMillis() - startTime) + "ms");
} }
private void rescheduleAll(final boolean hasConnectivity, final boolean doBackground, final Integer startId) private void rescheduleAll(final boolean hasConnectivity, final boolean doBackground, final Integer startId)
@ -246,6 +250,7 @@ public class MailService extends CoreService
@Override @Override
public void onDestroy() public void onDestroy()
{ {
if (K9.DEBUG)
Log.v(K9.LOG_TAG, "***** MailService *****: onDestroy()"); Log.v(K9.LOG_TAG, "***** MailService *****: onDestroy()");
super.onDestroy(); super.onDestroy();
// MessagingController.getInstance(getApplication()).removeListener(mListener); // MessagingController.getInstance(getApplication()).removeListener(mListener);
@ -278,6 +283,7 @@ public class MailService extends CoreService
if (shortestInterval == -1) if (shortestInterval == -1)
{ {
if (K9.DEBUG)
Log.v(K9.LOG_TAG, "No next check scheduled for package " + getApplication().getPackageName()); Log.v(K9.LOG_TAG, "No next check scheduled for package " + getApplication().getPackageName());
cancel(); cancel();
} }
@ -286,16 +292,19 @@ public class MailService extends CoreService
long delay = (shortestInterval * (60 * 1000)); long delay = (shortestInterval * (60 * 1000));
long nextTime = System.currentTimeMillis() + delay; long nextTime = System.currentTimeMillis() + delay;
if (K9.DEBUG)
{
try try
{ {
String checkString = "Next check for package " + getApplication().getPackageName() + " scheduled for " + new Date(nextTime); Log.i(K9.LOG_TAG,
Log.i(K9.LOG_TAG, checkString); "Next check for package " + getApplication().getPackageName() + " scheduled for " + new Date(nextTime));
} }
catch (Exception e) catch (Exception e)
{ {
// I once got a NullPointerException deep in new Date(); // I once got a NullPointerException deep in new Date();
Log.e(K9.LOG_TAG, "Exception while logging", e); Log.e(K9.LOG_TAG, "Exception while logging", e);
} }
}
Intent i = new Intent(); Intent i = new Intent();
i.setClassName(getApplication().getPackageName(), "com.fsck.k9.service.MailService"); i.setClassName(getApplication().getPackageName(), "com.fsck.k9.service.MailService");
@ -407,10 +416,9 @@ public class MailService extends CoreService
if (minInterval != -1) if (minInterval != -1)
{ {
long nextTime = System.currentTimeMillis() + minInterval; long nextTime = System.currentTimeMillis() + minInterval;
String checkString = "Next pusher refresh scheduled for " + new Date(nextTime);
if (K9.DEBUG) if (K9.DEBUG)
{ {
Log.d(K9.LOG_TAG, checkString); Log.d(K9.LOG_TAG, "Next pusher refresh scheduled for " + new Date(nextTime));
} }
Intent i = new Intent(); Intent i = new Intent();
i.setClassName(getApplication().getPackageName(), "com.fsck.k9.service.MailService"); i.setClassName(getApplication().getPackageName(), "com.fsck.k9.service.MailService");
@ -428,19 +436,22 @@ public class MailService extends CoreService
final WakeLock wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "K9"); final WakeLock wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "K9");
wakeLock.setReferenceCounted(false); wakeLock.setReferenceCounted(false);
wakeLock.acquire(wakeLockTime); wakeLock.acquire(wakeLockTime);
if (K9.DEBUG)
Log.i(K9.LOG_TAG, "MailService queueing Runnable " + runner.hashCode() + " with startId " + startId); Log.i(K9.LOG_TAG, "MailService queueing Runnable " + runner.hashCode() + " with startId " + startId);
Runnable myRunner = new Runnable() Runnable myRunner = new Runnable()
{ {
public void run() public void run()
{ {
try try
{ {
if (K9.DEBUG)
Log.i(K9.LOG_TAG, "MailService running Runnable " + runner.hashCode() + " with startId " + startId); Log.i(K9.LOG_TAG, "MailService running Runnable " + runner.hashCode() + " with startId " + startId);
runner.run(); runner.run();
} }
finally finally
{ {
if (K9.DEBUG)
Log.i(K9.LOG_TAG, "MailService completed Runnable " + runner.hashCode() + " with startId " + startId); Log.i(K9.LOG_TAG, "MailService completed Runnable " + runner.hashCode() + " with startId " + startId);
wakeLock.release(); wakeLock.release();
if (startId != null) if (startId != null)

View File

@ -40,12 +40,14 @@ public class PollService extends CoreService
{ {
if (START_SERVICE.equals(intent.getAction())) if (START_SERVICE.equals(intent.getAction()))
{ {
if (K9.DEBUG)
Log.i(K9.LOG_TAG, "PollService started with startId = " + startId); Log.i(K9.LOG_TAG, "PollService started with startId = " + startId);
MessagingController controller = MessagingController.getInstance(getApplication()); MessagingController controller = MessagingController.getInstance(getApplication());
Listener listener = (Listener)controller.getCheckMailListener(); Listener listener = (Listener)controller.getCheckMailListener();
if (listener == null) if (listener == null)
{ {
if (K9.DEBUG)
Log.i(K9.LOG_TAG, "***** PollService *****: starting new check"); Log.i(K9.LOG_TAG, "***** PollService *****: starting new check");
mListener.setStartId(startId); mListener.setStartId(startId);
mListener.wakeLockAcquire(); mListener.wakeLockAcquire();
@ -54,6 +56,7 @@ public class PollService extends CoreService
} }
else else
{ {
if (K9.DEBUG)
Log.i(K9.LOG_TAG,"***** PollService *****: renewing WakeLock"); Log.i(K9.LOG_TAG,"***** PollService *****: renewing WakeLock");
listener.setStartId(startId); listener.setStartId(startId);
listener.wakeLockAcquire(); listener.wakeLockAcquire();
@ -61,6 +64,7 @@ public class PollService extends CoreService
} }
else if (STOP_SERVICE.equals(intent.getAction())) else if (STOP_SERVICE.equals(intent.getAction()))
{ {
if (K9.DEBUG)
Log.i(K9.LOG_TAG, "PollService stopping"); Log.i(K9.LOG_TAG, "PollService stopping");
stopSelf(); stopSelf();
} }
@ -158,6 +162,7 @@ public class PollService extends CoreService
controller.setCheckMailListener(null); controller.setCheckMailListener(null);
MailService.rescheduleCheck(PollService.this, null); MailService.rescheduleCheck(PollService.this, null);
wakeLockRelease(); wakeLockRelease();
if (K9.DEBUG)
Log.i(K9.LOG_TAG, "PollService stopping with startId = " + startId); Log.i(K9.LOG_TAG, "PollService stopping with startId = " + startId);
stopSelf(startId); stopSelf(startId);
@ -167,6 +172,7 @@ public class PollService extends CoreService
public void checkMailFinished(Context context, Account account) public void checkMailFinished(Context context, Account account)
{ {
if (K9.DEBUG)
Log.v(K9.LOG_TAG, "***** PollService *****: checkMailFinished"); Log.v(K9.LOG_TAG, "***** PollService *****: checkMailFinished");
try try
{ {

View File

@ -26,9 +26,7 @@ public class SleepService extends CoreService
{ {
Integer id = latchId.getAndIncrement(); Integer id = latchId.getAndIncrement();
if (K9.DEBUG) if (K9.DEBUG)
{
Log.d(K9.LOG_TAG, "SleepService Preparing CountDownLatch with id = " + id + ", thread " + Thread.currentThread().getName()); Log.d(K9.LOG_TAG, "SleepService Preparing CountDownLatch with id = " + id + ", thread " + Thread.currentThread().getName());
}
SleepDatum sleepDatum = new SleepDatum(); SleepDatum sleepDatum = new SleepDatum();
CountDownLatch latch = new CountDownLatch(1); CountDownLatch latch = new CountDownLatch(1);
sleepDatum.latch = latch; sleepDatum.latch = latch;
@ -53,9 +51,7 @@ public class SleepService extends CoreService
if (timedOut == false) if (timedOut == false)
{ {
if (K9.DEBUG) if (K9.DEBUG)
{
Log.d(K9.LOG_TAG, "SleepService latch timed out for id = " + id + ", thread " + Thread.currentThread().getName()); Log.d(K9.LOG_TAG, "SleepService latch timed out for id = " + id + ", thread " + Thread.currentThread().getName());
}
// don't call endSleep here or remove the sleepDatum here, instead of the following block. // don't call endSleep here or remove the sleepDatum here, instead of the following block.
// We might not get the wakeLock before // We might not get the wakeLock before
// falling asleep again, so we have to get the wakeLock *first* The alarmed version will // falling asleep again, so we have to get the wakeLock *first* The alarmed version will
@ -77,9 +73,7 @@ public class SleepService extends CoreService
long endTime = System.currentTimeMillis(); long endTime = System.currentTimeMillis();
long actualSleep = endTime - startTime; long actualSleep = endTime - startTime;
if (K9.DEBUG) if (K9.DEBUG)
{
Log.d(K9.LOG_TAG, "SleepService requested sleep time was " + sleepTime + ", actual was " + actualSleep); Log.d(K9.LOG_TAG, "SleepService requested sleep time was " + sleepTime + ", actual was " + actualSleep);
}
if (actualSleep < sleepTime) if (actualSleep < sleepTime)
{ {
Log.w(K9.LOG_TAG, "SleepService sleep time too short: requested was " + sleepTime + ", actual was " + actualSleep); Log.w(K9.LOG_TAG, "SleepService sleep time too short: requested was " + sleepTime + ", actual was " + actualSleep);
@ -101,9 +95,7 @@ public class SleepService extends CoreService
else else
{ {
if (K9.DEBUG) if (K9.DEBUG)
{
Log.d(K9.LOG_TAG, "SleepService Counting down CountDownLatch with id = " + id); Log.d(K9.LOG_TAG, "SleepService Counting down CountDownLatch with id = " + id);
}
latch.countDown(); latch.countDown();
} }
reacquireWakeLock(sleepDatum); reacquireWakeLock(sleepDatum);
@ -111,12 +103,10 @@ public class SleepService extends CoreService
else else
{ {
if (K9.DEBUG) if (K9.DEBUG)
{
Log.d(K9.LOG_TAG, "SleepService Sleep for id " + id + " already finished"); Log.d(K9.LOG_TAG, "SleepService Sleep for id " + id + " already finished");
} }
} }
} }
}
private static void reacquireWakeLock(SleepDatum sleepDatum) private static void reacquireWakeLock(SleepDatum sleepDatum)
{ {
@ -127,9 +117,7 @@ public class SleepService extends CoreService
{ {
long timeout = sleepDatum.timeout; long timeout = sleepDatum.timeout;
if (K9.DEBUG) if (K9.DEBUG)
{
Log.d(K9.LOG_TAG, "SleepService Acquring wakeLock for id for " + timeout + "ms"); Log.d(K9.LOG_TAG, "SleepService Acquring wakeLock for id for " + timeout + "ms");
}
wakeLock.acquire(timeout); wakeLock.acquire(timeout);
} }
} }