mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-12 10:49:06 +01:00
Compare commits
5 Commits
beta-1.2.9
...
1712-passi
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f663bf8667 | ||
|
|
ef5b91da89 | ||
|
|
9909d205c7 | ||
|
|
9768b048d2 | ||
|
|
6dcad6c425 |
@@ -11,8 +11,8 @@ android {
|
||||
defaultConfig {
|
||||
minSdkVersion 16
|
||||
targetSdkVersion 28
|
||||
versionCode 10209
|
||||
versionName "1.2.9"
|
||||
versionCode 10207
|
||||
versionName "1.2.7"
|
||||
consumerProguardFiles 'proguard-rules.txt'
|
||||
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
|
||||
@@ -31,7 +31,6 @@ import java.util.concurrent.BlockingQueue;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
@@ -67,7 +66,6 @@ class AndroidBluetoothPlugin extends BluetoothPlugin<BluetoothServerSocket> {
|
||||
|
||||
private static final int MAX_DISCOVERY_MS = 10_000;
|
||||
|
||||
private final ScheduledExecutorService scheduler;
|
||||
private final AndroidExecutor androidExecutor;
|
||||
private final Context appContext;
|
||||
private final Clock clock;
|
||||
@@ -80,13 +78,11 @@ class AndroidBluetoothPlugin extends BluetoothPlugin<BluetoothServerSocket> {
|
||||
|
||||
AndroidBluetoothPlugin(BluetoothConnectionLimiter connectionLimiter,
|
||||
TimeoutMonitor timeoutMonitor, Executor ioExecutor,
|
||||
SecureRandom secureRandom, ScheduledExecutorService scheduler,
|
||||
AndroidExecutor androidExecutor, Context appContext, Clock clock,
|
||||
Backoff backoff, PluginCallback callback, int maxLatency,
|
||||
int maxIdleTime) {
|
||||
SecureRandom secureRandom, AndroidExecutor androidExecutor,
|
||||
Context appContext, Clock clock, Backoff backoff,
|
||||
PluginCallback callback, int maxLatency, int maxIdleTime) {
|
||||
super(connectionLimiter, timeoutMonitor, ioExecutor, secureRandom,
|
||||
backoff, callback, maxLatency, maxIdleTime);
|
||||
this.scheduler = scheduler;
|
||||
this.androidExecutor = androidExecutor;
|
||||
this.appContext = appContext;
|
||||
this.clock = clock;
|
||||
@@ -154,12 +150,6 @@ class AndroidBluetoothPlugin extends BluetoothPlugin<BluetoothServerSocket> {
|
||||
wasEnabledByUs = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
void onAdapterDisabled() {
|
||||
super.onAdapterDisabled();
|
||||
wasEnabledByUs = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
String getBluetoothAddress() {
|
||||
@@ -187,7 +177,7 @@ class AndroidBluetoothPlugin extends BluetoothPlugin<BluetoothServerSocket> {
|
||||
private DuplexTransportConnection wrapSocket(BluetoothSocket s)
|
||||
throws IOException {
|
||||
return new AndroidBluetoothTransportConnection(this, connectionLimiter,
|
||||
timeoutMonitor, appContext, scheduler, s);
|
||||
timeoutMonitor, s);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -16,7 +16,6 @@ import org.briarproject.bramble.api.system.Clock;
|
||||
|
||||
import java.security.SecureRandom;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
|
||||
@@ -33,7 +32,6 @@ public class AndroidBluetoothPluginFactory implements DuplexPluginFactory {
|
||||
private static final double BACKOFF_BASE = 1.2;
|
||||
|
||||
private final Executor ioExecutor;
|
||||
private final ScheduledExecutorService scheduler;
|
||||
private final AndroidExecutor androidExecutor;
|
||||
private final Context appContext;
|
||||
private final SecureRandom secureRandom;
|
||||
@@ -43,12 +41,10 @@ public class AndroidBluetoothPluginFactory implements DuplexPluginFactory {
|
||||
private final BackoffFactory backoffFactory;
|
||||
|
||||
public AndroidBluetoothPluginFactory(Executor ioExecutor,
|
||||
ScheduledExecutorService scheduler,
|
||||
AndroidExecutor androidExecutor, Context appContext,
|
||||
SecureRandom secureRandom, EventBus eventBus, Clock clock,
|
||||
TimeoutMonitor timeoutMonitor, BackoffFactory backoffFactory) {
|
||||
this.ioExecutor = ioExecutor;
|
||||
this.scheduler = scheduler;
|
||||
this.androidExecutor = androidExecutor;
|
||||
this.appContext = appContext;
|
||||
this.secureRandom = secureRandom;
|
||||
@@ -71,12 +67,12 @@ public class AndroidBluetoothPluginFactory implements DuplexPluginFactory {
|
||||
@Override
|
||||
public DuplexPlugin createPlugin(PluginCallback callback) {
|
||||
BluetoothConnectionLimiter connectionLimiter =
|
||||
new BluetoothConnectionLimiterImpl(eventBus);
|
||||
new BluetoothConnectionLimiterImpl(eventBus, clock);
|
||||
Backoff backoff = backoffFactory.createBackoff(MIN_POLLING_INTERVAL,
|
||||
MAX_POLLING_INTERVAL, BACKOFF_BASE);
|
||||
AndroidBluetoothPlugin plugin = new AndroidBluetoothPlugin(
|
||||
connectionLimiter, timeoutMonitor, ioExecutor, secureRandom,
|
||||
scheduler, androidExecutor, appContext, clock, backoff,
|
||||
androidExecutor, appContext, clock, backoff,
|
||||
callback, MAX_LATENCY, MAX_IDLE_TIME);
|
||||
eventBus.addListener(plugin);
|
||||
return plugin;
|
||||
|
||||
@@ -1,26 +1,17 @@
|
||||
package org.briarproject.bramble.plugin.bluetooth;
|
||||
|
||||
import android.bluetooth.BluetoothSocket;
|
||||
import android.content.Context;
|
||||
import android.os.PowerManager;
|
||||
|
||||
import org.briarproject.bramble.api.io.TimeoutMonitor;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.plugin.Plugin;
|
||||
import org.briarproject.bramble.api.plugin.duplex.AbstractDuplexTransportConnection;
|
||||
import org.briarproject.bramble.util.RenewableWakeLock;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
|
||||
import static android.content.Context.POWER_SERVICE;
|
||||
import static android.os.PowerManager.PARTIAL_WAKE_LOCK;
|
||||
import static java.util.concurrent.TimeUnit.MINUTES;
|
||||
import static org.briarproject.bramble.api.nullsafety.NullSafety.requireNonNull;
|
||||
import static org.briarproject.bramble.api.plugin.BluetoothConstants.PROP_ADDRESS;
|
||||
import static org.briarproject.bramble.util.AndroidUtils.getWakeLockTag;
|
||||
import static org.briarproject.bramble.util.AndroidUtils.isValidBluetoothAddress;
|
||||
|
||||
@NotNullByDefault
|
||||
@@ -28,26 +19,18 @@ class AndroidBluetoothTransportConnection
|
||||
extends AbstractDuplexTransportConnection {
|
||||
|
||||
private final BluetoothConnectionLimiter connectionLimiter;
|
||||
private final RenewableWakeLock wakeLock;
|
||||
private final BluetoothSocket socket;
|
||||
private final InputStream in;
|
||||
|
||||
AndroidBluetoothTransportConnection(Plugin plugin,
|
||||
BluetoothConnectionLimiter connectionLimiter,
|
||||
TimeoutMonitor timeoutMonitor, Context appContext,
|
||||
ScheduledExecutorService scheduler, BluetoothSocket socket)
|
||||
TimeoutMonitor timeoutMonitor, BluetoothSocket socket)
|
||||
throws IOException {
|
||||
super(plugin);
|
||||
this.connectionLimiter = connectionLimiter;
|
||||
this.socket = socket;
|
||||
in = timeoutMonitor.createTimeoutInputStream(
|
||||
socket.getInputStream(), plugin.getMaxIdleTime() * 2);
|
||||
PowerManager powerManager = (PowerManager)
|
||||
requireNonNull(appContext.getSystemService(POWER_SERVICE));
|
||||
String tag = getWakeLockTag(appContext);
|
||||
wakeLock = new RenewableWakeLock(powerManager, scheduler,
|
||||
PARTIAL_WAKE_LOCK, tag, 1, MINUTES);
|
||||
wakeLock.acquire();
|
||||
String address = socket.getRemoteDevice().getAddress();
|
||||
if (isValidBluetoothAddress(address)) remote.put(PROP_ADDRESS, address);
|
||||
}
|
||||
@@ -67,7 +50,6 @@ class AndroidBluetoothTransportConnection
|
||||
try {
|
||||
socket.close();
|
||||
} finally {
|
||||
wakeLock.release();
|
||||
connectionLimiter.connectionClosed(this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,30 +1,23 @@
|
||||
package org.briarproject.bramble.plugin.tcp;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.content.Context;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.LinkAddress;
|
||||
import android.net.LinkProperties;
|
||||
import android.net.Network;
|
||||
import android.net.NetworkCapabilities;
|
||||
import android.net.NetworkInfo;
|
||||
import android.net.wifi.WifiInfo;
|
||||
import android.net.wifi.WifiManager;
|
||||
|
||||
import org.briarproject.bramble.PoliteExecutor;
|
||||
import org.briarproject.bramble.api.Pair;
|
||||
import org.briarproject.bramble.api.event.Event;
|
||||
import org.briarproject.bramble.api.event.EventListener;
|
||||
import org.briarproject.bramble.api.network.event.NetworkStatusEvent;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.plugin.Backoff;
|
||||
import org.briarproject.bramble.api.plugin.PluginCallback;
|
||||
import org.briarproject.bramble.api.settings.Settings;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetAddress;
|
||||
import java.net.InterfaceAddress;
|
||||
import java.net.NetworkInterface;
|
||||
import java.net.Socket;
|
||||
import java.net.SocketException;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Executor;
|
||||
@@ -35,21 +28,14 @@ import javax.net.SocketFactory;
|
||||
|
||||
import static android.content.Context.CONNECTIVITY_SERVICE;
|
||||
import static android.content.Context.WIFI_SERVICE;
|
||||
import static android.net.NetworkCapabilities.TRANSPORT_WIFI;
|
||||
import static android.net.ConnectivityManager.TYPE_WIFI;
|
||||
import static android.os.Build.VERSION.SDK_INT;
|
||||
import static java.util.Collections.emptyList;
|
||||
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;
|
||||
import static org.briarproject.bramble.util.LogUtils.logException;
|
||||
|
||||
@NotNullByDefault
|
||||
class AndroidLanTcpPlugin extends LanTcpPlugin {
|
||||
class AndroidLanTcpPlugin extends LanTcpPlugin implements EventListener {
|
||||
|
||||
private static final Logger LOG =
|
||||
getLogger(AndroidLanTcpPlugin.class.getName());
|
||||
@@ -82,137 +68,37 @@ class AndroidLanTcpPlugin extends LanTcpPlugin {
|
||||
public void start() {
|
||||
if (used.getAndSet(true)) throw new IllegalStateException();
|
||||
initialisePortProperty();
|
||||
Settings settings = callback.getSettings();
|
||||
state.setStarted(settings.getBoolean(PREF_PLUGIN_ENABLE,
|
||||
DEFAULT_PREF_PLUGIN_ENABLE));
|
||||
running = true;
|
||||
updateConnectionStatus();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() {
|
||||
running = false;
|
||||
tryToClose(socket);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Socket createSocket() throws IOException {
|
||||
return socketFactory.createSocket();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<InetAddress> getUsableLocalInetAddresses(boolean ipv4) {
|
||||
InetAddress addr = getWifiAddress(ipv4);
|
||||
return addr == null ? emptyList() : singletonList(addr);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private InetAddress getWifiAddress(boolean ipv4) {
|
||||
Pair<InetAddress, Boolean> wifi = getWifiIpv4Address();
|
||||
if (ipv4) return wifi == null ? null : wifi.getFirst();
|
||||
// If there's no wifi IPv4 address, we might be a client on an
|
||||
// IPv6-only wifi network. We can only detect this on API 21+
|
||||
if (wifi == null) {
|
||||
return SDK_INT >= 21 ? getWifiClientIpv6Address() : null;
|
||||
}
|
||||
// Use the wifi IPv4 address to determine which interface's IPv6
|
||||
// address we should return (if the interface has a suitable address)
|
||||
return getIpv6AddressForInterface(wifi.getFirst());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a {@link Pair} where the first element is the IPv4 address of
|
||||
* the wifi interface and the second element is true if this device is
|
||||
* providing an access point, or false if this device is a client. Returns
|
||||
* null if this device isn't connected to wifi as an access point or client.
|
||||
*/
|
||||
@Nullable
|
||||
private Pair<InetAddress, Boolean> getWifiIpv4Address() {
|
||||
if (wifiManager == null) return null;
|
||||
protected List<InetAddress> getUsableLocalInetAddresses() {
|
||||
// If the device doesn't have wifi, don't open any sockets
|
||||
if (wifiManager == null) return emptyList();
|
||||
// If we're connected to a wifi network, return its address
|
||||
WifiInfo info = wifiManager.getConnectionInfo();
|
||||
if (info != null && info.getIpAddress() != 0) {
|
||||
return new Pair<>(intToInetAddress(info.getIpAddress()), false);
|
||||
return singletonList(intToInetAddress(info.getIpAddress()));
|
||||
}
|
||||
List<InterfaceAddress> ifAddrs = getLocalInterfaceAddresses();
|
||||
// If we're providing a normal access point, return its address
|
||||
for (InterfaceAddress ifAddr : ifAddrs) {
|
||||
if (isAndroidWifiApAddress(ifAddr)) {
|
||||
return new Pair<>(ifAddr.getAddress(), true);
|
||||
}
|
||||
}
|
||||
// If we're providing a wifi direct access point, return its address
|
||||
for (InterfaceAddress ifAddr : ifAddrs) {
|
||||
if (isAndroidWifiDirectApAddress(ifAddr)) {
|
||||
return new Pair<>(ifAddr.getAddress(), true);
|
||||
}
|
||||
}
|
||||
// Not connected to wifi
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the given address belongs to a network provided by an
|
||||
* Android access point (including the access point's own address).
|
||||
* <p>
|
||||
* The access point's address is usually 192.168.43.1, but at least one
|
||||
* device (Honor 8A) may use other addresses in the range 192.168.43.0/24.
|
||||
*/
|
||||
private boolean isAndroidWifiApAddress(InterfaceAddress ifAddr) {
|
||||
if (ifAddr.getNetworkPrefixLength() != 24) return false;
|
||||
byte[] ip = ifAddr.getAddress().getAddress();
|
||||
return ip.length == 4
|
||||
&& ip[0] == (byte) 192
|
||||
&& ip[1] == (byte) 168
|
||||
&& ip[2] == (byte) 43;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the given address belongs to a network provided by an
|
||||
* Android wifi direct legacy mode access point (including the access
|
||||
* point's own address).
|
||||
*/
|
||||
private boolean isAndroidWifiDirectApAddress(InterfaceAddress ifAddr) {
|
||||
if (ifAddr.getNetworkPrefixLength() != 24) return false;
|
||||
byte[] ip = ifAddr.getAddress().getAddress();
|
||||
return ip.length == 4
|
||||
&& ip[0] == (byte) 192
|
||||
&& ip[1] == (byte) 168
|
||||
&& ip[2] == (byte) 49;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a link-local IPv6 address for the wifi client interface, or null
|
||||
* if there's no such interface or it doesn't have a suitable address.
|
||||
*/
|
||||
@TargetApi(21)
|
||||
@Nullable
|
||||
private InetAddress getWifiClientIpv6Address() {
|
||||
for (Network net : connectivityManager.getAllNetworks()) {
|
||||
NetworkCapabilities caps =
|
||||
connectivityManager.getNetworkCapabilities(net);
|
||||
if (caps == null || !caps.hasTransport(TRANSPORT_WIFI)) continue;
|
||||
LinkProperties props = connectivityManager.getLinkProperties(net);
|
||||
if (props == null) continue;
|
||||
for (LinkAddress linkAddress : props.getLinkAddresses()) {
|
||||
InetAddress addr = linkAddress.getAddress();
|
||||
if (isIpv6LinkLocalAddress(addr)) return addr;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a link-local IPv6 address for the interface with the given IPv4
|
||||
* address, or null if the interface doesn't have a suitable address.
|
||||
*/
|
||||
@Nullable
|
||||
private InetAddress getIpv6AddressForInterface(InetAddress ipv4) {
|
||||
try {
|
||||
NetworkInterface iface = NetworkInterface.getByInetAddress(ipv4);
|
||||
if (iface == null) return null;
|
||||
for (InetAddress addr : list(iface.getInetAddresses())) {
|
||||
if (isIpv6LinkLocalAddress(addr)) return addr;
|
||||
}
|
||||
// No suitable address
|
||||
return null;
|
||||
} catch (SocketException e) {
|
||||
logException(LOG, WARNING, e);
|
||||
return null;
|
||||
// If we're running an access point, return its address
|
||||
for (InetAddress addr : getLocalInetAddresses()) {
|
||||
if (addr.equals(WIFI_AP_ADDRESS)) return singletonList(addr);
|
||||
if (addr.equals(WIFI_DIRECT_AP_ADDRESS)) return singletonList(addr);
|
||||
}
|
||||
// No suitable addresses
|
||||
return emptyList();
|
||||
}
|
||||
|
||||
private InetAddress intToInetAddress(int ip) {
|
||||
@@ -234,11 +120,9 @@ class AndroidLanTcpPlugin extends LanTcpPlugin {
|
||||
private SocketFactory getSocketFactory() {
|
||||
if (SDK_INT < 21) return SocketFactory.getDefault();
|
||||
for (Network net : connectivityManager.getAllNetworks()) {
|
||||
NetworkCapabilities caps =
|
||||
connectivityManager.getNetworkCapabilities(net);
|
||||
if (caps != null && caps.hasTransport(TRANSPORT_WIFI)) {
|
||||
NetworkInfo info = connectivityManager.getNetworkInfo(net);
|
||||
if (info != null && info.getType() == TYPE_WIFI)
|
||||
return net.getSocketFactory();
|
||||
}
|
||||
}
|
||||
LOG.warning("Could not find suitable socket factory");
|
||||
return SocketFactory.getDefault();
|
||||
@@ -246,59 +130,31 @@ class AndroidLanTcpPlugin extends LanTcpPlugin {
|
||||
|
||||
@Override
|
||||
public void eventOccurred(Event e) {
|
||||
super.eventOccurred(e);
|
||||
if (e instanceof NetworkStatusEvent) updateConnectionStatus();
|
||||
}
|
||||
|
||||
private void updateConnectionStatus() {
|
||||
connectionStatusExecutor.execute(() -> {
|
||||
State s = getState();
|
||||
if (s != ACTIVE && s != INACTIVE) return;
|
||||
Pair<InetAddress, Boolean> wifi = getPreferredWifiAddress();
|
||||
if (wifi == null) {
|
||||
LOG.info("Not connected to wifi");
|
||||
socketFactory = SocketFactory.getDefault();
|
||||
// Server sockets may not have been closed automatically when
|
||||
// interface was taken down. If any sockets are open, closing
|
||||
// them here will cause the sockets to be cleared and the state
|
||||
// to be updated in acceptContactConnections()
|
||||
if (s == ACTIVE) {
|
||||
LOG.info("Closing server sockets");
|
||||
tryToClose(state.getServerSocket(true), LOG, WARNING);
|
||||
tryToClose(state.getServerSocket(false), LOG, WARNING);
|
||||
}
|
||||
} else if (wifi.getSecond()) {
|
||||
if (!running) return;
|
||||
List<InetAddress> addrs = getUsableLocalInetAddresses();
|
||||
if (addrs.contains(WIFI_AP_ADDRESS)
|
||||
|| addrs.contains(WIFI_DIRECT_AP_ADDRESS)) {
|
||||
LOG.info("Providing wifi hotspot");
|
||||
// There's no corresponding Network object and thus no way
|
||||
// to get a suitable socket factory, so we won't be able to
|
||||
// make outgoing connections on API 21+ if another network
|
||||
// has internet access
|
||||
socketFactory = SocketFactory.getDefault();
|
||||
if (s == INACTIVE) bind();
|
||||
if (socket == null || socket.isClosed()) bind();
|
||||
} else if (addrs.isEmpty()) {
|
||||
LOG.info("Not connected to wifi");
|
||||
socketFactory = SocketFactory.getDefault();
|
||||
tryToClose(socket);
|
||||
} else {
|
||||
LOG.info("Connected to wifi");
|
||||
socketFactory = getSocketFactory();
|
||||
if (s == INACTIVE) bind();
|
||||
if (socket == null || socket.isClosed()) bind();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a {@link Pair} where the first element is an IP address (IPv4 if
|
||||
* available, otherwise IPv6) of the wifi interface and the second element
|
||||
* is true if this device is providing an access point, or false if this
|
||||
* device is a client. Returns null if this device isn't connected to wifi
|
||||
* as an access point or client.
|
||||
*/
|
||||
@Nullable
|
||||
private Pair<InetAddress, Boolean> getPreferredWifiAddress() {
|
||||
Pair<InetAddress, Boolean> wifi = getWifiIpv4Address();
|
||||
// If there's no wifi IPv4 address, we might be a client on an
|
||||
// IPv6-only wifi network. We can only detect this on API 21+
|
||||
if (wifi == null && SDK_INT >= 21) {
|
||||
InetAddress ipv6 = getWifiClientIpv6Address();
|
||||
if (ipv6 != null) return new Pair<>(ipv6, false);
|
||||
}
|
||||
return wifi;
|
||||
}
|
||||
}
|
||||
@@ -27,7 +27,6 @@ import static android.content.Context.MODE_PRIVATE;
|
||||
import static android.content.Context.POWER_SERVICE;
|
||||
import static android.os.PowerManager.PARTIAL_WAKE_LOCK;
|
||||
import static java.util.concurrent.TimeUnit.MINUTES;
|
||||
import static org.briarproject.bramble.util.AndroidUtils.getWakeLockTag;
|
||||
|
||||
@MethodsNotNullByDefault
|
||||
@ParametersNotNullByDefault
|
||||
@@ -54,7 +53,7 @@ class AndroidTorPlugin extends TorPlugin {
|
||||
appContext.getSystemService(POWER_SERVICE);
|
||||
if (pm == null) throw new AssertionError();
|
||||
wakeLock = new RenewableWakeLock(pm, scheduler, PARTIAL_WAKE_LOCK,
|
||||
getWakeLockTag(appContext), 1, MINUTES);
|
||||
getWakeLockTag(), 1, MINUTES);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -75,6 +74,7 @@ class AndroidTorPlugin extends TorPlugin {
|
||||
|
||||
@Override
|
||||
protected void enableNetwork(boolean enable) throws IOException {
|
||||
if (!running) return;
|
||||
if (enable) wakeLock.acquire();
|
||||
super.enableNetwork(enable);
|
||||
if (!enable) wakeLock.release();
|
||||
@@ -85,4 +85,17 @@ class AndroidTorPlugin extends TorPlugin {
|
||||
super.stop();
|
||||
wakeLock.release();
|
||||
}
|
||||
|
||||
private String getWakeLockTag() {
|
||||
PackageManager pm = appContext.getPackageManager();
|
||||
for (PackageInfo info : pm.getInstalledPackages(0)) {
|
||||
String name = info.packageName.toLowerCase();
|
||||
if (name.startsWith("com.huawei.powergenie")) {
|
||||
return "LocationManagerService";
|
||||
} else if (name.startsWith("com.evenwell.powermonitor")) {
|
||||
return "AudioIn";
|
||||
}
|
||||
}
|
||||
return getClass().getSimpleName();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,12 +61,12 @@ class AndroidLocationUtils implements LocationUtils {
|
||||
private String getCountryFromPhoneNetwork() {
|
||||
Object o = appContext.getSystemService(TELEPHONY_SERVICE);
|
||||
TelephonyManager tm = (TelephonyManager) o;
|
||||
return tm == null ? "" : tm.getNetworkCountryIso();
|
||||
return tm.getNetworkCountryIso();
|
||||
}
|
||||
|
||||
private String getCountryFromSimCard() {
|
||||
Object o = appContext.getSystemService(TELEPHONY_SERVICE);
|
||||
TelephonyManager tm = (TelephonyManager) o;
|
||||
return tm == null ? "" : tm.getSimCountryIso();
|
||||
return tm.getSimCountryIso();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,8 +3,6 @@ package org.briarproject.bramble.util;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.bluetooth.BluetoothAdapter;
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.Build;
|
||||
import android.provider.Settings;
|
||||
|
||||
@@ -119,17 +117,4 @@ public class AndroidUtils {
|
||||
if (SDK_INT < 24) return new String[] {"image/jpeg", "image/png"};
|
||||
else return new String[] {"image/jpeg", "image/png", "image/gif"};
|
||||
}
|
||||
|
||||
public static String getWakeLockTag(Context ctx) {
|
||||
PackageManager pm = ctx.getPackageManager();
|
||||
for (PackageInfo info : pm.getInstalledPackages(0)) {
|
||||
String name = info.packageName.toLowerCase();
|
||||
if (name.startsWith("com.huawei.powergenie")) {
|
||||
return "LocationManagerService";
|
||||
} else if (name.startsWith("com.evenwell.powermonitor")) {
|
||||
return "AudioIn";
|
||||
}
|
||||
}
|
||||
return ctx.getPackageName();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,8 +18,6 @@ public interface EventBus {
|
||||
/**
|
||||
* Asynchronously notifies all listeners of an event. Listeners are
|
||||
* notified on the {@link EventExecutor}.
|
||||
* <p>
|
||||
* This method can safely be called while holding a lock.
|
||||
*/
|
||||
void broadcast(Event e);
|
||||
}
|
||||
|
||||
@@ -6,10 +6,8 @@ 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;
|
||||
String PREF_BT_ENABLE = "enable";
|
||||
}
|
||||
|
||||
@@ -7,12 +7,7 @@ public interface LanTcpConstants {
|
||||
// Transport properties (shared with contacts)
|
||||
String PROP_IP_PORTS = "ipPorts";
|
||||
String PROP_PORT = "port";
|
||||
String PROP_IPV6 = "ipv6";
|
||||
|
||||
// Local settings (not shared with contacts)
|
||||
// A local setting
|
||||
String PREF_LAN_IP_PORTS = "ipPorts";
|
||||
String PREF_IPV6 = "ipv6";
|
||||
|
||||
// Default value for PREF_PLUGIN_ENABLE
|
||||
boolean DEFAULT_PREF_PLUGIN_ENABLE = true;
|
||||
}
|
||||
|
||||
@@ -3,55 +3,12 @@ package org.briarproject.bramble.api.plugin;
|
||||
import org.briarproject.bramble.api.Pair;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.properties.TransportProperties;
|
||||
import org.briarproject.bramble.api.settings.SettingsManager;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
@NotNullByDefault
|
||||
public interface Plugin {
|
||||
|
||||
enum State {
|
||||
|
||||
/**
|
||||
* The plugin has not finished starting or has been stopped.
|
||||
*/
|
||||
STARTING_STOPPING,
|
||||
|
||||
/**
|
||||
* The plugin is disabled by settings. Use {@link #getReasonsDisabled()}
|
||||
* to find out which settings are responsible.
|
||||
*/
|
||||
DISABLED,
|
||||
|
||||
/**
|
||||
* The plugin is being enabled and can't yet make or receive
|
||||
* connections.
|
||||
*/
|
||||
ENABLING,
|
||||
|
||||
/**
|
||||
* The plugin is enabled and can make or receive connections.
|
||||
*/
|
||||
ACTIVE,
|
||||
|
||||
/**
|
||||
* The plugin is enabled but can't make or receive connections
|
||||
*/
|
||||
INACTIVE
|
||||
}
|
||||
|
||||
/**
|
||||
* The string for the boolean preference
|
||||
* to use with the {@link SettingsManager} to enable or disable the plugin.
|
||||
*/
|
||||
String PREF_PLUGIN_ENABLE = "enable";
|
||||
|
||||
/**
|
||||
* Reason flag returned by {@link #getReasonsDisabled()} to indicate that
|
||||
* the plugin has been disabled by the user.
|
||||
*/
|
||||
int REASON_USER = 1;
|
||||
|
||||
/**
|
||||
* Returns the plugin's transport identifier.
|
||||
*/
|
||||
@@ -78,18 +35,9 @@ public interface Plugin {
|
||||
void stop() throws PluginException;
|
||||
|
||||
/**
|
||||
* Returns the current state of the plugin.
|
||||
* Returns true if the plugin is running.
|
||||
*/
|
||||
State getState();
|
||||
|
||||
/**
|
||||
* Returns a set of flags indicating why the plugin is
|
||||
* {@link State#DISABLED disabled}, or 0 if the plugin is not disabled.
|
||||
* <p>
|
||||
* The flags used are plugin-specific, except the generic flag
|
||||
* {@link #REASON_USER}, which may be used by any plugin.
|
||||
*/
|
||||
int getReasonsDisabled();
|
||||
boolean isRunning();
|
||||
|
||||
/**
|
||||
* Returns true if the plugin should be polled periodically to attempt to
|
||||
|
||||
@@ -1,10 +1,6 @@
|
||||
package org.briarproject.bramble.api.plugin;
|
||||
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.plugin.Plugin.State;
|
||||
import org.briarproject.bramble.api.plugin.event.TransportActiveEvent;
|
||||
import org.briarproject.bramble.api.plugin.event.TransportInactiveEvent;
|
||||
import org.briarproject.bramble.api.plugin.event.TransportStateEvent;
|
||||
import org.briarproject.bramble.api.properties.TransportProperties;
|
||||
import org.briarproject.bramble.api.settings.Settings;
|
||||
|
||||
@@ -36,17 +32,12 @@ public interface PluginCallback extends ConnectionHandler {
|
||||
void mergeLocalProperties(TransportProperties p);
|
||||
|
||||
/**
|
||||
* Informs the callback of the plugin's current state.
|
||||
* <p>
|
||||
* If the current state is different from the previous state, the callback
|
||||
* will broadcast a {@link TransportStateEvent}. If the current state is
|
||||
* {@link State#ACTIVE} and the previous state was not
|
||||
* {@link State#ACTIVE}, the callback will broadcast a
|
||||
* {@link TransportActiveEvent}. If the current state is not
|
||||
* {@link State#ACTIVE} and the previous state was {@link State#ACTIVE},
|
||||
* the callback will broadcast a {@link TransportInactiveEvent}.
|
||||
* <p>
|
||||
* This method can safely be called while holding a lock.
|
||||
* Signals that the transport is enabled.
|
||||
*/
|
||||
void pluginStateChanged(State state);
|
||||
void transportEnabled();
|
||||
|
||||
/**
|
||||
* Signals that the transport is disabled.
|
||||
*/
|
||||
void transportDisabled();
|
||||
}
|
||||
|
||||
@@ -41,17 +41,4 @@ public interface PluginManager {
|
||||
* Returns any duplex plugins that support rendezvous.
|
||||
*/
|
||||
Collection<DuplexPlugin> getRendezvousPlugins();
|
||||
|
||||
/**
|
||||
* Enables or disables the plugin
|
||||
* identified by the given {@link TransportId}.
|
||||
* <p>
|
||||
* Note that this applies the change asynchronously
|
||||
* and there are no order guarantees.
|
||||
* <p>
|
||||
* If no plugin with the given {@link TransportId} is registered,
|
||||
* this is a no-op.
|
||||
*/
|
||||
void setPluginEnabled(TransportId t, boolean enabled);
|
||||
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ public interface TorConstants {
|
||||
|
||||
TransportId ID = new TransportId("org.briarproject.bramble.tor");
|
||||
|
||||
// Transport properties
|
||||
String PROP_ONION_V2 = "onion";
|
||||
String PROP_ONION_V3 = "onion3";
|
||||
|
||||
@@ -14,37 +13,14 @@ 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()}.
|
||||
*/
|
||||
int REASON_BATTERY = 2;
|
||||
|
||||
/**
|
||||
* Reason flag returned by {@link Plugin#getReasonsDisabled()}.
|
||||
*/
|
||||
int REASON_MOBILE_DATA = 4;
|
||||
|
||||
/**
|
||||
* Reason flag returned by {@link Plugin#getReasonsDisabled()}.
|
||||
*/
|
||||
int REASON_COUNTRY_BLOCKED = 8;
|
||||
}
|
||||
|
||||
@@ -4,7 +4,4 @@ public interface WanTcpConstants {
|
||||
|
||||
TransportId ID = new TransportId("org.briarproject.bramble.wan");
|
||||
|
||||
// Default value for PREF_PLUGIN_ENABLE
|
||||
boolean DEFAULT_PREF_PLUGIN_ENABLE = false;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,22 +2,20 @@ package org.briarproject.bramble.api.plugin.event;
|
||||
|
||||
import org.briarproject.bramble.api.event.Event;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.plugin.Plugin.State;
|
||||
import org.briarproject.bramble.api.plugin.TransportId;
|
||||
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
|
||||
/**
|
||||
* An event that is broadcast when a plugin enters the {@link State#ACTIVE}
|
||||
* state.
|
||||
* An event that is broadcast when a transport is disabled.
|
||||
*/
|
||||
@Immutable
|
||||
@NotNullByDefault
|
||||
public class TransportActiveEvent extends Event {
|
||||
public class TransportDisabledEvent extends Event {
|
||||
|
||||
private final TransportId transportId;
|
||||
|
||||
public TransportActiveEvent(TransportId transportId) {
|
||||
public TransportDisabledEvent(TransportId transportId) {
|
||||
this.transportId = transportId;
|
||||
}
|
||||
|
||||
@@ -2,22 +2,20 @@ package org.briarproject.bramble.api.plugin.event;
|
||||
|
||||
import org.briarproject.bramble.api.event.Event;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.plugin.Plugin.State;
|
||||
import org.briarproject.bramble.api.plugin.TransportId;
|
||||
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
|
||||
/**
|
||||
* An event that is broadcast when a plugin leaves the {@link State#ACTIVE}
|
||||
* state.
|
||||
* An event that is broadcast when a transport is enabled.
|
||||
*/
|
||||
@Immutable
|
||||
@NotNullByDefault
|
||||
public class TransportInactiveEvent extends Event {
|
||||
public class TransportEnabledEvent extends Event {
|
||||
|
||||
private final TransportId transportId;
|
||||
|
||||
public TransportInactiveEvent(TransportId transportId) {
|
||||
public TransportEnabledEvent(TransportId transportId) {
|
||||
this.transportId = transportId;
|
||||
}
|
||||
|
||||
@@ -1,32 +0,0 @@
|
||||
package org.briarproject.bramble.api.plugin.event;
|
||||
|
||||
import org.briarproject.bramble.api.event.Event;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.plugin.Plugin.State;
|
||||
import org.briarproject.bramble.api.plugin.TransportId;
|
||||
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
|
||||
/**
|
||||
* An event that is broadcast when the {@link State state} of a plugin changes.
|
||||
*/
|
||||
@Immutable
|
||||
@NotNullByDefault
|
||||
public class TransportStateEvent extends Event {
|
||||
|
||||
private final TransportId transportId;
|
||||
private final State state;
|
||||
|
||||
public TransportStateEvent(TransportId transportId, State state) {
|
||||
this.transportId = transportId;
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
public TransportId getTransportId() {
|
||||
return transportId;
|
||||
}
|
||||
|
||||
public State getState() {
|
||||
return state;
|
||||
}
|
||||
}
|
||||
@@ -2,17 +2,13 @@ package org.briarproject.bramble.util;
|
||||
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
|
||||
import java.net.Inet4Address;
|
||||
import java.net.Inet6Address;
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.SocketAddress;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import static org.briarproject.bramble.util.StringUtils.isNullOrEmpty;
|
||||
import static org.briarproject.bramble.util.StringUtils.isValidMac;
|
||||
import static org.briarproject.bramble.util.StringUtils.toHexString;
|
||||
|
||||
@NotNullByDefault
|
||||
public class PrivacyUtils {
|
||||
|
||||
@@ -23,7 +19,7 @@ public class PrivacyUtils {
|
||||
|
||||
@Nullable
|
||||
public static String scrubMacAddress(@Nullable String address) {
|
||||
if (isNullOrEmpty(address) || !isValidMac(address)) return address;
|
||||
if (address == null || address.length() == 0) return null;
|
||||
// this is a fake address we need to know about
|
||||
if (address.equals("02:00:00:00:00:00")) return address;
|
||||
// keep first and last octet of MAC address
|
||||
@@ -31,37 +27,39 @@ public class PrivacyUtils {
|
||||
+ address.substring(14, 17);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static String scrubInetAddress(InetAddress address) {
|
||||
if (address instanceof Inet4Address) {
|
||||
// Don't scrub local IPv4 addresses
|
||||
if (address.isLoopbackAddress() || address.isLinkLocalAddress() ||
|
||||
address.isSiteLocalAddress()) {
|
||||
return address.getHostAddress();
|
||||
}
|
||||
// Keep first and last octet of non-local IPv4 addresses
|
||||
return scrubIpv4Address(address.getAddress());
|
||||
} else {
|
||||
// Keep first and last octet of IPv6 addresses
|
||||
return scrubIpv6Address(address.getAddress());
|
||||
}
|
||||
// don't scrub link and site local addresses
|
||||
if (address.isLinkLocalAddress() || address.isSiteLocalAddress())
|
||||
return address.toString();
|
||||
// completely scrub IPv6 addresses
|
||||
if (address instanceof Inet6Address) return "[scrubbed]";
|
||||
// keep first and last octet of IPv4 addresses
|
||||
return scrubInetAddress(address.toString());
|
||||
}
|
||||
|
||||
private static String scrubIpv4Address(byte[] ipv4) {
|
||||
return (ipv4[0] & 0xFF) + ".[scrubbed]." + (ipv4[3] & 0xFF);
|
||||
}
|
||||
|
||||
private static String scrubIpv6Address(byte[] ipv6) {
|
||||
String hex = toHexString(ipv6).toLowerCase();
|
||||
return hex.substring(0, 2) + "[scrubbed]" + hex.substring(30);
|
||||
@Nullable
|
||||
public static String scrubInetAddress(@Nullable String address) {
|
||||
if (address == null) return null;
|
||||
|
||||
int firstDot = address.indexOf(".");
|
||||
if (firstDot == -1) return "[scrubbed]";
|
||||
String prefix = address.substring(0, firstDot + 1);
|
||||
int lastDot = address.lastIndexOf(".");
|
||||
String suffix = address.substring(lastDot, address.length());
|
||||
return prefix + "[scrubbed]" + suffix;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static String scrubSocketAddress(InetSocketAddress address) {
|
||||
return scrubInetAddress(address.getAddress());
|
||||
InetAddress inetAddress = address.getAddress();
|
||||
return scrubInetAddress(inetAddress);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static String scrubSocketAddress(SocketAddress address) {
|
||||
if (address instanceof InetSocketAddress)
|
||||
return scrubSocketAddress((InetSocketAddress) address);
|
||||
return "[scrubbed]";
|
||||
return scrubInetAddress(address.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,12 +63,18 @@ class ConnectionRegistryImpl implements ConnectionRegistry {
|
||||
@Override
|
||||
public void registerIncomingConnection(ContactId c, TransportId t,
|
||||
InterruptibleConnection conn) {
|
||||
if (LOG.isLoggable(INFO)) {
|
||||
LOG.info("Incoming connection registered: " + t);
|
||||
}
|
||||
registerConnection(c, t, conn, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerOutgoingConnection(ContactId c, TransportId t,
|
||||
InterruptibleConnection conn, Priority priority) {
|
||||
if (LOG.isLoggable(INFO)) {
|
||||
LOG.info("Outgoing connection registered: " + t);
|
||||
}
|
||||
registerConnection(c, t, conn, false);
|
||||
setPriority(c, t, conn, priority);
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@ import org.briarproject.bramble.api.lifecycle.Service;
|
||||
import org.briarproject.bramble.api.lifecycle.ServiceException;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.plugin.Plugin;
|
||||
import org.briarproject.bramble.api.plugin.Plugin.State;
|
||||
import org.briarproject.bramble.api.plugin.PluginCallback;
|
||||
import org.briarproject.bramble.api.plugin.PluginConfig;
|
||||
import org.briarproject.bramble.api.plugin.PluginException;
|
||||
@@ -19,9 +18,8 @@ import org.briarproject.bramble.api.plugin.TransportId;
|
||||
import org.briarproject.bramble.api.plugin.duplex.DuplexPlugin;
|
||||
import org.briarproject.bramble.api.plugin.duplex.DuplexPluginFactory;
|
||||
import org.briarproject.bramble.api.plugin.duplex.DuplexTransportConnection;
|
||||
import org.briarproject.bramble.api.plugin.event.TransportActiveEvent;
|
||||
import org.briarproject.bramble.api.plugin.event.TransportInactiveEvent;
|
||||
import org.briarproject.bramble.api.plugin.event.TransportStateEvent;
|
||||
import org.briarproject.bramble.api.plugin.event.TransportDisabledEvent;
|
||||
import org.briarproject.bramble.api.plugin.event.TransportEnabledEvent;
|
||||
import org.briarproject.bramble.api.plugin.simplex.SimplexPlugin;
|
||||
import org.briarproject.bramble.api.plugin.simplex.SimplexPluginFactory;
|
||||
import org.briarproject.bramble.api.properties.TransportProperties;
|
||||
@@ -38,7 +36,6 @@ import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javax.annotation.concurrent.ThreadSafe;
|
||||
@@ -48,9 +45,6 @@ import static java.util.logging.Level.FINE;
|
||||
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.plugin.Plugin.PREF_PLUGIN_ENABLE;
|
||||
import static org.briarproject.bramble.api.plugin.Plugin.State.ACTIVE;
|
||||
import static org.briarproject.bramble.api.plugin.Plugin.State.STARTING_STOPPING;
|
||||
import static org.briarproject.bramble.util.LogUtils.logDuration;
|
||||
import static org.briarproject.bramble.util.LogUtils.logException;
|
||||
import static org.briarproject.bramble.util.LogUtils.now;
|
||||
@@ -183,26 +177,6 @@ class PluginManagerImpl implements PluginManager, Service {
|
||||
return supported;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPluginEnabled(TransportId t, boolean enabled) {
|
||||
Plugin plugin = plugins.get(t);
|
||||
if (plugin == null) return;
|
||||
|
||||
Settings s = new Settings();
|
||||
s.putBoolean(PREF_PLUGIN_ENABLE, enabled);
|
||||
ioExecutor.execute(() -> mergeSettings(s, t.getString()));
|
||||
}
|
||||
|
||||
private void mergeSettings(Settings s, String namespace) {
|
||||
try {
|
||||
long start = now();
|
||||
settingsManager.mergeSettings(s, namespace);
|
||||
logDuration(LOG, "Merging settings", start);
|
||||
} catch (DbException e) {
|
||||
logException(LOG, WARNING, e);
|
||||
}
|
||||
}
|
||||
|
||||
private class PluginStarter implements Runnable {
|
||||
|
||||
private final Plugin plugin;
|
||||
@@ -276,8 +250,7 @@ class PluginManagerImpl implements PluginManager, Service {
|
||||
private class Callback implements PluginCallback {
|
||||
|
||||
private final TransportId id;
|
||||
private final AtomicReference<State> state =
|
||||
new AtomicReference<>(STARTING_STOPPING);
|
||||
private final AtomicBoolean enabled = new AtomicBoolean(false);
|
||||
|
||||
private Callback(TransportId id) {
|
||||
this.id = id;
|
||||
@@ -305,7 +278,11 @@ class PluginManagerImpl implements PluginManager, Service {
|
||||
|
||||
@Override
|
||||
public void mergeSettings(Settings s) {
|
||||
PluginManagerImpl.this.mergeSettings(s, id.getString());
|
||||
try {
|
||||
settingsManager.mergeSettings(s, id.getString());
|
||||
} catch (DbException e) {
|
||||
logException(LOG, WARNING, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -318,20 +295,15 @@ class PluginManagerImpl implements PluginManager, Service {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void pluginStateChanged(State newState) {
|
||||
State oldState = state.getAndSet(newState);
|
||||
if (newState != oldState) {
|
||||
if (LOG.isLoggable(INFO)) {
|
||||
LOG.info(id + " changed from state " + oldState
|
||||
+ " to " + newState);
|
||||
}
|
||||
eventBus.broadcast(new TransportStateEvent(id, newState));
|
||||
if (newState == ACTIVE) {
|
||||
eventBus.broadcast(new TransportActiveEvent(id));
|
||||
} else if (oldState == ACTIVE) {
|
||||
eventBus.broadcast(new TransportInactiveEvent(id));
|
||||
}
|
||||
}
|
||||
public void transportEnabled() {
|
||||
if (!enabled.getAndSet(true))
|
||||
eventBus.broadcast(new TransportEnabledEvent(id));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void transportDisabled() {
|
||||
if (enabled.getAndSet(false))
|
||||
eventBus.broadcast(new TransportDisabledEvent(id));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -20,8 +20,8 @@ import org.briarproject.bramble.api.plugin.duplex.DuplexPlugin;
|
||||
import org.briarproject.bramble.api.plugin.duplex.DuplexTransportConnection;
|
||||
import org.briarproject.bramble.api.plugin.event.ConnectionClosedEvent;
|
||||
import org.briarproject.bramble.api.plugin.event.ConnectionOpenedEvent;
|
||||
import org.briarproject.bramble.api.plugin.event.TransportActiveEvent;
|
||||
import org.briarproject.bramble.api.plugin.event.TransportInactiveEvent;
|
||||
import org.briarproject.bramble.api.plugin.event.TransportDisabledEvent;
|
||||
import org.briarproject.bramble.api.plugin.event.TransportEnabledEvent;
|
||||
import org.briarproject.bramble.api.plugin.simplex.SimplexPlugin;
|
||||
import org.briarproject.bramble.api.properties.TransportProperties;
|
||||
import org.briarproject.bramble.api.properties.TransportPropertyManager;
|
||||
@@ -106,13 +106,13 @@ class PollerImpl implements Poller, EventListener {
|
||||
ConnectionOpenedEvent c = (ConnectionOpenedEvent) e;
|
||||
// Reschedule polling, the polling interval may have decreased
|
||||
reschedule(c.getTransportId());
|
||||
} else if (e instanceof TransportActiveEvent) {
|
||||
TransportActiveEvent t = (TransportActiveEvent) e;
|
||||
// Poll the newly activated transport
|
||||
} else if (e instanceof TransportEnabledEvent) {
|
||||
TransportEnabledEvent t = (TransportEnabledEvent) e;
|
||||
// Poll the newly enabled transport
|
||||
pollNow(t.getTransportId());
|
||||
} else if (e instanceof TransportInactiveEvent) {
|
||||
TransportInactiveEvent t = (TransportInactiveEvent) e;
|
||||
// Cancel polling for the deactivated transport
|
||||
} else if (e instanceof TransportDisabledEvent) {
|
||||
TransportDisabledEvent t = (TransportDisabledEvent) e;
|
||||
// Cancel polling for the disabled transport
|
||||
cancel(t.getTransportId());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,9 +3,16 @@ package org.briarproject.bramble.plugin.bluetooth;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.plugin.duplex.DuplexTransportConnection;
|
||||
|
||||
import static java.util.concurrent.TimeUnit.SECONDS;
|
||||
|
||||
@NotNullByDefault
|
||||
interface BluetoothConnectionLimiter {
|
||||
|
||||
/**
|
||||
* How long a connection must remain open before it's considered stable.
|
||||
*/
|
||||
long STABILITY_PERIOD_MS = SECONDS.toMillis(90);
|
||||
|
||||
/**
|
||||
* Informs the limiter that key agreement has started.
|
||||
*/
|
||||
|
||||
@@ -4,7 +4,9 @@ import org.briarproject.bramble.api.event.EventBus;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.plugin.duplex.DuplexTransportConnection;
|
||||
import org.briarproject.bramble.api.sync.event.CloseSyncConnectionsEvent;
|
||||
import org.briarproject.bramble.api.system.Clock;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.logging.Logger;
|
||||
@@ -24,16 +26,19 @@ class BluetoothConnectionLimiterImpl implements BluetoothConnectionLimiter {
|
||||
getLogger(BluetoothConnectionLimiterImpl.class.getName());
|
||||
|
||||
private final EventBus eventBus;
|
||||
private final Clock clock;
|
||||
|
||||
private final Object lock = new Object();
|
||||
@GuardedBy("lock")
|
||||
private final List<DuplexTransportConnection> connections =
|
||||
new LinkedList<>();
|
||||
private final List<ConnectionRecord> connections = new LinkedList<>();
|
||||
@GuardedBy("lock")
|
||||
private boolean keyAgreementInProgress = false;
|
||||
@GuardedBy("lock")
|
||||
private int connectionLimit = 2;
|
||||
|
||||
BluetoothConnectionLimiterImpl(EventBus eventBus) {
|
||||
BluetoothConnectionLimiterImpl(EventBus eventBus, Clock clock) {
|
||||
this.eventBus = eventBus;
|
||||
this.clock = clock;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -59,9 +64,15 @@ class BluetoothConnectionLimiterImpl implements BluetoothConnectionLimiter {
|
||||
if (keyAgreementInProgress) {
|
||||
LOG.info("Can't open contact connection during key agreement");
|
||||
return false;
|
||||
} else {
|
||||
}
|
||||
long now = clock.currentTimeMillis();
|
||||
countStableConnections(now);
|
||||
if (connections.size() < connectionLimit) {
|
||||
LOG.info("Can open contact connection");
|
||||
return true;
|
||||
} else {
|
||||
LOG.info("Can't open contact connection due to limit");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -69,7 +80,9 @@ class BluetoothConnectionLimiterImpl implements BluetoothConnectionLimiter {
|
||||
@Override
|
||||
public void connectionOpened(DuplexTransportConnection conn) {
|
||||
synchronized (lock) {
|
||||
connections.add(conn);
|
||||
long now = clock.currentTimeMillis();
|
||||
countStableConnections(now);
|
||||
connections.add(new ConnectionRecord(conn, now));
|
||||
if (LOG.isLoggable(INFO)) {
|
||||
LOG.info("Connection opened, " + connections.size() + " open");
|
||||
}
|
||||
@@ -79,7 +92,14 @@ class BluetoothConnectionLimiterImpl implements BluetoothConnectionLimiter {
|
||||
@Override
|
||||
public void connectionClosed(DuplexTransportConnection conn) {
|
||||
synchronized (lock) {
|
||||
connections.remove(conn);
|
||||
countStableConnections(clock.currentTimeMillis());
|
||||
Iterator<ConnectionRecord> it = connections.iterator();
|
||||
while (it.hasNext()) {
|
||||
if (it.next().conn == conn) {
|
||||
it.remove();
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (LOG.isLoggable(INFO)) {
|
||||
LOG.info("Connection closed, " + connections.size() + " open");
|
||||
}
|
||||
@@ -89,8 +109,36 @@ class BluetoothConnectionLimiterImpl implements BluetoothConnectionLimiter {
|
||||
@Override
|
||||
public void allConnectionsClosed() {
|
||||
synchronized (lock) {
|
||||
long now = clock.currentTimeMillis();
|
||||
countStableConnections(now);
|
||||
connections.clear();
|
||||
LOG.info("All connections closed");
|
||||
}
|
||||
}
|
||||
|
||||
@GuardedBy("lock")
|
||||
private void countStableConnections(long now) {
|
||||
int stable = 0;
|
||||
for (ConnectionRecord rec : connections) {
|
||||
if (now - rec.timeOpened >= STABILITY_PERIOD_MS) stable++;
|
||||
}
|
||||
if (stable > connectionLimit) {
|
||||
connectionLimit = stable;
|
||||
if (LOG.isLoggable(INFO)) {
|
||||
LOG.info("Raising connection limit to " + connectionLimit);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static class ConnectionRecord {
|
||||
|
||||
private final DuplexTransportConnection conn;
|
||||
private final long timeOpened;
|
||||
|
||||
private ConnectionRecord(DuplexTransportConnection conn,
|
||||
long timeOpened) {
|
||||
this.conn = conn;
|
||||
this.timeOpened = timeOpened;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,9 +10,7 @@ import org.briarproject.bramble.api.keyagreement.KeyAgreementConnection;
|
||||
import org.briarproject.bramble.api.keyagreement.KeyAgreementListener;
|
||||
import org.briarproject.bramble.api.keyagreement.event.KeyAgreementListeningEvent;
|
||||
import org.briarproject.bramble.api.keyagreement.event.KeyAgreementStoppedListeningEvent;
|
||||
import org.briarproject.bramble.api.lifecycle.IoExecutor;
|
||||
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
||||
import org.briarproject.bramble.api.plugin.Backoff;
|
||||
import org.briarproject.bramble.api.plugin.ConnectionHandler;
|
||||
@@ -39,22 +37,16 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import javax.annotation.concurrent.GuardedBy;
|
||||
import javax.annotation.concurrent.ThreadSafe;
|
||||
|
||||
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.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;
|
||||
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.Plugin.State.STARTING_STOPPING;
|
||||
import static org.briarproject.bramble.util.LogUtils.logException;
|
||||
import static org.briarproject.bramble.util.PrivacyUtils.scrubMacAddress;
|
||||
import static org.briarproject.bramble.util.StringUtils.isNullOrEmpty;
|
||||
@@ -78,9 +70,9 @@ abstract class BluetoothPlugin<SS> implements DuplexPlugin, EventListener {
|
||||
private final int maxLatency, maxIdleTime;
|
||||
private final AtomicBoolean used = new AtomicBoolean(false);
|
||||
|
||||
protected final PluginState state = new PluginState();
|
||||
|
||||
private volatile boolean running = false, contactConnections = false;
|
||||
private volatile String contactConnectionsUuid = null;
|
||||
private volatile SS socket = null;
|
||||
|
||||
abstract void initialiseAdapter() throws IOException;
|
||||
|
||||
@@ -132,18 +124,14 @@ abstract class BluetoothPlugin<SS> implements DuplexPlugin, EventListener {
|
||||
LOG.info("Bluetooth enabled");
|
||||
// We may not have been able to get the local address before
|
||||
ioExecutor.execute(this::updateProperties);
|
||||
if (getState() == INACTIVE) bind();
|
||||
if (shouldAllowContactConnections()) bind();
|
||||
}
|
||||
|
||||
void onAdapterDisabled() {
|
||||
LOG.info("Bluetooth disabled");
|
||||
tryToClose(socket);
|
||||
connectionLimiter.allConnectionsClosed();
|
||||
// The server socket may not have been closed automatically
|
||||
SS ss = state.clearServerSocket();
|
||||
if (ss != null) {
|
||||
LOG.info("Closing server socket");
|
||||
tryToClose(ss);
|
||||
}
|
||||
callback.transportDisabled();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -164,25 +152,31 @@ abstract class BluetoothPlugin<SS> implements DuplexPlugin, EventListener {
|
||||
@Override
|
||||
public void start() throws PluginException {
|
||||
if (used.getAndSet(true)) throw new IllegalStateException();
|
||||
Settings settings = callback.getSettings();
|
||||
boolean enabledByUser = settings.getBoolean(PREF_PLUGIN_ENABLE,
|
||||
DEFAULT_PREF_PLUGIN_ENABLE);
|
||||
state.setStarted(enabledByUser);
|
||||
try {
|
||||
initialiseAdapter();
|
||||
} catch (IOException e) {
|
||||
throw new PluginException(e);
|
||||
}
|
||||
updateProperties();
|
||||
if (enabledByUser) {
|
||||
running = true;
|
||||
loadSettings(callback.getSettings());
|
||||
if (shouldAllowContactConnections()) {
|
||||
if (isAdapterEnabled()) bind();
|
||||
else enableAdapter();
|
||||
}
|
||||
}
|
||||
|
||||
private void loadSettings(Settings settings) {
|
||||
contactConnections = settings.getBoolean(PREF_BT_ENABLE, false);
|
||||
}
|
||||
|
||||
private boolean shouldAllowContactConnections() {
|
||||
return contactConnections;
|
||||
}
|
||||
|
||||
private void bind() {
|
||||
ioExecutor.execute(() -> {
|
||||
if (getState() != INACTIVE) return;
|
||||
if (!isRunning() || !shouldAllowContactConnections()) return;
|
||||
// Bind a server socket to accept connections from contacts
|
||||
SS ss;
|
||||
try {
|
||||
@@ -191,13 +185,14 @@ abstract class BluetoothPlugin<SS> implements DuplexPlugin, EventListener {
|
||||
logException(LOG, WARNING, e);
|
||||
return;
|
||||
}
|
||||
if (!state.setServerSocket(ss)) {
|
||||
LOG.info("Closing redundant server socket");
|
||||
if (!isRunning() || !shouldAllowContactConnections()) {
|
||||
tryToClose(ss);
|
||||
return;
|
||||
}
|
||||
socket = ss;
|
||||
backoff.reset();
|
||||
acceptContactConnections(ss);
|
||||
callback.transportEnabled();
|
||||
acceptContactConnections();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -226,39 +221,35 @@ abstract class BluetoothPlugin<SS> implements DuplexPlugin, EventListener {
|
||||
if (changed) callback.mergeLocalProperties(p);
|
||||
}
|
||||
|
||||
private void acceptContactConnections(SS ss) {
|
||||
private void acceptContactConnections() {
|
||||
while (true) {
|
||||
DuplexTransportConnection conn;
|
||||
try {
|
||||
conn = acceptConnection(ss);
|
||||
conn = acceptConnection(socket);
|
||||
} catch (IOException e) {
|
||||
// This is expected when the server socket is closed
|
||||
LOG.info("Server socket closed");
|
||||
state.clearServerSocket();
|
||||
// This is expected when the socket is closed
|
||||
if (LOG.isLoggable(INFO)) LOG.info(e.toString());
|
||||
return;
|
||||
}
|
||||
LOG.info("Connection received");
|
||||
connectionLimiter.connectionOpened(conn);
|
||||
backoff.reset();
|
||||
callback.handleConnection(conn);
|
||||
if (!running) return;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() {
|
||||
SS ss = state.setStopped();
|
||||
tryToClose(ss);
|
||||
running = false;
|
||||
tryToClose(socket);
|
||||
callback.transportDisabled();
|
||||
disableAdapterIfEnabledByUs();
|
||||
}
|
||||
|
||||
@Override
|
||||
public State getState() {
|
||||
return state.getState();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getReasonsDisabled() {
|
||||
return state.getReasonsDisabled();
|
||||
public boolean isRunning() {
|
||||
return running && isAdapterEnabled();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -274,7 +265,7 @@ abstract class BluetoothPlugin<SS> implements DuplexPlugin, EventListener {
|
||||
@Override
|
||||
public void poll(Collection<Pair<TransportProperties, ConnectionHandler>>
|
||||
properties) {
|
||||
if (getState() != ACTIVE) return;
|
||||
if (!isRunning() || !shouldAllowContactConnections()) return;
|
||||
backoff.increment();
|
||||
for (Pair<TransportProperties, ConnectionHandler> p : properties) {
|
||||
connect(p.getFirst(), p.getSecond());
|
||||
@@ -328,7 +319,7 @@ abstract class BluetoothPlugin<SS> implements DuplexPlugin, EventListener {
|
||||
|
||||
@Override
|
||||
public DuplexTransportConnection createConnection(TransportProperties p) {
|
||||
if (getState() != ACTIVE) return null;
|
||||
if (!isRunning() || !shouldAllowContactConnections()) return null;
|
||||
if (!connectionLimiter.canOpenContactConnection()) return null;
|
||||
String address = p.get(PROP_ADDRESS);
|
||||
if (isNullOrEmpty(address)) return null;
|
||||
@@ -346,7 +337,7 @@ abstract class BluetoothPlugin<SS> implements DuplexPlugin, EventListener {
|
||||
|
||||
@Override
|
||||
public KeyAgreementListener createKeyAgreementListener(byte[] commitment) {
|
||||
if (getState() != ACTIVE) return null;
|
||||
if (!isRunning()) return null;
|
||||
// No truncation necessary because COMMIT_LENGTH = 16
|
||||
String uuid = UUID.nameUUIDFromBytes(commitment).toString();
|
||||
if (LOG.isLoggable(INFO)) LOG.info("Key agreement UUID " + uuid);
|
||||
@@ -358,7 +349,7 @@ abstract class BluetoothPlugin<SS> implements DuplexPlugin, EventListener {
|
||||
logException(LOG, WARNING, e);
|
||||
return null;
|
||||
}
|
||||
if (getState() != ACTIVE) {
|
||||
if (!isRunning()) {
|
||||
tryToClose(ss);
|
||||
return null;
|
||||
}
|
||||
@@ -372,7 +363,7 @@ abstract class BluetoothPlugin<SS> implements DuplexPlugin, EventListener {
|
||||
@Override
|
||||
public DuplexTransportConnection createKeyAgreementConnection(
|
||||
byte[] commitment, BdfList descriptor) {
|
||||
if (getState() != ACTIVE) return null;
|
||||
if (!isRunning()) return null;
|
||||
// No truncation necessary because COMMIT_LENGTH = 16
|
||||
String uuid = UUID.nameUUIDFromBytes(commitment).toString();
|
||||
DuplexTransportConnection conn;
|
||||
@@ -432,18 +423,17 @@ abstract class BluetoothPlugin<SS> implements DuplexPlugin, EventListener {
|
||||
}
|
||||
}
|
||||
|
||||
@IoExecutor
|
||||
private void onSettingsUpdated(Settings settings) {
|
||||
boolean enabledByUser = settings.getBoolean(PREF_PLUGIN_ENABLE,
|
||||
DEFAULT_PREF_PLUGIN_ENABLE);
|
||||
SS ss = state.setEnabledByUser(enabledByUser);
|
||||
State s = getState();
|
||||
if (ss != null) {
|
||||
LOG.info("Disabled by user, closing server socket");
|
||||
tryToClose(ss);
|
||||
boolean wasAllowed = shouldAllowContactConnections();
|
||||
loadSettings(settings);
|
||||
boolean isAllowed = shouldAllowContactConnections();
|
||||
if (wasAllowed && !isAllowed) {
|
||||
LOG.info("Contact connections disabled");
|
||||
tryToClose(socket);
|
||||
callback.transportDisabled();
|
||||
disableAdapterIfEnabledByUs();
|
||||
} else if (s == INACTIVE) {
|
||||
LOG.info("Enabled by user, opening server socket");
|
||||
} else if (!wasAllowed && isAllowed) {
|
||||
LOG.info("Contact connections enabled");
|
||||
if (isAdapterEnabled()) bind();
|
||||
else enableAdapter();
|
||||
}
|
||||
@@ -471,70 +461,4 @@ abstract class BluetoothPlugin<SS> implements DuplexPlugin, EventListener {
|
||||
tryToClose(ss);
|
||||
}
|
||||
}
|
||||
|
||||
@ThreadSafe
|
||||
@NotNullByDefault
|
||||
protected class PluginState {
|
||||
|
||||
@GuardedBy("this")
|
||||
private boolean started = false,
|
||||
stopped = false,
|
||||
enabledByUser = false;
|
||||
|
||||
@GuardedBy("this")
|
||||
@Nullable
|
||||
private SS serverSocket = null;
|
||||
|
||||
synchronized void setStarted(boolean enabledByUser) {
|
||||
started = true;
|
||||
this.enabledByUser = enabledByUser;
|
||||
callback.pluginStateChanged(getState());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
synchronized SS setStopped() {
|
||||
stopped = true;
|
||||
SS ss = serverSocket;
|
||||
serverSocket = null;
|
||||
callback.pluginStateChanged(getState());
|
||||
return ss;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
synchronized SS setEnabledByUser(boolean enabledByUser) {
|
||||
this.enabledByUser = enabledByUser;
|
||||
SS ss = null;
|
||||
if (!enabledByUser) {
|
||||
ss = serverSocket;
|
||||
serverSocket = null;
|
||||
}
|
||||
callback.pluginStateChanged(getState());
|
||||
return ss;
|
||||
}
|
||||
|
||||
synchronized boolean setServerSocket(SS ss) {
|
||||
if (stopped || serverSocket != null) return false;
|
||||
serverSocket = ss;
|
||||
callback.pluginStateChanged(getState());
|
||||
return true;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
synchronized SS clearServerSocket() {
|
||||
SS ss = serverSocket;
|
||||
serverSocket = null;
|
||||
callback.pluginStateChanged(getState());
|
||||
return ss;
|
||||
}
|
||||
|
||||
synchronized State getState() {
|
||||
if (!started || stopped) return STARTING_STOPPING;
|
||||
if (!enabledByUser) return DISABLED;
|
||||
return serverSocket == null ? INACTIVE : ACTIVE;
|
||||
}
|
||||
|
||||
synchronized int getReasonsDisabled() {
|
||||
return getState() == DISABLED ? REASON_USER : 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,6 @@ import java.util.logging.Logger;
|
||||
import static java.util.logging.Level.WARNING;
|
||||
import static java.util.logging.Logger.getLogger;
|
||||
import static org.briarproject.bramble.api.plugin.FileConstants.PROP_PATH;
|
||||
import static org.briarproject.bramble.api.plugin.Plugin.State.ACTIVE;
|
||||
import static org.briarproject.bramble.util.LogUtils.logException;
|
||||
import static org.briarproject.bramble.util.StringUtils.isNullOrEmpty;
|
||||
|
||||
@@ -46,7 +45,7 @@ abstract class FilePlugin implements SimplexPlugin {
|
||||
|
||||
@Override
|
||||
public TransportConnectionReader createReader(TransportProperties p) {
|
||||
if (getState() != ACTIVE) return null;
|
||||
if (!isRunning()) return null;
|
||||
String path = p.get(PROP_PATH);
|
||||
if (isNullOrEmpty(path)) return null;
|
||||
try {
|
||||
@@ -61,7 +60,7 @@ abstract class FilePlugin implements SimplexPlugin {
|
||||
|
||||
@Override
|
||||
public TransportConnectionWriter createWriter(TransportProperties p) {
|
||||
if (getState() != ACTIVE) return null;
|
||||
if (!isRunning()) return null;
|
||||
String path = p.get(PROP_PATH);
|
||||
if (isNullOrEmpty(path)) return null;
|
||||
try {
|
||||
|
||||
@@ -11,10 +11,10 @@ import org.briarproject.bramble.api.plugin.TransportId;
|
||||
import org.briarproject.bramble.api.plugin.duplex.DuplexTransportConnection;
|
||||
import org.briarproject.bramble.api.properties.TransportProperties;
|
||||
import org.briarproject.bramble.api.settings.Settings;
|
||||
import org.briarproject.bramble.util.IoUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.Inet4Address;
|
||||
import java.net.Inet6Address;
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.InterfaceAddress;
|
||||
@@ -22,9 +22,8 @@ import java.net.ServerSocket;
|
||||
import java.net.Socket;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Deque;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
@@ -32,49 +31,38 @@ import javax.annotation.Nullable;
|
||||
|
||||
import static java.lang.Integer.parseInt;
|
||||
import static java.util.Collections.addAll;
|
||||
import static java.util.Collections.emptyList;
|
||||
import static java.util.Collections.sort;
|
||||
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;
|
||||
import static org.briarproject.bramble.api.plugin.LanTcpConstants.PROP_IPV6;
|
||||
import static org.briarproject.bramble.api.plugin.LanTcpConstants.PROP_IP_PORTS;
|
||||
import static org.briarproject.bramble.api.plugin.LanTcpConstants.PROP_PORT;
|
||||
import static org.briarproject.bramble.api.properties.TransportPropertyConstants.MAX_PROPERTY_LENGTH;
|
||||
import static org.briarproject.bramble.util.ByteUtils.MAX_16_BIT_UNSIGNED;
|
||||
import static org.briarproject.bramble.util.IoUtils.tryToClose;
|
||||
import static org.briarproject.bramble.util.PrivacyUtils.scrubSocketAddress;
|
||||
import static org.briarproject.bramble.util.StringUtils.fromHexString;
|
||||
import static org.briarproject.bramble.util.StringUtils.isNullOrEmpty;
|
||||
import static org.briarproject.bramble.util.StringUtils.join;
|
||||
import static org.briarproject.bramble.util.StringUtils.toHexString;
|
||||
import static org.briarproject.bramble.util.StringUtils.utf8IsTooLong;
|
||||
|
||||
@NotNullByDefault
|
||||
class LanTcpPlugin extends TcpPlugin {
|
||||
|
||||
private static final Logger LOG = getLogger(LanTcpPlugin.class.getName());
|
||||
|
||||
private static final int MAX_ADDRESSES = 4;
|
||||
private static final String SEPARATOR = ",";
|
||||
|
||||
/**
|
||||
* The IP address of an Android device providing a wifi access point.
|
||||
* <p>
|
||||
* Most devices use this address, but at least one device (Honor 8A) may
|
||||
* use other addresses in the range 192.168.43.0/24.
|
||||
*/
|
||||
private static final InetAddress WIFI_AP_ADDRESS;
|
||||
protected static final InetAddress WIFI_AP_ADDRESS;
|
||||
|
||||
/**
|
||||
* The IP address of an Android device providing a wifi direct
|
||||
* legacy mode access point.
|
||||
*/
|
||||
private static final InetAddress WIFI_DIRECT_AP_ADDRESS;
|
||||
protected static final InetAddress WIFI_DIRECT_AP_ADDRESS;
|
||||
|
||||
static {
|
||||
try {
|
||||
@@ -103,36 +91,29 @@ class LanTcpPlugin extends TcpPlugin {
|
||||
public void start() {
|
||||
if (used.getAndSet(true)) throw new IllegalStateException();
|
||||
initialisePortProperty();
|
||||
Settings settings = callback.getSettings();
|
||||
state.setStarted(settings.getBoolean(PREF_PLUGIN_ENABLE,
|
||||
DEFAULT_PREF_PLUGIN_ENABLE));
|
||||
running = true;
|
||||
bind();
|
||||
}
|
||||
|
||||
protected void initialisePortProperty() {
|
||||
TransportProperties p = callback.getLocalProperties();
|
||||
if (isNullOrEmpty(p.get(PROP_PORT))) {
|
||||
int port = chooseEphemeralPort();
|
||||
int port = new Random().nextInt(32768) + 32768;
|
||||
p.put(PROP_PORT, String.valueOf(port));
|
||||
callback.mergeLocalProperties(p);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isEnabledByDefault() {
|
||||
return DEFAULT_PREF_PLUGIN_ENABLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<InetSocketAddress> getLocalSocketAddresses(boolean ipv4) {
|
||||
protected List<InetSocketAddress> getLocalSocketAddresses() {
|
||||
TransportProperties p = callback.getLocalProperties();
|
||||
int preferredPort = parsePortProperty(p.get(PROP_PORT));
|
||||
String oldIpPorts = p.get(PROP_IP_PORTS);
|
||||
List<InetSocketAddress> olds = parseIpv4SocketAddresses(oldIpPorts);
|
||||
List<InetSocketAddress> olds = parseSocketAddresses(oldIpPorts);
|
||||
|
||||
List<InetSocketAddress> locals = new ArrayList<>();
|
||||
List<InetSocketAddress> fallbacks = new ArrayList<>();
|
||||
for (InetAddress local : getUsableLocalInetAddresses(ipv4)) {
|
||||
for (InetAddress local : getUsableLocalInetAddresses()) {
|
||||
// If we've used this address before, try to use the same port
|
||||
int port = preferredPort;
|
||||
for (InetSocketAddress old : olds) {
|
||||
@@ -158,17 +139,17 @@ class LanTcpPlugin extends TcpPlugin {
|
||||
}
|
||||
}
|
||||
|
||||
private List<InetSocketAddress> parseIpv4SocketAddresses(String ipPorts) {
|
||||
private List<InetSocketAddress> parseSocketAddresses(String ipPorts) {
|
||||
List<InetSocketAddress> addresses = new ArrayList<>();
|
||||
if (isNullOrEmpty(ipPorts)) return addresses;
|
||||
for (String ipPort : ipPorts.split(SEPARATOR)) {
|
||||
InetSocketAddress a = parseIpv4SocketAddress(ipPort);
|
||||
InetSocketAddress a = parseSocketAddress(ipPort);
|
||||
if (a != null) addresses.add(a);
|
||||
}
|
||||
return addresses;
|
||||
}
|
||||
|
||||
protected List<InetAddress> getUsableLocalInetAddresses(boolean ipv4) {
|
||||
protected List<InetAddress> getUsableLocalInetAddresses() {
|
||||
List<InterfaceAddress> ifAddrs =
|
||||
new ArrayList<>(getLocalInterfaceAddresses());
|
||||
// Prefer longer network prefixes
|
||||
@@ -177,74 +158,50 @@ class LanTcpPlugin extends TcpPlugin {
|
||||
List<InetAddress> addrs = new ArrayList<>();
|
||||
for (InterfaceAddress ifAddr : ifAddrs) {
|
||||
InetAddress addr = ifAddr.getAddress();
|
||||
if (isAcceptableAddress(addr, ipv4)) addrs.add(addr);
|
||||
if (isAcceptableAddress(addr)) addrs.add(addr);
|
||||
}
|
||||
return addrs;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setLocalSocketAddress(InetSocketAddress a, boolean ipv4) {
|
||||
if (ipv4) setLocalIpv4SocketAddress(a);
|
||||
else setLocalIpv6SocketAddress(a);
|
||||
}
|
||||
|
||||
private void setLocalIpv4SocketAddress(InetSocketAddress a) {
|
||||
protected void setLocalSocketAddress(InetSocketAddress a) {
|
||||
String ipPort = getIpPortString(a);
|
||||
updateRecentAddresses(PREF_LAN_IP_PORTS, PROP_IP_PORTS, ipPort);
|
||||
}
|
||||
|
||||
private void setLocalIpv6SocketAddress(InetSocketAddress a) {
|
||||
String hex = toHexString(a.getAddress().getAddress());
|
||||
updateRecentAddresses(PREF_IPV6, PROP_IPV6, hex);
|
||||
}
|
||||
|
||||
private void updateRecentAddresses(String settingKey, String propertyKey,
|
||||
String item) {
|
||||
// Get the list of recently used addresses
|
||||
String setting = callback.getSettings().get(settingKey);
|
||||
Deque<String> recent = new LinkedList<>();
|
||||
if (!isNullOrEmpty(setting)) {
|
||||
String setting = callback.getSettings().get(PREF_LAN_IP_PORTS);
|
||||
List<String> recent = new ArrayList<>();
|
||||
if (!isNullOrEmpty(setting))
|
||||
addAll(recent, setting.split(SEPARATOR));
|
||||
}
|
||||
if (recent.remove(item)) {
|
||||
// Move the item to the start of the list
|
||||
recent.addFirst(item);
|
||||
// Is the address already in the list?
|
||||
if (recent.remove(ipPort)) {
|
||||
// Move the address to the start of the list
|
||||
recent.add(0, ipPort);
|
||||
setting = join(recent, SEPARATOR);
|
||||
} else {
|
||||
// Add the item to the start of the list
|
||||
recent.addFirst(item);
|
||||
// Drop items from the end of the list if it's too long to encode
|
||||
// Add the address to the start of the list
|
||||
recent.add(0, ipPort);
|
||||
// Drop the least recently used address if the list is full
|
||||
if (recent.size() > MAX_ADDRESSES)
|
||||
recent = recent.subList(0, MAX_ADDRESSES);
|
||||
setting = join(recent, SEPARATOR);
|
||||
while (utf8IsTooLong(setting, MAX_PROPERTY_LENGTH)) {
|
||||
recent.removeLast();
|
||||
setting = join(recent, SEPARATOR);
|
||||
}
|
||||
// Update the list of addresses shared with contacts
|
||||
List<String> shared = new ArrayList<>(recent);
|
||||
sort(shared);
|
||||
String property = join(shared, SEPARATOR);
|
||||
TransportProperties properties = new TransportProperties();
|
||||
properties.put(propertyKey, setting);
|
||||
properties.put(PROP_IP_PORTS, property);
|
||||
callback.mergeLocalProperties(properties);
|
||||
}
|
||||
// Save the setting
|
||||
Settings settings = new Settings();
|
||||
settings.put(settingKey, setting);
|
||||
settings.put(PREF_LAN_IP_PORTS, setting);
|
||||
callback.mergeSettings(settings);
|
||||
}
|
||||
|
||||
protected boolean isIpv6LinkLocalAddress(InetAddress a) {
|
||||
return a instanceof Inet6Address && a.isLinkLocalAddress();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<InetSocketAddress> getRemoteSocketAddresses(
|
||||
TransportProperties p, boolean ipv4) {
|
||||
if (ipv4) return getRemoteIpv4SocketAddresses(p);
|
||||
else return getRemoteIpv6SocketAddresses(p);
|
||||
}
|
||||
|
||||
private List<InetSocketAddress> getRemoteIpv4SocketAddresses(
|
||||
TransportProperties p) {
|
||||
String ipPorts = p.get(PROP_IP_PORTS);
|
||||
List<InetSocketAddress> remotes = parseIpv4SocketAddresses(ipPorts);
|
||||
List<InetSocketAddress> remotes = parseSocketAddresses(ipPorts);
|
||||
int port = parsePortProperty(p.get(PROP_PORT));
|
||||
// If the contact has a preferred port, we can guess their IP:port when
|
||||
// they're providing a wifi access point
|
||||
@@ -259,52 +216,20 @@ class LanTcpPlugin extends TcpPlugin {
|
||||
return remotes;
|
||||
}
|
||||
|
||||
private List<InetSocketAddress> getRemoteIpv6SocketAddresses(
|
||||
TransportProperties p) {
|
||||
List<InetAddress> addrs = parseIpv6Addresses(p.get(PROP_IPV6));
|
||||
int port = parsePortProperty(p.get(PROP_PORT));
|
||||
if (addrs.isEmpty() || port == 0) return emptyList();
|
||||
List<InetSocketAddress> remotes = new ArrayList<>();
|
||||
for (InetAddress addr : addrs) {
|
||||
remotes.add(new InetSocketAddress(addr, port));
|
||||
}
|
||||
return remotes;
|
||||
}
|
||||
|
||||
private List<InetAddress> parseIpv6Addresses(String property) {
|
||||
if (isNullOrEmpty(property)) return emptyList();
|
||||
try {
|
||||
List<InetAddress> addrs = new ArrayList<>();
|
||||
for (String hex : property.split(SEPARATOR)) {
|
||||
byte[] ip = fromHexString(hex);
|
||||
if (ip.length == 16) addrs.add(InetAddress.getByAddress(ip));
|
||||
}
|
||||
return addrs;
|
||||
} catch (IllegalArgumentException | UnknownHostException e) {
|
||||
return emptyList();
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isAcceptableAddress(InetAddress a, boolean ipv4) {
|
||||
if (ipv4) {
|
||||
// Accept link-local and site-local IPv4 addresses
|
||||
boolean isIpv4 = a instanceof Inet4Address;
|
||||
boolean link = a.isLinkLocalAddress();
|
||||
boolean site = a.isSiteLocalAddress();
|
||||
return isIpv4 && (link || site);
|
||||
} else {
|
||||
// Accept link-local IPv6 addresses
|
||||
return isIpv6LinkLocalAddress(a);
|
||||
}
|
||||
private boolean isAcceptableAddress(InetAddress a) {
|
||||
// Accept link-local and site-local IPv4 addresses
|
||||
boolean ipv4 = a instanceof Inet4Address;
|
||||
boolean loop = a.isLoopbackAddress();
|
||||
boolean link = a.isLinkLocalAddress();
|
||||
boolean site = a.isSiteLocalAddress();
|
||||
return ipv4 && !loop && (link || site);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isConnectable(InterfaceAddress local,
|
||||
InetSocketAddress remote) {
|
||||
if (remote.getPort() == 0) return false;
|
||||
InetAddress remoteAddress = remote.getAddress();
|
||||
boolean ipv4 = local.getAddress() instanceof Inet4Address;
|
||||
if (!isAcceptableAddress(remoteAddress, ipv4)) return false;
|
||||
if (!isAcceptableAddress(remote.getAddress())) return false;
|
||||
// Try to determine whether the address is on the same LAN as us
|
||||
byte[] localIp = local.getAddress().getAddress();
|
||||
byte[] remoteIp = remote.getAddress().getAddress();
|
||||
@@ -346,7 +271,7 @@ class LanTcpPlugin extends TcpPlugin {
|
||||
} catch (IOException e) {
|
||||
if (LOG.isLoggable(INFO))
|
||||
LOG.info("Failed to bind " + scrubSocketAddress(addr));
|
||||
tryToClose(ss, LOG, WARNING);
|
||||
tryToClose(ss);
|
||||
}
|
||||
}
|
||||
if (ss == null || !ss.isBound()) {
|
||||
@@ -362,18 +287,11 @@ class LanTcpPlugin extends TcpPlugin {
|
||||
return new LanKeyAgreementListener(descriptor, ss);
|
||||
}
|
||||
|
||||
private List<InetSocketAddress> getLocalSocketAddresses() {
|
||||
List<InetSocketAddress> addrs = new ArrayList<>();
|
||||
addrs.addAll(getLocalSocketAddresses(true));
|
||||
addrs.addAll(getLocalSocketAddresses(false));
|
||||
return addrs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DuplexTransportConnection createKeyAgreementConnection(
|
||||
byte[] commitment, BdfList descriptor) {
|
||||
ServerSocket ss = state.getServerSocket(true);
|
||||
if (ss == null) return null;
|
||||
if (!isRunning()) return null;
|
||||
ServerSocket ss = socket;
|
||||
InterfaceAddress local = getLocalInterfaceAddress(ss.getInetAddress());
|
||||
if (local == null) {
|
||||
LOG.warning("No interface for key agreement server socket");
|
||||
@@ -445,7 +363,7 @@ class LanTcpPlugin extends TcpPlugin {
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
tryToClose(ss, LOG, WARNING);
|
||||
IoUtils.tryToClose(ss, LOG, WARNING);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package org.briarproject.bramble.plugin.tcp;
|
||||
|
||||
import org.briarproject.bramble.api.event.EventBus;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.plugin.Backoff;
|
||||
import org.briarproject.bramble.api.plugin.BackoffFactory;
|
||||
@@ -27,13 +26,11 @@ public class LanTcpPluginFactory implements DuplexPluginFactory {
|
||||
private static final double BACKOFF_BASE = 1.2;
|
||||
|
||||
private final Executor ioExecutor;
|
||||
private final EventBus eventBus;
|
||||
private final BackoffFactory backoffFactory;
|
||||
|
||||
public LanTcpPluginFactory(Executor ioExecutor, EventBus eventBus,
|
||||
public LanTcpPluginFactory(Executor ioExecutor,
|
||||
BackoffFactory backoffFactory) {
|
||||
this.ioExecutor = ioExecutor;
|
||||
this.eventBus = eventBus;
|
||||
this.backoffFactory = backoffFactory;
|
||||
}
|
||||
|
||||
@@ -51,9 +48,7 @@ public class LanTcpPluginFactory implements DuplexPluginFactory {
|
||||
public DuplexPlugin createPlugin(PluginCallback callback) {
|
||||
Backoff backoff = backoffFactory.createBackoff(MIN_POLLING_INTERVAL,
|
||||
MAX_POLLING_INTERVAL, BACKOFF_BASE);
|
||||
LanTcpPlugin plugin = new LanTcpPlugin(ioExecutor, backoff, callback, MAX_LATENCY,
|
||||
return new LanTcpPlugin(ioExecutor, backoff, callback, MAX_LATENCY,
|
||||
MAX_IDLE_TIME, CONNECTION_TIMEOUT);
|
||||
eventBus.addListener(plugin);
|
||||
return plugin;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,13 +54,11 @@ class PortMapperImpl implements PortMapper {
|
||||
shutdownManager.addShutdownHook(() -> deleteMapping(port));
|
||||
}
|
||||
String externalString = gateway.getExternalIPAddress();
|
||||
if (externalString == null) {
|
||||
LOG.info("External address not available");
|
||||
} else {
|
||||
if (LOG.isLoggable(INFO))
|
||||
LOG.info(
|
||||
"External address " + scrubInetAddress(externalString));
|
||||
if (externalString != null)
|
||||
external = InetAddress.getByName(externalString);
|
||||
if (LOG.isLoggable(INFO))
|
||||
LOG.info("External address " + scrubInetAddress(external));
|
||||
}
|
||||
} catch (IOException | SAXException e) {
|
||||
logException(LOG, WARNING, e);
|
||||
}
|
||||
|
||||
@@ -3,12 +3,8 @@ package org.briarproject.bramble.plugin.tcp;
|
||||
import org.briarproject.bramble.PoliteExecutor;
|
||||
import org.briarproject.bramble.api.Pair;
|
||||
import org.briarproject.bramble.api.data.BdfList;
|
||||
import org.briarproject.bramble.api.event.Event;
|
||||
import org.briarproject.bramble.api.event.EventListener;
|
||||
import org.briarproject.bramble.api.keyagreement.KeyAgreementListener;
|
||||
import org.briarproject.bramble.api.lifecycle.IoExecutor;
|
||||
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
||||
import org.briarproject.bramble.api.plugin.Backoff;
|
||||
import org.briarproject.bramble.api.plugin.ConnectionHandler;
|
||||
@@ -18,8 +14,7 @@ import org.briarproject.bramble.api.plugin.duplex.DuplexTransportConnection;
|
||||
import org.briarproject.bramble.api.properties.TransportProperties;
|
||||
import org.briarproject.bramble.api.rendezvous.KeyMaterialSource;
|
||||
import org.briarproject.bramble.api.rendezvous.RendezvousEndpoint;
|
||||
import org.briarproject.bramble.api.settings.Settings;
|
||||
import org.briarproject.bramble.api.settings.event.SettingsUpdatedEvent;
|
||||
import org.briarproject.bramble.util.IoUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetAddress;
|
||||
@@ -40,26 +35,19 @@ import java.util.logging.Logger;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import javax.annotation.concurrent.GuardedBy;
|
||||
import javax.annotation.concurrent.ThreadSafe;
|
||||
|
||||
import static java.util.Collections.emptyList;
|
||||
import static java.util.Collections.list;
|
||||
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.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.Plugin.State.STARTING_STOPPING;
|
||||
import static org.briarproject.bramble.util.IoUtils.tryToClose;
|
||||
import static org.briarproject.bramble.util.LogUtils.logException;
|
||||
import static org.briarproject.bramble.util.PrivacyUtils.scrubSocketAddress;
|
||||
import static org.briarproject.bramble.util.StringUtils.isNullOrEmpty;
|
||||
|
||||
@MethodsNotNullByDefault
|
||||
@ParametersNotNullByDefault
|
||||
abstract class TcpPlugin implements DuplexPlugin, EventListener {
|
||||
abstract class TcpPlugin implements DuplexPlugin {
|
||||
|
||||
private static final Logger LOG = getLogger(TcpPlugin.class.getName());
|
||||
|
||||
@@ -72,28 +60,28 @@ abstract class TcpPlugin implements DuplexPlugin, EventListener {
|
||||
protected final int maxLatency, maxIdleTime;
|
||||
protected final int connectionTimeout, socketTimeout;
|
||||
protected final AtomicBoolean used = new AtomicBoolean(false);
|
||||
protected final PluginState state = new PluginState();
|
||||
|
||||
protected volatile boolean running = false;
|
||||
protected volatile ServerSocket socket = null;
|
||||
|
||||
/**
|
||||
* Returns zero or more socket addresses on which the plugin should listen,
|
||||
* in order of preference. At most one of the addresses will be bound.
|
||||
*/
|
||||
protected abstract List<InetSocketAddress> getLocalSocketAddresses(
|
||||
boolean ipv4);
|
||||
protected abstract List<InetSocketAddress> getLocalSocketAddresses();
|
||||
|
||||
/**
|
||||
* Adds the address on which the plugin is listening to the transport
|
||||
* properties.
|
||||
*/
|
||||
protected abstract void setLocalSocketAddress(InetSocketAddress a,
|
||||
boolean ipv4);
|
||||
protected abstract void setLocalSocketAddress(InetSocketAddress a);
|
||||
|
||||
/**
|
||||
* Returns zero or more socket addresses for connecting to a contact with
|
||||
* the given transport properties.
|
||||
*/
|
||||
protected abstract List<InetSocketAddress> getRemoteSocketAddresses(
|
||||
TransportProperties p, boolean ipv4);
|
||||
TransportProperties p);
|
||||
|
||||
/**
|
||||
* Returns true if connections to the given address can be attempted.
|
||||
@@ -102,11 +90,6 @@ 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;
|
||||
@@ -135,50 +118,49 @@ abstract class TcpPlugin implements DuplexPlugin, EventListener {
|
||||
@Override
|
||||
public void start() {
|
||||
if (used.getAndSet(true)) throw new IllegalStateException();
|
||||
Settings settings = callback.getSettings();
|
||||
state.setStarted(
|
||||
settings.getBoolean(PREF_PLUGIN_ENABLE, isEnabledByDefault()));
|
||||
running = true;
|
||||
bind();
|
||||
}
|
||||
|
||||
protected void bind() {
|
||||
bindExecutor.execute(() -> {
|
||||
if (getState() != INACTIVE) return;
|
||||
bind(true);
|
||||
bind(false);
|
||||
if (!running) return;
|
||||
if (socket != null && !socket.isClosed()) return;
|
||||
ServerSocket ss = null;
|
||||
for (InetSocketAddress addr : getLocalSocketAddresses()) {
|
||||
try {
|
||||
ss = new ServerSocket();
|
||||
ss.bind(addr);
|
||||
break;
|
||||
} catch (IOException e) {
|
||||
if (LOG.isLoggable(INFO))
|
||||
LOG.info("Failed to bind " + scrubSocketAddress(addr));
|
||||
tryToClose(ss);
|
||||
}
|
||||
}
|
||||
if (ss == null || !ss.isBound()) {
|
||||
LOG.info("Could not bind server socket");
|
||||
return;
|
||||
}
|
||||
if (!running) {
|
||||
tryToClose(ss);
|
||||
return;
|
||||
}
|
||||
socket = ss;
|
||||
backoff.reset();
|
||||
InetSocketAddress local =
|
||||
(InetSocketAddress) ss.getLocalSocketAddress();
|
||||
setLocalSocketAddress(local);
|
||||
if (LOG.isLoggable(INFO))
|
||||
LOG.info("Listening on " + scrubSocketAddress(local));
|
||||
callback.transportEnabled();
|
||||
acceptContactConnections();
|
||||
});
|
||||
}
|
||||
|
||||
private void bind(boolean ipv4) {
|
||||
ServerSocket ss = null;
|
||||
for (InetSocketAddress addr : getLocalSocketAddresses(ipv4)) {
|
||||
try {
|
||||
ss = new ServerSocket();
|
||||
ss.bind(addr);
|
||||
break;
|
||||
} catch (IOException e) {
|
||||
if (LOG.isLoggable(INFO))
|
||||
LOG.info("Failed to bind " + scrubSocketAddress(addr));
|
||||
tryToClose(ss, LOG, WARNING);
|
||||
}
|
||||
}
|
||||
if (ss == null || !ss.isBound()) {
|
||||
LOG.info("Could not bind server socket");
|
||||
return;
|
||||
}
|
||||
if (!state.setServerSocket(ss, ipv4)) {
|
||||
LOG.info("Closing redundant server socket");
|
||||
tryToClose(ss, LOG, WARNING);
|
||||
return;
|
||||
}
|
||||
backoff.reset();
|
||||
InetSocketAddress local =
|
||||
(InetSocketAddress) ss.getLocalSocketAddress();
|
||||
setLocalSocketAddress(local, ipv4);
|
||||
if (LOG.isLoggable(INFO))
|
||||
LOG.info("Listening on " + scrubSocketAddress(local));
|
||||
ServerSocket finalSocket = ss;
|
||||
ioExecutor.execute(() -> acceptContactConnections(finalSocket, ipv4));
|
||||
protected void tryToClose(@Nullable ServerSocket ss) {
|
||||
IoUtils.tryToClose(ss, LOG, WARNING);
|
||||
callback.transportDisabled();
|
||||
}
|
||||
|
||||
String getIpPortString(InetSocketAddress a) {
|
||||
@@ -188,22 +170,20 @@ abstract class TcpPlugin implements DuplexPlugin, EventListener {
|
||||
return addr + ":" + a.getPort();
|
||||
}
|
||||
|
||||
private void acceptContactConnections(ServerSocket ss, boolean ipv4) {
|
||||
while (true) {
|
||||
private void acceptContactConnections() {
|
||||
while (isRunning()) {
|
||||
Socket s;
|
||||
try {
|
||||
s = ss.accept();
|
||||
s = socket.accept();
|
||||
s.setSoTimeout(socketTimeout);
|
||||
} catch (IOException e) {
|
||||
// This is expected when the server socket is closed
|
||||
LOG.info("Server socket closed");
|
||||
state.clearServerSocket(ss, ipv4);
|
||||
// This is expected when the socket is closed
|
||||
if (LOG.isLoggable(INFO)) LOG.info(e.toString());
|
||||
return;
|
||||
}
|
||||
if (LOG.isLoggable(INFO)) {
|
||||
if (LOG.isLoggable(INFO))
|
||||
LOG.info("Connection from " +
|
||||
scrubSocketAddress(s.getRemoteSocketAddress()));
|
||||
}
|
||||
backoff.reset();
|
||||
callback.handleConnection(new TcpTransportConnection(this, s));
|
||||
}
|
||||
@@ -211,17 +191,13 @@ abstract class TcpPlugin implements DuplexPlugin, EventListener {
|
||||
|
||||
@Override
|
||||
public void stop() {
|
||||
for (ServerSocket ss : state.setStopped()) tryToClose(ss, LOG, WARNING);
|
||||
running = false;
|
||||
tryToClose(socket);
|
||||
}
|
||||
|
||||
@Override
|
||||
public State getState() {
|
||||
return state.getState();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getReasonsDisabled() {
|
||||
return state.getReasonsDisabled();
|
||||
public boolean isRunning() {
|
||||
return running && socket != null && !socket.isClosed();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -237,7 +213,7 @@ abstract class TcpPlugin implements DuplexPlugin, EventListener {
|
||||
@Override
|
||||
public void poll(Collection<Pair<TransportProperties, ConnectionHandler>>
|
||||
properties) {
|
||||
if (getState() != ACTIVE) return;
|
||||
if (!isRunning()) return;
|
||||
backoff.increment();
|
||||
for (Pair<TransportProperties, ConnectionHandler> p : properties) {
|
||||
connect(p.getFirst(), p.getSecond());
|
||||
@@ -256,22 +232,14 @@ abstract class TcpPlugin implements DuplexPlugin, EventListener {
|
||||
|
||||
@Override
|
||||
public DuplexTransportConnection createConnection(TransportProperties p) {
|
||||
DuplexTransportConnection c = createConnection(p, true);
|
||||
if (c != null) return c;
|
||||
return createConnection(p, false);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private DuplexTransportConnection createConnection(TransportProperties p,
|
||||
boolean ipv4) {
|
||||
ServerSocket ss = state.getServerSocket(ipv4);
|
||||
if (ss == null) return null;
|
||||
if (!isRunning()) return null;
|
||||
ServerSocket ss = socket;
|
||||
InterfaceAddress local = getLocalInterfaceAddress(ss.getInetAddress());
|
||||
if (local == null) {
|
||||
LOG.warning("No interface for server socket");
|
||||
return null;
|
||||
}
|
||||
for (InetSocketAddress remote : getRemoteSocketAddresses(p, ipv4)) {
|
||||
for (InetSocketAddress remote : getRemoteSocketAddresses(p)) {
|
||||
// Don't try to connect to our own address
|
||||
if (!canConnectToOwnAddress() &&
|
||||
remote.getAddress().equals(ss.getInetAddress())) {
|
||||
@@ -296,10 +264,9 @@ abstract class TcpPlugin implements DuplexPlugin, EventListener {
|
||||
LOG.info("Connected to " + scrubSocketAddress(remote));
|
||||
return new TcpTransportConnection(this, s);
|
||||
} catch (IOException e) {
|
||||
if (LOG.isLoggable(INFO)) {
|
||||
if (LOG.isLoggable(INFO))
|
||||
LOG.info("Could not connect to " +
|
||||
scrubSocketAddress(remote));
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
@@ -322,12 +289,8 @@ abstract class TcpPlugin implements DuplexPlugin, EventListener {
|
||||
return new Socket();
|
||||
}
|
||||
|
||||
int chooseEphemeralPort() {
|
||||
return 32768 + (int) (Math.random() * 32768);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
InetSocketAddress parseIpv4SocketAddress(String ipPort) {
|
||||
InetSocketAddress parseSocketAddress(String ipPort) {
|
||||
if (isNullOrEmpty(ipPort)) return null;
|
||||
String[] split = ipPort.split(":");
|
||||
if (split.length != 2) return null;
|
||||
@@ -338,7 +301,14 @@ abstract class TcpPlugin implements DuplexPlugin, EventListener {
|
||||
InetAddress a = InetAddress.getByName(addr);
|
||||
int p = Integer.parseInt(port);
|
||||
return new InetSocketAddress(a, p);
|
||||
} catch (UnknownHostException | NumberFormatException e) {
|
||||
} catch (UnknownHostException e) {
|
||||
if (LOG.isLoggable(WARNING))
|
||||
// not scrubbing to enable us to find the problem
|
||||
LOG.warning("Invalid address: " + addr);
|
||||
return null;
|
||||
} catch (NumberFormatException e) {
|
||||
if (LOG.isLoggable(WARNING))
|
||||
LOG.warning("Invalid port: " + port);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -396,114 +366,4 @@ abstract class TcpPlugin implements DuplexPlugin, EventListener {
|
||||
return emptyList();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void eventOccurred(Event e) {
|
||||
if (e instanceof SettingsUpdatedEvent) {
|
||||
SettingsUpdatedEvent s = (SettingsUpdatedEvent) e;
|
||||
if (s.getNamespace().equals(getId().getString()))
|
||||
ioExecutor.execute(() -> onSettingsUpdated(s.getSettings()));
|
||||
}
|
||||
}
|
||||
|
||||
@IoExecutor
|
||||
private void onSettingsUpdated(Settings settings) {
|
||||
boolean enabledByUser =
|
||||
settings.getBoolean(PREF_PLUGIN_ENABLE, isEnabledByDefault());
|
||||
List<ServerSocket> toClose = state.setEnabledByUser(enabledByUser);
|
||||
State s = getState();
|
||||
if (!toClose.isEmpty()) {
|
||||
LOG.info("Disabled by user, closing server sockets");
|
||||
for (ServerSocket ss : toClose) tryToClose(ss, LOG, WARNING);
|
||||
} else if (s == INACTIVE) {
|
||||
LOG.info("Enabled by user, opening server sockets");
|
||||
bind();
|
||||
}
|
||||
}
|
||||
|
||||
@ThreadSafe
|
||||
@NotNullByDefault
|
||||
protected class PluginState {
|
||||
|
||||
@GuardedBy("this")
|
||||
private boolean started = false, stopped = false, enabledByUser = false;
|
||||
|
||||
@GuardedBy("this")
|
||||
@Nullable
|
||||
private ServerSocket serverSocketV4 = null, serverSocketV6 = null;
|
||||
|
||||
synchronized void setStarted(boolean enabledByUser) {
|
||||
started = true;
|
||||
this.enabledByUser = enabledByUser;
|
||||
callback.pluginStateChanged(getState());
|
||||
}
|
||||
|
||||
synchronized List<ServerSocket> setStopped() {
|
||||
stopped = true;
|
||||
List<ServerSocket> toClose = clearServerSockets();
|
||||
callback.pluginStateChanged(getState());
|
||||
return toClose;
|
||||
}
|
||||
|
||||
@GuardedBy("this")
|
||||
private List<ServerSocket> clearServerSockets() {
|
||||
List<ServerSocket> toClose = new ArrayList<>(2);
|
||||
if (serverSocketV4 != null) {
|
||||
toClose.add(serverSocketV4);
|
||||
serverSocketV4 = null;
|
||||
}
|
||||
if (serverSocketV6 != null) {
|
||||
toClose.add(serverSocketV6);
|
||||
serverSocketV6 = null;
|
||||
}
|
||||
return toClose;
|
||||
}
|
||||
|
||||
synchronized List<ServerSocket> setEnabledByUser(
|
||||
boolean enabledByUser) {
|
||||
this.enabledByUser = enabledByUser;
|
||||
List<ServerSocket> toClose = enabledByUser
|
||||
? emptyList() : clearServerSockets();
|
||||
callback.pluginStateChanged(getState());
|
||||
return toClose;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
synchronized ServerSocket getServerSocket(boolean ipv4) {
|
||||
return ipv4 ? serverSocketV4 : serverSocketV6;
|
||||
}
|
||||
|
||||
synchronized boolean setServerSocket(ServerSocket ss, boolean ipv4) {
|
||||
if (stopped) return false;
|
||||
if (ipv4) {
|
||||
if (serverSocketV4 != null) return false;
|
||||
serverSocketV4 = ss;
|
||||
} else {
|
||||
if (serverSocketV6 != null) return false;
|
||||
serverSocketV6 = ss;
|
||||
}
|
||||
callback.pluginStateChanged(getState());
|
||||
return true;
|
||||
}
|
||||
|
||||
synchronized void clearServerSocket(ServerSocket ss, boolean ipv4) {
|
||||
if (ipv4) {
|
||||
if (serverSocketV4 == ss) serverSocketV4 = null;
|
||||
} else {
|
||||
if (serverSocketV6 == ss) serverSocketV6 = null;
|
||||
}
|
||||
callback.pluginStateChanged(getState());
|
||||
}
|
||||
|
||||
synchronized State getState() {
|
||||
if (!started || stopped) return STARTING_STOPPING;
|
||||
if (!enabledByUser) return DISABLED;
|
||||
if (serverSocketV4 != null || serverSocketV6 != null) return ACTIVE;
|
||||
return INACTIVE;
|
||||
}
|
||||
|
||||
synchronized int getReasonsDisabled() {
|
||||
return getState() == DISABLED ? REASON_USER : 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,6 @@ 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
|
||||
@@ -44,16 +43,10 @@ class WanTcpPlugin extends TcpPlugin {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isEnabledByDefault() {
|
||||
return DEFAULT_PREF_PLUGIN_ENABLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<InetSocketAddress> getLocalSocketAddresses(boolean ipv4) {
|
||||
if (!ipv4) return emptyList();
|
||||
protected List<InetSocketAddress> getLocalSocketAddresses() {
|
||||
// Use the same address and port as last time if available
|
||||
TransportProperties p = callback.getLocalProperties();
|
||||
InetSocketAddress old = parseIpv4SocketAddress(p.get(PROP_IP_PORT));
|
||||
InetSocketAddress old = parseSocketAddress(p.get(PROP_IP_PORT));
|
||||
List<InetSocketAddress> addrs = new LinkedList<>();
|
||||
for (InetAddress a : getLocalInetAddresses()) {
|
||||
if (isAcceptableAddress(a)) {
|
||||
@@ -83,11 +76,14 @@ class WanTcpPlugin extends TcpPlugin {
|
||||
return ipv4 && !loop && !link && !site;
|
||||
}
|
||||
|
||||
private int chooseEphemeralPort() {
|
||||
return 32768 + (int) (Math.random() * 32768);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<InetSocketAddress> getRemoteSocketAddresses(
|
||||
TransportProperties p, boolean ipv4) {
|
||||
if (!ipv4) return emptyList();
|
||||
InetSocketAddress parsed = parseIpv4SocketAddress(p.get(PROP_IP_PORT));
|
||||
TransportProperties p) {
|
||||
InetSocketAddress parsed = parseSocketAddress(p.get(PROP_IP_PORT));
|
||||
if (parsed == null) return emptyList();
|
||||
return singletonList(parsed);
|
||||
}
|
||||
@@ -100,8 +96,7 @@ class WanTcpPlugin extends TcpPlugin {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setLocalSocketAddress(InetSocketAddress a, boolean ipv4) {
|
||||
if (!ipv4) throw new AssertionError();
|
||||
protected void setLocalSocketAddress(InetSocketAddress a) {
|
||||
if (mappingResult != null && mappingResult.isUsable()) {
|
||||
// Advertise the external address to contacts
|
||||
if (a.equals(mappingResult.getInternal())) {
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package org.briarproject.bramble.plugin.tcp;
|
||||
|
||||
import org.briarproject.bramble.api.event.EventBus;
|
||||
import org.briarproject.bramble.api.lifecycle.ShutdownManager;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.plugin.Backoff;
|
||||
@@ -28,14 +27,12 @@ public class WanTcpPluginFactory implements DuplexPluginFactory {
|
||||
private static final double BACKOFF_BASE = 1.2;
|
||||
|
||||
private final Executor ioExecutor;
|
||||
private final EventBus eventBus;
|
||||
private final BackoffFactory backoffFactory;
|
||||
private final ShutdownManager shutdownManager;
|
||||
|
||||
public WanTcpPluginFactory(Executor ioExecutor, EventBus eventBus,
|
||||
public WanTcpPluginFactory(Executor ioExecutor,
|
||||
BackoffFactory backoffFactory, ShutdownManager shutdownManager) {
|
||||
this.ioExecutor = ioExecutor;
|
||||
this.eventBus = eventBus;
|
||||
this.backoffFactory = backoffFactory;
|
||||
this.shutdownManager = shutdownManager;
|
||||
}
|
||||
@@ -54,10 +51,8 @@ public class WanTcpPluginFactory implements DuplexPluginFactory {
|
||||
public DuplexPlugin createPlugin(PluginCallback callback) {
|
||||
Backoff backoff = backoffFactory.createBackoff(MIN_POLLING_INTERVAL,
|
||||
MAX_POLLING_INTERVAL, BACKOFF_BASE);
|
||||
WanTcpPlugin plugin = new WanTcpPlugin(ioExecutor, backoff,
|
||||
return new WanTcpPlugin(ioExecutor, backoff,
|
||||
new PortMapperImpl(shutdownManager), callback, MAX_LATENCY,
|
||||
MAX_IDLE_TIME, CONNECTION_TIMEOUT);
|
||||
eventBus.addListener(plugin);
|
||||
return plugin;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ public interface CircumventionProvider {
|
||||
String[] BLOCKED = {"CN", "IR", "EG", "BY", "TR", "SY", "VE"};
|
||||
|
||||
/**
|
||||
* Countries where obfs4 or meek bridge connections are likely to work.
|
||||
* Countries where obfs4 bridge connection are likely to work.
|
||||
* Should be a subset of {@link #BLOCKED}.
|
||||
*/
|
||||
String[] BRIDGES = { "CN", "IR", "EG", "BY", "TR", "SY", "VE" };
|
||||
|
||||
@@ -15,7 +15,6 @@ import org.briarproject.bramble.api.network.NetworkManager;
|
||||
import org.briarproject.bramble.api.network.NetworkStatus;
|
||||
import org.briarproject.bramble.api.network.event.NetworkStatusEvent;
|
||||
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
||||
import org.briarproject.bramble.api.plugin.Backoff;
|
||||
import org.briarproject.bramble.api.plugin.ConnectionHandler;
|
||||
@@ -55,9 +54,6 @@ import java.util.logging.Logger;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.zip.ZipInputStream;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import javax.annotation.concurrent.GuardedBy;
|
||||
import javax.annotation.concurrent.ThreadSafe;
|
||||
import javax.net.SocketFactory;
|
||||
|
||||
import static java.util.Arrays.asList;
|
||||
@@ -69,16 +65,7 @@ import static java.util.logging.Logger.getLogger;
|
||||
import static net.freehaven.tor.control.TorControlCommands.HS_ADDRESS;
|
||||
import static net.freehaven.tor.control.TorControlCommands.HS_PRIVKEY;
|
||||
import static org.briarproject.bramble.api.nullsafety.NullSafety.requireNonNull;
|
||||
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.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;
|
||||
@@ -89,9 +76,6 @@ import static org.briarproject.bramble.api.plugin.TorConstants.PREF_TOR_ONLY_WHE
|
||||
import static org.briarproject.bramble.api.plugin.TorConstants.PREF_TOR_PORT;
|
||||
import static org.briarproject.bramble.api.plugin.TorConstants.PROP_ONION_V2;
|
||||
import static org.briarproject.bramble.api.plugin.TorConstants.PROP_ONION_V3;
|
||||
import static org.briarproject.bramble.api.plugin.TorConstants.REASON_BATTERY;
|
||||
import static org.briarproject.bramble.api.plugin.TorConstants.REASON_COUNTRY_BLOCKED;
|
||||
import static org.briarproject.bramble.api.plugin.TorConstants.REASON_MOBILE_DATA;
|
||||
import static org.briarproject.bramble.plugin.tor.TorRendezvousCrypto.SEED_BYTES;
|
||||
import static org.briarproject.bramble.util.IoUtils.copyAndClose;
|
||||
import static org.briarproject.bramble.util.IoUtils.tryToClose;
|
||||
@@ -129,14 +113,16 @@ abstract class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
|
||||
private final int maxLatency, maxIdleTime, socketTimeout;
|
||||
private final File torDirectory, torFile, geoIpFile, obfs4File, configFile;
|
||||
private final File doneFile, cookieFile;
|
||||
private final ConnectionStatus connectionStatus;
|
||||
private final AtomicBoolean used = new AtomicBoolean(false);
|
||||
|
||||
protected final PluginState state = new PluginState();
|
||||
|
||||
private volatile ServerSocket socket = null;
|
||||
private volatile Socket controlSocket = null;
|
||||
private volatile TorControlConnection controlConnection = null;
|
||||
private volatile Settings settings = null;
|
||||
|
||||
protected volatile boolean running = false;
|
||||
|
||||
protected abstract int getProcessId();
|
||||
|
||||
protected abstract long getLastUpdateTime();
|
||||
@@ -173,6 +159,7 @@ abstract class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
|
||||
configFile = new File(torDirectory, "torrc");
|
||||
doneFile = new File(torDirectory, "done");
|
||||
cookieFile = new File(torDirectory, ".tor/control_auth_cookie");
|
||||
connectionStatus = new ConnectionStatus();
|
||||
// Don't execute more than one connection status check at a time
|
||||
connectionStatusExecutor =
|
||||
new PoliteExecutor("TorPlugin", ioExecutor, 1);
|
||||
@@ -203,7 +190,7 @@ abstract class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
|
||||
}
|
||||
}
|
||||
// Load the settings
|
||||
settings = migrateSettings(callback.getSettings());
|
||||
settings = callback.getSettings();
|
||||
// Install or update the assets if necessary
|
||||
if (!assetsAreUpToDate()) installAssets();
|
||||
if (cookieFile.exists() && !cookieFile.delete())
|
||||
@@ -271,6 +258,7 @@ abstract class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
|
||||
// Tell Tor to exit when the control connection is closed
|
||||
controlConnection.takeOwnership();
|
||||
controlConnection.resetConf(singletonList(OWNER));
|
||||
running = true;
|
||||
// Register to receive events from the Tor process
|
||||
controlConnection.setEventHandler(this);
|
||||
controlConnection.setEvents(asList(EVENTS));
|
||||
@@ -278,12 +266,11 @@ abstract class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
|
||||
String phase = controlConnection.getInfo("status/bootstrap-phase");
|
||||
if (phase != null && phase.contains("PROGRESS=100")) {
|
||||
LOG.info("Tor has already bootstrapped");
|
||||
state.setBootstrapped();
|
||||
connectionStatus.setBootstrapped();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new PluginException(e);
|
||||
}
|
||||
state.setStarted();
|
||||
// Check whether we're online
|
||||
updateConnectionStatus(networkManager.getNetworkStatus(),
|
||||
batteryManager.isCharging());
|
||||
@@ -291,18 +278,6 @@ abstract class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
|
||||
bind();
|
||||
}
|
||||
|
||||
// TODO: Remove after a reasonable migration period (added 2020-06-25)
|
||||
private Settings migrateSettings(Settings settings) {
|
||||
int network = settings.getInt(PREF_TOR_NETWORK,
|
||||
DEFAULT_PREF_TOR_NETWORK);
|
||||
if (network == PREF_TOR_NETWORK_NEVER) {
|
||||
settings.putInt(PREF_TOR_NETWORK, DEFAULT_PREF_TOR_NETWORK);
|
||||
settings.putBoolean(PREF_PLUGIN_ENABLE, false);
|
||||
callback.mergeSettings(settings);
|
||||
}
|
||||
return settings;
|
||||
}
|
||||
|
||||
private boolean assetsAreUpToDate() {
|
||||
return doneFile.lastModified() > getLastUpdateTime();
|
||||
}
|
||||
@@ -418,11 +393,11 @@ abstract class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
|
||||
tryToClose(ss, LOG, WARNING);
|
||||
return;
|
||||
}
|
||||
if (!state.setServerSocket(ss)) {
|
||||
LOG.info("Closing redundant server socket");
|
||||
if (!running) {
|
||||
tryToClose(ss, LOG, WARNING);
|
||||
return;
|
||||
}
|
||||
socket = ss;
|
||||
// Store the port number
|
||||
String localPort = String.valueOf(ss.getLocalPort());
|
||||
Settings s = new Settings();
|
||||
@@ -437,7 +412,7 @@ abstract class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
|
||||
}
|
||||
|
||||
private void publishHiddenService(String port) {
|
||||
if (!state.isTorRunning()) return;
|
||||
if (!running) return;
|
||||
LOG.info("Creating hidden service");
|
||||
String privKey = settings.get(HS_PRIVKEY);
|
||||
Map<Integer, String> portLines = singletonMap(80, "127.0.0.1:" + port);
|
||||
@@ -475,15 +450,14 @@ abstract class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
|
||||
}
|
||||
|
||||
private void acceptContactConnections(ServerSocket ss) {
|
||||
while (true) {
|
||||
while (running) {
|
||||
Socket s;
|
||||
try {
|
||||
s = ss.accept();
|
||||
s.setSoTimeout(socketTimeout);
|
||||
} catch (IOException e) {
|
||||
// This is expected when the server socket is closed
|
||||
LOG.info("Server socket closed");
|
||||
state.clearServerSocket(ss);
|
||||
// This is expected when the socket is closed
|
||||
if (LOG.isLoggable(INFO)) LOG.info(e.toString());
|
||||
return;
|
||||
}
|
||||
LOG.info("Connection received");
|
||||
@@ -493,8 +467,10 @@ abstract class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
|
||||
}
|
||||
|
||||
protected void enableNetwork(boolean enable) throws IOException {
|
||||
state.enableNetwork(enable);
|
||||
if (!running) return;
|
||||
connectionStatus.enableNetwork(enable);
|
||||
controlConnection.setConf("DisableNetwork", enable ? "0" : "1");
|
||||
if (!enable) callback.transportDisabled();
|
||||
}
|
||||
|
||||
private void enableBridges(boolean enable, boolean needsMeek)
|
||||
@@ -518,8 +494,9 @@ abstract class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
|
||||
|
||||
@Override
|
||||
public void stop() {
|
||||
ServerSocket ss = state.setStopped();
|
||||
tryToClose(ss, LOG, WARNING);
|
||||
running = false;
|
||||
tryToClose(socket, LOG, WARNING);
|
||||
callback.transportDisabled();
|
||||
if (controlSocket != null && controlConnection != null) {
|
||||
try {
|
||||
LOG.info("Stopping Tor");
|
||||
@@ -533,13 +510,8 @@ abstract class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
|
||||
}
|
||||
|
||||
@Override
|
||||
public State getState() {
|
||||
return state.getState();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getReasonsDisabled() {
|
||||
return state.getReasonsDisabled();
|
||||
public boolean isRunning() {
|
||||
return running && connectionStatus.isConnected();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -555,7 +527,7 @@ abstract class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
|
||||
@Override
|
||||
public void poll(Collection<Pair<TransportProperties, ConnectionHandler>>
|
||||
properties) {
|
||||
if (getState() != ACTIVE) return;
|
||||
if (!isRunning()) return;
|
||||
backoff.increment();
|
||||
for (Pair<TransportProperties, ConnectionHandler> p : properties) {
|
||||
connect(p.getFirst(), p.getSecond());
|
||||
@@ -574,7 +546,7 @@ abstract class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
|
||||
|
||||
@Override
|
||||
public DuplexTransportConnection createConnection(TransportProperties p) {
|
||||
if (getState() != ACTIVE) return null;
|
||||
if (!isRunning()) return null;
|
||||
String bestOnion = null;
|
||||
String onion2 = p.get(PROP_ONION_V2);
|
||||
String onion3 = p.get(PROP_ONION_V3);
|
||||
@@ -662,8 +634,8 @@ abstract class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
|
||||
new TorTransportConnection(this, s));
|
||||
}
|
||||
} catch (IOException e) {
|
||||
// This is expected when the server socket is closed
|
||||
LOG.info("Rendezvous server socket closed");
|
||||
// This is expected when the socket is closed
|
||||
if (LOG.isLoggable(INFO)) LOG.info(e.toString());
|
||||
}
|
||||
});
|
||||
Map<Integer, String> portLines =
|
||||
@@ -691,9 +663,10 @@ abstract class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
|
||||
@Override
|
||||
public void circuitStatus(String status, String id, String path) {
|
||||
if (status.equals("BUILT") &&
|
||||
state.getAndSetCircuitBuilt()) {
|
||||
connectionStatus.getAndSetCircuitBuilt()) {
|
||||
LOG.info("First circuit built");
|
||||
backoff.reset();
|
||||
if (isRunning()) callback.transportEnabled();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -724,8 +697,9 @@ abstract class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
|
||||
public void message(String severity, String msg) {
|
||||
if (LOG.isLoggable(INFO)) LOG.info(severity + " " + msg);
|
||||
if (severity.equals("NOTICE") && msg.startsWith("Bootstrapped 100%")) {
|
||||
state.setBootstrapped();
|
||||
connectionStatus.setBootstrapped();
|
||||
backoff.reset();
|
||||
if (isRunning()) callback.transportEnabled();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -762,7 +736,7 @@ abstract class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
|
||||
private void disableNetwork() {
|
||||
connectionStatusExecutor.execute(() -> {
|
||||
try {
|
||||
if (state.isTorRunning()) enableNetwork(false);
|
||||
enableNetwork(false);
|
||||
} catch (IOException ex) {
|
||||
logException(LOG, WARNING, ex);
|
||||
}
|
||||
@@ -772,90 +746,63 @@ abstract class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
|
||||
private void updateConnectionStatus(NetworkStatus status,
|
||||
boolean charging) {
|
||||
connectionStatusExecutor.execute(() -> {
|
||||
if (!state.isTorRunning()) return;
|
||||
if (!running) return;
|
||||
boolean online = status.isConnected();
|
||||
boolean wifi = status.isWifi();
|
||||
String country = locationUtils.getCurrentCountry();
|
||||
boolean blocked =
|
||||
circumventionProvider.isTorProbablyBlocked(country);
|
||||
boolean enabledByUser = settings.getBoolean(PREF_PLUGIN_ENABLE,
|
||||
DEFAULT_PREF_PLUGIN_ENABLE);
|
||||
int network = settings.getInt(PREF_TOR_NETWORK,
|
||||
DEFAULT_PREF_TOR_NETWORK);
|
||||
boolean useMobile = settings.getBoolean(PREF_TOR_MOBILE,
|
||||
DEFAULT_PREF_TOR_MOBILE);
|
||||
PREF_TOR_NETWORK_AUTOMATIC);
|
||||
boolean useMobile = settings.getBoolean(PREF_TOR_MOBILE, true);
|
||||
boolean onlyWhenCharging =
|
||||
settings.getBoolean(PREF_TOR_ONLY_WHEN_CHARGING,
|
||||
DEFAULT_PREF_TOR_ONLY_WHEN_CHARGING);
|
||||
settings.getBoolean(PREF_TOR_ONLY_WHEN_CHARGING, false);
|
||||
boolean bridgesWork = circumventionProvider.doBridgesWork(country);
|
||||
boolean automatic = network == PREF_TOR_NETWORK_AUTOMATIC;
|
||||
|
||||
if (LOG.isLoggable(INFO)) {
|
||||
LOG.info("Online: " + online + ", wifi: " + wifi);
|
||||
if (country.isEmpty()) LOG.info("Country code unknown");
|
||||
if ("".equals(country)) LOG.info("Country code unknown");
|
||||
else LOG.info("Country code: " + country);
|
||||
LOG.info("Charging: " + charging);
|
||||
}
|
||||
|
||||
int reasonsDisabled = 0;
|
||||
boolean enableNetwork = false, enableBridges = false;
|
||||
boolean useMeek = false, enableConnectionPadding = false;
|
||||
|
||||
if (!online) {
|
||||
LOG.info("Disabling network, device is offline");
|
||||
} else {
|
||||
if (!enabledByUser) {
|
||||
LOG.info("User has disabled Tor");
|
||||
reasonsDisabled |= REASON_USER;
|
||||
}
|
||||
if (!charging && onlyWhenCharging) {
|
||||
LOG.info("Configured not to use battery");
|
||||
reasonsDisabled |= REASON_BATTERY;
|
||||
}
|
||||
if (!useMobile && !wifi) {
|
||||
LOG.info("Configured not to use mobile data");
|
||||
reasonsDisabled |= REASON_MOBILE_DATA;
|
||||
}
|
||||
if (automatic && blocked && !bridgesWork) {
|
||||
LOG.info("Country is blocked");
|
||||
reasonsDisabled |= REASON_COUNTRY_BLOCKED;
|
||||
}
|
||||
|
||||
if (reasonsDisabled != 0) {
|
||||
LOG.info("Disabling network due to settings");
|
||||
} else {
|
||||
LOG.info("Enabling network");
|
||||
enableNetwork = true;
|
||||
if (network == PREF_TOR_NETWORK_WITH_BRIDGES ||
|
||||
(automatic && bridgesWork)) {
|
||||
if (circumventionProvider.needsMeek(country)) {
|
||||
LOG.info("Using meek bridges");
|
||||
enableBridges = true;
|
||||
useMeek = true;
|
||||
} else {
|
||||
LOG.info("Using obfs4 bridges");
|
||||
enableBridges = true;
|
||||
}
|
||||
} else {
|
||||
LOG.info("Not using bridges");
|
||||
}
|
||||
if (wifi && charging) {
|
||||
LOG.info("Enabling connection padding");
|
||||
enableConnectionPadding = true;
|
||||
} else {
|
||||
LOG.info("Disabling connection padding");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
state.setReasonsDisabled(reasonsDisabled);
|
||||
|
||||
try {
|
||||
if (enableNetwork) {
|
||||
enableBridges(enableBridges, useMeek);
|
||||
enableConnectionPadding(enableConnectionPadding);
|
||||
if (!online) {
|
||||
LOG.info("Disabling network, device is offline");
|
||||
enableNetwork(false);
|
||||
} else if (!charging && onlyWhenCharging) {
|
||||
LOG.info("Disabling network, device is on battery");
|
||||
enableNetwork(false);
|
||||
} else if (network == PREF_TOR_NETWORK_NEVER ||
|
||||
(!useMobile && !wifi)) {
|
||||
LOG.info("Disabling network, device is using mobile data");
|
||||
enableNetwork(false);
|
||||
} else if (automatic && blocked && !bridgesWork) {
|
||||
LOG.info("Disabling network, country is blocked");
|
||||
enableNetwork(false);
|
||||
} else if (network == PREF_TOR_NETWORK_WITH_BRIDGES ||
|
||||
(automatic && bridgesWork)) {
|
||||
if (circumventionProvider.needsMeek(country)) {
|
||||
LOG.info("Enabling network, using meek bridges");
|
||||
enableBridges(true, true);
|
||||
} else {
|
||||
LOG.info("Enabling network, using obfs4 bridges");
|
||||
enableBridges(true, false);
|
||||
}
|
||||
enableNetwork(true);
|
||||
} else {
|
||||
LOG.info("Enabling network, not using bridges");
|
||||
enableBridges(false, false);
|
||||
enableNetwork(true);
|
||||
}
|
||||
if (online && wifi && charging) {
|
||||
LOG.info("Enabling connection padding");
|
||||
enableConnectionPadding(true);
|
||||
} else {
|
||||
LOG.info("Disabling connection padding");
|
||||
enableConnectionPadding(false);
|
||||
}
|
||||
enableNetwork(enableNetwork);
|
||||
} catch (IOException e) {
|
||||
logException(LOG, WARNING, e);
|
||||
}
|
||||
@@ -863,96 +810,33 @@ abstract class TorPlugin implements DuplexPlugin, EventHandler, EventListener {
|
||||
}
|
||||
|
||||
private void enableConnectionPadding(boolean enable) throws IOException {
|
||||
if (!running) return;
|
||||
controlConnection.setConf("ConnectionPadding", enable ? "1" : "0");
|
||||
}
|
||||
|
||||
@ThreadSafe
|
||||
@NotNullByDefault
|
||||
protected class PluginState {
|
||||
private static class ConnectionStatus {
|
||||
|
||||
@GuardedBy("this")
|
||||
private boolean started = false,
|
||||
stopped = false,
|
||||
networkInitialised = false,
|
||||
networkEnabled = false,
|
||||
bootstrapped = false,
|
||||
circuitBuilt = false,
|
||||
settingsChecked = false;
|
||||
// All of the following are locking: this
|
||||
private boolean networkEnabled = false;
|
||||
private boolean bootstrapped = false, circuitBuilt = false;
|
||||
|
||||
@GuardedBy("this")
|
||||
private int reasonsDisabled = 0;
|
||||
|
||||
@GuardedBy("this")
|
||||
@Nullable
|
||||
private ServerSocket serverSocket = null;
|
||||
|
||||
synchronized void setStarted() {
|
||||
started = true;
|
||||
callback.pluginStateChanged(getState());
|
||||
}
|
||||
|
||||
synchronized boolean isTorRunning() {
|
||||
return started && !stopped;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
synchronized ServerSocket setStopped() {
|
||||
stopped = true;
|
||||
ServerSocket ss = serverSocket;
|
||||
serverSocket = null;
|
||||
callback.pluginStateChanged(getState());
|
||||
return ss;
|
||||
}
|
||||
|
||||
synchronized void setBootstrapped() {
|
||||
private synchronized void setBootstrapped() {
|
||||
bootstrapped = true;
|
||||
callback.pluginStateChanged(getState());
|
||||
}
|
||||
|
||||
synchronized boolean getAndSetCircuitBuilt() {
|
||||
private synchronized boolean getAndSetCircuitBuilt() {
|
||||
boolean firstCircuit = !circuitBuilt;
|
||||
circuitBuilt = true;
|
||||
callback.pluginStateChanged(getState());
|
||||
return firstCircuit;
|
||||
}
|
||||
|
||||
synchronized void enableNetwork(boolean enable) {
|
||||
networkInitialised = true;
|
||||
private synchronized void enableNetwork(boolean enable) {
|
||||
networkEnabled = enable;
|
||||
if (!enable) circuitBuilt = false;
|
||||
callback.pluginStateChanged(getState());
|
||||
}
|
||||
|
||||
synchronized void setReasonsDisabled(int reasonsDisabled) {
|
||||
settingsChecked = true;
|
||||
this.reasonsDisabled = reasonsDisabled;
|
||||
callback.pluginStateChanged(getState());
|
||||
}
|
||||
|
||||
// Doesn't affect getState()
|
||||
synchronized boolean setServerSocket(ServerSocket ss) {
|
||||
if (stopped || serverSocket != null) return false;
|
||||
serverSocket = ss;
|
||||
return true;
|
||||
}
|
||||
|
||||
// Doesn't affect getState()
|
||||
synchronized void clearServerSocket(ServerSocket ss) {
|
||||
if (serverSocket == ss) serverSocket = null;
|
||||
}
|
||||
|
||||
synchronized State getState() {
|
||||
if (!started || stopped || !settingsChecked) {
|
||||
return STARTING_STOPPING;
|
||||
}
|
||||
if (reasonsDisabled != 0) return DISABLED;
|
||||
if (!networkInitialised) return ENABLING;
|
||||
if (!networkEnabled) return INACTIVE;
|
||||
return bootstrapped && circuitBuilt ? ACTIVE : ENABLING;
|
||||
}
|
||||
|
||||
synchronized int getReasonsDisabled() {
|
||||
return getState() == DISABLED ? reasonsDisabled : 0;
|
||||
private synchronized boolean isConnected() {
|
||||
return networkEnabled && bootstrapped && circuitBuilt;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,8 +31,8 @@ import org.briarproject.bramble.api.plugin.TransportConnectionWriter;
|
||||
import org.briarproject.bramble.api.plugin.TransportId;
|
||||
import org.briarproject.bramble.api.plugin.duplex.DuplexPlugin;
|
||||
import org.briarproject.bramble.api.plugin.duplex.DuplexTransportConnection;
|
||||
import org.briarproject.bramble.api.plugin.event.TransportActiveEvent;
|
||||
import org.briarproject.bramble.api.plugin.event.TransportInactiveEvent;
|
||||
import org.briarproject.bramble.api.plugin.event.TransportDisabledEvent;
|
||||
import org.briarproject.bramble.api.plugin.event.TransportEnabledEvent;
|
||||
import org.briarproject.bramble.api.properties.TransportProperties;
|
||||
import org.briarproject.bramble.api.rendezvous.KeyMaterialSource;
|
||||
import org.briarproject.bramble.api.rendezvous.RendezvousEndpoint;
|
||||
@@ -269,11 +269,11 @@ class RendezvousPollerImpl implements RendezvousPoller, Service, EventListener {
|
||||
} else if (e instanceof PendingContactRemovedEvent) {
|
||||
PendingContactRemovedEvent p = (PendingContactRemovedEvent) e;
|
||||
removePendingContactAsync(p.getId());
|
||||
} else if (e instanceof TransportActiveEvent) {
|
||||
TransportActiveEvent t = (TransportActiveEvent) e;
|
||||
} else if (e instanceof TransportEnabledEvent) {
|
||||
TransportEnabledEvent t = (TransportEnabledEvent) e;
|
||||
addTransportAsync(t.getTransportId());
|
||||
} else if (e instanceof TransportInactiveEvent) {
|
||||
TransportInactiveEvent t = (TransportInactiveEvent) e;
|
||||
} else if (e instanceof TransportDisabledEvent) {
|
||||
TransportDisabledEvent t = (TransportDisabledEvent) e;
|
||||
removeTransportAsync(t.getTransportId());
|
||||
} else if (e instanceof RendezvousConnectionOpenedEvent) {
|
||||
RendezvousConnectionOpenedEvent r =
|
||||
|
||||
@@ -6,7 +6,7 @@ import org.briarproject.bramble.api.event.EventListener;
|
||||
import org.briarproject.bramble.api.lifecycle.IoExecutor;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.plugin.TorConstants;
|
||||
import org.briarproject.bramble.api.plugin.event.TransportActiveEvent;
|
||||
import org.briarproject.bramble.api.plugin.event.TransportEnabledEvent;
|
||||
import org.briarproject.bramble.api.reporting.DevConfig;
|
||||
import org.briarproject.bramble.api.reporting.DevReporter;
|
||||
import org.briarproject.bramble.util.IoUtils;
|
||||
@@ -92,8 +92,8 @@ class DevReporterImpl implements DevReporter, EventListener {
|
||||
|
||||
@Override
|
||||
public void eventOccurred(Event e) {
|
||||
if (e instanceof TransportActiveEvent) {
|
||||
TransportActiveEvent t = (TransportActiveEvent) e;
|
||||
if (e instanceof TransportEnabledEvent) {
|
||||
TransportEnabledEvent t = (TransportEnabledEvent) e;
|
||||
if (t.getTransportId().equals(TorConstants.ID))
|
||||
ioExecutor.execute(this::sendReports);
|
||||
}
|
||||
|
||||
@@ -12,7 +12,6 @@ import org.briarproject.bramble.api.lifecycle.IoExecutor;
|
||||
import org.briarproject.bramble.api.lifecycle.event.LifecycleEvent;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.plugin.TransportId;
|
||||
import org.briarproject.bramble.api.plugin.event.TransportInactiveEvent;
|
||||
import org.briarproject.bramble.api.sync.Ack;
|
||||
import org.briarproject.bramble.api.sync.Message;
|
||||
import org.briarproject.bramble.api.sync.Offer;
|
||||
@@ -239,9 +238,6 @@ class DuplexOutgoingSession implements SyncSession, EventListener {
|
||||
} else if (e instanceof CloseSyncConnectionsEvent) {
|
||||
CloseSyncConnectionsEvent c = (CloseSyncConnectionsEvent) e;
|
||||
if (c.getTransportId().equals(transportId)) interrupt();
|
||||
} else if (e instanceof TransportInactiveEvent) {
|
||||
TransportInactiveEvent t = (TransportInactiveEvent) e;
|
||||
if (t.getTransportId().equals(transportId)) interrupt();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,6 @@ import org.briarproject.bramble.api.lifecycle.IoExecutor;
|
||||
import org.briarproject.bramble.api.lifecycle.event.LifecycleEvent;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.plugin.TransportId;
|
||||
import org.briarproject.bramble.api.plugin.event.TransportInactiveEvent;
|
||||
import org.briarproject.bramble.api.sync.Ack;
|
||||
import org.briarproject.bramble.api.sync.Message;
|
||||
import org.briarproject.bramble.api.sync.SyncRecordWriter;
|
||||
@@ -132,9 +131,6 @@ class SimplexOutgoingSession implements SyncSession, EventListener {
|
||||
} else if (e instanceof CloseSyncConnectionsEvent) {
|
||||
CloseSyncConnectionsEvent c = (CloseSyncConnectionsEvent) e;
|
||||
if (c.getTransportId().equals(transportId)) interrupt();
|
||||
} else if (e instanceof TransportInactiveEvent) {
|
||||
TransportInactiveEvent t = (TransportInactiveEvent) e;
|
||||
if (t.getTransportId().equals(transportId)) interrupt();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -13,8 +13,8 @@ import org.briarproject.bramble.api.plugin.duplex.DuplexPlugin;
|
||||
import org.briarproject.bramble.api.plugin.duplex.DuplexTransportConnection;
|
||||
import org.briarproject.bramble.api.plugin.event.ConnectionClosedEvent;
|
||||
import org.briarproject.bramble.api.plugin.event.ConnectionOpenedEvent;
|
||||
import org.briarproject.bramble.api.plugin.event.TransportActiveEvent;
|
||||
import org.briarproject.bramble.api.plugin.event.TransportInactiveEvent;
|
||||
import org.briarproject.bramble.api.plugin.event.TransportDisabledEvent;
|
||||
import org.briarproject.bramble.api.plugin.event.TransportEnabledEvent;
|
||||
import org.briarproject.bramble.api.plugin.simplex.SimplexPlugin;
|
||||
import org.briarproject.bramble.api.properties.TransportProperties;
|
||||
import org.briarproject.bramble.api.properties.TransportPropertyManager;
|
||||
@@ -331,7 +331,7 @@ public class PollerImplTest extends BrambleMockTestCase {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPollsOnTransportActivated() throws Exception {
|
||||
public void testPollsOnTransportEnabled() throws Exception {
|
||||
DuplexPlugin plugin = context.mock(DuplexPlugin.class);
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
@@ -370,7 +370,7 @@ public class PollerImplTest extends BrambleMockTestCase {
|
||||
pairOf(equal(properties), any(ConnectionHandler.class)))));
|
||||
}});
|
||||
|
||||
poller.eventOccurred(new TransportActiveEvent(transportId));
|
||||
poller.eventOccurred(new TransportEnabledEvent(transportId));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -411,11 +411,11 @@ public class PollerImplTest extends BrambleMockTestCase {
|
||||
// All contacts are connected, so don't poll the plugin
|
||||
}});
|
||||
|
||||
poller.eventOccurred(new TransportActiveEvent(transportId));
|
||||
poller.eventOccurred(new TransportEnabledEvent(transportId));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCancelsPollingOnTransportDeactivated() {
|
||||
public void testCancelsPollingOnTransportDisabled() {
|
||||
Plugin plugin = context.mock(Plugin.class);
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
@@ -433,12 +433,12 @@ public class PollerImplTest extends BrambleMockTestCase {
|
||||
oneOf(scheduler).schedule(with(any(Runnable.class)), with(0L),
|
||||
with(MILLISECONDS));
|
||||
will(returnValue(future));
|
||||
// The plugin is deactivated before the task runs - cancel the task
|
||||
// The plugin is disabled before the task runs - cancel the task
|
||||
oneOf(future).cancel(false);
|
||||
}});
|
||||
|
||||
poller.eventOccurred(new TransportActiveEvent(transportId));
|
||||
poller.eventOccurred(new TransportInactiveEvent(transportId));
|
||||
poller.eventOccurred(new TransportEnabledEvent(transportId));
|
||||
poller.eventOccurred(new TransportDisabledEvent(transportId));
|
||||
}
|
||||
|
||||
private void expectReschedule(Plugin plugin) {
|
||||
|
||||
@@ -4,7 +4,6 @@ import org.briarproject.bramble.api.data.BdfList;
|
||||
import org.briarproject.bramble.api.keyagreement.KeyAgreementListener;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.plugin.Backoff;
|
||||
import org.briarproject.bramble.api.plugin.Plugin.State;
|
||||
import org.briarproject.bramble.api.plugin.PluginCallback;
|
||||
import org.briarproject.bramble.api.plugin.TransportConnectionReader;
|
||||
import org.briarproject.bramble.api.plugin.TransportConnectionWriter;
|
||||
@@ -32,7 +31,6 @@ import static java.util.concurrent.Executors.newCachedThreadPool;
|
||||
import static java.util.concurrent.TimeUnit.SECONDS;
|
||||
import static org.briarproject.bramble.api.keyagreement.KeyAgreementConstants.COMMIT_LENGTH;
|
||||
import static org.briarproject.bramble.api.keyagreement.KeyAgreementConstants.TRANSPORT_ID_LAN;
|
||||
import static org.briarproject.bramble.api.plugin.Plugin.PREF_PLUGIN_ENABLE;
|
||||
import static org.briarproject.bramble.plugin.tcp.LanTcpPlugin.areAddressesInSameNetwork;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
@@ -304,15 +302,10 @@ public class LanTcpPluginTest extends BrambleTestCase {
|
||||
private final CountDownLatch propertiesLatch = new CountDownLatch(2);
|
||||
private final CountDownLatch connectionsLatch = new CountDownLatch(1);
|
||||
private final TransportProperties local = new TransportProperties();
|
||||
private final Settings settings = new Settings();
|
||||
|
||||
private Callback() {
|
||||
settings.putBoolean(PREF_PLUGIN_ENABLE, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Settings getSettings() {
|
||||
return settings;
|
||||
return new Settings();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -331,7 +324,11 @@ public class LanTcpPluginTest extends BrambleTestCase {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void pluginStateChanged(State newState) {
|
||||
public void transportEnabled() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void transportDisabled() {
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -17,8 +17,8 @@ import org.briarproject.bramble.api.plugin.ConnectionHandler;
|
||||
import org.briarproject.bramble.api.plugin.PluginManager;
|
||||
import org.briarproject.bramble.api.plugin.TransportId;
|
||||
import org.briarproject.bramble.api.plugin.duplex.DuplexPlugin;
|
||||
import org.briarproject.bramble.api.plugin.event.TransportActiveEvent;
|
||||
import org.briarproject.bramble.api.plugin.event.TransportInactiveEvent;
|
||||
import org.briarproject.bramble.api.plugin.event.TransportDisabledEvent;
|
||||
import org.briarproject.bramble.api.plugin.event.TransportEnabledEvent;
|
||||
import org.briarproject.bramble.api.properties.TransportProperties;
|
||||
import org.briarproject.bramble.api.rendezvous.KeyMaterialSource;
|
||||
import org.briarproject.bramble.api.rendezvous.RendezvousEndpoint;
|
||||
@@ -178,10 +178,10 @@ public class RendezvousPollerImplTest extends BrambleMockTestCase {
|
||||
rendezvousPoller.startService();
|
||||
context.assertIsSatisfied();
|
||||
|
||||
// Activate the transport - no endpoints should be created yet
|
||||
// Enable the transport - no endpoints should be created yet
|
||||
expectGetPlugin();
|
||||
|
||||
rendezvousPoller.eventOccurred(new TransportActiveEvent(transportId));
|
||||
rendezvousPoller.eventOccurred(new TransportEnabledEvent(transportId));
|
||||
context.assertIsSatisfied();
|
||||
|
||||
// Add the pending contact - endpoint should be created and polled
|
||||
@@ -212,8 +212,8 @@ public class RendezvousPollerImplTest extends BrambleMockTestCase {
|
||||
new PendingContactRemovedEvent(pendingContact.getId()));
|
||||
context.assertIsSatisfied();
|
||||
|
||||
// Deactivate the transport - endpoint is already closed
|
||||
rendezvousPoller.eventOccurred(new TransportInactiveEvent(transportId));
|
||||
// Disable the transport - endpoint is already closed
|
||||
rendezvousPoller.eventOccurred(new TransportDisabledEvent(transportId));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -230,10 +230,10 @@ public class RendezvousPollerImplTest extends BrambleMockTestCase {
|
||||
rendezvousPoller.startService();
|
||||
context.assertIsSatisfied();
|
||||
|
||||
// Activate the transport - no endpoints should be created yet
|
||||
// Enable the transport - no endpoints should be created yet
|
||||
expectGetPlugin();
|
||||
|
||||
rendezvousPoller.eventOccurred(new TransportActiveEvent(transportId));
|
||||
rendezvousPoller.eventOccurred(new TransportEnabledEvent(transportId));
|
||||
context.assertIsSatisfied();
|
||||
|
||||
// Add the pending contact - endpoint should be created and polled
|
||||
@@ -269,12 +269,12 @@ public class RendezvousPollerImplTest extends BrambleMockTestCase {
|
||||
new PendingContactRemovedEvent(pendingContact.getId()));
|
||||
context.assertIsSatisfied();
|
||||
|
||||
// Deactivate the transport - endpoint is already closed
|
||||
rendezvousPoller.eventOccurred(new TransportInactiveEvent(transportId));
|
||||
// Disable the transport - endpoint is already closed
|
||||
rendezvousPoller.eventOccurred(new TransportDisabledEvent(transportId));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreatesAndClosesEndpointsWhenTransportIsActivatedAndDeactivated()
|
||||
public void testCreatesAndClosesEndpointsWhenTransportIsEnabledAndDisabled()
|
||||
throws Exception {
|
||||
long beforeExpiry = pendingContact.getTimestamp();
|
||||
|
||||
@@ -292,19 +292,19 @@ public class RendezvousPollerImplTest extends BrambleMockTestCase {
|
||||
new PendingContactAddedEvent(pendingContact));
|
||||
context.assertIsSatisfied();
|
||||
|
||||
// Activate the transport - endpoint should be created
|
||||
// Enable the transport - endpoint should be created
|
||||
expectGetPlugin();
|
||||
expectCreateEndpoint();
|
||||
expectStateChangedEvent(WAITING_FOR_CONNECTION);
|
||||
|
||||
rendezvousPoller.eventOccurred(new TransportActiveEvent(transportId));
|
||||
rendezvousPoller.eventOccurred(new TransportEnabledEvent(transportId));
|
||||
context.assertIsSatisfied();
|
||||
|
||||
// Deactivate the transport - endpoint should be closed
|
||||
// Disable the transport - endpoint should be closed
|
||||
expectCloseEndpoint();
|
||||
expectStateChangedEvent(OFFLINE);
|
||||
|
||||
rendezvousPoller.eventOccurred(new TransportInactiveEvent(transportId));
|
||||
rendezvousPoller.eventOccurred(new TransportDisabledEvent(transportId));
|
||||
context.assertIsSatisfied();
|
||||
|
||||
// Remove the pending contact - endpoint is already closed
|
||||
|
||||
@@ -13,6 +13,7 @@ import org.briarproject.bramble.api.plugin.TransportId;
|
||||
import org.briarproject.bramble.api.plugin.duplex.DuplexPluginFactory;
|
||||
import org.briarproject.bramble.api.plugin.simplex.SimplexPluginFactory;
|
||||
import org.briarproject.bramble.api.reliability.ReliabilityLayerFactory;
|
||||
import org.briarproject.bramble.api.system.Clock;
|
||||
import org.briarproject.bramble.plugin.bluetooth.JavaBluetoothPluginFactory;
|
||||
import org.briarproject.bramble.plugin.modem.ModemPluginFactory;
|
||||
import org.briarproject.bramble.plugin.tcp.LanTcpPluginFactory;
|
||||
@@ -39,15 +40,16 @@ public class DesktopPluginModule extends PluginModule {
|
||||
PluginConfig getPluginConfig(@IoExecutor Executor ioExecutor,
|
||||
SecureRandom random, BackoffFactory backoffFactory,
|
||||
ReliabilityLayerFactory reliabilityFactory,
|
||||
ShutdownManager shutdownManager, EventBus eventBus,
|
||||
ShutdownManager shutdownManager, EventBus eventBus, Clock clock,
|
||||
TimeoutMonitor timeoutMonitor) {
|
||||
DuplexPluginFactory bluetooth = new JavaBluetoothPluginFactory(
|
||||
ioExecutor, random, eventBus, timeoutMonitor, backoffFactory);
|
||||
ioExecutor, random, eventBus, clock, timeoutMonitor,
|
||||
backoffFactory);
|
||||
DuplexPluginFactory modem = new ModemPluginFactory(ioExecutor,
|
||||
reliabilityFactory);
|
||||
DuplexPluginFactory lan = new LanTcpPluginFactory(ioExecutor, eventBus,
|
||||
DuplexPluginFactory lan = new LanTcpPluginFactory(ioExecutor,
|
||||
backoffFactory);
|
||||
DuplexPluginFactory wan = new WanTcpPluginFactory(ioExecutor, eventBus,
|
||||
DuplexPluginFactory wan = new WanTcpPluginFactory(ioExecutor,
|
||||
backoffFactory, shutdownManager);
|
||||
Collection<DuplexPluginFactory> duplex =
|
||||
asList(bluetooth, modem, lan, wan);
|
||||
|
||||
@@ -9,6 +9,7 @@ import org.briarproject.bramble.api.plugin.PluginCallback;
|
||||
import org.briarproject.bramble.api.plugin.TransportId;
|
||||
import org.briarproject.bramble.api.plugin.duplex.DuplexPlugin;
|
||||
import org.briarproject.bramble.api.plugin.duplex.DuplexPluginFactory;
|
||||
import org.briarproject.bramble.api.system.Clock;
|
||||
|
||||
import java.security.SecureRandom;
|
||||
import java.util.concurrent.Executor;
|
||||
@@ -30,15 +31,17 @@ public class JavaBluetoothPluginFactory implements DuplexPluginFactory {
|
||||
private final Executor ioExecutor;
|
||||
private final SecureRandom secureRandom;
|
||||
private final EventBus eventBus;
|
||||
private final Clock clock;
|
||||
private final TimeoutMonitor timeoutMonitor;
|
||||
private final BackoffFactory backoffFactory;
|
||||
|
||||
public JavaBluetoothPluginFactory(Executor ioExecutor,
|
||||
SecureRandom secureRandom, EventBus eventBus,
|
||||
SecureRandom secureRandom, EventBus eventBus, Clock clock,
|
||||
TimeoutMonitor timeoutMonitor, BackoffFactory backoffFactory) {
|
||||
this.ioExecutor = ioExecutor;
|
||||
this.secureRandom = secureRandom;
|
||||
this.eventBus = eventBus;
|
||||
this.clock = clock;
|
||||
this.timeoutMonitor = timeoutMonitor;
|
||||
this.backoffFactory = backoffFactory;
|
||||
}
|
||||
@@ -56,7 +59,7 @@ public class JavaBluetoothPluginFactory implements DuplexPluginFactory {
|
||||
@Override
|
||||
public DuplexPlugin createPlugin(PluginCallback callback) {
|
||||
BluetoothConnectionLimiter connectionLimiter =
|
||||
new BluetoothConnectionLimiterImpl(eventBus);
|
||||
new BluetoothConnectionLimiterImpl(eventBus, clock);
|
||||
Backoff backoff = backoffFactory.createBackoff(MIN_POLLING_INTERVAL,
|
||||
MAX_POLLING_INTERVAL, BACKOFF_BASE);
|
||||
JavaBluetoothPlugin plugin = new JavaBluetoothPlugin(connectionLimiter,
|
||||
|
||||
@@ -4,7 +4,6 @@ import org.briarproject.bramble.api.Pair;
|
||||
import org.briarproject.bramble.api.data.BdfList;
|
||||
import org.briarproject.bramble.api.keyagreement.KeyAgreementListener;
|
||||
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
||||
import org.briarproject.bramble.api.plugin.ConnectionHandler;
|
||||
import org.briarproject.bramble.api.plugin.PluginCallback;
|
||||
@@ -24,16 +23,9 @@ import java.util.Collection;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javax.annotation.concurrent.GuardedBy;
|
||||
import javax.annotation.concurrent.ThreadSafe;
|
||||
|
||||
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.plugin.Plugin.State.ACTIVE;
|
||||
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.util.LogUtils.logException;
|
||||
import static org.briarproject.bramble.util.StringUtils.isNullOrEmpty;
|
||||
|
||||
@@ -52,8 +44,8 @@ class ModemPlugin implements DuplexPlugin, Modem.Callback {
|
||||
private final PluginCallback callback;
|
||||
private final int maxLatency;
|
||||
private final AtomicBoolean used = new AtomicBoolean(false);
|
||||
private final PluginState state = new PluginState();
|
||||
|
||||
private volatile boolean running = false;
|
||||
private volatile Modem modem = null;
|
||||
|
||||
ModemPlugin(ModemFactory modemFactory, SerialPortList serialPortList,
|
||||
@@ -83,7 +75,6 @@ class ModemPlugin implements DuplexPlugin, Modem.Callback {
|
||||
@Override
|
||||
public void start() throws PluginException {
|
||||
if (used.getAndSet(true)) throw new IllegalStateException();
|
||||
state.setStarted();
|
||||
for (String portName : serialPortList.getPortNames()) {
|
||||
if (LOG.isLoggable(INFO))
|
||||
LOG.info("Trying to initialise modem on " + portName);
|
||||
@@ -92,20 +83,18 @@ class ModemPlugin implements DuplexPlugin, Modem.Callback {
|
||||
if (!modem.start()) continue;
|
||||
if (LOG.isLoggable(INFO))
|
||||
LOG.info("Initialised modem on " + portName);
|
||||
state.setInitialised();
|
||||
running = true;
|
||||
return;
|
||||
} catch (IOException e) {
|
||||
logException(LOG, WARNING, e);
|
||||
}
|
||||
}
|
||||
LOG.warning("Failed to initialised modem");
|
||||
state.setFailed();
|
||||
throw new PluginException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() {
|
||||
state.setStopped();
|
||||
running = false;
|
||||
if (modem != null) {
|
||||
try {
|
||||
modem.stop();
|
||||
@@ -116,13 +105,8 @@ class ModemPlugin implements DuplexPlugin, Modem.Callback {
|
||||
}
|
||||
|
||||
@Override
|
||||
public State getState() {
|
||||
return state.getState();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getReasonsDisabled() {
|
||||
return 0;
|
||||
public boolean isRunning() {
|
||||
return running;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -141,8 +125,8 @@ class ModemPlugin implements DuplexPlugin, Modem.Callback {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
private void resetModem() {
|
||||
if (getState() != ACTIVE) return;
|
||||
private boolean resetModem() {
|
||||
if (!running) return false;
|
||||
for (String portName : serialPortList.getPortNames()) {
|
||||
if (LOG.isLoggable(INFO))
|
||||
LOG.info("Trying to initialise modem on " + portName);
|
||||
@@ -151,18 +135,18 @@ class ModemPlugin implements DuplexPlugin, Modem.Callback {
|
||||
if (!modem.start()) continue;
|
||||
if (LOG.isLoggable(INFO))
|
||||
LOG.info("Initialised modem on " + portName);
|
||||
return;
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
logException(LOG, WARNING, e);
|
||||
}
|
||||
}
|
||||
LOG.warning("Failed to initialise modem");
|
||||
state.setFailed();
|
||||
running = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DuplexTransportConnection createConnection(TransportProperties p) {
|
||||
if (getState() != ACTIVE) return null;
|
||||
if (!running) return null;
|
||||
// Get the ISO 3166 code for the caller's country
|
||||
String fromIso = callback.getLocalProperties().get("iso3166");
|
||||
if (isNullOrEmpty(fromIso)) return null;
|
||||
@@ -248,41 +232,4 @@ class ModemPlugin implements DuplexPlugin, Modem.Callback {
|
||||
if (exception) resetModem();
|
||||
}
|
||||
}
|
||||
|
||||
@ThreadSafe
|
||||
@NotNullByDefault
|
||||
private class PluginState {
|
||||
|
||||
@GuardedBy("this")
|
||||
private boolean started = false,
|
||||
stopped = false,
|
||||
initialised = false,
|
||||
failed = false;
|
||||
|
||||
private synchronized void setStarted() {
|
||||
started = true;
|
||||
callback.pluginStateChanged(getState());
|
||||
}
|
||||
|
||||
private synchronized void setStopped() {
|
||||
stopped = true;
|
||||
callback.pluginStateChanged(getState());
|
||||
}
|
||||
|
||||
private synchronized void setInitialised() {
|
||||
initialised = true;
|
||||
callback.pluginStateChanged(getState());
|
||||
}
|
||||
|
||||
private synchronized void setFailed() {
|
||||
failed = true;
|
||||
callback.pluginStateChanged(getState());
|
||||
}
|
||||
|
||||
private State getState() {
|
||||
if (!started || stopped) return STARTING_STOPPING;
|
||||
if (failed) return INACTIVE;
|
||||
return initialised ? ACTIVE : ENABLING;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,8 +9,6 @@ import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.briarproject.bramble.api.plugin.Plugin.State.ACTIVE;
|
||||
import static org.briarproject.bramble.api.plugin.Plugin.State.ENABLING;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
@@ -35,7 +33,6 @@ public class ModemPluginTest extends BrambleMockTestCase {
|
||||
@Test
|
||||
public void testModemCreation() throws Exception {
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(callback).pluginStateChanged(ENABLING);
|
||||
oneOf(serialPortList).getPortNames();
|
||||
will(returnValue(new String[] {"foo", "bar", "baz"}));
|
||||
// First call to createModem() returns false
|
||||
@@ -53,7 +50,6 @@ public class ModemPluginTest extends BrambleMockTestCase {
|
||||
will(returnValue(modem));
|
||||
oneOf(modem).start();
|
||||
will(returnValue(true));
|
||||
oneOf(callback).pluginStateChanged(ACTIVE);
|
||||
}});
|
||||
|
||||
plugin.start();
|
||||
@@ -69,14 +65,12 @@ public class ModemPluginTest extends BrambleMockTestCase {
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
// start()
|
||||
oneOf(callback).pluginStateChanged(ENABLING);
|
||||
oneOf(serialPortList).getPortNames();
|
||||
will(returnValue(new String[] {"foo"}));
|
||||
oneOf(modemFactory).createModem(plugin, "foo");
|
||||
will(returnValue(modem));
|
||||
oneOf(modem).start();
|
||||
will(returnValue(true));
|
||||
oneOf(callback).pluginStateChanged(ACTIVE);
|
||||
// createConnection()
|
||||
oneOf(callback).getLocalProperties();
|
||||
will(returnValue(local));
|
||||
@@ -99,14 +93,12 @@ public class ModemPluginTest extends BrambleMockTestCase {
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
// start()
|
||||
oneOf(callback).pluginStateChanged(ENABLING);
|
||||
oneOf(serialPortList).getPortNames();
|
||||
will(returnValue(new String[] {"foo"}));
|
||||
oneOf(modemFactory).createModem(plugin, "foo");
|
||||
will(returnValue(modem));
|
||||
oneOf(modem).start();
|
||||
will(returnValue(true));
|
||||
oneOf(callback).pluginStateChanged(ACTIVE);
|
||||
// createConnection()
|
||||
oneOf(callback).getLocalProperties();
|
||||
will(returnValue(local));
|
||||
@@ -129,14 +121,12 @@ public class ModemPluginTest extends BrambleMockTestCase {
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
// start()
|
||||
oneOf(callback).pluginStateChanged(ENABLING);
|
||||
oneOf(serialPortList).getPortNames();
|
||||
will(returnValue(new String[] {"foo"}));
|
||||
oneOf(modemFactory).createModem(plugin, "foo");
|
||||
will(returnValue(modem));
|
||||
oneOf(modem).start();
|
||||
will(returnValue(true));
|
||||
oneOf(callback).pluginStateChanged(ACTIVE);
|
||||
// createConnection()
|
||||
oneOf(callback).getLocalProperties();
|
||||
will(returnValue(local));
|
||||
|
||||
@@ -32,7 +32,6 @@ import javax.net.SocketFactory;
|
||||
import static java.util.Collections.singletonList;
|
||||
import static java.util.concurrent.TimeUnit.SECONDS;
|
||||
import static java.util.logging.Logger.getLogger;
|
||||
import static org.briarproject.bramble.api.plugin.Plugin.State.ACTIVE;
|
||||
import static org.briarproject.bramble.test.TestUtils.deleteTestDirectory;
|
||||
import static org.briarproject.bramble.test.TestUtils.getTestDirectory;
|
||||
import static org.briarproject.bramble.test.TestUtils.isOptionalTestEnabled;
|
||||
@@ -142,10 +141,10 @@ public class BridgeTest extends BrambleTestCase {
|
||||
plugin.start();
|
||||
long start = clock.currentTimeMillis();
|
||||
while (clock.currentTimeMillis() - start < TIMEOUT) {
|
||||
if (plugin.getState() == ACTIVE) return;
|
||||
if (plugin.isRunning()) return;
|
||||
clock.sleep(500);
|
||||
}
|
||||
if (plugin.getState() != ACTIVE) {
|
||||
if (!plugin.isRunning()) {
|
||||
fail("Could not connect to Tor within timeout.");
|
||||
}
|
||||
} finally {
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package org.briarproject.bramble.plugin.tor;
|
||||
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.plugin.Plugin.State;
|
||||
import org.briarproject.bramble.api.plugin.PluginCallback;
|
||||
import org.briarproject.bramble.api.plugin.TransportConnectionReader;
|
||||
import org.briarproject.bramble.api.plugin.TransportConnectionWriter;
|
||||
@@ -31,7 +30,11 @@ public class TestPluginCallback implements PluginCallback {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void pluginStateChanged(State state) {
|
||||
public void transportEnabled() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void transportDisabled() {
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -22,8 +22,8 @@ android {
|
||||
defaultConfig {
|
||||
minSdkVersion 16
|
||||
targetSdkVersion 28
|
||||
versionCode 10209
|
||||
versionName "1.2.9"
|
||||
versionCode 10207
|
||||
versionName "1.2.7"
|
||||
applicationId "org.briarproject.briar.android"
|
||||
buildConfigField "String", "GitHash",
|
||||
"\"${getStdout(['git', 'rev-parse', '--short=7', 'HEAD'], 'No commit hash')}\""
|
||||
|
||||
@@ -164,7 +164,7 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager,
|
||||
nc.setLockscreenVisibility(VISIBILITY_SECRET);
|
||||
nc.enableVibration(true);
|
||||
nc.enableLights(true);
|
||||
nc.setLightColor(getColor(appContext, R.color.briar_lime_400));
|
||||
nc.setLightColor(getColor(appContext, R.color.briar_green_light));
|
||||
notificationManager.createNotificationChannel(nc);
|
||||
}
|
||||
|
||||
|
||||
@@ -41,7 +41,6 @@ import org.briarproject.bramble.util.StringUtils;
|
||||
import org.briarproject.briar.android.account.LockManagerImpl;
|
||||
import org.briarproject.briar.android.keyagreement.ContactExchangeModule;
|
||||
import org.briarproject.briar.android.login.LoginModule;
|
||||
import org.briarproject.briar.android.navdrawer.NavDrawerModule;
|
||||
import org.briarproject.briar.android.viewmodel.ViewModelModule;
|
||||
import org.briarproject.briar.api.android.AndroidNotificationManager;
|
||||
import org.briarproject.briar.api.android.DozeWatchdog;
|
||||
@@ -77,7 +76,6 @@ import static org.briarproject.briar.android.TestingConstants.IS_DEBUG_BUILD;
|
||||
@Module(includes = {
|
||||
ContactExchangeModule.class,
|
||||
LoginModule.class,
|
||||
NavDrawerModule.class,
|
||||
ViewModelModule.class
|
||||
})
|
||||
public class AppModule {
|
||||
@@ -136,8 +134,8 @@ public class AppModule {
|
||||
TimeoutMonitor timeoutMonitor) {
|
||||
Context appContext = app.getApplicationContext();
|
||||
DuplexPluginFactory bluetooth = new AndroidBluetoothPluginFactory(
|
||||
ioExecutor, scheduler, androidExecutor, appContext, random,
|
||||
eventBus, clock, timeoutMonitor, backoffFactory);
|
||||
ioExecutor, androidExecutor, appContext, random, eventBus,
|
||||
clock, timeoutMonitor, backoffFactory);
|
||||
DuplexPluginFactory tor = new AndroidTorPluginFactory(ioExecutor,
|
||||
scheduler, appContext, networkManager, locationUtils, eventBus,
|
||||
torSocketFactory, backoffFactory, resourceProvider,
|
||||
|
||||
@@ -8,6 +8,8 @@ import org.briarproject.briar.android.controller.BriarController;
|
||||
import org.briarproject.briar.android.controller.BriarControllerImpl;
|
||||
import org.briarproject.briar.android.controller.DbController;
|
||||
import org.briarproject.briar.android.controller.DbControllerImpl;
|
||||
import org.briarproject.briar.android.navdrawer.NavDrawerController;
|
||||
import org.briarproject.briar.android.navdrawer.NavDrawerControllerImpl;
|
||||
|
||||
import dagger.Module;
|
||||
import dagger.Provides;
|
||||
@@ -56,6 +58,14 @@ public class ActivityModule {
|
||||
return dbController;
|
||||
}
|
||||
|
||||
@ActivityScope
|
||||
@Provides
|
||||
NavDrawerController provideNavDrawerController(
|
||||
NavDrawerControllerImpl navDrawerController) {
|
||||
activity.addLifecycleController(navDrawerController);
|
||||
return navDrawerController;
|
||||
}
|
||||
|
||||
@ActivityScope
|
||||
@Provides
|
||||
BriarServiceConnection provideBriarServiceConnection() {
|
||||
|
||||
@@ -3,6 +3,7 @@ package org.briarproject.briar.android.contact.add.remote;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface.OnClickListener;
|
||||
import android.content.Intent;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Bundle;
|
||||
import android.text.Editable;
|
||||
import android.view.LayoutInflater;
|
||||
@@ -37,10 +38,12 @@ import androidx.lifecycle.ViewModelProviders;
|
||||
import static android.view.View.INVISIBLE;
|
||||
import static android.view.View.VISIBLE;
|
||||
import static android.widget.Toast.LENGTH_LONG;
|
||||
import static androidx.core.content.ContextCompat.getColor;
|
||||
import static androidx.core.content.ContextCompat.getDrawable;
|
||||
import static androidx.core.graphics.drawable.DrawableCompat.setTint;
|
||||
import static java.util.Objects.requireNonNull;
|
||||
import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_AUTHOR_NAME_LENGTH;
|
||||
import static org.briarproject.bramble.util.StringUtils.utf8IsTooLong;
|
||||
import static org.briarproject.briar.android.util.UiUtils.getDialogIcon;
|
||||
|
||||
@MethodsNotNullByDefault
|
||||
@ParametersNotNullByDefault
|
||||
@@ -196,7 +199,9 @@ public class NicknameFragment extends BaseFragment {
|
||||
private void showWarningDialog(String name1, String name2) {
|
||||
Context ctx = requireContext();
|
||||
Builder b = new Builder(ctx, R.style.BriarDialogTheme);
|
||||
b.setIcon(getDialogIcon(ctx, R.drawable.alerts_and_states_error));
|
||||
Drawable icon = getDrawable(ctx, R.drawable.alerts_and_states_error);
|
||||
setTint(requireNonNull(icon), getColor(ctx, R.color.color_primary));
|
||||
b.setIcon(icon);
|
||||
b.setTitle(getString(R.string.duplicate_link_dialog_title));
|
||||
b.setMessage(
|
||||
getString(R.string.duplicate_link_dialog_text_3, name1, name2));
|
||||
|
||||
@@ -76,7 +76,7 @@ public class PendingContactListActivity extends BriarActivity
|
||||
list.showProgressBar();
|
||||
|
||||
offlineSnackbar = new BriarSnackbarBuilder()
|
||||
.setBackgroundColor(R.color.briar_red_500)
|
||||
.setBackgroundColor(R.color.briar_red)
|
||||
.make(list, R.string.offline_state, LENGTH_INDEFINITE);
|
||||
}
|
||||
|
||||
|
||||
@@ -46,11 +46,11 @@ class PendingContactViewHolder extends ViewHolder {
|
||||
});
|
||||
|
||||
int color = ContextCompat
|
||||
.getColor(status.getContext(), R.color.briar_lime_600);
|
||||
.getColor(status.getContext(), R.color.briar_green);
|
||||
switch (item.getState()) {
|
||||
case WAITING_FOR_CONNECTION:
|
||||
color = ContextCompat.getColor(status.getContext(),
|
||||
R.color.briar_orange_500);
|
||||
color = ContextCompat
|
||||
.getColor(status.getContext(), R.color.briar_yellow);
|
||||
status.setText(R.string.waiting_for_contact_to_come_online);
|
||||
break;
|
||||
case OFFLINE:
|
||||
@@ -64,7 +64,7 @@ class PendingContactViewHolder extends ViewHolder {
|
||||
break;
|
||||
case FAILED:
|
||||
color = ContextCompat
|
||||
.getColor(status.getContext(), R.color.briar_red_500);
|
||||
.getColor(status.getContext(), R.color.briar_red);
|
||||
status.setText(R.string.adding_contact_failed);
|
||||
break;
|
||||
default:
|
||||
|
||||
@@ -41,8 +41,7 @@ class ConversationMessageViewHolder extends ConversationItemViewHolder {
|
||||
|
||||
// remember original status text color
|
||||
timeColor = time.getCurrentTextColor();
|
||||
timeColorBubble =
|
||||
getColor(v.getContext(), R.color.msg_status_bubble_foreground);
|
||||
timeColorBubble = getColor(v.getContext(), R.color.briar_white);
|
||||
|
||||
// clone constraint sets from layout files
|
||||
textConstraints.clone(v.getContext(),
|
||||
|
||||
@@ -230,11 +230,7 @@ class ConversationVisitor implements
|
||||
R.layout.list_item_conversation_notice_out, text, r);
|
||||
} else {
|
||||
String text;
|
||||
if (r.wasAnswered()) {
|
||||
text = ctx.getString(
|
||||
R.string.introduction_request_answered_received,
|
||||
contactName.getValue(), name);
|
||||
} else if (r.isContact()) {
|
||||
if (r.isContact()) {
|
||||
text = ctx.getString(
|
||||
R.string.introduction_request_exists_received,
|
||||
contactName.getValue(), name);
|
||||
|
||||
@@ -2,6 +2,7 @@ package org.briarproject.briar.android.conversation;
|
||||
|
||||
import android.content.DialogInterface.OnClickListener;
|
||||
import android.content.Intent;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Bundle;
|
||||
import android.transition.Fade;
|
||||
import android.transition.Transition;
|
||||
@@ -34,6 +35,8 @@ import androidx.annotation.Nullable;
|
||||
import androidx.annotation.RequiresApi;
|
||||
import androidx.appcompat.app.AlertDialog.Builder;
|
||||
import androidx.appcompat.widget.Toolbar;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.core.graphics.drawable.DrawableCompat;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
import androidx.fragment.app.FragmentStatePagerAdapter;
|
||||
@@ -56,7 +59,6 @@ import static com.google.android.material.snackbar.Snackbar.LENGTH_LONG;
|
||||
import static java.util.Objects.requireNonNull;
|
||||
import static org.briarproject.briar.android.activity.RequestCodes.REQUEST_SAVE_ATTACHMENT;
|
||||
import static org.briarproject.briar.android.util.UiUtils.formatDateAbsolute;
|
||||
import static org.briarproject.briar.android.util.UiUtils.getDialogIcon;
|
||||
|
||||
@MethodsNotNullByDefault
|
||||
@ParametersNotNullByDefault
|
||||
@@ -276,7 +278,10 @@ public class ImageActivity extends BriarActivity
|
||||
Builder builder = new Builder(this, R.style.BriarDialogTheme);
|
||||
builder.setTitle(getString(R.string.dialog_title_save_image));
|
||||
builder.setMessage(getString(R.string.dialog_message_save_image));
|
||||
builder.setIcon(getDialogIcon(this, R.drawable.ic_security));
|
||||
Drawable icon = ContextCompat.getDrawable(this, R.drawable.ic_security);
|
||||
DrawableCompat.setTint(requireNonNull(icon),
|
||||
ContextCompat.getColor(this, R.color.color_primary));
|
||||
builder.setIcon(icon);
|
||||
builder.setPositiveButton(R.string.save_image, okListener);
|
||||
builder.setNegativeButton(R.string.cancel, null);
|
||||
builder.show();
|
||||
@@ -299,7 +304,7 @@ public class ImageActivity extends BriarActivity
|
||||
int stringRes = error ?
|
||||
R.string.save_image_error : R.string.save_image_success;
|
||||
int colorRes = error ?
|
||||
R.color.briar_red_500 : R.color.briar_primary;
|
||||
R.color.briar_red : R.color.briar_primary;
|
||||
new BriarSnackbarBuilder()
|
||||
.setBackgroundColor(colorRes)
|
||||
.make(layout, stringRes, LENGTH_LONG)
|
||||
|
||||
@@ -9,7 +9,6 @@ import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
|
||||
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
||||
import org.briarproject.briar.R;
|
||||
import org.briarproject.briar.android.activity.ActivityComponent;
|
||||
import org.briarproject.briar.android.fragment.BaseFragment;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import javax.inject.Inject;
|
||||
@@ -80,13 +79,13 @@ public class ContactExchangeActivity extends KeyAgreementActivity {
|
||||
|
||||
@UiThread
|
||||
private void contactExchangeFailed() {
|
||||
showErrorFragment();
|
||||
showErrorFragment(R.string.connection_error_explanation);
|
||||
}
|
||||
|
||||
@UiThread
|
||||
@Override
|
||||
public void keyAgreementFailed() {
|
||||
showErrorFragment();
|
||||
showErrorFragment(R.string.connection_error_explanation);
|
||||
}
|
||||
|
||||
@UiThread
|
||||
@@ -104,7 +103,7 @@ public class ContactExchangeActivity extends KeyAgreementActivity {
|
||||
@UiThread
|
||||
@Override
|
||||
public void keyAgreementAborted(boolean remoteAborted) {
|
||||
showErrorFragment();
|
||||
showErrorFragment(R.string.connection_error_explanation);
|
||||
}
|
||||
|
||||
@UiThread
|
||||
@@ -113,10 +112,4 @@ public class ContactExchangeActivity extends KeyAgreementActivity {
|
||||
startContactExchange(result);
|
||||
return getString(R.string.exchanging_contact_details);
|
||||
}
|
||||
|
||||
protected void showErrorFragment() {
|
||||
String errorMsg = getString(R.string.connection_error_explanation);
|
||||
BaseFragment f = ContactExchangeErrorFragment.newInstance(errorMsg);
|
||||
showNextFragment(f);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,18 +8,10 @@ import android.content.IntentFilter;
|
||||
import android.os.Bundle;
|
||||
import android.view.MenuItem;
|
||||
|
||||
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.nullsafety.MethodsNotNullByDefault;
|
||||
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
||||
import org.briarproject.bramble.api.plugin.BluetoothConstants;
|
||||
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.event.BluetoothEnabledEvent;
|
||||
import org.briarproject.bramble.api.plugin.event.TransportStateEvent;
|
||||
import org.briarproject.briar.R;
|
||||
import org.briarproject.briar.android.activity.ActivityComponent;
|
||||
import org.briarproject.briar.android.activity.BriarActivity;
|
||||
@@ -45,15 +37,13 @@ import static android.Manifest.permission.ACCESS_COARSE_LOCATION;
|
||||
import static android.Manifest.permission.CAMERA;
|
||||
import static android.bluetooth.BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE;
|
||||
import static android.bluetooth.BluetoothAdapter.ACTION_SCAN_MODE_CHANGED;
|
||||
import static android.bluetooth.BluetoothAdapter.ACTION_STATE_CHANGED;
|
||||
import static android.bluetooth.BluetoothAdapter.EXTRA_SCAN_MODE;
|
||||
import static android.bluetooth.BluetoothAdapter.EXTRA_STATE;
|
||||
import static android.bluetooth.BluetoothAdapter.SCAN_MODE_CONNECTABLE;
|
||||
import static android.bluetooth.BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE;
|
||||
import static android.bluetooth.BluetoothAdapter.STATE_ON;
|
||||
import static android.content.pm.PackageManager.PERMISSION_GRANTED;
|
||||
import static java.util.logging.Level.INFO;
|
||||
import static java.util.logging.Logger.getLogger;
|
||||
import static org.briarproject.bramble.api.nullsafety.NullSafety.requireNonNull;
|
||||
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.Plugin.State.STARTING_STOPPING;
|
||||
import static org.briarproject.briar.android.activity.RequestCodes.REQUEST_BLUETOOTH_DISCOVERABLE;
|
||||
import static org.briarproject.briar.android.activity.RequestCodes.REQUEST_PERMISSION_CAMERA_LOCATION;
|
||||
|
||||
@@ -61,33 +51,10 @@ import static org.briarproject.briar.android.activity.RequestCodes.REQUEST_PERMI
|
||||
@ParametersNotNullByDefault
|
||||
public abstract class KeyAgreementActivity extends BriarActivity implements
|
||||
BaseFragmentListener, IntroScreenSeenListener,
|
||||
KeyAgreementEventListener, EventListener {
|
||||
KeyAgreementEventListener {
|
||||
|
||||
private enum BluetoothDecision {
|
||||
/**
|
||||
* We haven't asked the user about Bluetooth discoverability.
|
||||
*/
|
||||
UNKNOWN,
|
||||
|
||||
/**
|
||||
* The device doesn't have a Bluetooth adapter.
|
||||
*/
|
||||
NO_ADAPTER,
|
||||
|
||||
/**
|
||||
* We're waiting for the user to accept or refuse discoverability.
|
||||
*/
|
||||
WAITING,
|
||||
|
||||
/**
|
||||
* The user has accepted discoverability.
|
||||
*/
|
||||
ACCEPTED,
|
||||
|
||||
/**
|
||||
* The user has refused discoverability.
|
||||
*/
|
||||
REFUSED
|
||||
private enum BluetoothState {
|
||||
UNKNOWN, NO_ADAPTER, WAITING, REFUSED, ENABLED, DISCOVERABLE
|
||||
}
|
||||
|
||||
private enum Permission {
|
||||
@@ -95,14 +62,11 @@ public abstract class KeyAgreementActivity extends BriarActivity implements
|
||||
}
|
||||
|
||||
private static final Logger LOG =
|
||||
getLogger(KeyAgreementActivity.class.getName());
|
||||
Logger.getLogger(KeyAgreementActivity.class.getName());
|
||||
|
||||
@Inject
|
||||
EventBus eventBus;
|
||||
|
||||
@Inject
|
||||
PluginManager pluginManager;
|
||||
|
||||
/**
|
||||
* Set to true in onPostResume() and false in onPause(). This prevents the
|
||||
* QR code fragment from being shown if onRequestPermissionsResult() is
|
||||
@@ -110,36 +74,21 @@ public abstract class KeyAgreementActivity extends BriarActivity implements
|
||||
* https://issuetracker.google.com/issues/37067655.
|
||||
*/
|
||||
private boolean isResumed = false;
|
||||
|
||||
/**
|
||||
* Set to true when the continue button is clicked, and false when the QR
|
||||
* code fragment is shown. This prevents the QR code fragment from being
|
||||
* shown automatically before the continue button has been clicked.
|
||||
*/
|
||||
private boolean continueClicked = false;
|
||||
|
||||
/**
|
||||
* Records whether the Bluetooth adapter was already enabled before we
|
||||
* asked for Bluetooth discoverability, so we know whether to broadcast a
|
||||
* {@link BluetoothEnabledEvent}.
|
||||
*/
|
||||
private boolean wasAdapterEnabled = false;
|
||||
|
||||
/**
|
||||
* Records whether we've enabled the wifi plugin so we don't enable it more
|
||||
* than once.
|
||||
*/
|
||||
private boolean hasEnabledWifi = false;
|
||||
|
||||
/**
|
||||
* Records whether we've enabled the Bluetooth plugin so we don't enable it
|
||||
* more than once.
|
||||
*/
|
||||
private boolean hasEnabledBluetooth = false;
|
||||
|
||||
private Permission cameraPermission = Permission.UNKNOWN;
|
||||
private Permission locationPermission = Permission.UNKNOWN;
|
||||
private BluetoothDecision bluetoothDecision = BluetoothDecision.UNKNOWN;
|
||||
private BluetoothState bluetoothState = BluetoothState.UNKNOWN;
|
||||
private BroadcastReceiver bluetoothReceiver = null;
|
||||
|
||||
@Override
|
||||
@@ -147,17 +96,20 @@ public abstract class KeyAgreementActivity extends BriarActivity implements
|
||||
component.inject(this);
|
||||
}
|
||||
|
||||
@SuppressWarnings("ConstantConditions")
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle state) {
|
||||
super.onCreate(state);
|
||||
setContentView(R.layout.activity_fragment_container_toolbar);
|
||||
Toolbar toolbar = findViewById(R.id.toolbar);
|
||||
setSupportActionBar(toolbar);
|
||||
requireNonNull(getSupportActionBar()).setDisplayHomeAsUpEnabled(true);
|
||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
if (state == null) {
|
||||
showInitialFragment(IntroFragment.newInstance());
|
||||
}
|
||||
IntentFilter filter = new IntentFilter(ACTION_SCAN_MODE_CHANGED);
|
||||
IntentFilter filter = new IntentFilter();
|
||||
filter.addAction(ACTION_STATE_CHANGED);
|
||||
filter.addAction(ACTION_SCAN_MODE_CHANGED);
|
||||
bluetoothReceiver = new BluetoothStateReceiver();
|
||||
registerReceiver(bluetoothReceiver, filter);
|
||||
}
|
||||
@@ -170,17 +122,18 @@ public abstract class KeyAgreementActivity extends BriarActivity implements
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
if (item.getItemId() == android.R.id.home) {
|
||||
onBackPressed();
|
||||
return true;
|
||||
switch (item.getItemId()) {
|
||||
case android.R.id.home:
|
||||
onBackPressed();
|
||||
return true;
|
||||
default:
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
eventBus.addListener(this);
|
||||
// Permissions may have been granted manually while we were stopped
|
||||
cameraPermission = Permission.UNKNOWN;
|
||||
locationPermission = Permission.UNKNOWN;
|
||||
@@ -197,22 +150,11 @@ public abstract class KeyAgreementActivity extends BriarActivity implements
|
||||
|
||||
private void showQrCodeFragmentIfAllowed() {
|
||||
if (isResumed && continueClicked && areEssentialPermissionsGranted()) {
|
||||
if (isWifiReady() && isBluetoothReady()) {
|
||||
LOG.info("Wifi and Bluetooth are ready");
|
||||
if (bluetoothState == BluetoothState.UNKNOWN ||
|
||||
bluetoothState == BluetoothState.ENABLED) {
|
||||
requestBluetoothDiscoverable();
|
||||
} else if (bluetoothState != BluetoothState.WAITING) {
|
||||
showQrCodeFragment();
|
||||
} else {
|
||||
if (shouldEnableWifi()) {
|
||||
LOG.info("Enabling wifi plugin");
|
||||
hasEnabledWifi = true;
|
||||
pluginManager.setPluginEnabled(LanTcpConstants.ID, true);
|
||||
}
|
||||
if (bluetoothDecision == BluetoothDecision.UNKNOWN) {
|
||||
requestBluetoothDiscoverable();
|
||||
} else if (shouldEnableBluetooth()) {
|
||||
LOG.info("Enabling Bluetooth plugin");
|
||||
hasEnabledBluetooth = true;
|
||||
pluginManager.setPluginEnabled(BluetoothConstants.ID, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -225,108 +167,57 @@ public abstract class KeyAgreementActivity extends BriarActivity implements
|
||||
locationPermission == Permission.PERMANENTLY_DENIED);
|
||||
}
|
||||
|
||||
private boolean isWifiReady() {
|
||||
Plugin p = pluginManager.getPlugin(LanTcpConstants.ID);
|
||||
if (p == null) return true; // Continue without wifi
|
||||
State state = p.getState();
|
||||
// Wait for plugin to become enabled
|
||||
return state == ACTIVE || state == INACTIVE;
|
||||
}
|
||||
|
||||
private boolean isBluetoothReady() {
|
||||
if (bluetoothDecision == BluetoothDecision.UNKNOWN ||
|
||||
bluetoothDecision == BluetoothDecision.WAITING) {
|
||||
// Wait for decision
|
||||
return false;
|
||||
}
|
||||
if (bluetoothDecision == BluetoothDecision.NO_ADAPTER
|
||||
|| bluetoothDecision == BluetoothDecision.REFUSED) {
|
||||
// Continue without Bluetooth
|
||||
return true;
|
||||
}
|
||||
BluetoothAdapter bt = BluetoothAdapter.getDefaultAdapter();
|
||||
if (bt == null) return true; // Continue without Bluetooth
|
||||
if (bt.getScanMode() != SCAN_MODE_CONNECTABLE_DISCOVERABLE) {
|
||||
// Wait for adapter to become discoverable
|
||||
return false;
|
||||
}
|
||||
Plugin p = pluginManager.getPlugin(BluetoothConstants.ID);
|
||||
if (p == null) return true; // Continue without Bluetooth
|
||||
// Wait for plugin to become active
|
||||
return p.getState() == ACTIVE;
|
||||
}
|
||||
|
||||
private boolean shouldEnableWifi() {
|
||||
if (hasEnabledWifi) return false;
|
||||
Plugin p = pluginManager.getPlugin(LanTcpConstants.ID);
|
||||
if (p == null) return false;
|
||||
State state = p.getState();
|
||||
return state == STARTING_STOPPING || state == DISABLED;
|
||||
}
|
||||
|
||||
private void requestBluetoothDiscoverable() {
|
||||
BluetoothAdapter bt = BluetoothAdapter.getDefaultAdapter();
|
||||
if (bt == null) {
|
||||
bluetoothDecision = BluetoothDecision.NO_ADAPTER;
|
||||
showQrCodeFragmentIfAllowed();
|
||||
} else {
|
||||
Intent i = new Intent(ACTION_REQUEST_DISCOVERABLE);
|
||||
if (i.resolveActivity(getPackageManager()) != null) {
|
||||
LOG.info("Asking for Bluetooth discoverability");
|
||||
bluetoothDecision = BluetoothDecision.WAITING;
|
||||
wasAdapterEnabled = bt.isEnabled();
|
||||
startActivityForResult(i, REQUEST_BLUETOOTH_DISCOVERABLE);
|
||||
} else {
|
||||
bluetoothDecision = BluetoothDecision.NO_ADAPTER;
|
||||
showQrCodeFragmentIfAllowed();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean shouldEnableBluetooth() {
|
||||
if (bluetoothDecision != BluetoothDecision.ACCEPTED) return false;
|
||||
if (hasEnabledBluetooth) return false;
|
||||
Plugin p = pluginManager.getPlugin(BluetoothConstants.ID);
|
||||
if (p == null) return false;
|
||||
State state = p.getState();
|
||||
return state == STARTING_STOPPING || state == DISABLED;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
isResumed = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop() {
|
||||
super.onStop();
|
||||
eventBus.removeListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showNextScreen() {
|
||||
continueClicked = true;
|
||||
if (checkPermissions()) showQrCodeFragmentIfAllowed();
|
||||
}
|
||||
|
||||
private void requestBluetoothDiscoverable() {
|
||||
BluetoothAdapter bt = BluetoothAdapter.getDefaultAdapter();
|
||||
if (bt == null) {
|
||||
setBluetoothState(BluetoothState.NO_ADAPTER);
|
||||
} else {
|
||||
Intent i = new Intent(ACTION_REQUEST_DISCOVERABLE);
|
||||
if (i.resolveActivity(getPackageManager()) != null) {
|
||||
setBluetoothState(BluetoothState.WAITING);
|
||||
wasAdapterEnabled = bt.isEnabled();
|
||||
startActivityForResult(i, REQUEST_BLUETOOTH_DISCOVERABLE);
|
||||
} else {
|
||||
setBluetoothState(BluetoothState.NO_ADAPTER);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void setBluetoothState(BluetoothState bluetoothState) {
|
||||
LOG.info("Setting Bluetooth state to " + bluetoothState);
|
||||
this.bluetoothState = bluetoothState;
|
||||
if (!wasAdapterEnabled && bluetoothState == BluetoothState.ENABLED) {
|
||||
eventBus.broadcast(new BluetoothEnabledEvent());
|
||||
wasAdapterEnabled = true;
|
||||
}
|
||||
showQrCodeFragmentIfAllowed();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityResult(int request, int result,
|
||||
@Nullable Intent data) {
|
||||
public void onActivityResult(int request, int result, Intent data) {
|
||||
if (request == REQUEST_BLUETOOTH_DISCOVERABLE) {
|
||||
if (result == RESULT_CANCELED) {
|
||||
LOG.info("Bluetooth discoverability was refused");
|
||||
bluetoothDecision = BluetoothDecision.REFUSED;
|
||||
setBluetoothState(BluetoothState.REFUSED);
|
||||
} else {
|
||||
LOG.info("Bluetooth discoverability was accepted");
|
||||
bluetoothDecision = BluetoothDecision.ACCEPTED;
|
||||
if (!wasAdapterEnabled) {
|
||||
LOG.info("Bluetooth adapter was enabled by us");
|
||||
eventBus.broadcast(new BluetoothEnabledEvent());
|
||||
wasAdapterEnabled = true;
|
||||
}
|
||||
// If Bluetooth is already discoverable, show the QR code -
|
||||
// otherwise wait for the state or scan mode to change
|
||||
BluetoothAdapter bt = BluetoothAdapter.getDefaultAdapter();
|
||||
if (bt == null) throw new AssertionError();
|
||||
if (bt.getScanMode() == SCAN_MODE_CONNECTABLE_DISCOVERABLE)
|
||||
setBluetoothState(BluetoothState.DISCOVERABLE);
|
||||
}
|
||||
showQrCodeFragmentIfAllowed();
|
||||
} else super.onActivityResult(request, result, data);
|
||||
}
|
||||
|
||||
@@ -336,12 +227,7 @@ public abstract class KeyAgreementActivity extends BriarActivity implements
|
||||
continueClicked = false;
|
||||
// If we return to the intro fragment, ask for Bluetooth
|
||||
// discoverability again before showing the QR code fragment
|
||||
bluetoothDecision = BluetoothDecision.UNKNOWN;
|
||||
// If we return to the intro fragment, we may need to enable wifi and
|
||||
// Bluetooth again
|
||||
hasEnabledWifi = false;
|
||||
hasEnabledBluetooth = false;
|
||||
|
||||
bluetoothState = BluetoothState.UNKNOWN;
|
||||
// FIXME #824
|
||||
FragmentManager fm = getSupportFragmentManager();
|
||||
if (fm.findFragmentByTag(KeyAgreementFragment.TAG) == null) {
|
||||
@@ -353,6 +239,12 @@ public abstract class KeyAgreementActivity extends BriarActivity implements
|
||||
}
|
||||
}
|
||||
|
||||
protected void showErrorFragment(@StringRes int errorResId) {
|
||||
String errorMsg = getString(errorResId);
|
||||
BaseFragment f = ContactExchangeErrorFragment.newInstance(errorMsg);
|
||||
showNextFragment(f);
|
||||
}
|
||||
|
||||
private boolean checkPermissions() {
|
||||
if (areEssentialPermissionsGranted()) return true;
|
||||
// If the camera permission has been permanently denied, ask the
|
||||
@@ -443,30 +335,24 @@ public abstract class KeyAgreementActivity extends BriarActivity implements
|
||||
permission);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void eventOccurred(Event e) {
|
||||
if (e instanceof TransportStateEvent) {
|
||||
TransportStateEvent t = (TransportStateEvent) e;
|
||||
if (t.getTransportId().equals(BluetoothConstants.ID)) {
|
||||
if (LOG.isLoggable(INFO)) {
|
||||
LOG.info("Bluetooth state changed to " + t.getState());
|
||||
}
|
||||
showQrCodeFragmentIfAllowed();
|
||||
} else if (t.getTransportId().equals(LanTcpConstants.ID)) {
|
||||
if (LOG.isLoggable(INFO)) {
|
||||
LOG.info("Wifi state changed to " + t.getState());
|
||||
}
|
||||
showQrCodeFragmentIfAllowed();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class BluetoothStateReceiver extends BroadcastReceiver {
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
LOG.info("Bluetooth scan mode changed");
|
||||
showQrCodeFragmentIfAllowed();
|
||||
String action = intent.getAction();
|
||||
if (ACTION_STATE_CHANGED.equals(action)) {
|
||||
int state = intent.getIntExtra(EXTRA_STATE, 0);
|
||||
if (state == STATE_ON)
|
||||
setBluetoothState(BluetoothState.ENABLED);
|
||||
else setBluetoothState(BluetoothState.UNKNOWN);
|
||||
} else if (ACTION_SCAN_MODE_CHANGED.equals(action)) {
|
||||
int scanMode = intent.getIntExtra(EXTRA_SCAN_MODE, 0);
|
||||
if (scanMode == SCAN_MODE_CONNECTABLE_DISCOVERABLE)
|
||||
setBluetoothState(BluetoothState.DISCOVERABLE);
|
||||
else if (scanMode == SCAN_MODE_CONNECTABLE)
|
||||
setBluetoothState(BluetoothState.ENABLED);
|
||||
else setBluetoothState(BluetoothState.UNKNOWN);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package org.briarproject.briar.android.navdrawer;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Intent;
|
||||
import android.content.res.Configuration;
|
||||
import android.net.Uri;
|
||||
@@ -22,7 +23,6 @@ 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.LanTcpConstants;
|
||||
import org.briarproject.bramble.api.plugin.Plugin.State;
|
||||
import org.briarproject.bramble.api.plugin.TorConstants;
|
||||
import org.briarproject.bramble.api.plugin.TransportId;
|
||||
import org.briarproject.briar.R;
|
||||
@@ -30,6 +30,7 @@ import org.briarproject.briar.android.activity.ActivityComponent;
|
||||
import org.briarproject.briar.android.activity.BriarActivity;
|
||||
import org.briarproject.briar.android.blog.FeedFragment;
|
||||
import org.briarproject.briar.android.contact.ContactListFragment;
|
||||
import org.briarproject.briar.android.controller.handler.UiResultHandler;
|
||||
import org.briarproject.briar.android.forum.ForumListFragment;
|
||||
import org.briarproject.briar.android.fragment.BaseFragment;
|
||||
import org.briarproject.briar.android.fragment.BaseFragment.BaseFragmentListener;
|
||||
@@ -43,11 +44,9 @@ import java.util.logging.Logger;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import androidx.annotation.ColorRes;
|
||||
import androidx.annotation.DrawableRes;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.StringRes;
|
||||
import androidx.annotation.UiThread;
|
||||
import androidx.appcompat.app.ActionBar;
|
||||
import androidx.appcompat.app.ActionBarDrawerToggle;
|
||||
import androidx.appcompat.widget.Toolbar;
|
||||
@@ -56,8 +55,6 @@ import androidx.core.content.ContextCompat;
|
||||
import androidx.drawerlayout.widget.DrawerLayout;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
import androidx.fragment.app.FragmentTransaction;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
import androidx.lifecycle.ViewModelProviders;
|
||||
|
||||
import static android.view.View.GONE;
|
||||
import static android.view.View.VISIBLE;
|
||||
@@ -67,11 +64,7 @@ import static androidx.fragment.app.FragmentManager.POP_BACK_STACK_INCLUSIVE;
|
||||
import static java.util.Objects.requireNonNull;
|
||||
import static java.util.logging.Logger.getLogger;
|
||||
import static org.briarproject.bramble.api.lifecycle.LifecycleManager.LifecycleState.RUNNING;
|
||||
import static org.briarproject.bramble.api.plugin.Plugin.State.ACTIVE;
|
||||
import static org.briarproject.bramble.api.plugin.Plugin.State.ENABLING;
|
||||
import static org.briarproject.bramble.api.plugin.Plugin.State.STARTING_STOPPING;
|
||||
import static org.briarproject.briar.android.BriarService.EXTRA_STARTUP_FAILED;
|
||||
import static org.briarproject.briar.android.TestingConstants.IS_DEBUG_BUILD;
|
||||
import static org.briarproject.briar.android.activity.RequestCodes.REQUEST_PASSWORD;
|
||||
import static org.briarproject.briar.android.navdrawer.IntentRouter.handleExternalIntent;
|
||||
import static org.briarproject.briar.android.util.UiUtils.getDaysUntilExpiry;
|
||||
@@ -79,7 +72,8 @@ import static org.briarproject.briar.android.util.UiUtils.getDaysUntilExpiry;
|
||||
@MethodsNotNullByDefault
|
||||
@ParametersNotNullByDefault
|
||||
public class NavDrawerActivity extends BriarActivity implements
|
||||
BaseFragmentListener, OnNavigationItemSelectedListener {
|
||||
BaseFragmentListener, TransportStateListener,
|
||||
OnNavigationItemSelectedListener {
|
||||
|
||||
private static final Logger LOG =
|
||||
getLogger(NavDrawerActivity.class.getName());
|
||||
@@ -97,13 +91,10 @@ public class NavDrawerActivity extends BriarActivity implements
|
||||
public static Uri SIGN_OUT_URI =
|
||||
Uri.parse("briar-content://org.briarproject.briar/sign-out");
|
||||
|
||||
private NavDrawerViewModel navDrawerViewModel;
|
||||
private PluginViewModel pluginViewModel;
|
||||
private ActionBarDrawerToggle drawerToggle;
|
||||
|
||||
@Inject
|
||||
ViewModelProvider.Factory viewModelFactory;
|
||||
|
||||
NavDrawerController controller;
|
||||
@Inject
|
||||
LifecycleManager lifecycleManager;
|
||||
|
||||
@@ -124,19 +115,6 @@ public class NavDrawerActivity extends BriarActivity implements
|
||||
exitIfStartupFailed(getIntent());
|
||||
setContentView(R.layout.activity_nav_drawer);
|
||||
|
||||
ViewModelProvider provider =
|
||||
ViewModelProviders.of(this, viewModelFactory);
|
||||
navDrawerViewModel = provider.get(NavDrawerViewModel.class);
|
||||
pluginViewModel = provider.get(PluginViewModel.class);
|
||||
|
||||
if (IS_DEBUG_BUILD) {
|
||||
navDrawerViewModel.showExpiryWarning()
|
||||
.observe(this, this::showExpiryWarning);
|
||||
}
|
||||
navDrawerViewModel.shouldAskForDozeWhitelisting().observe(this, ask -> {
|
||||
if (ask) showDozeDialog(getString(R.string.setup_doze_intro));
|
||||
});
|
||||
|
||||
Toolbar toolbar = findViewById(R.id.toolbar);
|
||||
drawerLayout = findViewById(R.id.drawer_layout);
|
||||
navigation = findViewById(R.id.navigation);
|
||||
@@ -153,7 +131,7 @@ public class NavDrawerActivity extends BriarActivity implements
|
||||
drawerLayout.addDrawerListener(drawerToggle);
|
||||
navigation.setNavigationItemSelectedListener(this);
|
||||
|
||||
initializeTransports();
|
||||
initializeTransports(getLayoutInflater());
|
||||
transportsView.setAdapter(transportsAdapter);
|
||||
|
||||
lockManager.isLockable().observe(this, this::setLockVisible);
|
||||
@@ -171,10 +149,17 @@ public class NavDrawerActivity extends BriarActivity implements
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressLint("NewApi")
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
updateTransports();
|
||||
lockManager.checkIfLockable();
|
||||
if (IS_DEBUG_BUILD) navDrawerViewModel.checkExpiryWarning();
|
||||
controller.showExpiryWarning(new UiResultHandler<Boolean>(this) {
|
||||
@Override
|
||||
public void onResultUi(Boolean expiry) {
|
||||
if (expiry) showExpiryWarning();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -182,7 +167,16 @@ public class NavDrawerActivity extends BriarActivity implements
|
||||
@Nullable Intent data) {
|
||||
super.onActivityResult(request, result, data);
|
||||
if (request == REQUEST_PASSWORD && result == RESULT_OK) {
|
||||
navDrawerViewModel.checkDozeWhitelisting();
|
||||
controller.shouldAskForDozeWhitelisting(this,
|
||||
new UiResultHandler<Boolean>(this) {
|
||||
@Override
|
||||
public void onResultUi(Boolean ask) {
|
||||
if (ask) {
|
||||
showDozeDialog(
|
||||
getString(R.string.setup_doze_intro));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -352,38 +346,55 @@ public class NavDrawerActivity extends BriarActivity implements
|
||||
if (item != null) item.setVisible(visible);
|
||||
}
|
||||
|
||||
private void showExpiryWarning(boolean show) {
|
||||
long daysUntilExpiry = getDaysUntilExpiry();
|
||||
if (daysUntilExpiry < 0) {
|
||||
signOut();
|
||||
return;
|
||||
}
|
||||
private void showExpiryWarning() {
|
||||
int daysUntilExpiry = getDaysUntilExpiry();
|
||||
if (daysUntilExpiry < 0) signOut();
|
||||
|
||||
// show expiry warning text
|
||||
ViewGroup expiryWarning = findViewById(R.id.expiryWarning);
|
||||
if (show) {
|
||||
// show expiry warning text
|
||||
TextView expiryWarningText =
|
||||
expiryWarning.findViewById(R.id.expiryWarningText);
|
||||
String text = getResources().getQuantityString(
|
||||
R.plurals.expiry_warning, (int) daysUntilExpiry,
|
||||
(int) daysUntilExpiry);
|
||||
expiryWarningText.setText(text);
|
||||
// make close button functional
|
||||
ImageView expiryWarningClose =
|
||||
expiryWarning.findViewById(R.id.expiryWarningClose);
|
||||
expiryWarningClose.setOnClickListener(v ->
|
||||
navDrawerViewModel.expiryWarningDismissed());
|
||||
expiryWarning.setVisibility(VISIBLE);
|
||||
} else {
|
||||
TextView expiryWarningText =
|
||||
expiryWarning.findViewById(R.id.expiryWarningText);
|
||||
// make close button functional
|
||||
ImageView expiryWarningClose =
|
||||
expiryWarning.findViewById(R.id.expiryWarningClose);
|
||||
|
||||
expiryWarningText.setText(getResources()
|
||||
.getQuantityString(R.plurals.expiry_warning,
|
||||
daysUntilExpiry, daysUntilExpiry));
|
||||
|
||||
expiryWarningClose.setOnClickListener(v -> {
|
||||
controller.expiryWarningDismissed();
|
||||
expiryWarning.setVisibility(GONE);
|
||||
}
|
||||
});
|
||||
|
||||
expiryWarning.setVisibility(VISIBLE);
|
||||
}
|
||||
|
||||
private void initializeTransports() {
|
||||
private void initializeTransports(LayoutInflater inflater) {
|
||||
transports = new ArrayList<>(3);
|
||||
|
||||
transportsAdapter = new BaseAdapter() {
|
||||
Transport tor = new Transport();
|
||||
tor.id = TorConstants.ID;
|
||||
tor.enabled = controller.isTransportRunning(tor.id);
|
||||
tor.iconId = R.drawable.transport_tor;
|
||||
tor.textId = R.string.transport_tor;
|
||||
transports.add(tor);
|
||||
|
||||
Transport bt = new Transport();
|
||||
bt.id = BluetoothConstants.ID;
|
||||
bt.enabled = controller.isTransportRunning(bt.id);
|
||||
bt.iconId = R.drawable.transport_bt;
|
||||
bt.textId = R.string.transport_bt;
|
||||
transports.add(bt);
|
||||
|
||||
Transport lan = new Transport();
|
||||
lan.id = LanTcpConstants.ID;
|
||||
lan.enabled = controller.isTransportRunning(lan.id);
|
||||
lan.iconId = R.drawable.transport_lan;
|
||||
lan.textId = R.string.transport_lan;
|
||||
transports.add(lan);
|
||||
|
||||
transportsAdapter = new BaseAdapter() {
|
||||
@Override
|
||||
public int getCount() {
|
||||
return transports.size();
|
||||
@@ -406,67 +417,63 @@ public class NavDrawerActivity extends BriarActivity implements
|
||||
if (convertView != null) {
|
||||
view = convertView;
|
||||
} else {
|
||||
LayoutInflater inflater = getLayoutInflater();
|
||||
view = inflater.inflate(R.layout.list_item_transport,
|
||||
parent, false);
|
||||
}
|
||||
|
||||
Transport t = getItem(position);
|
||||
int c;
|
||||
if (t.enabled) {
|
||||
c = ContextCompat.getColor(NavDrawerActivity.this,
|
||||
R.color.briar_green_light);
|
||||
} else {
|
||||
c = ContextCompat.getColor(NavDrawerActivity.this,
|
||||
android.R.color.tertiary_text_light);
|
||||
}
|
||||
|
||||
ImageView icon = view.findViewById(R.id.imageView);
|
||||
icon.setImageDrawable(ContextCompat.getDrawable(
|
||||
NavDrawerActivity.this, t.iconDrawable));
|
||||
icon.setColorFilter(ContextCompat.getColor(
|
||||
NavDrawerActivity.this, t.iconColor));
|
||||
icon.setImageDrawable(ContextCompat
|
||||
.getDrawable(NavDrawerActivity.this, t.iconId));
|
||||
icon.setColorFilter(c);
|
||||
|
||||
TextView text = view.findViewById(R.id.textView);
|
||||
text.setText(getString(t.label));
|
||||
text.setText(getString(t.textId));
|
||||
|
||||
return view;
|
||||
}
|
||||
};
|
||||
|
||||
transports.add(createTransport(TorConstants.ID,
|
||||
R.drawable.transport_tor, R.string.transport_tor));
|
||||
transports.add(createTransport(LanTcpConstants.ID,
|
||||
R.drawable.transport_lan, R.string.transport_lan));
|
||||
transports.add(createTransport(BluetoothConstants.ID,
|
||||
R.drawable.transport_bt, R.string.transport_bt));
|
||||
}
|
||||
|
||||
@ColorRes
|
||||
private int getIconColor(State state) {
|
||||
if (state == ACTIVE) return R.color.briar_lime_400;
|
||||
else if (state == ENABLING) return R.color.briar_orange_500;
|
||||
else return android.R.color.tertiary_text_light;
|
||||
@UiThread
|
||||
private void setTransport(TransportId id, boolean enabled) {
|
||||
if (transports == null || transportsAdapter == null) return;
|
||||
for (Transport t : transports) {
|
||||
if (t.id.equals(id)) {
|
||||
t.enabled = enabled;
|
||||
transportsAdapter.notifyDataSetChanged();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Transport createTransport(TransportId id,
|
||||
@DrawableRes int iconDrawable, @StringRes int label) {
|
||||
int iconColor = getIconColor(STARTING_STOPPING);
|
||||
Transport transport = new Transport(iconDrawable, label, iconColor);
|
||||
pluginViewModel.getPluginState(id).observe(this, state -> {
|
||||
transport.iconColor = getIconColor(state);
|
||||
transportsAdapter.notifyDataSetChanged();
|
||||
});
|
||||
return transport;
|
||||
private void updateTransports() {
|
||||
if (transports == null || transportsAdapter == null) return;
|
||||
for (Transport t : transports) {
|
||||
t.enabled = controller.isTransportRunning(t.id);
|
||||
}
|
||||
transportsAdapter.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stateUpdate(TransportId id, boolean enabled) {
|
||||
setTransport(id, enabled);
|
||||
}
|
||||
|
||||
private static class Transport {
|
||||
|
||||
@DrawableRes
|
||||
private final int iconDrawable;
|
||||
@StringRes
|
||||
private final int label;
|
||||
|
||||
@ColorRes
|
||||
private int iconColor;
|
||||
|
||||
private Transport(@DrawableRes int iconDrawable, @StringRes int label,
|
||||
@ColorRes int iconColor) {
|
||||
this.iconDrawable = iconDrawable;
|
||||
this.label = label;
|
||||
this.iconColor = iconColor;
|
||||
}
|
||||
private TransportId id;
|
||||
private boolean enabled;
|
||||
private int iconId;
|
||||
private int textId;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
package org.briarproject.briar.android.navdrawer;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.plugin.TransportId;
|
||||
import org.briarproject.briar.android.controller.ActivityLifecycleController;
|
||||
import org.briarproject.briar.android.controller.handler.ResultHandler;
|
||||
|
||||
@NotNullByDefault
|
||||
public interface NavDrawerController extends ActivityLifecycleController {
|
||||
|
||||
boolean isTransportRunning(TransportId transportId);
|
||||
|
||||
void showExpiryWarning(ResultHandler<Boolean> handler);
|
||||
|
||||
void expiryWarningDismissed();
|
||||
|
||||
void shouldAskForDozeWhitelisting(Context ctx,
|
||||
ResultHandler<Boolean> handler);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,182 @@
|
||||
package org.briarproject.briar.android.navdrawer;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
|
||||
import org.briarproject.bramble.api.db.DatabaseExecutor;
|
||||
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.LifecycleManager;
|
||||
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
|
||||
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
||||
import org.briarproject.bramble.api.plugin.Plugin;
|
||||
import org.briarproject.bramble.api.plugin.PluginManager;
|
||||
import org.briarproject.bramble.api.plugin.TransportId;
|
||||
import org.briarproject.bramble.api.plugin.event.TransportDisabledEvent;
|
||||
import org.briarproject.bramble.api.plugin.event.TransportEnabledEvent;
|
||||
import org.briarproject.bramble.api.settings.Settings;
|
||||
import org.briarproject.bramble.api.settings.SettingsManager;
|
||||
import org.briarproject.briar.android.controller.DbControllerImpl;
|
||||
import org.briarproject.briar.android.controller.handler.ResultHandler;
|
||||
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import static java.util.concurrent.TimeUnit.DAYS;
|
||||
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.util.LogUtils.logException;
|
||||
import static org.briarproject.briar.android.TestingConstants.EXPIRY_DATE;
|
||||
import static org.briarproject.briar.android.TestingConstants.IS_DEBUG_BUILD;
|
||||
import static org.briarproject.briar.android.controller.BriarControllerImpl.DOZE_ASK_AGAIN;
|
||||
import static org.briarproject.briar.android.settings.SettingsFragment.SETTINGS_NAMESPACE;
|
||||
import static org.briarproject.briar.android.util.UiUtils.needsDozeWhitelisting;
|
||||
|
||||
@MethodsNotNullByDefault
|
||||
@ParametersNotNullByDefault
|
||||
public class NavDrawerControllerImpl extends DbControllerImpl
|
||||
implements NavDrawerController, EventListener {
|
||||
|
||||
private static final Logger LOG =
|
||||
getLogger(NavDrawerControllerImpl.class.getName());
|
||||
|
||||
private static final String EXPIRY_DATE_WARNING = "expiryDateWarning";
|
||||
|
||||
private final PluginManager pluginManager;
|
||||
private final SettingsManager settingsManager;
|
||||
private final EventBus eventBus;
|
||||
|
||||
// UI thread
|
||||
private TransportStateListener listener;
|
||||
|
||||
@Inject
|
||||
NavDrawerControllerImpl(@DatabaseExecutor Executor dbExecutor,
|
||||
LifecycleManager lifecycleManager, PluginManager pluginManager,
|
||||
SettingsManager settingsManager, EventBus eventBus) {
|
||||
super(dbExecutor, lifecycleManager);
|
||||
this.pluginManager = pluginManager;
|
||||
this.settingsManager = settingsManager;
|
||||
this.eventBus = eventBus;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityCreate(Activity activity) {
|
||||
listener = (TransportStateListener) activity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityStart() {
|
||||
eventBus.addListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityStop() {
|
||||
eventBus.removeListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityDestroy() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void eventOccurred(Event e) {
|
||||
if (e instanceof TransportEnabledEvent) {
|
||||
TransportId id = ((TransportEnabledEvent) e).getTransportId();
|
||||
if (LOG.isLoggable(INFO)) {
|
||||
LOG.info("TransportEnabledEvent: " + id.getString());
|
||||
}
|
||||
listener.stateUpdate(id, true);
|
||||
} else if (e instanceof TransportDisabledEvent) {
|
||||
TransportId id = ((TransportDisabledEvent) e).getTransportId();
|
||||
if (LOG.isLoggable(INFO)) {
|
||||
LOG.info("TransportDisabledEvent: " + id.getString());
|
||||
}
|
||||
listener.stateUpdate(id, false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showExpiryWarning(ResultHandler<Boolean> handler) {
|
||||
if (!IS_DEBUG_BUILD) {
|
||||
handler.onResult(false);
|
||||
return;
|
||||
}
|
||||
runOnDbThread(() -> {
|
||||
try {
|
||||
Settings settings =
|
||||
settingsManager.getSettings(SETTINGS_NAMESPACE);
|
||||
int warningInt = settings.getInt(EXPIRY_DATE_WARNING, 0);
|
||||
|
||||
if (warningInt == 0) {
|
||||
// we have not warned before
|
||||
handler.onResult(true);
|
||||
} else {
|
||||
long warningLong = warningInt * 1000L;
|
||||
long now = System.currentTimeMillis();
|
||||
long daysSinceLastWarning =
|
||||
(now - warningLong) / DAYS.toMillis(1);
|
||||
long daysBeforeExpiry =
|
||||
(EXPIRY_DATE - now) / DAYS.toMillis(1);
|
||||
|
||||
if (daysSinceLastWarning >= 30) {
|
||||
handler.onResult(true);
|
||||
} else if (daysBeforeExpiry <= 3 &&
|
||||
daysSinceLastWarning > 0) {
|
||||
handler.onResult(true);
|
||||
} else {
|
||||
handler.onResult(false);
|
||||
}
|
||||
}
|
||||
} catch (DbException e) {
|
||||
logException(LOG, WARNING, e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void expiryWarningDismissed() {
|
||||
runOnDbThread(() -> {
|
||||
try {
|
||||
Settings settings = new Settings();
|
||||
int date = (int) (System.currentTimeMillis() / 1000L);
|
||||
settings.putInt(EXPIRY_DATE_WARNING, date);
|
||||
settingsManager.mergeSettings(settings, SETTINGS_NAMESPACE);
|
||||
} catch (DbException e) {
|
||||
logException(LOG, WARNING, e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void shouldAskForDozeWhitelisting(Context ctx,
|
||||
ResultHandler<Boolean> handler) {
|
||||
// check this first, to hit the DbThread only when really necessary
|
||||
if (!needsDozeWhitelisting(ctx)) {
|
||||
handler.onResult(false);
|
||||
return;
|
||||
}
|
||||
runOnDbThread(() -> {
|
||||
try {
|
||||
Settings settings =
|
||||
settingsManager.getSettings(SETTINGS_NAMESPACE);
|
||||
boolean ask = settings.getBoolean(DOZE_ASK_AGAIN, true);
|
||||
handler.onResult(ask);
|
||||
} catch (DbException e) {
|
||||
logException(LOG, WARNING, e);
|
||||
handler.onResult(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTransportRunning(TransportId transportId) {
|
||||
Plugin plugin = pluginManager.getPlugin(transportId);
|
||||
return plugin != null && plugin.isRunning();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
package org.briarproject.briar.android.navdrawer;
|
||||
|
||||
import org.briarproject.briar.android.viewmodel.ViewModelKey;
|
||||
|
||||
import androidx.lifecycle.ViewModel;
|
||||
import dagger.Binds;
|
||||
import dagger.Module;
|
||||
import dagger.multibindings.IntoMap;
|
||||
|
||||
@Module
|
||||
public abstract class NavDrawerModule {
|
||||
|
||||
@Binds
|
||||
@IntoMap
|
||||
@ViewModelKey(NavDrawerViewModel.class)
|
||||
abstract ViewModel bindNavDrawerViewModel(
|
||||
NavDrawerViewModel navDrawerViewModel);
|
||||
|
||||
@Binds
|
||||
@IntoMap
|
||||
@ViewModelKey(PluginViewModel.class)
|
||||
abstract ViewModel bindPluginViewModel(PluginViewModel pluginViewModel);
|
||||
}
|
||||
@@ -1,131 +0,0 @@
|
||||
package org.briarproject.briar.android.navdrawer;
|
||||
|
||||
import android.app.Application;
|
||||
|
||||
import org.briarproject.bramble.api.db.DatabaseExecutor;
|
||||
import org.briarproject.bramble.api.db.DbException;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.settings.Settings;
|
||||
import org.briarproject.bramble.api.settings.SettingsManager;
|
||||
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import androidx.annotation.UiThread;
|
||||
import androidx.lifecycle.AndroidViewModel;
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
|
||||
import static java.util.concurrent.TimeUnit.DAYS;
|
||||
import static java.util.logging.Level.WARNING;
|
||||
import static java.util.logging.Logger.getLogger;
|
||||
import static org.briarproject.bramble.util.LogUtils.logException;
|
||||
import static org.briarproject.briar.android.TestingConstants.EXPIRY_DATE;
|
||||
import static org.briarproject.briar.android.controller.BriarControllerImpl.DOZE_ASK_AGAIN;
|
||||
import static org.briarproject.briar.android.settings.SettingsFragment.SETTINGS_NAMESPACE;
|
||||
import static org.briarproject.briar.android.util.UiUtils.needsDozeWhitelisting;
|
||||
|
||||
@NotNullByDefault
|
||||
public class NavDrawerViewModel extends AndroidViewModel {
|
||||
|
||||
private static final Logger LOG =
|
||||
getLogger(NavDrawerViewModel.class.getName());
|
||||
|
||||
private static final String EXPIRY_DATE_WARNING = "expiryDateWarning";
|
||||
|
||||
@DatabaseExecutor
|
||||
private final Executor dbExecutor;
|
||||
private final SettingsManager settingsManager;
|
||||
|
||||
private final MutableLiveData<Boolean> showExpiryWarning =
|
||||
new MutableLiveData<>();
|
||||
private final MutableLiveData<Boolean> shouldAskForDozeWhitelisting =
|
||||
new MutableLiveData<>();
|
||||
|
||||
@Inject
|
||||
NavDrawerViewModel(Application app, @DatabaseExecutor Executor dbExecutor,
|
||||
SettingsManager settingsManager) {
|
||||
super(app);
|
||||
this.dbExecutor = dbExecutor;
|
||||
this.settingsManager = settingsManager;
|
||||
}
|
||||
|
||||
LiveData<Boolean> showExpiryWarning() {
|
||||
return showExpiryWarning;
|
||||
}
|
||||
|
||||
@UiThread
|
||||
void checkExpiryWarning() {
|
||||
dbExecutor.execute(() -> {
|
||||
try {
|
||||
Settings settings =
|
||||
settingsManager.getSettings(SETTINGS_NAMESPACE);
|
||||
int warningInt = settings.getInt(EXPIRY_DATE_WARNING, 0);
|
||||
|
||||
if (warningInt == 0) {
|
||||
// we have not warned before
|
||||
showExpiryWarning.postValue(true);
|
||||
} else {
|
||||
long warningLong = warningInt * 1000L;
|
||||
long now = System.currentTimeMillis();
|
||||
long daysSinceLastWarning =
|
||||
(now - warningLong) / DAYS.toMillis(1);
|
||||
long daysBeforeExpiry =
|
||||
(EXPIRY_DATE - now) / DAYS.toMillis(1);
|
||||
|
||||
if (daysSinceLastWarning >= 30) {
|
||||
showExpiryWarning.postValue(true);
|
||||
} else if (daysBeforeExpiry <= 3 &&
|
||||
daysSinceLastWarning > 0) {
|
||||
showExpiryWarning.postValue(true);
|
||||
} else {
|
||||
showExpiryWarning.postValue(false);
|
||||
}
|
||||
}
|
||||
} catch (DbException e) {
|
||||
logException(LOG, WARNING, e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@UiThread
|
||||
void expiryWarningDismissed() {
|
||||
showExpiryWarning.setValue(false);
|
||||
dbExecutor.execute(() -> {
|
||||
try {
|
||||
Settings settings = new Settings();
|
||||
int date = (int) (System.currentTimeMillis() / 1000L);
|
||||
settings.putInt(EXPIRY_DATE_WARNING, date);
|
||||
settingsManager.mergeSettings(settings, SETTINGS_NAMESPACE);
|
||||
} catch (DbException e) {
|
||||
logException(LOG, WARNING, e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
LiveData<Boolean> shouldAskForDozeWhitelisting() {
|
||||
return shouldAskForDozeWhitelisting;
|
||||
}
|
||||
|
||||
@UiThread
|
||||
void checkDozeWhitelisting() {
|
||||
// check this first, to hit the DbThread only when really necessary
|
||||
if (!needsDozeWhitelisting(getApplication())) {
|
||||
shouldAskForDozeWhitelisting.setValue(false);
|
||||
return;
|
||||
}
|
||||
dbExecutor.execute(() -> {
|
||||
try {
|
||||
Settings settings =
|
||||
settingsManager.getSettings(SETTINGS_NAMESPACE);
|
||||
boolean ask = settings.getBoolean(DOZE_ASK_AGAIN, true);
|
||||
shouldAskForDozeWhitelisting.postValue(ask);
|
||||
} catch (DbException e) {
|
||||
logException(LOG, WARNING, e);
|
||||
shouldAskForDozeWhitelisting.postValue(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,92 +0,0 @@
|
||||
package org.briarproject.briar.android.navdrawer;
|
||||
|
||||
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.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.plugin.BluetoothConstants;
|
||||
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.TorConstants;
|
||||
import org.briarproject.bramble.api.plugin.TransportId;
|
||||
import org.briarproject.bramble.api.plugin.event.TransportStateEvent;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
import androidx.lifecycle.ViewModel;
|
||||
|
||||
import static java.util.logging.Level.INFO;
|
||||
import static java.util.logging.Logger.getLogger;
|
||||
import static org.briarproject.bramble.api.plugin.Plugin.State.STARTING_STOPPING;
|
||||
|
||||
@NotNullByDefault
|
||||
public class PluginViewModel extends ViewModel implements EventListener {
|
||||
|
||||
private static final Logger LOG =
|
||||
getLogger(PluginViewModel.class.getName());
|
||||
|
||||
private final PluginManager pluginManager;
|
||||
private final EventBus eventBus;
|
||||
|
||||
private final MutableLiveData<State> torPluginState =
|
||||
new MutableLiveData<>();
|
||||
private final MutableLiveData<State> wifiPluginState =
|
||||
new MutableLiveData<>();
|
||||
private final MutableLiveData<State> btPluginState =
|
||||
new MutableLiveData<>();
|
||||
|
||||
@Inject
|
||||
PluginViewModel(PluginManager pluginManager, EventBus eventBus) {
|
||||
this.pluginManager = pluginManager;
|
||||
this.eventBus = eventBus;
|
||||
eventBus.addListener(this);
|
||||
torPluginState.setValue(getTransportState(TorConstants.ID));
|
||||
wifiPluginState.setValue(getTransportState(LanTcpConstants.ID));
|
||||
btPluginState.setValue(getTransportState(BluetoothConstants.ID));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCleared() {
|
||||
eventBus.removeListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void eventOccurred(Event e) {
|
||||
if (e instanceof TransportStateEvent) {
|
||||
TransportStateEvent t = (TransportStateEvent) e;
|
||||
TransportId id = t.getTransportId();
|
||||
State state = t.getState();
|
||||
if (LOG.isLoggable(INFO)) {
|
||||
LOG.info("TransportStateEvent: " + id + " is " + state);
|
||||
}
|
||||
MutableLiveData<State> liveData = getPluginLiveData(id);
|
||||
if (liveData != null) liveData.postValue(state);
|
||||
}
|
||||
}
|
||||
|
||||
LiveData<State> getPluginState(TransportId id) {
|
||||
LiveData<State> liveData = getPluginLiveData(id);
|
||||
if (liveData == null) throw new IllegalArgumentException();
|
||||
return liveData;
|
||||
}
|
||||
|
||||
private State getTransportState(TransportId id) {
|
||||
Plugin plugin = pluginManager.getPlugin(id);
|
||||
return plugin == null ? STARTING_STOPPING : plugin.getState();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private MutableLiveData<State> getPluginLiveData(TransportId id) {
|
||||
if (id.equals(TorConstants.ID)) return torPluginState;
|
||||
else if (id.equals(LanTcpConstants.ID)) return wifiPluginState;
|
||||
else if (id.equals(BluetoothConstants.ID)) return btPluginState;
|
||||
else return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package org.briarproject.briar.android.navdrawer;
|
||||
|
||||
import org.briarproject.bramble.api.plugin.TransportId;
|
||||
|
||||
import androidx.annotation.UiThread;
|
||||
|
||||
interface TransportStateListener {
|
||||
|
||||
@UiThread
|
||||
void stateUpdate(TransportId id, boolean enabled);
|
||||
}
|
||||
@@ -21,8 +21,6 @@ import org.briarproject.briar.android.logging.BriefLogFormatter;
|
||||
import java.io.File;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.Callable;
|
||||
@@ -187,18 +185,12 @@ public class BriarReportPrimer implements ReportPrimer {
|
||||
WifiInfo wifiInfo = wm.getConnectionInfo();
|
||||
if (wifiInfo != null) {
|
||||
int ip = wifiInfo.getIpAddress(); // Nice API, Google
|
||||
byte[] ipBytes = new byte[4];
|
||||
ipBytes[0] = (byte) (ip & 0xFF);
|
||||
ipBytes[1] = (byte) ((ip >> 8) & 0xFF);
|
||||
ipBytes[2] = (byte) ((ip >> 16) & 0xFF);
|
||||
ipBytes[3] = (byte) ((ip >> 24) & 0xFF);
|
||||
try {
|
||||
InetAddress address = InetAddress.getByAddress(ipBytes);
|
||||
customData.put("Wi-Fi address",
|
||||
scrubInetAddress(address));
|
||||
} catch (UnknownHostException ignored) {
|
||||
// Should only be thrown if address has illegal length
|
||||
}
|
||||
int ip1 = ip & 0xFF;
|
||||
int ip2 = (ip >> 8) & 0xFF;
|
||||
int ip3 = (ip >> 16) & 0xFF;
|
||||
int ip4 = (ip >> 24) & 0xFF;
|
||||
String address = ip1 + "." + ip2 + "." + ip3 + "." + ip4;
|
||||
customData.put("Wi-Fi address", scrubInetAddress(address));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -21,7 +21,6 @@ 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.LanTcpConstants;
|
||||
import org.briarproject.bramble.api.plugin.TorConstants;
|
||||
import org.briarproject.bramble.api.settings.Settings;
|
||||
import org.briarproject.bramble.api.settings.SettingsManager;
|
||||
@@ -42,7 +41,6 @@ import java.util.logging.Logger;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.StringRes;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.core.text.TextUtilsCompat;
|
||||
@@ -74,14 +72,10 @@ 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.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.BluetoothConstants.PREF_BT_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;
|
||||
import static org.briarproject.bramble.api.plugin.TorConstants.PREF_TOR_NETWORK_NEVER;
|
||||
import static org.briarproject.bramble.api.plugin.TorConstants.PREF_TOR_ONLY_WHEN_CHARGING;
|
||||
import static org.briarproject.bramble.util.LogUtils.logDuration;
|
||||
import static org.briarproject.bramble.util.LogUtils.logException;
|
||||
@@ -90,7 +84,6 @@ import static org.briarproject.briar.android.BriarApplication.ENTRY_ACTIVITY;
|
||||
import static org.briarproject.briar.android.TestingConstants.IS_DEBUG_BUILD;
|
||||
import static org.briarproject.briar.android.activity.RequestCodes.REQUEST_RINGTONE;
|
||||
import static org.briarproject.briar.android.navdrawer.NavDrawerActivity.SIGN_OUT_URI;
|
||||
import static org.briarproject.briar.android.util.UiUtils.getCountryDisplayName;
|
||||
import static org.briarproject.briar.android.util.UiUtils.hasScreenLock;
|
||||
import static org.briarproject.briar.android.util.UiUtils.triggerFeedback;
|
||||
import static org.briarproject.briar.api.android.AndroidNotificationManager.BLOG_CHANNEL_ID;
|
||||
@@ -112,24 +105,16 @@ public class SettingsFragment extends PreferenceFragmentCompat
|
||||
implements EventListener, OnPreferenceChangeListener {
|
||||
|
||||
public static final String SETTINGS_NAMESPACE = "android-ui";
|
||||
public static final String BT_NAMESPACE = BluetoothConstants.ID.getString();
|
||||
public static final String TOR_NAMESPACE = TorConstants.ID.getString();
|
||||
public static final String LANGUAGE = "pref_key_language";
|
||||
public static final String PREF_SCREEN_LOCK = "pref_key_lock";
|
||||
public static final String PREF_SCREEN_LOCK_TIMEOUT =
|
||||
"pref_key_lock_timeout";
|
||||
public static final String NOTIFY_SIGN_IN = "pref_key_notify_sign_in";
|
||||
|
||||
private static final String BT_NAMESPACE =
|
||||
BluetoothConstants.ID.getString();
|
||||
private static final String BT_ENABLE = "pref_key_bluetooth";
|
||||
|
||||
private static final String WIFI_NAMESPACE = LanTcpConstants.ID.getString();
|
||||
private static final String WIFI_ENABLE = "pref_key_wifi";
|
||||
|
||||
private static final String TOR_NAMESPACE = TorConstants.ID.getString();
|
||||
private static final String TOR_ENABLE = "pref_key_tor_enable";
|
||||
private static final String TOR_NETWORK = "pref_key_tor_network";
|
||||
private static final String TOR_MOBILE = "pref_key_tor_mobile_data";
|
||||
private static final String TOR_ONLY_WHEN_CHARGING =
|
||||
public static final String TOR_NETWORK = "pref_key_tor_network";
|
||||
public static final String TOR_MOBILE = "pref_key_tor_mobile_data";
|
||||
public static final String TOR_ONLY_WHEN_CHARGING =
|
||||
"pref_key_tor_only_when_charging";
|
||||
|
||||
private static final Logger LOG =
|
||||
@@ -137,9 +122,7 @@ public class SettingsFragment extends PreferenceFragmentCompat
|
||||
|
||||
private SettingsActivity listener;
|
||||
private ListPreference language;
|
||||
private SwitchPreference enableBluetooth;
|
||||
private SwitchPreference enableWifi;
|
||||
private SwitchPreference enableTor;
|
||||
private ListPreference enableBluetooth;
|
||||
private ListPreference torNetwork;
|
||||
private SwitchPreference torMobile;
|
||||
private SwitchPreference torOnlyWhenCharging;
|
||||
@@ -154,7 +137,7 @@ public class SettingsFragment extends PreferenceFragmentCompat
|
||||
private Preference notifySound;
|
||||
|
||||
// Fields that are accessed from background threads must be volatile
|
||||
private volatile Settings settings, btSettings, wifiSettings, torSettings;
|
||||
private volatile Settings settings, btSettings, torSettings;
|
||||
private volatile boolean settingsLoaded = false;
|
||||
|
||||
@Inject
|
||||
@@ -180,23 +163,28 @@ public class SettingsFragment extends PreferenceFragmentCompat
|
||||
public void onCreatePreferences(Bundle bundle, String s) {
|
||||
addPreferencesFromResource(R.xml.settings);
|
||||
|
||||
language = findPreference(LANGUAGE);
|
||||
language = (ListPreference) findPreference(LANGUAGE);
|
||||
setLanguageEntries();
|
||||
ListPreference theme = findPreference("pref_key_theme");
|
||||
enableBluetooth = findPreference(BT_ENABLE);
|
||||
enableWifi = findPreference(WIFI_ENABLE);
|
||||
enableTor = findPreference(TOR_ENABLE);
|
||||
torNetwork = findPreference(TOR_NETWORK);
|
||||
torMobile = findPreference(TOR_MOBILE);
|
||||
torOnlyWhenCharging = findPreference(TOR_ONLY_WHEN_CHARGING);
|
||||
screenLock = findPreference(PREF_SCREEN_LOCK);
|
||||
screenLockTimeout = findPreference(PREF_SCREEN_LOCK_TIMEOUT);
|
||||
notifyPrivateMessages =
|
||||
findPreference("pref_key_notify_private_messages");
|
||||
notifyGroupMessages = findPreference("pref_key_notify_group_messages");
|
||||
notifyForumPosts = findPreference("pref_key_notify_forum_posts");
|
||||
notifyBlogPosts = findPreference("pref_key_notify_blog_posts");
|
||||
notifyVibration = findPreference("pref_key_notify_vibration");
|
||||
ListPreference theme =
|
||||
(ListPreference) findPreference("pref_key_theme");
|
||||
enableBluetooth = (ListPreference) findPreference("pref_key_bluetooth");
|
||||
torNetwork = (ListPreference) findPreference(TOR_NETWORK);
|
||||
torMobile = (SwitchPreference) findPreference(TOR_MOBILE);
|
||||
torOnlyWhenCharging =
|
||||
(SwitchPreference) findPreference(TOR_ONLY_WHEN_CHARGING);
|
||||
screenLock = (SwitchPreference) findPreference(PREF_SCREEN_LOCK);
|
||||
screenLockTimeout =
|
||||
(ListPreference) findPreference(PREF_SCREEN_LOCK_TIMEOUT);
|
||||
notifyPrivateMessages = (SwitchPreference) findPreference(
|
||||
"pref_key_notify_private_messages");
|
||||
notifyGroupMessages = (SwitchPreference) findPreference(
|
||||
"pref_key_notify_group_messages");
|
||||
notifyForumPosts = (SwitchPreference) findPreference(
|
||||
"pref_key_notify_forum_posts");
|
||||
notifyBlogPosts = (SwitchPreference) findPreference(
|
||||
"pref_key_notify_blog_posts");
|
||||
notifyVibration = (SwitchPreference) findPreference(
|
||||
"pref_key_notify_vibration");
|
||||
notifySound = findPreference("pref_key_notify_sound");
|
||||
|
||||
language.setOnPreferenceChangeListener(this);
|
||||
@@ -206,7 +194,8 @@ public class SettingsFragment extends PreferenceFragmentCompat
|
||||
UiUtils.setTheme(getActivity(), (String) newValue);
|
||||
// bring up parent activity, so it can change its theme as well
|
||||
// upstream bug: https://issuetracker.google.com/issues/38352704
|
||||
Intent intent = new Intent(getActivity(), ENTRY_ACTIVITY);
|
||||
Intent intent =
|
||||
new Intent(getActivity(), ENTRY_ACTIVITY);
|
||||
intent.setFlags(
|
||||
FLAG_ACTIVITY_CLEAR_TASK | FLAG_ACTIVITY_NEW_TASK);
|
||||
startActivity(intent);
|
||||
@@ -218,8 +207,6 @@ public class SettingsFragment extends PreferenceFragmentCompat
|
||||
return true;
|
||||
});
|
||||
enableBluetooth.setOnPreferenceChangeListener(this);
|
||||
enableWifi.setOnPreferenceChangeListener(this);
|
||||
enableTor.setOnPreferenceChangeListener(this);
|
||||
torNetwork.setOnPreferenceChangeListener(this);
|
||||
torMobile.setOnPreferenceChangeListener(this);
|
||||
torOnlyWhenCharging.setOnPreferenceChangeListener(this);
|
||||
@@ -262,9 +249,8 @@ public class SettingsFragment extends PreferenceFragmentCompat
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater,
|
||||
@Nullable ViewGroup container,
|
||||
@Nullable Bundle savedInstanceState) {
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
View view = super.onCreateView(inflater, container, savedInstanceState);
|
||||
ColorDrawable divider = new ColorDrawable(
|
||||
ContextCompat.getColor(requireContext(), R.color.divider));
|
||||
@@ -339,13 +325,17 @@ public class SettingsFragment extends PreferenceFragmentCompat
|
||||
|
||||
// Look up country name in the user's chosen language if available
|
||||
String country = locationUtils.getCurrentCountry();
|
||||
String countryName = getCountryDisplayName(country);
|
||||
|
||||
String countryName = country;
|
||||
for (Locale locale : Locale.getAvailableLocales()) {
|
||||
if (locale.getCountry().equalsIgnoreCase(country)) {
|
||||
countryName = locale.getDisplayCountry();
|
||||
break;
|
||||
}
|
||||
}
|
||||
boolean blocked =
|
||||
circumventionProvider.isTorProbablyBlocked(country);
|
||||
boolean useBridges = circumventionProvider.doBridgesWork(country);
|
||||
String setting =
|
||||
getString(R.string.tor_network_setting_without_bridges);
|
||||
String setting = getString(R.string.tor_network_setting_without_bridges);
|
||||
if (blocked && useBridges) {
|
||||
setting = getString(R.string.tor_network_setting_with_bridges);
|
||||
} else if (blocked) {
|
||||
@@ -362,7 +352,6 @@ public class SettingsFragment extends PreferenceFragmentCompat
|
||||
long start = now();
|
||||
settings = settingsManager.getSettings(SETTINGS_NAMESPACE);
|
||||
btSettings = settingsManager.getSettings(BT_NAMESPACE);
|
||||
wifiSettings = settingsManager.getSettings(WIFI_NAMESPACE);
|
||||
torSettings = settingsManager.getSettings(TOR_NAMESPACE);
|
||||
settingsLoaded = true;
|
||||
logDuration(LOG, "Loading settings", start);
|
||||
@@ -373,50 +362,26 @@ 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, DEFAULT_PREF_TOR_NETWORK);
|
||||
if (network == PREF_TOR_NETWORK_NEVER) {
|
||||
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
|
||||
// settings are loaded before the plugin migrates them.
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
private void displaySettings() {
|
||||
listener.runOnUiThreadUnlessDestroyed(() -> {
|
||||
// due to events, we might try to display before a load completed
|
||||
if (!settingsLoaded) return;
|
||||
|
||||
boolean btEnabledSetting = btSettings.getBoolean(PREF_PLUGIN_ENABLE,
|
||||
BluetoothConstants.DEFAULT_PREF_PLUGIN_ENABLE);
|
||||
enableBluetooth.setChecked(btEnabledSetting);
|
||||
|
||||
boolean wifiEnabledSetting =
|
||||
wifiSettings.getBoolean(PREF_PLUGIN_ENABLE,
|
||||
LanTcpConstants.DEFAULT_PREF_PLUGIN_ENABLE);
|
||||
enableWifi.setChecked(wifiEnabledSetting);
|
||||
|
||||
boolean torEnabledSetting =
|
||||
torSettings.getBoolean(PREF_PLUGIN_ENABLE,
|
||||
TorConstants.DEFAULT_PREF_PLUGIN_ENABLE);
|
||||
enableTor.setChecked(torEnabledSetting);
|
||||
boolean btEnabledSetting =
|
||||
btSettings.getBoolean(PREF_BT_ENABLE, false);
|
||||
enableBluetooth.setValue(Boolean.toString(btEnabledSetting));
|
||||
|
||||
int torNetworkSetting = torSettings.getInt(PREF_TOR_NETWORK,
|
||||
DEFAULT_PREF_TOR_NETWORK);
|
||||
PREF_TOR_NETWORK_AUTOMATIC);
|
||||
torNetwork.setValue(Integer.toString(torNetworkSetting));
|
||||
setTorNetworkSummary(torNetworkSetting);
|
||||
|
||||
boolean torMobileSetting = torSettings.getBoolean(PREF_TOR_MOBILE,
|
||||
DEFAULT_PREF_TOR_MOBILE);
|
||||
boolean torMobileSetting =
|
||||
torSettings.getBoolean(PREF_TOR_MOBILE, true);
|
||||
torMobile.setChecked(torMobileSetting);
|
||||
|
||||
boolean torChargingSetting =
|
||||
torSettings.getBoolean(PREF_TOR_ONLY_WHEN_CHARGING,
|
||||
DEFAULT_PREF_TOR_ONLY_WHEN_CHARGING);
|
||||
torSettings.getBoolean(PREF_TOR_ONLY_WHEN_CHARGING, false);
|
||||
torOnlyWhenCharging.setChecked(torChargingSetting);
|
||||
|
||||
displayScreenLockSetting();
|
||||
@@ -478,8 +443,6 @@ public class SettingsFragment extends PreferenceFragmentCompat
|
||||
// - pref_key_lock (screenLock -> displayScreenLockSetting())
|
||||
// - pref_key_lock_timeout (screenLockTimeout)
|
||||
enableBluetooth.setEnabled(enabled);
|
||||
enableWifi.setEnabled(enabled);
|
||||
enableTor.setEnabled(enabled);
|
||||
torNetwork.setEnabled(enabled);
|
||||
torMobile.setEnabled(enabled);
|
||||
torOnlyWhenCharging.setEnabled(enabled);
|
||||
@@ -582,14 +545,8 @@ public class SettingsFragment extends PreferenceFragmentCompat
|
||||
languageChanged((String) newValue);
|
||||
return false;
|
||||
} else if (preference == enableBluetooth) {
|
||||
boolean btSetting = (Boolean) newValue;
|
||||
storeBluetoothSetting(btSetting);
|
||||
} else if (preference == enableWifi) {
|
||||
boolean wifiSetting = (Boolean) newValue;
|
||||
storeWifiSetting(wifiSetting);
|
||||
} else if (preference == enableTor) {
|
||||
boolean torEnabledSetting = (Boolean) newValue;
|
||||
storeTorEnabledSetting(torEnabledSetting);
|
||||
boolean btSetting = Boolean.valueOf((String) newValue);
|
||||
storeBluetoothSettings(btSetting);
|
||||
} else if (preference == torNetwork) {
|
||||
int torNetworkSetting = Integer.valueOf((String) newValue);
|
||||
storeTorNetworkSetting(torNetworkSetting);
|
||||
@@ -653,12 +610,6 @@ public class SettingsFragment extends PreferenceFragmentCompat
|
||||
builder.show();
|
||||
}
|
||||
|
||||
private void storeTorEnabledSetting(boolean torEnabledSetting) {
|
||||
Settings s = new Settings();
|
||||
s.putBoolean(PREF_PLUGIN_ENABLE, torEnabledSetting);
|
||||
mergeSettings(s, TOR_NAMESPACE);
|
||||
}
|
||||
|
||||
private void storeTorNetworkSetting(int torNetworkSetting) {
|
||||
Settings s = new Settings();
|
||||
s.putInt(PREF_TOR_NETWORK, torNetworkSetting);
|
||||
@@ -677,18 +628,12 @@ public class SettingsFragment extends PreferenceFragmentCompat
|
||||
mergeSettings(s, TOR_NAMESPACE);
|
||||
}
|
||||
|
||||
private void storeBluetoothSetting(boolean btSetting) {
|
||||
private void storeBluetoothSettings(boolean btSetting) {
|
||||
Settings s = new Settings();
|
||||
s.putBoolean(PREF_PLUGIN_ENABLE, btSetting);
|
||||
s.putBoolean(PREF_BT_ENABLE, btSetting);
|
||||
mergeSettings(s, BT_NAMESPACE);
|
||||
}
|
||||
|
||||
private void storeWifiSetting(boolean wifiSetting) {
|
||||
Settings s = new Settings();
|
||||
s.putBoolean(PREF_PLUGIN_ENABLE, wifiSetting);
|
||||
mergeSettings(s, WIFI_NAMESPACE);
|
||||
}
|
||||
|
||||
private void storeSettings(Settings s) {
|
||||
mergeSettings(s, SETTINGS_NAMESPACE);
|
||||
}
|
||||
@@ -751,13 +696,9 @@ public class SettingsFragment extends PreferenceFragmentCompat
|
||||
LOG.info("Bluetooth settings updated");
|
||||
btSettings = s.getSettings();
|
||||
displaySettings();
|
||||
} else if (namespace.equals(WIFI_NAMESPACE)) {
|
||||
LOG.info("Wifi settings updated");
|
||||
wifiSettings = s.getSettings();
|
||||
displaySettings();
|
||||
} else if (namespace.equals(TOR_NAMESPACE)) {
|
||||
LOG.info("Tor settings updated");
|
||||
torSettings = migrateTorSettings(s.getSettings());
|
||||
torSettings = s.getSettings();
|
||||
displaySettings();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ public class BriarNotificationBuilder extends NotificationCompat.Builder {
|
||||
// https://issuetracker.google.com/issues/36961721
|
||||
setAutoCancel(true);
|
||||
|
||||
setLights(ContextCompat.getColor(context, R.color.briar_lime_400),
|
||||
setLights(ContextCompat.getColor(context, R.color.briar_green_light),
|
||||
750, 500);
|
||||
if (SDK_INT >= 21) setVisibility(VISIBILITY_PRIVATE);
|
||||
}
|
||||
|
||||
@@ -6,7 +6,6 @@ import android.app.KeyguardManager;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface.OnClickListener;
|
||||
import android.content.Intent;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.net.Uri;
|
||||
import android.os.PowerManager;
|
||||
import android.text.Html;
|
||||
@@ -39,12 +38,9 @@ import org.briarproject.briar.R;
|
||||
import org.briarproject.briar.android.view.ArticleMovementMethod;
|
||||
import org.briarproject.briar.android.widget.LinkDialogFragment;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import androidx.annotation.AttrRes;
|
||||
import androidx.annotation.ColorInt;
|
||||
import androidx.annotation.ColorRes;
|
||||
import androidx.annotation.DrawableRes;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.RequiresApi;
|
||||
import androidx.annotation.UiThread;
|
||||
@@ -83,10 +79,7 @@ import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM;
|
||||
import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_NO;
|
||||
import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_YES;
|
||||
import static androidx.appcompat.app.AppCompatDelegate.setDefaultNightMode;
|
||||
import static androidx.core.content.ContextCompat.getColor;
|
||||
import static androidx.core.content.ContextCompat.getDrawable;
|
||||
import static androidx.core.content.ContextCompat.getSystemService;
|
||||
import static androidx.core.graphics.drawable.DrawableCompat.setTint;
|
||||
import static androidx.core.view.ViewCompat.LAYOUT_DIRECTION_RTL;
|
||||
import static java.util.Objects.requireNonNull;
|
||||
import static java.util.concurrent.TimeUnit.DAYS;
|
||||
@@ -159,9 +152,10 @@ public class UiUtils {
|
||||
return DateUtils.formatDateTime(ctx, time, flags);
|
||||
}
|
||||
|
||||
public static long getDaysUntilExpiry() {
|
||||
public static int getDaysUntilExpiry() {
|
||||
long now = System.currentTimeMillis();
|
||||
return (EXPIRY_DATE - now) / DAYS.toMillis(1);
|
||||
long daysBeforeExpiry = (EXPIRY_DATE - now) / DAYS.toMillis(1);
|
||||
return (int) daysBeforeExpiry;
|
||||
}
|
||||
|
||||
public static SpannableStringBuilder getTeaser(Context ctx, Spanned text) {
|
||||
@@ -407,20 +401,4 @@ public class UiUtils {
|
||||
return ctx.getResources().getConfiguration().getLayoutDirection() ==
|
||||
LAYOUT_DIRECTION_RTL;
|
||||
}
|
||||
|
||||
public static String getCountryDisplayName(String isoCode) {
|
||||
for (Locale locale : Locale.getAvailableLocales()) {
|
||||
if (locale.getCountry().equalsIgnoreCase(isoCode)) {
|
||||
return locale.getDisplayCountry();
|
||||
}
|
||||
}
|
||||
// Name is unknown
|
||||
return isoCode;
|
||||
}
|
||||
|
||||
public static Drawable getDialogIcon(Context ctx, @DrawableRes int resId) {
|
||||
Drawable icon = getDrawable(ctx, resId);
|
||||
setTint(requireNonNull(icon), getColor(ctx, R.color.color_primary));
|
||||
return icon;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
C7.58,20,4,16.42,4,12 S7.58,4,12,4 S20,7.58,20,12 S16.42,20,12,20 Z"/>
|
||||
|
||||
<path
|
||||
android:fillColor="#82c91e"
|
||||
android:fillColor="#95d220"
|
||||
android:pathData="M10.8972,19.9503 C6.5514,19.3493,3.43091,15.2154,4.0625,10.896
|
||||
C4.55452,7.53099,7.09451,4.8236,10.394,4.14714
|
||||
C14.2569,3.35517,18.1698,5.54347,19.5236,9.25295
|
||||
|
||||
@@ -17,12 +17,12 @@
|
||||
android:fillColor="#ffffff"
|
||||
android:pathData="M175.3 16.5l-9.8 0 0 -5.7c0 -1.4 -1.2 -2.6 -2.6 -2.6l-19.3 0c-1.4 0 -2.6 1.2 -2.6 2.6l0 14.4c0 1.4 1.2 2.6 2.6 2.6l15.1 0 0 17.3c0 2.4 2 4.4 4.4 4.4l12.2 0c2.4 0 4.4 -2 4.4 -4.4l0 -24.2c0.1 -2.4 -1.9 -4.4 -4.4 -4.4zm-12.4 -5.9l-9.6 6 -9.6 -6 19.2 0zm-19.4 14.8l0 -12.3 9.8 6.1 9.8 -6.1 0 12.3 -19.6 0zm28.6 21.2l-5.8 0 0 -1.5 5.8 0 0 1.5zm5 -4.6l-15.8 0 0 -14.2 1.6 0c1.4 0 2.6 -1.2 2.6 -2.6l0 -4.1 11.6 0 0 20.9z"/>
|
||||
<path
|
||||
android:fillColor="#db3b21"
|
||||
android:fillColor="#ff0000"
|
||||
android:pathData="M101.4 17.8l2 2 7.4 -7.3 7.3 7.3 2.1 -2 -7.4 -7.4 7.4 -7.3 -2.1 -2.1 -7.3 7.4 -7.4 -7.4 -2 2.1 7.3 7.3z"/>
|
||||
<path
|
||||
android:fillColor="#db3b21"
|
||||
android:fillColor="#ff0000"
|
||||
android:pathData="M176 17.8l2.1 2 7.3 -7.3 7.4 7.3 2 -2 -7.3 -7.4 7.3 -7.3 -2 -2.1 -7.4 7.4 -7.3 -7.4 -2.1 2.1 7.3 7.3z"/>
|
||||
<path
|
||||
android:fillColor="#67a60f"
|
||||
android:fillColor="#08b124"
|
||||
android:pathData="M35.8 18.8l0 0L52.5 2.1 50.5 0 35.6 14.8 28.5 7.7l-2.1 2.1 9.2 9.1z"/>
|
||||
</vector>
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
android:radius="32dp"/>
|
||||
|
||||
<solid
|
||||
android:color="@color/briar_lime_600"/>
|
||||
android:color="@color/briar_green"/>
|
||||
|
||||
</shape>
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ C7.58,20,4,16.42,4,12 S7.58,4,12,4 S20,7.58,20,12 S16.42,20,12,20 Z"/>
|
||||
<path
|
||||
android:pathData="M0,0 L24,0 L24,24 L0,24 Z"/>
|
||||
<path
|
||||
android:fillColor="#82c91e"
|
||||
android:fillColor="#95d220"
|
||||
android:pathData="M10.8972,19.9503 C6.5514,19.3493,3.43091,15.2154,4.0625,10.896
|
||||
C4.55452,7.53099,7.09451,4.8236,10.394,4.14714
|
||||
C14.2569,3.35517,18.1698,5.54347,19.5236,9.25295
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
android:viewportWidth="24">
|
||||
|
||||
<path
|
||||
android:fillColor="#2e3d4f"
|
||||
android:fillColor="#2D3E50"
|
||||
android:pathData="M10.8972,19.9503 C6.5514,19.3493,3.43091,15.2154,4.0625,10.896
|
||||
C4.55452,7.53099,7.09451,4.8236,10.394,4.14714
|
||||
C14.2569,3.35517,18.1698,5.54347,19.5236,9.25295
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
android:viewportWidth="24">
|
||||
|
||||
<path
|
||||
android:fillColor="#82c91e"
|
||||
android:fillColor="#95D220"
|
||||
android:pathData="M10.8972,19.9503 C6.5514,19.3493,3.43091,15.2154,4.0625,10.896
|
||||
C4.55452,7.53099,7.09451,4.8236,10.394,4.14714
|
||||
C14.2569,3.35517,18.1698,5.54347,19.5236,9.25295
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:tint="#418cd8"
|
||||
android:tint="#2A93C6"
|
||||
android:viewportHeight="24.0"
|
||||
android:viewportWidth="24.0">
|
||||
<path
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:tint="#418cd8"
|
||||
android:tint="#2A93C6"
|
||||
android:viewportHeight="24.0"
|
||||
android:viewportWidth="24.0">
|
||||
<path
|
||||
|
||||
@@ -4,6 +4,6 @@
|
||||
android:viewportHeight="24.0"
|
||||
android:viewportWidth="24.0">
|
||||
<path
|
||||
android:fillColor="#707070"
|
||||
android:fillColor="#808080"
|
||||
android:pathData="M21,5v6.59l-3,-3.01 -4,4.01 -4,-4 -4,4 -3,-3.01L3,5c0,-1.1 0.9,-2 2,-2h14c1.1,0 2,0.9 2,2zM18,11.42l3,3.01L21,19c0,1.1 -0.9,2 -2,2L5,21c-1.1,0 -2,-0.9 -2,-2v-6.58l3,2.99 4,-4 4,4 4,-3.99z"/>
|
||||
</vector>
|
||||
|
||||
@@ -4,6 +4,6 @@
|
||||
android:viewportHeight="24.0"
|
||||
android:viewportWidth="24.0">
|
||||
<path
|
||||
android:fillColor="#2e3d4f"
|
||||
android:fillColor="#FF2D3E50"
|
||||
android:pathData="M12,8c1.1,0 2,-0.9 2,-2s-0.9,-2 -2,-2 -2,0.9 -2,2 0.9,2 2,2zM12,10c-1.1,0 -2,0.9 -2,2s0.9,2 2,2 2,-0.9 2,-2 -0.9,-2 -2,-2zM12,16c-1.1,0 -2,0.9 -2,2s0.9,2 2,2 2,-0.9 2,-2 -0.9,-2 -2,-2z"/>
|
||||
</vector>
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
android:viewportWidth="30">
|
||||
|
||||
<path
|
||||
android:fillColor="#fc9403"
|
||||
android:fillColor="#ffa500"
|
||||
android:pathData="M0,0 L30,0 L30,30 L0,30 L0,0 Z"/>
|
||||
<path
|
||||
android:fillColor="#ffffff"
|
||||
|
||||
@@ -18,12 +18,12 @@
|
||||
android:fillColor="#000000"
|
||||
android:pathData="M175.3 16.5l-9.8 0 0 -5.7c0 -1.4 -1.2 -2.6 -2.6 -2.6l-19.3 0c-1.4 0 -2.6 1.2 -2.6 2.6l0 14.4c0 1.4 1.2 2.6 2.6 2.6l15.1 0 0 17.3c0 2.4 2 4.4 4.4 4.4l12.2 0c2.4 0 4.4 -2 4.4 -4.4l0 -24.2c0.1 -2.4 -1.9 -4.4 -4.4 -4.4zm-12.4 -5.9l-9.6 6 -9.6 -6 19.2 0zm-19.4 14.8l0 -12.3 9.8 6.1 9.8 -6.1 0 12.3 -19.6 0zm28.6 21.2l-5.8 0 0 -1.5 5.8 0 0 1.5zm5 -4.6l-15.8 0 0 -14.2 1.6 0c1.4 0 2.6 -1.2 2.6 -2.6l0 -4.1 11.6 0 0 20.9z"/>
|
||||
<path
|
||||
android:fillColor="#db3b21"
|
||||
android:fillColor="#ff0000"
|
||||
android:pathData="M101.4 17.8l2 2 7.4 -7.3 7.3 7.3 2.1 -2 -7.4 -7.4 7.4 -7.3 -2.1 -2.1 -7.3 7.4 -7.4 -7.4 -2 2.1 7.3 7.3z"/>
|
||||
<path
|
||||
android:fillColor="#db3b21"
|
||||
android:fillColor="#ff0000"
|
||||
android:pathData="M176 17.8l2.1 2 7.3 -7.3 7.4 7.3 2 -2 -7.3 -7.4 7.3 -7.3 -2 -2.1 -7.4 7.4 -7.3 -7.4 -2.1 2.1 7.3 7.3z"/>
|
||||
<path
|
||||
android:fillColor="#67a60f"
|
||||
android:fillColor="#08b124"
|
||||
android:pathData="M35.8 18.8l0 0L52.5 2.1 50.5 0 35.6 14.8 28.5 7.7l-2.1 2.1 9.2 9.1z"/>
|
||||
</vector>
|
||||
@@ -1,7 +1,7 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:tint="#418cd8"
|
||||
android:tint="#2A93C6"
|
||||
android:viewportHeight="24.0"
|
||||
android:viewportWidth="24.0">
|
||||
<path
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
android:viewportHeight="20"
|
||||
android:viewportWidth="49">
|
||||
<path
|
||||
android:fillColor="#a7a7a7"
|
||||
android:fillColor="#b7b7b7"
|
||||
android:pathData="M15.5002,13.8797 L15.5002,11.8208 L12.9502,11.8208 L12.9502,8.38194
|
||||
L15.5002,8.38194 L15.5002,6.32312 L12.9502,6.32312 L12.9502,2.49959
|
||||
L10.5752,2.49959 L10.5752,6.32312 L7.42514,6.32312 L7.42514,2.49959
|
||||
@@ -16,7 +16,7 @@ L10.5752,13.8797 L10.5752,17.4996 L12.9502,17.4996 L12.9502,13.8797
|
||||
L15.5002,13.8797 Z M10.5752,11.8208 L7.42514,11.8208 L7.42514,8.38194
|
||||
L10.5752,8.38194 L10.5752,11.8208 Z"/>
|
||||
<path
|
||||
android:fillColor="#a7a7a7"
|
||||
android:fillColor="#b7b7b7"
|
||||
android:pathData="M31.0002,13.8797 L31.0002,11.8208 L28.4502,11.8208 L28.4502,8.38194
|
||||
L31.0002,8.38194 L31.0002,6.32312 L28.4502,6.32312 L28.4502,2.49959
|
||||
L26.0752,2.49959 L26.0752,6.32312 L22.9251,6.32312 L22.9251,2.49959
|
||||
@@ -27,7 +27,7 @@ L26.0752,13.8797 L26.0752,17.4996 L28.4502,17.4996 L28.4502,13.8797
|
||||
L31.0002,13.8797 Z M26.0752,11.8208 L22.9251,11.8208 L22.9251,8.38194
|
||||
L26.0752,8.38194 L26.0752,11.8208 Z"/>
|
||||
<path
|
||||
android:fillColor="#a7a7a7"
|
||||
android:fillColor="#b7b7b7"
|
||||
android:pathData="M46.5002,13.8797 L46.5002,11.8208 L43.9502,11.8208 L43.9502,8.38194
|
||||
L46.5002,8.38194 L46.5002,6.32312 L43.9502,6.32312 L43.9502,2.49959
|
||||
L41.5752,2.49959 L41.5752,6.32312 L38.4251,6.32312 L38.4251,2.49959
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
android:viewportHeight="20"
|
||||
android:viewportWidth="49">
|
||||
<path
|
||||
android:fillColor="#db3b21"
|
||||
android:fillColor="#c34032"
|
||||
android:pathData="M15.5002,13.8797 L15.5002,11.8208 L12.9502,11.8208 L12.9502,8.38194
|
||||
L15.5002,8.38194 L15.5002,6.32312 L12.9502,6.32312 L12.9502,2.49959
|
||||
L10.5752,2.49959 L10.5752,6.32312 L7.42514,6.32312 L7.42514,2.49959
|
||||
@@ -16,7 +16,7 @@ L10.5752,13.8797 L10.5752,17.4996 L12.9502,17.4996 L12.9502,13.8797
|
||||
L15.5002,13.8797 Z M10.5752,11.8208 L7.42514,11.8208 L7.42514,8.38194
|
||||
L10.5752,8.38194 L10.5752,11.8208 Z"/>
|
||||
<path
|
||||
android:fillColor="#a7a7a7"
|
||||
android:fillColor="#b7b7b7"
|
||||
android:pathData="M31.0002,13.8797 L31.0002,11.8208 L28.4502,11.8208 L28.4502,8.38194
|
||||
L31.0002,8.38194 L31.0002,6.32312 L28.4502,6.32312 L28.4502,2.49959
|
||||
L26.0752,2.49959 L26.0752,6.32312 L22.9251,6.32312 L22.9251,2.49959
|
||||
@@ -27,7 +27,7 @@ L26.0752,13.8797 L26.0752,17.4996 L28.4502,17.4996 L28.4502,13.8797
|
||||
L31.0002,13.8797 Z M26.0752,11.8208 L22.9251,11.8208 L22.9251,8.38194
|
||||
L26.0752,8.38194 L26.0752,11.8208 Z"/>
|
||||
<path
|
||||
android:fillColor="#a7a7a7"
|
||||
android:fillColor="#b7b7b7"
|
||||
android:pathData="M46.5002,13.8797 L46.5002,11.8208 L43.9502,11.8208 L43.9502,8.38194
|
||||
L46.5002,8.38194 L46.5002,6.32312 L43.9502,6.32312 L43.9502,2.49959
|
||||
L41.5752,2.49959 L41.5752,6.32312 L38.4251,6.32312 L38.4251,2.49959
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
android:viewportHeight="20"
|
||||
android:viewportWidth="49">
|
||||
<path
|
||||
android:fillColor="#fc9403"
|
||||
android:fillColor="#fcd53a"
|
||||
android:pathData="M15.5002,13.8797 L15.5002,11.8208 L12.9502,11.8208 L12.9502,8.38194
|
||||
L15.5002,8.38194 L15.5002,6.32312 L12.9502,6.32312 L12.9502,2.49959
|
||||
L10.5752,2.49959 L10.5752,6.32312 L7.42514,6.32312 L7.42514,2.49959
|
||||
@@ -16,7 +16,7 @@ L10.5752,13.8797 L10.5752,17.4996 L12.9502,17.4996 L12.9502,13.8797
|
||||
L15.5002,13.8797 Z M10.5752,11.8208 L7.42514,11.8208 L7.42514,8.38194
|
||||
L10.5752,8.38194 L10.5752,11.8208 Z"/>
|
||||
<path
|
||||
android:fillColor="#fc9403"
|
||||
android:fillColor="#fcd53a"
|
||||
android:pathData="M31.0002,13.8797 L31.0002,11.8208 L28.4502,11.8208 L28.4502,8.38194
|
||||
L31.0002,8.38194 L31.0002,6.32312 L28.4502,6.32312 L28.4502,2.49959
|
||||
L26.0752,2.49959 L26.0752,6.32312 L22.9251,6.32312 L22.9251,2.49959
|
||||
@@ -27,7 +27,7 @@ L26.0752,13.8797 L26.0752,17.4996 L28.4502,17.4996 L28.4502,13.8797
|
||||
L31.0002,13.8797 Z M26.0752,11.8208 L22.9251,11.8208 L22.9251,8.38194
|
||||
L26.0752,8.38194 L26.0752,11.8208 Z"/>
|
||||
<path
|
||||
android:fillColor="#a7a7a7"
|
||||
android:fillColor="#b7b7b7"
|
||||
android:pathData="M46.5002,13.8797 L46.5002,11.8208 L43.9502,11.8208 L43.9502,8.38194
|
||||
L46.5002,8.38194 L46.5002,6.32312 L43.9502,6.32312 L43.9502,2.49959
|
||||
L41.5752,2.49959 L41.5752,6.32312 L38.4251,6.32312 L38.4251,2.49959
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
android:viewportHeight="20"
|
||||
android:viewportWidth="49">
|
||||
<path
|
||||
android:fillColor="#67a60f"
|
||||
android:fillColor="#7fac49"
|
||||
android:pathData="M15.5002,13.8797 L15.5002,11.8208 L12.9502,11.8208 L12.9502,8.38194
|
||||
L15.5002,8.38194 L15.5002,6.32312 L12.9502,6.32312 L12.9502,2.49959
|
||||
L10.5752,2.49959 L10.5752,6.32312 L7.42514,6.32312 L7.42514,2.49959
|
||||
@@ -16,7 +16,7 @@ L10.5752,13.8797 L10.5752,17.4996 L12.9502,17.4996 L12.9502,13.8797
|
||||
L15.5002,13.8797 Z M10.5752,11.8208 L7.42514,11.8208 L7.42514,8.38194
|
||||
L10.5752,8.38194 L10.5752,11.8208 Z"/>
|
||||
<path
|
||||
android:fillColor="#67a60f"
|
||||
android:fillColor="#7fac49"
|
||||
android:pathData="M31.0002,13.8797 L31.0002,11.8208 L28.4502,11.8208 L28.4502,8.38194
|
||||
L31.0002,8.38194 L31.0002,6.32312 L28.4502,6.32312 L28.4502,2.49959
|
||||
L26.0752,2.49959 L26.0752,6.32312 L22.9251,6.32312 L22.9251,2.49959
|
||||
@@ -27,7 +27,7 @@ L26.0752,13.8797 L26.0752,17.4996 L28.4502,17.4996 L28.4502,13.8797
|
||||
L31.0002,13.8797 Z M26.0752,11.8208 L22.9251,11.8208 L22.9251,8.38194
|
||||
L26.0752,8.38194 L26.0752,11.8208 Z"/>
|
||||
<path
|
||||
android:fillColor="#67a60f"
|
||||
android:fillColor="#7fac49"
|
||||
android:pathData="M46.5002,13.8797 L46.5002,11.8208 L43.9502,11.8208 L43.9502,8.38194
|
||||
L46.5002,8.38194 L46.5002,6.32312 L43.9502,6.32312 L43.9502,2.49959
|
||||
L41.5752,2.49959 L41.5752,6.32312 L38.4251,6.32312 L38.4251,2.49959
|
||||
|
||||
@@ -4,13 +4,14 @@
|
||||
android:id="@+id/layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="@android:color/black"
|
||||
android:background="@color/briar_black"
|
||||
tools:context=".android.conversation.ImageActivity">
|
||||
|
||||
<androidx.viewpager.widget.ViewPager
|
||||
android:id="@+id/viewPager"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
||||
android:layout_height="match_parent"
|
||||
tools:background="@color/briar_green_light" />
|
||||
|
||||
<com.google.android.material.appbar.AppBarLayout
|
||||
android:id="@+id/appBarLayout"
|
||||
|
||||
@@ -60,7 +60,7 @@
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_marginTop="16dp"
|
||||
android:layout_marginBottom="16dp"
|
||||
android:background="@android:color/white"
|
||||
android:background="@color/briar_white"
|
||||
android:padding="8dp"
|
||||
android:textColor="@color/briar_text_primary"
|
||||
android:textIsSelectable="true"
|
||||
|
||||
@@ -84,7 +84,7 @@
|
||||
android:src="@drawable/ic_call_made"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/stepOneText"
|
||||
app:tint="@android:color/white" />
|
||||
app:tint="@color/briar_white" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/yourLink"
|
||||
@@ -105,7 +105,7 @@
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="16dp"
|
||||
android:background="@android:color/white"
|
||||
android:background="@color/briar_white"
|
||||
android:ellipsize="end"
|
||||
android:padding="8dp"
|
||||
android:singleLine="true"
|
||||
@@ -160,7 +160,7 @@
|
||||
android:src="@drawable/ic_call_received"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/copyButton"
|
||||
app:tint="@android:color/white" />
|
||||
app:tint="@color/briar_white" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/inputLink"
|
||||
|
||||
@@ -97,7 +97,7 @@
|
||||
app:layout_constraintBottom_toTopOf="@+id/contactNameLayout"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/imageView"
|
||||
app:tint="@android:color/white" />
|
||||
app:tint="@color/briar_white" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/nicknameIntro"
|
||||
|
||||
@@ -60,7 +60,7 @@
|
||||
app:layout_constraintEnd_toStartOf="@+id/time"
|
||||
app:layout_constraintStart_toStartOf="@+id/name"
|
||||
app:layout_constraintTop_toBottomOf="@+id/name"
|
||||
tools:textColor="@color/briar_red_500" />
|
||||
tools:textColor="@color/briar_red" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/time"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools">
|
||||
<menu
|
||||
xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<group android:checkableBehavior="single">
|
||||
<item
|
||||
@@ -30,8 +30,7 @@
|
||||
android:id="@+id/nav_btn_lock"
|
||||
android:icon="@drawable/startup_lock"
|
||||
android:title="@string/lock_button"
|
||||
android:visible="false"
|
||||
tools:visible="false" />
|
||||
android:visible="false"/>
|
||||
<item
|
||||
android:id="@+id/nav_btn_signout"
|
||||
android:icon="@drawable/ic_signout"
|
||||
|
||||
@@ -116,6 +116,7 @@
|
||||
<string name="delete">حذف</string>
|
||||
<string name="accept">قبول</string>
|
||||
<string name="decline">رفض</string>
|
||||
<string name="options">الخيارات</string>
|
||||
<string name="online">متصل</string>
|
||||
<string name="offline">غير متصل</string>
|
||||
<string name="send">ارسال</string>
|
||||
@@ -192,6 +193,7 @@
|
||||
<string name="add_contact_remotely_title_case">إضافة جهة اتصال عن بعد </string>
|
||||
<string name="add_contact_nearby_title">إضافة جهة اتصال قريبة</string>
|
||||
<string name="add_contact_remotely_title">إضافة جهة اتصال عن بعد </string>
|
||||
<string name="contact_name_hint">إعطاء اسم مستعار لجهة الاتصال</string>
|
||||
<string name="contact_link_intro">أدخلوا الرّابط المرسل من جهة الاتصال هنا </string>
|
||||
<string name="contact_link_hint">رابط جهة الاتصال</string>
|
||||
<string name="paste_button">لصق</string>
|
||||
@@ -209,6 +211,7 @@
|
||||
<string name="pending_contact_requests_snackbar">هناك طلبات للاتصال بكم في الانتظار </string>
|
||||
<string name="pending_contact_requests">طلبات التواصل القائمة </string>
|
||||
<string name="no_pending_contacts">لا توجد جهات اتصال قيد الإضافة</string>
|
||||
<string name="add_contact_remote_connecting">جاري الاتصال ...</string>
|
||||
<string name="waiting_for_contact_to_come_online">بانتظار ظهور جهة الاتصال على الانترنت. </string>
|
||||
<string name="connecting">جاري الاتصال ...</string>
|
||||
<string name="adding_contact">جاري إضافة جهة الاتصال ...</string>
|
||||
@@ -233,6 +236,9 @@
|
||||
<item quantity="many">تمّت إضافة %d من جهات الاتصال</item>
|
||||
<item quantity="other">تمّت إضافة %d من جهات الاتصال.</item>
|
||||
</plurals>
|
||||
<string name="adding_contact_slow_warning">إضافة جهة الاتصال هذه تستغرق وقتاً أكثر من العادة</string>
|
||||
<string name="adding_contact_slow_title">لم يمكن الاتصال بجهة الاتصال </string>
|
||||
<string name="adding_contact_slow_text">إضافة جهة الاتصال هذه تستغرق وقتاً أكثر من العادة. \n\n يرجى التأكّد من أن جهة الاتصال استلمت الرّابط الخاص بك ومن ثمّ أضافتك:</string>
|
||||
<string name="offline_state">لا اتصال بالانترنت </string>
|
||||
<string name="duplicate_link_dialog_title">الرّابط مكرّر </string>
|
||||
<string name="duplicate_link_dialog_text_1">لديكم جهة اتصال معلّقة تحمل نفس هذا الرّابط: %s</string>
|
||||
@@ -260,6 +266,7 @@
|
||||
<string name="introduction_button">عمل تقديم</string>
|
||||
<string name="introduction_sent">تم إرسال تقديمك.</string>
|
||||
<string name="introduction_error">حدث خطأ في عمل التقديم.</string>
|
||||
<string name="introduction_response_error">خطأ في الإجابة على التقديم</string>
|
||||
<string name="introduction_request_sent">لقد طلبت تقديم %1$s إلى %2$s.</string>
|
||||
<string name="introduction_request_received">قد طلب %1$s أن يقوم بتقديمك إلى %2$s. فهل توافق أن يتم إضافة %2$s إلى قائمة جهات اتصالك؟</string>
|
||||
<string name="introduction_request_exists_received">قد طلب %1$s أن يقدمك إلى %2$s، لكن %2$s هو بالفعل في قائمة جهات اتصالك. حيث أن %1$s قد لا يعرف هذا، فلا زال يمكنك الرد:</string>
|
||||
@@ -447,11 +454,20 @@
|
||||
<string name="pref_theme_dark">ليلي</string>
|
||||
<string name="pref_theme_auto">تلقائي (توقيت النهار)</string>
|
||||
<string name="pref_theme_system">النظام الافتراضي</string>
|
||||
<!--Settings Connections-->
|
||||
<!--Settings Network-->
|
||||
<string name="network_settings_title">الشبكات</string>
|
||||
<string name="bluetooth_setting">الإتصال عبر بلوتوث</string>
|
||||
<string name="bluetooth_setting_enabled">متى ما كان أحد جهات الاتصال قريبًا</string>
|
||||
<string name="bluetooth_setting_disabled">فقط عند إضافة جهة إتصال</string>
|
||||
<string name="tor_network_setting">اتصال عبر الانترنت (تور)</string>
|
||||
<string name="tor_network_setting_automatic">تلقائيًا حسب الموقع</string>
|
||||
<!--How and when Briar will connect to Tor: E.g. "Don't connect to the Internet (in China)" or "Use Tor network with bridges (in Belarus)"-->
|
||||
<string name="tor_network_setting_without_bridges">استخدام تور بلا جسور</string>
|
||||
<string name="tor_network_setting_with_bridges">استخدام تور مع الجسور</string>
|
||||
<string name="tor_network_setting_never">عدم الاتصال</string>
|
||||
<!--How and when Tor will connect after Automatic: E.g. Don't connect (in China) or Use Tor with bridges (in Belarus)-->
|
||||
<string name="tor_network_setting_summary">تلقائيا: %1$s (في %2$s)</string>
|
||||
<string name="tor_mobile_data_title">إستخدام بيانات الجوال</string>
|
||||
<string name="tor_only_when_charging_title">الاتصال عبر الانترنت (تور أو Tor) عند اتصال الجهار بالشّاحن فقط</string>
|
||||
<string name="tor_only_when_charging_summary">تعطيل الاتصال بالانترنت عند تشغيل الجهاز على البطارية</string>
|
||||
<!--Settings Security and Panic-->
|
||||
<string name="security_settings_title">الأمان</string>
|
||||
@@ -492,6 +508,8 @@
|
||||
<string name="panic_setting_signout_summary">تسجيل الخروج من Briar (براير) عند ضغط زر الذعر</string>
|
||||
<string name="purge_setting_title">حذف الحساب</string>
|
||||
<string name="purge_setting_summary">احذف حساب Briar (براير) إذا تم ضغط زر الذعر. انتبه: هذا سيسبب حذف دائم لكل معرفات وحساباتك ورسائلك.</string>
|
||||
<string name="uninstall_setting_title">ألغ تثبيت Briar (براير)</string>
|
||||
<string name="uninstall_setting_summary">هذا يتطلب تأكيد يدوي في حالة الذعر</string>
|
||||
<!--Settings Notifications-->
|
||||
<string name="notification_settings_title">الإشعارات</string>
|
||||
<string name="notify_sign_in_title">ذكرني لتسجيل الدخول</string>
|
||||
|
||||
@@ -96,6 +96,7 @@
|
||||
<string name="delete">Sil</string>
|
||||
<string name="accept">Qəbul et</string>
|
||||
<string name="decline">Azaldılma</string>
|
||||
<string name="options">Seçimlər</string>
|
||||
<string name="online">Online</string>
|
||||
<string name="offline">Offline</string>
|
||||
<string name="send">Göndər</string>
|
||||
@@ -165,6 +166,7 @@
|
||||
<string name="add_contact_remotely_title_case">Məsafədə kontakt əlavə etmək </string>
|
||||
<string name="add_contact_nearby_title">Yaxında kontakt əlavə etmək </string>
|
||||
<string name="add_contact_remotely_title">Məsafədə kontakt əlavə etmək </string>
|
||||
<string name="contact_name_hint">Niklə kontakt saxlayın</string>
|
||||
<string name="contact_link_intro">Kontaktın linkini buraya daxil edin</string>
|
||||
<string name="contact_link_hint">Kontaktın linki</string>
|
||||
<string name="paste_button">Yapışdır</string>
|
||||
@@ -182,6 +184,7 @@
|
||||
<string name="pending_contact_requests_snackbar">Gözləyən kontakt sorğuları var. </string>
|
||||
<string name="pending_contact_requests">Kənara qoyulmuş kontak sorğuları</string>
|
||||
<string name="no_pending_contacts">Gözləyən kontakt yoxdur</string>
|
||||
<string name="add_contact_remote_connecting">Qoşulur...</string>
|
||||
<string name="waiting_for_contact_to_come_online">Kontaktı xəttdə gözləyin ...</string>
|
||||
<string name="connecting">Qoşulur...</string>
|
||||
<string name="adding_contact">Kontaktın əlavə etməsi... </string>
|
||||
@@ -202,6 +205,9 @@
|
||||
<item quantity="one">New contact added.</item>
|
||||
<item quantity="other">%d yeni kontakt əlavə olundu. </item>
|
||||
</plurals>
|
||||
<string name="adding_contact_slow_warning">Bu kontaktın əlavə edilməsi adi haldan daha uzun sürür</string>
|
||||
<string name="adding_contact_slow_title">Kontakta qoşula bilmir</string>
|
||||
<string name="adding_contact_slow_text">Bu kontaktın əlavə edilməsi normaldan daha çox vaxt tələb edir.\n\nYoxlayın ki kontakt sizin linkinizi qəbul edib və sizi əlavə etdi: </string>
|
||||
<string name="offline_state">İnternet bağlantısı yoxdur</string>
|
||||
<string name="duplicate_link_dialog_title">Dublikat Link</string>
|
||||
<!--This is a question asking whether two nicknames refer to the same person-->
|
||||
@@ -225,6 +231,7 @@
|
||||
<string name="introduction_button">Şərh edin</string>
|
||||
<string name="introduction_sent">Şərhiniz göndərildi.</string>
|
||||
<string name="introduction_error">Şərhinizi gödərəndə xəta baş verdi.</string>
|
||||
<string name="introduction_response_error">Cavab verərkən səhv</string>
|
||||
<string name="introduction_request_sent">Siz %1$s-i %2$s-ə təqdim etmək istədiniz.</string>
|
||||
<string name="introduction_request_received">%1$ssizi%2$s-ə təqdim etmək istədi. %2$s-i kontakt siyahınıza əlavə etmək istəyirsiniz?</string>
|
||||
<string name="introduction_request_exists_received">%1$ssizi %2$s-ə tanıtmaq istədi, ancaq %2$s sizin kontaklarinizda var. %1$sbilənə qədər cavab verə bilərsiniz:</string>
|
||||
@@ -365,10 +372,19 @@
|
||||
<string name="pref_theme_dark">Tünd</string>
|
||||
<string name="pref_theme_auto">Avtomatik (Gündüz)</string>
|
||||
<string name="pref_theme_system">Sistem Olduğu kimi</string>
|
||||
<!--Settings Connections-->
|
||||
<!--Settings Network-->
|
||||
<string name="network_settings_title">Şəbəkələr</string>
|
||||
<string name="bluetooth_setting">Bluetooth-la bağlantı</string>
|
||||
<string name="bluetooth_setting_enabled">Kontaktlar yaxın olduqda</string>
|
||||
<string name="bluetooth_setting_disabled">Yalnız kontakt əlavə edərkən</string>
|
||||
<string name="tor_network_setting">İnternet (Tor)-la qoşulma</string>
|
||||
<string name="tor_network_setting_automatic">Yerə görə avtomatik olaraq</string>
|
||||
<!--How and when Briar will connect to Tor: E.g. "Don't connect to the Internet (in China)" or "Use Tor network with bridges (in Belarus)"-->
|
||||
<string name="tor_network_setting_without_bridges">Köprü olmadan Tor-u istifadə edin</string>
|
||||
<string name="tor_network_setting_with_bridges">Tor ilə körpülərdən istifadə edin</string>
|
||||
<string name="tor_network_setting_never">Qoşulmamaq</string>
|
||||
<!--How and when Tor will connect after Automatic: E.g. Don't connect (in China) or Use Tor with bridges (in Belarus)-->
|
||||
<string name="tor_mobile_data_title">Mobil interneti istifadə etmək</string>
|
||||
<string name="tor_only_when_charging_title">Yalnız şarj edərkən İnternet (Tor) vasitəsilə qoşun</string>
|
||||
<string name="tor_only_when_charging_summary">Cihaz batareyadan işləyərkən internet bağlantısını kəsir</string>
|
||||
<!--Settings Security and Panic-->
|
||||
<string name="security_settings_title">Təhlükəsizlik</string>
|
||||
@@ -407,6 +423,8 @@
|
||||
<string name="panic_setting_signout_title">Çıxış</string>
|
||||
<string name="panic_setting_signout_summary">Panik düyməsi basarkən Briar-dan çıxın</string>
|
||||
<string name="purge_setting_title">Hesabı sil</string>
|
||||
<string name="uninstall_setting_title">Briar-i sil</string>
|
||||
<string name="uninstall_setting_summary">Çaxnaşma zamanı əllə dəstəkləmək tələb olunur</string>
|
||||
<!--Settings Notifications-->
|
||||
<string name="notification_settings_title">Bildirişler</string>
|
||||
<string name="notify_sign_in_title">Daxil olmaq üçün mənim yadıma salmaq</string>
|
||||
|
||||
@@ -74,6 +74,7 @@
|
||||
<string name="delete">Obriši</string>
|
||||
<string name="accept">Prihvati</string>
|
||||
<string name="decline">Odbij</string>
|
||||
<string name="options">Opcije</string>
|
||||
<string name="online">Online</string>
|
||||
<string name="offline">Offline</string>
|
||||
<string name="send">Pošalji</string>
|
||||
@@ -137,6 +138,7 @@
|
||||
<string name="add_contact_remotely_title_case">Dodaj udaljeni konktakt</string>
|
||||
<string name="add_contact_nearby_title">Dodaj kontakt koji je u blizini</string>
|
||||
<string name="add_contact_remotely_title">Dodaj udaljeni kontakt</string>
|
||||
<string name="contact_name_hint">Dodjeli kontaktu nadimak</string>
|
||||
<string name="contact_link_intro">Unesite link vašeg kontakta ovdje</string>
|
||||
<string name="contact_link_hint">Kontaktov link</string>
|
||||
<string name="paste_button">Zalepi</string>
|
||||
@@ -154,6 +156,7 @@
|
||||
<string name="pending_contact_requests_snackbar">Postoje zahtjevi za kontaktima koji čekanju</string>
|
||||
<string name="pending_contact_requests">Zahtjevi za kontaktima na čekanju</string>
|
||||
<string name="no_pending_contacts">Nema Zahtjeva za kontaktima na čekanju</string>
|
||||
<string name="add_contact_remote_connecting">Konektovanje…</string>
|
||||
<string name="waiting_for_contact_to_come_online">Čekanje da kontakt bude online…</string>
|
||||
<string name="connecting">Konektovanje…</string>
|
||||
<string name="adding_contact">Dodavanje kontakta...</string>
|
||||
@@ -170,6 +173,9 @@
|
||||
<string name="step_1">1</string>
|
||||
<!--This is a numeral indicating the second step in a series of screens-->
|
||||
<string name="step_2">2</string>
|
||||
<string name="adding_contact_slow_warning">Dodavanje ovog kontakta traje duže nego obično</string>
|
||||
<string name="adding_contact_slow_title">Nije moguće povezivanje sa kontaktom</string>
|
||||
<string name="adding_contact_slow_text">Dodavanje ovog kontakta traje duže nego obično.\n\nMolim vas provjerite da li je vaš kontakt dobio vaš link i dodao vas:</string>
|
||||
<string name="offline_state">Nema konekcije na internet</string>
|
||||
<string name="duplicate_link_dialog_title">Duliciran Link</string>
|
||||
<string name="duplicate_link_dialog_text_1">Već imate kontakta na čekanju sa ovim linkom: %s</string>
|
||||
@@ -196,6 +202,7 @@
|
||||
<string name="introduction_button">Izvršite upoznavanje</string>
|
||||
<string name="introduction_sent">Vaše poziv na upoznavanje je poslat</string>
|
||||
<string name="introduction_error">Došlo je do greške pri izvršenju upoznavanja.</string>
|
||||
<string name="introduction_response_error">Greška pri odgovoru na upoznavanje</string>
|
||||
<string name="introduction_request_sent">Tražili ste da se %1$s i %2$s upoznaju.</string>
|
||||
<string name="introduction_request_received">%1$s je tražio da vas upozna sa %2$s. Da li želite da dodate %2$s u vašu listu kontakata?</string>
|
||||
<string name="introduction_request_exists_received">%1$s je tražio da vas upozna sa %2$s, ali %2$s je već u vašoj listi kontakata. Pošto %1$s to možda ne zna, vi i dalje možete da odgovorite: </string>
|
||||
@@ -350,11 +357,20 @@
|
||||
<string name="pref_theme_dark">Tamna</string>
|
||||
<string name="pref_theme_auto">Automatski (Dnevno)</string>
|
||||
<string name="pref_theme_system">Podrazumjevane postavke sistema</string>
|
||||
<!--Settings Connections-->
|
||||
<!--Settings Network-->
|
||||
<string name="network_settings_title">Mreže</string>
|
||||
<string name="bluetooth_setting">Povežite se preko Bluetooth-a</string>
|
||||
<string name="bluetooth_setting_enabled">Kad god su kontakti blizu</string>
|
||||
<string name="bluetooth_setting_disabled">Samo pri dodavanju kontakata</string>
|
||||
<string name="tor_network_setting">Konektuj se preko Interneta (Tor)</string>
|
||||
<string name="tor_network_setting_automatic">Automatski prema na lokaciji</string>
|
||||
<!--How and when Briar will connect to Tor: E.g. "Don't connect to the Internet (in China)" or "Use Tor network with bridges (in Belarus)"-->
|
||||
<string name="tor_network_setting_without_bridges">Koristi Tor bez mostova</string>
|
||||
<string name="tor_network_setting_with_bridges">Koristi Tor sa mostovima</string>
|
||||
<string name="tor_network_setting_never">Ne konektuj se</string>
|
||||
<!--How and when Tor will connect after Automatic: E.g. Don't connect (in China) or Use Tor with bridges (in Belarus)-->
|
||||
<string name="tor_network_setting_summary">Automatski: %1$s (za %2$s)</string>
|
||||
<string name="tor_mobile_data_title">Koristi mobilinu mrežu</string>
|
||||
<string name="tor_only_when_charging_title">Konektuj se preko Interneta (Tor) samo tokom punjenja uređaja</string>
|
||||
<string name="tor_only_when_charging_summary">Onemogući interent konekciju kada se uređaj napaja samo sa baterijie</string>
|
||||
<!--Settings Security and Panic-->
|
||||
<string name="security_settings_title">Sigurnost</string>
|
||||
@@ -395,6 +411,8 @@
|
||||
<string name="panic_setting_signout_summary">Izloguj se iz Briar-a ako je pritisnuto panik dugme</string>
|
||||
<string name="purge_setting_title">Izbriši račun</string>
|
||||
<string name="purge_setting_summary">Izbriši Briar račun ako je panik dugme pritisnuto. Pažnja: Ovo će trajno izbrisati vaše identitete, kontakte i poruke</string>
|
||||
<string name="uninstall_setting_title">Deinstaliraj Briar</string>
|
||||
<string name="uninstall_setting_summary">Ovo zahtijeva ručnu potvrdu u slučaju panike</string>
|
||||
<!--Settings Notifications-->
|
||||
<string name="notification_settings_title">Obavještenja</string>
|
||||
<string name="notify_sign_in_title">Podsjeti me da se prijavim</string>
|
||||
|
||||
@@ -26,8 +26,6 @@
|
||||
<!--Login-->
|
||||
<string name="enter_password">Contrasenya</string>
|
||||
<string name="try_again">La contrasenya és incorrecta, torneu a escriure-la</string>
|
||||
<string name="dialog_title_cannot_check_password">No es pot verificar la contrasenya</string>
|
||||
<string name="dialog_message_cannot_check_password">El Briar no pot verificar la contrasenya. Proveu de reiniciar el vostre aparell per a solucionar aquest problema.</string>
|
||||
<string name="sign_in_button">Inicia la sessió</string>
|
||||
<string name="forgotten_password">No recordo la contrasenya</string>
|
||||
<string name="dialog_title_lost_password">Contrasenya perduda</string>
|
||||
@@ -98,6 +96,7 @@
|
||||
<string name="delete">Suprimeix</string>
|
||||
<string name="accept">Accepta</string>
|
||||
<string name="decline">Refusa</string>
|
||||
<string name="options">Opcions</string>
|
||||
<string name="online">En línia</string>
|
||||
<string name="offline">Fora de línia</string>
|
||||
<string name="send">Envia</string>
|
||||
@@ -129,13 +128,6 @@
|
||||
<string name="dialog_title_delete_all_messages">Confirmeu la supressió dels missatges</string>
|
||||
<string name="dialog_message_delete_all_messages">Esteu segur que voleu suprimir tots els missatges?</string>
|
||||
<string name="dialog_title_not_all_messages_deleted">No s\'ha pogut suprimir tots els missatges</string>
|
||||
<string name="dialog_message_not_deleted_ongoing_both">Els missatges relacionats amb introduccions i invitacions pendents no es poden suprimir fins que es finalitzin.</string>
|
||||
<string name="dialog_message_not_deleted_ongoing_introductions">Els missatges relacionats amb introduccions pendents no es poden suprimir fins que es finalitzin.</string>
|
||||
<string name="dialog_message_not_deleted_ongoing_invitations">Els missatges relacionats amb invitacions pendents no es poden suprimir fins que es finalitzin.</string>
|
||||
<string name="dialog_message_not_deleted_partly_downloaded">Els missatges baixats parcialment no es poden suprimir fins que s\'acabin de baixar.</string>
|
||||
<string name="dialog_message_not_deleted_not_all_selected_both">Per a suprimir una invitació o una introducció, cal que seleccioneu la sol·licitdu i la resposta.</string>
|
||||
<string name="dialog_message_not_deleted_not_all_selected_introductions">Per a suprimir una introducció, cal que seleccioneu la sol·licitud i la resposta.</string>
|
||||
<string name="dialog_message_not_deleted_not_all_selected_invitations">Per a suprimir una invitació, cal que seleccioneu la sol·licitud i la resposta.</string>
|
||||
<string name="delete_contact">Suprimeix aquest contacte</string>
|
||||
<string name="dialog_title_delete_contact">Confirmeu la supressió del contacte</string>
|
||||
<string name="dialog_message_delete_contact">Segur que voleu suprimir aquest contacte i tots els missatges que us heu intercanviat?</string>
|
||||
@@ -175,6 +167,7 @@ Així que l\'actualitzi li veureu una icona diferent .</string>
|
||||
<string name="add_contact_remotely_title_case">Afegeix un contacte llunyà</string>
|
||||
<string name="add_contact_nearby_title">Afegeix un contacte proper</string>
|
||||
<string name="add_contact_remotely_title">Afegeix un contacte llunyà</string>
|
||||
<string name="contact_name_hint">Doneu un sobrenom al contacte</string>
|
||||
<string name="contact_link_intro">Escriviu l\'enllaç del vostre contacte</string>
|
||||
<string name="contact_link_hint">Enllaç del contacte</string>
|
||||
<string name="paste_button">Enganxa</string>
|
||||
@@ -192,6 +185,7 @@ Així que l\'actualitzi li veureu una icona diferent .</string>
|
||||
<string name="pending_contact_requests_snackbar">Hi ha sol·licituds de contacte pendents</string>
|
||||
<string name="pending_contact_requests">Sol·licituds de contacte pendents</string>
|
||||
<string name="no_pending_contacts">No hi ha sol·licituds de contacte pendents</string>
|
||||
<string name="add_contact_remote_connecting">S\'està connectant...</string>
|
||||
<string name="waiting_for_contact_to_come_online">S\'està esperant que el contacte estigui connectat…</string>
|
||||
<string name="connecting">S\'està connectant...</string>
|
||||
<string name="adding_contact">S\'està afegint el contacte…</string>
|
||||
@@ -212,6 +206,9 @@ Així que l\'actualitzi li veureu una icona diferent .</string>
|
||||
<item quantity="one">S\'ha afegit el nou contacte </item>
|
||||
<item quantity="other">S\'han afegit %d nous contactes.</item>
|
||||
</plurals>
|
||||
<string name="adding_contact_slow_warning">Afegir aquest contacte està trigant més que de costum…</string>
|
||||
<string name="adding_contact_slow_title">No pot connectar-se al contacte</string>
|
||||
<string name="adding_contact_slow_text">Afegir aquest contacte està trigant més que de costum.\n\nComproveu que el contacte ha rebut el vostre enllaç i també us ha afegit.</string>
|
||||
<string name="offline_state">No hi ha connexió a Internet</string>
|
||||
<string name="duplicate_link_dialog_title">Enllaç duplicat</string>
|
||||
<string name="duplicate_link_dialog_text_1">Teniu una sol·licitud de contacte pendent amb l\'enllaç %s</string>
|
||||
@@ -239,6 +236,7 @@ Així que l\'actualitzi li veureu una icona diferent .</string>
|
||||
<string name="introduction_button">Presenta\'ls</string>
|
||||
<string name="introduction_sent">S\'ha enviat la vostra presentació.</string>
|
||||
<string name="introduction_error">Hi ha hagut un error en presentar els contactes.</string>
|
||||
<string name="introduction_response_error">Error en respondre a la presentació</string>
|
||||
<string name="introduction_request_sent">Heu demanat fer les presentacions per a que %1$s i %2$s es coneguin.</string>
|
||||
<string name="introduction_request_received">%1$s us vol presentar a %2$s. Voleu afegir a%2$s a la vostra llista de contactes?</string>
|
||||
<string name="introduction_request_exists_received">%1$s us vol presentar a %2$s, però ja teniu a %2$s a la llista de contactes. Atès que segurament %1$s no ho sabia, encara el podeu contestar:</string>
|
||||
@@ -409,11 +407,20 @@ Així que l\'actualitzi li veureu una icona diferent .</string>
|
||||
<string name="pref_theme_dark">Fosc</string>
|
||||
<string name="pref_theme_auto">Automàtic (segons l\'hora)</string>
|
||||
<string name="pref_theme_system">Valor per defecte del sistema</string>
|
||||
<!--Settings Connections-->
|
||||
<!--Settings Network-->
|
||||
<string name="network_settings_title">Xarxes</string>
|
||||
<string name="bluetooth_setting">Connecta via bluetooth</string>
|
||||
<string name="bluetooth_setting_enabled">Sempre que hi hagi contactes propers</string>
|
||||
<string name="bluetooth_setting_disabled">Només quan s\'afegeixen contactes</string>
|
||||
<string name="tor_network_setting">Connecta a través d\'Internet (Tor)</string>
|
||||
<string name="tor_network_setting_automatic">Automàtic, basat en la posició</string>
|
||||
<!--How and when Briar will connect to Tor: E.g. "Don't connect to the Internet (in China)" or "Use Tor network with bridges (in Belarus)"-->
|
||||
<string name="tor_network_setting_without_bridges">Usa Tor sense ponts</string>
|
||||
<string name="tor_network_setting_with_bridges">Usa Tor amb ponts</string>
|
||||
<string name="tor_network_setting_never">No et connectis</string>
|
||||
<!--How and when Tor will connect after Automatic: E.g. Don't connect (in China) or Use Tor with bridges (in Belarus)-->
|
||||
<string name="tor_network_setting_summary">Automàtic: %1$s (a %2$s)</string>
|
||||
<string name="tor_mobile_data_title">Usa dades mòbils</string>
|
||||
<string name="tor_only_when_charging_title">Connecta a través d\'Internet (Tor) només quan s\'estigui carregant</string>
|
||||
<string name="tor_only_when_charging_summary">Desactiva la connexió a Internet quan el dispositiu estigui funcionant amb la bateria</string>
|
||||
<!--Settings Security and Panic-->
|
||||
<string name="security_settings_title">Seguretat</string>
|
||||
@@ -454,6 +461,8 @@ Així que l\'actualitzi li veureu una icona diferent .</string>
|
||||
<string name="panic_setting_signout_summary">Tanca la sessió de Briar si es prem un botó de pànic</string>
|
||||
<string name="purge_setting_title">Esborreu el compte</string>
|
||||
<string name="purge_setting_summary">Suprimeix el compte de Briar si es prem el botó de pànic. Atenció: En aquest cas, s\'eliminarien permanentment les vostres identitats, contactes i missatges</string>
|
||||
<string name="uninstall_setting_title">Desinstal·leu Briar</string>
|
||||
<string name="uninstall_setting_summary">Això requeria la confirmació manual malgrat ser en una situació de pànic</string>
|
||||
<!--Settings Notifications-->
|
||||
<string name="notification_settings_title">Notificacions</string>
|
||||
<string name="notify_sign_in_title">Recorda\'m que iniciï la sessió</string>
|
||||
|
||||
@@ -26,8 +26,6 @@
|
||||
<!--Login-->
|
||||
<string name="enter_password">Passwort</string>
|
||||
<string name="try_again">Passwort falsch, bitte erneut versuchen</string>
|
||||
<string name="dialog_title_cannot_check_password">Passwort kann nicht überprüft werden</string>
|
||||
<string name="dialog_message_cannot_check_password">Briar kann dein Passwort nicht überprüfen. Starte bitte dein Gerät neu und versuche damit, dieses Problem zu lösen.</string>
|
||||
<string name="sign_in_button">Anmelden</string>
|
||||
<string name="forgotten_password">Ich habe mein Passwort vergessen</string>
|
||||
<string name="dialog_title_lost_password">Passwort vergessen</string>
|
||||
@@ -98,6 +96,7 @@
|
||||
<string name="delete">Löschen</string>
|
||||
<string name="accept">Annehmen</string>
|
||||
<string name="decline">Ablehnen</string>
|
||||
<string name="options">Optionen</string>
|
||||
<string name="online">Online</string>
|
||||
<string name="offline">Offline</string>
|
||||
<string name="send">Senden</string>
|
||||
@@ -110,7 +109,7 @@
|
||||
<string name="fix">Behoben</string>
|
||||
<string name="help">Hilfe</string>
|
||||
<string name="sorry">Entschuldigung</string>
|
||||
<string name="error_start_activity">Nicht Verfügbar für dein System</string>
|
||||
<string name="error_start_activity">Nicht Verfügbar auf deinem Gerät</string>
|
||||
<!--Contacts and Private Conversations-->
|
||||
<string name="no_contacts">Keine Kontakte vorhanden</string>
|
||||
<string name="no_contacts_action">Tippe auf das + Symbol, um einen Kontakt hinzuzufügen</string>
|
||||
@@ -128,20 +127,17 @@
|
||||
<string name="delete_all_messages">Alle Nachrichten löschen</string>
|
||||
<string name="dialog_title_delete_all_messages">Löschen der Nachrichten bestätigen</string>
|
||||
<string name="dialog_message_delete_all_messages">Bist Du sicher, dass Du alle Nachrichten löschen willst?</string>
|
||||
<string name="dialog_title_not_all_messages_deleted">Es konnten nicht alle Nachrichten gelöscht werden</string>
|
||||
<string name="dialog_title_not_all_messages_deleted">Konnte nicht alle Nachrichten löschen</string>
|
||||
<string name="dialog_message_not_deleted_ongoing_both">Nachrichten, die sich auf laufende Einladungen und Kontaktempfehlungen beziehen, können nicht gelöscht werden, bis sie abgeschlossen sind.</string>
|
||||
<string name="dialog_message_not_deleted_ongoing_introductions">Nachrichten, die sich auf laufende Kontaktempfehlungen beziehen, können nicht gelöscht werden, bis sie abgeschlossen sind.</string>
|
||||
<string name="dialog_message_not_deleted_ongoing_invitations">Nachrichten, die sich auf laufende Einladungen beziehen, können nicht gelöscht werden, bis sie abgeschlossen sind.</string>
|
||||
<string name="dialog_message_not_deleted_partly_downloaded">Teilweise heruntergeladene Nachrichten können erst nach dem Ende des Downloads gelöscht werden.</string>
|
||||
<string name="dialog_message_not_deleted_not_all_selected_both">Um eine Einladung oder Kontaktempfehlung zu löschen, musst du die Anfrage und die Antwort auswählen.</string>
|
||||
<string name="dialog_message_not_deleted_not_all_selected_introductions">Um eine Kontaktempfehlung zu löschen, musst du die Anfrage und die Antwort auswählen.</string>
|
||||
<string name="dialog_message_not_deleted_not_all_selected_invitations">Um eine Einladung zu löschen, musst du die Anfrage und die Antwort auswählen.</string>
|
||||
<string name="delete_contact">Kontakt löschen</string>
|
||||
<string name="dialog_title_delete_contact">Löschen des Kontakts bestätigen</string>
|
||||
<string name="dialog_message_delete_contact">Bist du sicher, dass du diesen Kontakt und alle dazugehörigen Nachrichten löschen möchtest?</string>
|
||||
<string name="contact_deleted_toast">Kontakt gelöscht</string>
|
||||
<!--This is shown in the action bar when opening an image in fullscreen that the user sent-->
|
||||
<string name="you">Du</string>
|
||||
<string name="you">Sie</string>
|
||||
<string name="save_image">Bild speichern</string>
|
||||
<string name="dialog_title_save_image">Bild speichern?</string>
|
||||
<string name="dialog_message_save_image">Gespeicherte Bilder können von vielen anderen Apps eingesehen werden.\n\nBist du sicher, dass du das Bild speichern möchtest?</string>
|
||||
@@ -157,7 +153,7 @@
|
||||
<string name="face_to_face">Um einen neuen Kontakt hinzuzufügen, ist es notwendig, dass sich beide Kontakte an einem Ort treffen.\n\nDadurch wird betrügerische Identitätsvortäuschung und unautorisierter Kommunikationszugriff verhindert.</string>
|
||||
<string name="continue_button">Weiter</string>
|
||||
<string name="try_again_button">Noch einmal versuchen</string>
|
||||
<string name="waiting_for_contact_to_scan">Warten auf Kontakt zum scannen und verbinden\u2026</string>
|
||||
<string name="waiting_for_contact_to_scan">Warte auf Scan und Verbindung mit dem Kontakt\u2026</string>
|
||||
<string name="exchanging_contact_details">Kontaktdetails werden ausgetauscht\u2026</string>
|
||||
<string name="contact_added_toast">Kontakt hinzugefügt: %s</string>
|
||||
<string name="contact_already_exists">Kontakt %s existiert bereits</string>
|
||||
@@ -173,7 +169,8 @@
|
||||
<!--Adding Contacts Remotely-->
|
||||
<string name="add_contact_remotely_title_case">Kontakt aus der Ferne hinzufügen</string>
|
||||
<string name="add_contact_nearby_title">Kontakt in der Nähe hinzufügen</string>
|
||||
<string name="add_contact_remotely_title">Kontakt in der Ferne hinzufügen</string>
|
||||
<string name="add_contact_remotely_title">Kontakt aus der Ferne hinzufügen</string>
|
||||
<string name="contact_name_hint">Gib dem Kontakt einen Spitznamen</string>
|
||||
<string name="contact_link_intro">Füge hier den Link des Kontakts ein, den du hinzufügen möchtest:</string>
|
||||
<string name="contact_link_hint">Kontakt Link</string>
|
||||
<string name="paste_button">Einfügen</string>
|
||||
@@ -191,6 +188,7 @@
|
||||
<string name="pending_contact_requests_snackbar">Es gibt ausstehende Kontaktanfragen</string>
|
||||
<string name="pending_contact_requests">Ausstehende Kontaktanfragen</string>
|
||||
<string name="no_pending_contacts">Keine ausstehenden Kontakte</string>
|
||||
<string name="add_contact_remote_connecting">Verbindung wird aufgebaut …</string>
|
||||
<string name="waiting_for_contact_to_come_online">Warte auf Online-Aktivität des Kontakts ...</string>
|
||||
<string name="connecting">Verbindung wird aufgebaut …</string>
|
||||
<string name="adding_contact">Kontakt hinzufügen...</string>
|
||||
@@ -211,6 +209,9 @@
|
||||
<item quantity="one">Neuer Kontakt hinzugefügt.</item>
|
||||
<item quantity="other">%d neue Kontakte hinzugefügt.</item>
|
||||
</plurals>
|
||||
<string name="adding_contact_slow_warning">Das Hinzufügen des Kontakts dauert länger als normal</string>
|
||||
<string name="adding_contact_slow_title">Kann nicht zu Kontakt verbinden</string>
|
||||
<string name="adding_contact_slow_text">Das Hinzufügen des Kontakts dauert länger als normal.\n\nBitte kontrolliere, dass dein Kontakt deinen Link erhalten und eingegeben hat:</string>
|
||||
<string name="offline_state">Keine Internetverbindung</string>
|
||||
<string name="duplicate_link_dialog_title">Link duplizieren</string>
|
||||
<string name="duplicate_link_dialog_text_1">Du hast bereits einen Kontakt mit diesem Link ausstehend: %s</string>
|
||||
@@ -238,6 +239,7 @@
|
||||
<string name="introduction_button">Kontaktempfehlung abgeben</string>
|
||||
<string name="introduction_sent">Deine Kontaktempfehlung wurde verschickt.</string>
|
||||
<string name="introduction_error">Es gab einen Fehler beim Versuch, die Kontaktempfehlung zu verschicken.</string>
|
||||
<string name="introduction_response_error">Fehler bei Antwort auf Kontaktempfehlung</string>
|
||||
<string name="introduction_request_sent">Du wolltest %1$s an %2$s als Kontakt empfehlen</string>
|
||||
<string name="introduction_request_received">%1$s schlägt vor, dich als Kontakt an %2$s zu empfehlen. Möchtest du %2$s zu deiner Kontaktliste hinzufügen?</string>
|
||||
<string name="introduction_request_exists_received">%1$s schlägt vor, dich als Kontakt an %2$s zu empfehlen. %2$s ist allerdings bereits in deiner Kontaktliste. Da %1$s das vielleicht nicht weiss, kannst du trotzdem antworten:</string>
|
||||
@@ -408,12 +410,20 @@
|
||||
<string name="pref_theme_dark">Dunkel</string>
|
||||
<string name="pref_theme_auto">Automatisch (Tageszeit)</string>
|
||||
<string name="pref_theme_system">Systemstandard</string>
|
||||
<!--Settings Connections-->
|
||||
<string name="network_settings_title">Verbindungen</string>
|
||||
<!--Settings Network-->
|
||||
<string name="network_settings_title">Netzwerke</string>
|
||||
<string name="bluetooth_setting">Über Bluetooth verbinden</string>
|
||||
<string name="bluetooth_setting_enabled">Sobald Kontakte in der Nähe sind</string>
|
||||
<string name="bluetooth_setting_disabled">Nur beim Hinzufügen von Kontakten</string>
|
||||
<string name="tor_network_setting">Über Internet (Tor) verbinden</string>
|
||||
<string name="tor_network_setting_automatic">Automatisch (standortbasiert)</string>
|
||||
<!--How and when Briar will connect to Tor: E.g. "Don't connect to the Internet (in China)" or "Use Tor network with bridges (in Belarus)"-->
|
||||
<string name="tor_network_setting_without_bridges">Tor ohne Bridges nutzen</string>
|
||||
<string name="tor_network_setting_with_bridges">Tor mit Bridges nutzen</string>
|
||||
<string name="tor_network_setting_never">Nicht verbinden</string>
|
||||
<!--How and when Tor will connect after Automatic: E.g. Don't connect (in China) or Use Tor with bridges (in Belarus)-->
|
||||
<string name="tor_network_setting_summary">Automatisch: %1$s (in %2$s)</string>
|
||||
<string name="tor_mobile_data_title">Mobile Daten benutzen</string>
|
||||
<string name="tor_only_when_charging_title">Verbindung über Internet (Tor) nur während des Ladevorgangs herstellen</string>
|
||||
<string name="tor_only_when_charging_summary">Deaktiviert die Internetverbindung, wenn das Gerät mit Akku betrieben wird</string>
|
||||
<!--Settings Security and Panic-->
|
||||
<string name="security_settings_title">Sicherheit</string>
|
||||
@@ -454,6 +464,8 @@
|
||||
<string name="panic_setting_signout_summary">Von Briar abmelden, wenn ein Panik-Button aktiviert wird</string>
|
||||
<string name="purge_setting_title">Konto löschen</string>
|
||||
<string name="purge_setting_summary">Briar-Konto löschen, wenn der Panik-Button gedrückt wird. Achtung: Es werden alle Identitäten, Kontakte und Nachrichten unwiderruflich gelöscht</string>
|
||||
<string name="uninstall_setting_title">Briar deinstallieren</string>
|
||||
<string name="uninstall_setting_summary">Diese Aktion benötigt eine manuelle Bestätigung im Falle eines Panik-Ereignisses</string>
|
||||
<!--Settings Notifications-->
|
||||
<string name="notification_settings_title">Benachrichtigungen</string>
|
||||
<string name="notify_sign_in_title">Anmeldeerinnerung</string>
|
||||
|
||||
@@ -26,8 +26,6 @@
|
||||
<!--Login-->
|
||||
<string name="enter_password">Contraseña</string>
|
||||
<string name="try_again">Contraseña incorrecta, inténtalo de nuevo</string>
|
||||
<string name="dialog_title_cannot_check_password">Imposible comprobar la contraseña</string>
|
||||
<string name="dialog_message_cannot_check_password">Briar no ha podido comprobar tu contraseña. Por favor, prueba a reiniciar tu dispositivo para resolver el problema.</string>
|
||||
<string name="sign_in_button">Iniciar sesión</string>
|
||||
<string name="forgotten_password">He olvidado mi contraseña</string>
|
||||
<string name="dialog_title_lost_password">Contraseña perdida</string>
|
||||
@@ -98,6 +96,7 @@
|
||||
<string name="delete">Borrar</string>
|
||||
<string name="accept">Aceptar</string>
|
||||
<string name="decline">Rechazar</string>
|
||||
<string name="options">Opciones</string>
|
||||
<string name="online">En línea</string>
|
||||
<string name="offline">Fuera de línea</string>
|
||||
<string name="send">Enviar</string>
|
||||
@@ -126,7 +125,7 @@
|
||||
<string name="set_contact_alias_hint">Nombre del contacto</string>
|
||||
<string name="set_alias_button">Cambiar</string>
|
||||
<string name="delete_all_messages">Eliminar todos los mensajes</string>
|
||||
<string name="dialog_title_delete_all_messages">Confirmar la eliminación del mensaje</string>
|
||||
<string name="dialog_title_delete_all_messages">Confirmar eliminación de mensajes</string>
|
||||
<string name="dialog_message_delete_all_messages">¿Estás seguro de que deseas eliminar todos los mensajes?</string>
|
||||
<string name="dialog_title_not_all_messages_deleted">No se pudieron eliminar todos los mensajes.</string>
|
||||
<string name="dialog_message_not_deleted_ongoing_both">Los mensajes relacionados con presentaciones o invitaciones en curso no se pueden eliminar hasta que finalicen.</string>
|
||||
@@ -153,7 +152,7 @@
|
||||
<string name="dialog_message_image_support">Pulsa este ícono para adjuntar imágenes.</string>
|
||||
<string name="messaging_too_many_attachments_toast">Solo se enviarán las primeras %d imágenes</string>
|
||||
<!--Adding Contacts-->
|
||||
<string name="add_contact_title">Agregar contacto cercano</string>
|
||||
<string name="add_contact_title">Agregar Contacto Cercano</string>
|
||||
<string name="face_to_face">Debes reunirte con la persona a la que quieras añadir como contacto.\n\nHaciéndolo así prevendrás que nadie te suplante o pueda leer tus mensajes en el futuro.</string>
|
||||
<string name="continue_button">Continuar</string>
|
||||
<string name="try_again_button">Prueba de nuevo</string>
|
||||
@@ -174,6 +173,7 @@
|
||||
<string name="add_contact_remotely_title_case">Añadir un Contacto a Distancia</string>
|
||||
<string name="add_contact_nearby_title">Agregar un contacto cercano</string>
|
||||
<string name="add_contact_remotely_title">Añadir un contacto a distancia</string>
|
||||
<string name="contact_name_hint">Ponerle un sobrenombre al contacto</string>
|
||||
<string name="contact_link_intro">Introduzca el enlace de su contacto aquí</string>
|
||||
<string name="contact_link_hint">Enlace de contacto</string>
|
||||
<string name="paste_button">Pegar</string>
|
||||
@@ -191,6 +191,7 @@
|
||||
<string name="pending_contact_requests_snackbar">Hay solicitudes de contacto pendientes</string>
|
||||
<string name="pending_contact_requests">Solicitudes de contacto pendientes</string>
|
||||
<string name="no_pending_contacts">No hay contactos pendientes</string>
|
||||
<string name="add_contact_remote_connecting">Conectando...</string>
|
||||
<string name="waiting_for_contact_to_come_online">Esperando que el contacto se ponga en línea....</string>
|
||||
<string name="connecting">Conectando...</string>
|
||||
<string name="adding_contact">Añadir contacto....</string>
|
||||
@@ -211,6 +212,9 @@
|
||||
<item quantity="one">Nuevo contacto añadido.</item>
|
||||
<item quantity="other">%d nuevos contactos añadidos.</item>
|
||||
</plurals>
|
||||
<string name="adding_contact_slow_warning">Añadir este contacto tarda más de lo habitual</string>
|
||||
<string name="adding_contact_slow_title">No se puede conectar con el contacto</string>
|
||||
<string name="adding_contact_slow_text">Agregar este contacto está tomando más tiempo de lo normal.\n\nPor favor, compruebe que su contacto ha recibido su enlace y lo ha agregado:</string>
|
||||
<string name="offline_state">No hay conexión a Internet</string>
|
||||
<string name="duplicate_link_dialog_title">Duplicar enlace</string>
|
||||
<string name="duplicate_link_dialog_text_1">Ya tiene un contacto pendiente con este enlace: %s</string>
|
||||
@@ -238,6 +242,7 @@
|
||||
<string name="introduction_button">Hacer presentación</string>
|
||||
<string name="introduction_sent">Tu presentación se ha mandado.</string>
|
||||
<string name="introduction_error">Ocurrió un error realizando la presentación.</string>
|
||||
<string name="introduction_response_error">Error al responder a la presentación</string>
|
||||
<string name="introduction_request_sent">Le has preguntado a %1$s si quiere que le presentes a %2$s.</string>
|
||||
<string name="introduction_request_received">%1$s ha pedido presentarte a %2$s. ¿Quieres añadir a %2$s a tu lista de contactos?</string>
|
||||
<string name="introduction_request_exists_received">%1$s ha pedido presentarte a %2$s, pero %2$s ya está en tu lista de contactos. %1$s puede no saberlo, así que puedes responderle de todas maneras:</string>
|
||||
@@ -408,12 +413,20 @@
|
||||
<string name="pref_theme_dark">Oscuro</string>
|
||||
<string name="pref_theme_auto">Automático (Diurno)</string>
|
||||
<string name="pref_theme_system">Predeterminado del sistema</string>
|
||||
<!--Settings Connections-->
|
||||
<string name="network_settings_title">Conexiones</string>
|
||||
<!--Settings Network-->
|
||||
<string name="network_settings_title">Redes</string>
|
||||
<string name="bluetooth_setting">Conectar mediante Bluetooth</string>
|
||||
<string name="bluetooth_setting_enabled">Cuando haya contactos cerca</string>
|
||||
<string name="bluetooth_setting_disabled">Solo al añadir contactos</string>
|
||||
<string name="tor_network_setting">Conectar vía Internet (Tor)</string>
|
||||
<string name="tor_network_setting_automatic">Automático basado en ubicación</string>
|
||||
<!--How and when Briar will connect to Tor: E.g. "Don't connect to the Internet (in China)" or "Use Tor network with bridges (in Belarus)"-->
|
||||
<string name="tor_network_setting_without_bridges">Usar Tor sin puentes de red</string>
|
||||
<string name="tor_network_setting_with_bridges">Usar Tor con puentes de red</string>
|
||||
<string name="tor_network_setting_never">No conectar</string>
|
||||
<!--How and when Tor will connect after Automatic: E.g. Don't connect (in China) or Use Tor with bridges (in Belarus)-->
|
||||
<string name="tor_network_setting_summary">Automática: %1$s (en %2$s)</string>
|
||||
<string name="tor_mobile_data_title">Usar datos móviles</string>
|
||||
<string name="tor_only_when_charging_title">Conectar vía Internet (Tor) solamente cuando está cargando</string>
|
||||
<string name="tor_only_when_charging_summary">Deshabilita la conexión a Internet cuando el dispositivo está corriendo con batería.</string>
|
||||
<!--Settings Security and Panic-->
|
||||
<string name="security_settings_title">Seguridad</string>
|
||||
@@ -454,6 +467,8 @@
|
||||
<string name="panic_setting_signout_summary">Cerrar la sesión de Briar si se pulsa un botón de pánico</string>
|
||||
<string name="purge_setting_title">Eliminar cuenta</string>
|
||||
<string name="purge_setting_summary">Eliminar tu cuenta de Briar si se pulsa un botón de pánico. Precaución: esto eliminará permanentemente tus identidades, contactos y mensajes</string>
|
||||
<string name="uninstall_setting_title">Desinstalar Briar</string>
|
||||
<string name="uninstall_setting_summary">Requerirá confirmación manual en un evento de pánico</string>
|
||||
<!--Settings Notifications-->
|
||||
<string name="notification_settings_title">Notificaciones</string>
|
||||
<string name="notify_sign_in_title">Recordarme para iniciar sesión</string>
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user