mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-12 18:59:06 +01:00
Merge branch 'default-plugin-settings' into 'master'
Enable LAN plugin by default, move default settings to constants See merge request briar/briar!1256
This commit is contained in:
@@ -42,6 +42,7 @@ import static java.util.Collections.list;
|
||||
import static java.util.Collections.singletonList;
|
||||
import static java.util.logging.Level.WARNING;
|
||||
import static java.util.logging.Logger.getLogger;
|
||||
import static org.briarproject.bramble.api.plugin.LanTcpConstants.DEFAULT_PREF_PLUGIN_ENABLE;
|
||||
import static org.briarproject.bramble.api.plugin.Plugin.State.ACTIVE;
|
||||
import static org.briarproject.bramble.api.plugin.Plugin.State.INACTIVE;
|
||||
import static org.briarproject.bramble.util.IoUtils.tryToClose;
|
||||
@@ -82,7 +83,8 @@ class AndroidLanTcpPlugin extends LanTcpPlugin {
|
||||
if (used.getAndSet(true)) throw new IllegalStateException();
|
||||
initialisePortProperty();
|
||||
Settings settings = callback.getSettings();
|
||||
state.setStarted(settings.getBoolean(PREF_PLUGIN_ENABLE, false));
|
||||
state.setStarted(settings.getBoolean(PREF_PLUGIN_ENABLE,
|
||||
DEFAULT_PREF_PLUGIN_ENABLE));
|
||||
updateConnectionStatus();
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,10 @@ public interface BluetoothConstants {
|
||||
|
||||
int UUID_BYTES = 16;
|
||||
|
||||
// Transport properties
|
||||
String PROP_ADDRESS = "address";
|
||||
String PROP_UUID = "uuid";
|
||||
|
||||
// Default value for PREF_PLUGIN_ENABLE
|
||||
boolean DEFAULT_PREF_PLUGIN_ENABLE = false;
|
||||
}
|
||||
|
||||
@@ -12,4 +12,7 @@ public interface LanTcpConstants {
|
||||
// Local settings (not shared with contacts)
|
||||
String PREF_LAN_IP_PORTS = "ipPorts";
|
||||
String PREF_IPV6 = "ipv6";
|
||||
|
||||
// Default value for PREF_PLUGIN_ENABLE
|
||||
boolean DEFAULT_PREF_PLUGIN_ENABLE = true;
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ public interface TorConstants {
|
||||
|
||||
TransportId ID = new TransportId("org.briarproject.bramble.tor");
|
||||
|
||||
// Transport properties
|
||||
String PROP_ONION_V2 = "onion";
|
||||
String PROP_ONION_V3 = "onion3";
|
||||
|
||||
@@ -13,17 +14,25 @@ public interface TorConstants {
|
||||
int CONNECT_TO_PROXY_TIMEOUT = 5000; // Milliseconds
|
||||
int EXTRA_SOCKET_TIMEOUT = 30000; // Milliseconds
|
||||
|
||||
// Local settings (not shared with contacts)
|
||||
String PREF_TOR_NETWORK = "network2";
|
||||
String PREF_TOR_PORT = "port";
|
||||
String PREF_TOR_MOBILE = "useMobileData";
|
||||
String PREF_TOR_ONLY_WHEN_CHARGING = "onlyWhenCharging";
|
||||
|
||||
// Values for PREF_TOR_NETWORK
|
||||
int PREF_TOR_NETWORK_AUTOMATIC = 0;
|
||||
int PREF_TOR_NETWORK_WITHOUT_BRIDGES = 1;
|
||||
int PREF_TOR_NETWORK_WITH_BRIDGES = 2;
|
||||
// TODO: Remove when settings migration code is removed
|
||||
int PREF_TOR_NETWORK_NEVER = 3;
|
||||
|
||||
// Default values for local settings
|
||||
boolean DEFAULT_PREF_PLUGIN_ENABLE = true;
|
||||
int DEFAULT_PREF_TOR_NETWORK = PREF_TOR_NETWORK_AUTOMATIC;
|
||||
boolean DEFAULT_PREF_TOR_MOBILE = true;
|
||||
boolean DEFAULT_PREF_TOR_ONLY_WHEN_CHARGING = false;
|
||||
|
||||
/**
|
||||
* Reason flag returned by {@link Plugin#getReasonsDisabled()}.
|
||||
*/
|
||||
|
||||
@@ -4,4 +4,7 @@ public interface WanTcpConstants {
|
||||
|
||||
TransportId ID = new TransportId("org.briarproject.bramble.wan");
|
||||
|
||||
// Default value for PREF_PLUGIN_ENABLE
|
||||
boolean DEFAULT_PREF_PLUGIN_ENABLE = false;
|
||||
}
|
||||
|
||||
|
||||
@@ -46,6 +46,7 @@ import static java.util.logging.Level.INFO;
|
||||
import static java.util.logging.Level.WARNING;
|
||||
import static java.util.logging.Logger.getLogger;
|
||||
import static org.briarproject.bramble.api.keyagreement.KeyAgreementConstants.TRANSPORT_ID_BLUETOOTH;
|
||||
import static org.briarproject.bramble.api.plugin.BluetoothConstants.DEFAULT_PREF_PLUGIN_ENABLE;
|
||||
import static org.briarproject.bramble.api.plugin.BluetoothConstants.ID;
|
||||
import static org.briarproject.bramble.api.plugin.BluetoothConstants.PROP_ADDRESS;
|
||||
import static org.briarproject.bramble.api.plugin.BluetoothConstants.PROP_UUID;
|
||||
@@ -164,7 +165,8 @@ abstract class BluetoothPlugin<SS> implements DuplexPlugin, EventListener {
|
||||
public void start() throws PluginException {
|
||||
if (used.getAndSet(true)) throw new IllegalStateException();
|
||||
Settings settings = callback.getSettings();
|
||||
boolean enabledByUser = settings.getBoolean(PREF_PLUGIN_ENABLE, false);
|
||||
boolean enabledByUser = settings.getBoolean(PREF_PLUGIN_ENABLE,
|
||||
DEFAULT_PREF_PLUGIN_ENABLE);
|
||||
state.setStarted(enabledByUser);
|
||||
try {
|
||||
initialiseAdapter();
|
||||
@@ -432,7 +434,8 @@ abstract class BluetoothPlugin<SS> implements DuplexPlugin, EventListener {
|
||||
|
||||
@IoExecutor
|
||||
private void onSettingsUpdated(Settings settings) {
|
||||
boolean enabledByUser = settings.getBoolean(PREF_PLUGIN_ENABLE, false);
|
||||
boolean enabledByUser = settings.getBoolean(PREF_PLUGIN_ENABLE,
|
||||
DEFAULT_PREF_PLUGIN_ENABLE);
|
||||
SS ss = state.setEnabledByUser(enabledByUser);
|
||||
State s = getState();
|
||||
if (ss != null) {
|
||||
|
||||
@@ -38,6 +38,7 @@ import static java.util.logging.Level.INFO;
|
||||
import static java.util.logging.Level.WARNING;
|
||||
import static java.util.logging.Logger.getLogger;
|
||||
import static org.briarproject.bramble.api.keyagreement.KeyAgreementConstants.TRANSPORT_ID_LAN;
|
||||
import static org.briarproject.bramble.api.plugin.LanTcpConstants.DEFAULT_PREF_PLUGIN_ENABLE;
|
||||
import static org.briarproject.bramble.api.plugin.LanTcpConstants.ID;
|
||||
import static org.briarproject.bramble.api.plugin.LanTcpConstants.PREF_IPV6;
|
||||
import static org.briarproject.bramble.api.plugin.LanTcpConstants.PREF_LAN_IP_PORTS;
|
||||
@@ -103,7 +104,8 @@ class LanTcpPlugin extends TcpPlugin {
|
||||
if (used.getAndSet(true)) throw new IllegalStateException();
|
||||
initialisePortProperty();
|
||||
Settings settings = callback.getSettings();
|
||||
state.setStarted(settings.getBoolean(PREF_PLUGIN_ENABLE, false));
|
||||
state.setStarted(settings.getBoolean(PREF_PLUGIN_ENABLE,
|
||||
DEFAULT_PREF_PLUGIN_ENABLE));
|
||||
bind();
|
||||
}
|
||||
|
||||
@@ -116,6 +118,11 @@ class LanTcpPlugin extends TcpPlugin {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isEnabledByDefault() {
|
||||
return DEFAULT_PREF_PLUGIN_ENABLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<InetSocketAddress> getLocalSocketAddresses(boolean ipv4) {
|
||||
TransportProperties p = callback.getLocalProperties();
|
||||
|
||||
@@ -102,6 +102,11 @@ abstract class TcpPlugin implements DuplexPlugin, EventListener {
|
||||
protected abstract boolean isConnectable(InterfaceAddress local,
|
||||
InetSocketAddress remote);
|
||||
|
||||
/**
|
||||
* Returns true if the plugin is enabled by default.
|
||||
*/
|
||||
protected abstract boolean isEnabledByDefault();
|
||||
|
||||
TcpPlugin(Executor ioExecutor, Backoff backoff, PluginCallback callback,
|
||||
int maxLatency, int maxIdleTime, int connectionTimeout) {
|
||||
this.ioExecutor = ioExecutor;
|
||||
@@ -131,7 +136,8 @@ abstract class TcpPlugin implements DuplexPlugin, EventListener {
|
||||
public void start() {
|
||||
if (used.getAndSet(true)) throw new IllegalStateException();
|
||||
Settings settings = callback.getSettings();
|
||||
state.setStarted(settings.getBoolean(PREF_PLUGIN_ENABLE, false));
|
||||
state.setStarted(
|
||||
settings.getBoolean(PREF_PLUGIN_ENABLE, isEnabledByDefault()));
|
||||
bind();
|
||||
}
|
||||
|
||||
@@ -402,7 +408,8 @@ abstract class TcpPlugin implements DuplexPlugin, EventListener {
|
||||
|
||||
@IoExecutor
|
||||
private void onSettingsUpdated(Settings settings) {
|
||||
boolean enabledByUser = settings.getBoolean(PREF_PLUGIN_ENABLE, false);
|
||||
boolean enabledByUser =
|
||||
settings.getBoolean(PREF_PLUGIN_ENABLE, isEnabledByDefault());
|
||||
List<ServerSocket> toClose = state.setEnabledByUser(enabledByUser);
|
||||
State s = getState();
|
||||
if (!toClose.isEmpty()) {
|
||||
|
||||
@@ -17,6 +17,7 @@ import java.util.concurrent.Executor;
|
||||
|
||||
import static java.util.Collections.emptyList;
|
||||
import static java.util.Collections.singletonList;
|
||||
import static org.briarproject.bramble.api.plugin.WanTcpConstants.DEFAULT_PREF_PLUGIN_ENABLE;
|
||||
import static org.briarproject.bramble.api.plugin.WanTcpConstants.ID;
|
||||
|
||||
@MethodsNotNullByDefault
|
||||
@@ -42,6 +43,11 @@ class WanTcpPlugin extends TcpPlugin {
|
||||
return ID;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isEnabledByDefault() {
|
||||
return DEFAULT_PREF_PLUGIN_ENABLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<InetSocketAddress> getLocalSocketAddresses(boolean ipv4) {
|
||||
if (!ipv4) return emptyList();
|
||||
|
||||
@@ -75,6 +75,10 @@ import static org.briarproject.bramble.api.plugin.Plugin.State.ENABLING;
|
||||
import static org.briarproject.bramble.api.plugin.Plugin.State.INACTIVE;
|
||||
import static org.briarproject.bramble.api.plugin.Plugin.State.STARTING_STOPPING;
|
||||
import static org.briarproject.bramble.api.plugin.TorConstants.CONTROL_PORT;
|
||||
import static org.briarproject.bramble.api.plugin.TorConstants.DEFAULT_PREF_PLUGIN_ENABLE;
|
||||
import static org.briarproject.bramble.api.plugin.TorConstants.DEFAULT_PREF_TOR_MOBILE;
|
||||
import static org.briarproject.bramble.api.plugin.TorConstants.DEFAULT_PREF_TOR_NETWORK;
|
||||
import static org.briarproject.bramble.api.plugin.TorConstants.DEFAULT_PREF_TOR_ONLY_WHEN_CHARGING;
|
||||
import static org.briarproject.bramble.api.plugin.TorConstants.ID;
|
||||
import static org.briarproject.bramble.api.plugin.TorConstants.PREF_TOR_MOBILE;
|
||||
import static org.briarproject.bramble.api.plugin.TorConstants.PREF_TOR_NETWORK;
|
||||
@@ -290,9 +294,9 @@ abstract class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
|
||||
// TODO: Remove after a reasonable migration period (added 2020-06-25)
|
||||
private Settings migrateSettings(Settings settings) {
|
||||
int network = settings.getInt(PREF_TOR_NETWORK,
|
||||
PREF_TOR_NETWORK_AUTOMATIC);
|
||||
DEFAULT_PREF_TOR_NETWORK);
|
||||
if (network == PREF_TOR_NETWORK_NEVER) {
|
||||
settings.putInt(PREF_TOR_NETWORK, PREF_TOR_NETWORK_AUTOMATIC);
|
||||
settings.putInt(PREF_TOR_NETWORK, DEFAULT_PREF_TOR_NETWORK);
|
||||
settings.putBoolean(PREF_PLUGIN_ENABLE, false);
|
||||
callback.mergeSettings(settings);
|
||||
}
|
||||
@@ -774,13 +778,15 @@ abstract class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
|
||||
String country = locationUtils.getCurrentCountry();
|
||||
boolean blocked =
|
||||
circumventionProvider.isTorProbablyBlocked(country);
|
||||
boolean enabledByUser =
|
||||
settings.getBoolean(PREF_PLUGIN_ENABLE, true);
|
||||
boolean enabledByUser = settings.getBoolean(PREF_PLUGIN_ENABLE,
|
||||
DEFAULT_PREF_PLUGIN_ENABLE);
|
||||
int network = settings.getInt(PREF_TOR_NETWORK,
|
||||
PREF_TOR_NETWORK_AUTOMATIC);
|
||||
boolean useMobile = settings.getBoolean(PREF_TOR_MOBILE, true);
|
||||
DEFAULT_PREF_TOR_NETWORK);
|
||||
boolean useMobile = settings.getBoolean(PREF_TOR_MOBILE,
|
||||
DEFAULT_PREF_TOR_MOBILE);
|
||||
boolean onlyWhenCharging =
|
||||
settings.getBoolean(PREF_TOR_ONLY_WHEN_CHARGING, false);
|
||||
settings.getBoolean(PREF_TOR_ONLY_WHEN_CHARGING,
|
||||
DEFAULT_PREF_TOR_ONLY_WHEN_CHARGING);
|
||||
boolean bridgesWork = circumventionProvider.doBridgesWork(country);
|
||||
boolean automatic = network == PREF_TOR_NETWORK_AUTOMATIC;
|
||||
|
||||
|
||||
@@ -75,6 +75,9 @@ import static androidx.core.view.ViewCompat.LAYOUT_DIRECTION_LTR;
|
||||
import static java.util.logging.Level.INFO;
|
||||
import static java.util.logging.Level.WARNING;
|
||||
import static org.briarproject.bramble.api.plugin.Plugin.PREF_PLUGIN_ENABLE;
|
||||
import static org.briarproject.bramble.api.plugin.TorConstants.DEFAULT_PREF_TOR_MOBILE;
|
||||
import static org.briarproject.bramble.api.plugin.TorConstants.DEFAULT_PREF_TOR_NETWORK;
|
||||
import static org.briarproject.bramble.api.plugin.TorConstants.DEFAULT_PREF_TOR_ONLY_WHEN_CHARGING;
|
||||
import static org.briarproject.bramble.api.plugin.TorConstants.PREF_TOR_MOBILE;
|
||||
import static org.briarproject.bramble.api.plugin.TorConstants.PREF_TOR_NETWORK;
|
||||
import static org.briarproject.bramble.api.plugin.TorConstants.PREF_TOR_NETWORK_AUTOMATIC;
|
||||
@@ -372,9 +375,9 @@ public class SettingsFragment extends PreferenceFragmentCompat
|
||||
|
||||
// TODO: Remove after a reasonable migration period (added 2020-06-25)
|
||||
private Settings migrateTorSettings(Settings s) {
|
||||
int network = s.getInt(PREF_TOR_NETWORK, PREF_TOR_NETWORK_AUTOMATIC);
|
||||
int network = s.getInt(PREF_TOR_NETWORK, DEFAULT_PREF_TOR_NETWORK);
|
||||
if (network == PREF_TOR_NETWORK_NEVER) {
|
||||
s.putInt(PREF_TOR_NETWORK, PREF_TOR_NETWORK_AUTOMATIC);
|
||||
s.putInt(PREF_TOR_NETWORK, DEFAULT_PREF_TOR_NETWORK);
|
||||
s.putBoolean(PREF_PLUGIN_ENABLE, false);
|
||||
// We don't need to save the migrated settings - the Tor plugin is
|
||||
// responsible for that. This code just handles the case where the
|
||||
@@ -388,29 +391,32 @@ public class SettingsFragment extends PreferenceFragmentCompat
|
||||
// due to events, we might try to display before a load completed
|
||||
if (!settingsLoaded) return;
|
||||
|
||||
boolean btEnabledSetting =
|
||||
btSettings.getBoolean(PREF_PLUGIN_ENABLE, false);
|
||||
boolean btEnabledSetting = btSettings.getBoolean(PREF_PLUGIN_ENABLE,
|
||||
BluetoothConstants.DEFAULT_PREF_PLUGIN_ENABLE);
|
||||
enableBluetooth.setChecked(btEnabledSetting);
|
||||
|
||||
boolean wifiEnabledSetting =
|
||||
wifiSettings.getBoolean(PREF_PLUGIN_ENABLE, false);
|
||||
wifiSettings.getBoolean(PREF_PLUGIN_ENABLE,
|
||||
LanTcpConstants.DEFAULT_PREF_PLUGIN_ENABLE);
|
||||
enableWifi.setChecked(wifiEnabledSetting);
|
||||
|
||||
boolean torEnabledSetting =
|
||||
torSettings.getBoolean(PREF_PLUGIN_ENABLE, true);
|
||||
torSettings.getBoolean(PREF_PLUGIN_ENABLE,
|
||||
TorConstants.DEFAULT_PREF_PLUGIN_ENABLE);
|
||||
enableTor.setChecked(torEnabledSetting);
|
||||
|
||||
int torNetworkSetting = torSettings.getInt(PREF_TOR_NETWORK,
|
||||
PREF_TOR_NETWORK_AUTOMATIC);
|
||||
DEFAULT_PREF_TOR_NETWORK);
|
||||
torNetwork.setValue(Integer.toString(torNetworkSetting));
|
||||
setTorNetworkSummary(torNetworkSetting);
|
||||
|
||||
boolean torMobileSetting =
|
||||
torSettings.getBoolean(PREF_TOR_MOBILE, true);
|
||||
boolean torMobileSetting = torSettings.getBoolean(PREF_TOR_MOBILE,
|
||||
DEFAULT_PREF_TOR_MOBILE);
|
||||
torMobile.setChecked(torMobileSetting);
|
||||
|
||||
boolean torChargingSetting =
|
||||
torSettings.getBoolean(PREF_TOR_ONLY_WHEN_CHARGING, false);
|
||||
torSettings.getBoolean(PREF_TOR_ONLY_WHEN_CHARGING,
|
||||
DEFAULT_PREF_TOR_ONLY_WHEN_CHARGING);
|
||||
torOnlyWhenCharging.setChecked(torChargingSetting);
|
||||
|
||||
displayScreenLockSetting();
|
||||
|
||||
Reference in New Issue
Block a user