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