From a51f0f803f6279acc48bf2e18b3ae9f08654d300 Mon Sep 17 00:00:00 2001 From: goapunk Date: Thu, 10 May 2018 11:50:33 +0200 Subject: [PATCH] add bt polling speedtest --- .../briarproject/bramble/plugin/Poller.java | 2 + .../plugin/bluetooth/BluetoothPlugin.java | 2 +- briar-android/build.gradle | 4 + briar-android/src/main/AndroidManifest.xml | 45 +++-- .../android/activity/ActivityComponent.java | 3 + .../android/test/PollingTestActivity.java | 176 ++++++++++++++++++ .../main/res/layout/activity_test_polling.xml | 24 +++ briar-android/src/main/res/xml/settings.xml | 9 + 8 files changed, 247 insertions(+), 18 deletions(-) create mode 100644 briar-android/src/main/java/org/briarproject/briar/android/test/PollingTestActivity.java create mode 100644 briar-android/src/main/res/layout/activity_test_polling.xml diff --git a/bramble-core/src/main/java/org/briarproject/bramble/plugin/Poller.java b/bramble-core/src/main/java/org/briarproject/bramble/plugin/Poller.java index 0d0a8a95e..2d97a026b 100644 --- a/bramble-core/src/main/java/org/briarproject/bramble/plugin/Poller.java +++ b/bramble-core/src/main/java/org/briarproject/bramble/plugin/Poller.java @@ -79,10 +79,12 @@ class Poller implements EventListener { public void eventOccurred(Event e) { if (e instanceof ContactStatusChangedEvent) { ContactStatusChangedEvent c = (ContactStatusChangedEvent) e; + /* if (c.isActive()) { // Connect to the newly activated contact connectToContact(c.getContactId()); } + */ } else if (e instanceof ConnectionClosedEvent) { ConnectionClosedEvent c = (ConnectionClosedEvent) e; // Reschedule polling, the polling interval may have decreased diff --git a/bramble-core/src/main/java/org/briarproject/bramble/plugin/bluetooth/BluetoothPlugin.java b/bramble-core/src/main/java/org/briarproject/bramble/plugin/bluetooth/BluetoothPlugin.java index cf46fc571..2a4fa76fe 100644 --- a/bramble-core/src/main/java/org/briarproject/bramble/plugin/bluetooth/BluetoothPlugin.java +++ b/bramble-core/src/main/java/org/briarproject/bramble/plugin/bluetooth/BluetoothPlugin.java @@ -59,7 +59,7 @@ abstract class BluetoothPlugin implements DuplexPlugin, EventListener { * How many milliseconds to pause between connection attempts when * polling, to avoid interfering with other Bluetooth or wifi connections. */ - private static final int POLLING_PAUSE_MS = 1000; + private static final int POLLING_PAUSE_MS = 3000; final BluetoothConnectionLimiter connectionLimiter; diff --git a/briar-android/build.gradle b/briar-android/build.gradle index 34fd302ad..26b01c1d8 100644 --- a/briar-android/build.gradle +++ b/briar-android/build.gradle @@ -33,6 +33,10 @@ dependencies { implementation 'com.jpardogo.materialtabstrip:library:1.1.0' implementation 'com.github.bumptech.glide:glide:3.8.0' implementation 'uk.co.samuelwall:material-tap-target-prompt:2.8.0' + implementation'fr.bmartel:jspeedtest:1.32.0' + implementation 'com.jjoe64:graphview:4.2.2' + + annotationProcessor 'com.google.dagger:dagger-compiler:2.0.2' diff --git a/briar-android/src/main/AndroidManifest.xml b/briar-android/src/main/AndroidManifest.xml index 19b55dca6..566437792 100644 --- a/briar-android/src/main/AndroidManifest.xml +++ b/briar-android/src/main/AndroidManifest.xml @@ -4,17 +4,18 @@ xmlns:android="http://schemas.android.com/apk/res/android"> - + - - - - - - + + + + + + - - + + + + android:label="@string/app_name" + android:theme="@style/BriarTheme.NoActionBar"> @@ -84,15 +85,15 @@ + android:launchMode="singleTop" + android:theme="@style/BriarTheme.NoActionBar"> - + android:parentActivityName="org.briarproject.briar.android.navdrawer.NavDrawerActivity" + android:theme="@style/BriarTheme.NoActionBar"> @@ -362,6 +363,16 @@ /> + + + + { + runTest(); + }); + graphView = findViewById(R.id.graph); + graphView.getGridLabelRenderer() + .setHorizontalAxisTitle("Number of contacts"); + graphView.getGridLabelRenderer().setVerticalAxisTitle("MBit/s"); + graphView.getViewport().setXAxisBoundsManual(true); + graphView.getViewport().setMinX(0); + graphView.getViewport().setMaxX(NUMBER_OF_CONTACTS); + } + + private void runTest() { + executor.runOnBackgroundThread(() -> { + LineGraphSeries series = new LineGraphSeries<>(); + graphView.addSeries(series); + for (int i = 0; i < NUMBER_OF_CONTACTS; i++) { + if (i != 0) { + createContact(); + // Wait to let the previous round of polling settle. + synchronized (this) { + try { + wait(PAUSE); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + } + // Reset BT polling. + eventBus.broadcast(new TransportDisabledEvent( + BluetoothConstants.ID)); + eventBus.broadcast( + new TransportEnabledEvent(BluetoothConstants.ID)); + LOG.info("\n###########\nRound " + i + " (Contacts)"); + double y = run(); + series.appendData(new DataPoint(i, y), false, + NUMBER_OF_CONTACTS); + } + }); + } + + private double run() { + SpeedTestReport reports[] = new SpeedTestReport[3]; + double average = 0; + for (int i = 0; i < NUMBER_OF_DOWNLOADS; i++) { + final CountDownLatch cl = new CountDownLatch(1); + SpeedTestSocket speedTestSocket = new SpeedTestSocket(); + speedTestSocket.setSocketTimeout(SO_TIMEOUT); + int finalI = i; + speedTestSocket.addSpeedTestListener(new ISpeedTestListener() { + @Override + public void onCompletion(SpeedTestReport report) { + LOG.info("[COMPLETED]: rate in bit/s : " + + report.getTransferRateBit() + " in " + + (report.getReportTime() - + report.getStartTime()) + "ms"); + reports[finalI] = report; + cl.countDown(); + } + + @Override + public void onProgress(float percent, + SpeedTestReport report) { + /* LOG.info("[PROGRESS] rate in bit/s : " + + report.getTransferRateBit()); + */ + } + + @Override + public void onError(SpeedTestError speedTestError, + String errorMessage) { + LOG.info("Error: " + speedTestError.name() + " : " + + errorMessage); + + } + }); + LOG.info("Download " + (i + 1) + " of " + NUMBER_OF_DOWNLOADS); + speedTestSocket + .startDownload( + "http://ikoula.testdebit.info/" + DOWNLOAD_SIZE + + "M.iso"); + try { + cl.await(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + average += reports[i].getTransferRateBit().doubleValue() / 1000000; + } + return average / NUMBER_OF_DOWNLOADS; + } + + private void createContact() { + testDataCreator.createTestData(1, 0, 0, 0, 0); + } + + @Override + public void injectActivity(ActivityComponent component) { + component.inject(this); + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + if (item.getItemId() == android.R.id.home) { + onBackPressed(); + return true; + } + return false; + } +} diff --git a/briar-android/src/main/res/layout/activity_test_polling.xml b/briar-android/src/main/res/layout/activity_test_polling.xml new file mode 100644 index 000000000..56c6163b9 --- /dev/null +++ b/briar-android/src/main/res/layout/activity_test_polling.xml @@ -0,0 +1,24 @@ + + + +