Remove (unused) timer functionality from TracingPowerManager
package com.fsck.k9.power;
-import java.util.Timer;
-import java.util.TimerTask;
import java.util.concurrent.atomic.AtomicInteger;
import android.content.Context;
@@ -16,11 +14,9 @@ import timber.log.Timber;
public class TracingPowerManager implements com.fsck.k9.mail.power.PowerManager {
- private final static boolean TRACE = false;
public static AtomicInteger wakeLockId = new AtomicInteger(0);
PowerManager pm = null;
private static TracingPowerManager tracingPowerManager;
- private Timer timer = null;
public static synchronized TracingPowerManager getPowerManager(Context context) {
Context appContext = context.getApplicationContext();
@@ -36,9 +32,6 @@ public class TracingPowerManager implements com.fsck.k9.mail.power.PowerManager
private TracingPowerManager(Context context) {
pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
- if (TRACE) {
- timer = new Timer();
- }
}
@NotNull
@@ -56,7 +49,6 @@ public class TracingPowerManager implements com.fsck.k9.mail.power.PowerManager
final WakeLock wakeLock;
final int id;
final String tag;
- volatile TimerTask timerTask;
volatile Long startTime = null;
volatile Long timeout = null;
@@ -77,7 +69,7 @@ public class TracingPowerManager implements com.fsck.k9.mail.power.PowerManager
if (K9MailLib.isDebug()) {
Timber.v("TracingWakeLock for tag %s / id %d for %d ms: acquired", tag, id, timeout);
}
- raiseNotification();
+
if (startTime == null) {
startTime = SystemClock.elapsedRealtime();
}
@@ -89,7 +81,7 @@ public class TracingPowerManager implements com.fsck.k9.mail.power.PowerManager
synchronized (wakeLock) {
wakeLock.acquire();
}
- raiseNotification();
+
if (K9MailLib.isDebug()) {
Timber.w("TracingWakeLock for tag %s / id %d: acquired with no timeout. K-9 Mail should not do this",
tag, id);
@@ -120,48 +112,11 @@ public class TracingPowerManager implements com.fsck.k9.mail.power.PowerManager
Timber.v("TracingWakeLock for tag %s / id %d, timeout = %d ms: releasing", tag, id, timeout);
}
}
- cancelNotification();
+
synchronized (wakeLock) {
wakeLock.release();
}
startTime = null;
}
-
- private void cancelNotification() {
- if (timer != null) {
- synchronized (timer) {
- if (timerTask != null) {
- timerTask.cancel();
- }
- }
- }
- }
-
- private void raiseNotification() {
- if (timer != null) {
- synchronized (timer) {
- if (timerTask != null) {
- timerTask.cancel();
- timerTask = null;
- }
- timerTask = new TimerTask() {
- @Override
- public void run() {
- if (startTime != null) {
- Long endTime = SystemClock.elapsedRealtime();
- Timber.i("TracingWakeLock for tag %s / id %d: has been active for %d ms, timeout = %d ms",
- tag, id, endTime - startTime, timeout);
-
- } else {
- Timber.i("TracingWakeLock for tag %s / id %d: still active, timeout = %d ms",
- tag, id, timeout);
- }
- }
-
- };
- timer.schedule(timerTask, 1000, 1000);
- }
- }
- }
}
}
