Skip to content
Snippets Groups Projects
Commit 10f41ef1 authored by akwizgran's avatar akwizgran
Browse files

Log network usage at shutdown.

parent e6b1597f
No related merge requests found
......@@ -38,6 +38,8 @@ public class AppModule {
static class EagerSingletons {
@Inject
AndroidNotificationManager androidNotificationManager;
@Inject
NetworkUsageLogger networkUsageLogger;
}
private final Application application;
......@@ -173,4 +175,12 @@ public class AppModule {
ScreenFilterMonitorImpl screenFilterMonitor) {
return screenFilterMonitor;
}
@Provides
NetworkUsageLogger provideNetworkUsageLogger(
LifecycleManager lifecycleManager) {
NetworkUsageLogger networkUsageLogger = new NetworkUsageLogger();
lifecycleManager.registerService(networkUsageLogger);
return networkUsageLogger;
}
}
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");
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment