mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-22 15:49:53 +01:00
add bt polling speedtest
This commit is contained in:
@@ -79,10 +79,12 @@ class Poller implements EventListener {
|
|||||||
public void eventOccurred(Event e) {
|
public void eventOccurred(Event e) {
|
||||||
if (e instanceof ContactStatusChangedEvent) {
|
if (e instanceof ContactStatusChangedEvent) {
|
||||||
ContactStatusChangedEvent c = (ContactStatusChangedEvent) e;
|
ContactStatusChangedEvent c = (ContactStatusChangedEvent) e;
|
||||||
|
/*
|
||||||
if (c.isActive()) {
|
if (c.isActive()) {
|
||||||
// Connect to the newly activated contact
|
// Connect to the newly activated contact
|
||||||
connectToContact(c.getContactId());
|
connectToContact(c.getContactId());
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
} else if (e instanceof ConnectionClosedEvent) {
|
} else if (e instanceof ConnectionClosedEvent) {
|
||||||
ConnectionClosedEvent c = (ConnectionClosedEvent) e;
|
ConnectionClosedEvent c = (ConnectionClosedEvent) e;
|
||||||
// Reschedule polling, the polling interval may have decreased
|
// Reschedule polling, the polling interval may have decreased
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ abstract class BluetoothPlugin<SS> implements DuplexPlugin, EventListener {
|
|||||||
* How many milliseconds to pause between connection attempts when
|
* How many milliseconds to pause between connection attempts when
|
||||||
* polling, to avoid interfering with other Bluetooth or wifi connections.
|
* 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;
|
final BluetoothConnectionLimiter connectionLimiter;
|
||||||
|
|
||||||
|
|||||||
@@ -33,6 +33,10 @@ dependencies {
|
|||||||
implementation 'com.jpardogo.materialtabstrip:library:1.1.0'
|
implementation 'com.jpardogo.materialtabstrip:library:1.1.0'
|
||||||
implementation 'com.github.bumptech.glide:glide:3.8.0'
|
implementation 'com.github.bumptech.glide:glide:3.8.0'
|
||||||
implementation 'uk.co.samuelwall:material-tap-target-prompt:2.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'
|
annotationProcessor 'com.google.dagger:dagger-compiler:2.0.2'
|
||||||
|
|
||||||
|
|||||||
@@ -4,17 +4,18 @@
|
|||||||
xmlns:android="http://schemas.android.com/apk/res/android">
|
xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
|
||||||
<uses-feature android:name="android.hardware.bluetooth"/>
|
<uses-feature android:name="android.hardware.bluetooth"/>
|
||||||
<uses-feature android:name="android.hardware.camera" />
|
<uses-feature android:name="android.hardware.camera"/>
|
||||||
|
|
||||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
|
||||||
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
|
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
|
||||||
<uses-permission android:name="android.permission.BLUETOOTH" />
|
<uses-permission android:name="android.permission.BLUETOOTH"/>
|
||||||
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
|
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
|
||||||
<uses-permission android:name="android.permission.CAMERA" />
|
<uses-permission android:name="android.permission.CAMERA"/>
|
||||||
<uses-permission android:name="android.permission.INTERNET" />
|
<uses-permission android:name="android.permission.INTERNET"/>
|
||||||
<uses-permission android:name="android.permission.READ_LOGS"/>
|
<uses-permission android:name="android.permission.READ_LOGS"/>
|
||||||
<uses-permission android:name="android.permission.VIBRATE" />
|
<uses-permission android:name="android.permission.VIBRATE"/>
|
||||||
<uses-permission android:name="android.permission.WAKE_LOCK" />
|
<uses-permission android:name="android.permission.WAKE_LOCK"/>
|
||||||
|
|
||||||
<uses-permission-sdk-23 android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS"/>
|
<uses-permission-sdk-23 android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS"/>
|
||||||
|
|
||||||
<application
|
<application
|
||||||
@@ -69,8 +70,8 @@
|
|||||||
|
|
||||||
<activity
|
<activity
|
||||||
android:name="org.briarproject.briar.android.splash.SplashScreenActivity"
|
android:name="org.briarproject.briar.android.splash.SplashScreenActivity"
|
||||||
android:theme="@style/BriarTheme.NoActionBar"
|
android:label="@string/app_name"
|
||||||
android:label="@string/app_name">
|
android:theme="@style/BriarTheme.NoActionBar">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.MAIN"/>
|
<action android:name="android.intent.action.MAIN"/>
|
||||||
<category android:name="android.intent.category.LAUNCHER"/>
|
<category android:name="android.intent.category.LAUNCHER"/>
|
||||||
@@ -84,15 +85,15 @@
|
|||||||
|
|
||||||
<activity
|
<activity
|
||||||
android:name="org.briarproject.briar.android.navdrawer.NavDrawerActivity"
|
android:name="org.briarproject.briar.android.navdrawer.NavDrawerActivity"
|
||||||
android:theme="@style/BriarTheme.NoActionBar"
|
android:launchMode="singleTop"
|
||||||
android:launchMode="singleTop">
|
android:theme="@style/BriarTheme.NoActionBar">
|
||||||
</activity>
|
</activity>
|
||||||
|
|
||||||
<activity
|
<activity
|
||||||
android:name="org.briarproject.briar.android.contact.ConversationActivity"
|
android:name="org.briarproject.briar.android.contact.ConversationActivity"
|
||||||
android:label="@string/app_name"
|
android:label="@string/app_name"
|
||||||
android:theme="@style/BriarTheme.NoActionBar"
|
|
||||||
android:parentActivityName="org.briarproject.briar.android.navdrawer.NavDrawerActivity"
|
android:parentActivityName="org.briarproject.briar.android.navdrawer.NavDrawerActivity"
|
||||||
|
android:theme="@style/BriarTheme.NoActionBar"
|
||||||
android:windowSoftInputMode="stateHidden|adjustResize">
|
android:windowSoftInputMode="stateHidden|adjustResize">
|
||||||
<meta-data
|
<meta-data
|
||||||
android:name="android.support.PARENT_ACTIVITY"
|
android:name="android.support.PARENT_ACTIVITY"
|
||||||
@@ -132,7 +133,7 @@
|
|||||||
android:value="org.briarproject.briar.android.navdrawer.NavDrawerActivity"/>
|
android:value="org.briarproject.briar.android.navdrawer.NavDrawerActivity"/>
|
||||||
</activity>
|
</activity>
|
||||||
|
|
||||||
<activity
|
<activity
|
||||||
android:name="org.briarproject.briar.android.privategroup.memberlist.GroupMemberListActivity"
|
android:name="org.briarproject.briar.android.privategroup.memberlist.GroupMemberListActivity"
|
||||||
android:label="@string/groups_member_list"
|
android:label="@string/groups_member_list"
|
||||||
android:parentActivityName="org.briarproject.briar.android.privategroup.conversation.GroupActivity"
|
android:parentActivityName="org.briarproject.briar.android.privategroup.conversation.GroupActivity"
|
||||||
@@ -304,8 +305,8 @@
|
|||||||
<activity
|
<activity
|
||||||
android:name="org.briarproject.briar.android.keyagreement.KeyAgreementActivity"
|
android:name="org.briarproject.briar.android.keyagreement.KeyAgreementActivity"
|
||||||
android:label="@string/add_contact_title"
|
android:label="@string/add_contact_title"
|
||||||
android:theme="@style/BriarTheme.NoActionBar"
|
android:parentActivityName="org.briarproject.briar.android.navdrawer.NavDrawerActivity"
|
||||||
android:parentActivityName="org.briarproject.briar.android.navdrawer.NavDrawerActivity">
|
android:theme="@style/BriarTheme.NoActionBar">
|
||||||
<meta-data
|
<meta-data
|
||||||
android:name="android.support.PARENT_ACTIVITY"
|
android:name="android.support.PARENT_ACTIVITY"
|
||||||
android:value="org.briarproject.briar.android.navdrawer.NavDrawerActivity"/>
|
android:value="org.briarproject.briar.android.navdrawer.NavDrawerActivity"/>
|
||||||
@@ -362,6 +363,16 @@
|
|||||||
/>
|
/>
|
||||||
</activity>
|
</activity>
|
||||||
|
|
||||||
|
<activity
|
||||||
|
android:name="org.briarproject.briar.android.test.PollingTestActivity"
|
||||||
|
android:label="Test polling"
|
||||||
|
android:parentActivityName="org.briarproject.briar.android.settings.SettingsActivity">
|
||||||
|
<meta-data
|
||||||
|
android:name="android.support.PARENT_ACTIVITY"
|
||||||
|
android:value="org.briarproject.briar.android.settings.SettingsActivity"
|
||||||
|
/>
|
||||||
|
</activity>
|
||||||
|
|
||||||
<activity
|
<activity
|
||||||
android:name="org.briarproject.briar.android.panic.PanicPreferencesActivity"
|
android:name="org.briarproject.briar.android.panic.PanicPreferencesActivity"
|
||||||
android:label="@string/panic_setting"
|
android:label="@string/panic_setting"
|
||||||
|
|||||||
@@ -70,6 +70,7 @@ import org.briarproject.briar.android.sharing.ShareForumFragment;
|
|||||||
import org.briarproject.briar.android.sharing.ShareForumMessageFragment;
|
import org.briarproject.briar.android.sharing.ShareForumMessageFragment;
|
||||||
import org.briarproject.briar.android.sharing.SharingModule;
|
import org.briarproject.briar.android.sharing.SharingModule;
|
||||||
import org.briarproject.briar.android.splash.SplashScreenActivity;
|
import org.briarproject.briar.android.splash.SplashScreenActivity;
|
||||||
|
import org.briarproject.briar.android.test.PollingTestActivity;
|
||||||
import org.briarproject.briar.android.test.TestDataActivity;
|
import org.briarproject.briar.android.test.TestDataActivity;
|
||||||
|
|
||||||
import dagger.Component;
|
import dagger.Component;
|
||||||
@@ -150,6 +151,8 @@ public interface ActivityComponent {
|
|||||||
|
|
||||||
void inject(TestDataActivity activity);
|
void inject(TestDataActivity activity);
|
||||||
|
|
||||||
|
void inject(PollingTestActivity activity);
|
||||||
|
|
||||||
void inject(ChangePasswordActivity activity);
|
void inject(ChangePasswordActivity activity);
|
||||||
|
|
||||||
void inject(IntroductionActivity activity);
|
void inject(IntroductionActivity activity);
|
||||||
|
|||||||
@@ -0,0 +1,176 @@
|
|||||||
|
package org.briarproject.briar.android.test;
|
||||||
|
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.support.v7.app.ActionBar;
|
||||||
|
import android.view.MenuItem;
|
||||||
|
import android.widget.Button;
|
||||||
|
|
||||||
|
import com.jjoe64.graphview.GraphView;
|
||||||
|
import com.jjoe64.graphview.series.DataPoint;
|
||||||
|
import com.jjoe64.graphview.series.LineGraphSeries;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.event.EventBus;
|
||||||
|
import org.briarproject.bramble.api.plugin.BluetoothConstants;
|
||||||
|
import org.briarproject.bramble.api.plugin.event.TransportDisabledEvent;
|
||||||
|
import org.briarproject.bramble.api.plugin.event.TransportEnabledEvent;
|
||||||
|
import org.briarproject.bramble.api.system.AndroidExecutor;
|
||||||
|
import org.briarproject.briar.R;
|
||||||
|
import org.briarproject.briar.android.activity.ActivityComponent;
|
||||||
|
import org.briarproject.briar.android.activity.BriarActivity;
|
||||||
|
import org.briarproject.briar.api.test.TestDataCreator;
|
||||||
|
|
||||||
|
import java.util.concurrent.CountDownLatch;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
import fr.bmartel.speedtest.SpeedTestReport;
|
||||||
|
import fr.bmartel.speedtest.SpeedTestSocket;
|
||||||
|
import fr.bmartel.speedtest.inter.ISpeedTestListener;
|
||||||
|
import fr.bmartel.speedtest.model.SpeedTestError;
|
||||||
|
|
||||||
|
public class PollingTestActivity extends BriarActivity {
|
||||||
|
|
||||||
|
private static final Logger LOG =
|
||||||
|
Logger.getLogger(PollingTestActivity.class.getName());
|
||||||
|
|
||||||
|
// Add one contact after each round up to:
|
||||||
|
private static int NUMBER_OF_CONTACTS = 10;
|
||||||
|
// Download x times per #contacts
|
||||||
|
private static int NUMBER_OF_DOWNLOADS = 1;
|
||||||
|
// File size to download. One of (5,10,50,100,500)MB.
|
||||||
|
private static int DOWNLOAD_SIZE = 10;
|
||||||
|
// Time to wait between each round in ms.
|
||||||
|
private static int PAUSE = 5000;
|
||||||
|
// Socket timeout in ms
|
||||||
|
private static int SO_TIMEOUT = 60000;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
TestDataCreator testDataCreator;
|
||||||
|
@Inject
|
||||||
|
AndroidExecutor executor;
|
||||||
|
@Inject
|
||||||
|
EventBus eventBus;
|
||||||
|
|
||||||
|
GraphView graphView;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreate(Bundle bundle) {
|
||||||
|
super.onCreate(bundle);
|
||||||
|
|
||||||
|
ActionBar actionBar = getSupportActionBar();
|
||||||
|
if (actionBar != null) {
|
||||||
|
actionBar.setHomeButtonEnabled(true);
|
||||||
|
actionBar.setDisplayHomeAsUpEnabled(true);
|
||||||
|
}
|
||||||
|
setContentView(R.layout.activity_test_polling);
|
||||||
|
Button button = findViewById(R.id.run_test_button);
|
||||||
|
button.setOnClickListener(v -> {
|
||||||
|
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<DataPoint> 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
24
briar-android/src/main/res/layout/activity_test_polling.xml
Normal file
24
briar-android/src/main/res/layout/activity_test_polling.xml
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<android.support.constraint.ConstraintLayout
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/run_test_button"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="Run test"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
/>
|
||||||
|
<com.jjoe64.graphview.GraphView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="0dp"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toBottomOf="@+id/run_test_button"
|
||||||
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
android:id="@+id/graph" />
|
||||||
|
</android.support.constraint.ConstraintLayout>
|
||||||
@@ -131,4 +131,13 @@
|
|||||||
android:targetPackage="@string/app_package"/>
|
android:targetPackage="@string/app_package"/>
|
||||||
</Preference>
|
</Preference>
|
||||||
|
|
||||||
|
<Preference
|
||||||
|
android:key="pref_key_speed_test"
|
||||||
|
android:title="Test polling impact on bandwith">
|
||||||
|
|
||||||
|
<intent
|
||||||
|
android:targetClass="org.briarproject.briar.android.test.PollingTestActivity"
|
||||||
|
android:targetPackage="@string/app_package"/>
|
||||||
|
</Preference>
|
||||||
|
|
||||||
</PreferenceScreen>
|
</PreferenceScreen>
|
||||||
|
|||||||
Reference in New Issue
Block a user