mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-13 03:09:04 +01:00
[bramble] Add method for enabling/disabling plugins to PluginManager
This commit is contained in:
@@ -8,11 +8,9 @@ import android.content.IntentFilter;
|
||||
import android.os.Bundle;
|
||||
import android.view.MenuItem;
|
||||
|
||||
import org.briarproject.bramble.api.db.DbException;
|
||||
import org.briarproject.bramble.api.event.Event;
|
||||
import org.briarproject.bramble.api.event.EventBus;
|
||||
import org.briarproject.bramble.api.event.EventListener;
|
||||
import org.briarproject.bramble.api.lifecycle.IoExecutor;
|
||||
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
|
||||
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
||||
import org.briarproject.bramble.api.plugin.BluetoothConstants;
|
||||
@@ -20,11 +18,8 @@ import org.briarproject.bramble.api.plugin.LanTcpConstants;
|
||||
import org.briarproject.bramble.api.plugin.Plugin;
|
||||
import org.briarproject.bramble.api.plugin.Plugin.State;
|
||||
import org.briarproject.bramble.api.plugin.PluginManager;
|
||||
import org.briarproject.bramble.api.plugin.TransportId;
|
||||
import org.briarproject.bramble.api.plugin.event.BluetoothEnabledEvent;
|
||||
import org.briarproject.bramble.api.plugin.event.TransportStateEvent;
|
||||
import org.briarproject.bramble.api.settings.Settings;
|
||||
import org.briarproject.bramble.api.settings.SettingsManager;
|
||||
import org.briarproject.briar.R;
|
||||
import org.briarproject.briar.android.activity.ActivityComponent;
|
||||
import org.briarproject.briar.android.activity.BriarActivity;
|
||||
@@ -34,7 +29,6 @@ import org.briarproject.briar.android.keyagreement.IntroFragment.IntroScreenSeen
|
||||
import org.briarproject.briar.android.keyagreement.KeyAgreementFragment.KeyAgreementEventListener;
|
||||
import org.briarproject.briar.android.util.UiUtils;
|
||||
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
@@ -54,15 +48,11 @@ import static android.bluetooth.BluetoothAdapter.ACTION_SCAN_MODE_CHANGED;
|
||||
import static android.bluetooth.BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE;
|
||||
import static android.content.pm.PackageManager.PERMISSION_GRANTED;
|
||||
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.nullsafety.NullSafety.requireNonNull;
|
||||
import static org.briarproject.bramble.api.plugin.BluetoothConstants.PREF_BT_ENABLE;
|
||||
import static org.briarproject.bramble.api.plugin.Plugin.State.ACTIVE;
|
||||
import static org.briarproject.bramble.api.plugin.Plugin.State.DISABLED;
|
||||
import static org.briarproject.bramble.api.plugin.Plugin.State.INACTIVE;
|
||||
import static org.briarproject.bramble.api.plugin.TcpConstants.PREF_TCP_ENABLE;
|
||||
import static org.briarproject.bramble.util.LogUtils.logException;
|
||||
import static org.briarproject.briar.android.activity.RequestCodes.REQUEST_BLUETOOTH_DISCOVERABLE;
|
||||
import static org.briarproject.briar.android.activity.RequestCodes.REQUEST_PERMISSION_CAMERA_LOCATION;
|
||||
|
||||
@@ -112,13 +102,6 @@ public abstract class KeyAgreementActivity extends BriarActivity implements
|
||||
@Inject
|
||||
PluginManager pluginManager;
|
||||
|
||||
@Inject
|
||||
@IoExecutor
|
||||
Executor ioExecutor;
|
||||
|
||||
@Inject
|
||||
SettingsManager settingsManager;
|
||||
|
||||
/**
|
||||
* Set to true in onPostResume() and false in onPause(). This prevents the
|
||||
* QR code fragment from being shown if onRequestPermissionsResult() is
|
||||
@@ -220,14 +203,14 @@ public abstract class KeyAgreementActivity extends BriarActivity implements
|
||||
if (shouldEnableWifi()) {
|
||||
LOG.info("Enabling wifi plugin");
|
||||
hasEnabledWifi = true;
|
||||
enablePlugin(LanTcpConstants.ID, PREF_TCP_ENABLE);
|
||||
pluginManager.setPluginEnabled(LanTcpConstants.ID, true);
|
||||
}
|
||||
if (bluetoothDecision == BluetoothDecision.UNKNOWN) {
|
||||
requestBluetoothDiscoverable();
|
||||
} else if (shouldEnableBluetooth()) {
|
||||
LOG.info("Enabling Bluetooth plugin");
|
||||
hasEnabledBluetooth = true;
|
||||
enablePlugin(BluetoothConstants.ID, PREF_BT_ENABLE);
|
||||
pluginManager.setPluginEnabled(BluetoothConstants.ID, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -278,18 +261,6 @@ public abstract class KeyAgreementActivity extends BriarActivity implements
|
||||
return p != null && p.getState() == DISABLED;
|
||||
}
|
||||
|
||||
private void enablePlugin(TransportId t, String settingKey) {
|
||||
ioExecutor.execute(() -> {
|
||||
try {
|
||||
Settings s = new Settings();
|
||||
s.putBoolean(settingKey, true);
|
||||
settingsManager.mergeSettings(s, t.getString());
|
||||
} catch (DbException e) {
|
||||
logException(LOG, WARNING, e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void requestBluetoothDiscoverable() {
|
||||
BluetoothAdapter bt = BluetoothAdapter.getDefaultAdapter();
|
||||
if (bt == null) {
|
||||
|
||||
@@ -73,9 +73,7 @@ import static android.widget.Toast.LENGTH_SHORT;
|
||||
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.BluetoothConstants.PREF_BT_ENABLE;
|
||||
import static org.briarproject.bramble.api.plugin.TcpConstants.PREF_TCP_ENABLE;
|
||||
import static org.briarproject.bramble.api.plugin.TorConstants.PREF_TOR_ENABLE;
|
||||
import static org.briarproject.bramble.api.plugin.Plugin.PREF_PLUGIN_ENABLE;
|
||||
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;
|
||||
@@ -379,15 +377,15 @@ public class SettingsFragment extends PreferenceFragmentCompat
|
||||
if (!settingsLoaded) return;
|
||||
|
||||
boolean btEnabledSetting =
|
||||
btSettings.getBoolean(PREF_BT_ENABLE, false);
|
||||
btSettings.getBoolean(PREF_PLUGIN_ENABLE, false);
|
||||
enableBluetooth.setChecked(btEnabledSetting);
|
||||
|
||||
boolean wifiEnabledSetting =
|
||||
wifiSettings.getBoolean(PREF_TCP_ENABLE, false);
|
||||
wifiSettings.getBoolean(PREF_PLUGIN_ENABLE, false);
|
||||
enableWifi.setChecked(wifiEnabledSetting);
|
||||
|
||||
boolean torEnabledSetting =
|
||||
torSettings.getBoolean(PREF_TOR_ENABLE, true);
|
||||
torSettings.getBoolean(PREF_PLUGIN_ENABLE, true);
|
||||
enableTor.setChecked(torEnabledSetting);
|
||||
|
||||
int torNetworkSetting = torSettings.getInt(PREF_TOR_NETWORK,
|
||||
@@ -639,7 +637,7 @@ public class SettingsFragment extends PreferenceFragmentCompat
|
||||
|
||||
private void storeTorEnabledSetting(boolean torEnabledSetting) {
|
||||
Settings s = new Settings();
|
||||
s.putBoolean(PREF_TOR_ENABLE, torEnabledSetting);
|
||||
s.putBoolean(PREF_PLUGIN_ENABLE, torEnabledSetting);
|
||||
mergeSettings(s, TOR_NAMESPACE);
|
||||
}
|
||||
|
||||
@@ -663,13 +661,13 @@ public class SettingsFragment extends PreferenceFragmentCompat
|
||||
|
||||
private void storeBluetoothSetting(boolean btSetting) {
|
||||
Settings s = new Settings();
|
||||
s.putBoolean(PREF_BT_ENABLE, btSetting);
|
||||
s.putBoolean(PREF_PLUGIN_ENABLE, btSetting);
|
||||
mergeSettings(s, BT_NAMESPACE);
|
||||
}
|
||||
|
||||
private void storeWifiSetting(boolean wifiSetting) {
|
||||
Settings s = new Settings();
|
||||
s.putBoolean(PREF_TCP_ENABLE, wifiSetting);
|
||||
s.putBoolean(PREF_PLUGIN_ENABLE, wifiSetting);
|
||||
mergeSettings(s, WIFI_NAMESPACE);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user