Commit 9f98bfe3 authored by akwizgran's avatar akwizgran

Show an error message if Bluetooth isn't supported.

parent 32ce1eb9
......@@ -19,6 +19,7 @@ import static org.briarproject.interferometer.MainViewModel.ConnectionState.DISC
import static org.briarproject.interferometer.MainViewModel.ConnectionState.DOWNLOADING;
import static org.briarproject.interferometer.MainViewModel.ConnectionState.UPLOADING;
import static org.briarproject.interferometer.MainViewModel.StartResult.INVALID_ADDRESS;
import static org.briarproject.interferometer.MainViewModel.StartResult.NO_BLUETOOTH;
import static org.briarproject.interferometer.MainViewModel.TestPhase.READY;
public class MainActivity extends AppCompatActivity {
......@@ -73,6 +74,8 @@ public class MainActivity extends AppCompatActivity {
StartResult result = viewModel.startTest(serverAddressEditText.getText().toString());
if (result == INVALID_ADDRESS) {
Toast.makeText(this, R.string.server_address_error, LENGTH_SHORT).show();
} else if (result == NO_BLUETOOTH) {
Toast.makeText(this, R.string.no_bluetooth_error, LENGTH_SHORT).show();
}
} else {
viewModel.stopTest();
......
package org.briarproject.interferometer;
import android.bluetooth.BluetoothAdapter;
import android.util.Log;
import java.io.IOException;
......@@ -24,6 +25,7 @@ import static org.briarproject.interferometer.MainViewModel.ConnectionState.DISC
import static org.briarproject.interferometer.MainViewModel.ConnectionState.DOWNLOADING;
import static org.briarproject.interferometer.MainViewModel.ConnectionState.UPLOADING;
import static org.briarproject.interferometer.MainViewModel.StartResult.INVALID_ADDRESS;
import static org.briarproject.interferometer.MainViewModel.StartResult.NO_BLUETOOTH;
import static org.briarproject.interferometer.MainViewModel.StartResult.STARTED;
import static org.briarproject.interferometer.MainViewModel.TestPhase.DOWNLOAD;
import static org.briarproject.interferometer.MainViewModel.TestPhase.READY;
......@@ -35,7 +37,7 @@ public class MainViewModel extends ViewModel {
enum ConnectionState {DISCONNECTED, DOWNLOADING, UPLOADING}
enum StartResult {INVALID_ADDRESS, STARTED}
enum StartResult {INVALID_ADDRESS, NO_BLUETOOTH, STARTED}
private static final byte CONNECTION_TYPE_UPLOAD = 0;
private static final byte CONNECTION_TYPE_DOWNLOAD = 1;
......@@ -69,6 +71,8 @@ public class MainViewModel extends ViewModel {
StartResult startTest(String serverAddress) {
HostPort hostPort = parseServerAddress(serverAddress);
if (hostPort == null) return INVALID_ADDRESS;
BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
if (adapter == null) return NO_BLUETOOTH;
task = executorService.submit(() -> {
try {
testPhase.postValue(DOWNLOAD);
......
......@@ -3,6 +3,7 @@
<string name="server_address">Server address</string>
<string name="server_address_error">Invalid address</string>
<string name="no_bluetooth_error">Device does not have Bluetooth</string>
<string name="start_test">Start test</string>
<string name="stop_test">Stop test</string>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment