Use default value of false for Bluetooth setting. #178

This commit is contained in:
akwizgran
2015-12-15 16:09:09 +00:00
parent bab9a41981
commit 660f709ede

View File

@@ -29,8 +29,8 @@ import static android.widget.Toast.LENGTH_LONG;
import static java.util.logging.Level.INFO; import static java.util.logging.Level.INFO;
import static java.util.logging.Level.WARNING; import static java.util.logging.Level.WARNING;
import static org.briarproject.android.invitation.ConfirmationCodeView.ConfirmationState.CONNECTED; import static org.briarproject.android.invitation.ConfirmationCodeView.ConfirmationState.CONNECTED;
import static org.briarproject.android.invitation.ConfirmationCodeView.ConfirmationState.WAIT_FOR_CONTACT;
import static org.briarproject.android.invitation.ConfirmationCodeView.ConfirmationState.DETAILS; import static org.briarproject.android.invitation.ConfirmationCodeView.ConfirmationState.DETAILS;
import static org.briarproject.android.invitation.ConfirmationCodeView.ConfirmationState.WAIT_FOR_CONTACT;
public class AddContactActivity extends BriarActivity public class AddContactActivity extends BriarActivity
implements InvitationListener { implements InvitationListener {
@@ -76,7 +76,8 @@ implements InvitationListener {
taskHandle = state.getLong("briar.TASK_HANDLE", -1); taskHandle = state.getLong("briar.TASK_HANDLE", -1);
task = referenceManager.getReference(taskHandle, task = referenceManager.getReference(taskHandle,
InvitationTask.class); InvitationTask.class);
bluetoothWasEnabled = state.getBoolean("briar.BLUETOOTH_WAS_ENABLED"); bluetoothWasEnabled =
state.getBoolean("briar.BLUETOOTH_WAS_ENABLED");
if (task == null) { if (task == null) {
// No background task - we must be in an initial or final state // No background task - we must be in an initial or final state
@@ -97,10 +98,10 @@ implements InvitationListener {
setView(new ErrorView(this, R.string.connection_failed, setView(new ErrorView(this, R.string.connection_failed,
R.string.could_not_find_contact)); R.string.could_not_find_contact));
} else if (contactName == null) { } else if (contactName == null) {
setView(new ErrorView(this, R.string.codes_do_not_match, R.string.interfering)); setView(new ErrorView(this, R.string.codes_do_not_match,
R.string.interfering));
} else { } else {
showToastAndFinish(); showToastAndFinish();
return;
} }
} else { } else {
// A background task exists - listen to it and get its state // A background task exists - listen to it and get its state
@@ -122,7 +123,8 @@ implements InvitationListener {
} else if (remoteInvitationCode == -1) { } else if (remoteInvitationCode == -1) {
setView(new InvitationCodeView(this)); setView(new InvitationCodeView(this));
} else if (connectionFailed) { } else if (connectionFailed) {
setView(new ErrorView(AddContactActivity.this, R.string.connection_failed, setView(new ErrorView(AddContactActivity.this,
R.string.connection_failed,
R.string.could_not_find_contact)); R.string.could_not_find_contact));
} else if (connected && localConfirmationCode == -1) { } else if (connected && localConfirmationCode == -1) {
setView(new ConfirmationCodeView(this, CONNECTED)); setView(new ConfirmationCodeView(this, CONNECTED));
@@ -137,10 +139,10 @@ implements InvitationListener {
setView(new ConfirmationCodeView(this, DETAILS)); setView(new ConfirmationCodeView(this, DETAILS));
} else { } else {
showToastAndFinish(); showToastAndFinish();
return;
} }
} else { } else {
setView(new ErrorView(this, R.string.codes_do_not_match, R.string.interfering)); setView(new ErrorView(this, R.string.codes_do_not_match,
R.string.interfering));
} }
} }
} }
@@ -169,7 +171,7 @@ implements InvitationListener {
long duration = System.currentTimeMillis() - now; long duration = System.currentTimeMillis() - now;
if (LOG.isLoggable(INFO)) if (LOG.isLoggable(INFO))
LOG.info("Loading setting took " + duration + " ms"); LOG.info("Loading setting took " + duration + " ms");
leaveBluetoothEnabled = c.getBoolean("enable", true); leaveBluetoothEnabled = c.getBoolean("enable", false);
} catch (DbException e) { } catch (DbException e) {
if (LOG.isLoggable(WARNING)) if (LOG.isLoggable(WARNING))
LOG.log(WARNING, e.toString(), e); LOG.log(WARNING, e.toString(), e);
@@ -305,36 +307,38 @@ implements InvitationListener {
localCompared = true; localCompared = true;
if (code == remoteConfirmationCode) { if (code == remoteConfirmationCode) {
localMatched = true; localMatched = true;
if (remoteMatched) setView(new ConfirmationCodeView(this, DETAILS)); if (remoteMatched) {
else if (remoteCompared) setView(new ErrorView(this, R.string.codes_do_not_match, setView(new ConfirmationCodeView(this, DETAILS));
R.string.interfering)); } else if (remoteCompared) {
else setView(new ConfirmationCodeView(this, WAIT_FOR_CONTACT)); setView(new ErrorView(this, R.string.codes_do_not_match,
R.string.interfering));
} else {
setView(new ConfirmationCodeView(this, WAIT_FOR_CONTACT));
}
task.localConfirmationSucceeded(); task.localConfirmationSucceeded();
} else { } else {
localMatched = false; localMatched = false;
setView(new ErrorView(this, R.string.codes_do_not_match, R.string.interfering)); setView(new ErrorView(this, R.string.codes_do_not_match,
R.string.interfering));
task.localConfirmationFailed(); task.localConfirmationFailed();
} }
} }
public void disableBluetooth() { public void disableBluetooth() {
if (!bluetoothWasEnabled && !leaveBluetoothEnabled) { if (!bluetoothWasEnabled && !leaveBluetoothEnabled) {
if (LOG.isLoggable(INFO)) LOG.info("Turning off Bluetooth again."); if (LOG.isLoggable(INFO)) LOG.info("Turning off Bluetooth again");
BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter(); BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
if (adapter != null) adapter.disable(); if (adapter != null) adapter.disable();
} }
} }
String getContactName() {
return contactName;
}
public void connectionSucceeded() { public void connectionSucceeded() {
runOnUiThread(new Runnable() { runOnUiThread(new Runnable() {
public void run() { public void run() {
connected = true; connected = true;
setView(new ConfirmationCodeView(AddContactActivity.this, CONNECTED)); setView(new ConfirmationCodeView(AddContactActivity.this,
CONNECTED));
} }
}); });
} }
@@ -343,7 +347,8 @@ implements InvitationListener {
runOnUiThread(new Runnable() { runOnUiThread(new Runnable() {
public void run() { public void run() {
connectionFailed = true; connectionFailed = true;
setView(new ErrorView(AddContactActivity.this, R.string.connection_failed, setView(new ErrorView(AddContactActivity.this,
R.string.connection_failed,
R.string.could_not_find_contact)); R.string.could_not_find_contact));
} }
}); });
@@ -364,7 +369,8 @@ implements InvitationListener {
runOnUiThread(new Runnable() { runOnUiThread(new Runnable() {
public void run() { public void run() {
connectionFailed = true; connectionFailed = true;
setView(new ErrorView(AddContactActivity.this, R.string.connection_failed, setView(new ErrorView(AddContactActivity.this,
R.string.connection_failed,
R.string.could_not_find_contact)); R.string.could_not_find_contact));
} }
}); });
@@ -375,8 +381,10 @@ implements InvitationListener {
public void run() { public void run() {
remoteCompared = true; remoteCompared = true;
remoteMatched = true; remoteMatched = true;
if (localMatched) if (localMatched) {
setView(new ConfirmationCodeView(AddContactActivity.this, DETAILS)); setView(new ConfirmationCodeView(AddContactActivity.this,
DETAILS));
}
} }
}); });
} }
@@ -386,9 +394,10 @@ implements InvitationListener {
public void run() { public void run() {
remoteCompared = true; remoteCompared = true;
remoteMatched = false; remoteMatched = false;
if (localMatched) if (localMatched) {
setView(new ErrorView(AddContactActivity.this, R.string.codes_do_not_match, setView(new ErrorView(AddContactActivity.this,
R.string.interfering)); R.string.codes_do_not_match, R.string.interfering));
}
} }
}); });
} }
@@ -405,7 +414,8 @@ implements InvitationListener {
public void pseudonymExchangeFailed() { public void pseudonymExchangeFailed() {
runOnUiThread(new Runnable() { runOnUiThread(new Runnable() {
public void run() { public void run() {
setView(new ErrorView(AddContactActivity.this, R.string.connection_failed, setView(new ErrorView(AddContactActivity.this,
R.string.connection_failed,
R.string.could_not_find_contact)); R.string.could_not_find_contact));
} }
}); });