ENH: Replaces transport config with namespaced settings

This commit is contained in:
Santiago Torres
2016-01-17 15:42:45 -05:00
parent 2b02db3023
commit 190bb12964
27 changed files with 206 additions and 238 deletions

View File

@@ -93,7 +93,7 @@ EventListener {
dbExecutor.execute(new Runnable() {
public void run() {
try {
settings = db.getSettings();
settings = db.getSettings("settings-activity");
} catch (DbException e) {
if (LOG.isLoggable(WARNING))
LOG.log(WARNING, e.toString(), e);

View File

@@ -23,7 +23,7 @@ import org.briarproject.android.util.HorizontalBorder;
import org.briarproject.android.util.LayoutUtils;
import org.briarproject.android.util.ListLoadingProgressBar;
import org.briarproject.api.Settings;
import org.briarproject.api.TransportConfig;
import org.briarproject.api.settings.SettingsManager;
import org.briarproject.api.TransportId;
import org.briarproject.api.db.DatabaseComponent;
import org.briarproject.api.db.DbException;
@@ -77,6 +77,7 @@ OnClickListener {
// Fields that are accessed from background threads must be volatile
@Inject private volatile DatabaseComponent db;
@Inject private volatile SettingsManager settingsManager;
@Inject private volatile EventBus eventBus;
private volatile Settings settings;
private volatile boolean bluetoothSetting = true, torSetting = false;
@@ -262,14 +263,15 @@ OnClickListener {
runOnDbThread(new Runnable() {
public void run() {
try {
settings = settingsManager.getSettings("settings-activity");
long now = System.currentTimeMillis();
TransportConfig c = db.getConfig(new TransportId("bt"));
settings = db.getSettings();
Settings btSettings = settingsManager.getSettings("bt");
Settings torSettings = settingsManager.getSettings("tor");
long duration = System.currentTimeMillis() - now;
if (LOG.isLoggable(INFO))
LOG.info("Loading settings took " + duration + " ms");
bluetoothSetting = c.getBoolean("enable", false);
torSetting = settings.getBoolean("torOverWifi", false);
bluetoothSetting = btSettings.getBoolean("enable", false);
torSetting = torSettings.getBoolean("torOverWifi", false);
displaySettings();
} catch (DbException e) {
if (LOG.isLoggable(WARNING))
@@ -338,6 +340,7 @@ OnClickListener {
} else if (view == torOverWifi || view == torOverWifiHint) {
torSetting = !torSetting;
storeTorSettings();
displaySettings();
} else if (view == notifyPrivateMessages) {
Settings s = new Settings();
s.putBoolean("notifyPrivateMessages",
@@ -378,11 +381,8 @@ OnClickListener {
try {
Settings s = new Settings();
s.putBoolean("torOverWifi", torSetting);
TransportConfig c = new TransportConfig();
c.putBoolean("torOverWifi", torSetting);
long now = System.currentTimeMillis();
db.mergeSettings(s);
db.mergeConfig(new TransportId("tor"), c);
settingsManager.mergeSettings(s, "tor");
long duration = System.currentTimeMillis() - now;
if (LOG.isLoggable(INFO))
LOG.info("Merging config took " + duration + " ms");
@@ -398,10 +398,10 @@ OnClickListener {
runOnDbThread(new Runnable() {
public void run() {
try {
TransportConfig c = new TransportConfig();
c.putBoolean("enable", bluetoothSetting);
Settings s = new Settings();
s.putBoolean("enable", bluetoothSetting);
long now = System.currentTimeMillis();
db.mergeConfig(new TransportId("bt"), c);
settingsManager.mergeSettings(s, "bt");
long duration = System.currentTimeMillis() - now;
if (LOG.isLoggable(INFO))
LOG.info("Merging config took " + duration + " ms");
@@ -418,7 +418,7 @@ OnClickListener {
public void run() {
try {
long now = System.currentTimeMillis();
db.mergeSettings(settings);
settingsManager.mergeSettings(settings, "settings-activity");
long duration = System.currentTimeMillis() - now;
if (LOG.isLoggable(INFO))
LOG.info("Merging settings took " + duration + " ms");

View File

@@ -8,7 +8,7 @@ import android.widget.Toast;
import org.briarproject.R;
import org.briarproject.android.BriarActivity;
import org.briarproject.android.util.AndroidUtils;
import org.briarproject.api.TransportConfig;
import org.briarproject.api.Settings;
import org.briarproject.api.TransportId;
import org.briarproject.api.android.ReferenceManager;
import org.briarproject.api.crypto.CryptoComponent;
@@ -170,12 +170,12 @@ implements InvitationListener {
public void run() {
try {
long now = System.currentTimeMillis();
TransportConfig c = db.getConfig(new TransportId("bt"));
Settings s = db.getSettings("bt");
long duration = System.currentTimeMillis() - now;
if (LOG.isLoggable(INFO))
LOG.info("Loading setting took " + duration + " ms");
leaveBluetoothEnabled = bluetoothWasEnabled
|| c.getBoolean("enable", false);
|| s.getBoolean("enable", false);
} catch (DbException e) {
if (LOG.isLoggable(WARNING))
LOG.log(WARNING, e.toString(), e);

View File

@@ -137,7 +137,7 @@ class DroidtoothPlugin implements DuplexPlugin {
bind();
} else {
wasDisabled = true;
if (callback.getConfig().getBoolean("enable", false)) {
if (callback.getSettings().getBoolean("enable", false)) {
if (adapter.enable()) LOG.info("Enabling Bluetooth");
else LOG.info("Could not enable Bluetooth");
} else {

View File

@@ -11,7 +11,7 @@ import android.os.FileObserver;
import net.freehaven.tor.control.EventHandler;
import net.freehaven.tor.control.TorControlConnection;
import org.briarproject.api.TransportConfig;
import org.briarproject.api.Settings;
import org.briarproject.api.TransportId;
import org.briarproject.api.TransportProperties;
import org.briarproject.api.contact.ContactId;
@@ -23,6 +23,7 @@ import org.briarproject.api.plugins.duplex.DuplexPlugin;
import org.briarproject.api.plugins.duplex.DuplexPluginCallback;
import org.briarproject.api.plugins.duplex.DuplexTransportConnection;
import org.briarproject.api.system.LocationUtils;
import org.briarproject.api.settings.SettingsManager;
import org.briarproject.util.StringUtils;
import java.io.EOFException;
@@ -349,7 +350,7 @@ class TorPlugin implements DuplexPlugin, EventHandler,
ioExecutor.execute(new Runnable() {
public void run() {
// If there's already a port number stored in config, reuse it
String portString = callback.getConfig().get("port");
String portString = callback.getSettings().get("port");
int port;
if (StringUtils.isNullOrEmpty(portString)) port = 0;
else port = Integer.parseInt(portString);
@@ -371,9 +372,9 @@ class TorPlugin implements DuplexPlugin, EventHandler,
socket = ss;
// Store the port number
final String localPort = String.valueOf(ss.getLocalPort());
TransportConfig c = new TransportConfig();
c.put("port", localPort);
callback.mergeConfig(c);
Settings s = new Settings();
s.put("port", localPort);
callback.mergeSettings(s);
// Create a hidden service if necessary
ioExecutor.execute(new Runnable() {
public void run() {
@@ -614,8 +615,8 @@ class TorPlugin implements DuplexPlugin, EventHandler,
}
boolean blocked = TorNetworkMetadata.isTorProbablyBlocked(
country);
TransportConfig c = callback.getConfig();
boolean wifiOnly = c.getBoolean("torOverWifi", false);
Settings s = callback.getSettings();
boolean wifiOnly = s.getBoolean("torOverWifi", false);
try {
if (!online) {