diff --git a/briar-android/src/org/briarproject/android/SettingsActivity.java b/briar-android/src/org/briarproject/android/SettingsActivity.java index 2be512d37644c9c4b52d26f2cb975626909d150b..addccdc66bab944a325e198444a7cd07ebfb41bc 100644 --- a/briar-android/src/org/briarproject/android/SettingsActivity.java +++ b/briar-android/src/org/briarproject/android/SettingsActivity.java @@ -23,14 +23,13 @@ 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.settings.SettingsManager; -import org.briarproject.api.TransportId; import org.briarproject.api.db.DatabaseComponent; import org.briarproject.api.db.DbException; import org.briarproject.api.event.Event; import org.briarproject.api.event.EventBus; import org.briarproject.api.event.EventListener; import org.briarproject.api.event.SettingsUpdatedEvent; +import org.briarproject.api.settings.SettingsManager; import org.briarproject.util.StringUtils; import java.util.logging.Logger; @@ -263,8 +262,8 @@ OnClickListener { runOnDbThread(new Runnable() { public void run() { try { - settings = settingsManager.getSettings("settings-activity"); long now = System.currentTimeMillis(); + settings = settingsManager.getSettings("settings-activity"); Settings btSettings = settingsManager.getSettings("bt"); Settings torSettings = settingsManager.getSettings("tor"); long duration = System.currentTimeMillis() - now; @@ -335,7 +334,7 @@ OnClickListener { if (adapter != null) { AndroidUtils.setBluetooth(adapter, bluetoothSetting); } - storeBluetoothSetting(); + storeBluetoothSettings(); displaySettings(); } else if (view == torOverWifi || view == torOverWifiHint) { torSetting = !torSetting; @@ -385,7 +384,7 @@ OnClickListener { settingsManager.mergeSettings(s, "tor"); long duration = System.currentTimeMillis() - now; if (LOG.isLoggable(INFO)) - LOG.info("Merging config took " + duration + " ms"); + LOG.info("Merging settings took " + duration + " ms"); } catch (DbException e) { if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e); @@ -394,7 +393,7 @@ OnClickListener { }); } - private void storeBluetoothSetting() { + private void storeBluetoothSettings() { runOnDbThread(new Runnable() { public void run() { try { @@ -404,7 +403,7 @@ OnClickListener { settingsManager.mergeSettings(s, "bt"); long duration = System.currentTimeMillis() - now; if (LOG.isLoggable(INFO)) - LOG.info("Merging config took " + duration + " ms"); + LOG.info("Merging settings took " + duration + " ms"); } catch (DbException e) { if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e); diff --git a/briar-api/src/org/briarproject/api/db/DatabaseComponent.java b/briar-api/src/org/briarproject/api/db/DatabaseComponent.java index d1ed50606e9685814da7cbfa8148e6aee0caec67..086689409b835ed413541fde6dffa092d6bc0dd9 100644 --- a/briar-api/src/org/briarproject/api/db/DatabaseComponent.java +++ b/briar-api/src/org/briarproject/api/db/DatabaseComponent.java @@ -190,7 +190,7 @@ public interface DatabaseComponent { Map<ContactId, TransportProperties> getRemoteProperties(TransportId t) throws DbException; - /** Returns all settings for a given namespace. */ + /** Returns all settings in the given namespace. */ Settings getSettings(String namespace) throws DbException; /** Returns all contacts who subscribe to the given group. */ @@ -223,7 +223,10 @@ public interface DatabaseComponent { void mergeLocalProperties(TransportId t, TransportProperties p) throws DbException; - /** Merges the given settings with the existing settings. */ + /** + * Merges the given settings with the existing settings in the given + * namespace. + */ void mergeSettings(Settings s, String namespace) throws DbException; /** Processes an ack from the given contact. */ diff --git a/briar-api/src/org/briarproject/api/settings/SettingsManager.java b/briar-api/src/org/briarproject/api/settings/SettingsManager.java index c398ebc62347a21874261b512d4b1b2d516925a2..33c36e4ef193b88907a2118c6ea01c101ac8a32b 100644 --- a/briar-api/src/org/briarproject/api/settings/SettingsManager.java +++ b/briar-api/src/org/briarproject/api/settings/SettingsManager.java @@ -1,20 +1,16 @@ package org.briarproject.api.settings; -import org.briarproject.api.db.DbException; import org.briarproject.api.Settings; +import org.briarproject.api.db.DbException; public interface SettingsManager { - /** - * Returns the settings object identified by the provided namespace - * string - */ + /** Returns all settings in the given namespace. */ Settings getSettings(String namespace) throws DbException; /** - * Merges (read syncs) the provided settings identified by the provided namespace - * string - */ + * Merges the given settings with the existing settings in the given + * namespace. + */ void mergeSettings(Settings s, String namespace) throws DbException; - } diff --git a/briar-core/src/org/briarproject/db/Database.java b/briar-core/src/org/briarproject/db/Database.java index 374c56081160c46e35b9483620546329fb8ea879..9963267fee251901ff844bad912a4637bec7bd9c 100644 --- a/briar-core/src/org/briarproject/db/Database.java +++ b/briar-core/src/org/briarproject/db/Database.java @@ -411,7 +411,7 @@ interface Database<T> { int maxLength) throws DbException; /** - * Returns all settings that belong to a namespace. + * Returns all settings in the given namespace. * <p> * Locking: read. */ @@ -526,11 +526,12 @@ interface Database<T> { throws DbException; /** - * Merges the given settings with the existing settings. + * Merges the given settings with the existing settings in the given + * namespace. * <p> * Locking: write. */ - void mergeSettings(T txn, Settings s, String Namespace) throws DbException; + void mergeSettings(T txn, Settings s, String namespace) throws DbException; /** * Marks a message as needing to be acknowledged to the given contact. diff --git a/briar-core/src/org/briarproject/plugins/PluginManagerImpl.java b/briar-core/src/org/briarproject/plugins/PluginManagerImpl.java index 1bd9f805fc4e6c4e2315d02feb909c9b2a55bc4e..abdf1657800d0b496084a3baffb7013fced02aa8 100644 --- a/briar-core/src/org/briarproject/plugins/PluginManagerImpl.java +++ b/briar-core/src/org/briarproject/plugins/PluginManagerImpl.java @@ -1,5 +1,6 @@ package org.briarproject.plugins; +import org.briarproject.api.Settings; import org.briarproject.api.TransportId; import org.briarproject.api.TransportProperties; import org.briarproject.api.contact.ContactId; @@ -27,8 +28,6 @@ import org.briarproject.api.plugins.simplex.SimplexPluginFactory; import org.briarproject.api.property.TransportPropertyManager; import org.briarproject.api.system.Clock; import org.briarproject.api.ui.UiCallback; -import org.briarproject.api.Settings; -import org.briarproject.api.settings.SettingsManager; import java.io.IOException; import java.util.ArrayList; @@ -168,9 +167,7 @@ class PluginManagerImpl implements PluginManager { public void run() { try { TransportId id = factory.getId(); - String namespace = id.toString(); - - SimplexCallback callback = new SimplexCallback(id, namespace); + SimplexCallback callback = new SimplexCallback(id); SimplexPlugin plugin = factory.createPlugin(callback); if (plugin == null) { if (LOG.isLoggable(INFO)) { @@ -233,8 +230,7 @@ class PluginManagerImpl implements PluginManager { public void run() { try { TransportId id = factory.getId(); - String namespace = id.toString(); - DuplexCallback callback = new DuplexCallback(id, namespace); + DuplexCallback callback = new DuplexCallback(id); DuplexPlugin plugin = factory.createPlugin(callback); if (plugin == null) { if (LOG.isLoggable(INFO)) { @@ -313,22 +309,18 @@ class PluginManagerImpl implements PluginManager { private abstract class PluginCallbackImpl implements PluginCallback { protected final TransportId id; - protected final String namespace; - protected PluginCallbackImpl(TransportId id, String namespace) { + protected PluginCallbackImpl(TransportId id) { this.id = id; - this.namespace = namespace; } public Settings getSettings() { - try { - return db.getSettings(namespace); + return db.getSettings(id.getString()); } catch (DbException e) { if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e); return new Settings(); } - } public TransportProperties getLocalProperties() { @@ -352,13 +344,11 @@ class PluginManagerImpl implements PluginManager { } public void mergeSettings(Settings s) { - try { - db.mergeSettings(s, namespace); + db.mergeSettings(s, id.getString()); } catch (DbException e) { if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e); } - } public void mergeLocalProperties(TransportProperties p) { @@ -383,7 +373,6 @@ class PluginManagerImpl implements PluginManager { public void transportEnabled() { eventBus.broadcast(new TransportEnabledEvent(id)); - Plugin p = plugins.get(id); if (p != null) poller.pollNow(p); } @@ -396,8 +385,8 @@ class PluginManagerImpl implements PluginManager { private class SimplexCallback extends PluginCallbackImpl implements SimplexPluginCallback { - private SimplexCallback(TransportId id, String namespace) { - super(id, namespace); + private SimplexCallback(TransportId id) { + super(id); } public void readerCreated(TransportConnectionReader r) { @@ -412,8 +401,8 @@ class PluginManagerImpl implements PluginManager { private class DuplexCallback extends PluginCallbackImpl implements DuplexPluginCallback { - private DuplexCallback(TransportId id, String namespace) { - super(id, namespace); + private DuplexCallback(TransportId id) { + super(id); } public void incomingConnectionCreated(DuplexTransportConnection d) { diff --git a/briar-core/src/org/briarproject/settings/SettingsManagerImpl.java b/briar-core/src/org/briarproject/settings/SettingsManagerImpl.java index 6aa72c0273e71139ec6e4688b68a99cf34462440..d003f9e35d6fb99d7f00ee85e72572aba7c02ef5 100644 --- a/briar-core/src/org/briarproject/settings/SettingsManagerImpl.java +++ b/briar-core/src/org/briarproject/settings/SettingsManagerImpl.java @@ -2,43 +2,27 @@ package org.briarproject.settings; import com.google.inject.Inject; -import org.briarproject.api.settings.SettingsManager; import org.briarproject.api.Settings; - import org.briarproject.api.db.DatabaseComponent; import org.briarproject.api.db.DbException; -import java.util.logging.Logger; - -import java.util.Collection; +import org.briarproject.api.settings.SettingsManager; class SettingsManagerImpl implements SettingsManager { private final DatabaseComponent db; - private static final Logger LOG = - Logger.getLogger("SettingsManagerImpl"); @Inject SettingsManagerImpl(DatabaseComponent db) { this.db = db; } - /** - * Returns the settings object identified by the provided namespace - * string - */ @Override public Settings getSettings(String namespace) throws DbException { return db.getSettings(namespace); } - /** - * Merges (read syncs) the provided settings identified by the provided namespace - * string - */ @Override public void mergeSettings(Settings s, String namespace) throws DbException { db.mergeSettings(s, namespace); } - - }