mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-13 03:09:04 +01:00
Merge branch 'network-usage-metrics' into 'master'
Include network usage metrics in crash reports and feedback See merge request briar/briar!1555
This commit is contained in:
@@ -56,6 +56,7 @@ import org.briarproject.briar.android.viewmodel.ViewModelModule;
|
||||
import org.briarproject.briar.api.android.AndroidNotificationManager;
|
||||
import org.briarproject.briar.api.android.DozeWatchdog;
|
||||
import org.briarproject.briar.api.android.LockManager;
|
||||
import org.briarproject.briar.api.android.NetworkUsageMetrics;
|
||||
import org.briarproject.briar.api.android.ScreenFilterMonitor;
|
||||
import org.briarproject.briar.api.test.TestAvatarCreator;
|
||||
|
||||
@@ -114,7 +115,7 @@ public class AppModule {
|
||||
@Inject
|
||||
ScreenFilterMonitor screenFilterMonitor;
|
||||
@Inject
|
||||
NetworkUsageLogger networkUsageLogger;
|
||||
NetworkUsageMetrics networkUsageMetrics;
|
||||
@Inject
|
||||
DozeWatchdog dozeWatchdog;
|
||||
@Inject
|
||||
@@ -287,11 +288,12 @@ public class AppModule {
|
||||
}
|
||||
|
||||
@Provides
|
||||
NetworkUsageLogger provideNetworkUsageLogger(
|
||||
@Singleton
|
||||
NetworkUsageMetrics provideNetworkUsageMetrics(
|
||||
LifecycleManager lifecycleManager) {
|
||||
NetworkUsageLogger networkUsageLogger = new NetworkUsageLogger();
|
||||
lifecycleManager.registerService(networkUsageLogger);
|
||||
return networkUsageLogger;
|
||||
NetworkUsageMetrics networkUsageMetrics = new NetworkUsageMetricsImpl();
|
||||
lifecycleManager.registerService(networkUsageMetrics);
|
||||
return networkUsageMetrics;
|
||||
}
|
||||
|
||||
@Provides
|
||||
|
||||
@@ -1,40 +0,0 @@
|
||||
package org.briarproject.briar.android;
|
||||
|
||||
import android.net.TrafficStats;
|
||||
import android.os.Process;
|
||||
|
||||
import org.briarproject.bramble.api.lifecycle.Service;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import static java.util.logging.Level.INFO;
|
||||
import static org.briarproject.bramble.util.LogUtils.now;
|
||||
|
||||
class NetworkUsageLogger implements Service {
|
||||
|
||||
private static final Logger LOG =
|
||||
Logger.getLogger(NetworkUsageLogger.class.getName());
|
||||
|
||||
private volatile long startTime, rxBytes, txBytes;
|
||||
|
||||
@Override
|
||||
public void startService() {
|
||||
startTime = now();
|
||||
int uid = Process.myUid();
|
||||
rxBytes = TrafficStats.getUidRxBytes(uid);
|
||||
txBytes = TrafficStats.getUidTxBytes(uid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stopService() {
|
||||
if (LOG.isLoggable(INFO)) {
|
||||
long sessionDuration = now() - 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,0 +1,49 @@
|
||||
package org.briarproject.briar.android;
|
||||
|
||||
import android.net.TrafficStats;
|
||||
import android.os.Process;
|
||||
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.briar.api.android.NetworkUsageMetrics;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import static java.util.logging.Level.INFO;
|
||||
import static org.briarproject.bramble.util.LogUtils.now;
|
||||
|
||||
@NotNullByDefault
|
||||
class NetworkUsageMetricsImpl implements NetworkUsageMetrics {
|
||||
|
||||
private static final Logger LOG =
|
||||
Logger.getLogger(NetworkUsageMetricsImpl.class.getName());
|
||||
|
||||
private volatile long startTime, rxBytes, txBytes;
|
||||
|
||||
@Override
|
||||
public void startService() {
|
||||
startTime = now();
|
||||
int uid = Process.myUid();
|
||||
rxBytes = TrafficStats.getUidRxBytes(uid);
|
||||
txBytes = TrafficStats.getUidTxBytes(uid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stopService() {
|
||||
if (LOG.isLoggable(INFO)) {
|
||||
Metrics metrics = getMetrics();
|
||||
LOG.info("Duration " + (metrics.getSessionDurationMs() / 1000)
|
||||
+ " seconds");
|
||||
LOG.info("Received " + metrics.getRxBytes() + " bytes");
|
||||
LOG.info("Sent " + metrics.getTxBytes() + " bytes");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Metrics getMetrics() {
|
||||
long sessionDurationMs = now() - startTime;
|
||||
int uid = Process.myUid();
|
||||
long rx = TrafficStats.getUidRxBytes(uid) - rxBytes;
|
||||
long tx = TrafficStats.getUidTxBytes(uid) - txBytes;
|
||||
return new Metrics(sessionDurationMs, rx, tx);
|
||||
}
|
||||
}
|
||||
@@ -28,6 +28,8 @@ import org.briarproject.briar.R;
|
||||
import org.briarproject.briar.android.reporting.ReportData.MultiReportInfo;
|
||||
import org.briarproject.briar.android.reporting.ReportData.ReportItem;
|
||||
import org.briarproject.briar.android.reporting.ReportData.SingleReportInfo;
|
||||
import org.briarproject.briar.api.android.NetworkUsageMetrics;
|
||||
import org.briarproject.briar.api.android.NetworkUsageMetrics.Metrics;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.PrintWriter;
|
||||
@@ -65,9 +67,11 @@ import static org.briarproject.bramble.util.StringUtils.isNullOrEmpty;
|
||||
class BriarReportCollector {
|
||||
|
||||
private final Context ctx;
|
||||
private final NetworkUsageMetrics networkUsageMetrics;
|
||||
|
||||
BriarReportCollector(Context ctx) {
|
||||
BriarReportCollector(Context ctx, NetworkUsageMetrics networkUsageMetrics) {
|
||||
this.ctx = ctx;
|
||||
this.networkUsageMetrics = networkUsageMetrics;
|
||||
}
|
||||
|
||||
ReportData collectReportData(@Nullable Throwable t, long appStartTime,
|
||||
@@ -81,6 +85,7 @@ class BriarReportCollector {
|
||||
.add(getMemory())
|
||||
.add(getStorage())
|
||||
.add(getConnectivity())
|
||||
.add(getNetworkUsage())
|
||||
.add(getBuildConfig())
|
||||
.add(getLogcat(logs))
|
||||
.add(getDeviceFeatures());
|
||||
@@ -298,6 +303,16 @@ class BriarReportCollector {
|
||||
connectivityInfo);
|
||||
}
|
||||
|
||||
private ReportItem getNetworkUsage() {
|
||||
Metrics metrics = networkUsageMetrics.getMetrics();
|
||||
MultiReportInfo networkUsage = new MultiReportInfo()
|
||||
.add("SessionDuration", metrics.getSessionDurationMs())
|
||||
.add("BytesReceived", metrics.getRxBytes())
|
||||
.add("BytesSent", metrics.getTxBytes());
|
||||
return new ReportItem("NetworkUsage", R.string.dev_report_network_usage,
|
||||
networkUsage);
|
||||
}
|
||||
|
||||
private ReportItem getBuildConfig() {
|
||||
MultiReportInfo buildConfig = new MultiReportInfo()
|
||||
.add("GitHash", BuildConfig.GitHash)
|
||||
|
||||
@@ -18,6 +18,7 @@ import org.briarproject.briar.android.reporting.ReportData.MultiReportInfo;
|
||||
import org.briarproject.briar.android.reporting.ReportData.ReportItem;
|
||||
import org.briarproject.briar.android.viewmodel.LiveEvent;
|
||||
import org.briarproject.briar.android.viewmodel.MutableLiveEvent;
|
||||
import org.briarproject.briar.api.android.NetworkUsageMetrics;
|
||||
import org.json.JSONException;
|
||||
|
||||
import java.io.File;
|
||||
@@ -69,12 +70,13 @@ class ReportViewModel extends AndroidViewModel {
|
||||
|
||||
@Inject
|
||||
ReportViewModel(@NonNull Application application,
|
||||
NetworkUsageMetrics networkUsageMetrics,
|
||||
CachingLogHandler logHandler,
|
||||
LogDecrypter logDecrypter,
|
||||
DevReporter reporter,
|
||||
PluginManager pluginManager) {
|
||||
super(application);
|
||||
collector = new BriarReportCollector(application);
|
||||
collector = new BriarReportCollector(application, networkUsageMetrics);
|
||||
this.logHandler = logHandler;
|
||||
this.logDecrypter = logDecrypter;
|
||||
this.reporter = reporter;
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
package org.briarproject.briar.api.android;
|
||||
|
||||
import org.briarproject.bramble.api.lifecycle.Service;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
|
||||
@NotNullByDefault
|
||||
public interface NetworkUsageMetrics extends Service {
|
||||
|
||||
Metrics getMetrics();
|
||||
|
||||
class Metrics {
|
||||
|
||||
private final long sessionDurationMs, rxBytes, txBytes;
|
||||
|
||||
public Metrics(long sessionDurationMs, long rxBytes,
|
||||
long txBytes) {
|
||||
this.sessionDurationMs = sessionDurationMs;
|
||||
this.rxBytes = rxBytes;
|
||||
this.txBytes = txBytes;
|
||||
}
|
||||
|
||||
public long getSessionDurationMs() {
|
||||
return sessionDurationMs;
|
||||
}
|
||||
|
||||
public long getRxBytes() {
|
||||
return rxBytes;
|
||||
}
|
||||
|
||||
public long getTxBytes() {
|
||||
return txBytes;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -649,6 +649,7 @@
|
||||
<string name="dev_report_memory">Memory</string>
|
||||
<string name="dev_report_storage">Storage</string>
|
||||
<string name="dev_report_connectivity">Connectivity</string>
|
||||
<string name="dev_report_network_usage">Network usage</string>
|
||||
<string name="dev_report_build_config">Build configuration</string>
|
||||
<string name="dev_report_logcat">App log</string>
|
||||
<string name="dev_report_device_features">Device Features</string>
|
||||
|
||||
Reference in New Issue
Block a user