mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-21 15:19:53 +01:00
Merge branch 'log-network-usage' into 'master'
Log network usage at shutdown See merge request !616
This commit is contained in:
@@ -38,6 +38,8 @@ public class AppModule {
|
|||||||
static class EagerSingletons {
|
static class EagerSingletons {
|
||||||
@Inject
|
@Inject
|
||||||
AndroidNotificationManager androidNotificationManager;
|
AndroidNotificationManager androidNotificationManager;
|
||||||
|
@Inject
|
||||||
|
NetworkUsageLogger networkUsageLogger;
|
||||||
}
|
}
|
||||||
|
|
||||||
private final Application application;
|
private final Application application;
|
||||||
@@ -173,4 +175,12 @@ public class AppModule {
|
|||||||
ScreenFilterMonitorImpl screenFilterMonitor) {
|
ScreenFilterMonitorImpl screenFilterMonitor) {
|
||||||
return screenFilterMonitor;
|
return screenFilterMonitor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
NetworkUsageLogger provideNetworkUsageLogger(
|
||||||
|
LifecycleManager lifecycleManager) {
|
||||||
|
NetworkUsageLogger networkUsageLogger = new NetworkUsageLogger();
|
||||||
|
lifecycleManager.registerService(networkUsageLogger);
|
||||||
|
return networkUsageLogger;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,40 @@
|
|||||||
|
package org.briarproject.briar.android;
|
||||||
|
|
||||||
|
import android.net.TrafficStats;
|
||||||
|
import android.os.Process;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.lifecycle.Service;
|
||||||
|
import org.briarproject.bramble.api.lifecycle.ServiceException;
|
||||||
|
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
import static java.util.logging.Level.INFO;
|
||||||
|
|
||||||
|
class NetworkUsageLogger implements Service {
|
||||||
|
|
||||||
|
private static final Logger LOG =
|
||||||
|
Logger.getLogger(NetworkUsageLogger.class.getName());
|
||||||
|
|
||||||
|
private volatile long startTime, rxBytes, txBytes;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void startService() throws ServiceException {
|
||||||
|
startTime = System.currentTimeMillis();
|
||||||
|
int uid = Process.myUid();
|
||||||
|
rxBytes = TrafficStats.getUidRxBytes(uid);
|
||||||
|
txBytes = TrafficStats.getUidTxBytes(uid);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void stopService() throws ServiceException {
|
||||||
|
if (LOG.isLoggable(INFO)) {
|
||||||
|
long sessionDuration = System.currentTimeMillis() - startTime;
|
||||||
|
int uid = Process.myUid();
|
||||||
|
long rx = TrafficStats.getUidRxBytes(uid) - rxBytes;
|
||||||
|
long tx = TrafficStats.getUidTxBytes(uid) - txBytes;
|
||||||
|
LOG.info("Duration " + (sessionDuration / 1000) + " seconds");
|
||||||
|
LOG.info("Received " + rx + " bytes");
|
||||||
|
LOG.info("Sent " + tx + " bytes");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user