mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-12 10:49:06 +01:00
Merge branch 'setting-to-disable-tor' into 'master'
Add a setting to disable Tor See merge request !489
This commit is contained in:
@@ -67,6 +67,7 @@ import static java.util.logging.Level.INFO;
|
||||
import static java.util.logging.Level.WARNING;
|
||||
import static org.briarproject.bramble.api.keyagreement.KeyAgreementConstants.TRANSPORT_ID_BLUETOOTH;
|
||||
import static org.briarproject.bramble.api.plugin.BluetoothConstants.ID;
|
||||
import static org.briarproject.bramble.api.plugin.BluetoothConstants.PREF_BT_ENABLE;
|
||||
import static org.briarproject.bramble.api.plugin.BluetoothConstants.PROP_ADDRESS;
|
||||
import static org.briarproject.bramble.api.plugin.BluetoothConstants.PROP_UUID;
|
||||
import static org.briarproject.bramble.api.plugin.BluetoothConstants.UUID_BYTES;
|
||||
@@ -164,7 +165,7 @@ class DroidtoothPlugin implements DuplexPlugin {
|
||||
bind();
|
||||
} else {
|
||||
// Enable Bluetooth if settings allow
|
||||
if (callback.getSettings().getBoolean("enable", false)) {
|
||||
if (callback.getSettings().getBoolean(PREF_BT_ENABLE, false)) {
|
||||
wasEnabledByUs = true;
|
||||
if (adapter.enable()) LOG.info("Enabling Bluetooth");
|
||||
else LOG.info("Could not enable Bluetooth");
|
||||
|
||||
@@ -79,6 +79,12 @@ import static java.util.logging.Level.WARNING;
|
||||
import static net.freehaven.tor.control.TorControlCommands.HS_ADDRESS;
|
||||
import static net.freehaven.tor.control.TorControlCommands.HS_PRIVKEY;
|
||||
import static org.briarproject.bramble.api.plugin.TorConstants.CONTROL_PORT;
|
||||
import static org.briarproject.bramble.api.plugin.TorConstants.ID;
|
||||
import static org.briarproject.bramble.api.plugin.TorConstants.PREF_TOR_NETWORK;
|
||||
import static org.briarproject.bramble.api.plugin.TorConstants.PREF_TOR_NETWORK_ALWAYS;
|
||||
import static org.briarproject.bramble.api.plugin.TorConstants.PREF_TOR_NETWORK_NEVER;
|
||||
import static org.briarproject.bramble.api.plugin.TorConstants.PREF_TOR_NETWORK_WIFI;
|
||||
import static org.briarproject.bramble.api.plugin.TorConstants.PREF_TOR_PORT;
|
||||
import static org.briarproject.bramble.util.PrivacyUtils.scrubOnion;
|
||||
|
||||
@MethodsNotNullByDefault
|
||||
@@ -379,7 +385,7 @@ class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
|
||||
@Override
|
||||
public void run() {
|
||||
// If there's already a port number stored in config, reuse it
|
||||
String portString = callback.getSettings().get("port");
|
||||
String portString = callback.getSettings().get(PREF_TOR_PORT);
|
||||
int port;
|
||||
if (StringUtils.isNullOrEmpty(portString)) port = 0;
|
||||
else port = Integer.parseInt(portString);
|
||||
@@ -402,7 +408,7 @@ class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
|
||||
// Store the port number
|
||||
final String localPort = String.valueOf(ss.getLocalPort());
|
||||
Settings s = new Settings();
|
||||
s.put("port", localPort);
|
||||
s.put(PREF_TOR_PORT, localPort);
|
||||
callback.mergeSettings(s);
|
||||
// Create a hidden service if necessary
|
||||
ioExecutor.execute(new Runnable() {
|
||||
@@ -679,7 +685,8 @@ class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
|
||||
@Override
|
||||
public void eventOccurred(Event e) {
|
||||
if (e instanceof SettingsUpdatedEvent) {
|
||||
if (((SettingsUpdatedEvent) e).getNamespace().equals("tor")) {
|
||||
SettingsUpdatedEvent s = (SettingsUpdatedEvent) e;
|
||||
if (s.getNamespace().equals(ID.getString())) {
|
||||
LOG.info("Tor settings updated");
|
||||
updateConnectionStatus();
|
||||
}
|
||||
@@ -701,7 +708,8 @@ class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
|
||||
boolean blocked = TorNetworkMetadata.isTorProbablyBlocked(
|
||||
country);
|
||||
Settings s = callback.getSettings();
|
||||
boolean useMobileData = s.getBoolean("torOverMobile", true);
|
||||
int network = s.getInt(PREF_TOR_NETWORK,
|
||||
PREF_TOR_NETWORK_ALWAYS);
|
||||
|
||||
if (LOG.isLoggable(INFO)) {
|
||||
LOG.info("Online: " + online + ", wifi: " + wifi);
|
||||
@@ -716,7 +724,8 @@ class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
|
||||
} else if (blocked) {
|
||||
LOG.info("Disabling network, country is blocked");
|
||||
enableNetwork(false);
|
||||
} else if (!wifi && !useMobileData) {
|
||||
} else if (network == PREF_TOR_NETWORK_NEVER
|
||||
|| (network == PREF_TOR_NETWORK_WIFI && !wifi)) {
|
||||
LOG.info("Disabling network due to data setting");
|
||||
enableNetwork(false);
|
||||
} else {
|
||||
|
||||
@@ -9,4 +9,5 @@ public interface BluetoothConstants {
|
||||
String PROP_ADDRESS = "address";
|
||||
String PROP_UUID = "uuid";
|
||||
|
||||
String PREF_BT_ENABLE = "enable";
|
||||
}
|
||||
|
||||
@@ -4,4 +4,5 @@ public interface LanTcpConstants {
|
||||
|
||||
TransportId ID = new TransportId("org.briarproject.bramble.lan");
|
||||
|
||||
String PREF_LAN_IP_PORTS = "ipPorts";
|
||||
}
|
||||
|
||||
@@ -8,4 +8,11 @@ public interface TorConstants {
|
||||
int CONTROL_PORT = 59051;
|
||||
|
||||
int CONNECT_TO_PROXY_TIMEOUT = 5000; // Milliseconds
|
||||
|
||||
String PREF_TOR_NETWORK = "network";
|
||||
String PREF_TOR_PORT = "port";
|
||||
|
||||
int PREF_TOR_NETWORK_NEVER = 0;
|
||||
int PREF_TOR_NETWORK_WIFI = 1;
|
||||
int PREF_TOR_NETWORK_ALWAYS = 2;
|
||||
}
|
||||
|
||||
@@ -34,6 +34,7 @@ import static java.util.logging.Level.INFO;
|
||||
import static java.util.logging.Level.WARNING;
|
||||
import static org.briarproject.bramble.api.keyagreement.KeyAgreementConstants.TRANSPORT_ID_LAN;
|
||||
import static org.briarproject.bramble.api.plugin.LanTcpConstants.ID;
|
||||
import static org.briarproject.bramble.api.plugin.LanTcpConstants.PREF_LAN_IP_PORTS;
|
||||
import static org.briarproject.bramble.util.ByteUtils.MAX_16_BIT_UNSIGNED;
|
||||
import static org.briarproject.bramble.util.PrivacyUtils.scrubSocketAddress;
|
||||
|
||||
@@ -82,19 +83,19 @@ class LanTcpPlugin extends TcpPlugin {
|
||||
private List<InetSocketAddress> parseSocketAddresses(String ipPorts) {
|
||||
if (StringUtils.isNullOrEmpty(ipPorts)) return Collections.emptyList();
|
||||
String[] split = ipPorts.split(SEPARATOR);
|
||||
List<InetSocketAddress> remotes = new ArrayList<InetSocketAddress>();
|
||||
List<InetSocketAddress> addresses = new ArrayList<InetSocketAddress>();
|
||||
for (String ipPort : split) {
|
||||
InetSocketAddress a = parseSocketAddress(ipPort);
|
||||
if (a != null) remotes.add(a);
|
||||
if (a != null) addresses.add(a);
|
||||
}
|
||||
return remotes;
|
||||
return addresses;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setLocalSocketAddress(InetSocketAddress a) {
|
||||
String ipPort = getIpPortString(a);
|
||||
// Get the list of recently used addresses
|
||||
String setting = callback.getSettings().get(PROP_IP_PORTS);
|
||||
String setting = callback.getSettings().get(PREF_LAN_IP_PORTS);
|
||||
List<String> recent = new ArrayList<String>();
|
||||
if (!StringUtils.isNullOrEmpty(setting))
|
||||
Collections.addAll(recent, setting.split(SEPARATOR));
|
||||
@@ -120,7 +121,7 @@ class LanTcpPlugin extends TcpPlugin {
|
||||
}
|
||||
// Save the setting
|
||||
Settings settings = new Settings();
|
||||
settings.put(PROP_IP_PORTS, setting);
|
||||
settings.put(PREF_LAN_IP_PORTS, setting);
|
||||
callback.mergeSettings(settings);
|
||||
}
|
||||
|
||||
|
||||
@@ -73,8 +73,6 @@ import static org.briarproject.briar.android.navdrawer.NavDrawerActivity.INTENT_
|
||||
import static org.briarproject.briar.android.navdrawer.NavDrawerActivity.INTENT_CONTACTS;
|
||||
import static org.briarproject.briar.android.navdrawer.NavDrawerActivity.INTENT_FORUMS;
|
||||
import static org.briarproject.briar.android.navdrawer.NavDrawerActivity.INTENT_GROUPS;
|
||||
import static org.briarproject.briar.android.settings.SettingsFragment.PREF_NOTIFY_BLOG;
|
||||
import static org.briarproject.briar.android.settings.SettingsFragment.PREF_NOTIFY_GROUP;
|
||||
import static org.briarproject.briar.android.settings.SettingsFragment.SETTINGS_NAMESPACE;
|
||||
|
||||
@ThreadSafe
|
||||
@@ -92,13 +90,13 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager,
|
||||
|
||||
// Content URIs to differentiate between pending intents
|
||||
private static final String CONTACT_URI =
|
||||
"content://org.briarproject/contact";
|
||||
"content://org.briarproject.briar/contact";
|
||||
private static final String GROUP_URI =
|
||||
"content://org.briarproject/group";
|
||||
"content://org.briarproject.briar/group";
|
||||
private static final String FORUM_URI =
|
||||
"content://org.briarproject/forum";
|
||||
"content://org.briarproject.briar/forum";
|
||||
private static final String BLOG_URI =
|
||||
"content://org.briarproject/blog";
|
||||
"content://org.briarproject.briar/blog";
|
||||
|
||||
// Actions for intents that are broadcast when notifications are dismissed
|
||||
private static final String CLEAR_PRIVATE_MESSAGE_ACTION =
|
||||
@@ -325,17 +323,18 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager,
|
||||
private void updateContactNotification() {
|
||||
if (contactTotal == 0) {
|
||||
clearContactNotification();
|
||||
} else if (settings.getBoolean("notifyPrivateMessages", true)) {
|
||||
} else if (settings.getBoolean(PREF_NOTIFY_PRIVATE, true)) {
|
||||
NotificationCompat.Builder b =
|
||||
new NotificationCompat.Builder(appContext);
|
||||
b.setSmallIcon(R.drawable.notification_private_message);
|
||||
b.setColor(ContextCompat.getColor(appContext, R.color.briar_primary));
|
||||
b.setColor(ContextCompat.getColor(appContext,
|
||||
R.color.briar_primary));
|
||||
b.setContentTitle(appContext.getText(R.string.app_name));
|
||||
b.setContentText(appContext.getResources().getQuantityString(
|
||||
R.plurals.private_message_notification_text, contactTotal,
|
||||
contactTotal));
|
||||
boolean sound = settings.getBoolean("notifySound", true);
|
||||
String ringtoneUri = settings.get("notifyRingtoneUri");
|
||||
boolean sound = settings.getBoolean(PREF_NOTIFY_SOUND, true);
|
||||
String ringtoneUri = settings.get(PREF_NOTIFY_RINGTONE_URI);
|
||||
if (sound && !StringUtils.isNullOrEmpty(ringtoneUri))
|
||||
b.setSound(Uri.parse(ringtoneUri));
|
||||
b.setDefaults(getDefaults());
|
||||
@@ -381,11 +380,11 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager,
|
||||
@UiThread
|
||||
private int getDefaults() {
|
||||
int defaults = DEFAULT_LIGHTS;
|
||||
boolean sound = settings.getBoolean("notifySound", true);
|
||||
String ringtoneUri = settings.get("notifyRingtoneUri");
|
||||
boolean sound = settings.getBoolean(PREF_NOTIFY_SOUND, true);
|
||||
String ringtoneUri = settings.get(PREF_NOTIFY_RINGTONE_URI);
|
||||
if (sound && StringUtils.isNullOrEmpty(ringtoneUri))
|
||||
defaults |= DEFAULT_SOUND;
|
||||
if (settings.getBoolean("notifyVibration", true))
|
||||
if (settings.getBoolean(PREF_NOTIFY_VIBRATION, true))
|
||||
defaults |= DEFAULT_VIBRATE;
|
||||
return defaults;
|
||||
}
|
||||
@@ -438,12 +437,13 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager,
|
||||
NotificationCompat.Builder b =
|
||||
new NotificationCompat.Builder(appContext);
|
||||
b.setSmallIcon(R.drawable.notification_private_group);
|
||||
b.setColor(ContextCompat.getColor(appContext, R.color.briar_primary));
|
||||
b.setColor(ContextCompat.getColor(appContext,
|
||||
R.color.briar_primary));
|
||||
b.setContentTitle(appContext.getText(R.string.app_name));
|
||||
b.setContentText(appContext.getResources().getQuantityString(
|
||||
R.plurals.group_message_notification_text, groupTotal,
|
||||
groupTotal));
|
||||
String ringtoneUri = settings.get("notifyRingtoneUri");
|
||||
String ringtoneUri = settings.get(PREF_NOTIFY_RINGTONE_URI);
|
||||
if (!StringUtils.isNullOrEmpty(ringtoneUri))
|
||||
b.setSound(Uri.parse(ringtoneUri));
|
||||
b.setDefaults(getDefaults());
|
||||
@@ -530,16 +530,17 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager,
|
||||
private void updateForumPostNotification() {
|
||||
if (forumTotal == 0) {
|
||||
clearForumPostNotification();
|
||||
} else if (settings.getBoolean("notifyForumPosts", true)) {
|
||||
} else if (settings.getBoolean(PREF_NOTIFY_FORUM, true)) {
|
||||
NotificationCompat.Builder b =
|
||||
new NotificationCompat.Builder(appContext);
|
||||
b.setSmallIcon(R.drawable.notification_forum);
|
||||
b.setColor(ContextCompat.getColor(appContext, R.color.briar_primary));
|
||||
b.setColor(ContextCompat.getColor(appContext,
|
||||
R.color.briar_primary));
|
||||
b.setContentTitle(appContext.getText(R.string.app_name));
|
||||
b.setContentText(appContext.getResources().getQuantityString(
|
||||
R.plurals.forum_post_notification_text, forumTotal,
|
||||
forumTotal));
|
||||
String ringtoneUri = settings.get("notifyRingtoneUri");
|
||||
String ringtoneUri = settings.get(PREF_NOTIFY_RINGTONE_URI);
|
||||
if (!StringUtils.isNullOrEmpty(ringtoneUri))
|
||||
b.setSound(Uri.parse(ringtoneUri));
|
||||
b.setDefaults(getDefaults());
|
||||
@@ -630,12 +631,13 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager,
|
||||
NotificationCompat.Builder b =
|
||||
new NotificationCompat.Builder(appContext);
|
||||
b.setSmallIcon(R.drawable.notification_blog);
|
||||
b.setColor(ContextCompat.getColor(appContext, R.color.briar_primary));
|
||||
b.setColor(ContextCompat.getColor(appContext,
|
||||
R.color.briar_primary));
|
||||
b.setContentTitle(appContext.getText(R.string.app_name));
|
||||
b.setContentText(appContext.getResources().getQuantityString(
|
||||
R.plurals.blog_post_notification_text, blogTotal,
|
||||
blogTotal));
|
||||
String ringtoneUri = settings.get("notifyRingtoneUri");
|
||||
String ringtoneUri = settings.get(PREF_NOTIFY_RINGTONE_URI);
|
||||
if (!StringUtils.isNullOrEmpty(ringtoneUri))
|
||||
b.setSound(Uri.parse(ringtoneUri));
|
||||
b.setDefaults(getDefaults());
|
||||
@@ -696,7 +698,7 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager,
|
||||
b.setContentText(appContext.getResources().getQuantityString(
|
||||
R.plurals.introduction_notification_text, introductionTotal,
|
||||
introductionTotal));
|
||||
String ringtoneUri = settings.get("notifyRingtoneUri");
|
||||
String ringtoneUri = settings.get(PREF_NOTIFY_RINGTONE_URI);
|
||||
if (!StringUtils.isNullOrEmpty(ringtoneUri))
|
||||
b.setSound(Uri.parse(ringtoneUri));
|
||||
b.setDefaults(getDefaults());
|
||||
|
||||
@@ -22,6 +22,8 @@ import org.briarproject.bramble.api.event.EventBus;
|
||||
import org.briarproject.bramble.api.event.EventListener;
|
||||
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
|
||||
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
||||
import org.briarproject.bramble.api.plugin.BluetoothConstants;
|
||||
import org.briarproject.bramble.api.plugin.TorConstants;
|
||||
import org.briarproject.bramble.api.settings.Settings;
|
||||
import org.briarproject.bramble.api.settings.SettingsManager;
|
||||
import org.briarproject.bramble.api.settings.event.SettingsUpdatedEvent;
|
||||
@@ -45,7 +47,18 @@ import static android.media.RingtoneManager.TYPE_NOTIFICATION;
|
||||
import static android.provider.Settings.System.DEFAULT_NOTIFICATION_URI;
|
||||
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.TorConstants.PREF_TOR_NETWORK;
|
||||
import static org.briarproject.bramble.api.plugin.TorConstants.PREF_TOR_NETWORK_ALWAYS;
|
||||
import static org.briarproject.briar.android.activity.RequestCodes.REQUEST_RINGTONE;
|
||||
import static org.briarproject.briar.api.android.AndroidNotificationManager.PREF_NOTIFY_BLOG;
|
||||
import static org.briarproject.briar.api.android.AndroidNotificationManager.PREF_NOTIFY_FORUM;
|
||||
import static org.briarproject.briar.api.android.AndroidNotificationManager.PREF_NOTIFY_GROUP;
|
||||
import static org.briarproject.briar.api.android.AndroidNotificationManager.PREF_NOTIFY_PRIVATE;
|
||||
import static org.briarproject.briar.api.android.AndroidNotificationManager.PREF_NOTIFY_RINGTONE_NAME;
|
||||
import static org.briarproject.briar.api.android.AndroidNotificationManager.PREF_NOTIFY_RINGTONE_URI;
|
||||
import static org.briarproject.briar.api.android.AndroidNotificationManager.PREF_NOTIFY_SOUND;
|
||||
import static org.briarproject.briar.api.android.AndroidNotificationManager.PREF_NOTIFY_VIBRATION;
|
||||
|
||||
@MethodsNotNullByDefault
|
||||
@ParametersNotNullByDefault
|
||||
@@ -53,8 +66,8 @@ public class SettingsFragment extends PreferenceFragmentCompat
|
||||
implements EventListener, Preference.OnPreferenceChangeListener {
|
||||
|
||||
public static final String SETTINGS_NAMESPACE = "android-ui";
|
||||
public static final String PREF_NOTIFY_GROUP = "notifyGroupMessages";
|
||||
public static final String PREF_NOTIFY_BLOG = "notifyBlogPosts";
|
||||
public static final String BT_NAMESPACE = BluetoothConstants.ID.getString();
|
||||
public static final String TOR_NAMESPACE = TorConstants.ID.getString();
|
||||
|
||||
private static final Logger LOG =
|
||||
Logger.getLogger(SettingsFragment.class.getName());
|
||||
@@ -62,7 +75,7 @@ public class SettingsFragment extends PreferenceFragmentCompat
|
||||
private SettingsActivity listener;
|
||||
private AndroidExecutor androidExecutor;
|
||||
private ListPreference enableBluetooth;
|
||||
private ListPreference torOverMobile;
|
||||
private ListPreference torNetwork;
|
||||
private CheckBoxPreference notifyPrivateMessages;
|
||||
private CheckBoxPreference notifyGroupMessages;
|
||||
private CheckBoxPreference notifyForumPosts;
|
||||
@@ -74,7 +87,6 @@ public class SettingsFragment extends PreferenceFragmentCompat
|
||||
private volatile SettingsManager settingsManager;
|
||||
private volatile EventBus eventBus;
|
||||
private volatile Settings settings;
|
||||
private volatile boolean bluetoothSetting = false, torSetting = false;
|
||||
|
||||
@Override
|
||||
public void onAttach(Context context) {
|
||||
@@ -90,10 +102,8 @@ public class SettingsFragment extends PreferenceFragmentCompat
|
||||
public void onCreatePreferences(Bundle bundle, String s) {
|
||||
addPreferencesFromResource(R.xml.settings);
|
||||
|
||||
enableBluetooth =
|
||||
(ListPreference) findPreference("pref_key_bluetooth");
|
||||
torOverMobile =
|
||||
(ListPreference) findPreference("pref_key_tor_mobile");
|
||||
enableBluetooth = (ListPreference) findPreference("pref_key_bluetooth");
|
||||
torNetwork = (ListPreference) findPreference("pref_key_tor_network");
|
||||
notifyPrivateMessages = (CheckBoxPreference) findPreference(
|
||||
"pref_key_notify_private_messages");
|
||||
notifyGroupMessages = (CheckBoxPreference) findPreference(
|
||||
@@ -107,7 +117,7 @@ public class SettingsFragment extends PreferenceFragmentCompat
|
||||
notifySound = findPreference("pref_key_notify_sound");
|
||||
|
||||
enableBluetooth.setOnPreferenceChangeListener(this);
|
||||
torOverMobile.setOnPreferenceChangeListener(this);
|
||||
torNetwork.setOnPreferenceChangeListener(this);
|
||||
notifyPrivateMessages.setOnPreferenceChangeListener(this);
|
||||
notifyGroupMessages.setOnPreferenceChangeListener(this);
|
||||
notifyForumPosts.setOnPreferenceChangeListener(this);
|
||||
@@ -126,10 +136,10 @@ public class SettingsFragment extends PreferenceFragmentCompat
|
||||
i.putExtra(EXTRA_RINGTONE_DEFAULT_URI,
|
||||
DEFAULT_NOTIFICATION_URI);
|
||||
i.putExtra(EXTRA_RINGTONE_SHOW_SILENT, true);
|
||||
if (settings.getBoolean("notifySound", true)) {
|
||||
if (settings.getBoolean(PREF_NOTIFY_SOUND, true)) {
|
||||
Uri uri;
|
||||
String ringtoneUri =
|
||||
settings.get("notifyRingtoneUri");
|
||||
settings.get(PREF_NOTIFY_RINGTONE_URI);
|
||||
if (StringUtils.isNullOrEmpty(ringtoneUri))
|
||||
uri = DEFAULT_NOTIFICATION_URI;
|
||||
else uri = Uri.parse(ringtoneUri);
|
||||
@@ -181,14 +191,18 @@ public class SettingsFragment extends PreferenceFragmentCompat
|
||||
try {
|
||||
long now = System.currentTimeMillis();
|
||||
settings = settingsManager.getSettings(SETTINGS_NAMESPACE);
|
||||
Settings btSettings = settingsManager.getSettings("bt");
|
||||
Settings torSettings = settingsManager.getSettings("tor");
|
||||
Settings btSettings =
|
||||
settingsManager.getSettings(BT_NAMESPACE);
|
||||
Settings torSettings =
|
||||
settingsManager.getSettings(TOR_NAMESPACE);
|
||||
long duration = System.currentTimeMillis() - now;
|
||||
if (LOG.isLoggable(INFO))
|
||||
LOG.info("Loading settings took " + duration + " ms");
|
||||
bluetoothSetting = btSettings.getBoolean("enable", false);
|
||||
torSetting = torSettings.getBoolean("torOverMobile", true);
|
||||
displaySettings();
|
||||
boolean btSetting =
|
||||
btSettings.getBoolean(PREF_BT_ENABLE, false);
|
||||
int torSetting = torSettings.getInt(PREF_TOR_NETWORK,
|
||||
PREF_TOR_NETWORK_ALWAYS);
|
||||
displaySettings(btSetting, torSetting);
|
||||
} catch (DbException e) {
|
||||
if (LOG.isLoggable(WARNING))
|
||||
LOG.log(WARNING, e.toString(), e);
|
||||
@@ -197,31 +211,33 @@ public class SettingsFragment extends PreferenceFragmentCompat
|
||||
});
|
||||
}
|
||||
|
||||
private void displaySettings() {
|
||||
private void displaySettings(final boolean btSetting,
|
||||
final int torSetting) {
|
||||
listener.runOnUiThreadUnlessDestroyed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
enableBluetooth.setValue(Boolean.toString(bluetoothSetting));
|
||||
torOverMobile.setValue(Boolean.toString(torSetting));
|
||||
enableBluetooth.setValue(Boolean.toString(btSetting));
|
||||
torNetwork.setValue(Integer.toString(torSetting));
|
||||
|
||||
notifyPrivateMessages.setChecked(settings.getBoolean(
|
||||
"notifyPrivateMessages", true));
|
||||
PREF_NOTIFY_PRIVATE, true));
|
||||
|
||||
notifyGroupMessages.setChecked(settings.getBoolean(
|
||||
PREF_NOTIFY_GROUP, true));
|
||||
|
||||
notifyForumPosts.setChecked(settings.getBoolean(
|
||||
"notifyForumPosts", true));
|
||||
PREF_NOTIFY_FORUM, true));
|
||||
|
||||
notifyBlogPosts.setChecked(settings.getBoolean(
|
||||
PREF_NOTIFY_BLOG, true));
|
||||
|
||||
notifyVibration.setChecked(settings.getBoolean(
|
||||
"notifyVibration", true));
|
||||
PREF_NOTIFY_VIBRATION, true));
|
||||
|
||||
String text;
|
||||
if (settings.getBoolean("notifySound", true)) {
|
||||
String ringtoneName = settings.get("notifyRingtoneName");
|
||||
if (settings.getBoolean(PREF_NOTIFY_SOUND, true)) {
|
||||
String ringtoneName =
|
||||
settings.get(PREF_NOTIFY_RINGTONE_NAME);
|
||||
if (StringUtils.isNullOrEmpty(ringtoneName)) {
|
||||
text = getString(R.string.notify_sound_setting_default);
|
||||
} else {
|
||||
@@ -248,15 +264,15 @@ public class SettingsFragment extends PreferenceFragmentCompat
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object o) {
|
||||
if (preference == enableBluetooth) {
|
||||
bluetoothSetting = Boolean.valueOf((String) o);
|
||||
enableOrDisableBluetooth(bluetoothSetting);
|
||||
storeBluetoothSettings();
|
||||
} else if (preference == torOverMobile) {
|
||||
torSetting = Boolean.valueOf((String) o);
|
||||
storeTorSettings();
|
||||
boolean btSetting = Boolean.valueOf((String) o);
|
||||
enableOrDisableBluetooth(btSetting);
|
||||
storeBluetoothSettings(btSetting);
|
||||
} else if (preference == torNetwork) {
|
||||
int torSetting = Integer.valueOf((String) o);
|
||||
storeTorSettings(torSetting);
|
||||
} else if (preference == notifyPrivateMessages) {
|
||||
Settings s = new Settings();
|
||||
s.putBoolean("notifyPrivateMessages", (Boolean) o);
|
||||
s.putBoolean(PREF_NOTIFY_PRIVATE, (Boolean) o);
|
||||
storeSettings(s);
|
||||
} else if (preference == notifyGroupMessages) {
|
||||
Settings s = new Settings();
|
||||
@@ -264,7 +280,7 @@ public class SettingsFragment extends PreferenceFragmentCompat
|
||||
storeSettings(s);
|
||||
} else if (preference == notifyForumPosts) {
|
||||
Settings s = new Settings();
|
||||
s.putBoolean("notifyForumPosts", (Boolean) o);
|
||||
s.putBoolean(PREF_NOTIFY_FORUM, (Boolean) o);
|
||||
storeSettings(s);
|
||||
} else if (preference == notifyBlogPosts) {
|
||||
Settings s = new Settings();
|
||||
@@ -272,7 +288,7 @@ public class SettingsFragment extends PreferenceFragmentCompat
|
||||
storeSettings(s);
|
||||
} else if (preference == notifyVibration) {
|
||||
Settings s = new Settings();
|
||||
s.putBoolean("notifyVibration", (Boolean) o);
|
||||
s.putBoolean(PREF_NOTIFY_VIBRATION, (Boolean) o);
|
||||
storeSettings(s);
|
||||
}
|
||||
return true;
|
||||
@@ -291,15 +307,15 @@ public class SettingsFragment extends PreferenceFragmentCompat
|
||||
}
|
||||
}
|
||||
|
||||
private void storeTorSettings() {
|
||||
private void storeTorSettings(final int torSetting) {
|
||||
listener.runOnDbThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
Settings s = new Settings();
|
||||
s.putBoolean("torOverMobile", torSetting);
|
||||
s.putInt(PREF_TOR_NETWORK, torSetting);
|
||||
long now = System.currentTimeMillis();
|
||||
settingsManager.mergeSettings(s, "tor");
|
||||
settingsManager.mergeSettings(s, TOR_NAMESPACE);
|
||||
long duration = System.currentTimeMillis() - now;
|
||||
if (LOG.isLoggable(INFO))
|
||||
LOG.info("Merging settings took " + duration + " ms");
|
||||
@@ -311,15 +327,15 @@ public class SettingsFragment extends PreferenceFragmentCompat
|
||||
});
|
||||
}
|
||||
|
||||
private void storeBluetoothSettings() {
|
||||
private void storeBluetoothSettings(final boolean btSetting) {
|
||||
listener.runOnDbThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
Settings s = new Settings();
|
||||
s.putBoolean("enable", bluetoothSetting);
|
||||
s.putBoolean(PREF_BT_ENABLE, btSetting);
|
||||
long now = System.currentTimeMillis();
|
||||
settingsManager.mergeSettings(s, "bt");
|
||||
settingsManager.mergeSettings(s, BT_NAMESPACE);
|
||||
long duration = System.currentTimeMillis() - now;
|
||||
if (LOG.isLoggable(INFO))
|
||||
LOG.info("Merging settings took " + duration + " ms");
|
||||
@@ -357,21 +373,21 @@ public class SettingsFragment extends PreferenceFragmentCompat
|
||||
Uri uri = data.getParcelableExtra(EXTRA_RINGTONE_PICKED_URI);
|
||||
if (uri == null) {
|
||||
// The user chose silence
|
||||
s.putBoolean("notifySound", false);
|
||||
s.put("notifyRingtoneName", "");
|
||||
s.put("notifyRingtoneUri", "");
|
||||
s.putBoolean(PREF_NOTIFY_SOUND, false);
|
||||
s.put(PREF_NOTIFY_RINGTONE_NAME, "");
|
||||
s.put(PREF_NOTIFY_RINGTONE_URI, "");
|
||||
} else if (RingtoneManager.isDefault(uri)) {
|
||||
// The user chose the default
|
||||
s.putBoolean("notifySound", true);
|
||||
s.put("notifyRingtoneName", "");
|
||||
s.put("notifyRingtoneUri", "");
|
||||
s.putBoolean(PREF_NOTIFY_SOUND, true);
|
||||
s.put(PREF_NOTIFY_RINGTONE_NAME, "");
|
||||
s.put(PREF_NOTIFY_RINGTONE_URI, "");
|
||||
} else {
|
||||
// The user chose a ringtone other than the default
|
||||
Ringtone r = RingtoneManager.getRingtone(getContext(), uri);
|
||||
String name = r.getTitle(getContext());
|
||||
s.putBoolean("notifySound", true);
|
||||
s.put("notifyRingtoneName", name);
|
||||
s.put("notifyRingtoneUri", uri.toString());
|
||||
s.putBoolean(PREF_NOTIFY_SOUND, true);
|
||||
s.put(PREF_NOTIFY_RINGTONE_NAME, name);
|
||||
s.put(PREF_NOTIFY_RINGTONE_URI, uri.toString());
|
||||
}
|
||||
storeSettings(s);
|
||||
}
|
||||
@@ -381,7 +397,8 @@ public class SettingsFragment extends PreferenceFragmentCompat
|
||||
public void eventOccurred(Event e) {
|
||||
if (e instanceof SettingsUpdatedEvent) {
|
||||
String namespace = ((SettingsUpdatedEvent) e).getNamespace();
|
||||
if (namespace.equals("bt") || namespace.equals("tor")
|
||||
if (namespace.equals(BT_NAMESPACE)
|
||||
|| namespace.equals(TOR_NAMESPACE)
|
||||
|| namespace.equals(SETTINGS_NAMESPACE)) {
|
||||
LOG.info("Settings updated");
|
||||
loadSettings();
|
||||
|
||||
@@ -9,6 +9,16 @@ import org.briarproject.bramble.api.sync.GroupId;
|
||||
*/
|
||||
public interface AndroidNotificationManager {
|
||||
|
||||
String PREF_NOTIFY_PRIVATE = "notifyPrivateMessages";
|
||||
String PREF_NOTIFY_GROUP = "notifyGroupMessages";
|
||||
String PREF_NOTIFY_FORUM = "notifyForumPosts";
|
||||
String PREF_NOTIFY_BLOG = "notifyBlogPosts";
|
||||
|
||||
String PREF_NOTIFY_SOUND = "notifySound";
|
||||
String PREF_NOTIFY_RINGTONE_NAME = "notifyRingtoneName";
|
||||
String PREF_NOTIFY_RINGTONE_URI = "notifyRingtoneUri";
|
||||
String PREF_NOTIFY_VIBRATION = "notifyVibration";
|
||||
|
||||
void clearContactNotification(ContactId c);
|
||||
|
||||
void clearAllContactNotifications();
|
||||
|
||||
@@ -8,8 +8,14 @@
|
||||
<item>@string/bluetooth_setting_enabled</item>
|
||||
<item>@string/bluetooth_setting_disabled</item>
|
||||
</string-array>
|
||||
<string-array name="tor_mobile_setting_names">
|
||||
<item>@string/tor_mobile_setting_enabled</item>
|
||||
<item>@string/tor_mobile_setting_disabled</item>
|
||||
<string-array name="tor_network_setting_names">
|
||||
<item>@string/tor_network_setting_never</item>
|
||||
<item>@string/tor_network_setting_wifi</item>
|
||||
<item>@string/tor_network_setting_always</item>
|
||||
</string-array>
|
||||
<string-array name="tor_network_setting_values">
|
||||
<item>0</item>
|
||||
<item>1</item>
|
||||
<item>2</item>
|
||||
</string-array>
|
||||
</resources>
|
||||
@@ -310,9 +310,10 @@
|
||||
<string name="bluetooth_setting">Connect via Bluetooth</string>
|
||||
<string name="bluetooth_setting_enabled">Whenever contacts are nearby</string>
|
||||
<string name="bluetooth_setting_disabled">Only when adding contacts</string>
|
||||
<string name="tor_mobile_setting">Connect via Tor</string>
|
||||
<string name="tor_mobile_setting_enabled">When using Wi-Fi or mobile data</string>
|
||||
<string name="tor_mobile_setting_disabled">Only when using Wi-Fi</string>
|
||||
<string name="tor_network_setting">Connect via Tor</string>
|
||||
<string name="tor_network_setting_never">Never</string>
|
||||
<string name="tor_network_setting_wifi">Only when using Wi-Fi</string>
|
||||
<string name="tor_network_setting_always">When using Wi-Fi or mobile data</string>
|
||||
|
||||
<!-- Settings Security and Panic -->
|
||||
<string name="security_settings_title">Security</string>
|
||||
|
||||
@@ -15,13 +15,13 @@
|
||||
android:title="@string/bluetooth_setting"/>
|
||||
|
||||
<ListPreference
|
||||
android:defaultValue="true"
|
||||
android:entries="@array/tor_mobile_setting_names"
|
||||
android:entryValues="@array/boolean_array"
|
||||
android:key="pref_key_tor_mobile"
|
||||
android:defaultValue="2"
|
||||
android:entries="@array/tor_network_setting_names"
|
||||
android:entryValues="@array/tor_network_setting_values"
|
||||
android:key="pref_key_tor_network"
|
||||
android:persistent="false"
|
||||
android:summary="%s"
|
||||
android:title="@string/tor_mobile_setting"/>
|
||||
android:title="@string/tor_network_setting"/>
|
||||
|
||||
</PreferenceCategory>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user