mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-15 04:18:53 +01:00
Merge branch 'android-12'
This commit is contained in:
@@ -89,6 +89,17 @@ abstract class AbstractBluetoothPlugin<S, SS> implements BluetoothPlugin,
|
||||
|
||||
private volatile String contactConnectionsUuid = null;
|
||||
|
||||
/**
|
||||
* Override and return true, if the plugin is now allowed to access the
|
||||
* Bluetooth hardware.
|
||||
* If this returns false, the plugin must be
|
||||
* {@link org.briarproject.bramble.api.plugin.Plugin.State#DISABLED}
|
||||
* in {@link #start()} and not attempt to access Bluetooth hardware.
|
||||
*/
|
||||
protected boolean isBluetoothAccessible() {
|
||||
return true;
|
||||
}
|
||||
|
||||
abstract void initialiseAdapter() throws IOException;
|
||||
|
||||
abstract boolean isAdapterEnabled();
|
||||
@@ -176,19 +187,28 @@ abstract class AbstractBluetoothPlugin<S, SS> implements BluetoothPlugin,
|
||||
DEFAULT_PREF_PLUGIN_ENABLE);
|
||||
everConnected.set(settings.getBoolean(PREF_EVER_CONNECTED,
|
||||
DEFAULT_PREF_EVER_CONNECTED));
|
||||
// disable plugin, if conditions for enabling are not met
|
||||
if (enabledByUser && !isBluetoothAccessible()) {
|
||||
enabledByUser = false;
|
||||
settings.putBoolean(PREF_PLUGIN_ENABLE, false);
|
||||
callback.mergeSettings(settings);
|
||||
}
|
||||
state.setStarted(enabledByUser);
|
||||
try {
|
||||
initialiseAdapter();
|
||||
} catch (IOException e) {
|
||||
throw new PluginException(e);
|
||||
}
|
||||
updateProperties();
|
||||
if (enabledByUser && isAdapterEnabled()) bind();
|
||||
if (enabledByUser) {
|
||||
updateProperties();
|
||||
if (isAdapterEnabled()) bind();
|
||||
}
|
||||
}
|
||||
|
||||
private void bind() {
|
||||
ioExecutor.execute(() -> {
|
||||
if (getState() != INACTIVE) return;
|
||||
if (contactConnectionsUuid == null) updateProperties();
|
||||
// Bind a server socket to accept connections from contacts
|
||||
SS ss;
|
||||
try {
|
||||
@@ -534,7 +554,8 @@ abstract class AbstractBluetoothPlugin<S, SS> implements BluetoothPlugin,
|
||||
private void onSettingsUpdated(Settings settings) {
|
||||
boolean enabledByUser = settings.getBoolean(PREF_PLUGIN_ENABLE,
|
||||
DEFAULT_PREF_PLUGIN_ENABLE);
|
||||
SS ss = state.setEnabledByUser(enabledByUser);
|
||||
boolean shouldEnable = enabledByUser && isBluetoothAccessible();
|
||||
SS ss = state.setEnabledByUser(shouldEnable);
|
||||
State s = getState();
|
||||
if (ss != null) {
|
||||
LOG.info("Disabled by user, closing server socket");
|
||||
|
||||
Reference in New Issue
Block a user