mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-20 14:49:53 +01:00
Add fine logging for wake locks.
This commit is contained in:
@@ -3,9 +3,13 @@ package org.briarproject.bramble.system;
|
|||||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
import org.briarproject.bramble.api.system.AndroidWakeLock;
|
import org.briarproject.bramble.api.system.AndroidWakeLock;
|
||||||
|
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import javax.annotation.concurrent.GuardedBy;
|
import javax.annotation.concurrent.GuardedBy;
|
||||||
import javax.annotation.concurrent.ThreadSafe;
|
import javax.annotation.concurrent.ThreadSafe;
|
||||||
|
|
||||||
|
import static java.util.logging.Logger.getLogger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A wrapper around a {@link SharedWakeLock} that provides the more convenient
|
* A wrapper around a {@link SharedWakeLock} that provides the more convenient
|
||||||
* semantics of {@link AndroidWakeLock} (i.e. calls to acquire() and release()
|
* semantics of {@link AndroidWakeLock} (i.e. calls to acquire() and release()
|
||||||
@@ -15,6 +19,9 @@ import javax.annotation.concurrent.ThreadSafe;
|
|||||||
@NotNullByDefault
|
@NotNullByDefault
|
||||||
class AndroidWakeLockImpl implements AndroidWakeLock {
|
class AndroidWakeLockImpl implements AndroidWakeLock {
|
||||||
|
|
||||||
|
private static final Logger LOG =
|
||||||
|
getLogger(AndroidWakeLockImpl.class.getName());
|
||||||
|
|
||||||
private final SharedWakeLock sharedWakeLock;
|
private final SharedWakeLock sharedWakeLock;
|
||||||
private final Object lock = new Object();
|
private final Object lock = new Object();
|
||||||
@GuardedBy("lock")
|
@GuardedBy("lock")
|
||||||
@@ -27,7 +34,10 @@ class AndroidWakeLockImpl implements AndroidWakeLock {
|
|||||||
@Override
|
@Override
|
||||||
public void acquire() {
|
public void acquire() {
|
||||||
synchronized (lock) {
|
synchronized (lock) {
|
||||||
if (!held) {
|
if (held) {
|
||||||
|
LOG.fine("Already acquired");
|
||||||
|
} else {
|
||||||
|
LOG.fine("Acquiring shared wake lock");
|
||||||
held = true;
|
held = true;
|
||||||
sharedWakeLock.acquire();
|
sharedWakeLock.acquire();
|
||||||
}
|
}
|
||||||
@@ -38,8 +48,11 @@ class AndroidWakeLockImpl implements AndroidWakeLock {
|
|||||||
public void release() {
|
public void release() {
|
||||||
synchronized (lock) {
|
synchronized (lock) {
|
||||||
if (held) {
|
if (held) {
|
||||||
|
LOG.fine("Releasing shared wake lock");
|
||||||
held = false;
|
held = false;
|
||||||
sharedWakeLock.release();
|
sharedWakeLock.release();
|
||||||
|
} else {
|
||||||
|
LOG.fine("Already released");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import javax.annotation.concurrent.GuardedBy;
|
|||||||
import javax.annotation.concurrent.ThreadSafe;
|
import javax.annotation.concurrent.ThreadSafe;
|
||||||
|
|
||||||
import static java.util.concurrent.TimeUnit.MILLISECONDS;
|
import static java.util.concurrent.TimeUnit.MILLISECONDS;
|
||||||
|
import static java.util.logging.Level.FINE;
|
||||||
import static java.util.logging.Level.INFO;
|
import static java.util.logging.Level.INFO;
|
||||||
import static java.util.logging.Level.WARNING;
|
import static java.util.logging.Level.WARNING;
|
||||||
import static java.util.logging.Logger.getLogger;
|
import static java.util.logging.Logger.getLogger;
|
||||||
@@ -75,6 +76,8 @@ class RenewableWakeLock implements SharedWakeLock {
|
|||||||
future = scheduledExecutorService.schedule(this::renew,
|
future = scheduledExecutorService.schedule(this::renew,
|
||||||
durationMs, MILLISECONDS);
|
durationMs, MILLISECONDS);
|
||||||
acquired = android.os.SystemClock.elapsedRealtime();
|
acquired = android.os.SystemClock.elapsedRealtime();
|
||||||
|
} else if (LOG.isLoggable(FINE)) {
|
||||||
|
LOG.fine("Wake lock " + tag + " has " + refCount + " holders");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -86,6 +89,9 @@ class RenewableWakeLock implements SharedWakeLock {
|
|||||||
LOG.info("Already released");
|
LOG.info("Already released");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (LOG.isLoggable(FINE)) {
|
||||||
|
LOG.fine("Wake lock " + tag + " has " + refCount + " holders");
|
||||||
|
}
|
||||||
long now = android.os.SystemClock.elapsedRealtime();
|
long now = android.os.SystemClock.elapsedRealtime();
|
||||||
long expiry = acquired + durationMs + safetyMarginMs;
|
long expiry = acquired + durationMs + safetyMarginMs;
|
||||||
if (now > expiry && LOG.isLoggable(WARNING)) {
|
if (now > expiry && LOG.isLoggable(WARNING)) {
|
||||||
@@ -115,6 +121,8 @@ class RenewableWakeLock implements SharedWakeLock {
|
|||||||
requireNonNull(wakeLock).release();
|
requireNonNull(wakeLock).release();
|
||||||
wakeLock = null;
|
wakeLock = null;
|
||||||
acquired = 0;
|
acquired = 0;
|
||||||
|
} else if (LOG.isLoggable(FINE)) {
|
||||||
|
LOG.fine("Wake lock " + tag + " has " + refCount + " holders");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user