mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-17 05:09:53 +01:00
Miscellaneous code cleanups.
This commit is contained in:
@@ -13,8 +13,7 @@ import org.briarproject.bramble.api.lifecycle.Service;
|
|||||||
import org.briarproject.bramble.api.network.NetworkManager;
|
import org.briarproject.bramble.api.network.NetworkManager;
|
||||||
import org.briarproject.bramble.api.network.NetworkStatus;
|
import org.briarproject.bramble.api.network.NetworkStatus;
|
||||||
import org.briarproject.bramble.api.network.event.NetworkStatusEvent;
|
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.system.Scheduler;
|
import org.briarproject.bramble.api.system.Scheduler;
|
||||||
|
|
||||||
import java.util.concurrent.Future;
|
import java.util.concurrent.Future;
|
||||||
@@ -34,13 +33,13 @@ import static android.net.ConnectivityManager.CONNECTIVITY_ACTION;
|
|||||||
import static android.net.ConnectivityManager.TYPE_WIFI;
|
import static android.net.ConnectivityManager.TYPE_WIFI;
|
||||||
import static android.os.Build.VERSION.SDK_INT;
|
import static android.os.Build.VERSION.SDK_INT;
|
||||||
import static android.os.PowerManager.ACTION_DEVICE_IDLE_MODE_CHANGED;
|
import static android.os.PowerManager.ACTION_DEVICE_IDLE_MODE_CHANGED;
|
||||||
|
import static java.util.Objects.requireNonNull;
|
||||||
import static java.util.concurrent.TimeUnit.MINUTES;
|
import static java.util.concurrent.TimeUnit.MINUTES;
|
||||||
import static java.util.concurrent.TimeUnit.SECONDS;
|
import static java.util.concurrent.TimeUnit.SECONDS;
|
||||||
import static java.util.logging.Level.INFO;
|
import static java.util.logging.Level.INFO;
|
||||||
import static java.util.logging.Logger.getLogger;
|
import static java.util.logging.Logger.getLogger;
|
||||||
|
|
||||||
@MethodsNotNullByDefault
|
@NotNullByDefault
|
||||||
@ParametersNotNullByDefault
|
|
||||||
class AndroidNetworkManager implements NetworkManager, Service {
|
class AndroidNetworkManager implements NetworkManager, Service {
|
||||||
|
|
||||||
private static final Logger LOG =
|
private static final Logger LOG =
|
||||||
@@ -57,6 +56,7 @@ class AndroidNetworkManager implements NetworkManager, Service {
|
|||||||
new AtomicReference<>();
|
new AtomicReference<>();
|
||||||
private final AtomicBoolean used = new AtomicBoolean(false);
|
private final AtomicBoolean used = new AtomicBoolean(false);
|
||||||
|
|
||||||
|
@Nullable
|
||||||
private volatile BroadcastReceiver networkStateReceiver = null;
|
private volatile BroadcastReceiver networkStateReceiver = null;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
@@ -90,9 +90,8 @@ class AndroidNetworkManager implements NetworkManager, Service {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NetworkStatus getNetworkStatus() {
|
public NetworkStatus getNetworkStatus() {
|
||||||
ConnectivityManager cm = (ConnectivityManager)
|
ConnectivityManager cm = (ConnectivityManager) requireNonNull(
|
||||||
appContext.getSystemService(CONNECTIVITY_SERVICE);
|
appContext.getSystemService(CONNECTIVITY_SERVICE));
|
||||||
if (cm == null) throw new AssertionError();
|
|
||||||
NetworkInfo net = cm.getActiveNetworkInfo();
|
NetworkInfo net = cm.getActiveNetworkInfo();
|
||||||
boolean connected = net != null && net.isConnected();
|
boolean connected = net != null && net.isConnected();
|
||||||
boolean wifi = connected && net.getType() == TYPE_WIFI;
|
boolean wifi = connected && net.getType() == TYPE_WIFI;
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ import static android.net.ConnectivityManager.TYPE_WIFI;
|
|||||||
import static android.os.Build.VERSION.SDK_INT;
|
import static android.os.Build.VERSION.SDK_INT;
|
||||||
import static java.util.Collections.emptyList;
|
import static java.util.Collections.emptyList;
|
||||||
import static java.util.Collections.singletonList;
|
import static java.util.Collections.singletonList;
|
||||||
|
import static java.util.Objects.requireNonNull;
|
||||||
import static java.util.logging.Logger.getLogger;
|
import static java.util.logging.Logger.getLogger;
|
||||||
|
|
||||||
@NotNullByDefault
|
@NotNullByDefault
|
||||||
@@ -67,10 +68,8 @@ class AndroidLanTcpPlugin extends LanTcpPlugin implements EventListener {
|
|||||||
// Don't execute more than one connection status check at a time
|
// Don't execute more than one connection status check at a time
|
||||||
connectionStatusExecutor =
|
connectionStatusExecutor =
|
||||||
new PoliteExecutor("AndroidLanTcpPlugin", ioExecutor, 1);
|
new PoliteExecutor("AndroidLanTcpPlugin", ioExecutor, 1);
|
||||||
ConnectivityManager connectivityManager = (ConnectivityManager)
|
connectivityManager = (ConnectivityManager) requireNonNull(
|
||||||
appContext.getSystemService(CONNECTIVITY_SERVICE);
|
appContext.getSystemService(CONNECTIVITY_SERVICE));
|
||||||
if (connectivityManager == null) throw new AssertionError();
|
|
||||||
this.connectivityManager = connectivityManager;
|
|
||||||
wifiManager = (WifiManager) appContext.getApplicationContext()
|
wifiManager = (WifiManager) appContext.getApplicationContext()
|
||||||
.getSystemService(WIFI_SERVICE);
|
.getSystemService(WIFI_SERVICE);
|
||||||
socketFactory = SocketFactory.getDefault();
|
socketFactory = SocketFactory.getDefault();
|
||||||
|
|||||||
@@ -8,8 +8,7 @@ import android.os.PowerManager;
|
|||||||
|
|
||||||
import org.briarproject.bramble.api.battery.BatteryManager;
|
import org.briarproject.bramble.api.battery.BatteryManager;
|
||||||
import org.briarproject.bramble.api.network.NetworkManager;
|
import org.briarproject.bramble.api.network.NetworkManager;
|
||||||
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.Backoff;
|
||||||
import org.briarproject.bramble.api.plugin.duplex.DuplexPluginCallback;
|
import org.briarproject.bramble.api.plugin.duplex.DuplexPluginCallback;
|
||||||
import org.briarproject.bramble.api.system.Clock;
|
import org.briarproject.bramble.api.system.Clock;
|
||||||
@@ -26,10 +25,10 @@ import javax.net.SocketFactory;
|
|||||||
import static android.content.Context.MODE_PRIVATE;
|
import static android.content.Context.MODE_PRIVATE;
|
||||||
import static android.content.Context.POWER_SERVICE;
|
import static android.content.Context.POWER_SERVICE;
|
||||||
import static android.os.PowerManager.PARTIAL_WAKE_LOCK;
|
import static android.os.PowerManager.PARTIAL_WAKE_LOCK;
|
||||||
|
import static java.util.Objects.requireNonNull;
|
||||||
import static java.util.concurrent.TimeUnit.MINUTES;
|
import static java.util.concurrent.TimeUnit.MINUTES;
|
||||||
|
|
||||||
@MethodsNotNullByDefault
|
@NotNullByDefault
|
||||||
@ParametersNotNullByDefault
|
|
||||||
class AndroidTorPlugin extends TorPlugin {
|
class AndroidTorPlugin extends TorPlugin {
|
||||||
|
|
||||||
// This tag may prevent Huawei's power manager from killing us
|
// This tag may prevent Huawei's power manager from killing us
|
||||||
@@ -52,8 +51,7 @@ class AndroidTorPlugin extends TorPlugin {
|
|||||||
appContext.getDir("tor", MODE_PRIVATE));
|
appContext.getDir("tor", MODE_PRIVATE));
|
||||||
this.appContext = appContext;
|
this.appContext = appContext;
|
||||||
PowerManager pm = (PowerManager)
|
PowerManager pm = (PowerManager)
|
||||||
appContext.getSystemService(POWER_SERVICE);
|
requireNonNull(appContext.getSystemService(POWER_SERVICE));
|
||||||
if (pm == null) throw new AssertionError();
|
|
||||||
wakeLock = new RenewableWakeLock(pm, scheduler, PARTIAL_WAKE_LOCK,
|
wakeLock = new RenewableWakeLock(pm, scheduler, PARTIAL_WAKE_LOCK,
|
||||||
WAKE_LOCK_TAG, 1, MINUTES);
|
WAKE_LOCK_TAG, 1, MINUTES);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,14 +60,14 @@ class AndroidLocationUtils implements LocationUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private String getCountryFromPhoneNetwork() {
|
private String getCountryFromPhoneNetwork() {
|
||||||
Object o = appContext.getSystemService(TELEPHONY_SERVICE);
|
TelephonyManager tm = (TelephonyManager)
|
||||||
TelephonyManager tm = (TelephonyManager) o;
|
appContext.getSystemService(TELEPHONY_SERVICE);
|
||||||
return tm.getNetworkCountryIso();
|
return tm == null ? "" : tm.getNetworkCountryIso();
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getCountryFromSimCard() {
|
private String getCountryFromSimCard() {
|
||||||
Object o = appContext.getSystemService(TELEPHONY_SERVICE);
|
TelephonyManager tm = (TelephonyManager)
|
||||||
TelephonyManager tm = (TelephonyManager) o;
|
appContext.getSystemService(TELEPHONY_SERVICE);
|
||||||
return tm.getSimCountryIso();
|
return tm == null ? "" : tm.getSimCountryIso();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import org.briarproject.bramble.api.Bytes;
|
|||||||
import org.briarproject.bramble.api.FormatException;
|
import org.briarproject.bramble.api.FormatException;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
|
||||||
import java.util.TreeMap;
|
import java.util.TreeMap;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
@@ -24,9 +23,9 @@ public class BdfDictionary extends TreeMap<String, Object> {
|
|||||||
* );
|
* );
|
||||||
* </pre>
|
* </pre>
|
||||||
*/
|
*/
|
||||||
public static BdfDictionary of(Entry<String, ?>... entries) {
|
public static BdfDictionary of(BdfEntry... entries) {
|
||||||
BdfDictionary d = new BdfDictionary();
|
BdfDictionary d = new BdfDictionary();
|
||||||
for (Entry<String, ?> e : entries) d.put(e.getKey(), e.getValue());
|
for (BdfEntry e : entries) d.put(e.getKey(), e.getValue());
|
||||||
return d;
|
return d;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ public class BdfList extends ArrayList<Object> {
|
|||||||
super(items);
|
super(items);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("BooleanMethodIsAlwaysInverted")
|
||||||
private boolean isInRange(int index) {
|
private boolean isInRange(int index) {
|
||||||
return index >= 0 && index < size();
|
return index >= 0 && index < size();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ public class TransportId {
|
|||||||
/**
|
/**
|
||||||
* The maximum length of a transport identifier in UTF-8 bytes.
|
* The maximum length of a transport identifier in UTF-8 bytes.
|
||||||
*/
|
*/
|
||||||
public static int MAX_TRANSPORT_ID_LENGTH = 100;
|
public static final int MAX_TRANSPORT_ID_LENGTH = 100;
|
||||||
|
|
||||||
private final String id;
|
private final String id;
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ public class ClientId implements Comparable<ClientId> {
|
|||||||
/**
|
/**
|
||||||
* The maximum length of a client identifier in UTF-8 bytes.
|
* The maximum length of a client identifier in UTF-8 bytes.
|
||||||
*/
|
*/
|
||||||
public static int MAX_CLIENT_ID_LENGTH = 100;
|
public static final int MAX_CLIENT_ID_LENGTH = 100;
|
||||||
|
|
||||||
private final String id;
|
private final String id;
|
||||||
|
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ public class BdfDictionaryTest extends BrambleTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testKeySetIteratorIsOrderedByKeys() throws Exception {
|
public void testKeySetIteratorIsOrderedByKeys() {
|
||||||
BdfDictionary d = new BdfDictionary();
|
BdfDictionary d = new BdfDictionary();
|
||||||
d.put("a", 1);
|
d.put("a", 1);
|
||||||
d.put("d", 4);
|
d.put("d", 4);
|
||||||
@@ -87,7 +87,7 @@ public class BdfDictionaryTest extends BrambleTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testValuesIteratorIsOrderedByKeys() throws Exception {
|
public void testValuesIteratorIsOrderedByKeys() {
|
||||||
BdfDictionary d = new BdfDictionary();
|
BdfDictionary d = new BdfDictionary();
|
||||||
d.put("a", 1);
|
d.put("a", 1);
|
||||||
d.put("d", 4);
|
d.put("d", 4);
|
||||||
@@ -106,7 +106,7 @@ public class BdfDictionaryTest extends BrambleTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEntrySetIteratorIsOrderedByKeys() throws Exception {
|
public void testEntrySetIteratorIsOrderedByKeys() {
|
||||||
BdfDictionary d = new BdfDictionary();
|
BdfDictionary d = new BdfDictionary();
|
||||||
d.put("a", 1);
|
d.put("a", 1);
|
||||||
d.put("d", 4);
|
d.put("d", 4);
|
||||||
|
|||||||
@@ -6,8 +6,7 @@ import org.briarproject.bramble.api.crypto.SecretKey;
|
|||||||
import org.briarproject.bramble.api.db.DatabaseConfig;
|
import org.briarproject.bramble.api.db.DatabaseConfig;
|
||||||
import org.briarproject.bramble.api.identity.IdentityManager;
|
import org.briarproject.bramble.api.identity.IdentityManager;
|
||||||
import org.briarproject.bramble.api.identity.LocalAuthor;
|
import org.briarproject.bramble.api.identity.LocalAuthor;
|
||||||
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@@ -27,8 +26,7 @@ import static org.briarproject.bramble.util.LogUtils.logException;
|
|||||||
import static org.briarproject.bramble.util.StringUtils.fromHexString;
|
import static org.briarproject.bramble.util.StringUtils.fromHexString;
|
||||||
import static org.briarproject.bramble.util.StringUtils.toHexString;
|
import static org.briarproject.bramble.util.StringUtils.toHexString;
|
||||||
|
|
||||||
@MethodsNotNullByDefault
|
@NotNullByDefault
|
||||||
@ParametersNotNullByDefault
|
|
||||||
class AccountManagerImpl implements AccountManager {
|
class AccountManagerImpl implements AccountManager {
|
||||||
|
|
||||||
private static final Logger LOG =
|
private static final Logger LOG =
|
||||||
@@ -104,7 +102,7 @@ class AccountManagerImpl implements AccountManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Locking: stateChangeLock
|
// Locking: stateChangeLock
|
||||||
protected boolean storeEncryptedDatabaseKey(String hex) {
|
boolean storeEncryptedDatabaseKey(String hex) {
|
||||||
LOG.info("Storing database key in file");
|
LOG.info("Storing database key in file");
|
||||||
// Create the directory if necessary
|
// Create the directory if necessary
|
||||||
if (databaseConfig.getDatabaseKeyDirectory().mkdirs())
|
if (databaseConfig.getDatabaseKeyDirectory().mkdirs())
|
||||||
|
|||||||
@@ -191,6 +191,7 @@ class ContactExchangeTaskImpl extends Thread implements ContactExchangeTask {
|
|||||||
streamWriter.sendEndOfStream();
|
streamWriter.sendEndOfStream();
|
||||||
// Skip any remaining records from the incoming stream
|
// Skip any remaining records from the incoming stream
|
||||||
try {
|
try {
|
||||||
|
//noinspection InfiniteLoopStatement
|
||||||
while (true) recordReader.readRecord();
|
while (true) recordReader.readRecord();
|
||||||
} catch (EOFException expected) {
|
} catch (EOFException expected) {
|
||||||
LOG.info("End of stream");
|
LOG.info("End of stream");
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ class AsciiArmour {
|
|||||||
int length = wrapped.length();
|
int length = wrapped.length();
|
||||||
for (int i = 0; i < length; i += lineLength) {
|
for (int i = 0; i < length; i += lineLength) {
|
||||||
int end = Math.min(i + lineLength, length);
|
int end = Math.min(i + lineLength, length);
|
||||||
s.append(wrapped.substring(i, end));
|
s.append(wrapped, i, end);
|
||||||
s.append("\r\n");
|
s.append("\r\n");
|
||||||
}
|
}
|
||||||
return s.toString();
|
return s.toString();
|
||||||
|
|||||||
@@ -159,6 +159,7 @@ public class MessageEncrypter {
|
|||||||
printUsage();
|
printUsage();
|
||||||
System.exit(1);
|
System.exit(1);
|
||||||
}
|
}
|
||||||
|
//noinspection IfCanBeSwitch
|
||||||
if (args[0].equals("generate")) {
|
if (args[0].equals("generate")) {
|
||||||
if (args.length != 3) {
|
if (args.length != 3) {
|
||||||
printUsage();
|
printUsage();
|
||||||
|
|||||||
@@ -242,7 +242,7 @@ interface Database<T> {
|
|||||||
* bytes. This is based on the minimum of the space available on the device
|
* bytes. This is based on the minimum of the space available on the device
|
||||||
* where the database is stored and the database's configured size.
|
* where the database is stored and the database's configured size.
|
||||||
*/
|
*/
|
||||||
long getFreeSpace() throws DbException;
|
long getFreeSpace();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the group with the given ID.
|
* Returns the group with the given ID.
|
||||||
|
|||||||
@@ -339,6 +339,7 @@ abstract class JdbcDatabase implements Database<Connection> {
|
|||||||
this.clock = clock;
|
this.clock = clock;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
protected void open(String driverClass, boolean reopen, SecretKey key,
|
protected void open(String driverClass, boolean reopen, SecretKey key,
|
||||||
@Nullable MigrationListener listener) throws DbException {
|
@Nullable MigrationListener listener) throws DbException {
|
||||||
// Load the JDBC driver
|
// Load the JDBC driver
|
||||||
@@ -768,7 +769,7 @@ abstract class JdbcDatabase implements Database<Connection> {
|
|||||||
for (Entry<ContactId, Boolean> e : visibility.entrySet()) {
|
for (Entry<ContactId, Boolean> e : visibility.entrySet()) {
|
||||||
ContactId c = e.getKey();
|
ContactId c = e.getKey();
|
||||||
boolean offered = removeOfferedMessage(txn, c, m.getId());
|
boolean offered = removeOfferedMessage(txn, c, m.getId());
|
||||||
boolean seen = offered || (sender != null && c.equals(sender));
|
boolean seen = offered || c.equals(sender);
|
||||||
addStatus(txn, m.getId(), c, m.getGroupId(), m.getTimestamp(),
|
addStatus(txn, m.getId(), c, m.getGroupId(), m.getTimestamp(),
|
||||||
raw.length, state, e.getValue(), messageShared,
|
raw.length, state, e.getValue(), messageShared,
|
||||||
false, seen);
|
false, seen);
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ class Migration40_41 implements Migration<Connection> {
|
|||||||
|
|
||||||
private final DatabaseTypes dbTypes;
|
private final DatabaseTypes dbTypes;
|
||||||
|
|
||||||
public Migration40_41(DatabaseTypes databaseTypes) {
|
Migration40_41(DatabaseTypes databaseTypes) {
|
||||||
this.dbTypes = databaseTypes;
|
this.dbTypes = databaseTypes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package org.briarproject.bramble.keyagreement;
|
|||||||
|
|
||||||
class AbortException extends Exception {
|
class AbortException extends Exception {
|
||||||
|
|
||||||
boolean receivedAbort;
|
final boolean receivedAbort;
|
||||||
|
|
||||||
AbortException() {
|
AbortException() {
|
||||||
this(false);
|
this(false);
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ interface BluetoothConnectionLimiter {
|
|||||||
* Returns true if a contact connection can be opened. This method does not
|
* Returns true if a contact connection can be opened. This method does not
|
||||||
* need to be called for key agreement connections.
|
* need to be called for key agreement connections.
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("BooleanMethodIsAlwaysInverted")
|
||||||
boolean canOpenContactConnection();
|
boolean canOpenContactConnection();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -80,6 +80,7 @@ class LanTcpPlugin extends TcpPlugin {
|
|||||||
locals.add(new InetSocketAddress(local, 0));
|
locals.add(new InetSocketAddress(local, 0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//noinspection Java8ListSort
|
||||||
sort(locals, ADDRESS_COMPARATOR);
|
sort(locals, ADDRESS_COMPARATOR);
|
||||||
return locals;
|
return locals;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -85,6 +85,7 @@ abstract class TcpPlugin implements DuplexPlugin {
|
|||||||
/**
|
/**
|
||||||
* Returns true if connections to the given address can be attempted.
|
* Returns true if connections to the given address can be attempted.
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("BooleanMethodIsAlwaysInverted")
|
||||||
protected abstract boolean isConnectable(InetSocketAddress remote);
|
protected abstract boolean isConnectable(InetSocketAddress remote);
|
||||||
|
|
||||||
TcpPlugin(Executor ioExecutor, Backoff backoff,
|
TcpPlugin(Executor ioExecutor, Backoff backoff,
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ abstract class Frame {
|
|||||||
|
|
||||||
static final byte ACK_FLAG = (byte) 128, FIN_FLAG = 64;
|
static final byte ACK_FLAG = (byte) 128, FIN_FLAG = 64;
|
||||||
|
|
||||||
protected final byte[] buf;
|
final byte[] buf;
|
||||||
|
|
||||||
Frame(byte[] buf) {
|
Frame(byte[] buf) {
|
||||||
this.buf = buf;
|
this.buf = buf;
|
||||||
|
|||||||
@@ -101,6 +101,7 @@ class Receiver implements ReadHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("StatementWithEmptyBody")
|
||||||
private void handleData(byte[] b) throws IOException {
|
private void handleData(byte[] b) throws IOException {
|
||||||
windowLock.lock();
|
windowLock.lock();
|
||||||
try {
|
try {
|
||||||
@@ -124,6 +125,7 @@ class Receiver implements ReadHandler {
|
|||||||
finalSequenceNumber = sequenceNumber;
|
finalSequenceNumber = sequenceNumber;
|
||||||
// Remove any data frames with higher sequence numbers
|
// Remove any data frames with higher sequence numbers
|
||||||
Iterator<Data> it = dataFrames.iterator();
|
Iterator<Data> it = dataFrames.iterator();
|
||||||
|
//noinspection Java8CollectionRemoveIf
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
Data d1 = it.next();
|
Data d1 = it.next();
|
||||||
if (d1.getSequenceNumber() >= finalSequenceNumber)
|
if (d1.getSequenceNumber() >= finalSequenceNumber)
|
||||||
@@ -148,6 +150,7 @@ class Receiver implements ReadHandler {
|
|||||||
|
|
||||||
private static class SequenceNumberComparator implements Comparator<Data> {
|
private static class SequenceNumberComparator implements Comparator<Data> {
|
||||||
|
|
||||||
|
@SuppressWarnings("UseCompareMethod")
|
||||||
@Override
|
@Override
|
||||||
public int compare(Data d1, Data d2) {
|
public int compare(Data d1, Data d2) {
|
||||||
long s1 = d1.getSequenceNumber(), s2 = d2.getSequenceNumber();
|
long s1 = d1.getSequenceNumber(), s2 = d2.getSequenceNumber();
|
||||||
|
|||||||
@@ -52,6 +52,7 @@ class ReceiverInputStream extends InputStream {
|
|||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("BooleanMethodIsAlwaysInverted")
|
||||||
private boolean receive() throws IOException {
|
private boolean receive() throws IOException {
|
||||||
if (length != 0) throw new AssertionError();
|
if (length != 0) throw new AssertionError();
|
||||||
if (data != null && data.isLastFrame()) {
|
if (data != null && data.isLastFrame()) {
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import java.util.concurrent.locks.ReentrantLock;
|
|||||||
import javax.annotation.concurrent.ThreadSafe;
|
import javax.annotation.concurrent.ThreadSafe;
|
||||||
|
|
||||||
import static java.util.concurrent.TimeUnit.MILLISECONDS;
|
import static java.util.concurrent.TimeUnit.MILLISECONDS;
|
||||||
|
import static org.briarproject.bramble.api.nullsafety.NullSafety.requireNonNull;
|
||||||
|
|
||||||
@ThreadSafe
|
@ThreadSafe
|
||||||
@NotNullByDefault
|
@NotNullByDefault
|
||||||
@@ -96,7 +97,7 @@ class Sender {
|
|||||||
}
|
}
|
||||||
// If any older data frames are outstanding, retransmit the oldest
|
// If any older data frames are outstanding, retransmit the oldest
|
||||||
if (foundIndex > 0) {
|
if (foundIndex > 0) {
|
||||||
fastRetransmit = outstanding.poll();
|
fastRetransmit = requireNonNull(outstanding.poll());
|
||||||
fastRetransmit.lastTransmitted = now;
|
fastRetransmit.lastTransmitted = now;
|
||||||
fastRetransmit.retransmitted = true;
|
fastRetransmit.retransmitted = true;
|
||||||
outstanding.add(fastRetransmit);
|
outstanding.add(fastRetransmit);
|
||||||
@@ -191,7 +192,7 @@ class Sender {
|
|||||||
writeHandler.handleWrite(d.getBuffer());
|
writeHandler.handleWrite(d.getBuffer());
|
||||||
}
|
}
|
||||||
|
|
||||||
void flush() throws IOException, InterruptedException {
|
void flush() throws InterruptedException {
|
||||||
windowLock.lock();
|
windowLock.lock();
|
||||||
try {
|
try {
|
||||||
while (dataWaiting || !outstanding.isEmpty())
|
while (dataWaiting || !outstanding.isEmpty())
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ public class DevReportServer {
|
|||||||
TokenBucket bucket = new TokenBucket();
|
TokenBucket bucket = new TokenBucket();
|
||||||
bucket.start();
|
bucket.start();
|
||||||
try {
|
try {
|
||||||
|
//noinspection InfiniteLoopStatement
|
||||||
while (true) {
|
while (true) {
|
||||||
Socket s = ss.accept();
|
Socket s = ss.accept();
|
||||||
System.out.println("Incoming connection");
|
System.out.println("Incoming connection");
|
||||||
@@ -103,6 +104,7 @@ public class DevReportServer {
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
|
//noinspection InfiniteLoopStatement
|
||||||
while (true) {
|
while (true) {
|
||||||
// If the bucket isn't full, add a token
|
// If the bucket isn't full, add a token
|
||||||
if (semaphore.availablePermits() < MAX_TOKENS) {
|
if (semaphore.availablePermits() < MAX_TOKENS) {
|
||||||
@@ -134,6 +136,8 @@ public class DevReportServer {
|
|||||||
try {
|
try {
|
||||||
socket.setSoTimeout(SOCKET_TIMEOUT_MS);
|
socket.setSoTimeout(SOCKET_TIMEOUT_MS);
|
||||||
in = getInputStream(socket);
|
in = getInputStream(socket);
|
||||||
|
// Directory may already exist
|
||||||
|
//noinspection ResultOfMethodCallIgnored
|
||||||
reportDir.mkdirs();
|
reportDir.mkdirs();
|
||||||
reportFile = createTempFile(FILE_PREFIX, FILE_SUFFIX,
|
reportFile = createTempFile(FILE_PREFIX, FILE_SUFFIX,
|
||||||
reportDir);
|
reportDir);
|
||||||
@@ -153,7 +157,8 @@ public class DevReportServer {
|
|||||||
System.out.println("Saved " + length + " bytes");
|
System.out.println("Saved " + length + " bytes");
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
if (reportFile != null) reportFile.delete();
|
if (reportFile != null && !reportFile.delete())
|
||||||
|
System.err.println("Failed to delete report");
|
||||||
} finally {
|
} finally {
|
||||||
tryToClose(in);
|
tryToClose(in);
|
||||||
tryToClose(out);
|
tryToClose(out);
|
||||||
|
|||||||
@@ -111,17 +111,15 @@ class DevReporterImpl implements DevReporter, EventListener {
|
|||||||
LOG.info("Sending reports to developers");
|
LOG.info("Sending reports to developers");
|
||||||
for (File f : reports) {
|
for (File f : reports) {
|
||||||
OutputStream out = null;
|
OutputStream out = null;
|
||||||
InputStream in = null;
|
|
||||||
try {
|
try {
|
||||||
Socket s = connectToDevelopers();
|
Socket s = connectToDevelopers();
|
||||||
out = getOutputStream(s);
|
out = getOutputStream(s);
|
||||||
in = new FileInputStream(f);
|
InputStream in = new FileInputStream(f);
|
||||||
copyAndClose(in, out);
|
copyAndClose(in, out);
|
||||||
f.delete();
|
if (!f.delete()) LOG.warning("Failed to delete report");
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
LOG.log(WARNING, "Failed to send reports", e);
|
LOG.log(WARNING, "Failed to send reports", e);
|
||||||
tryToClose(out, LOG, WARNING);
|
tryToClose(out, LOG, WARNING);
|
||||||
tryToClose(in, LOG, WARNING);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ class SocksSocket extends Socket {
|
|||||||
"Address type not supported"
|
"Address type not supported"
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@SuppressWarnings("MismatchedReadAndWriteOfArray")
|
||||||
private static final byte[] UNSPECIFIED_ADDRESS = new byte[4];
|
private static final byte[] UNSPECIFIED_ADDRESS = new byte[4];
|
||||||
|
|
||||||
private final SocketAddress proxy;
|
private final SocketAddress proxy;
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ class SocksSocketFactory extends SocketFactory {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Socket createSocket(InetAddress address, int port,
|
public Socket createSocket(InetAddress address, int port,
|
||||||
InetAddress localAddress, int localPort) throws IOException {
|
InetAddress localAddress, int localPort) {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import javax.annotation.concurrent.Immutable;
|
|||||||
|
|
||||||
import static java.util.logging.Level.WARNING;
|
import static java.util.logging.Level.WARNING;
|
||||||
import static java.util.logging.Logger.getLogger;
|
import static java.util.logging.Logger.getLogger;
|
||||||
|
import static org.briarproject.bramble.util.IoUtils.tryToClose;
|
||||||
import static org.briarproject.bramble.util.LogUtils.logException;
|
import static org.briarproject.bramble.util.LogUtils.logException;
|
||||||
|
|
||||||
@Immutable
|
@Immutable
|
||||||
@@ -43,15 +44,16 @@ class UnixSecureRandomProvider extends AbstractSecureRandomProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected void writeSeed() {
|
protected void writeSeed() {
|
||||||
|
DataOutputStream out = null;
|
||||||
try {
|
try {
|
||||||
DataOutputStream out = new DataOutputStream(
|
out = new DataOutputStream(new FileOutputStream(outputDevice));
|
||||||
new FileOutputStream(outputDevice));
|
|
||||||
writeToEntropyPool(out);
|
writeToEntropyPool(out);
|
||||||
out.flush();
|
out.flush();
|
||||||
out.close();
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
// On some devices /dev/urandom isn't writable - this isn't fatal
|
// On some devices /dev/urandom isn't writable - this isn't fatal
|
||||||
logException(LOG, WARNING, e);
|
logException(LOG, WARNING, e);
|
||||||
|
} finally {
|
||||||
|
tryToClose(out, LOG, WARNING);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import java.util.logging.Logger;
|
|||||||
|
|
||||||
import static java.util.logging.Level.WARNING;
|
import static java.util.logging.Level.WARNING;
|
||||||
import static java.util.logging.Logger.getLogger;
|
import static java.util.logging.Logger.getLogger;
|
||||||
|
import static org.briarproject.bramble.util.IoUtils.tryToClose;
|
||||||
import static org.briarproject.bramble.util.LogUtils.logException;
|
import static org.briarproject.bramble.util.LogUtils.logException;
|
||||||
|
|
||||||
public class UnixSecureRandomSpi extends SecureRandomSpi {
|
public class UnixSecureRandomSpi extends SecureRandomSpi {
|
||||||
@@ -34,15 +35,16 @@ public class UnixSecureRandomSpi extends SecureRandomSpi {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void engineSetSeed(byte[] seed) {
|
protected void engineSetSeed(byte[] seed) {
|
||||||
|
DataOutputStream out = null;
|
||||||
try {
|
try {
|
||||||
DataOutputStream out = new DataOutputStream(
|
out = new DataOutputStream(new FileOutputStream(outputDevice));
|
||||||
new FileOutputStream(outputDevice));
|
|
||||||
out.write(seed);
|
out.write(seed);
|
||||||
out.flush();
|
out.flush();
|
||||||
out.close();
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
// On some devices /dev/urandom isn't writable - this isn't fatal
|
// On some devices /dev/urandom isn't writable - this isn't fatal
|
||||||
logException(LOG, WARNING, e);
|
logException(LOG, WARNING, e);
|
||||||
|
} finally {
|
||||||
|
tryToClose(out, LOG, WARNING);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ import static org.junit.Assert.assertEquals;
|
|||||||
public class EllipticCurveMultiplicationTest extends BrambleTestCase {
|
public class EllipticCurveMultiplicationTest extends BrambleTestCase {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMultiplierProducesSameResultsAsDefault() throws Exception {
|
public void testMultiplierProducesSameResultsAsDefault() {
|
||||||
// Instantiate the default implementation of the curve
|
// Instantiate the default implementation of the curve
|
||||||
X9ECParameters defaultX9Parameters =
|
X9ECParameters defaultX9Parameters =
|
||||||
TeleTrusTNamedCurves.getByName("brainpoolp256r1");
|
TeleTrusTNamedCurves.getByName("brainpoolp256r1");
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ public class KeyAgreementTest extends BrambleTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRfc7748TestVector() throws Exception {
|
public void testRfc7748TestVector() {
|
||||||
// Private keys need to be clamped because curve25519-java does the
|
// Private keys need to be clamped because curve25519-java does the
|
||||||
// clamping at key generation time, not multiplication time
|
// clamping at key generation time, not multiplication time
|
||||||
byte[] aPriv = Curve25519KeyParser.clamp(fromHexString(ALICE_PRIVATE));
|
byte[] aPriv = Curve25519KeyParser.clamp(fromHexString(ALICE_PRIVATE));
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ public class KeyEncodingAndParsingTest extends BrambleTestCase {
|
|||||||
new CryptoComponentImpl(new TestSecureRandomProvider(), null);
|
new CryptoComponentImpl(new TestSecureRandomProvider(), null);
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAgreementPublicKeyLength() throws Exception {
|
public void testAgreementPublicKeyLength() {
|
||||||
// Generate 10 agreement key pairs
|
// Generate 10 agreement key pairs
|
||||||
for (int i = 0; i < 10; i++) {
|
for (int i = 0; i < 10; i++) {
|
||||||
KeyPair keyPair = crypto.generateAgreementKeyPair();
|
KeyPair keyPair = crypto.generateAgreementKeyPair();
|
||||||
@@ -70,7 +70,7 @@ public class KeyEncodingAndParsingTest extends BrambleTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAgreementKeyParserByFuzzing() throws Exception {
|
public void testAgreementKeyParserByFuzzing() {
|
||||||
KeyParser parser = crypto.getAgreementKeyParser();
|
KeyParser parser = crypto.getAgreementKeyParser();
|
||||||
// Generate a key pair to get the proper public key length
|
// Generate a key pair to get the proper public key length
|
||||||
KeyPair p = crypto.generateAgreementKeyPair();
|
KeyPair p = crypto.generateAgreementKeyPair();
|
||||||
@@ -92,7 +92,7 @@ public class KeyEncodingAndParsingTest extends BrambleTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSignaturePublicKeyLength() throws Exception {
|
public void testSignaturePublicKeyLength() {
|
||||||
// Generate 10 signature key pairs
|
// Generate 10 signature key pairs
|
||||||
for (int i = 0; i < 10; i++) {
|
for (int i = 0; i < 10; i++) {
|
||||||
KeyPair keyPair = crypto.generateSignatureKeyPair();
|
KeyPair keyPair = crypto.generateSignatureKeyPair();
|
||||||
@@ -159,7 +159,7 @@ public class KeyEncodingAndParsingTest extends BrambleTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSignatureKeyParserByFuzzing() throws Exception {
|
public void testSignatureKeyParserByFuzzing() {
|
||||||
KeyParser parser = crypto.getSignatureKeyParser();
|
KeyParser parser = crypto.getSignatureKeyParser();
|
||||||
// Generate a key pair to get the proper public key length
|
// Generate a key pair to get the proper public key length
|
||||||
KeyPair p = crypto.generateSignatureKeyPair();
|
KeyPair p = crypto.generateSignatureKeyPair();
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ import static org.junit.Assert.assertEquals;
|
|||||||
public class ScryptKdfTest extends BrambleTestCase {
|
public class ScryptKdfTest extends BrambleTestCase {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPasswordAffectsKey() throws Exception {
|
public void testPasswordAffectsKey() {
|
||||||
PasswordBasedKdf kdf = new ScryptKdf(new SystemClock());
|
PasswordBasedKdf kdf = new ScryptKdf(new SystemClock());
|
||||||
byte[] salt = getRandomBytes(32);
|
byte[] salt = getRandomBytes(32);
|
||||||
Set<Bytes> keys = new HashSet<>();
|
Set<Bytes> keys = new HashSet<>();
|
||||||
@@ -31,7 +31,7 @@ public class ScryptKdfTest extends BrambleTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSaltAffectsKey() throws Exception {
|
public void testSaltAffectsKey() {
|
||||||
PasswordBasedKdf kdf = new ScryptKdf(new SystemClock());
|
PasswordBasedKdf kdf = new ScryptKdf(new SystemClock());
|
||||||
String password = getRandomString(16);
|
String password = getRandomString(16);
|
||||||
Set<Bytes> keys = new HashSet<>();
|
Set<Bytes> keys = new HashSet<>();
|
||||||
@@ -43,7 +43,7 @@ public class ScryptKdfTest extends BrambleTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCostParameterAffectsKey() throws Exception {
|
public void testCostParameterAffectsKey() {
|
||||||
PasswordBasedKdf kdf = new ScryptKdf(new SystemClock());
|
PasswordBasedKdf kdf = new ScryptKdf(new SystemClock());
|
||||||
String password = getRandomString(16);
|
String password = getRandomString(16);
|
||||||
byte[] salt = getRandomBytes(32);
|
byte[] salt = getRandomBytes(32);
|
||||||
@@ -55,7 +55,7 @@ public class ScryptKdfTest extends BrambleTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCalibration() throws Exception {
|
public void testCalibration() {
|
||||||
Clock clock = new ArrayClock(
|
Clock clock = new ArrayClock(
|
||||||
0, 50, // Duration for cost 256
|
0, 50, // Duration for cost 256
|
||||||
0, 100, // Duration for cost 512
|
0, 100, // Duration for cost 512
|
||||||
@@ -68,7 +68,7 @@ public class ScryptKdfTest extends BrambleTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCalibrationChoosesMinCost() throws Exception {
|
public void testCalibrationChoosesMinCost() {
|
||||||
Clock clock = new ArrayClock(
|
Clock clock = new ArrayClock(
|
||||||
0, 2000 // Duration for cost 256 is already too high
|
0, 2000 // Duration for cost 256 is already too high
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ public class TagEncodingTest extends BrambleMockTestCase {
|
|||||||
private final long streamNumber = 1234567890;
|
private final long streamNumber = 1234567890;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testKeyAffectsTag() throws Exception {
|
public void testKeyAffectsTag() {
|
||||||
Set<Bytes> set = new HashSet<>();
|
Set<Bytes> set = new HashSet<>();
|
||||||
for (int i = 0; i < 100; i++) {
|
for (int i = 0; i < 100; i++) {
|
||||||
byte[] tag = new byte[TAG_LENGTH];
|
byte[] tag = new byte[TAG_LENGTH];
|
||||||
@@ -37,7 +37,7 @@ public class TagEncodingTest extends BrambleMockTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testProtocolVersionAffectsTag() throws Exception {
|
public void testProtocolVersionAffectsTag() {
|
||||||
Set<Bytes> set = new HashSet<>();
|
Set<Bytes> set = new HashSet<>();
|
||||||
for (int i = 0; i < 100; i++) {
|
for (int i = 0; i < 100; i++) {
|
||||||
byte[] tag = new byte[TAG_LENGTH];
|
byte[] tag = new byte[TAG_LENGTH];
|
||||||
@@ -48,7 +48,7 @@ public class TagEncodingTest extends BrambleMockTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testStreamNumberAffectsTag() throws Exception {
|
public void testStreamNumberAffectsTag() {
|
||||||
Set<Bytes> set = new HashSet<>();
|
Set<Bytes> set = new HashSet<>();
|
||||||
for (int i = 0; i < 100; i++) {
|
for (int i = 0; i < 100; i++) {
|
||||||
byte[] tag = new byte[TAG_LENGTH];
|
byte[] tag = new byte[TAG_LENGTH];
|
||||||
|
|||||||
@@ -14,8 +14,7 @@ class TestAuthenticatedCipher implements AuthenticatedCipher {
|
|||||||
private boolean encrypt = false;
|
private boolean encrypt = false;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void init(boolean encrypt, SecretKey key, byte[] iv)
|
public void init(boolean encrypt, SecretKey key, byte[] iv) {
|
||||||
throws GeneralSecurityException {
|
|
||||||
this.encrypt = encrypt;
|
this.encrypt = encrypt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -557,10 +557,10 @@ public class BdfReaderImplTest extends BrambleTestCase {
|
|||||||
@Test
|
@Test
|
||||||
public void testNestedListWithinDepthLimit() throws Exception {
|
public void testNestedListWithinDepthLimit() throws Exception {
|
||||||
// A list containing a list containing a list containing a list...
|
// A list containing a list containing a list containing a list...
|
||||||
String lists = "";
|
StringBuilder lists = new StringBuilder();
|
||||||
for (int i = 1; i <= DEFAULT_NESTED_LIMIT; i++) lists += "60";
|
for (int i = 1; i <= DEFAULT_NESTED_LIMIT; i++) lists.append("60");
|
||||||
for (int i = 1; i <= DEFAULT_NESTED_LIMIT; i++) lists += "80";
|
for (int i = 1; i <= DEFAULT_NESTED_LIMIT; i++) lists.append("80");
|
||||||
setContents(lists);
|
setContents(lists.toString());
|
||||||
r.readList();
|
r.readList();
|
||||||
assertTrue(r.eof());
|
assertTrue(r.eof());
|
||||||
}
|
}
|
||||||
@@ -568,23 +568,23 @@ public class BdfReaderImplTest extends BrambleTestCase {
|
|||||||
@Test(expected = FormatException.class)
|
@Test(expected = FormatException.class)
|
||||||
public void testNestedListOutsideDepthLimit() throws Exception {
|
public void testNestedListOutsideDepthLimit() throws Exception {
|
||||||
// A list containing a list containing a list containing a list...
|
// A list containing a list containing a list containing a list...
|
||||||
String lists = "";
|
StringBuilder lists = new StringBuilder();
|
||||||
for (int i = 1; i <= DEFAULT_NESTED_LIMIT + 1; i++) lists += "60";
|
for (int i = 1; i <= DEFAULT_NESTED_LIMIT + 1; i++) lists.append("60");
|
||||||
for (int i = 1; i <= DEFAULT_NESTED_LIMIT + 1; i++) lists += "80";
|
for (int i = 1; i <= DEFAULT_NESTED_LIMIT + 1; i++) lists.append("80");
|
||||||
setContents(lists);
|
setContents(lists.toString());
|
||||||
r.readList();
|
r.readList();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNestedDictionaryWithinDepthLimit() throws Exception {
|
public void testNestedDictionaryWithinDepthLimit() throws Exception {
|
||||||
// A dictionary containing a dictionary containing a dictionary...
|
// A dictionary containing a dictionary containing a dictionary...
|
||||||
String dicts = "";
|
StringBuilder dicts = new StringBuilder();
|
||||||
for (int i = 1; i <= DEFAULT_NESTED_LIMIT; i++)
|
for (int i = 1; i <= DEFAULT_NESTED_LIMIT; i++)
|
||||||
dicts += "70" + "41" + "03" + "666F6F";
|
dicts.append("70" + "41" + "03" + "666F6F");
|
||||||
dicts += "11";
|
dicts.append("11");
|
||||||
for (int i = 1; i <= DEFAULT_NESTED_LIMIT; i++)
|
for (int i = 1; i <= DEFAULT_NESTED_LIMIT; i++)
|
||||||
dicts += "80";
|
dicts.append("80");
|
||||||
setContents(dicts);
|
setContents(dicts.toString());
|
||||||
r.readDictionary();
|
r.readDictionary();
|
||||||
assertTrue(r.eof());
|
assertTrue(r.eof());
|
||||||
}
|
}
|
||||||
@@ -592,13 +592,13 @@ public class BdfReaderImplTest extends BrambleTestCase {
|
|||||||
@Test(expected = FormatException.class)
|
@Test(expected = FormatException.class)
|
||||||
public void testNestedDictionaryOutsideDepthLimit() throws Exception {
|
public void testNestedDictionaryOutsideDepthLimit() throws Exception {
|
||||||
// A dictionary containing a dictionary containing a dictionary...
|
// A dictionary containing a dictionary containing a dictionary...
|
||||||
String dicts = "";
|
StringBuilder dicts = new StringBuilder();
|
||||||
for (int i = 1; i <= DEFAULT_NESTED_LIMIT + 1; i++)
|
for (int i = 1; i <= DEFAULT_NESTED_LIMIT + 1; i++)
|
||||||
dicts += "70" + "41" + "03" + "666F6F";
|
dicts.append("70" + "41" + "03" + "666F6F");
|
||||||
dicts += "11";
|
dicts.append("11");
|
||||||
for (int i = 1; i <= DEFAULT_NESTED_LIMIT + 1; i++)
|
for (int i = 1; i <= DEFAULT_NESTED_LIMIT + 1; i++)
|
||||||
dicts += "80";
|
dicts.append("80");
|
||||||
setContents(dicts);
|
setContents(dicts.toString());
|
||||||
r.readDictionary();
|
r.readDictionary();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ import static org.junit.Assert.assertNull;
|
|||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
|
@SuppressWarnings("TryFinallyCanBeTryWithResources")
|
||||||
public abstract class BasicDatabaseTest extends BrambleTestCase {
|
public abstract class BasicDatabaseTest extends BrambleTestCase {
|
||||||
|
|
||||||
private static final int BATCH_SIZE = 100;
|
private static final int BATCH_SIZE = 100;
|
||||||
@@ -47,7 +48,7 @@ public abstract class BasicDatabaseTest extends BrambleTestCase {
|
|||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
testDir.mkdirs();
|
assertTrue(testDir.mkdirs());
|
||||||
Class.forName(getDriverName());
|
Class.forName(getDriverName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -40,8 +40,7 @@ public class BasicH2Test extends BasicDatabaseTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void shutdownDatabase(File db, boolean encrypt)
|
protected void shutdownDatabase(File db, boolean encrypt) {
|
||||||
throws SQLException {
|
|
||||||
// The DB is closed automatically when the connection is closed
|
// The DB is closed automatically when the connection is closed
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ public abstract class DatabaseMigrationTest extends BrambleMockTestCase {
|
|||||||
protected final Clock clock = new SystemClock();
|
protected final Clock clock = new SystemClock();
|
||||||
|
|
||||||
abstract Database<Connection> createDatabase(
|
abstract Database<Connection> createDatabase(
|
||||||
List<Migration<Connection>> migrations) throws Exception;
|
List<Migration<Connection>> migrations);
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
|
|||||||
@@ -29,7 +29,8 @@ public abstract class DatabasePerformanceComparisonTest
|
|||||||
* How many blocks of each condition to compare.
|
* How many blocks of each condition to compare.
|
||||||
*/
|
*/
|
||||||
private static final int COMPARISON_BLOCKS = 10;
|
private static final int COMPARISON_BLOCKS = 10;
|
||||||
private SecretKey databaseKey = getSecretKey();
|
|
||||||
|
private final SecretKey databaseKey = getSecretKey();
|
||||||
|
|
||||||
abstract Database<Connection> createDatabase(boolean conditionA,
|
abstract Database<Connection> createDatabase(boolean conditionA,
|
||||||
DatabaseConfig databaseConfig, MessageFactory messageFactory,
|
DatabaseConfig databaseConfig, MessageFactory messageFactory,
|
||||||
|
|||||||
@@ -20,10 +20,11 @@ import javax.annotation.Nullable;
|
|||||||
import static org.briarproject.bramble.test.TestUtils.deleteTestDirectory;
|
import static org.briarproject.bramble.test.TestUtils.deleteTestDirectory;
|
||||||
import static org.briarproject.bramble.test.TestUtils.getSecretKey;
|
import static org.briarproject.bramble.test.TestUtils.getSecretKey;
|
||||||
import static org.briarproject.bramble.util.IoUtils.copyAndClose;
|
import static org.briarproject.bramble.util.IoUtils.copyAndClose;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
public abstract class DatabaseTraceTest extends DatabasePerformanceTest {
|
public abstract class DatabaseTraceTest extends DatabasePerformanceTest {
|
||||||
|
|
||||||
private SecretKey databaseKey = getSecretKey();
|
private final SecretKey databaseKey = getSecretKey();
|
||||||
|
|
||||||
abstract Database<Connection> createDatabase(DatabaseConfig databaseConfig,
|
abstract Database<Connection> createDatabase(DatabaseConfig databaseConfig,
|
||||||
MessageFactory messageFactory, Clock clock);
|
MessageFactory messageFactory, Clock clock);
|
||||||
@@ -39,7 +40,8 @@ public abstract class DatabaseTraceTest extends DatabasePerformanceTest {
|
|||||||
populateDatabase(db);
|
populateDatabase(db);
|
||||||
db.close();
|
db.close();
|
||||||
File traceFile = getTraceFile();
|
File traceFile = getTraceFile();
|
||||||
if (traceFile != null) traceFile.delete();
|
if (traceFile != null && traceFile.exists())
|
||||||
|
assertTrue(traceFile.delete());
|
||||||
db = openDatabase();
|
db = openDatabase();
|
||||||
task.run(db);
|
task.run(db);
|
||||||
db.close();
|
db.close();
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package org.briarproject.bramble.db;
|
package org.briarproject.bramble.db;
|
||||||
|
|
||||||
import org.briarproject.bramble.api.db.DatabaseConfig;
|
import org.briarproject.bramble.api.db.DatabaseConfig;
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
import org.briarproject.bramble.api.sync.MessageFactory;
|
import org.briarproject.bramble.api.sync.MessageFactory;
|
||||||
import org.briarproject.bramble.api.system.Clock;
|
import org.briarproject.bramble.api.system.Clock;
|
||||||
import org.junit.Ignore;
|
import org.junit.Ignore;
|
||||||
@@ -8,9 +9,8 @@ import org.junit.Ignore;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
|
|
||||||
@Ignore
|
@Ignore
|
||||||
|
@NotNullByDefault
|
||||||
public class H2DatabaseTraceTest extends DatabaseTraceTest {
|
public class H2DatabaseTraceTest extends DatabaseTraceTest {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -18,7 +18,6 @@ public class H2DatabaseTraceTest extends DatabaseTraceTest {
|
|||||||
MessageFactory messageFactory, Clock clock) {
|
MessageFactory messageFactory, Clock clock) {
|
||||||
return new H2Database(databaseConfig, messageFactory, clock) {
|
return new H2Database(databaseConfig, messageFactory, clock) {
|
||||||
@Override
|
@Override
|
||||||
@Nonnull
|
|
||||||
String getUrl() {
|
String getUrl() {
|
||||||
return super.getUrl() + ";TRACE_LEVEL_FILE=3";
|
return super.getUrl() + ";TRACE_LEVEL_FILE=3";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import static org.junit.Assert.assertFalse;
|
|||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
|
@SuppressWarnings("TryFinallyCanBeTryWithResources")
|
||||||
public class H2TransactionIsolationTest extends BrambleTestCase {
|
public class H2TransactionIsolationTest extends BrambleTestCase {
|
||||||
|
|
||||||
private static final String DROP_TABLE = "DROP TABLE foo IF EXISTS";
|
private static final String DROP_TABLE = "DROP TABLE foo IF EXISTS";
|
||||||
@@ -47,7 +48,7 @@ public class H2TransactionIsolationTest extends BrambleTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
public void tearDown() throws Exception {
|
public void tearDown() {
|
||||||
deleteTestDirectory(testDir);
|
deleteTestDirectory(testDir);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -92,7 +92,6 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
|
|||||||
// All our transports use a maximum latency of 30 seconds
|
// All our transports use a maximum latency of 30 seconds
|
||||||
private static final int MAX_LATENCY = 30 * 1000;
|
private static final int MAX_LATENCY = 30 * 1000;
|
||||||
|
|
||||||
|
|
||||||
private final SecretKey key = getSecretKey();
|
private final SecretKey key = getSecretKey();
|
||||||
private final File testDir = getTestDirectory();
|
private final File testDir = getTestDirectory();
|
||||||
private final GroupId groupId;
|
private final GroupId groupId;
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ public abstract class SingleDatabasePerformanceTest
|
|||||||
abstract Database<Connection> createDatabase(DatabaseConfig databaseConfig,
|
abstract Database<Connection> createDatabase(DatabaseConfig databaseConfig,
|
||||||
MessageFactory messageFactory, Clock clock);
|
MessageFactory messageFactory, Clock clock);
|
||||||
|
|
||||||
private SecretKey databaseKey = getSecretKey();
|
private final SecretKey databaseKey = getSecretKey();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void benchmark(String name,
|
protected void benchmark(String name,
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ import static org.junit.Assert.assertThat;
|
|||||||
public class KeyAgreementProtocolTest extends BrambleTestCase {
|
public class KeyAgreementProtocolTest extends BrambleTestCase {
|
||||||
|
|
||||||
@Rule
|
@Rule
|
||||||
public JUnitRuleMockery context = new JUnitRuleMockery() {{
|
public final JUnitRuleMockery context = new JUnitRuleMockery() {{
|
||||||
// So we can mock concrete classes like KeyAgreementTransport
|
// So we can mock concrete classes like KeyAgreementTransport
|
||||||
setImposteriser(ClassImposteriser.INSTANCE);
|
setImposteriser(ClassImposteriser.INSTANCE);
|
||||||
}};
|
}};
|
||||||
|
|||||||
@@ -327,6 +327,7 @@ public class LanTcpPluginTest extends BrambleTestCase {
|
|||||||
assertEquals(0, comparator.compare(linkLocal, linkLocal));
|
assertEquals(0, comparator.compare(linkLocal, linkLocal));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("BooleanMethodIsAlwaysInverted")
|
||||||
private boolean systemHasLocalIpv4Address() throws Exception {
|
private boolean systemHasLocalIpv4Address() throws Exception {
|
||||||
for (NetworkInterface i : list(getNetworkInterfaces())) {
|
for (NetworkInterface i : list(getNetworkInterfaces())) {
|
||||||
for (InetAddress a : list(i.getInetAddresses())) {
|
for (InetAddress a : list(i.getInetAddresses())) {
|
||||||
|
|||||||
@@ -165,7 +165,7 @@ public class SyncRecordReaderImplTest extends BrambleMockTestCase {
|
|||||||
return new Record(PROTOCOL_VERSION, ACK, createPayload());
|
return new Record(PROTOCOL_VERSION, ACK, createPayload());
|
||||||
}
|
}
|
||||||
|
|
||||||
private Record createEmptyAck() throws Exception {
|
private Record createEmptyAck() {
|
||||||
return new Record(PROTOCOL_VERSION, ACK, new byte[0]);
|
return new Record(PROTOCOL_VERSION, ACK, new byte[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -173,7 +173,7 @@ public class SyncRecordReaderImplTest extends BrambleMockTestCase {
|
|||||||
return new Record(PROTOCOL_VERSION, OFFER, createPayload());
|
return new Record(PROTOCOL_VERSION, OFFER, createPayload());
|
||||||
}
|
}
|
||||||
|
|
||||||
private Record createEmptyOffer() throws Exception {
|
private Record createEmptyOffer() {
|
||||||
return new Record(PROTOCOL_VERSION, OFFER, new byte[0]);
|
return new Record(PROTOCOL_VERSION, OFFER, new byte[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -181,7 +181,7 @@ public class SyncRecordReaderImplTest extends BrambleMockTestCase {
|
|||||||
return new Record(PROTOCOL_VERSION, REQUEST, createPayload());
|
return new Record(PROTOCOL_VERSION, REQUEST, createPayload());
|
||||||
}
|
}
|
||||||
|
|
||||||
private Record createEmptyRequest() throws Exception {
|
private Record createEmptyRequest() {
|
||||||
return new Record(PROTOCOL_VERSION, REQUEST, new byte[0]);
|
return new Record(PROTOCOL_VERSION, REQUEST, new byte[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import org.jmock.api.Invocation;
|
|||||||
public class RunAction implements Action {
|
public class RunAction implements Action {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object invoke(Invocation invocation) throws Throwable {
|
public Object invoke(Invocation invocation) {
|
||||||
Runnable task = (Runnable) invocation.getParameter(0);
|
Runnable task = (Runnable) invocation.getParameter(0);
|
||||||
task.run();
|
task.run();
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ public class RunTransactionAction implements Action {
|
|||||||
|
|
||||||
private final Transaction txn;
|
private final Transaction txn;
|
||||||
|
|
||||||
@SuppressWarnings("WeakerAccess")
|
|
||||||
public RunTransactionAction(Transaction txn) {
|
public RunTransactionAction(Transaction txn) {
|
||||||
this.txn = txn;
|
this.txn = txn;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package org.briarproject.bramble.test;
|
package org.briarproject.bramble.test;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.FileReader;
|
import java.io.FileReader;
|
||||||
@@ -7,13 +9,12 @@ import java.io.IOException;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
|
|
||||||
import static java.util.Collections.sort;
|
import static java.util.Collections.sort;
|
||||||
import static org.briarproject.bramble.test.UTest.Result.INCONCLUSIVE;
|
import static org.briarproject.bramble.test.UTest.Result.INCONCLUSIVE;
|
||||||
import static org.briarproject.bramble.test.UTest.Result.LARGER;
|
import static org.briarproject.bramble.test.UTest.Result.LARGER;
|
||||||
import static org.briarproject.bramble.test.UTest.Result.SMALLER;
|
import static org.briarproject.bramble.test.UTest.Result.SMALLER;
|
||||||
|
|
||||||
|
@NotNullByDefault
|
||||||
public class UTest {
|
public class UTest {
|
||||||
|
|
||||||
public enum Result {
|
public enum Result {
|
||||||
@@ -158,8 +159,7 @@ public class UTest {
|
|||||||
private static List<Double> readFile(String filename) {
|
private static List<Double> readFile(String filename) {
|
||||||
List<Double> values = new ArrayList<>();
|
List<Double> values = new ArrayList<>();
|
||||||
try {
|
try {
|
||||||
BufferedReader in;
|
BufferedReader in = new BufferedReader(new FileReader(filename));
|
||||||
in = new BufferedReader(new FileReader(filename));
|
|
||||||
String s;
|
String s;
|
||||||
while ((s = in.readLine()) != null) values.add(new Double(s));
|
while ((s = in.readLine()) != null) values.add(new Double(s));
|
||||||
in.close();
|
in.close();
|
||||||
@@ -185,8 +185,9 @@ public class UTest {
|
|||||||
this.a = a;
|
this.a = a;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("UseCompareMethod")
|
||||||
@Override
|
@Override
|
||||||
public int compareTo(@Nonnull Value v) {
|
public int compareTo(Value v) {
|
||||||
if (value < v.value) return -1;
|
if (value < v.value) return -1;
|
||||||
if (value > v.value) return 1;
|
if (value > v.value) return 1;
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@@ -33,11 +33,13 @@ public class ByteUtilsTest extends BrambleTestCase {
|
|||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test(expected = IllegalArgumentException.class)
|
||||||
public void testReadUint16ValidatesArguments1() {
|
public void testReadUint16ValidatesArguments1() {
|
||||||
|
//noinspection ResultOfMethodCallIgnored
|
||||||
readUint16(new byte[1], 0);
|
readUint16(new byte[1], 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test(expected = IllegalArgumentException.class)
|
||||||
public void testReadUint16ValidatesArguments2() {
|
public void testReadUint16ValidatesArguments2() {
|
||||||
|
//noinspection ResultOfMethodCallIgnored
|
||||||
readUint16(new byte[2], 1);
|
readUint16(new byte[2], 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -55,11 +57,13 @@ public class ByteUtilsTest extends BrambleTestCase {
|
|||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test(expected = IllegalArgumentException.class)
|
||||||
public void testReadUint32ValidatesArguments1() {
|
public void testReadUint32ValidatesArguments1() {
|
||||||
|
//noinspection ResultOfMethodCallIgnored
|
||||||
readUint32(new byte[3], 0);
|
readUint32(new byte[3], 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test(expected = IllegalArgumentException.class)
|
||||||
public void testReadUint32ValidatesArguments2() {
|
public void testReadUint32ValidatesArguments2() {
|
||||||
|
//noinspection ResultOfMethodCallIgnored
|
||||||
readUint32(new byte[4], 1);
|
readUint32(new byte[4], 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -79,11 +83,13 @@ public class ByteUtilsTest extends BrambleTestCase {
|
|||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test(expected = IllegalArgumentException.class)
|
||||||
public void testReadUint64ValidatesArguments1() {
|
public void testReadUint64ValidatesArguments1() {
|
||||||
|
//noinspection ResultOfMethodCallIgnored
|
||||||
readUint64(new byte[7], 0);
|
readUint64(new byte[7], 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test(expected = IllegalArgumentException.class)
|
||||||
public void testReadUint64ValidatesArguments2() {
|
public void testReadUint64ValidatesArguments2() {
|
||||||
|
//noinspection ResultOfMethodCallIgnored
|
||||||
readUint64(new byte[8], 1);
|
readUint64(new byte[8], 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ import java.util.Map;
|
|||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
import javax.annotation.concurrent.ThreadSafe;
|
import javax.annotation.concurrent.ThreadSafe;
|
||||||
|
|
||||||
import static com.sun.jna.Library.OPTION_FUNCTION_MAPPER;
|
import static com.sun.jna.Library.OPTION_FUNCTION_MAPPER;
|
||||||
@@ -163,11 +164,13 @@ class WindowsShutdownManagerImpl extends ShutdownManagerImpl {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("UnusedReturnValue")
|
||||||
private interface User32 extends StdCallLibrary {
|
private interface User32 extends StdCallLibrary {
|
||||||
|
|
||||||
HWND CreateWindowEx(int styleEx, String className, String windowName,
|
HWND CreateWindowEx(int styleEx, String className, String windowName,
|
||||||
int style, int x, int y, int width, int height, HWND parent,
|
int style, int x, int y, int width, int height,
|
||||||
HMENU menu, HINSTANCE instance, Pointer param);
|
@Nullable HWND parent, @Nullable HMENU menu,
|
||||||
|
@Nullable HINSTANCE instance, @Nullable Pointer param);
|
||||||
|
|
||||||
LRESULT DefWindowProc(HWND hwnd, int msg, WPARAM wp, LPARAM lp);
|
LRESULT DefWindowProc(HWND hwnd, int msg, WPARAM wp, LPARAM lp);
|
||||||
|
|
||||||
@@ -175,7 +178,8 @@ class WindowsShutdownManagerImpl extends ShutdownManagerImpl {
|
|||||||
|
|
||||||
LRESULT SetWindowLongPtr(HWND hwnd, int index, WindowProc newProc);
|
LRESULT SetWindowLongPtr(HWND hwnd, int index, WindowProc newProc);
|
||||||
|
|
||||||
int GetMessage(MSG msg, HWND hwnd, int filterMin, int filterMax);
|
int GetMessage(MSG msg, @Nullable HWND hwnd, int filterMin,
|
||||||
|
int filterMax);
|
||||||
|
|
||||||
boolean TranslateMessage(MSG msg);
|
boolean TranslateMessage(MSG msg);
|
||||||
|
|
||||||
@@ -184,6 +188,7 @@ class WindowsShutdownManagerImpl extends ShutdownManagerImpl {
|
|||||||
|
|
||||||
private interface WindowProc extends StdCallCallback {
|
private interface WindowProc extends StdCallCallback {
|
||||||
|
|
||||||
|
@SuppressWarnings("UnusedReturnValue")
|
||||||
LRESULT callback(HWND hwnd, int msg, WPARAM wp, LPARAM lp);
|
LRESULT callback(HWND hwnd, int msg, WPARAM wp, LPARAM lp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,8 +2,7 @@ package org.briarproject.bramble.network;
|
|||||||
|
|
||||||
import org.briarproject.bramble.api.network.NetworkManager;
|
import org.briarproject.bramble.api.network.NetworkManager;
|
||||||
import org.briarproject.bramble.api.network.NetworkStatus;
|
import org.briarproject.bramble.api.network.NetworkStatus;
|
||||||
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
|
||||||
|
|
||||||
import java.net.NetworkInterface;
|
import java.net.NetworkInterface;
|
||||||
import java.net.SocketException;
|
import java.net.SocketException;
|
||||||
@@ -19,8 +18,7 @@ import static java.util.logging.Level.WARNING;
|
|||||||
import static java.util.logging.Logger.getLogger;
|
import static java.util.logging.Logger.getLogger;
|
||||||
import static org.briarproject.bramble.util.LogUtils.logException;
|
import static org.briarproject.bramble.util.LogUtils.logException;
|
||||||
|
|
||||||
@MethodsNotNullByDefault
|
@NotNullByDefault
|
||||||
@ParametersNotNullByDefault
|
|
||||||
class JavaNetworkManager implements NetworkManager {
|
class JavaNetworkManager implements NetworkManager {
|
||||||
|
|
||||||
private static final Logger LOG =
|
private static final Logger LOG =
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ import java.util.concurrent.locks.ReentrantLock;
|
|||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
import javax.annotation.concurrent.GuardedBy;
|
||||||
|
|
||||||
import jssc.SerialPortEvent;
|
import jssc.SerialPortEvent;
|
||||||
import jssc.SerialPortEventListener;
|
import jssc.SerialPortEventListener;
|
||||||
@@ -63,9 +64,12 @@ class ModemImpl implements Modem, WriteHandler, SerialPortEventListener {
|
|||||||
private final Condition connectedStateChanged = lock.newCondition();
|
private final Condition connectedStateChanged = lock.newCondition();
|
||||||
private final Condition initialisedStateChanged = lock.newCondition();
|
private final Condition initialisedStateChanged = lock.newCondition();
|
||||||
|
|
||||||
// The following are locking: lock
|
@GuardedBy("lock")
|
||||||
private ReliabilityLayer reliability = null;
|
private ReliabilityLayer reliability = null;
|
||||||
private boolean initialised = false, connected = false;
|
@GuardedBy("lock")
|
||||||
|
private boolean initialised = false;
|
||||||
|
@GuardedBy("lock")
|
||||||
|
private boolean connected = false;
|
||||||
|
|
||||||
private int lineLen = 0;
|
private int lineLen = 0;
|
||||||
|
|
||||||
|
|||||||
@@ -19,12 +19,14 @@ package im.delight.android.identicons;
|
|||||||
import android.graphics.Canvas;
|
import android.graphics.Canvas;
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
import android.graphics.Paint;
|
import android.graphics.Paint;
|
||||||
import android.support.annotation.NonNull;
|
|
||||||
import android.support.annotation.UiThread;
|
import android.support.annotation.UiThread;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
|
||||||
import static android.graphics.Paint.Style.FILL;
|
import static android.graphics.Paint.Style.FILL;
|
||||||
|
|
||||||
@UiThread
|
@UiThread
|
||||||
|
@NotNullByDefault
|
||||||
class Identicon {
|
class Identicon {
|
||||||
|
|
||||||
private static final int ROWS = 9, COLUMNS = 9;
|
private static final int ROWS = 9, COLUMNS = 9;
|
||||||
@@ -36,7 +38,7 @@ class Identicon {
|
|||||||
|
|
||||||
private int cellWidth, cellHeight;
|
private int cellWidth, cellHeight;
|
||||||
|
|
||||||
Identicon(@NonNull byte[] input) {
|
Identicon(byte[] input) {
|
||||||
if (input.length == 0) throw new IllegalArgumentException();
|
if (input.length == 0) throw new IllegalArgumentException();
|
||||||
this.input = input;
|
this.input = input;
|
||||||
|
|
||||||
|
|||||||
@@ -20,19 +20,22 @@ import android.graphics.Canvas;
|
|||||||
import android.graphics.ColorFilter;
|
import android.graphics.ColorFilter;
|
||||||
import android.graphics.Rect;
|
import android.graphics.Rect;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.Nullable;
|
||||||
import android.support.annotation.UiThread;
|
import android.support.annotation.UiThread;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
|
||||||
import static android.graphics.PixelFormat.OPAQUE;
|
import static android.graphics.PixelFormat.OPAQUE;
|
||||||
|
|
||||||
@UiThread
|
@UiThread
|
||||||
|
@NotNullByDefault
|
||||||
public class IdenticonDrawable extends Drawable {
|
public class IdenticonDrawable extends Drawable {
|
||||||
|
|
||||||
private static final int HEIGHT = 200, WIDTH = 200;
|
private static final int HEIGHT = 200, WIDTH = 200;
|
||||||
|
|
||||||
private final Identicon identicon;
|
private final Identicon identicon;
|
||||||
|
|
||||||
public IdenticonDrawable(@NonNull byte[] input) {
|
public IdenticonDrawable(byte[] input) {
|
||||||
super();
|
super();
|
||||||
identicon = new Identicon(input);
|
identicon = new Identicon(input);
|
||||||
}
|
}
|
||||||
@@ -48,7 +51,7 @@ public class IdenticonDrawable extends Drawable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setBounds(@NonNull Rect bounds) {
|
public void setBounds(Rect bounds) {
|
||||||
super.setBounds(bounds);
|
super.setBounds(bounds);
|
||||||
identicon.updateSize(bounds.right - bounds.left,
|
identicon.updateSize(bounds.right - bounds.left,
|
||||||
bounds.bottom - bounds.top);
|
bounds.bottom - bounds.top);
|
||||||
@@ -61,7 +64,7 @@ public class IdenticonDrawable extends Drawable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void draw(@NonNull Canvas canvas) {
|
public void draw(Canvas canvas) {
|
||||||
identicon.draw(canvas);
|
identicon.draw(canvas);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -71,7 +74,7 @@ public class IdenticonDrawable extends Drawable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setColorFilter(ColorFilter cf) {
|
public void setColorFilter(@Nullable ColorFilter cf) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import android.app.PendingIntent;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
import android.support.annotation.StringRes;
|
import android.support.annotation.StringRes;
|
||||||
import android.support.annotation.UiThread;
|
import android.support.annotation.UiThread;
|
||||||
import android.support.v4.app.NotificationCompat;
|
import android.support.v4.app.NotificationCompat;
|
||||||
@@ -21,8 +22,7 @@ import org.briarproject.bramble.api.event.Event;
|
|||||||
import org.briarproject.bramble.api.event.EventListener;
|
import org.briarproject.bramble.api.event.EventListener;
|
||||||
import org.briarproject.bramble.api.lifecycle.Service;
|
import org.briarproject.bramble.api.lifecycle.Service;
|
||||||
import org.briarproject.bramble.api.lifecycle.ServiceException;
|
import org.briarproject.bramble.api.lifecycle.ServiceException;
|
||||||
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.settings.Settings;
|
import org.briarproject.bramble.api.settings.Settings;
|
||||||
import org.briarproject.bramble.api.settings.SettingsManager;
|
import org.briarproject.bramble.api.settings.SettingsManager;
|
||||||
import org.briarproject.bramble.api.settings.event.SettingsUpdatedEvent;
|
import org.briarproject.bramble.api.settings.event.SettingsUpdatedEvent;
|
||||||
@@ -82,8 +82,7 @@ import static org.briarproject.briar.android.navdrawer.NavDrawerActivity.INTENT_
|
|||||||
import static org.briarproject.briar.android.settings.SettingsFragment.SETTINGS_NAMESPACE;
|
import static org.briarproject.briar.android.settings.SettingsFragment.SETTINGS_NAMESPACE;
|
||||||
|
|
||||||
@ThreadSafe
|
@ThreadSafe
|
||||||
@MethodsNotNullByDefault
|
@NotNullByDefault
|
||||||
@ParametersNotNullByDefault
|
|
||||||
class AndroidNotificationManagerImpl implements AndroidNotificationManager,
|
class AndroidNotificationManagerImpl implements AndroidNotificationManager,
|
||||||
Service, EventListener {
|
Service, EventListener {
|
||||||
|
|
||||||
@@ -103,12 +102,12 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager,
|
|||||||
private final Multiset<GroupId> blogCounts = new Multiset<>();
|
private final Multiset<GroupId> blogCounts = new Multiset<>();
|
||||||
private int introductionTotal = 0;
|
private int introductionTotal = 0;
|
||||||
private int nextRequestId = 0;
|
private int nextRequestId = 0;
|
||||||
|
@Nullable
|
||||||
private ContactId blockedContact = null;
|
private ContactId blockedContact = null;
|
||||||
|
@Nullable
|
||||||
private GroupId blockedGroup = null;
|
private GroupId blockedGroup = null;
|
||||||
private boolean blockSignInReminder = false;
|
private boolean blockSignInReminder = false;
|
||||||
private boolean blockContacts = false, blockGroups = false;
|
private boolean blockBlogs = false;
|
||||||
private boolean blockForums = false, blockBlogs = false;
|
|
||||||
private boolean blockIntroductions = false;
|
|
||||||
private long lastSound = 0;
|
private long lastSound = 0;
|
||||||
|
|
||||||
private volatile Settings settings = new Settings();
|
private volatile Settings settings = new Settings();
|
||||||
@@ -283,7 +282,6 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager,
|
|||||||
|
|
||||||
private void showContactNotification(ContactId c) {
|
private void showContactNotification(ContactId c) {
|
||||||
androidExecutor.runOnUiThread(() -> {
|
androidExecutor.runOnUiThread(() -> {
|
||||||
if (blockContacts) return;
|
|
||||||
if (c.equals(blockedContact)) return;
|
if (c.equals(blockedContact)) return;
|
||||||
contactCounts.add(c);
|
contactCounts.add(c);
|
||||||
updateContactNotification(true);
|
updateContactNotification(true);
|
||||||
@@ -385,7 +383,6 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager,
|
|||||||
@UiThread
|
@UiThread
|
||||||
private void showGroupMessageNotification(GroupId g) {
|
private void showGroupMessageNotification(GroupId g) {
|
||||||
androidExecutor.runOnUiThread(() -> {
|
androidExecutor.runOnUiThread(() -> {
|
||||||
if (blockGroups) return;
|
|
||||||
if (g.equals(blockedGroup)) return;
|
if (g.equals(blockedGroup)) return;
|
||||||
groupCounts.add(g);
|
groupCounts.add(g);
|
||||||
updateGroupMessageNotification(true);
|
updateGroupMessageNotification(true);
|
||||||
@@ -456,7 +453,6 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager,
|
|||||||
@UiThread
|
@UiThread
|
||||||
private void showForumPostNotification(GroupId g) {
|
private void showForumPostNotification(GroupId g) {
|
||||||
androidExecutor.runOnUiThread(() -> {
|
androidExecutor.runOnUiThread(() -> {
|
||||||
if (blockForums) return;
|
|
||||||
if (g.equals(blockedGroup)) return;
|
if (g.equals(blockedGroup)) return;
|
||||||
forumCounts.add(g);
|
forumCounts.add(g);
|
||||||
updateForumPostNotification(true);
|
updateForumPostNotification(true);
|
||||||
@@ -580,7 +576,6 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager,
|
|||||||
|
|
||||||
private void showIntroductionNotification() {
|
private void showIntroductionNotification() {
|
||||||
androidExecutor.runOnUiThread(() -> {
|
androidExecutor.runOnUiThread(() -> {
|
||||||
if (blockIntroductions) return;
|
|
||||||
introductionTotal++;
|
introductionTotal++;
|
||||||
updateIntroductionNotification();
|
updateIntroductionNotification();
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK;
|
|||||||
import static android.content.Intent.FLAG_ACTIVITY_NO_ANIMATION;
|
import static android.content.Intent.FLAG_ACTIVITY_NO_ANIMATION;
|
||||||
import static android.os.Build.VERSION.SDK_INT;
|
import static android.os.Build.VERSION.SDK_INT;
|
||||||
import static android.support.v4.app.NotificationCompat.VISIBILITY_SECRET;
|
import static android.support.v4.app.NotificationCompat.VISIBILITY_SECRET;
|
||||||
|
import static java.util.Objects.requireNonNull;
|
||||||
import static java.util.logging.Level.INFO;
|
import static java.util.logging.Level.INFO;
|
||||||
import static java.util.logging.Level.WARNING;
|
import static java.util.logging.Level.WARNING;
|
||||||
import static java.util.logging.Logger.getLogger;
|
import static java.util.logging.Logger.getLogger;
|
||||||
@@ -57,11 +58,11 @@ import static org.briarproject.briar.api.android.LockManager.ACTION_LOCK;
|
|||||||
|
|
||||||
public class BriarService extends Service {
|
public class BriarService extends Service {
|
||||||
|
|
||||||
public static String EXTRA_START_RESULT =
|
public static final String EXTRA_START_RESULT =
|
||||||
"org.briarproject.briar.START_RESULT";
|
"org.briarproject.briar.START_RESULT";
|
||||||
public static String EXTRA_NOTIFICATION_ID =
|
public static final String EXTRA_NOTIFICATION_ID =
|
||||||
"org.briarproject.briar.FAILURE_NOTIFICATION_ID";
|
"org.briarproject.briar.FAILURE_NOTIFICATION_ID";
|
||||||
public static String EXTRA_STARTUP_FAILED =
|
public static final String EXTRA_STARTUP_FAILED =
|
||||||
"org.briarproject.briar.STARTUP_FAILED";
|
"org.briarproject.briar.STARTUP_FAILED";
|
||||||
|
|
||||||
private static final Logger LOG = getLogger(BriarService.class.getName());
|
private static final Logger LOG = getLogger(BriarService.class.getName());
|
||||||
@@ -110,7 +111,7 @@ public class BriarService extends Service {
|
|||||||
// Create notification channels
|
// Create notification channels
|
||||||
if (SDK_INT >= 26) {
|
if (SDK_INT >= 26) {
|
||||||
NotificationManager nm = (NotificationManager)
|
NotificationManager nm = (NotificationManager)
|
||||||
getSystemService(NOTIFICATION_SERVICE);
|
requireNonNull(getSystemService(NOTIFICATION_SERVICE));
|
||||||
NotificationChannel ongoingChannel = new NotificationChannel(
|
NotificationChannel ongoingChannel = new NotificationChannel(
|
||||||
ONGOING_CHANNEL_ID,
|
ONGOING_CHANNEL_ID,
|
||||||
getString(R.string.ongoing_notification_title),
|
getString(R.string.ongoing_notification_title),
|
||||||
@@ -178,8 +179,8 @@ public class BriarService extends Service {
|
|||||||
i.putExtra(EXTRA_NOTIFICATION_ID, FAILURE_NOTIFICATION_ID);
|
i.putExtra(EXTRA_NOTIFICATION_ID, FAILURE_NOTIFICATION_ID);
|
||||||
b.setContentIntent(PendingIntent.getActivity(BriarService.this,
|
b.setContentIntent(PendingIntent.getActivity(BriarService.this,
|
||||||
0, i, FLAG_UPDATE_CURRENT));
|
0, i, FLAG_UPDATE_CURRENT));
|
||||||
Object o = getSystemService(NOTIFICATION_SERVICE);
|
NotificationManager nm = (NotificationManager)
|
||||||
NotificationManager nm = (NotificationManager) o;
|
requireNonNull(getSystemService(NOTIFICATION_SERVICE));
|
||||||
nm.notify(FAILURE_NOTIFICATION_ID, b.build());
|
nm.notify(FAILURE_NOTIFICATION_ID, b.build());
|
||||||
// Bring the dashboard to the front to clear the back stack
|
// Bring the dashboard to the front to clear the back stack
|
||||||
i = new Intent(BriarService.this, NavDrawerActivity.class);
|
i = new Intent(BriarService.this, NavDrawerActivity.class);
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import android.content.IntentFilter;
|
|||||||
import android.os.PowerManager;
|
import android.os.PowerManager;
|
||||||
|
|
||||||
import org.briarproject.bramble.api.lifecycle.Service;
|
import org.briarproject.bramble.api.lifecycle.Service;
|
||||||
import org.briarproject.bramble.api.lifecycle.ServiceException;
|
|
||||||
import org.briarproject.briar.api.android.DozeWatchdog;
|
import org.briarproject.briar.api.android.DozeWatchdog;
|
||||||
|
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
@@ -15,6 +14,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
|||||||
import static android.content.Context.POWER_SERVICE;
|
import static android.content.Context.POWER_SERVICE;
|
||||||
import static android.os.Build.VERSION.SDK_INT;
|
import static android.os.Build.VERSION.SDK_INT;
|
||||||
import static android.os.PowerManager.ACTION_DEVICE_IDLE_MODE_CHANGED;
|
import static android.os.PowerManager.ACTION_DEVICE_IDLE_MODE_CHANGED;
|
||||||
|
import static java.util.Objects.requireNonNull;
|
||||||
|
|
||||||
class DozeWatchdogImpl implements DozeWatchdog, Service {
|
class DozeWatchdogImpl implements DozeWatchdog, Service {
|
||||||
|
|
||||||
@@ -32,14 +32,14 @@ class DozeWatchdogImpl implements DozeWatchdog, Service {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void startService() throws ServiceException {
|
public void startService() {
|
||||||
if (SDK_INT < 23) return;
|
if (SDK_INT < 23) return;
|
||||||
IntentFilter filter = new IntentFilter(ACTION_DEVICE_IDLE_MODE_CHANGED);
|
IntentFilter filter = new IntentFilter(ACTION_DEVICE_IDLE_MODE_CHANGED);
|
||||||
appContext.registerReceiver(receiver, filter);
|
appContext.registerReceiver(receiver, filter);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void stopService() throws ServiceException {
|
public void stopService() {
|
||||||
if (SDK_INT < 23) return;
|
if (SDK_INT < 23) return;
|
||||||
appContext.unregisterReceiver(receiver);
|
appContext.unregisterReceiver(receiver);
|
||||||
}
|
}
|
||||||
@@ -49,8 +49,8 @@ class DozeWatchdogImpl implements DozeWatchdog, Service {
|
|||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
if (SDK_INT < 23) return;
|
if (SDK_INT < 23) return;
|
||||||
PowerManager pm =
|
PowerManager pm = (PowerManager)
|
||||||
(PowerManager) appContext.getSystemService(POWER_SERVICE);
|
requireNonNull(appContext.getSystemService(POWER_SERVICE));
|
||||||
if (pm.isDeviceIdleMode()) dozed.set(true);
|
if (pm.isDeviceIdleMode()) dozed.set(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ public class NotificationCleanupService extends IntentService {
|
|||||||
protected void onHandleIntent(@Nullable Intent i) {
|
protected void onHandleIntent(@Nullable Intent i) {
|
||||||
if (i == null || i.getData() == null) return;
|
if (i == null || i.getData() == null) return;
|
||||||
String uri = i.getData().toString();
|
String uri = i.getData().toString();
|
||||||
|
//noinspection IfCanBeSwitch
|
||||||
if (uri.equals(CONTACT_URI)) {
|
if (uri.equals(CONTACT_URI)) {
|
||||||
notificationManager.clearAllContactNotifications();
|
notificationManager.clearAllContactNotifications();
|
||||||
} else if (uri.equals(GROUP_URI)) {
|
} else if (uri.equals(GROUP_URI)) {
|
||||||
|
|||||||
@@ -8,8 +8,7 @@ import com.vanniktech.emoji.emoji.Emoji;
|
|||||||
import org.briarproject.bramble.api.db.DatabaseExecutor;
|
import org.briarproject.bramble.api.db.DatabaseExecutor;
|
||||||
import org.briarproject.bramble.api.db.DbException;
|
import org.briarproject.bramble.api.db.DbException;
|
||||||
import org.briarproject.bramble.api.db.Transaction;
|
import org.briarproject.bramble.api.db.Transaction;
|
||||||
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.settings.Settings;
|
import org.briarproject.bramble.api.settings.Settings;
|
||||||
import org.briarproject.bramble.api.settings.SettingsManager;
|
import org.briarproject.bramble.api.settings.SettingsManager;
|
||||||
import org.briarproject.bramble.api.sync.Client;
|
import org.briarproject.bramble.api.sync.Client;
|
||||||
@@ -29,8 +28,7 @@ import static org.briarproject.bramble.util.LogUtils.logException;
|
|||||||
import static org.briarproject.bramble.util.StringUtils.join;
|
import static org.briarproject.bramble.util.StringUtils.join;
|
||||||
import static org.briarproject.briar.android.settings.SettingsFragment.SETTINGS_NAMESPACE;
|
import static org.briarproject.briar.android.settings.SettingsFragment.SETTINGS_NAMESPACE;
|
||||||
|
|
||||||
@MethodsNotNullByDefault
|
@NotNullByDefault
|
||||||
@ParametersNotNullByDefault
|
|
||||||
class RecentEmojiImpl implements RecentEmoji, Client {
|
class RecentEmojiImpl implements RecentEmoji, Client {
|
||||||
|
|
||||||
private static final Logger LOG =
|
private static final Logger LOG =
|
||||||
|
|||||||
@@ -44,8 +44,8 @@ public class StartupFailureActivity extends BaseActivity implements
|
|||||||
|
|
||||||
// cancel notification
|
// cancel notification
|
||||||
if (notificationId > -1) {
|
if (notificationId > -1) {
|
||||||
Object o = getSystemService(NOTIFICATION_SERVICE);
|
NotificationManager nm = (NotificationManager)
|
||||||
NotificationManager nm = (NotificationManager) requireNonNull(o);
|
requireNonNull(getSystemService(NOTIFICATION_SERVICE));
|
||||||
nm.cancel(notificationId);
|
nm.cancel(notificationId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -14,8 +14,7 @@ import org.briarproject.bramble.api.db.DbException;
|
|||||||
import org.briarproject.bramble.api.event.Event;
|
import org.briarproject.bramble.api.event.Event;
|
||||||
import org.briarproject.bramble.api.event.EventListener;
|
import org.briarproject.bramble.api.event.EventListener;
|
||||||
import org.briarproject.bramble.api.lifecycle.Service;
|
import org.briarproject.bramble.api.lifecycle.Service;
|
||||||
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.settings.Settings;
|
import org.briarproject.bramble.api.settings.Settings;
|
||||||
import org.briarproject.bramble.api.settings.SettingsManager;
|
import org.briarproject.bramble.api.settings.SettingsManager;
|
||||||
import org.briarproject.bramble.api.settings.event.SettingsUpdatedEvent;
|
import org.briarproject.bramble.api.settings.event.SettingsUpdatedEvent;
|
||||||
@@ -34,6 +33,7 @@ import static android.app.AlarmManager.ELAPSED_REALTIME;
|
|||||||
import static android.app.PendingIntent.getService;
|
import static android.app.PendingIntent.getService;
|
||||||
import static android.content.Context.ALARM_SERVICE;
|
import static android.content.Context.ALARM_SERVICE;
|
||||||
import static android.os.SystemClock.elapsedRealtime;
|
import static android.os.SystemClock.elapsedRealtime;
|
||||||
|
import static java.util.Objects.requireNonNull;
|
||||||
import static java.util.concurrent.TimeUnit.MINUTES;
|
import static java.util.concurrent.TimeUnit.MINUTES;
|
||||||
import static java.util.logging.Level.WARNING;
|
import static java.util.logging.Level.WARNING;
|
||||||
import static java.util.logging.Logger.getLogger;
|
import static java.util.logging.Logger.getLogger;
|
||||||
@@ -44,8 +44,7 @@ import static org.briarproject.briar.android.settings.SettingsFragment.SETTINGS_
|
|||||||
import static org.briarproject.briar.android.util.UiUtils.hasScreenLock;
|
import static org.briarproject.briar.android.util.UiUtils.hasScreenLock;
|
||||||
|
|
||||||
@ThreadSafe
|
@ThreadSafe
|
||||||
@MethodsNotNullByDefault
|
@NotNullByDefault
|
||||||
@ParametersNotNullByDefault
|
|
||||||
public class LockManagerImpl implements LockManager, Service, EventListener {
|
public class LockManagerImpl implements LockManager, Service, EventListener {
|
||||||
|
|
||||||
private static final Logger LOG =
|
private static final Logger LOG =
|
||||||
@@ -79,19 +78,19 @@ public class LockManagerImpl implements LockManager, Service, EventListener {
|
|||||||
this.settingsManager = settingsManager;
|
this.settingsManager = settingsManager;
|
||||||
this.notificationManager = notificationManager;
|
this.notificationManager = notificationManager;
|
||||||
this.dbExecutor = dbExecutor;
|
this.dbExecutor = dbExecutor;
|
||||||
this.alarmManager =
|
alarmManager = (AlarmManager)
|
||||||
(AlarmManager) appContext.getSystemService(ALARM_SERVICE);
|
requireNonNull(appContext.getSystemService(ALARM_SERVICE));
|
||||||
Intent i =
|
Intent i =
|
||||||
new Intent(ACTION_LOCK, null, appContext, BriarService.class);
|
new Intent(ACTION_LOCK, null, appContext, BriarService.class);
|
||||||
this.lockIntent = getService(appContext, 0, i, 0);
|
lockIntent = getService(appContext, 0, i, 0);
|
||||||
this.timeoutNever = Integer.valueOf(
|
timeoutNever = Integer.valueOf(
|
||||||
appContext.getString(R.string.pref_lock_timeout_value_never));
|
appContext.getString(R.string.pref_lock_timeout_value_never));
|
||||||
this.timeoutDefault = Integer.valueOf(
|
timeoutDefault = Integer.valueOf(
|
||||||
appContext.getString(R.string.pref_lock_timeout_value_default));
|
appContext.getString(R.string.pref_lock_timeout_value_default));
|
||||||
this.timeoutMinutes = timeoutNever;
|
timeoutMinutes = timeoutNever;
|
||||||
|
|
||||||
// setting this in the constructor makes #getValue() @NonNull
|
// setting this in the constructor makes #getValue() @NonNull
|
||||||
this.lockable.setValue(false);
|
lockable.setValue(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -145,7 +144,7 @@ public class LockManagerImpl implements LockManager, Service, EventListener {
|
|||||||
@UiThread
|
@UiThread
|
||||||
@Override
|
@Override
|
||||||
public void checkIfLockable() {
|
public void checkIfLockable() {
|
||||||
boolean oldValue = lockable.getValue();
|
boolean oldValue = requireNonNull(lockable.getValue());
|
||||||
boolean newValue = hasScreenLock(appContext) && lockableSetting;
|
boolean newValue = hasScreenLock(appContext) && lockableSetting;
|
||||||
if (oldValue != newValue) {
|
if (oldValue != newValue) {
|
||||||
this.lockable.setValue(newValue);
|
this.lockable.setValue(newValue);
|
||||||
@@ -201,7 +200,8 @@ public class LockManagerImpl implements LockManager, Service, EventListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean timeoutEnabled() {
|
private boolean timeoutEnabled() {
|
||||||
return timeoutMinutes != timeoutNever && lockable.getValue();
|
return timeoutMinutes != timeoutNever
|
||||||
|
&& requireNonNull(lockable.getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean timedOut() {
|
private boolean timedOut() {
|
||||||
|
|||||||
@@ -212,14 +212,16 @@ public abstract class BaseActivity extends AppCompatActivity
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void showSoftKeyboard(View view) {
|
public void showSoftKeyboard(View view) {
|
||||||
Object o = getSystemService(INPUT_METHOD_SERVICE);
|
InputMethodManager im = (InputMethodManager)
|
||||||
((InputMethodManager) o).showSoftInput(view, SHOW_IMPLICIT);
|
getSystemService(INPUT_METHOD_SERVICE);
|
||||||
|
if (im != null) im.showSoftInput(view, SHOW_IMPLICIT);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void hideSoftKeyboard(View view) {
|
public void hideSoftKeyboard(View view) {
|
||||||
IBinder token = view.getWindowToken();
|
IBinder token = view.getWindowToken();
|
||||||
Object o = getSystemService(INPUT_METHOD_SERVICE);
|
InputMethodManager im = (InputMethodManager)
|
||||||
((InputMethodManager) o).hideSoftInputFromWindow(token, 0);
|
getSystemService(INPUT_METHOD_SERVICE);
|
||||||
|
if (im != null) im.hideSoftInputFromWindow(token, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@UiThread
|
@UiThread
|
||||||
|
|||||||
@@ -54,9 +54,8 @@ abstract class BasePostFragment extends BaseFragment {
|
|||||||
@Nullable ViewGroup container,
|
@Nullable ViewGroup container,
|
||||||
@Nullable Bundle savedInstanceState) {
|
@Nullable Bundle savedInstanceState) {
|
||||||
// retrieve MessageId of blog post from arguments
|
// retrieve MessageId of blog post from arguments
|
||||||
byte[] p = requireNonNull(getArguments()).getByteArray(POST_ID);
|
Bundle args = requireNonNull(getArguments());
|
||||||
if (p == null) throw new IllegalStateException("No post ID in args");
|
postId = new MessageId(requireNonNull(args.getByteArray(POST_ID)));
|
||||||
postId = new MessageId(p);
|
|
||||||
|
|
||||||
View view = inflater.inflate(R.layout.fragment_blog_post, container,
|
View view = inflater.inflate(R.layout.fragment_blog_post, container,
|
||||||
false);
|
false);
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package org.briarproject.briar.android.blog;
|
package org.briarproject.briar.android.blog;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
import org.briarproject.briar.api.blog.BlogCommentHeader;
|
import org.briarproject.briar.api.blog.BlogCommentHeader;
|
||||||
import org.briarproject.briar.api.blog.BlogPostHeader;
|
import org.briarproject.briar.api.blog.BlogPostHeader;
|
||||||
|
|
||||||
@@ -7,9 +8,12 @@ import java.util.ArrayList;
|
|||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import javax.annotation.concurrent.NotThreadSafe;
|
||||||
|
|
||||||
import static java.util.Collections.sort;
|
import static java.util.Collections.sort;
|
||||||
|
|
||||||
// This class is not thread-safe
|
@NotThreadSafe
|
||||||
|
@NotNullByDefault
|
||||||
class BlogCommentItem extends BlogPostItem {
|
class BlogCommentItem extends BlogPostItem {
|
||||||
|
|
||||||
private static final BlogCommentComparator COMPARATOR =
|
private static final BlogCommentComparator COMPARATOR =
|
||||||
|
|||||||
@@ -167,7 +167,8 @@ public class BlogFragment extends BaseFragment
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onActivityResult(int request, int result, Intent data) {
|
public void onActivityResult(int request, int result,
|
||||||
|
@Nullable Intent data) {
|
||||||
super.onActivityResult(request, result, data);
|
super.onActivityResult(request, result, data);
|
||||||
|
|
||||||
if (request == REQUEST_WRITE_BLOG_POST && result == RESULT_OK) {
|
if (request == REQUEST_WRITE_BLOG_POST && result == RESULT_OK) {
|
||||||
|
|||||||
@@ -7,13 +7,11 @@ import android.view.LayoutInflater;
|
|||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
|
||||||
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
|
||||||
import org.briarproject.briar.R;
|
import org.briarproject.briar.R;
|
||||||
import org.briarproject.briar.android.util.BriarAdapter;
|
import org.briarproject.briar.android.util.BriarAdapter;
|
||||||
|
|
||||||
@MethodsNotNullByDefault
|
@NotNullByDefault
|
||||||
@ParametersNotNullByDefault
|
|
||||||
class BlogPostAdapter extends BriarAdapter<BlogPostItem, BlogPostViewHolder> {
|
class BlogPostAdapter extends BriarAdapter<BlogPostItem, BlogPostViewHolder> {
|
||||||
|
|
||||||
private final OnBlogPostClickListener listener;
|
private final OnBlogPostClickListener listener;
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
package org.briarproject.briar.android.blog;
|
package org.briarproject.briar.android.blog;
|
||||||
|
|
||||||
import android.support.annotation.NonNull;
|
|
||||||
|
|
||||||
import org.briarproject.bramble.api.identity.Author;
|
import org.briarproject.bramble.api.identity.Author;
|
||||||
import org.briarproject.bramble.api.identity.AuthorInfo;
|
import org.briarproject.bramble.api.identity.AuthorInfo;
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
import org.briarproject.bramble.api.sync.GroupId;
|
import org.briarproject.bramble.api.sync.GroupId;
|
||||||
import org.briarproject.bramble.api.sync.MessageId;
|
import org.briarproject.bramble.api.sync.MessageId;
|
||||||
import org.briarproject.briar.api.blog.BlogPostHeader;
|
import org.briarproject.briar.api.blog.BlogPostHeader;
|
||||||
@@ -12,6 +11,7 @@ import javax.annotation.Nullable;
|
|||||||
import javax.annotation.concurrent.NotThreadSafe;
|
import javax.annotation.concurrent.NotThreadSafe;
|
||||||
|
|
||||||
@NotThreadSafe
|
@NotThreadSafe
|
||||||
|
@NotNullByDefault
|
||||||
public class BlogPostItem implements Comparable<BlogPostItem> {
|
public class BlogPostItem implements Comparable<BlogPostItem> {
|
||||||
|
|
||||||
private final BlogPostHeader header;
|
private final BlogPostHeader header;
|
||||||
@@ -67,16 +67,13 @@ public class BlogPostItem implements Comparable<BlogPostItem> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int compareTo(@NonNull BlogPostItem other) {
|
public int compareTo(BlogPostItem other) {
|
||||||
if (this == other) return 0;
|
if (this == other) return 0;
|
||||||
return compare(getHeader(), other.getHeader());
|
return compare(getHeader(), other.getHeader());
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static int compare(BlogPostHeader h1, BlogPostHeader h2) {
|
protected static int compare(BlogPostHeader h1, BlogPostHeader h2) {
|
||||||
// The newest post comes first
|
// The newest post comes first
|
||||||
long aTime = h1.getTimeReceived(), bTime = h2.getTimeReceived();
|
return Long.compare(h2.getTimeReceived(), h1.getTimeReceived());
|
||||||
if (aTime > bTime) return -1;
|
|
||||||
if (aTime < bTime) return 1;
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package org.briarproject.briar.android.blog;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.support.annotation.NonNull;
|
|
||||||
import android.support.annotation.UiThread;
|
import android.support.annotation.UiThread;
|
||||||
import android.support.v4.app.FragmentManager;
|
import android.support.v4.app.FragmentManager;
|
||||||
import android.support.v4.view.ViewCompat;
|
import android.support.v4.view.ViewCompat;
|
||||||
@@ -14,6 +13,7 @@ import android.view.ViewGroup;
|
|||||||
import android.widget.ImageButton;
|
import android.widget.ImageButton;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
import org.briarproject.bramble.api.sync.MessageId;
|
import org.briarproject.bramble.api.sync.MessageId;
|
||||||
import org.briarproject.briar.R;
|
import org.briarproject.briar.R;
|
||||||
import org.briarproject.briar.android.view.AuthorView;
|
import org.briarproject.briar.android.view.AuthorView;
|
||||||
@@ -33,6 +33,7 @@ import static org.briarproject.briar.android.util.UiUtils.makeLinksClickable;
|
|||||||
import static org.briarproject.briar.api.blog.MessageType.POST;
|
import static org.briarproject.briar.api.blog.MessageType.POST;
|
||||||
|
|
||||||
@UiThread
|
@UiThread
|
||||||
|
@NotNullByDefault
|
||||||
class BlogPostViewHolder extends RecyclerView.ViewHolder {
|
class BlogPostViewHolder extends RecyclerView.ViewHolder {
|
||||||
|
|
||||||
private final Context ctx;
|
private final Context ctx;
|
||||||
@@ -44,13 +45,12 @@ class BlogPostViewHolder extends RecyclerView.ViewHolder {
|
|||||||
private final ViewGroup commentContainer;
|
private final ViewGroup commentContainer;
|
||||||
private final boolean fullText;
|
private final boolean fullText;
|
||||||
|
|
||||||
@NonNull
|
|
||||||
private final OnBlogPostClickListener listener;
|
private final OnBlogPostClickListener listener;
|
||||||
@Nullable
|
@Nullable
|
||||||
private final FragmentManager fragmentManager;
|
private final FragmentManager fragmentManager;
|
||||||
|
|
||||||
BlogPostViewHolder(View v, boolean fullText,
|
BlogPostViewHolder(View v, boolean fullText,
|
||||||
@NonNull OnBlogPostClickListener listener,
|
OnBlogPostClickListener listener,
|
||||||
@Nullable FragmentManager fragmentManager) {
|
@Nullable FragmentManager fragmentManager) {
|
||||||
super(v);
|
super(v);
|
||||||
this.fullText = fullText;
|
this.fullText = fullText;
|
||||||
|
|||||||
@@ -96,7 +96,8 @@ public class FeedFragment extends BaseFragment implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
public void onActivityResult(int requestCode, int resultCode,
|
||||||
|
@Nullable Intent data) {
|
||||||
super.onActivityResult(requestCode, resultCode, data);
|
super.onActivityResult(requestCode, resultCode, data);
|
||||||
|
|
||||||
// The BlogPostAddedEvent arrives when the controller is not listening
|
// The BlogPostAddedEvent arrives when the controller is not listening
|
||||||
|
|||||||
@@ -54,9 +54,7 @@ public class FeedPostFragment extends BasePostFragment {
|
|||||||
@Nullable ViewGroup container,
|
@Nullable ViewGroup container,
|
||||||
@Nullable Bundle savedInstanceState) {
|
@Nullable Bundle savedInstanceState) {
|
||||||
Bundle args = requireNonNull(getArguments());
|
Bundle args = requireNonNull(getArguments());
|
||||||
byte[] b = args.getByteArray(GROUP_ID);
|
blogId = new GroupId(requireNonNull(args.getByteArray(GROUP_ID)));
|
||||||
if (b == null) throw new IllegalStateException("No group ID in args");
|
|
||||||
blogId = new GroupId(b);
|
|
||||||
|
|
||||||
return super.onCreateView(inflater, container, savedInstanceState);
|
return super.onCreateView(inflater, container, savedInstanceState);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -73,7 +73,6 @@ public class ReblogFragment extends BaseFragment implements SendListener {
|
|||||||
public View onCreateView(LayoutInflater inflater,
|
public View onCreateView(LayoutInflater inflater,
|
||||||
@Nullable ViewGroup container,
|
@Nullable ViewGroup container,
|
||||||
@Nullable Bundle savedInstanceState) {
|
@Nullable Bundle savedInstanceState) {
|
||||||
|
|
||||||
Bundle args = requireNonNull(getArguments());
|
Bundle args = requireNonNull(getArguments());
|
||||||
GroupId blogId =
|
GroupId blogId =
|
||||||
new GroupId(requireNonNull(args.getByteArray(GROUP_ID)));
|
new GroupId(requireNonNull(args.getByteArray(GROUP_ID)));
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import android.view.ViewGroup;
|
|||||||
import android.widget.ImageButton;
|
import android.widget.ImageButton;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
import org.briarproject.briar.R;
|
import org.briarproject.briar.R;
|
||||||
import org.briarproject.briar.android.util.BriarAdapter;
|
import org.briarproject.briar.android.util.BriarAdapter;
|
||||||
import org.briarproject.briar.api.feed.Feed;
|
import org.briarproject.briar.api.feed.Feed;
|
||||||
@@ -16,6 +17,7 @@ import static android.view.View.GONE;
|
|||||||
import static android.view.View.VISIBLE;
|
import static android.view.View.VISIBLE;
|
||||||
import static org.briarproject.briar.android.util.UiUtils.formatDate;
|
import static org.briarproject.briar.android.util.UiUtils.formatDate;
|
||||||
|
|
||||||
|
@NotNullByDefault
|
||||||
class RssFeedAdapter extends BriarAdapter<Feed, RssFeedAdapter.FeedViewHolder> {
|
class RssFeedAdapter extends BriarAdapter<Feed, RssFeedAdapter.FeedViewHolder> {
|
||||||
|
|
||||||
private final RssFeedListener listener;
|
private final RssFeedListener listener;
|
||||||
@@ -72,10 +74,7 @@ class RssFeedAdapter extends BriarAdapter<Feed, RssFeedAdapter.FeedViewHolder> {
|
|||||||
@Override
|
@Override
|
||||||
public int compare(Feed a, Feed b) {
|
public int compare(Feed a, Feed b) {
|
||||||
if (a == b) return 0;
|
if (a == b) return 0;
|
||||||
long aTime = a.getAdded(), bTime = b.getAdded();
|
return Long.compare(b.getAdded(), a.getAdded());
|
||||||
if (aTime > bTime) return -1;
|
|
||||||
if (aTime < bTime) return 1;
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -5,14 +5,14 @@ import android.support.v7.app.AlertDialog;
|
|||||||
import android.text.Editable;
|
import android.text.Editable;
|
||||||
import android.text.TextWatcher;
|
import android.text.TextWatcher;
|
||||||
import android.util.Patterns;
|
import android.util.Patterns;
|
||||||
import android.view.Menu;
|
|
||||||
import android.view.MenuItem;
|
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
import android.widget.ProgressBar;
|
import android.widget.ProgressBar;
|
||||||
|
|
||||||
import org.briarproject.bramble.api.db.DbException;
|
import org.briarproject.bramble.api.db.DbException;
|
||||||
import org.briarproject.bramble.api.lifecycle.IoExecutor;
|
import org.briarproject.bramble.api.lifecycle.IoExecutor;
|
||||||
|
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
|
||||||
|
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
||||||
import org.briarproject.briar.R;
|
import org.briarproject.briar.R;
|
||||||
import org.briarproject.briar.android.activity.ActivityComponent;
|
import org.briarproject.briar.android.activity.ActivityComponent;
|
||||||
import org.briarproject.briar.android.activity.BriarActivity;
|
import org.briarproject.briar.android.activity.BriarActivity;
|
||||||
@@ -33,6 +33,8 @@ import static java.util.logging.Level.WARNING;
|
|||||||
import static java.util.logging.Logger.getLogger;
|
import static java.util.logging.Logger.getLogger;
|
||||||
import static org.briarproject.bramble.util.LogUtils.logException;
|
import static org.briarproject.bramble.util.LogUtils.logException;
|
||||||
|
|
||||||
|
@MethodsNotNullByDefault
|
||||||
|
@ParametersNotNullByDefault
|
||||||
public class RssFeedImportActivity extends BriarActivity {
|
public class RssFeedImportActivity extends BriarActivity {
|
||||||
|
|
||||||
private static final Logger LOG =
|
private static final Logger LOG =
|
||||||
@@ -47,11 +49,10 @@ public class RssFeedImportActivity extends BriarActivity {
|
|||||||
Executor ioExecutor;
|
Executor ioExecutor;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
@SuppressWarnings("WeakerAccess")
|
|
||||||
volatile FeedManager feedManager;
|
volatile FeedManager feedManager;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
setContentView(R.layout.activity_rss_feed_import);
|
setContentView(R.layout.activity_rss_feed_import);
|
||||||
@@ -80,16 +81,6 @@ public class RssFeedImportActivity extends BriarActivity {
|
|||||||
progressBar = findViewById(R.id.progressBar);
|
progressBar = findViewById(R.id.progressBar);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onCreateOptionsMenu(Menu menu) {
|
|
||||||
return super.onCreateOptionsMenu(menu);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
|
||||||
return super.onOptionsItemSelected(item);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void injectActivity(ActivityComponent component) {
|
public void injectActivity(ActivityComponent component) {
|
||||||
component.inject(this);
|
component.inject(this);
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package org.briarproject.briar.android.blog;
|
|||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
import android.support.design.widget.Snackbar;
|
import android.support.design.widget.Snackbar;
|
||||||
import android.support.v7.app.AlertDialog;
|
import android.support.v7.app.AlertDialog;
|
||||||
import android.support.v7.widget.LinearLayoutManager;
|
import android.support.v7.widget.LinearLayoutManager;
|
||||||
@@ -11,6 +12,8 @@ import android.view.MenuInflater;
|
|||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
|
|
||||||
import org.briarproject.bramble.api.db.DbException;
|
import org.briarproject.bramble.api.db.DbException;
|
||||||
|
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
|
||||||
|
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
||||||
import org.briarproject.briar.R;
|
import org.briarproject.briar.R;
|
||||||
import org.briarproject.briar.android.activity.ActivityComponent;
|
import org.briarproject.briar.android.activity.ActivityComponent;
|
||||||
import org.briarproject.briar.android.activity.BriarActivity;
|
import org.briarproject.briar.android.activity.BriarActivity;
|
||||||
@@ -30,6 +33,8 @@ import static java.util.logging.Level.WARNING;
|
|||||||
import static java.util.logging.Logger.getLogger;
|
import static java.util.logging.Logger.getLogger;
|
||||||
import static org.briarproject.bramble.util.LogUtils.logException;
|
import static org.briarproject.bramble.util.LogUtils.logException;
|
||||||
|
|
||||||
|
@MethodsNotNullByDefault
|
||||||
|
@ParametersNotNullByDefault
|
||||||
public class RssFeedManageActivity extends BriarActivity
|
public class RssFeedManageActivity extends BriarActivity
|
||||||
implements RssFeedListener {
|
implements RssFeedListener {
|
||||||
|
|
||||||
@@ -40,11 +45,10 @@ public class RssFeedManageActivity extends BriarActivity
|
|||||||
private RssFeedAdapter adapter;
|
private RssFeedAdapter adapter;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
@SuppressWarnings("WeakerAccess")
|
|
||||||
volatile FeedManager feedManager;
|
volatile FeedManager feedManager;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
setContentView(R.layout.activity_rss_feed_manage);
|
setContentView(R.layout.activity_rss_feed_manage);
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ import javax.inject.Inject;
|
|||||||
|
|
||||||
import static android.view.View.GONE;
|
import static android.view.View.GONE;
|
||||||
import static android.view.View.VISIBLE;
|
import static android.view.View.VISIBLE;
|
||||||
|
import static java.util.Objects.requireNonNull;
|
||||||
import static java.util.logging.Level.WARNING;
|
import static java.util.logging.Level.WARNING;
|
||||||
import static java.util.logging.Logger.getLogger;
|
import static java.util.logging.Logger.getLogger;
|
||||||
import static org.briarproject.bramble.util.LogUtils.logException;
|
import static org.briarproject.bramble.util.LogUtils.logException;
|
||||||
@@ -70,9 +71,7 @@ public class WriteBlogPostActivity extends BriarActivity
|
|||||||
super.onCreate(state);
|
super.onCreate(state);
|
||||||
|
|
||||||
Intent i = getIntent();
|
Intent i = getIntent();
|
||||||
byte[] b = i.getByteArrayExtra(GROUP_ID);
|
groupId = new GroupId(requireNonNull(i.getByteArrayExtra(GROUP_ID)));
|
||||||
if (b == null) throw new IllegalStateException("No Group in intent.");
|
|
||||||
groupId = new GroupId(b);
|
|
||||||
|
|
||||||
setContentView(R.layout.activity_write_blog_post);
|
setContentView(R.layout.activity_write_blog_post);
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
package org.briarproject.briar.android.contact;
|
package org.briarproject.briar.android.contact;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.support.annotation.NonNull;
|
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
|
||||||
import org.briarproject.bramble.api.contact.ContactId;
|
import org.briarproject.bramble.api.contact.ContactId;
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
import org.briarproject.briar.android.util.BriarAdapter;
|
import org.briarproject.briar.android.util.BriarAdapter;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
@@ -12,6 +12,7 @@ import javax.annotation.Nullable;
|
|||||||
import static android.support.v7.util.SortedList.INVALID_POSITION;
|
import static android.support.v7.util.SortedList.INVALID_POSITION;
|
||||||
import static org.briarproject.briar.android.util.UiUtils.getContactDisplayName;
|
import static org.briarproject.briar.android.util.UiUtils.getContactDisplayName;
|
||||||
|
|
||||||
|
@NotNullByDefault
|
||||||
public abstract class BaseContactListAdapter<I extends ContactItem, VH extends ContactItemViewHolder<I>>
|
public abstract class BaseContactListAdapter<I extends ContactItem, VH extends ContactItemViewHolder<I>>
|
||||||
extends BriarAdapter<I, VH> {
|
extends BriarAdapter<I, VH> {
|
||||||
|
|
||||||
@@ -25,7 +26,7 @@ public abstract class BaseContactListAdapter<I extends ContactItem, VH extends C
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBindViewHolder(@NonNull VH ui, int position) {
|
public void onBindViewHolder(VH ui, int position) {
|
||||||
I item = items.get(position);
|
I item = items.get(position);
|
||||||
ui.bind(item, listener);
|
ui.bind(item, listener);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,8 +5,10 @@ import android.view.LayoutInflater;
|
|||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
import org.briarproject.briar.R;
|
import org.briarproject.briar.R;
|
||||||
|
|
||||||
|
@NotNullByDefault
|
||||||
public class ContactListAdapter extends
|
public class ContactListAdapter extends
|
||||||
BaseContactListAdapter<ContactListItem, ContactListItemViewHolder> {
|
BaseContactListAdapter<ContactListItem, ContactListItemViewHolder> {
|
||||||
|
|
||||||
@@ -28,22 +30,14 @@ public class ContactListAdapter extends
|
|||||||
public boolean areContentsTheSame(ContactListItem c1, ContactListItem c2) {
|
public boolean areContentsTheSame(ContactListItem c1, ContactListItem c2) {
|
||||||
// check for all properties that influence visual
|
// check for all properties that influence visual
|
||||||
// representation of contact
|
// representation of contact
|
||||||
if (c1.getUnreadCount() != c2.getUnreadCount()) {
|
return c1.getUnreadCount() == c2.getUnreadCount() &&
|
||||||
return false;
|
c1.getTimestamp() == c2.getTimestamp() &&
|
||||||
}
|
c1.isConnected() == c2.isConnected();
|
||||||
if (c1.getTimestamp() != c2.getTimestamp()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return c1.isConnected() == c2.isConnected();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int compare(ContactListItem c1, ContactListItem c2) {
|
public int compare(ContactListItem c1, ContactListItem c2) {
|
||||||
long time1 = c1.getTimestamp();
|
return Long.compare(c2.getTimestamp(), c1.getTimestamp());
|
||||||
long time2 = c2.getTimestamp();
|
|
||||||
if (time1 < time2) return 1;
|
|
||||||
if (time1 > time2) return -1;
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,11 +53,8 @@ public abstract class BaseContactSelectorFragment<I extends SelectableContactIte
|
|||||||
@Override
|
@Override
|
||||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
Bundle args = requireNonNull(getArguments());
|
Bundle args = requireNonNull(getArguments());
|
||||||
byte[] b = args.getByteArray(GROUP_ID);
|
groupId = new GroupId(requireNonNull(args.getByteArray(GROUP_ID)));
|
||||||
if (b == null) throw new IllegalStateException("No GroupId");
|
|
||||||
groupId = new GroupId(b);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -65,7 +62,6 @@ public abstract class BaseContactSelectorFragment<I extends SelectableContactIte
|
|||||||
public View onCreateView(LayoutInflater inflater,
|
public View onCreateView(LayoutInflater inflater,
|
||||||
@Nullable ViewGroup container,
|
@Nullable ViewGroup container,
|
||||||
@Nullable Bundle savedInstanceState) {
|
@Nullable Bundle savedInstanceState) {
|
||||||
|
|
||||||
View contentView = inflater.inflate(R.layout.list, container, false);
|
View contentView = inflater.inflate(R.layout.list, container, false);
|
||||||
|
|
||||||
list = contentView.findViewById(R.id.list);
|
list = contentView.findViewById(R.id.list);
|
||||||
|
|||||||
@@ -59,6 +59,7 @@ public class SharingControllerImpl implements SharingController, EventListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void setConnected(ContactId c) {
|
private void setConnected(ContactId c) {
|
||||||
|
SharingListener listener = this.listener;
|
||||||
if (listener == null) return;
|
if (listener == null) return;
|
||||||
listener.runOnUiThreadUnlessDestroyed(() -> {
|
listener.runOnUiThreadUnlessDestroyed(() -> {
|
||||||
if (contacts.contains(c)) {
|
if (contacts.contains(c)) {
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ package org.briarproject.briar.android.conversation;
|
|||||||
import android.arch.lifecycle.ViewModelProvider;
|
import android.arch.lifecycle.ViewModelProvider;
|
||||||
import android.arch.lifecycle.ViewModelProviders;
|
import android.arch.lifecycle.ViewModelProviders;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.Nullable;
|
||||||
import android.support.v7.app.AppCompatDialogFragment;
|
import android.support.v7.app.AppCompatDialogFragment;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
@@ -12,6 +12,8 @@ import android.widget.Button;
|
|||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
|
|
||||||
import org.briarproject.bramble.api.contact.Contact;
|
import org.briarproject.bramble.api.contact.Contact;
|
||||||
|
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
|
||||||
|
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
||||||
import org.briarproject.briar.R;
|
import org.briarproject.briar.R;
|
||||||
import org.briarproject.briar.android.activity.BriarActivity;
|
import org.briarproject.briar.android.activity.BriarActivity;
|
||||||
|
|
||||||
@@ -19,6 +21,8 @@ import javax.inject.Inject;
|
|||||||
|
|
||||||
import static java.util.Objects.requireNonNull;
|
import static java.util.Objects.requireNonNull;
|
||||||
|
|
||||||
|
@MethodsNotNullByDefault
|
||||||
|
@ParametersNotNullByDefault
|
||||||
public class AliasDialogFragment extends AppCompatDialogFragment {
|
public class AliasDialogFragment extends AppCompatDialogFragment {
|
||||||
|
|
||||||
final static String TAG = AliasDialogFragment.class.getName();
|
final static String TAG = AliasDialogFragment.class.getName();
|
||||||
@@ -34,7 +38,7 @@ public class AliasDialogFragment extends AppCompatDialogFragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
setStyle(STYLE_NO_TITLE, R.style.BriarDialogTheme);
|
setStyle(STYLE_NO_TITLE, R.style.BriarDialogTheme);
|
||||||
@@ -45,8 +49,9 @@ public class AliasDialogFragment extends AppCompatDialogFragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(@NonNull LayoutInflater inflater,
|
public View onCreateView(LayoutInflater inflater,
|
||||||
ViewGroup container, Bundle savedInstanceState) {
|
@Nullable ViewGroup container,
|
||||||
|
@Nullable Bundle savedInstanceState) {
|
||||||
View v = inflater.inflate(R.layout.fragment_alias_dialog, container,
|
View v = inflater.inflate(R.layout.fragment_alias_dialog, container,
|
||||||
false);
|
false);
|
||||||
|
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ import static org.briarproject.briar.android.util.UiUtils.observeForeverOnce;
|
|||||||
@NotNullByDefault
|
@NotNullByDefault
|
||||||
public class ConversationViewModel extends AndroidViewModel {
|
public class ConversationViewModel extends AndroidViewModel {
|
||||||
|
|
||||||
private static Logger LOG =
|
private static final Logger LOG =
|
||||||
getLogger(ConversationViewModel.class.getName());
|
getLogger(ConversationViewModel.class.getName());
|
||||||
private static final String SHOW_ONBOARDING_IMAGE =
|
private static final String SHOW_ONBOARDING_IMAGE =
|
||||||
"showOnboardingImage";
|
"showOnboardingImage";
|
||||||
|
|||||||
@@ -88,7 +88,8 @@ public class ForumActivity extends
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onActivityResult(int request, int result, Intent data) {
|
protected void onActivityResult(int request, int result,
|
||||||
|
@Nullable Intent data) {
|
||||||
super.onActivityResult(request, result, data);
|
super.onActivityResult(request, result, data);
|
||||||
|
|
||||||
if (request == REQUEST_SHARE_FORUM && result == RESULT_OK) {
|
if (request == REQUEST_SHARE_FORUM && result == RESULT_OK) {
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import android.view.View;
|
|||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
import org.briarproject.bramble.api.sync.GroupId;
|
import org.briarproject.bramble.api.sync.GroupId;
|
||||||
import org.briarproject.briar.R;
|
import org.briarproject.briar.R;
|
||||||
import org.briarproject.briar.android.util.BriarAdapter;
|
import org.briarproject.briar.android.util.BriarAdapter;
|
||||||
@@ -21,6 +22,7 @@ import static org.briarproject.briar.android.activity.BriarActivity.GROUP_ID;
|
|||||||
import static org.briarproject.briar.android.activity.BriarActivity.GROUP_NAME;
|
import static org.briarproject.briar.android.activity.BriarActivity.GROUP_NAME;
|
||||||
import static org.briarproject.briar.android.util.UiUtils.formatDate;
|
import static org.briarproject.briar.android.util.UiUtils.formatDate;
|
||||||
|
|
||||||
|
@NotNullByDefault
|
||||||
class ForumListAdapter
|
class ForumListAdapter
|
||||||
extends BriarAdapter<ForumListItem, ForumListAdapter.ForumViewHolder> {
|
extends BriarAdapter<ForumListItem, ForumListAdapter.ForumViewHolder> {
|
||||||
|
|
||||||
|
|||||||
@@ -94,9 +94,8 @@ public class ForumListFragment extends BaseEventFragment implements
|
|||||||
@Nullable Bundle savedInstanceState) {
|
@Nullable Bundle savedInstanceState) {
|
||||||
requireActivity().setTitle(R.string.forums_button);
|
requireActivity().setTitle(R.string.forums_button);
|
||||||
|
|
||||||
View contentView =
|
View contentView = inflater.inflate(R.layout.fragment_forum_list,
|
||||||
inflater.inflate(R.layout.fragment_forum_list, container,
|
container, false);
|
||||||
false);
|
|
||||||
|
|
||||||
adapter = new ForumListAdapter(requireActivity());
|
adapter = new ForumListAdapter(requireActivity());
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,9 @@ import org.briarproject.briar.api.client.MessageTracker.GroupCount;
|
|||||||
import org.briarproject.briar.api.forum.Forum;
|
import org.briarproject.briar.api.forum.Forum;
|
||||||
import org.briarproject.briar.api.forum.ForumPostHeader;
|
import org.briarproject.briar.api.forum.ForumPostHeader;
|
||||||
|
|
||||||
// This class is NOT thread-safe
|
import javax.annotation.concurrent.NotThreadSafe;
|
||||||
|
|
||||||
|
@NotThreadSafe
|
||||||
class ForumListItem {
|
class ForumListItem {
|
||||||
|
|
||||||
private final Forum forum;
|
private final Forum forum;
|
||||||
|
|||||||
@@ -63,6 +63,7 @@ public abstract class BaseFragment extends Fragment
|
|||||||
}
|
}
|
||||||
|
|
||||||
public interface BaseFragmentListener {
|
public interface BaseFragmentListener {
|
||||||
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
void runOnDbThread(Runnable runnable);
|
void runOnDbThread(Runnable runnable);
|
||||||
|
|
||||||
|
|||||||
@@ -11,6 +11,8 @@ import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
|
|||||||
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
||||||
import org.briarproject.briar.R;
|
import org.briarproject.briar.R;
|
||||||
|
|
||||||
|
import static java.util.Objects.requireNonNull;
|
||||||
|
|
||||||
|
|
||||||
@MethodsNotNullByDefault
|
@MethodsNotNullByDefault
|
||||||
@ParametersNotNullByDefault
|
@ParametersNotNullByDefault
|
||||||
@@ -38,9 +40,7 @@ public class ErrorFragment extends BaseFragment {
|
|||||||
@Override
|
@Override
|
||||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
Bundle args = requireNonNull(getArguments());
|
||||||
Bundle args = getArguments();
|
|
||||||
if (args == null) throw new AssertionError();
|
|
||||||
errorMessage = args.getString(ERROR_MSG);
|
errorMessage = args.getString(ERROR_MSG);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -49,8 +49,7 @@ public class ErrorFragment extends BaseFragment {
|
|||||||
public View onCreateView(LayoutInflater inflater,
|
public View onCreateView(LayoutInflater inflater,
|
||||||
@Nullable ViewGroup container,
|
@Nullable ViewGroup container,
|
||||||
@Nullable Bundle savedInstanceState) {
|
@Nullable Bundle savedInstanceState) {
|
||||||
View v = inflater
|
View v = inflater.inflate(R.layout.fragment_error, container, false);
|
||||||
.inflate(R.layout.fragment_error, container, false);
|
|
||||||
TextView msg = v.findViewById(R.id.errorMessage);
|
TextView msg = v.findViewById(R.id.errorMessage);
|
||||||
msg.setText(errorMessage);
|
msg.setText(errorMessage);
|
||||||
return v;
|
return v;
|
||||||
|
|||||||
@@ -2,8 +2,11 @@ package org.briarproject.briar.android.introduction;
|
|||||||
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
|
|
||||||
import org.briarproject.bramble.api.contact.ContactId;
|
import org.briarproject.bramble.api.contact.ContactId;
|
||||||
|
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
|
||||||
|
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
||||||
import org.briarproject.briar.R;
|
import org.briarproject.briar.R;
|
||||||
import org.briarproject.briar.android.activity.ActivityComponent;
|
import org.briarproject.briar.android.activity.ActivityComponent;
|
||||||
import org.briarproject.briar.android.activity.BriarActivity;
|
import org.briarproject.briar.android.activity.BriarActivity;
|
||||||
@@ -11,11 +14,13 @@ import org.briarproject.briar.android.fragment.BaseFragment.BaseFragmentListener
|
|||||||
|
|
||||||
import static org.briarproject.briar.android.conversation.ConversationActivity.CONTACT_ID;
|
import static org.briarproject.briar.android.conversation.ConversationActivity.CONTACT_ID;
|
||||||
|
|
||||||
|
@MethodsNotNullByDefault
|
||||||
|
@ParametersNotNullByDefault
|
||||||
public class IntroductionActivity extends BriarActivity
|
public class IntroductionActivity extends BriarActivity
|
||||||
implements BaseFragmentListener {
|
implements BaseFragmentListener {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
Intent intent = getIntent();
|
Intent intent = getIntent();
|
||||||
|
|||||||
@@ -95,7 +95,6 @@ public class IntroductionMessageFragment extends BaseFragment
|
|||||||
public View onCreateView(LayoutInflater inflater,
|
public View onCreateView(LayoutInflater inflater,
|
||||||
@Nullable ViewGroup container,
|
@Nullable ViewGroup container,
|
||||||
@Nullable Bundle savedInstanceState) {
|
@Nullable Bundle savedInstanceState) {
|
||||||
|
|
||||||
// change toolbar text
|
// change toolbar text
|
||||||
ActionBar actionBar = introductionActivity.getSupportActionBar();
|
ActionBar actionBar = introductionActivity.getSupportActionBar();
|
||||||
if (actionBar != null) {
|
if (actionBar != null) {
|
||||||
@@ -126,11 +125,6 @@ public class IntroductionMessageFragment extends BaseFragment
|
|||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onStart() {
|
|
||||||
super.onStart();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getUniqueTag() {
|
public String getUniqueTag() {
|
||||||
return TAG;
|
return TAG;
|
||||||
|
|||||||
@@ -16,8 +16,7 @@ import android.view.SurfaceView;
|
|||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.WindowManager;
|
import android.view.WindowManager;
|
||||||
|
|
||||||
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -43,8 +42,7 @@ import static java.util.logging.Logger.getLogger;
|
|||||||
import static org.briarproject.bramble.util.LogUtils.logException;
|
import static org.briarproject.bramble.util.LogUtils.logException;
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
@MethodsNotNullByDefault
|
@NotNullByDefault
|
||||||
@ParametersNotNullByDefault
|
|
||||||
public class CameraView extends SurfaceView implements SurfaceHolder.Callback,
|
public class CameraView extends SurfaceView implements SurfaceHolder.Callback,
|
||||||
AutoFocusCallback, View.OnClickListener {
|
AutoFocusCallback, View.OnClickListener {
|
||||||
|
|
||||||
@@ -61,7 +59,9 @@ public class CameraView extends SurfaceView implements SurfaceHolder.Callback,
|
|||||||
@Nullable
|
@Nullable
|
||||||
private Camera camera = null;
|
private Camera camera = null;
|
||||||
private int cameraIndex = 0;
|
private int cameraIndex = 0;
|
||||||
|
@Nullable
|
||||||
private PreviewConsumer previewConsumer = null;
|
private PreviewConsumer previewConsumer = null;
|
||||||
|
@Nullable
|
||||||
private Surface surface = null;
|
private Surface surface = null;
|
||||||
private int displayOrientation = 0, surfaceWidth = 0, surfaceHeight = 0;
|
private int displayOrientation = 0, surfaceWidth = 0, surfaceHeight = 0;
|
||||||
private boolean previewStarted = false;
|
private boolean previewStarted = false;
|
||||||
@@ -126,6 +126,7 @@ public class CameraView extends SurfaceView implements SurfaceHolder.Callback,
|
|||||||
} catch (RuntimeException e) {
|
} catch (RuntimeException e) {
|
||||||
throw new CameraException(e);
|
throw new CameraException(e);
|
||||||
}
|
}
|
||||||
|
requireNonNull(camera);
|
||||||
setDisplayOrientation(getScreenRotationDegrees());
|
setDisplayOrientation(getScreenRotationDegrees());
|
||||||
// Use barcode scene mode if it's available
|
// Use barcode scene mode if it's available
|
||||||
Parameters params = requireNonNull(camera).getParameters();
|
Parameters params = requireNonNull(camera).getParameters();
|
||||||
@@ -214,7 +215,7 @@ public class CameraView extends SurfaceView implements SurfaceHolder.Callback,
|
|||||||
private void startConsumer() throws CameraException {
|
private void startConsumer() throws CameraException {
|
||||||
if (camera == null) throw new CameraException("Camera is null");
|
if (camera == null) throw new CameraException("Camera is null");
|
||||||
startAutoFocus();
|
startAutoFocus();
|
||||||
previewConsumer.start(camera, cameraIndex);
|
requireNonNull(previewConsumer).start(camera, cameraIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
@UiThread
|
@UiThread
|
||||||
@@ -234,7 +235,7 @@ public class CameraView extends SurfaceView implements SurfaceHolder.Callback,
|
|||||||
private void stopConsumer() throws CameraException {
|
private void stopConsumer() throws CameraException {
|
||||||
if (camera == null) throw new CameraException("Camera is null");
|
if (camera == null) throw new CameraException("Camera is null");
|
||||||
cancelAutoFocus();
|
cancelAutoFocus();
|
||||||
previewConsumer.stop();
|
requireNonNull(previewConsumer).stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
@UiThread
|
@UiThread
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ import javax.annotation.Nullable;
|
|||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
import static android.widget.Toast.LENGTH_LONG;
|
import static android.widget.Toast.LENGTH_LONG;
|
||||||
|
import static java.util.Objects.requireNonNull;
|
||||||
import static java.util.logging.Level.WARNING;
|
import static java.util.logging.Level.WARNING;
|
||||||
import static java.util.logging.Logger.getLogger;
|
import static java.util.logging.Logger.getLogger;
|
||||||
import static org.briarproject.bramble.util.LogUtils.logException;
|
import static org.briarproject.bramble.util.LogUtils.logException;
|
||||||
@@ -48,7 +49,8 @@ public class ContactExchangeActivity extends KeyAgreementActivity implements
|
|||||||
@Override
|
@Override
|
||||||
public void onCreate(@Nullable Bundle state) {
|
public void onCreate(@Nullable Bundle state) {
|
||||||
super.onCreate(state);
|
super.onCreate(state);
|
||||||
getSupportActionBar().setTitle(R.string.add_contact_title);
|
requireNonNull(getSupportActionBar())
|
||||||
|
.setTitle(R.string.add_contact_title);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void startContactExchange(KeyAgreementResult result) {
|
private void startContactExchange(KeyAgreementResult result) {
|
||||||
@@ -97,9 +99,8 @@ public class ContactExchangeActivity extends KeyAgreementActivity implements
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void contactExchangeFailed() {
|
public void contactExchangeFailed() {
|
||||||
runOnUiThreadUnlessDestroyed(() -> {
|
runOnUiThreadUnlessDestroyed(() ->
|
||||||
showErrorFragment(R.string.connection_error_explanation);
|
showErrorFragment(R.string.connection_error_explanation));
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@UiThread
|
@UiThread
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ import org.briarproject.briar.android.util.UiUtils;
|
|||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
import static java.util.Objects.requireNonNull;
|
||||||
import static org.briarproject.briar.android.util.UiUtils.onSingleLinkClick;
|
import static org.briarproject.briar.android.util.UiUtils.onSingleLinkClick;
|
||||||
|
|
||||||
@MethodsNotNullByDefault
|
@MethodsNotNullByDefault
|
||||||
@@ -59,10 +60,7 @@ public class ContactExchangeErrorFragment extends BaseFragment {
|
|||||||
|
|
||||||
// set humanized error message
|
// set humanized error message
|
||||||
TextView explanation = v.findViewById(R.id.errorMessage);
|
TextView explanation = v.findViewById(R.id.errorMessage);
|
||||||
Bundle args = getArguments();
|
Bundle args = requireNonNull(getArguments());
|
||||||
if (args == null) {
|
|
||||||
throw new IllegalArgumentException("Use newInstance()");
|
|
||||||
}
|
|
||||||
explanation.setText(args.getString(ERROR_MSG));
|
explanation.setText(args.getString(ERROR_MSG));
|
||||||
|
|
||||||
// make feedback link clickable
|
// make feedback link clickable
|
||||||
|
|||||||
@@ -54,7 +54,6 @@ public class IntroFragment extends BaseFragment {
|
|||||||
public View onCreateView(LayoutInflater inflater,
|
public View onCreateView(LayoutInflater inflater,
|
||||||
@Nullable ViewGroup container,
|
@Nullable ViewGroup container,
|
||||||
@Nullable Bundle savedInstanceState) {
|
@Nullable Bundle savedInstanceState) {
|
||||||
|
|
||||||
View v = inflater.inflate(R.layout.fragment_keyagreement_id, container,
|
View v = inflater.inflate(R.layout.fragment_keyagreement_id, container,
|
||||||
false);
|
false);
|
||||||
scrollView = v.findViewById(R.id.scrollView);
|
scrollView = v.findViewById(R.id.scrollView);
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import android.hardware.Camera.CameraInfo;
|
|||||||
import android.hardware.Camera.PreviewCallback;
|
import android.hardware.Camera.PreviewCallback;
|
||||||
import android.hardware.Camera.Size;
|
import android.hardware.Camera.Size;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
import android.support.annotation.UiThread;
|
import android.support.annotation.UiThread;
|
||||||
|
|
||||||
import com.google.zxing.BinaryBitmap;
|
import com.google.zxing.BinaryBitmap;
|
||||||
@@ -16,9 +17,7 @@ import com.google.zxing.Result;
|
|||||||
import com.google.zxing.common.HybridBinarizer;
|
import com.google.zxing.common.HybridBinarizer;
|
||||||
import com.google.zxing.qrcode.QRCodeReader;
|
import com.google.zxing.qrcode.QRCodeReader;
|
||||||
|
|
||||||
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
|
|
||||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
|
||||||
|
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
@@ -28,8 +27,7 @@ import static java.util.logging.Level.WARNING;
|
|||||||
import static java.util.logging.Logger.getLogger;
|
import static java.util.logging.Logger.getLogger;
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
@MethodsNotNullByDefault
|
@NotNullByDefault
|
||||||
@ParametersNotNullByDefault
|
|
||||||
class QrCodeDecoder implements PreviewConsumer, PreviewCallback {
|
class QrCodeDecoder implements PreviewConsumer, PreviewCallback {
|
||||||
|
|
||||||
private static final Logger LOG = getLogger(QrCodeDecoder.class.getName());
|
private static final Logger LOG = getLogger(QrCodeDecoder.class.getName());
|
||||||
@@ -37,6 +35,7 @@ class QrCodeDecoder implements PreviewConsumer, PreviewCallback {
|
|||||||
private final Reader reader = new QRCodeReader();
|
private final Reader reader = new QRCodeReader();
|
||||||
private final ResultCallback callback;
|
private final ResultCallback callback;
|
||||||
|
|
||||||
|
@Nullable
|
||||||
private Camera camera = null;
|
private Camera camera = null;
|
||||||
private int cameraIndex = 0;
|
private int cameraIndex = 0;
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package org.briarproject.briar.android.login;
|
package org.briarproject.briar.android.login;
|
||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.Nullable;
|
||||||
import android.support.design.widget.TextInputLayout;
|
import android.support.design.widget.TextInputLayout;
|
||||||
import android.text.Editable;
|
import android.text.Editable;
|
||||||
import android.text.TextWatcher;
|
import android.text.TextWatcher;
|
||||||
@@ -15,6 +15,8 @@ import android.widget.TextView;
|
|||||||
import android.widget.TextView.OnEditorActionListener;
|
import android.widget.TextView.OnEditorActionListener;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
|
||||||
|
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
||||||
import org.briarproject.briar.R;
|
import org.briarproject.briar.R;
|
||||||
import org.briarproject.briar.android.activity.ActivityComponent;
|
import org.briarproject.briar.android.activity.ActivityComponent;
|
||||||
import org.briarproject.briar.android.activity.BriarActivity;
|
import org.briarproject.briar.android.activity.BriarActivity;
|
||||||
@@ -27,6 +29,8 @@ import static android.view.View.VISIBLE;
|
|||||||
import static org.briarproject.bramble.api.crypto.PasswordStrengthEstimator.QUITE_WEAK;
|
import static org.briarproject.bramble.api.crypto.PasswordStrengthEstimator.QUITE_WEAK;
|
||||||
import static org.briarproject.briar.android.util.UiUtils.setError;
|
import static org.briarproject.briar.android.util.UiUtils.setError;
|
||||||
|
|
||||||
|
@MethodsNotNullByDefault
|
||||||
|
@ParametersNotNullByDefault
|
||||||
public class ChangePasswordActivity extends BriarActivity
|
public class ChangePasswordActivity extends BriarActivity
|
||||||
implements OnClickListener, OnEditorActionListener {
|
implements OnClickListener, OnEditorActionListener {
|
||||||
|
|
||||||
@@ -44,7 +48,7 @@ public class ChangePasswordActivity extends BriarActivity
|
|||||||
private ProgressBar progress;
|
private ProgressBar progress;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle state) {
|
public void onCreate(@Nullable Bundle state) {
|
||||||
super.onCreate(state);
|
super.onCreate(state);
|
||||||
setContentView(R.layout.activity_change_password);
|
setContentView(R.layout.activity_change_password);
|
||||||
|
|
||||||
@@ -127,7 +131,7 @@ public class ChangePasswordActivity extends BriarActivity
|
|||||||
newPassword.getText().toString(),
|
newPassword.getText().toString(),
|
||||||
new UiResultHandler<Boolean>(this) {
|
new UiResultHandler<Boolean>(this) {
|
||||||
@Override
|
@Override
|
||||||
public void onResultUi(@NonNull Boolean result) {
|
public void onResultUi(Boolean result) {
|
||||||
if (result) {
|
if (result) {
|
||||||
Toast.makeText(ChangePasswordActivity.this,
|
Toast.makeText(ChangePasswordActivity.this,
|
||||||
R.string.password_changed,
|
R.string.password_changed,
|
||||||
|
|||||||
@@ -76,7 +76,8 @@ public class DozeFragment extends SetupFragment
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onActivityResult(int request, int result, Intent data) {
|
public void onActivityResult(int request, int result,
|
||||||
|
@Nullable Intent data) {
|
||||||
super.onActivityResult(request, result, data);
|
super.onActivityResult(request, result, data);
|
||||||
if (request == REQUEST_DOZE_WHITELISTING) {
|
if (request == REQUEST_DOZE_WHITELISTING) {
|
||||||
if (!dozeView.needsToBeShown() || secondAttempt) {
|
if (!dozeView.needsToBeShown() || secondAttempt) {
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user