mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-13 11:19:04 +01:00
Compare commits
31 Commits
user-testi
...
detect-gli
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9d2cc4c3c1 | ||
|
|
8a534b4503 | ||
|
|
e5b2275c82 | ||
|
|
5159593825 | ||
|
|
6fbc82ee27 | ||
|
|
885b03cfd7 | ||
|
|
f81bfcafeb | ||
|
|
f36f1cf3d4 | ||
|
|
7d6a63d866 | ||
|
|
15ebdf8dd5 | ||
|
|
db2c235283 | ||
|
|
e5bd43469e | ||
|
|
9366c184d8 | ||
|
|
73d2c964d4 | ||
|
|
fb2b4209cf | ||
|
|
a04b512497 | ||
|
|
3d9515e308 | ||
|
|
1b19b331b1 | ||
|
|
d151a2d7f7 | ||
|
|
9712a4b849 | ||
|
|
cf1ac5e3e5 | ||
|
|
cb859e998d | ||
|
|
0b9345f867 | ||
|
|
12988120d1 | ||
|
|
8d6c866e62 | ||
|
|
8f82cf3c73 | ||
|
|
21112ce092 | ||
|
|
21ee3ea00d | ||
|
|
bb964101b3 | ||
|
|
d796eff0f6 | ||
|
|
700ea2b387 |
14
.idea/dictionaries/briar.xml
generated
Normal file
14
.idea/dictionaries/briar.xml
generated
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
<component name="ProjectDictionaryState">
|
||||||
|
<dictionary name="briar">
|
||||||
|
<words>
|
||||||
|
<w>briar</w>
|
||||||
|
<w>briarproject</w>
|
||||||
|
<w>emoji</w>
|
||||||
|
<w>encrypter</w>
|
||||||
|
<w>identicon</w>
|
||||||
|
<w>introducee</w>
|
||||||
|
<w>introducer</w>
|
||||||
|
<w>onboarding</w>
|
||||||
|
</words>
|
||||||
|
</dictionary>
|
||||||
|
</component>
|
||||||
@@ -11,8 +11,8 @@ android {
|
|||||||
defaultConfig {
|
defaultConfig {
|
||||||
minSdkVersion 16
|
minSdkVersion 16
|
||||||
targetSdkVersion 29
|
targetSdkVersion 29
|
||||||
versionCode 10214
|
versionCode 10216
|
||||||
versionName "1.2.14"
|
versionName "1.2.16"
|
||||||
consumerProguardFiles 'proguard-rules.txt'
|
consumerProguardFiles 'proguard-rules.txt'
|
||||||
|
|
||||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||||
@@ -38,8 +38,8 @@ configurations {
|
|||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation project(path: ':bramble-core', configuration: 'default')
|
implementation project(path: ':bramble-core', configuration: 'default')
|
||||||
tor 'org.briarproject:tor-android:0.3.5.12@zip'
|
tor 'org.briarproject:tor-android:0.3.5.13@zip'
|
||||||
tor 'org.briarproject:obfs4proxy-android:0.0.11-2@zip'
|
tor 'org.briarproject:obfs4proxy-android:0.0.12-dev-40245c4a@zip'
|
||||||
|
|
||||||
annotationProcessor 'com.google.dagger:dagger-compiler:2.24'
|
annotationProcessor 'com.google.dagger:dagger-compiler:2.24'
|
||||||
|
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ public class AndroidUtils {
|
|||||||
private static final String FAKE_BLUETOOTH_ADDRESS = "02:00:00:00:00:00";
|
private static final String FAKE_BLUETOOTH_ADDRESS = "02:00:00:00:00:00";
|
||||||
|
|
||||||
private static final String STORED_REPORTS = "dev-reports";
|
private static final String STORED_REPORTS = "dev-reports";
|
||||||
|
private static final String STORED_LOGCAT = "dev-logcat";
|
||||||
|
|
||||||
public static Collection<String> getSupportedArchitectures() {
|
public static Collection<String> getSupportedArchitectures() {
|
||||||
List<String> abis = new ArrayList<>();
|
List<String> abis = new ArrayList<>();
|
||||||
@@ -107,6 +108,10 @@ public class AndroidUtils {
|
|||||||
return ctx.getDir(STORED_REPORTS, MODE_PRIVATE);
|
return ctx.getDir(STORED_REPORTS, MODE_PRIVATE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static File getLogcatFile(Context ctx) {
|
||||||
|
return new File(ctx.getFilesDir(), STORED_LOGCAT);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an array of supported content types for image attachments.
|
* Returns an array of supported content types for image attachments.
|
||||||
* GIFs can't be compressed on API < 24 so they're not supported.
|
* GIFs can't be compressed on API < 24 so they're not supported.
|
||||||
|
|||||||
@@ -75,8 +75,8 @@ dependencyVerification {
|
|||||||
'org.beanshell:bsh:1.3.0:bsh-1.3.0.jar:9b04edc75d19db54f1b4e8b5355e9364384c6cf71eb0a1b9724c159d779879f8',
|
'org.beanshell:bsh:1.3.0:bsh-1.3.0.jar:9b04edc75d19db54f1b4e8b5355e9364384c6cf71eb0a1b9724c159d779879f8',
|
||||||
'org.bouncycastle:bcpkix-jdk15on:1.56:bcpkix-jdk15on-1.56.jar:7043dee4e9e7175e93e0b36f45b1ec1ecb893c5f755667e8b916eb8dd201c6ca',
|
'org.bouncycastle:bcpkix-jdk15on:1.56:bcpkix-jdk15on-1.56.jar:7043dee4e9e7175e93e0b36f45b1ec1ecb893c5f755667e8b916eb8dd201c6ca',
|
||||||
'org.bouncycastle:bcprov-jdk15on:1.56:bcprov-jdk15on-1.56.jar:963e1ee14f808ffb99897d848ddcdb28fa91ddda867eb18d303e82728f878349',
|
'org.bouncycastle:bcprov-jdk15on:1.56:bcprov-jdk15on-1.56.jar:963e1ee14f808ffb99897d848ddcdb28fa91ddda867eb18d303e82728f878349',
|
||||||
'org.briarproject:obfs4proxy-android:0.0.11-2:obfs4proxy-android-0.0.11-2.zip:57e55cbe87aa2aac210fdbb6cd8cdeafe15f825406a08ebf77a8b787aa2c6a8a',
|
'org.briarproject:obfs4proxy-android:0.0.12-dev-40245c4a:obfs4proxy-android-0.0.12-dev-40245c4a.zip:8ab05a8f8391be2cb5ab2b665c281a06d9e3a756bd0f95a40a36ca927866ea82',
|
||||||
'org.briarproject:tor-android:0.3.5.12:tor-android-0.3.5.12.zip:db71fb3290acff79d572af0752570eaf6aad7c4d88c9b9aa0b4d5afe2b9ead9c',
|
'org.briarproject:tor-android:0.3.5.13:tor-android-0.3.5.13.zip:e0978db136731dae07774b722970cdae1e462fb5adc82845dd80a7e2d87f356c',
|
||||||
'org.checkerframework:checker-compat-qual:2.5.3:checker-compat-qual-2.5.3.jar:d76b9afea61c7c082908023f0cbc1427fab9abd2df915c8b8a3e7a509bccbc6d',
|
'org.checkerframework:checker-compat-qual:2.5.3:checker-compat-qual-2.5.3.jar:d76b9afea61c7c082908023f0cbc1427fab9abd2df915c8b8a3e7a509bccbc6d',
|
||||||
'org.checkerframework:checker-qual:2.5.2:checker-qual-2.5.2.jar:64b02691c8b9d4e7700f8ee2e742dce7ea2c6e81e662b7522c9ee3bf568c040a',
|
'org.checkerframework:checker-qual:2.5.2:checker-qual-2.5.2.jar:64b02691c8b9d4e7700f8ee2e742dce7ea2c6e81e662b7522c9ee3bf568c040a',
|
||||||
'org.checkerframework:checker-qual:2.8.1:checker-qual-2.8.1.jar:9103499008bcecd4e948da29b17864abb64304e15706444ae209d17ebe0575df',
|
'org.checkerframework:checker-qual:2.8.1:checker-qual-2.8.1.jar:9103499008bcecd4e948da29b17864abb64304e15706444ae209d17ebe0575df',
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package org.briarproject.bramble.api.client;
|
package org.briarproject.bramble.api.client;
|
||||||
|
|
||||||
import org.briarproject.bramble.api.FormatException;
|
import org.briarproject.bramble.api.FormatException;
|
||||||
import org.briarproject.bramble.api.contact.ContactId;
|
|
||||||
import org.briarproject.bramble.api.crypto.PrivateKey;
|
import org.briarproject.bramble.api.crypto.PrivateKey;
|
||||||
import org.briarproject.bramble.api.crypto.PublicKey;
|
import org.briarproject.bramble.api.crypto.PublicKey;
|
||||||
import org.briarproject.bramble.api.data.BdfDictionary;
|
import org.briarproject.bramble.api.data.BdfDictionary;
|
||||||
@@ -120,17 +119,4 @@ public interface ClientHelper {
|
|||||||
Map<TransportId, TransportProperties> parseAndValidateTransportPropertiesMap(
|
Map<TransportId, TransportProperties> parseAndValidateTransportPropertiesMap(
|
||||||
BdfDictionary properties) throws FormatException;
|
BdfDictionary properties) throws FormatException;
|
||||||
|
|
||||||
/**
|
|
||||||
* Retrieves the contact ID from the group metadata of the given contact
|
|
||||||
* group.
|
|
||||||
*/
|
|
||||||
ContactId getContactId(Transaction txn, GroupId contactGroupId)
|
|
||||||
throws DbException, FormatException;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Stores the given contact ID in the group metadata of the given contact
|
|
||||||
* group.
|
|
||||||
*/
|
|
||||||
void setContactId(Transaction txn, GroupId contactGroupId, ContactId c)
|
|
||||||
throws DbException;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +0,0 @@
|
|||||||
package org.briarproject.bramble.api.client;
|
|
||||||
|
|
||||||
public interface ContactGroupConstants {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Group metadata key for associating a contact ID with a contact group.
|
|
||||||
*/
|
|
||||||
String GROUP_KEY_CONTACT_ID = "contactId";
|
|
||||||
}
|
|
||||||
@@ -19,4 +19,10 @@ public interface StreamDecrypterFactory {
|
|||||||
*/
|
*/
|
||||||
StreamDecrypter createContactExchangeStreamDecrypter(InputStream in,
|
StreamDecrypter createContactExchangeStreamDecrypter(InputStream in,
|
||||||
SecretKey headerKey);
|
SecretKey headerKey);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a {@link StreamDecrypter} for decrypting a log stream.
|
||||||
|
*/
|
||||||
|
StreamDecrypter createLogStreamDecrypter(InputStream in,
|
||||||
|
SecretKey headerKey);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,12 @@ public interface StreamEncrypterFactory {
|
|||||||
* Creates a {@link StreamEncrypter} for encrypting a contact exchange
|
* Creates a {@link StreamEncrypter} for encrypting a contact exchange
|
||||||
* stream.
|
* stream.
|
||||||
*/
|
*/
|
||||||
StreamEncrypter createContactExchangeStreamDecrypter(OutputStream out,
|
StreamEncrypter createContactExchangeStreamEncrypter(OutputStream out,
|
||||||
|
SecretKey headerKey);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a {@link StreamEncrypter} for encrypting a log stream.
|
||||||
|
*/
|
||||||
|
StreamEncrypter createLogStreamEncrypter(OutputStream out,
|
||||||
SecretKey headerKey);
|
SecretKey headerKey);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,4 +13,6 @@ public interface DevConfig {
|
|||||||
String getDevOnionAddress();
|
String getDevOnionAddress();
|
||||||
|
|
||||||
File getReportDir();
|
File getReportDir();
|
||||||
|
|
||||||
|
File getLogcatFile();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,8 +16,13 @@ public interface StreamReaderFactory {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an {@link InputStream InputStream} for reading from a contact
|
* Creates an {@link InputStream InputStream} for reading from a contact
|
||||||
* exchangestream.
|
* exchange stream.
|
||||||
*/
|
*/
|
||||||
InputStream createContactExchangeStreamReader(InputStream in,
|
InputStream createContactExchangeStreamReader(InputStream in,
|
||||||
SecretKey headerKey);
|
SecretKey headerKey);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates an {@link InputStream} for reading from a log stream.
|
||||||
|
*/
|
||||||
|
InputStream createLogStreamReader(InputStream in, SecretKey headerKey);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,17 +7,19 @@ import java.io.OutputStream;
|
|||||||
|
|
||||||
@NotNullByDefault
|
@NotNullByDefault
|
||||||
public interface StreamWriterFactory {
|
public interface StreamWriterFactory {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an {@link OutputStream OutputStream} for writing to a
|
* Creates a {@link StreamWriter} for writing to a transport stream.
|
||||||
* transport stream
|
|
||||||
*/
|
*/
|
||||||
StreamWriter createStreamWriter(OutputStream out, StreamContext ctx);
|
StreamWriter createStreamWriter(OutputStream out, StreamContext ctx);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an {@link OutputStream OutputStream} for writing to a contact
|
* Creates a {@link StreamWriter} for writing to a contact exchange stream.
|
||||||
* exchange stream.
|
|
||||||
*/
|
*/
|
||||||
StreamWriter createContactExchangeStreamWriter(OutputStream out,
|
StreamWriter createContactExchangeStreamWriter(OutputStream out,
|
||||||
SecretKey headerKey);
|
SecretKey headerKey);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a {@link StreamWriter} for writing to a log stream.
|
||||||
|
*/
|
||||||
|
StreamWriter createLogStreamWriter(OutputStream out, SecretKey headerKey);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,9 +6,7 @@ import org.briarproject.bramble.api.data.BdfList;
|
|||||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import javax.annotation.concurrent.Immutable;
|
|
||||||
|
|
||||||
@Immutable
|
|
||||||
@NotNullByDefault
|
@NotNullByDefault
|
||||||
public class ValidationUtils {
|
public class ValidationUtils {
|
||||||
|
|
||||||
@@ -66,9 +64,4 @@ public class ValidationUtils {
|
|||||||
if (dictionary != null && dictionary.size() != size)
|
if (dictionary != null && dictionary.size() != size)
|
||||||
throw new FormatException();
|
throw new FormatException();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void checkRange(@Nullable Long l, long min, long max)
|
|
||||||
throws FormatException {
|
|
||||||
if (l != null && (l < min || l > max)) throw new FormatException();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +0,0 @@
|
|||||||
package org.briarproject.bramble.test;
|
|
||||||
|
|
||||||
public interface TimeTravel {
|
|
||||||
|
|
||||||
void setCurrentTimeMillis(long now) throws InterruptedException;
|
|
||||||
|
|
||||||
void addCurrentTimeMillis(long add) throws InterruptedException;
|
|
||||||
}
|
|
||||||
@@ -21,6 +21,7 @@ import org.briarproject.bramble.rendezvous.RendezvousModule;
|
|||||||
import org.briarproject.bramble.settings.SettingsModule;
|
import org.briarproject.bramble.settings.SettingsModule;
|
||||||
import org.briarproject.bramble.sync.SyncModule;
|
import org.briarproject.bramble.sync.SyncModule;
|
||||||
import org.briarproject.bramble.sync.validation.ValidationModule;
|
import org.briarproject.bramble.sync.validation.ValidationModule;
|
||||||
|
import org.briarproject.bramble.system.ClockModule;
|
||||||
import org.briarproject.bramble.transport.TransportModule;
|
import org.briarproject.bramble.transport.TransportModule;
|
||||||
import org.briarproject.bramble.versioning.VersioningModule;
|
import org.briarproject.bramble.versioning.VersioningModule;
|
||||||
|
|
||||||
@@ -28,6 +29,7 @@ import dagger.Module;
|
|||||||
|
|
||||||
@Module(includes = {
|
@Module(includes = {
|
||||||
ClientModule.class,
|
ClientModule.class,
|
||||||
|
ClockModule.class,
|
||||||
ConnectionModule.class,
|
ConnectionModule.class,
|
||||||
ContactModule.class,
|
ContactModule.class,
|
||||||
CryptoModule.class,
|
CryptoModule.class,
|
||||||
|
|||||||
@@ -2,13 +2,11 @@ package org.briarproject.bramble.client;
|
|||||||
|
|
||||||
import org.briarproject.bramble.api.FormatException;
|
import org.briarproject.bramble.api.FormatException;
|
||||||
import org.briarproject.bramble.api.client.ClientHelper;
|
import org.briarproject.bramble.api.client.ClientHelper;
|
||||||
import org.briarproject.bramble.api.contact.ContactId;
|
|
||||||
import org.briarproject.bramble.api.crypto.CryptoComponent;
|
import org.briarproject.bramble.api.crypto.CryptoComponent;
|
||||||
import org.briarproject.bramble.api.crypto.KeyParser;
|
import org.briarproject.bramble.api.crypto.KeyParser;
|
||||||
import org.briarproject.bramble.api.crypto.PrivateKey;
|
import org.briarproject.bramble.api.crypto.PrivateKey;
|
||||||
import org.briarproject.bramble.api.crypto.PublicKey;
|
import org.briarproject.bramble.api.crypto.PublicKey;
|
||||||
import org.briarproject.bramble.api.data.BdfDictionary;
|
import org.briarproject.bramble.api.data.BdfDictionary;
|
||||||
import org.briarproject.bramble.api.data.BdfEntry;
|
|
||||||
import org.briarproject.bramble.api.data.BdfList;
|
import org.briarproject.bramble.api.data.BdfList;
|
||||||
import org.briarproject.bramble.api.data.BdfReader;
|
import org.briarproject.bramble.api.data.BdfReader;
|
||||||
import org.briarproject.bramble.api.data.BdfReaderFactory;
|
import org.briarproject.bramble.api.data.BdfReaderFactory;
|
||||||
@@ -41,7 +39,6 @@ import java.util.Map.Entry;
|
|||||||
import javax.annotation.concurrent.Immutable;
|
import javax.annotation.concurrent.Immutable;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
import static org.briarproject.bramble.api.client.ContactGroupConstants.GROUP_KEY_CONTACT_ID;
|
|
||||||
import static org.briarproject.bramble.api.identity.Author.FORMAT_VERSION;
|
import static org.briarproject.bramble.api.identity.Author.FORMAT_VERSION;
|
||||||
import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_AUTHOR_NAME_LENGTH;
|
import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_AUTHOR_NAME_LENGTH;
|
||||||
import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_PUBLIC_KEY_LENGTH;
|
import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_PUBLIC_KEY_LENGTH;
|
||||||
@@ -392,27 +389,4 @@ class ClientHelperImpl implements ClientHelper {
|
|||||||
return tpMap;
|
return tpMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public ContactId getContactId(Transaction txn, GroupId contactGroupId)
|
|
||||||
throws DbException {
|
|
||||||
try {
|
|
||||||
BdfDictionary meta =
|
|
||||||
getGroupMetadataAsDictionary(txn, contactGroupId);
|
|
||||||
return new ContactId(meta.getLong(GROUP_KEY_CONTACT_ID).intValue());
|
|
||||||
} catch (FormatException e) {
|
|
||||||
throw new DbException(e); // Invalid group metadata
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setContactId(Transaction txn, GroupId contactGroupId,
|
|
||||||
ContactId c) throws DbException {
|
|
||||||
BdfDictionary meta = BdfDictionary.of(
|
|
||||||
new BdfEntry(GROUP_KEY_CONTACT_ID, c.getInt()));
|
|
||||||
try {
|
|
||||||
mergeGroupMetadata(txn, contactGroupId, meta);
|
|
||||||
} catch (FormatException e) {
|
|
||||||
throw new AssertionError(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,14 +9,16 @@ import java.util.logging.Logger;
|
|||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
import static java.lang.Math.min;
|
||||||
import static java.util.logging.Level.INFO;
|
import static java.util.logging.Level.INFO;
|
||||||
|
import static java.util.logging.Logger.getLogger;
|
||||||
import static org.briarproject.bramble.util.LogUtils.logDuration;
|
import static org.briarproject.bramble.util.LogUtils.logDuration;
|
||||||
import static org.briarproject.bramble.util.LogUtils.now;
|
import static org.briarproject.bramble.util.LogUtils.now;
|
||||||
|
|
||||||
class ScryptKdf implements PasswordBasedKdf {
|
class ScryptKdf implements PasswordBasedKdf {
|
||||||
|
|
||||||
private static final Logger LOG =
|
private static final Logger LOG =
|
||||||
Logger.getLogger(ScryptKdf.class.getName());
|
getLogger(ScryptKdf.class.getName());
|
||||||
|
|
||||||
private static final int MIN_COST = 256; // Min parameter N
|
private static final int MIN_COST = 256; // Min parameter N
|
||||||
private static final int MAX_COST = 1024 * 1024; // Max parameter N
|
private static final int MAX_COST = 1024 * 1024; // Max parameter N
|
||||||
@@ -33,10 +35,20 @@ class ScryptKdf implements PasswordBasedKdf {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int chooseCostParameter() {
|
public int chooseCostParameter() {
|
||||||
|
// Scrypt uses at least 128 * N * r bytes of memory. Don't use more
|
||||||
|
// than half of the JVM's max heap size or we may run out of memory.
|
||||||
|
// https://blog.filippo.io/the-scrypt-parameters/
|
||||||
|
long maxMemory = Runtime.getRuntime().maxMemory();
|
||||||
|
long maxCost = min(MAX_COST, maxMemory / BLOCK_SIZE / 256);
|
||||||
|
if (LOG.isLoggable(INFO) && maxCost < MAX_COST) {
|
||||||
|
LOG.info("Max cost capped at " + maxCost
|
||||||
|
+ " due to max heap size " + maxMemory);
|
||||||
|
}
|
||||||
// Increase the cost from min to max while measuring performance
|
// Increase the cost from min to max while measuring performance
|
||||||
int cost = MIN_COST;
|
int cost = MIN_COST;
|
||||||
while (cost * 2 <= MAX_COST && measureDuration(cost) * 2 <= TARGET_MS)
|
while (cost * 2 <= maxCost && measureDuration(cost) * 2 <= TARGET_MS) {
|
||||||
cost *= 2;
|
cost *= 2;
|
||||||
|
}
|
||||||
if (LOG.isLoggable(INFO))
|
if (LOG.isLoggable(INFO))
|
||||||
LOG.info("KDF cost parameter " + cost);
|
LOG.info("KDF cost parameter " + cost);
|
||||||
return cost;
|
return cost;
|
||||||
|
|||||||
@@ -36,4 +36,10 @@ class StreamDecrypterFactoryImpl implements StreamDecrypterFactory {
|
|||||||
SecretKey headerKey) {
|
SecretKey headerKey) {
|
||||||
return new StreamDecrypterImpl(in, cipherProvider.get(), 0, headerKey);
|
return new StreamDecrypterImpl(in, cipherProvider.get(), 0, headerKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public StreamDecrypter createLogStreamDecrypter(InputStream in,
|
||||||
|
SecretKey headerKey) {
|
||||||
|
return createContactExchangeStreamDecrypter(in, headerKey);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ class StreamEncrypterFactoryImpl implements StreamEncrypterFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public StreamEncrypter createContactExchangeStreamDecrypter(
|
public StreamEncrypter createContactExchangeStreamEncrypter(
|
||||||
OutputStream out, SecretKey headerKey) {
|
OutputStream out, SecretKey headerKey) {
|
||||||
AuthenticatedCipher cipher = cipherProvider.get();
|
AuthenticatedCipher cipher = cipherProvider.get();
|
||||||
byte[] streamHeaderNonce = new byte[STREAM_HEADER_NONCE_LENGTH];
|
byte[] streamHeaderNonce = new byte[STREAM_HEADER_NONCE_LENGTH];
|
||||||
@@ -60,4 +60,10 @@ class StreamEncrypterFactoryImpl implements StreamEncrypterFactory {
|
|||||||
return new StreamEncrypterImpl(out, cipher, 0, null, streamHeaderNonce,
|
return new StreamEncrypterImpl(out, cipher, 0, null, streamHeaderNonce,
|
||||||
headerKey, frameKey);
|
headerKey, frameKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public StreamEncrypter createLogStreamEncrypter(OutputStream out,
|
||||||
|
SecretKey headerKey) {
|
||||||
|
return createContactExchangeStreamEncrypter(out, headerKey);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,15 +24,21 @@ class StreamReaderFactoryImpl implements StreamReaderFactory {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public InputStream createStreamReader(InputStream in, StreamContext ctx) {
|
public InputStream createStreamReader(InputStream in, StreamContext ctx) {
|
||||||
return new StreamReaderImpl(
|
return new StreamReaderImpl(streamDecrypterFactory
|
||||||
streamDecrypterFactory.createStreamDecrypter(in, ctx));
|
.createStreamDecrypter(in, ctx));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public InputStream createContactExchangeStreamReader(InputStream in,
|
public InputStream createContactExchangeStreamReader(InputStream in,
|
||||||
SecretKey headerKey) {
|
SecretKey headerKey) {
|
||||||
return new StreamReaderImpl(
|
return new StreamReaderImpl(streamDecrypterFactory
|
||||||
streamDecrypterFactory.createContactExchangeStreamDecrypter(in,
|
.createContactExchangeStreamDecrypter(in, headerKey));
|
||||||
headerKey));
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public InputStream createLogStreamReader(InputStream in,
|
||||||
|
SecretKey headerKey) {
|
||||||
|
return new StreamReaderImpl(streamDecrypterFactory
|
||||||
|
.createLogStreamDecrypter(in, headerKey));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,15 +26,21 @@ class StreamWriterFactoryImpl implements StreamWriterFactory {
|
|||||||
@Override
|
@Override
|
||||||
public StreamWriter createStreamWriter(OutputStream out,
|
public StreamWriter createStreamWriter(OutputStream out,
|
||||||
StreamContext ctx) {
|
StreamContext ctx) {
|
||||||
return new StreamWriterImpl(
|
return new StreamWriterImpl(streamEncrypterFactory
|
||||||
streamEncrypterFactory.createStreamEncrypter(out, ctx));
|
.createStreamEncrypter(out, ctx));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public StreamWriter createContactExchangeStreamWriter(OutputStream out,
|
public StreamWriter createContactExchangeStreamWriter(OutputStream out,
|
||||||
SecretKey headerKey) {
|
SecretKey headerKey) {
|
||||||
return new StreamWriterImpl(
|
return new StreamWriterImpl(streamEncrypterFactory
|
||||||
streamEncrypterFactory.createContactExchangeStreamDecrypter(out,
|
.createContactExchangeStreamEncrypter(out, headerKey));
|
||||||
headerKey));
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public StreamWriter createLogStreamWriter(OutputStream out,
|
||||||
|
SecretKey headerKey) {
|
||||||
|
return new StreamWriterImpl(streamEncrypterFactory
|
||||||
|
.createLogStreamEncrypter(out, headerKey));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -5,5 +5,6 @@ interface ClientVersioningConstants {
|
|||||||
// Metadata keys
|
// Metadata keys
|
||||||
String MSG_KEY_UPDATE_VERSION = "version";
|
String MSG_KEY_UPDATE_VERSION = "version";
|
||||||
String MSG_KEY_LOCAL = "local";
|
String MSG_KEY_LOCAL = "local";
|
||||||
|
String GROUP_KEY_CONTACT_ID = "contactId";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -50,6 +50,7 @@ import static java.util.Collections.emptyList;
|
|||||||
import static org.briarproject.bramble.api.sync.Group.Visibility.INVISIBLE;
|
import static org.briarproject.bramble.api.sync.Group.Visibility.INVISIBLE;
|
||||||
import static org.briarproject.bramble.api.sync.Group.Visibility.SHARED;
|
import static org.briarproject.bramble.api.sync.Group.Visibility.SHARED;
|
||||||
import static org.briarproject.bramble.api.sync.Group.Visibility.VISIBLE;
|
import static org.briarproject.bramble.api.sync.Group.Visibility.VISIBLE;
|
||||||
|
import static org.briarproject.bramble.versioning.ClientVersioningConstants.GROUP_KEY_CONTACT_ID;
|
||||||
import static org.briarproject.bramble.versioning.ClientVersioningConstants.MSG_KEY_LOCAL;
|
import static org.briarproject.bramble.versioning.ClientVersioningConstants.MSG_KEY_LOCAL;
|
||||||
import static org.briarproject.bramble.versioning.ClientVersioningConstants.MSG_KEY_UPDATE_VERSION;
|
import static org.briarproject.bramble.versioning.ClientVersioningConstants.MSG_KEY_UPDATE_VERSION;
|
||||||
|
|
||||||
@@ -160,7 +161,13 @@ class ClientVersioningManagerImpl implements ClientVersioningManager,
|
|||||||
db.addGroup(txn, g);
|
db.addGroup(txn, g);
|
||||||
db.setGroupVisibility(txn, c.getId(), g.getId(), SHARED);
|
db.setGroupVisibility(txn, c.getId(), g.getId(), SHARED);
|
||||||
// Attach the contact ID to the group
|
// Attach the contact ID to the group
|
||||||
clientHelper.setContactId(txn, g.getId(), c.getId());
|
BdfDictionary meta = new BdfDictionary();
|
||||||
|
meta.put(GROUP_KEY_CONTACT_ID, c.getId().getInt());
|
||||||
|
try {
|
||||||
|
clientHelper.mergeGroupMetadata(txn, g.getId(), meta);
|
||||||
|
} catch (FormatException e) {
|
||||||
|
throw new AssertionError(e);
|
||||||
|
}
|
||||||
// Create and store the first local update
|
// Create and store the first local update
|
||||||
List<ClientVersion> versions = new ArrayList<>(clients);
|
List<ClientVersion> versions = new ArrayList<>(clients);
|
||||||
Collections.sort(versions);
|
Collections.sort(versions);
|
||||||
@@ -222,7 +229,7 @@ class ClientVersioningManagerImpl implements ClientVersioningManager,
|
|||||||
Map<ClientMajorVersion, Visibility> after =
|
Map<ClientMajorVersion, Visibility> after =
|
||||||
getVisibilities(newLocalStates, newRemoteStates);
|
getVisibilities(newLocalStates, newRemoteStates);
|
||||||
// Call hooks for any visibilities that have changed
|
// Call hooks for any visibilities that have changed
|
||||||
ContactId c = clientHelper.getContactId(txn, m.getGroupId());
|
ContactId c = getContactId(txn, m.getGroupId());
|
||||||
if (!before.equals(after)) {
|
if (!before.equals(after)) {
|
||||||
Contact contact = db.getContact(txn, c);
|
Contact contact = db.getContact(txn, c);
|
||||||
callVisibilityHooks(txn, contact, before, after);
|
callVisibilityHooks(txn, contact, before, after);
|
||||||
@@ -514,6 +521,17 @@ class ClientVersioningManagerImpl implements ClientVersioningManager,
|
|||||||
storeUpdate(txn, g, states, 1);
|
storeUpdate(txn, g, states, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private ContactId getContactId(Transaction txn, GroupId g)
|
||||||
|
throws DbException {
|
||||||
|
try {
|
||||||
|
BdfDictionary meta =
|
||||||
|
clientHelper.getGroupMetadataAsDictionary(txn, g);
|
||||||
|
return new ContactId(meta.getLong(GROUP_KEY_CONTACT_ID).intValue());
|
||||||
|
} catch (FormatException e) {
|
||||||
|
throw new DbException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private List<ClientState> updateStatesFromRemoteStates(
|
private List<ClientState> updateStatesFromRemoteStates(
|
||||||
List<ClientState> oldLocalStates, List<ClientState> remoteStates) {
|
List<ClientState> oldLocalStates, List<ClientState> remoteStates) {
|
||||||
Set<ClientMajorVersion> remoteSet = new HashSet<>();
|
Set<ClientMajorVersion> remoteSet = new HashSet<>();
|
||||||
|
|||||||
@@ -1,18 +1,18 @@
|
|||||||
package org.briarproject.bramble;
|
package org.briarproject.bramble;
|
||||||
|
|
||||||
import org.briarproject.bramble.system.TimeTravelModule;
|
import org.briarproject.bramble.system.DefaultTaskSchedulerModule;
|
||||||
|
|
||||||
public interface BrambleCoreIntegrationTestEagerSingletons
|
public interface BrambleCoreIntegrationTestEagerSingletons
|
||||||
extends BrambleCoreEagerSingletons {
|
extends BrambleCoreEagerSingletons {
|
||||||
|
|
||||||
void inject(TimeTravelModule.EagerSingletons init);
|
void inject(DefaultTaskSchedulerModule.EagerSingletons init);
|
||||||
|
|
||||||
class Helper {
|
class Helper {
|
||||||
|
|
||||||
public static void injectEagerSingletons(
|
public static void injectEagerSingletons(
|
||||||
BrambleCoreIntegrationTestEagerSingletons c) {
|
BrambleCoreIntegrationTestEagerSingletons c) {
|
||||||
BrambleCoreEagerSingletons.Helper.injectEagerSingletons(c);
|
BrambleCoreEagerSingletons.Helper.injectEagerSingletons(c);
|
||||||
c.inject(new TimeTravelModule.EagerSingletons());
|
c.inject(new DefaultTaskSchedulerModule.EagerSingletons());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,122 +0,0 @@
|
|||||||
package org.briarproject.bramble.system;
|
|
||||||
|
|
||||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
|
||||||
import org.briarproject.bramble.api.system.Clock;
|
|
||||||
import org.briarproject.bramble.api.system.TaskScheduler;
|
|
||||||
|
|
||||||
import java.util.Queue;
|
|
||||||
import java.util.concurrent.CountDownLatch;
|
|
||||||
import java.util.concurrent.Executor;
|
|
||||||
import java.util.concurrent.PriorityBlockingQueue;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
|
||||||
|
|
||||||
import static java.util.concurrent.TimeUnit.MILLISECONDS;
|
|
||||||
import static java.util.concurrent.TimeUnit.MINUTES;
|
|
||||||
import static org.junit.Assert.fail;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A {@link TaskScheduler} for use in tests. The scheduler keeps all scheduled
|
|
||||||
* tasks in a queue until {@link #runTasks()} is called.
|
|
||||||
*/
|
|
||||||
@NotNullByDefault
|
|
||||||
class TestTaskScheduler implements TaskScheduler {
|
|
||||||
|
|
||||||
private final Queue<Task> queue = new PriorityBlockingQueue<>();
|
|
||||||
private final Clock clock;
|
|
||||||
|
|
||||||
TestTaskScheduler(Clock clock) {
|
|
||||||
this.clock = clock;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Cancellable schedule(Runnable task, Executor executor, long delay,
|
|
||||||
TimeUnit unit) {
|
|
||||||
AtomicBoolean cancelled = new AtomicBoolean(false);
|
|
||||||
return schedule(task, executor, delay, unit, cancelled);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Cancellable scheduleWithFixedDelay(Runnable task, Executor executor,
|
|
||||||
long delay, long interval, TimeUnit unit) {
|
|
||||||
AtomicBoolean cancelled = new AtomicBoolean(false);
|
|
||||||
return scheduleWithFixedDelay(task, executor, delay, interval, unit,
|
|
||||||
cancelled);
|
|
||||||
}
|
|
||||||
|
|
||||||
private Cancellable schedule(Runnable task, Executor executor, long delay,
|
|
||||||
TimeUnit unit, AtomicBoolean cancelled) {
|
|
||||||
long delayMillis = MILLISECONDS.convert(delay, unit);
|
|
||||||
long dueMillis = clock.currentTimeMillis() + delayMillis;
|
|
||||||
Task t = new Task(task, executor, dueMillis, cancelled);
|
|
||||||
queue.add(t);
|
|
||||||
return t;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Cancellable scheduleWithFixedDelay(Runnable task, Executor executor,
|
|
||||||
long delay, long interval, TimeUnit unit, AtomicBoolean cancelled) {
|
|
||||||
// All executions of this periodic task share a cancelled flag
|
|
||||||
Runnable wrapped = () -> {
|
|
||||||
task.run();
|
|
||||||
scheduleWithFixedDelay(task, executor, interval, interval, unit,
|
|
||||||
cancelled);
|
|
||||||
};
|
|
||||||
return schedule(wrapped, executor, delay, unit, cancelled);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Runs any scheduled tasks that are due.
|
|
||||||
*/
|
|
||||||
void runTasks() throws InterruptedException {
|
|
||||||
long now = clock.currentTimeMillis();
|
|
||||||
while (true) {
|
|
||||||
Task t = queue.peek();
|
|
||||||
if (t == null || t.dueMillis > now) return;
|
|
||||||
t = queue.poll();
|
|
||||||
// Submit the task to its executor and wait for it to finish
|
|
||||||
if (!t.run().await(1, MINUTES)) fail();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class Task
|
|
||||||
implements Cancellable, Comparable<Task> {
|
|
||||||
|
|
||||||
private final Runnable task;
|
|
||||||
private final Executor executor;
|
|
||||||
private final long dueMillis;
|
|
||||||
private final AtomicBoolean cancelled;
|
|
||||||
|
|
||||||
private Task(Runnable task, Executor executor, long dueMillis,
|
|
||||||
AtomicBoolean cancelled) {
|
|
||||||
this.task = task;
|
|
||||||
this.executor = executor;
|
|
||||||
this.dueMillis = dueMillis;
|
|
||||||
this.cancelled = cancelled;
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("UseCompareMethod") // Animal Sniffer
|
|
||||||
@Override
|
|
||||||
public int compareTo(Task task) {
|
|
||||||
return Long.valueOf(dueMillis).compareTo(task.dueMillis);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Submits the task to its executor and returns a latch that will be
|
|
||||||
* released when the task finishes.
|
|
||||||
*/
|
|
||||||
public CountDownLatch run() {
|
|
||||||
if (cancelled.get()) return new CountDownLatch(0);
|
|
||||||
CountDownLatch latch = new CountDownLatch(1);
|
|
||||||
executor.execute(() -> {
|
|
||||||
task.run();
|
|
||||||
latch.countDown();
|
|
||||||
});
|
|
||||||
return latch;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void cancel() {
|
|
||||||
cancelled.set(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,98 +0,0 @@
|
|||||||
package org.briarproject.bramble.system;
|
|
||||||
|
|
||||||
import org.briarproject.bramble.api.lifecycle.LifecycleManager;
|
|
||||||
import org.briarproject.bramble.api.system.Clock;
|
|
||||||
import org.briarproject.bramble.api.system.TaskScheduler;
|
|
||||||
import org.briarproject.bramble.test.SettableClock;
|
|
||||||
import org.briarproject.bramble.test.TimeTravel;
|
|
||||||
|
|
||||||
import java.util.concurrent.RejectedExecutionHandler;
|
|
||||||
import java.util.concurrent.ScheduledExecutorService;
|
|
||||||
import java.util.concurrent.ScheduledThreadPoolExecutor;
|
|
||||||
import java.util.concurrent.atomic.AtomicLong;
|
|
||||||
|
|
||||||
import javax.inject.Inject;
|
|
||||||
import javax.inject.Singleton;
|
|
||||||
|
|
||||||
import dagger.Module;
|
|
||||||
import dagger.Provides;
|
|
||||||
|
|
||||||
@Module
|
|
||||||
public class TimeTravelModule {
|
|
||||||
|
|
||||||
public static class EagerSingletons {
|
|
||||||
@Inject
|
|
||||||
TaskScheduler scheduler;
|
|
||||||
}
|
|
||||||
|
|
||||||
private final ScheduledExecutorService scheduledExecutorService;
|
|
||||||
private final Clock clock;
|
|
||||||
private final TaskScheduler taskScheduler;
|
|
||||||
private final TimeTravel timeTravel;
|
|
||||||
|
|
||||||
public TimeTravelModule() {
|
|
||||||
this(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
public TimeTravelModule(boolean travel) {
|
|
||||||
// Discard tasks that are submitted during shutdown
|
|
||||||
RejectedExecutionHandler policy =
|
|
||||||
new ScheduledThreadPoolExecutor.DiscardPolicy();
|
|
||||||
scheduledExecutorService =
|
|
||||||
new ScheduledThreadPoolExecutor(1, policy);
|
|
||||||
if (travel) {
|
|
||||||
// Use a SettableClock and TestTaskScheduler to allow time travel
|
|
||||||
AtomicLong time = new AtomicLong(System.currentTimeMillis());
|
|
||||||
clock = new SettableClock(time);
|
|
||||||
TestTaskScheduler testTaskScheduler = new TestTaskScheduler(clock);
|
|
||||||
taskScheduler = testTaskScheduler;
|
|
||||||
timeTravel = new TimeTravel() {
|
|
||||||
@Override
|
|
||||||
public void setCurrentTimeMillis(long now)
|
|
||||||
throws InterruptedException {
|
|
||||||
time.set(now);
|
|
||||||
testTaskScheduler.runTasks();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void addCurrentTimeMillis(long add)
|
|
||||||
throws InterruptedException {
|
|
||||||
time.addAndGet(add);
|
|
||||||
testTaskScheduler.runTasks();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
} else {
|
|
||||||
// Use the default clock and task scheduler
|
|
||||||
clock = new SystemClock();
|
|
||||||
taskScheduler = new TaskSchedulerImpl(scheduledExecutorService);
|
|
||||||
timeTravel = new TimeTravel() {
|
|
||||||
@Override
|
|
||||||
public void setCurrentTimeMillis(long now) {
|
|
||||||
throw new UnsupportedOperationException();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void addCurrentTimeMillis(long add) {
|
|
||||||
throw new UnsupportedOperationException();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Provides
|
|
||||||
Clock provideClock() {
|
|
||||||
return clock;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Provides
|
|
||||||
@Singleton
|
|
||||||
TaskScheduler provideTaskScheduler(LifecycleManager lifecycleManager) {
|
|
||||||
lifecycleManager.registerForShutdown(scheduledExecutorService);
|
|
||||||
return taskScheduler;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Provides
|
|
||||||
TimeTravel provideTimeTravel() {
|
|
||||||
return timeTravel;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -3,8 +3,8 @@ package org.briarproject.bramble.test;
|
|||||||
import org.briarproject.bramble.api.FeatureFlags;
|
import org.briarproject.bramble.api.FeatureFlags;
|
||||||
import org.briarproject.bramble.battery.DefaultBatteryManagerModule;
|
import org.briarproject.bramble.battery.DefaultBatteryManagerModule;
|
||||||
import org.briarproject.bramble.event.DefaultEventExecutorModule;
|
import org.briarproject.bramble.event.DefaultEventExecutorModule;
|
||||||
|
import org.briarproject.bramble.system.DefaultTaskSchedulerModule;
|
||||||
import org.briarproject.bramble.system.DefaultWakefulIoExecutorModule;
|
import org.briarproject.bramble.system.DefaultWakefulIoExecutorModule;
|
||||||
import org.briarproject.bramble.system.TimeTravelModule;
|
|
||||||
|
|
||||||
import dagger.Module;
|
import dagger.Module;
|
||||||
import dagger.Provides;
|
import dagger.Provides;
|
||||||
@@ -12,11 +12,11 @@ import dagger.Provides;
|
|||||||
@Module(includes = {
|
@Module(includes = {
|
||||||
DefaultBatteryManagerModule.class,
|
DefaultBatteryManagerModule.class,
|
||||||
DefaultEventExecutorModule.class,
|
DefaultEventExecutorModule.class,
|
||||||
|
DefaultTaskSchedulerModule.class,
|
||||||
DefaultWakefulIoExecutorModule.class,
|
DefaultWakefulIoExecutorModule.class,
|
||||||
TestDatabaseConfigModule.class,
|
TestDatabaseConfigModule.class,
|
||||||
TestPluginConfigModule.class,
|
TestPluginConfigModule.class,
|
||||||
TestSecureRandomModule.class,
|
TestSecureRandomModule.class
|
||||||
TimeTravelModule.class
|
|
||||||
})
|
})
|
||||||
public class BrambleCoreIntegrationTestModule {
|
public class BrambleCoreIntegrationTestModule {
|
||||||
|
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ import static org.briarproject.bramble.test.TestUtils.getContact;
|
|||||||
import static org.briarproject.bramble.test.TestUtils.getGroup;
|
import static org.briarproject.bramble.test.TestUtils.getGroup;
|
||||||
import static org.briarproject.bramble.test.TestUtils.getMessage;
|
import static org.briarproject.bramble.test.TestUtils.getMessage;
|
||||||
import static org.briarproject.bramble.test.TestUtils.getRandomId;
|
import static org.briarproject.bramble.test.TestUtils.getRandomId;
|
||||||
|
import static org.briarproject.bramble.versioning.ClientVersioningConstants.GROUP_KEY_CONTACT_ID;
|
||||||
import static org.briarproject.bramble.versioning.ClientVersioningConstants.MSG_KEY_LOCAL;
|
import static org.briarproject.bramble.versioning.ClientVersioningConstants.MSG_KEY_LOCAL;
|
||||||
import static org.briarproject.bramble.versioning.ClientVersioningConstants.MSG_KEY_UPDATE_VERSION;
|
import static org.briarproject.bramble.versioning.ClientVersioningConstants.MSG_KEY_UPDATE_VERSION;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
@@ -59,6 +60,8 @@ public class ClientVersioningManagerImplTest extends BrambleMockTestCase {
|
|||||||
private final ClientId clientId = getClientId();
|
private final ClientId clientId = getClientId();
|
||||||
private final long now = System.currentTimeMillis();
|
private final long now = System.currentTimeMillis();
|
||||||
private final Transaction txn = new Transaction(null, false);
|
private final Transaction txn = new Transaction(null, false);
|
||||||
|
private final BdfDictionary groupMeta = BdfDictionary.of(
|
||||||
|
new BdfEntry(GROUP_KEY_CONTACT_ID, contact.getId().getInt()));
|
||||||
|
|
||||||
private ClientVersioningManagerImpl createInstance() {
|
private ClientVersioningManagerImpl createInstance() {
|
||||||
context.checking(new Expectations() {{
|
context.checking(new Expectations() {{
|
||||||
@@ -120,8 +123,8 @@ public class ClientVersioningManagerImplTest extends BrambleMockTestCase {
|
|||||||
oneOf(db).addGroup(txn, contactGroup);
|
oneOf(db).addGroup(txn, contactGroup);
|
||||||
oneOf(db).setGroupVisibility(txn, contact.getId(),
|
oneOf(db).setGroupVisibility(txn, contact.getId(),
|
||||||
contactGroup.getId(), SHARED);
|
contactGroup.getId(), SHARED);
|
||||||
oneOf(clientHelper).setContactId(txn, contactGroup.getId(),
|
oneOf(clientHelper).mergeGroupMetadata(txn, contactGroup.getId(),
|
||||||
contact.getId());
|
groupMeta);
|
||||||
oneOf(clock).currentTimeMillis();
|
oneOf(clock).currentTimeMillis();
|
||||||
will(returnValue(now));
|
will(returnValue(now));
|
||||||
oneOf(clientHelper).createMessage(contactGroup.getId(), now,
|
oneOf(clientHelper).createMessage(contactGroup.getId(), now,
|
||||||
@@ -457,8 +460,9 @@ public class ClientVersioningManagerImplTest extends BrambleMockTestCase {
|
|||||||
oneOf(db).deleteMessage(txn, oldRemoteUpdateId);
|
oneOf(db).deleteMessage(txn, oldRemoteUpdateId);
|
||||||
oneOf(db).deleteMessageMetadata(txn, oldRemoteUpdateId);
|
oneOf(db).deleteMessageMetadata(txn, oldRemoteUpdateId);
|
||||||
// Get contact ID
|
// Get contact ID
|
||||||
oneOf(clientHelper).getContactId(txn, contactGroup.getId());
|
oneOf(clientHelper).getGroupMetadataAsDictionary(txn,
|
||||||
will(returnValue(contact.getId()));
|
contactGroup.getId());
|
||||||
|
will(returnValue(groupMeta));
|
||||||
// No states or visibilities have changed
|
// No states or visibilities have changed
|
||||||
}});
|
}});
|
||||||
|
|
||||||
@@ -488,9 +492,10 @@ public class ClientVersioningManagerImplTest extends BrambleMockTestCase {
|
|||||||
// Load the latest local update
|
// Load the latest local update
|
||||||
oneOf(clientHelper).getMessageAsList(txn, oldLocalUpdateId);
|
oneOf(clientHelper).getMessageAsList(txn, oldLocalUpdateId);
|
||||||
will(returnValue(oldLocalUpdateBody));
|
will(returnValue(oldLocalUpdateBody));
|
||||||
// Get contact ID
|
// Get client ID
|
||||||
oneOf(clientHelper).getContactId(txn, contactGroup.getId());
|
oneOf(clientHelper).getGroupMetadataAsDictionary(txn,
|
||||||
will(returnValue(contact.getId()));
|
contactGroup.getId());
|
||||||
|
will(returnValue(groupMeta));
|
||||||
// No states or visibilities have changed
|
// No states or visibilities have changed
|
||||||
}});
|
}});
|
||||||
|
|
||||||
@@ -541,6 +546,8 @@ public class ClientVersioningManagerImplTest extends BrambleMockTestCase {
|
|||||||
BdfDictionary newLocalUpdateMeta = BdfDictionary.of(
|
BdfDictionary newLocalUpdateMeta = BdfDictionary.of(
|
||||||
new BdfEntry(MSG_KEY_UPDATE_VERSION, 2L),
|
new BdfEntry(MSG_KEY_UPDATE_VERSION, 2L),
|
||||||
new BdfEntry(MSG_KEY_LOCAL, true));
|
new BdfEntry(MSG_KEY_LOCAL, true));
|
||||||
|
BdfDictionary groupMeta = BdfDictionary.of(
|
||||||
|
new BdfEntry(GROUP_KEY_CONTACT_ID, contact.getId().getInt()));
|
||||||
|
|
||||||
context.checking(new Expectations() {{
|
context.checking(new Expectations() {{
|
||||||
oneOf(clientHelper).toList(newRemoteUpdate);
|
oneOf(clientHelper).toList(newRemoteUpdate);
|
||||||
@@ -570,8 +577,9 @@ public class ClientVersioningManagerImplTest extends BrambleMockTestCase {
|
|||||||
oneOf(clientHelper).addLocalMessage(txn, newLocalUpdate,
|
oneOf(clientHelper).addLocalMessage(txn, newLocalUpdate,
|
||||||
newLocalUpdateMeta, true, false);
|
newLocalUpdateMeta, true, false);
|
||||||
// The client's visibility has changed
|
// The client's visibility has changed
|
||||||
oneOf(clientHelper).getContactId(txn, contactGroup.getId());
|
oneOf(clientHelper).getGroupMetadataAsDictionary(txn,
|
||||||
will(returnValue(contact.getId()));
|
contactGroup.getId());
|
||||||
|
will(returnValue(groupMeta));
|
||||||
oneOf(db).getContact(txn, contact.getId());
|
oneOf(db).getContact(txn, contact.getId());
|
||||||
will(returnValue(contact));
|
will(returnValue(contact));
|
||||||
oneOf(hook).onClientVisibilityChanging(txn, contact, visibility);
|
oneOf(hook).onClientVisibilityChanging(txn, contact, visibility);
|
||||||
@@ -611,6 +619,8 @@ public class ClientVersioningManagerImplTest extends BrambleMockTestCase {
|
|||||||
BdfDictionary newLocalUpdateMeta = BdfDictionary.of(
|
BdfDictionary newLocalUpdateMeta = BdfDictionary.of(
|
||||||
new BdfEntry(MSG_KEY_UPDATE_VERSION, 2L),
|
new BdfEntry(MSG_KEY_UPDATE_VERSION, 2L),
|
||||||
new BdfEntry(MSG_KEY_LOCAL, true));
|
new BdfEntry(MSG_KEY_LOCAL, true));
|
||||||
|
BdfDictionary groupMeta = BdfDictionary.of(
|
||||||
|
new BdfEntry(GROUP_KEY_CONTACT_ID, contact.getId().getInt()));
|
||||||
|
|
||||||
context.checking(new Expectations() {{
|
context.checking(new Expectations() {{
|
||||||
oneOf(clientHelper).toList(newRemoteUpdate);
|
oneOf(clientHelper).toList(newRemoteUpdate);
|
||||||
@@ -640,8 +650,9 @@ public class ClientVersioningManagerImplTest extends BrambleMockTestCase {
|
|||||||
oneOf(clientHelper).addLocalMessage(txn, newLocalUpdate,
|
oneOf(clientHelper).addLocalMessage(txn, newLocalUpdate,
|
||||||
newLocalUpdateMeta, true, false);
|
newLocalUpdateMeta, true, false);
|
||||||
// The client's visibility has changed
|
// The client's visibility has changed
|
||||||
oneOf(clientHelper).getContactId(txn, contactGroup.getId());
|
oneOf(clientHelper).getGroupMetadataAsDictionary(txn,
|
||||||
will(returnValue(contact.getId()));
|
contactGroup.getId());
|
||||||
|
will(returnValue(groupMeta));
|
||||||
oneOf(db).getContact(txn, contact.getId());
|
oneOf(db).getContact(txn, contact.getId());
|
||||||
will(returnValue(contact));
|
will(returnValue(contact));
|
||||||
oneOf(hook).onClientVisibilityChanging(txn, contact, INVISIBLE);
|
oneOf(hook).onClientVisibilityChanging(txn, contact, INVISIBLE);
|
||||||
|
|||||||
@@ -16,8 +16,8 @@ dependencies {
|
|||||||
implementation fileTree(dir: 'libs', include: '*.jar')
|
implementation fileTree(dir: 'libs', include: '*.jar')
|
||||||
implementation 'net.java.dev.jna:jna:4.5.2'
|
implementation 'net.java.dev.jna:jna:4.5.2'
|
||||||
implementation 'net.java.dev.jna:jna-platform:4.5.2'
|
implementation 'net.java.dev.jna:jna-platform:4.5.2'
|
||||||
tor 'org.briarproject:tor:0.3.5.12@zip'
|
tor 'org.briarproject:tor:0.3.5.13@zip'
|
||||||
tor 'org.briarproject:obfs4proxy:0.0.7@zip'
|
tor 'org.briarproject:obfs4proxy:0.0.12-dev-40245c4a@zip'
|
||||||
|
|
||||||
annotationProcessor 'com.google.dagger:dagger-compiler:2.24'
|
annotationProcessor 'com.google.dagger:dagger-compiler:2.24'
|
||||||
|
|
||||||
|
|||||||
@@ -8,9 +8,9 @@ import org.briarproject.bramble.system.JavaSystemModule;
|
|||||||
import dagger.Module;
|
import dagger.Module;
|
||||||
|
|
||||||
@Module(includes = {
|
@Module(includes = {
|
||||||
CircumventionModule.class,
|
|
||||||
JavaNetworkModule.class,
|
JavaNetworkModule.class,
|
||||||
JavaSystemModule.class,
|
JavaSystemModule.class,
|
||||||
|
CircumventionModule.class,
|
||||||
SocksModule.class
|
SocksModule.class
|
||||||
})
|
})
|
||||||
public class BrambleJavaModule {
|
public class BrambleJavaModule {
|
||||||
|
|||||||
@@ -14,12 +14,18 @@ import org.briarproject.bramble.api.system.ResourceProvider;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import javax.net.SocketFactory;
|
import javax.net.SocketFactory;
|
||||||
|
|
||||||
|
import static java.util.logging.Level.INFO;
|
||||||
|
import static java.util.logging.Logger.getLogger;
|
||||||
|
|
||||||
@NotNullByDefault
|
@NotNullByDefault
|
||||||
class UnixTorPlugin extends JavaTorPlugin {
|
class UnixTorPlugin extends JavaTorPlugin {
|
||||||
|
|
||||||
|
private static final Logger LOG = getLogger(UnixTorPlugin.class.getName());
|
||||||
|
|
||||||
UnixTorPlugin(Executor ioExecutor,
|
UnixTorPlugin(Executor ioExecutor,
|
||||||
Executor wakefulIoExecutor,
|
Executor wakefulIoExecutor,
|
||||||
NetworkManager networkManager,
|
NetworkManager networkManager,
|
||||||
@@ -41,6 +47,8 @@ class UnixTorPlugin extends JavaTorPlugin {
|
|||||||
circumventionProvider, batteryManager, backoff,
|
circumventionProvider, batteryManager, backoff,
|
||||||
torRendezvousCrypto, callback, architecture,
|
torRendezvousCrypto, callback, architecture,
|
||||||
maxLatency, maxIdleTime, torDirectory);
|
maxLatency, maxIdleTime, torDirectory);
|
||||||
|
boolean isGlibc = isGlibc();
|
||||||
|
if (LOG.isLoggable(INFO)) LOG.info("System uses glibc: " + isGlibc);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -48,10 +56,27 @@ class UnixTorPlugin extends JavaTorPlugin {
|
|||||||
return CLibrary.INSTANCE.getpid();
|
return CLibrary.INSTANCE.getpid();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected boolean isGlibc() {
|
||||||
|
try {
|
||||||
|
GnuCLibrary glibc = Native.loadLibrary("c", GnuCLibrary.class);
|
||||||
|
if (LOG.isLoggable(INFO)) {
|
||||||
|
LOG.info("glibc version " + glibc.gnu_get_libc_version());
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
} catch (UnsatisfiedLinkError e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private interface CLibrary extends Library {
|
private interface CLibrary extends Library {
|
||||||
|
|
||||||
CLibrary INSTANCE = Native.loadLibrary("c", CLibrary.class);
|
CLibrary INSTANCE = Native.loadLibrary("c", CLibrary.class);
|
||||||
|
|
||||||
int getpid();
|
int getpid();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private interface GnuCLibrary extends Library {
|
||||||
|
|
||||||
|
String gnu_get_libc_version();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,8 +23,8 @@ dependencyVerification {
|
|||||||
'org.apache.ant:ant-launcher:1.9.4:ant-launcher-1.9.4.jar:7bccea20b41801ca17bcbc909a78c835d0f443f12d639c77bd6ae3d05861608d',
|
'org.apache.ant:ant-launcher:1.9.4:ant-launcher-1.9.4.jar:7bccea20b41801ca17bcbc909a78c835d0f443f12d639c77bd6ae3d05861608d',
|
||||||
'org.apache.ant:ant:1.9.4:ant-1.9.4.jar:649ae0730251de07b8913f49286d46bba7b92d47c5f332610aa426c4f02161d8',
|
'org.apache.ant:ant:1.9.4:ant-1.9.4.jar:649ae0730251de07b8913f49286d46bba7b92d47c5f332610aa426c4f02161d8',
|
||||||
'org.beanshell:bsh:1.3.0:bsh-1.3.0.jar:9b04edc75d19db54f1b4e8b5355e9364384c6cf71eb0a1b9724c159d779879f8',
|
'org.beanshell:bsh:1.3.0:bsh-1.3.0.jar:9b04edc75d19db54f1b4e8b5355e9364384c6cf71eb0a1b9724c159d779879f8',
|
||||||
'org.briarproject:obfs4proxy:0.0.7:obfs4proxy-0.0.7.zip:5b2f693262ce43a7e130f7cc7d5d1617925330640a2eb6d71085e95df8ee0642',
|
'org.briarproject:obfs4proxy:0.0.12-dev-40245c4a:obfs4proxy-0.0.12-dev-40245c4a.zip:172029e7058b3a83ac93ac4991a44bf76e16ce8d46f558f5836d57da3cb3a766',
|
||||||
'org.briarproject:tor:0.3.5.12:tor-0.3.5.12.zip:2f542c4befd216f2226bf7c76e3b8b2d99af6f146a8cb28bf727f42014587006',
|
'org.briarproject:tor:0.3.5.13:tor-0.3.5.13.zip:1c5f0b821ee2aadb0ea04aa96caab3ca0a08370cce8de81c2dfe04d172f8a2a0',
|
||||||
'org.checkerframework:checker-compat-qual:2.5.3:checker-compat-qual-2.5.3.jar:d76b9afea61c7c082908023f0cbc1427fab9abd2df915c8b8a3e7a509bccbc6d',
|
'org.checkerframework:checker-compat-qual:2.5.3:checker-compat-qual-2.5.3.jar:d76b9afea61c7c082908023f0cbc1427fab9abd2df915c8b8a3e7a509bccbc6d',
|
||||||
'org.checkerframework:checker-qual:2.5.2:checker-qual-2.5.2.jar:64b02691c8b9d4e7700f8ee2e742dce7ea2c6e81e662b7522c9ee3bf568c040a',
|
'org.checkerframework:checker-qual:2.5.2:checker-qual-2.5.2.jar:64b02691c8b9d4e7700f8ee2e742dce7ea2c6e81e662b7522c9ee3bf568c040a',
|
||||||
'org.codehaus.mojo:animal-sniffer-annotations:1.17:animal-sniffer-annotations-1.17.jar:92654f493ecfec52082e76354f0ebf87648dc3d5cec2e3c3cdb947c016747a53',
|
'org.codehaus.mojo:animal-sniffer-annotations:1.17:animal-sniffer-annotations-1.17.jar:92654f493ecfec52082e76354f0ebf87648dc3d5cec2e3c3cdb947c016747a53',
|
||||||
|
|||||||
@@ -22,8 +22,8 @@ android {
|
|||||||
defaultConfig {
|
defaultConfig {
|
||||||
minSdkVersion 16
|
minSdkVersion 16
|
||||||
targetSdkVersion 29
|
targetSdkVersion 29
|
||||||
versionCode 10214
|
versionCode 10216
|
||||||
versionName "1.2.14"
|
versionName "1.2.16"
|
||||||
applicationId "org.briarproject.briar.android"
|
applicationId "org.briarproject.briar.android"
|
||||||
|
|
||||||
vectorDrawables.useSupportLibrary = true
|
vectorDrawables.useSupportLibrary = true
|
||||||
@@ -136,6 +136,7 @@ dependencies {
|
|||||||
testImplementation "org.jmock:jmock:$jmockVersion"
|
testImplementation "org.jmock:jmock:$jmockVersion"
|
||||||
testImplementation "org.jmock:jmock-junit4:$jmockVersion"
|
testImplementation "org.jmock:jmock-junit4:$jmockVersion"
|
||||||
testImplementation "org.jmock:jmock-legacy:$jmockVersion"
|
testImplementation "org.jmock:jmock-legacy:$jmockVersion"
|
||||||
|
testAnnotationProcessor "com.google.dagger:dagger-compiler:2.24"
|
||||||
|
|
||||||
androidTestImplementation project(path: ':bramble-api', configuration: 'testOutput')
|
androidTestImplementation project(path: ':bramble-api', configuration: 'testOutput')
|
||||||
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
|
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package org.briarproject.briar.android;
|
|||||||
import org.briarproject.bramble.BrambleAndroidModule;
|
import org.briarproject.bramble.BrambleAndroidModule;
|
||||||
import org.briarproject.bramble.BrambleCoreModule;
|
import org.briarproject.bramble.BrambleCoreModule;
|
||||||
import org.briarproject.bramble.account.BriarAccountModule;
|
import org.briarproject.bramble.account.BriarAccountModule;
|
||||||
import org.briarproject.bramble.system.ClockModule;
|
|
||||||
import org.briarproject.briar.BriarCoreModule;
|
import org.briarproject.briar.BriarCoreModule;
|
||||||
import org.briarproject.briar.android.attachment.AttachmentModule;
|
import org.briarproject.briar.android.attachment.AttachmentModule;
|
||||||
import org.briarproject.briar.android.attachment.media.MediaModule;
|
import org.briarproject.briar.android.attachment.media.MediaModule;
|
||||||
@@ -17,7 +16,6 @@ import dagger.Component;
|
|||||||
@Component(modules = {
|
@Component(modules = {
|
||||||
AppModule.class,
|
AppModule.class,
|
||||||
AttachmentModule.class,
|
AttachmentModule.class,
|
||||||
ClockModule.class,
|
|
||||||
MediaModule.class,
|
MediaModule.class,
|
||||||
BriarCoreModule.class,
|
BriarCoreModule.class,
|
||||||
BrambleAndroidModule.class,
|
BrambleAndroidModule.class,
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package org.briarproject.briar.android;
|
|||||||
import org.briarproject.bramble.BrambleAndroidModule;
|
import org.briarproject.bramble.BrambleAndroidModule;
|
||||||
import org.briarproject.bramble.BrambleCoreModule;
|
import org.briarproject.bramble.BrambleCoreModule;
|
||||||
import org.briarproject.bramble.account.BriarAccountModule;
|
import org.briarproject.bramble.account.BriarAccountModule;
|
||||||
import org.briarproject.bramble.system.ClockModule;
|
|
||||||
import org.briarproject.briar.BriarCoreModule;
|
import org.briarproject.briar.BriarCoreModule;
|
||||||
import org.briarproject.briar.android.attachment.AttachmentModule;
|
import org.briarproject.briar.android.attachment.AttachmentModule;
|
||||||
import org.briarproject.briar.android.attachment.media.MediaModule;
|
import org.briarproject.briar.android.attachment.media.MediaModule;
|
||||||
@@ -18,7 +17,6 @@ import dagger.Component;
|
|||||||
@Component(modules = {
|
@Component(modules = {
|
||||||
AppModule.class,
|
AppModule.class,
|
||||||
AttachmentModule.class,
|
AttachmentModule.class,
|
||||||
ClockModule.class,
|
|
||||||
MediaModule.class,
|
MediaModule.class,
|
||||||
BriarCoreModule.class,
|
BriarCoreModule.class,
|
||||||
BrambleAndroidModule.class,
|
BrambleAndroidModule.class,
|
||||||
|
|||||||
@@ -29,12 +29,12 @@ import org.briarproject.bramble.api.system.AndroidWakeLockManager;
|
|||||||
import org.briarproject.bramble.api.system.Clock;
|
import org.briarproject.bramble.api.system.Clock;
|
||||||
import org.briarproject.bramble.api.system.LocationUtils;
|
import org.briarproject.bramble.api.system.LocationUtils;
|
||||||
import org.briarproject.bramble.plugin.tor.CircumventionProvider;
|
import org.briarproject.bramble.plugin.tor.CircumventionProvider;
|
||||||
import org.briarproject.bramble.system.ClockModule;
|
|
||||||
import org.briarproject.briar.BriarCoreEagerSingletons;
|
import org.briarproject.briar.BriarCoreEagerSingletons;
|
||||||
import org.briarproject.briar.BriarCoreModule;
|
import org.briarproject.briar.BriarCoreModule;
|
||||||
import org.briarproject.briar.android.attachment.AttachmentModule;
|
import org.briarproject.briar.android.attachment.AttachmentModule;
|
||||||
import org.briarproject.briar.android.attachment.media.MediaModule;
|
import org.briarproject.briar.android.attachment.media.MediaModule;
|
||||||
import org.briarproject.briar.android.conversation.glide.BriarModelLoader;
|
import org.briarproject.briar.android.conversation.glide.BriarModelLoader;
|
||||||
|
import org.briarproject.briar.android.logging.CachingLogHandler;
|
||||||
import org.briarproject.briar.android.login.SignInReminderReceiver;
|
import org.briarproject.briar.android.login.SignInReminderReceiver;
|
||||||
import org.briarproject.briar.android.view.EmojiTextInputView;
|
import org.briarproject.briar.android.view.EmojiTextInputView;
|
||||||
import org.briarproject.briar.api.android.AndroidNotificationManager;
|
import org.briarproject.briar.api.android.AndroidNotificationManager;
|
||||||
@@ -42,7 +42,6 @@ import org.briarproject.briar.api.android.DozeWatchdog;
|
|||||||
import org.briarproject.briar.api.android.LockManager;
|
import org.briarproject.briar.api.android.LockManager;
|
||||||
import org.briarproject.briar.api.android.ScreenFilterMonitor;
|
import org.briarproject.briar.api.android.ScreenFilterMonitor;
|
||||||
import org.briarproject.briar.api.attachment.AttachmentReader;
|
import org.briarproject.briar.api.attachment.AttachmentReader;
|
||||||
import org.briarproject.briar.api.autodelete.AutoDeleteManager;
|
|
||||||
import org.briarproject.briar.api.blog.BlogManager;
|
import org.briarproject.briar.api.blog.BlogManager;
|
||||||
import org.briarproject.briar.api.blog.BlogPostFactory;
|
import org.briarproject.briar.api.blog.BlogPostFactory;
|
||||||
import org.briarproject.briar.api.blog.BlogSharingManager;
|
import org.briarproject.briar.api.blog.BlogSharingManager;
|
||||||
@@ -77,7 +76,6 @@ import dagger.Component;
|
|||||||
BriarAccountModule.class,
|
BriarAccountModule.class,
|
||||||
AppModule.class,
|
AppModule.class,
|
||||||
AttachmentModule.class,
|
AttachmentModule.class,
|
||||||
ClockModule.class,
|
|
||||||
MediaModule.class
|
MediaModule.class
|
||||||
})
|
})
|
||||||
public interface AndroidComponent
|
public interface AndroidComponent
|
||||||
@@ -182,7 +180,9 @@ public interface AndroidComponent
|
|||||||
|
|
||||||
AndroidWakeLockManager wakeLockManager();
|
AndroidWakeLockManager wakeLockManager();
|
||||||
|
|
||||||
AutoDeleteManager autoDeleteManager();
|
CachingLogHandler logHandler();
|
||||||
|
|
||||||
|
Thread.UncaughtExceptionHandler exceptionHandler();
|
||||||
|
|
||||||
void inject(SignInReminderReceiver briarService);
|
void inject(SignInReminderReceiver briarService);
|
||||||
|
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ import org.briarproject.briar.android.account.SetupModule;
|
|||||||
import org.briarproject.briar.android.contact.ContactListModule;
|
import org.briarproject.briar.android.contact.ContactListModule;
|
||||||
import org.briarproject.briar.android.forum.ForumModule;
|
import org.briarproject.briar.android.forum.ForumModule;
|
||||||
import org.briarproject.briar.android.keyagreement.ContactExchangeModule;
|
import org.briarproject.briar.android.keyagreement.ContactExchangeModule;
|
||||||
|
import org.briarproject.briar.android.logging.LoggingModule;
|
||||||
import org.briarproject.briar.android.login.LoginModule;
|
import org.briarproject.briar.android.login.LoginModule;
|
||||||
import org.briarproject.briar.android.navdrawer.NavDrawerModule;
|
import org.briarproject.briar.android.navdrawer.NavDrawerModule;
|
||||||
import org.briarproject.briar.android.privategroup.conversation.GroupConversationModule;
|
import org.briarproject.briar.android.privategroup.conversation.GroupConversationModule;
|
||||||
@@ -68,11 +69,13 @@ import static java.util.Collections.singletonList;
|
|||||||
import static java.util.Collections.singletonMap;
|
import static java.util.Collections.singletonMap;
|
||||||
import static org.briarproject.bramble.api.reporting.ReportingConstants.DEV_ONION_ADDRESS;
|
import static org.briarproject.bramble.api.reporting.ReportingConstants.DEV_ONION_ADDRESS;
|
||||||
import static org.briarproject.bramble.api.reporting.ReportingConstants.DEV_PUBLIC_KEY_HEX;
|
import static org.briarproject.bramble.api.reporting.ReportingConstants.DEV_PUBLIC_KEY_HEX;
|
||||||
|
import static org.briarproject.briar.android.TestingConstants.IS_DEBUG_BUILD;
|
||||||
|
|
||||||
@Module(includes = {
|
@Module(includes = {
|
||||||
SetupModule.class,
|
SetupModule.class,
|
||||||
DozeHelperModule.class,
|
DozeHelperModule.class,
|
||||||
ContactExchangeModule.class,
|
ContactExchangeModule.class,
|
||||||
|
LoggingModule.class,
|
||||||
LoginModule.class,
|
LoginModule.class,
|
||||||
NavDrawerModule.class,
|
NavDrawerModule.class,
|
||||||
ViewModelModule.class,
|
ViewModelModule.class,
|
||||||
@@ -191,6 +194,11 @@ public class AppModule {
|
|||||||
public File getReportDir() {
|
public File getReportDir() {
|
||||||
return AndroidUtils.getReportDir(app.getApplicationContext());
|
return AndroidUtils.getReportDir(app.getApplicationContext());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public File getLogcatFile() {
|
||||||
|
return AndroidUtils.getLogcatFile(app.getApplicationContext());
|
||||||
|
}
|
||||||
};
|
};
|
||||||
return devConfig;
|
return devConfig;
|
||||||
}
|
}
|
||||||
@@ -268,12 +276,12 @@ public class AppModule {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean shouldEnableImageAttachments() {
|
public boolean shouldEnableImageAttachments() {
|
||||||
return false;
|
return IS_DEBUG_BUILD;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean shouldEnableProfilePictures() {
|
public boolean shouldEnableProfilePictures() {
|
||||||
return false;
|
return IS_DEBUG_BUILD;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,9 +6,6 @@ import android.content.SharedPreferences;
|
|||||||
import org.briarproject.bramble.BrambleApplication;
|
import org.briarproject.bramble.BrambleApplication;
|
||||||
import org.briarproject.briar.android.navdrawer.NavDrawerActivity;
|
import org.briarproject.briar.android.navdrawer.NavDrawerActivity;
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.logging.LogRecord;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This exists so that the Application object will not necessarily be cast
|
* This exists so that the Application object will not necessarily be cast
|
||||||
* directly to the Briar application object.
|
* directly to the Briar application object.
|
||||||
@@ -17,8 +14,6 @@ public interface BriarApplication extends BrambleApplication {
|
|||||||
|
|
||||||
Class<? extends Activity> ENTRY_ACTIVITY = NavDrawerActivity.class;
|
Class<? extends Activity> ENTRY_ACTIVITY = NavDrawerActivity.class;
|
||||||
|
|
||||||
Collection<LogRecord> getRecentLogRecords();
|
|
||||||
|
|
||||||
AndroidComponent getApplicationComponent();
|
AndroidComponent getApplicationComponent();
|
||||||
|
|
||||||
SharedPreferences getDefaultSharedPreferences();
|
SharedPreferences getDefaultSharedPreferences();
|
||||||
|
|||||||
@@ -20,12 +20,10 @@ import org.briarproject.bramble.BrambleCoreEagerSingletons;
|
|||||||
import org.briarproject.briar.BriarCoreEagerSingletons;
|
import org.briarproject.briar.BriarCoreEagerSingletons;
|
||||||
import org.briarproject.briar.R;
|
import org.briarproject.briar.R;
|
||||||
import org.briarproject.briar.android.logging.CachingLogHandler;
|
import org.briarproject.briar.android.logging.CachingLogHandler;
|
||||||
import org.briarproject.briar.android.reporting.BriarExceptionHandler;
|
|
||||||
import org.briarproject.briar.android.util.UiUtils;
|
import org.briarproject.briar.android.util.UiUtils;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.lang.Thread.UncaughtExceptionHandler;
|
||||||
import java.util.logging.Handler;
|
import java.util.logging.Handler;
|
||||||
import java.util.logging.LogRecord;
|
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
@@ -42,22 +40,18 @@ public class BriarApplicationImpl extends Application
|
|||||||
private static final Logger LOG =
|
private static final Logger LOG =
|
||||||
getLogger(BriarApplicationImpl.class.getName());
|
getLogger(BriarApplicationImpl.class.getName());
|
||||||
|
|
||||||
private final CachingLogHandler logHandler = new CachingLogHandler();
|
|
||||||
private final BriarExceptionHandler exceptionHandler =
|
|
||||||
new BriarExceptionHandler(this);
|
|
||||||
|
|
||||||
private AndroidComponent applicationComponent;
|
private AndroidComponent applicationComponent;
|
||||||
private volatile SharedPreferences prefs;
|
private volatile SharedPreferences prefs;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void attachBaseContext(Context base) {
|
protected void attachBaseContext(Context base) {
|
||||||
Thread.setDefaultUncaughtExceptionHandler(exceptionHandler);
|
|
||||||
if (prefs == null)
|
if (prefs == null)
|
||||||
prefs = PreferenceManager.getDefaultSharedPreferences(base);
|
prefs = PreferenceManager.getDefaultSharedPreferences(base);
|
||||||
// Loading the language needs to be done here.
|
// Loading the language needs to be done here.
|
||||||
Localizer.initialize(prefs);
|
Localizer.initialize(prefs);
|
||||||
super.attachBaseContext(
|
super.attachBaseContext(
|
||||||
Localizer.getInstance().setLocale(base));
|
Localizer.getInstance().setLocale(base));
|
||||||
|
Localizer.getInstance().setLocale(this);
|
||||||
setTheme(base, prefs);
|
setTheme(base, prefs);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -67,6 +61,11 @@ public class BriarApplicationImpl extends Application
|
|||||||
|
|
||||||
if (IS_DEBUG_BUILD) enableStrictMode();
|
if (IS_DEBUG_BUILD) enableStrictMode();
|
||||||
|
|
||||||
|
applicationComponent = createApplicationComponent();
|
||||||
|
UncaughtExceptionHandler exceptionHandler =
|
||||||
|
applicationComponent.exceptionHandler();
|
||||||
|
Thread.setDefaultUncaughtExceptionHandler(exceptionHandler);
|
||||||
|
|
||||||
Logger rootLogger = getLogger("");
|
Logger rootLogger = getLogger("");
|
||||||
Handler[] handlers = rootLogger.getHandlers();
|
Handler[] handlers = rootLogger.getHandlers();
|
||||||
// Disable the Android logger for release builds
|
// Disable the Android logger for release builds
|
||||||
@@ -78,12 +77,12 @@ public class BriarApplicationImpl extends Application
|
|||||||
// Restore the default handlers after the level raising handler
|
// Restore the default handlers after the level raising handler
|
||||||
for (Handler handler : handlers) rootLogger.addHandler(handler);
|
for (Handler handler : handlers) rootLogger.addHandler(handler);
|
||||||
}
|
}
|
||||||
|
CachingLogHandler logHandler = applicationComponent.logHandler();
|
||||||
rootLogger.addHandler(logHandler);
|
rootLogger.addHandler(logHandler);
|
||||||
rootLogger.setLevel(IS_DEBUG_BUILD ? FINE : INFO);
|
rootLogger.setLevel(IS_DEBUG_BUILD ? FINE : INFO);
|
||||||
|
|
||||||
LOG.info("Created");
|
LOG.info("Created");
|
||||||
|
|
||||||
applicationComponent = createApplicationComponent();
|
|
||||||
EmojiManager.install(new GoogleEmojiProvider());
|
EmojiManager.install(new GoogleEmojiProvider());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -136,11 +135,6 @@ public class BriarApplicationImpl extends Application
|
|||||||
return applicationComponent;
|
return applicationComponent;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public Collection<LogRecord> getRecentLogRecords() {
|
|
||||||
return logHandler.getRecentLogRecords();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AndroidComponent getApplicationComponent() {
|
public AndroidComponent getApplicationComponent() {
|
||||||
return applicationComponent;
|
return applicationComponent;
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ import javax.inject.Inject;
|
|||||||
import androidx.core.app.NotificationCompat;
|
import androidx.core.app.NotificationCompat;
|
||||||
|
|
||||||
import static android.app.NotificationManager.IMPORTANCE_DEFAULT;
|
import static android.app.NotificationManager.IMPORTANCE_DEFAULT;
|
||||||
import static android.app.NotificationManager.IMPORTANCE_NONE;
|
import static android.app.NotificationManager.IMPORTANCE_LOW;
|
||||||
import static android.app.PendingIntent.FLAG_UPDATE_CURRENT;
|
import static android.app.PendingIntent.FLAG_UPDATE_CURRENT;
|
||||||
import static android.content.Intent.ACTION_SHUTDOWN;
|
import static android.content.Intent.ACTION_SHUTDOWN;
|
||||||
import static android.content.Intent.FLAG_ACTIVITY_CLEAR_TASK;
|
import static android.content.Intent.FLAG_ACTIVITY_CLEAR_TASK;
|
||||||
@@ -56,6 +56,7 @@ import static org.briarproject.briar.android.BriarApplication.ENTRY_ACTIVITY;
|
|||||||
import static org.briarproject.briar.api.android.AndroidNotificationManager.FAILURE_CHANNEL_ID;
|
import static org.briarproject.briar.api.android.AndroidNotificationManager.FAILURE_CHANNEL_ID;
|
||||||
import static org.briarproject.briar.api.android.AndroidNotificationManager.FAILURE_NOTIFICATION_ID;
|
import static org.briarproject.briar.api.android.AndroidNotificationManager.FAILURE_NOTIFICATION_ID;
|
||||||
import static org.briarproject.briar.api.android.AndroidNotificationManager.ONGOING_CHANNEL_ID;
|
import static org.briarproject.briar.api.android.AndroidNotificationManager.ONGOING_CHANNEL_ID;
|
||||||
|
import static org.briarproject.briar.api.android.AndroidNotificationManager.ONGOING_CHANNEL_OLD_ID;
|
||||||
import static org.briarproject.briar.api.android.AndroidNotificationManager.ONGOING_NOTIFICATION_ID;
|
import static org.briarproject.briar.api.android.AndroidNotificationManager.ONGOING_NOTIFICATION_ID;
|
||||||
import static org.briarproject.briar.api.android.LockManager.ACTION_LOCK;
|
import static org.briarproject.briar.api.android.LockManager.ACTION_LOCK;
|
||||||
|
|
||||||
@@ -120,11 +121,17 @@ public class BriarService extends Service {
|
|||||||
if (SDK_INT >= 26) {
|
if (SDK_INT >= 26) {
|
||||||
NotificationManager nm = (NotificationManager)
|
NotificationManager nm = (NotificationManager)
|
||||||
requireNonNull(getSystemService(NOTIFICATION_SERVICE));
|
requireNonNull(getSystemService(NOTIFICATION_SERVICE));
|
||||||
|
// Delete the old notification channel, which had
|
||||||
|
// IMPORTANCE_NONE and showed a badge
|
||||||
|
nm.deleteNotificationChannel(ONGOING_CHANNEL_OLD_ID);
|
||||||
|
// Use IMPORTANCE_LOW so the system doesn't show its own
|
||||||
|
// notification on API 26-27
|
||||||
NotificationChannel ongoingChannel = new NotificationChannel(
|
NotificationChannel ongoingChannel = new NotificationChannel(
|
||||||
ONGOING_CHANNEL_ID,
|
ONGOING_CHANNEL_ID,
|
||||||
getString(R.string.ongoing_notification_title),
|
getString(R.string.ongoing_notification_title),
|
||||||
IMPORTANCE_NONE);
|
IMPORTANCE_LOW);
|
||||||
ongoingChannel.setLockscreenVisibility(VISIBILITY_SECRET);
|
ongoingChannel.setLockscreenVisibility(VISIBILITY_SECRET);
|
||||||
|
ongoingChannel.setShowBadge(false);
|
||||||
nm.createNotificationChannel(ongoingChannel);
|
nm.createNotificationChannel(ongoingChannel);
|
||||||
NotificationChannel failureChannel = new NotificationChannel(
|
NotificationChannel failureChannel = new NotificationChannel(
|
||||||
FAILURE_CHANNEL_ID,
|
FAILURE_CHANNEL_ID,
|
||||||
@@ -170,6 +177,7 @@ public class BriarService extends Service {
|
|||||||
@Override
|
@Override
|
||||||
protected void attachBaseContext(Context base) {
|
protected void attachBaseContext(Context base) {
|
||||||
super.attachBaseContext(Localizer.getInstance().setLocale(base));
|
super.attachBaseContext(Localizer.getInstance().setLocale(base));
|
||||||
|
Localizer.getInstance().setLocale(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showStartupFailureNotification(StartResult result) {
|
private void showStartupFailureNotification(StartResult result) {
|
||||||
|
|||||||
@@ -68,7 +68,21 @@ public class Localizer {
|
|||||||
return new Locale(tag);
|
return new Locale(tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns the localized version of context
|
/*
|
||||||
|
* Apply localization to the specified context.
|
||||||
|
*
|
||||||
|
* It updates the configuration of the context's resources object but can
|
||||||
|
* also return a new context derived from the context parameter. Hence
|
||||||
|
* make sure to work with the return value of this method instead of
|
||||||
|
* the context you passed as a parameter.
|
||||||
|
*
|
||||||
|
* This method also has side-effects as it calls Locale#setDefault().
|
||||||
|
*
|
||||||
|
* When using this in attachBaseContext() of Application, Service or
|
||||||
|
* Activity subclasses, it is important to not only apply this method to the
|
||||||
|
* base Context parameter received in that method, but also apply it on the
|
||||||
|
* class itself which also extends Context.
|
||||||
|
*/
|
||||||
public Context setLocale(Context context) {
|
public Context setLocale(Context context) {
|
||||||
Resources res = context.getResources();
|
Resources res = context.getResources();
|
||||||
Configuration conf = res.getConfiguration();
|
Configuration conf = res.getConfiguration();
|
||||||
@@ -82,7 +96,7 @@ public class Localizer {
|
|||||||
Locale.setDefault(locale);
|
Locale.setDefault(locale);
|
||||||
if (SDK_INT >= 17) {
|
if (SDK_INT >= 17) {
|
||||||
conf.setLocale(locale);
|
conf.setLocale(locale);
|
||||||
context.createConfigurationContext(conf);
|
context = context.createConfigurationContext(conf);
|
||||||
} else
|
} else
|
||||||
conf.locale = locale;
|
conf.locale = locale;
|
||||||
//noinspection deprecation
|
//noinspection deprecation
|
||||||
|
|||||||
@@ -27,7 +27,6 @@ import org.briarproject.briar.android.contact.add.remote.NicknameFragment;
|
|||||||
import org.briarproject.briar.android.contact.add.remote.PendingContactListActivity;
|
import org.briarproject.briar.android.contact.add.remote.PendingContactListActivity;
|
||||||
import org.briarproject.briar.android.conversation.AliasDialogFragment;
|
import org.briarproject.briar.android.conversation.AliasDialogFragment;
|
||||||
import org.briarproject.briar.android.conversation.ConversationActivity;
|
import org.briarproject.briar.android.conversation.ConversationActivity;
|
||||||
import org.briarproject.briar.android.conversation.ConversationSettingsDialog;
|
|
||||||
import org.briarproject.briar.android.conversation.ImageActivity;
|
import org.briarproject.briar.android.conversation.ImageActivity;
|
||||||
import org.briarproject.briar.android.conversation.ImageFragment;
|
import org.briarproject.briar.android.conversation.ImageFragment;
|
||||||
import org.briarproject.briar.android.forum.CreateForumActivity;
|
import org.briarproject.briar.android.forum.CreateForumActivity;
|
||||||
@@ -239,6 +238,4 @@ public interface ActivityComponent {
|
|||||||
|
|
||||||
void inject(ConfirmAvatarDialogFragment fragment);
|
void inject(ConfirmAvatarDialogFragment fragment);
|
||||||
|
|
||||||
void inject(ConversationSettingsDialog dialog);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -109,6 +109,7 @@ public abstract class BaseActivity extends AppCompatActivity
|
|||||||
protected void attachBaseContext(Context base) {
|
protected void attachBaseContext(Context base) {
|
||||||
super.attachBaseContext(
|
super.attachBaseContext(
|
||||||
Localizer.getInstance().setLocale(base));
|
Localizer.getInstance().setLocale(base));
|
||||||
|
Localizer.getInstance().setLocale(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ActivityComponent getActivityComponent() {
|
public ActivityComponent getActivityComponent() {
|
||||||
|
|||||||
@@ -20,7 +20,6 @@ import org.briarproject.briar.android.fragment.BaseFragment;
|
|||||||
import org.briarproject.briar.android.view.TextInputView;
|
import org.briarproject.briar.android.view.TextInputView;
|
||||||
import org.briarproject.briar.android.view.TextSendController;
|
import org.briarproject.briar.android.view.TextSendController;
|
||||||
import org.briarproject.briar.android.view.TextSendController.SendListener;
|
import org.briarproject.briar.android.view.TextSendController.SendListener;
|
||||||
import org.briarproject.briar.android.view.TextSendController.SendState;
|
|
||||||
import org.briarproject.briar.api.attachment.AttachmentHeader;
|
import org.briarproject.briar.api.attachment.AttachmentHeader;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -28,9 +27,6 @@ import java.util.List;
|
|||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
import androidx.lifecycle.LiveData;
|
|
||||||
import androidx.lifecycle.MutableLiveData;
|
|
||||||
|
|
||||||
import static android.view.View.FOCUS_DOWN;
|
import static android.view.View.FOCUS_DOWN;
|
||||||
import static android.view.View.GONE;
|
import static android.view.View.GONE;
|
||||||
import static android.view.View.INVISIBLE;
|
import static android.view.View.INVISIBLE;
|
||||||
@@ -38,7 +34,6 @@ import static android.view.View.VISIBLE;
|
|||||||
import static java.util.Objects.requireNonNull;
|
import static java.util.Objects.requireNonNull;
|
||||||
import static org.briarproject.briar.android.activity.BriarActivity.GROUP_ID;
|
import static org.briarproject.briar.android.activity.BriarActivity.GROUP_ID;
|
||||||
import static org.briarproject.briar.android.blog.BasePostFragment.POST_ID;
|
import static org.briarproject.briar.android.blog.BasePostFragment.POST_ID;
|
||||||
import static org.briarproject.briar.android.view.TextSendController.SendState.SENT;
|
|
||||||
import static org.briarproject.briar.api.blog.BlogConstants.MAX_BLOG_POST_TEXT_LENGTH;
|
import static org.briarproject.briar.api.blog.BlogConstants.MAX_BLOG_POST_TEXT_LENGTH;
|
||||||
|
|
||||||
@MethodsNotNullByDefault
|
@MethodsNotNullByDefault
|
||||||
@@ -126,8 +121,8 @@ public class ReblogFragment extends BaseFragment implements SendListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LiveData<SendState> onSendClick(@Nullable String text,
|
public void onSendClick(@Nullable String text,
|
||||||
List<AttachmentHeader> headers, long expectedAutoDeleteTimer) {
|
List<AttachmentHeader> headers) {
|
||||||
ui.input.hideSoftKeyboard();
|
ui.input.hideSoftKeyboard();
|
||||||
feedController.repeatPost(item, text,
|
feedController.repeatPost(item, text,
|
||||||
new UiExceptionHandler<DbException>(this) {
|
new UiExceptionHandler<DbException>(this) {
|
||||||
@@ -137,7 +132,6 @@ public class ReblogFragment extends BaseFragment implements SendListener {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
finish();
|
finish();
|
||||||
return new MutableLiveData<>(SENT);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showProgressBar() {
|
private void showProgressBar() {
|
||||||
|
|||||||
@@ -31,16 +31,12 @@ import java.util.logging.Logger;
|
|||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.lifecycle.LiveData;
|
|
||||||
import androidx.lifecycle.MutableLiveData;
|
|
||||||
|
|
||||||
import static android.view.View.GONE;
|
import static android.view.View.GONE;
|
||||||
import static android.view.View.VISIBLE;
|
import static android.view.View.VISIBLE;
|
||||||
import static java.util.logging.Level.WARNING;
|
import static java.util.logging.Level.WARNING;
|
||||||
import static org.briarproject.bramble.util.LogUtils.logException;
|
import static org.briarproject.bramble.util.LogUtils.logException;
|
||||||
import static org.briarproject.bramble.util.StringUtils.isNullOrEmpty;
|
import static org.briarproject.bramble.util.StringUtils.isNullOrEmpty;
|
||||||
import static org.briarproject.briar.android.view.TextSendController.SendState;
|
|
||||||
import static org.briarproject.briar.android.view.TextSendController.SendState.SENT;
|
|
||||||
import static org.briarproject.briar.api.blog.BlogConstants.MAX_BLOG_POST_TEXT_LENGTH;
|
import static org.briarproject.briar.api.blog.BlogConstants.MAX_BLOG_POST_TEXT_LENGTH;
|
||||||
|
|
||||||
@MethodsNotNullByDefault
|
@MethodsNotNullByDefault
|
||||||
@@ -116,8 +112,8 @@ public class WriteBlogPostActivity extends BriarActivity
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LiveData<SendState> onSendClick(@Nullable String text,
|
public void onSendClick(@Nullable String text,
|
||||||
List<AttachmentHeader> headers, long expectedAutoDeleteTimer) {
|
List<AttachmentHeader> headers) {
|
||||||
if (isNullOrEmpty(text)) throw new AssertionError();
|
if (isNullOrEmpty(text)) throw new AssertionError();
|
||||||
|
|
||||||
// hide publish button, show progress bar
|
// hide publish button, show progress bar
|
||||||
@@ -126,7 +122,6 @@ public class WriteBlogPostActivity extends BriarActivity
|
|||||||
progressBar.setVisibility(VISIBLE);
|
progressBar.setVisibility(VISIBLE);
|
||||||
|
|
||||||
storePost(text);
|
storePost(text);
|
||||||
return new MutableLiveData<>(SENT);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void storePost(String text) {
|
private void storePost(String text) {
|
||||||
|
|||||||
@@ -124,7 +124,7 @@ public class AddContactViewModel extends DbViewModel {
|
|||||||
return addContactResult;
|
return addContactResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updatePendingContact(String name, PendingContact p) {
|
void updatePendingContact(String name, PendingContact p) {
|
||||||
runOnDbThread(() -> {
|
runOnDbThread(() -> {
|
||||||
try {
|
try {
|
||||||
contactManager.removePendingContact(p.getId());
|
contactManager.removePendingContact(p.getId());
|
||||||
|
|||||||
@@ -29,11 +29,11 @@ import org.briarproject.briar.android.fragment.BaseFragment;
|
|||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.StringRes;
|
import androidx.annotation.StringRes;
|
||||||
import androidx.appcompat.app.AlertDialog.Builder;
|
import androidx.appcompat.app.AlertDialog.Builder;
|
||||||
import androidx.lifecycle.LifecycleOwner;
|
import androidx.lifecycle.LifecycleOwner;
|
||||||
import androidx.lifecycle.ViewModelProvider;
|
import androidx.lifecycle.ViewModelProvider;
|
||||||
import androidx.lifecycle.ViewModelProviders;
|
|
||||||
|
|
||||||
import static android.view.View.INVISIBLE;
|
import static android.view.View.INVISIBLE;
|
||||||
import static android.view.View.VISIBLE;
|
import static android.view.View.VISIBLE;
|
||||||
@@ -48,6 +48,7 @@ import static org.briarproject.briar.android.util.UiUtils.getDialogIcon;
|
|||||||
public class NicknameFragment extends BaseFragment {
|
public class NicknameFragment extends BaseFragment {
|
||||||
|
|
||||||
private static final String TAG = NicknameFragment.class.getName();
|
private static final String TAG = NicknameFragment.class.getName();
|
||||||
|
private static final String SAVED_LINK = "savedLink";
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
ViewModelProvider.Factory viewModelFactory;
|
ViewModelProvider.Factory viewModelFactory;
|
||||||
@@ -67,6 +68,20 @@ public class NicknameFragment extends BaseFragment {
|
|||||||
@Override
|
@Override
|
||||||
public void injectFragment(ActivityComponent component) {
|
public void injectFragment(ActivityComponent component) {
|
||||||
component.inject(this);
|
component.inject(this);
|
||||||
|
viewModel = new ViewModelProvider(requireActivity(), viewModelFactory)
|
||||||
|
.get(AddContactViewModel.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
if (savedInstanceState != null) {
|
||||||
|
// When the activity (and the ViewModel) get destroyed,
|
||||||
|
// the link will not be available anymore and needs to be restored.
|
||||||
|
// TODO migrate to SavedStateViewModelFactory (once we can use it)
|
||||||
|
String savedLink = savedInstanceState.getString(SAVED_LINK);
|
||||||
|
if (savedLink != null) viewModel.setRemoteHandshakeLink(savedLink);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@@ -74,14 +89,9 @@ public class NicknameFragment extends BaseFragment {
|
|||||||
public View onCreateView(LayoutInflater inflater,
|
public View onCreateView(LayoutInflater inflater,
|
||||||
@Nullable ViewGroup container,
|
@Nullable ViewGroup container,
|
||||||
@Nullable Bundle savedInstanceState) {
|
@Nullable Bundle savedInstanceState) {
|
||||||
if (getActivity() == null || getContext() == null) return null;
|
|
||||||
|
|
||||||
View v = inflater.inflate(R.layout.fragment_nickname,
|
View v = inflater.inflate(R.layout.fragment_nickname,
|
||||||
container, false);
|
container, false);
|
||||||
|
|
||||||
viewModel = ViewModelProviders.of(getActivity(), viewModelFactory)
|
|
||||||
.get(AddContactViewModel.class);
|
|
||||||
|
|
||||||
contactNameLayout = v.findViewById(R.id.contactNameLayout);
|
contactNameLayout = v.findViewById(R.id.contactNameLayout);
|
||||||
contactNameInput = v.findViewById(R.id.contactNameInput);
|
contactNameInput = v.findViewById(R.id.contactNameInput);
|
||||||
|
|
||||||
@@ -93,6 +103,12 @@ public class NicknameFragment extends BaseFragment {
|
|||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onSaveInstanceState(@NonNull Bundle outState) {
|
||||||
|
super.onSaveInstanceState(outState);
|
||||||
|
outState.putString(SAVED_LINK, viewModel.getRemoteHandshakeLink());
|
||||||
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private String getNicknameOrNull() {
|
private String getNicknameOrNull() {
|
||||||
Editable text = contactNameInput.getText();
|
Editable text = contactNameInput.getText();
|
||||||
|
|||||||
@@ -31,8 +31,6 @@ import static org.briarproject.briar.android.util.UiUtils.showSoftKeyboard;
|
|||||||
|
|
||||||
@MethodsNotNullByDefault
|
@MethodsNotNullByDefault
|
||||||
@ParametersNotNullByDefault
|
@ParametersNotNullByDefault
|
||||||
// TODO: we can probably switch to androidx DialogFragment here but need to
|
|
||||||
// test this properly
|
|
||||||
public class AliasDialogFragment extends AppCompatDialogFragment {
|
public class AliasDialogFragment extends AppCompatDialogFragment {
|
||||||
|
|
||||||
final static String TAG = AliasDialogFragment.class.getName();
|
final static String TAG = AliasDialogFragment.class.getName();
|
||||||
|
|||||||
@@ -50,7 +50,6 @@ import org.briarproject.briar.android.blog.BlogActivity;
|
|||||||
import org.briarproject.briar.android.conversation.ConversationVisitor.AttachmentCache;
|
import org.briarproject.briar.android.conversation.ConversationVisitor.AttachmentCache;
|
||||||
import org.briarproject.briar.android.conversation.ConversationVisitor.TextCache;
|
import org.briarproject.briar.android.conversation.ConversationVisitor.TextCache;
|
||||||
import org.briarproject.briar.android.forum.ForumActivity;
|
import org.briarproject.briar.android.forum.ForumActivity;
|
||||||
import org.briarproject.briar.android.fragment.BaseFragment.BaseFragmentListener;
|
|
||||||
import org.briarproject.briar.android.introduction.IntroductionActivity;
|
import org.briarproject.briar.android.introduction.IntroductionActivity;
|
||||||
import org.briarproject.briar.android.privategroup.conversation.GroupActivity;
|
import org.briarproject.briar.android.privategroup.conversation.GroupActivity;
|
||||||
import org.briarproject.briar.android.util.BriarSnackbarBuilder;
|
import org.briarproject.briar.android.util.BriarSnackbarBuilder;
|
||||||
@@ -60,7 +59,6 @@ import org.briarproject.briar.android.view.TextAttachmentController;
|
|||||||
import org.briarproject.briar.android.view.TextAttachmentController.AttachmentListener;
|
import org.briarproject.briar.android.view.TextAttachmentController.AttachmentListener;
|
||||||
import org.briarproject.briar.android.view.TextInputView;
|
import org.briarproject.briar.android.view.TextInputView;
|
||||||
import org.briarproject.briar.android.view.TextSendController;
|
import org.briarproject.briar.android.view.TextSendController;
|
||||||
import org.briarproject.briar.android.view.TextSendController.SendState;
|
|
||||||
import org.briarproject.briar.api.android.AndroidNotificationManager;
|
import org.briarproject.briar.api.android.AndroidNotificationManager;
|
||||||
import org.briarproject.briar.api.attachment.AttachmentHeader;
|
import org.briarproject.briar.api.attachment.AttachmentHeader;
|
||||||
import org.briarproject.briar.api.blog.BlogSharingManager;
|
import org.briarproject.briar.api.blog.BlogSharingManager;
|
||||||
@@ -140,14 +138,12 @@ import static org.briarproject.briar.android.util.UiUtils.observeOnce;
|
|||||||
import static org.briarproject.briar.android.view.AuthorView.setAvatar;
|
import static org.briarproject.briar.android.view.AuthorView.setAvatar;
|
||||||
import static org.briarproject.briar.api.messaging.MessagingConstants.MAX_ATTACHMENTS_PER_MESSAGE;
|
import static org.briarproject.briar.api.messaging.MessagingConstants.MAX_ATTACHMENTS_PER_MESSAGE;
|
||||||
import static org.briarproject.briar.api.messaging.MessagingConstants.MAX_PRIVATE_MESSAGE_TEXT_LENGTH;
|
import static org.briarproject.briar.api.messaging.MessagingConstants.MAX_PRIVATE_MESSAGE_TEXT_LENGTH;
|
||||||
import static org.briarproject.briar.api.messaging.PrivateMessageFormat.TEXT_IMAGES_AUTO_DELETE;
|
|
||||||
import static org.briarproject.briar.api.messaging.PrivateMessageFormat.TEXT_ONLY;
|
|
||||||
|
|
||||||
@MethodsNotNullByDefault
|
@MethodsNotNullByDefault
|
||||||
@ParametersNotNullByDefault
|
@ParametersNotNullByDefault
|
||||||
public class ConversationActivity extends BriarActivity
|
public class ConversationActivity extends BriarActivity
|
||||||
implements BaseFragmentListener, EventListener, ConversationListener,
|
implements EventListener, ConversationListener, TextCache,
|
||||||
TextCache, AttachmentCache, AttachmentListener, ActionMode.Callback {
|
AttachmentCache, AttachmentListener, ActionMode.Callback {
|
||||||
|
|
||||||
public static final String CONTACT_ID = "briar.CONTACT_ID";
|
public static final String CONTACT_ID = "briar.CONTACT_ID";
|
||||||
|
|
||||||
@@ -272,11 +268,15 @@ public class ConversationActivity extends BriarActivity
|
|||||||
ImagePreview imagePreview = findViewById(R.id.imagePreview);
|
ImagePreview imagePreview = findViewById(R.id.imagePreview);
|
||||||
sendController = new TextAttachmentController(textInputView,
|
sendController = new TextAttachmentController(textInputView,
|
||||||
imagePreview, this, viewModel);
|
imagePreview, this, viewModel);
|
||||||
observeOnce(viewModel.getPrivateMessageFormat(), this, format -> {
|
viewModel.hasImageSupport().observe(this, new Observer<Boolean>() {
|
||||||
if (format != TEXT_ONLY) {
|
@Override
|
||||||
// TODO: remove cast when removing feature flag
|
public void onChanged(@Nullable Boolean hasSupport) {
|
||||||
((TextAttachmentController) sendController)
|
if (hasSupport != null && hasSupport) {
|
||||||
.setImagesSupported();
|
// TODO: remove cast when removing feature flag
|
||||||
|
((TextAttachmentController) sendController)
|
||||||
|
.setImagesSupported();
|
||||||
|
viewModel.hasImageSupport().removeObserver(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
@@ -286,9 +286,6 @@ public class ConversationActivity extends BriarActivity
|
|||||||
textInputView.setMaxTextLength(MAX_PRIVATE_MESSAGE_TEXT_LENGTH);
|
textInputView.setMaxTextLength(MAX_PRIVATE_MESSAGE_TEXT_LENGTH);
|
||||||
textInputView.setReady(false);
|
textInputView.setReady(false);
|
||||||
textInputView.setOnKeyboardShownListener(this::scrollToBottom);
|
textInputView.setOnKeyboardShownListener(this::scrollToBottom);
|
||||||
|
|
||||||
viewModel.getAutoDeleteTimer().observe(this, timer ->
|
|
||||||
sendController.setAutoDeleteTimer(timer));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void scrollToBottom() {
|
private void scrollToBottom() {
|
||||||
@@ -372,12 +369,6 @@ public class ConversationActivity extends BriarActivity
|
|||||||
// enable alias action if available
|
// enable alias action if available
|
||||||
observeOnce(viewModel.getContactItem(), this, contact ->
|
observeOnce(viewModel.getContactItem(), this, contact ->
|
||||||
menu.findItem(R.id.action_set_alias).setEnabled(true));
|
menu.findItem(R.id.action_set_alias).setEnabled(true));
|
||||||
// show auto-delete timer setting only, if contacts supports it
|
|
||||||
observeOnce(viewModel.getPrivateMessageFormat(), this, format -> {
|
|
||||||
boolean visible = format == TEXT_IMAGES_AUTO_DELETE;
|
|
||||||
MenuItem item = menu.findItem(R.id.action_conversation_settings);
|
|
||||||
item.setVisible(visible);
|
|
||||||
});
|
|
||||||
|
|
||||||
return super.onCreateOptionsMenu(menu);
|
return super.onCreateOptionsMenu(menu);
|
||||||
}
|
}
|
||||||
@@ -399,10 +390,6 @@ public class ConversationActivity extends BriarActivity
|
|||||||
AliasDialogFragment.newInstance().show(
|
AliasDialogFragment.newInstance().show(
|
||||||
getSupportFragmentManager(), AliasDialogFragment.TAG);
|
getSupportFragmentManager(), AliasDialogFragment.TAG);
|
||||||
return true;
|
return true;
|
||||||
case R.id.action_conversation_settings:
|
|
||||||
if (contactId == null) return false;
|
|
||||||
onAutoDeleteTimerNoticeClicked();
|
|
||||||
return true;
|
|
||||||
case R.id.action_delete_all_messages:
|
case R.id.action_delete_all_messages:
|
||||||
askToDeleteAllMessages();
|
askToDeleteAllMessages();
|
||||||
return true;
|
return true;
|
||||||
@@ -653,8 +640,8 @@ public class ConversationActivity extends BriarActivity
|
|||||||
supportFinishAfterTransition();
|
supportFinishAfterTransition();
|
||||||
}
|
}
|
||||||
} else if (e instanceof ConversationMessageReceivedEvent) {
|
} else if (e instanceof ConversationMessageReceivedEvent) {
|
||||||
ConversationMessageReceivedEvent<?> p =
|
ConversationMessageReceivedEvent p =
|
||||||
(ConversationMessageReceivedEvent<?>) e;
|
(ConversationMessageReceivedEvent) e;
|
||||||
if (p.getContactId().equals(contactId)) {
|
if (p.getContactId().equals(contactId)) {
|
||||||
LOG.info("Message received, adding");
|
LOG.info("Message received, adding");
|
||||||
onNewConversationMessage(p.getMessageHeader());
|
onNewConversationMessage(p.getMessageHeader());
|
||||||
@@ -748,13 +735,20 @@ public class ConversationActivity extends BriarActivity
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LiveData<SendState> onSendClick(@Nullable String text,
|
public void onSendClick(@Nullable String text,
|
||||||
List<AttachmentHeader> attachmentHeaders,
|
List<AttachmentHeader> attachmentHeaders) {
|
||||||
long expectedAutoDeleteTimer) {
|
|
||||||
if (isNullOrEmpty(text) && attachmentHeaders.isEmpty())
|
if (isNullOrEmpty(text) && attachmentHeaders.isEmpty())
|
||||||
throw new AssertionError();
|
throw new AssertionError();
|
||||||
return viewModel
|
long timestamp = System.currentTimeMillis();
|
||||||
.sendMessage(text, attachmentHeaders, expectedAutoDeleteTimer);
|
timestamp = Math.max(timestamp, getMinTimestampForNewMessage());
|
||||||
|
viewModel.sendMessage(text, attachmentHeaders, timestamp);
|
||||||
|
textInputView.clearText();
|
||||||
|
}
|
||||||
|
|
||||||
|
private long getMinTimestampForNewMessage() {
|
||||||
|
// Don't use an earlier timestamp than the newest message
|
||||||
|
ConversationItem item = adapter.getLastItem();
|
||||||
|
return item == null ? 0 : item.getTime() + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onAddedPrivateMessage(@Nullable PrivateMessageHeader h) {
|
private void onAddedPrivateMessage(@Nullable PrivateMessageHeader h) {
|
||||||
@@ -964,11 +958,13 @@ public class ConversationActivity extends BriarActivity
|
|||||||
adapter.notifyItemChanged(position, item);
|
adapter.notifyItemChanged(position, item);
|
||||||
}
|
}
|
||||||
runOnDbThread(() -> {
|
runOnDbThread(() -> {
|
||||||
|
long timestamp = System.currentTimeMillis();
|
||||||
|
timestamp = Math.max(timestamp, getMinTimestampForNewMessage());
|
||||||
try {
|
try {
|
||||||
switch (item.getRequestType()) {
|
switch (item.getRequestType()) {
|
||||||
case INTRODUCTION:
|
case INTRODUCTION:
|
||||||
respondToIntroductionRequest(item.getSessionId(),
|
respondToIntroductionRequest(item.getSessionId(),
|
||||||
accept);
|
accept, timestamp);
|
||||||
break;
|
break;
|
||||||
case FORUM:
|
case FORUM:
|
||||||
respondToForumRequest(item.getSessionId(), accept);
|
respondToForumRequest(item.getSessionId(), accept);
|
||||||
@@ -1042,18 +1038,11 @@ public class ConversationActivity extends BriarActivity
|
|||||||
ActivityCompat.startActivity(this, i, options.toBundle());
|
ActivityCompat.startActivity(this, i, options.toBundle());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onAutoDeleteTimerNoticeClicked() {
|
|
||||||
ConversationSettingsDialog dialog =
|
|
||||||
ConversationSettingsDialog.newInstance(contactId);
|
|
||||||
dialog.show(getSupportFragmentManager(),
|
|
||||||
ConversationSettingsDialog.TAG);
|
|
||||||
}
|
|
||||||
|
|
||||||
@DatabaseExecutor
|
@DatabaseExecutor
|
||||||
private void respondToIntroductionRequest(SessionId sessionId,
|
private void respondToIntroductionRequest(SessionId sessionId,
|
||||||
boolean accept) throws DbException {
|
boolean accept, long time) throws DbException {
|
||||||
introductionManager.respondToIntroduction(contactId, sessionId, accept);
|
introductionManager.respondToIntroduction(contactId, sessionId, time,
|
||||||
|
accept);
|
||||||
}
|
}
|
||||||
|
|
||||||
@DatabaseExecutor
|
@DatabaseExecutor
|
||||||
|
|||||||
@@ -13,8 +13,6 @@ import org.briarproject.briar.R;
|
|||||||
import org.briarproject.briar.android.util.BriarAdapter;
|
import org.briarproject.briar.android.util.BriarAdapter;
|
||||||
import org.briarproject.briar.android.util.ItemReturningAdapter;
|
import org.briarproject.briar.android.util.ItemReturningAdapter;
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
|
|
||||||
import androidx.annotation.LayoutRes;
|
import androidx.annotation.LayoutRes;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.recyclerview.selection.SelectionTracker;
|
import androidx.recyclerview.selection.SelectionTracker;
|
||||||
@@ -22,14 +20,13 @@ import androidx.recyclerview.widget.LinearLayoutManager;
|
|||||||
import androidx.recyclerview.widget.RecyclerView.RecycledViewPool;
|
import androidx.recyclerview.widget.RecyclerView.RecycledViewPool;
|
||||||
|
|
||||||
import static androidx.recyclerview.widget.RecyclerView.NO_POSITION;
|
import static androidx.recyclerview.widget.RecyclerView.NO_POSITION;
|
||||||
import static org.briarproject.briar.api.autodelete.AutoDeleteConstants.NO_AUTO_DELETE_TIMER;
|
|
||||||
|
|
||||||
@NotNullByDefault
|
@NotNullByDefault
|
||||||
class ConversationAdapter
|
class ConversationAdapter
|
||||||
extends BriarAdapter<ConversationItem, ConversationItemViewHolder>
|
extends BriarAdapter<ConversationItem, ConversationItemViewHolder>
|
||||||
implements ItemReturningAdapter<ConversationItem> {
|
implements ItemReturningAdapter<ConversationItem> {
|
||||||
|
|
||||||
private final ConversationListener listener;
|
private ConversationListener listener;
|
||||||
private final RecycledViewPool imageViewPool;
|
private final RecycledViewPool imageViewPool;
|
||||||
private final ImageItemDecoration imageItemDecoration;
|
private final ImageItemDecoration imageItemDecoration;
|
||||||
@Nullable
|
@Nullable
|
||||||
@@ -68,20 +65,22 @@ class ConversationAdapter
|
|||||||
@LayoutRes int type) {
|
@LayoutRes int type) {
|
||||||
View v = LayoutInflater.from(viewGroup.getContext()).inflate(
|
View v = LayoutInflater.from(viewGroup.getContext()).inflate(
|
||||||
type, viewGroup, false);
|
type, viewGroup, false);
|
||||||
if (type == R.layout.list_item_conversation_msg_in) {
|
switch (type) {
|
||||||
return new ConversationMessageViewHolder(v, listener, true,
|
case R.layout.list_item_conversation_msg_in:
|
||||||
imageViewPool, imageItemDecoration);
|
return new ConversationMessageViewHolder(v, listener, true,
|
||||||
} else if (type == R.layout.list_item_conversation_msg_out) {
|
imageViewPool, imageItemDecoration);
|
||||||
return new ConversationMessageViewHolder(v, listener, false,
|
case R.layout.list_item_conversation_msg_out:
|
||||||
imageViewPool, imageItemDecoration);
|
return new ConversationMessageViewHolder(v, listener, false,
|
||||||
} else if (type == R.layout.list_item_conversation_notice_in) {
|
imageViewPool, imageItemDecoration);
|
||||||
return new ConversationNoticeViewHolder(v, listener, true);
|
case R.layout.list_item_conversation_notice_in:
|
||||||
} else if (type == R.layout.list_item_conversation_notice_out) {
|
return new ConversationNoticeViewHolder(v, listener, true);
|
||||||
return new ConversationNoticeViewHolder(v, listener, false);
|
case R.layout.list_item_conversation_notice_out:
|
||||||
} else if (type == R.layout.list_item_conversation_request) {
|
return new ConversationNoticeViewHolder(v, listener, false);
|
||||||
return new ConversationRequestViewHolder(v, listener, true);
|
case R.layout.list_item_conversation_request:
|
||||||
|
return new ConversationRequestViewHolder(v, listener, true);
|
||||||
|
default:
|
||||||
|
throw new IllegalArgumentException("Unknown ConversationItem");
|
||||||
}
|
}
|
||||||
throw new IllegalArgumentException("Unknown ConversationItem");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -108,49 +107,22 @@ class ConversationAdapter
|
|||||||
return c1.equals(c2);
|
return c1.equals(c2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void add(ConversationItem item) {
|
|
||||||
items.beginBatchedUpdates();
|
|
||||||
items.add(item);
|
|
||||||
updateTimersInBatch();
|
|
||||||
items.endBatchedUpdates();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void addAll(Collection<ConversationItem> itemsToAdd) {
|
|
||||||
items.beginBatchedUpdates();
|
|
||||||
// there can be items already in the adapter
|
|
||||||
// SortedList takes care of duplicates and detecting changed items
|
|
||||||
items.addAll(itemsToAdd);
|
|
||||||
updateTimersInBatch();
|
|
||||||
items.endBatchedUpdates();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updateTimersInBatch() {
|
|
||||||
long lastTimerIncoming = NO_AUTO_DELETE_TIMER;
|
|
||||||
long lastTimerOutgoing = NO_AUTO_DELETE_TIMER;
|
|
||||||
for (int i = 0; i < items.size(); i++) {
|
|
||||||
ConversationItem c = items.get(i);
|
|
||||||
boolean itemChanged;
|
|
||||||
boolean timerChanged;
|
|
||||||
if (c.isIncoming()) {
|
|
||||||
timerChanged = lastTimerIncoming != c.getAutoDeleteTimer();
|
|
||||||
lastTimerIncoming = c.getAutoDeleteTimer();
|
|
||||||
} else {
|
|
||||||
timerChanged = lastTimerOutgoing != c.getAutoDeleteTimer();
|
|
||||||
lastTimerOutgoing = c.getAutoDeleteTimer();
|
|
||||||
}
|
|
||||||
itemChanged = c.setTimerNoticeVisible(timerChanged);
|
|
||||||
if (itemChanged) items.updateItemAt(i, c);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void setSelectionTracker(SelectionTracker<String> tracker) {
|
void setSelectionTracker(SelectionTracker<String> tracker) {
|
||||||
this.tracker = tracker;
|
this.tracker = tracker;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
ConversationItem getLastItem() {
|
||||||
|
if (items.size() > 0) {
|
||||||
|
return items.get(items.size() - 1);
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
SparseArray<ConversationItem> getOutgoingMessages() {
|
SparseArray<ConversationItem> getOutgoingMessages() {
|
||||||
SparseArray<ConversationItem> messages = new SparseArray<>();
|
SparseArray<ConversationItem> messages = new SparseArray<>();
|
||||||
|
|
||||||
for (int i = 0; i < items.size(); i++) {
|
for (int i = 0; i < items.size(); i++) {
|
||||||
ConversationItem item = items.get(i);
|
ConversationItem item = items.get(i);
|
||||||
if (!item.isIncoming()) {
|
if (!item.isIncoming()) {
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ import javax.annotation.Nullable;
|
|||||||
import javax.annotation.concurrent.NotThreadSafe;
|
import javax.annotation.concurrent.NotThreadSafe;
|
||||||
|
|
||||||
import androidx.annotation.LayoutRes;
|
import androidx.annotation.LayoutRes;
|
||||||
import androidx.lifecycle.LiveData;
|
|
||||||
|
|
||||||
import static org.briarproject.bramble.util.StringUtils.toHexString;
|
import static org.briarproject.bramble.util.StringUtils.toHexString;
|
||||||
|
|
||||||
@@ -23,25 +22,20 @@ abstract class ConversationItem {
|
|||||||
protected String text;
|
protected String text;
|
||||||
private final MessageId id;
|
private final MessageId id;
|
||||||
private final GroupId groupId;
|
private final GroupId groupId;
|
||||||
private final long time, autoDeleteTimer;
|
private final long time;
|
||||||
private final boolean isIncoming;
|
private final boolean isIncoming;
|
||||||
private final LiveData<String> contactName;
|
private boolean read, sent, seen;
|
||||||
private boolean read, sent, seen, showTimerNotice;
|
|
||||||
|
|
||||||
ConversationItem(@LayoutRes int layoutRes, ConversationMessageHeader h,
|
ConversationItem(@LayoutRes int layoutRes, ConversationMessageHeader h) {
|
||||||
LiveData<String> contactName) {
|
|
||||||
this.layoutRes = layoutRes;
|
this.layoutRes = layoutRes;
|
||||||
this.text = null;
|
this.text = null;
|
||||||
this.id = h.getId();
|
this.id = h.getId();
|
||||||
this.groupId = h.getGroupId();
|
this.groupId = h.getGroupId();
|
||||||
this.time = h.getTimestamp();
|
this.time = h.getTimestamp();
|
||||||
this.autoDeleteTimer = h.getAutoDeleteTimer();
|
|
||||||
this.read = h.isRead();
|
this.read = h.isRead();
|
||||||
this.sent = h.isSent();
|
this.sent = h.isSent();
|
||||||
this.seen = h.isSeen();
|
this.seen = h.isSeen();
|
||||||
this.isIncoming = !h.isLocal();
|
this.isIncoming = !h.isLocal();
|
||||||
this.contactName = contactName;
|
|
||||||
this.showTimerNotice = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@LayoutRes
|
@LayoutRes
|
||||||
@@ -74,10 +68,6 @@ abstract class ConversationItem {
|
|||||||
return time;
|
return time;
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getAutoDeleteTimer() {
|
|
||||||
return autoDeleteTimer;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Only useful for incoming messages.
|
* Only useful for incoming messages.
|
||||||
*/
|
*/
|
||||||
@@ -121,25 +111,4 @@ abstract class ConversationItem {
|
|||||||
return isIncoming;
|
return isIncoming;
|
||||||
}
|
}
|
||||||
|
|
||||||
public LiveData<String> getContactName() {
|
|
||||||
return contactName;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set this to true when {@link #getAutoDeleteTimer()} has changed
|
|
||||||
* since the last message from the same peer.
|
|
||||||
*
|
|
||||||
* @return true if the value was set, false if it was already set.
|
|
||||||
*/
|
|
||||||
boolean setTimerNoticeVisible(boolean visible) {
|
|
||||||
if (this.showTimerNotice != visible) {
|
|
||||||
this.showTimerNotice = visible;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean isTimerNoticeVisible() {
|
|
||||||
return showTimerNotice;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
package org.briarproject.briar.android.conversation;
|
package org.briarproject.briar.android.conversation;
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.ImageView;
|
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
@@ -14,11 +12,8 @@ import androidx.annotation.UiThread;
|
|||||||
import androidx.constraintlayout.widget.ConstraintLayout;
|
import androidx.constraintlayout.widget.ConstraintLayout;
|
||||||
import androidx.recyclerview.widget.RecyclerView.ViewHolder;
|
import androidx.recyclerview.widget.RecyclerView.ViewHolder;
|
||||||
|
|
||||||
import static android.view.View.GONE;
|
|
||||||
import static android.view.View.VISIBLE;
|
|
||||||
import static org.briarproject.bramble.util.StringUtils.trim;
|
import static org.briarproject.bramble.util.StringUtils.trim;
|
||||||
import static org.briarproject.briar.android.util.UiUtils.formatDate;
|
import static org.briarproject.briar.android.util.UiUtils.formatDate;
|
||||||
import static org.briarproject.briar.api.autodelete.AutoDeleteConstants.NO_AUTO_DELETE_TIMER;
|
|
||||||
|
|
||||||
@UiThread
|
@UiThread
|
||||||
@NotNullByDefault
|
@NotNullByDefault
|
||||||
@@ -29,9 +24,8 @@ abstract class ConversationItemViewHolder extends ViewHolder {
|
|||||||
protected final ConstraintLayout layout;
|
protected final ConstraintLayout layout;
|
||||||
@Nullable
|
@Nullable
|
||||||
private final OutItemViewHolder outViewHolder;
|
private final OutItemViewHolder outViewHolder;
|
||||||
private final TextView topNotice, text;
|
private final TextView text;
|
||||||
protected final TextView time;
|
protected final TextView time;
|
||||||
protected final ImageView bomb;
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private String itemKey = null;
|
private String itemKey = null;
|
||||||
|
|
||||||
@@ -39,13 +33,11 @@ abstract class ConversationItemViewHolder extends ViewHolder {
|
|||||||
boolean isIncoming) {
|
boolean isIncoming) {
|
||||||
super(v);
|
super(v);
|
||||||
this.listener = listener;
|
this.listener = listener;
|
||||||
outViewHolder = isIncoming ? null : new OutItemViewHolder(v);
|
this.outViewHolder = isIncoming ? null : new OutItemViewHolder(v);
|
||||||
root = v;
|
root = v;
|
||||||
topNotice = v.findViewById(R.id.topNotice);
|
|
||||||
layout = v.findViewById(R.id.layout);
|
layout = v.findViewById(R.id.layout);
|
||||||
text = v.findViewById(R.id.text);
|
text = v.findViewById(R.id.text);
|
||||||
time = v.findViewById(R.id.time);
|
time = v.findViewById(R.id.time);
|
||||||
bomb = v.findViewById(R.id.bomb);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@CallSuper
|
@CallSuper
|
||||||
@@ -53,8 +45,6 @@ abstract class ConversationItemViewHolder extends ViewHolder {
|
|||||||
itemKey = item.getKey();
|
itemKey = item.getKey();
|
||||||
root.setActivated(selected);
|
root.setActivated(selected);
|
||||||
|
|
||||||
setTopNotice(item);
|
|
||||||
|
|
||||||
if (item.getText() != null) {
|
if (item.getText() != null) {
|
||||||
text.setText(trim(item.getText()));
|
text.setText(trim(item.getText()));
|
||||||
}
|
}
|
||||||
@@ -62,9 +52,6 @@ abstract class ConversationItemViewHolder extends ViewHolder {
|
|||||||
long timestamp = item.getTime();
|
long timestamp = item.getTime();
|
||||||
time.setText(formatDate(time.getContext(), timestamp));
|
time.setText(formatDate(time.getContext(), timestamp));
|
||||||
|
|
||||||
boolean showBomb = item.getAutoDeleteTimer() != NO_AUTO_DELETE_TIMER;
|
|
||||||
bomb.setVisibility(showBomb ? VISIBLE : GONE);
|
|
||||||
|
|
||||||
if (outViewHolder != null) outViewHolder.bind(item);
|
if (outViewHolder != null) outViewHolder.bind(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -77,31 +64,4 @@ abstract class ConversationItemViewHolder extends ViewHolder {
|
|||||||
return itemKey;
|
return itemKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setTopNotice(ConversationItem item) {
|
|
||||||
if (item.isTimerNoticeVisible()) {
|
|
||||||
Context ctx = itemView.getContext();
|
|
||||||
topNotice.setVisibility(VISIBLE);
|
|
||||||
boolean enabled = item.getAutoDeleteTimer() != NO_AUTO_DELETE_TIMER;
|
|
||||||
String tapToLearnMore = ctx.getString(R.string.tap_to_learn_more);
|
|
||||||
String text;
|
|
||||||
if (item.isIncoming()) {
|
|
||||||
String name = item.getContactName().getValue();
|
|
||||||
int strRes = enabled ?
|
|
||||||
R.string.auto_delete_msg_contact_enabled :
|
|
||||||
R.string.auto_delete_msg_contact_disabled;
|
|
||||||
text = ctx.getString(strRes, name, tapToLearnMore);
|
|
||||||
} else {
|
|
||||||
int strRes = enabled ?
|
|
||||||
R.string.auto_delete_msg_you_enabled :
|
|
||||||
R.string.auto_delete_msg_you_disabled;
|
|
||||||
text = ctx.getString(strRes, tapToLearnMore);
|
|
||||||
}
|
|
||||||
topNotice.setText(text);
|
|
||||||
topNotice.setOnClickListener(
|
|
||||||
v -> listener.onAutoDeleteTimerNoticeClicked());
|
|
||||||
} else {
|
|
||||||
topNotice.setVisibility(GONE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,6 +18,4 @@ interface ConversationListener {
|
|||||||
void onAttachmentClicked(View view, ConversationMessageItem messageItem,
|
void onAttachmentClicked(View view, ConversationMessageItem messageItem,
|
||||||
AttachmentItem attachmentItem);
|
AttachmentItem attachmentItem);
|
||||||
|
|
||||||
void onAutoDeleteTimerNoticeClicked();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ import javax.annotation.concurrent.NotThreadSafe;
|
|||||||
|
|
||||||
import androidx.annotation.LayoutRes;
|
import androidx.annotation.LayoutRes;
|
||||||
import androidx.annotation.UiThread;
|
import androidx.annotation.UiThread;
|
||||||
import androidx.lifecycle.LiveData;
|
|
||||||
|
|
||||||
@NotThreadSafe
|
@NotThreadSafe
|
||||||
@NotNullByDefault
|
@NotNullByDefault
|
||||||
@@ -19,8 +18,8 @@ class ConversationMessageItem extends ConversationItem {
|
|||||||
private final List<AttachmentItem> attachments;
|
private final List<AttachmentItem> attachments;
|
||||||
|
|
||||||
ConversationMessageItem(@LayoutRes int layoutRes, PrivateMessageHeader h,
|
ConversationMessageItem(@LayoutRes int layoutRes, PrivateMessageHeader h,
|
||||||
LiveData<String> contactName, List<AttachmentItem> attachments) {
|
List<AttachmentItem> attachments) {
|
||||||
super(layoutRes, h, contactName);
|
super(layoutRes, h);
|
||||||
this.attachments = attachments;
|
this.attachments = attachments;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package org.briarproject.briar.android.conversation;
|
package org.briarproject.briar.android.conversation;
|
||||||
|
|
||||||
import android.content.res.ColorStateList;
|
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
|
||||||
@@ -15,7 +14,6 @@ import androidx.recyclerview.widget.RecyclerView.RecycledViewPool;
|
|||||||
|
|
||||||
import static androidx.constraintlayout.widget.ConstraintSet.WRAP_CONTENT;
|
import static androidx.constraintlayout.widget.ConstraintSet.WRAP_CONTENT;
|
||||||
import static androidx.core.content.ContextCompat.getColor;
|
import static androidx.core.content.ContextCompat.getColor;
|
||||||
import static androidx.core.widget.ImageViewCompat.setImageTintList;
|
|
||||||
|
|
||||||
@UiThread
|
@UiThread
|
||||||
@NotNullByDefault
|
@NotNullByDefault
|
||||||
@@ -86,7 +84,6 @@ class ConversationMessageViewHolder extends ConversationItemViewHolder {
|
|||||||
if (item.getText() == null) {
|
if (item.getText() == null) {
|
||||||
statusLayout.setBackgroundResource(R.drawable.msg_status_bubble);
|
statusLayout.setBackgroundResource(R.drawable.msg_status_bubble);
|
||||||
time.setTextColor(timeColorBubble);
|
time.setTextColor(timeColorBubble);
|
||||||
setImageTintList(bomb, ColorStateList.valueOf(timeColorBubble));
|
|
||||||
constraintSet = imageConstraints;
|
constraintSet = imageConstraints;
|
||||||
} else {
|
} else {
|
||||||
resetStatusLayoutForText();
|
resetStatusLayoutForText();
|
||||||
@@ -114,7 +111,6 @@ class ConversationMessageViewHolder extends ConversationItemViewHolder {
|
|||||||
// also reset padding (the background drawable defines some)
|
// also reset padding (the background drawable defines some)
|
||||||
statusLayout.setPadding(0, 0, 0, 0);
|
statusLayout.setPadding(0, 0, 0, 0);
|
||||||
time.setTextColor(timeColor);
|
time.setTextColor(timeColor);
|
||||||
setImageTintList(bomb, ColorStateList.valueOf(timeColor));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import javax.annotation.Nullable;
|
|||||||
import javax.annotation.concurrent.NotThreadSafe;
|
import javax.annotation.concurrent.NotThreadSafe;
|
||||||
|
|
||||||
import androidx.annotation.LayoutRes;
|
import androidx.annotation.LayoutRes;
|
||||||
import androidx.lifecycle.LiveData;
|
|
||||||
|
|
||||||
@NotThreadSafe
|
@NotThreadSafe
|
||||||
@NotNullByDefault
|
@NotNullByDefault
|
||||||
@@ -18,15 +17,15 @@ class ConversationNoticeItem extends ConversationItem {
|
|||||||
private final String msgText;
|
private final String msgText;
|
||||||
|
|
||||||
ConversationNoticeItem(@LayoutRes int layoutRes, String text,
|
ConversationNoticeItem(@LayoutRes int layoutRes, String text,
|
||||||
LiveData<String> contactName, ConversationRequest<?> r) {
|
ConversationRequest r) {
|
||||||
super(layoutRes, r, contactName);
|
super(layoutRes, r);
|
||||||
this.text = text;
|
this.text = text;
|
||||||
this.msgText = r.getText();
|
this.msgText = r.getText();
|
||||||
}
|
}
|
||||||
|
|
||||||
ConversationNoticeItem(@LayoutRes int layoutRes, String text,
|
ConversationNoticeItem(@LayoutRes int layoutRes, String text,
|
||||||
LiveData<String> contactName, ConversationResponse r) {
|
ConversationResponse r) {
|
||||||
super(layoutRes, r, contactName);
|
super(layoutRes, r);
|
||||||
this.text = text;
|
this.text = text;
|
||||||
this.msgText = null;
|
this.msgText = null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ import javax.annotation.Nullable;
|
|||||||
import javax.annotation.concurrent.NotThreadSafe;
|
import javax.annotation.concurrent.NotThreadSafe;
|
||||||
|
|
||||||
import androidx.annotation.LayoutRes;
|
import androidx.annotation.LayoutRes;
|
||||||
import androidx.lifecycle.LiveData;
|
|
||||||
|
|
||||||
@NotThreadSafe
|
@NotThreadSafe
|
||||||
@NotNullByDefault
|
@NotNullByDefault
|
||||||
@@ -27,15 +26,14 @@ class ConversationRequestItem extends ConversationNoticeItem {
|
|||||||
private boolean answered;
|
private boolean answered;
|
||||||
|
|
||||||
ConversationRequestItem(@LayoutRes int layoutRes, String text,
|
ConversationRequestItem(@LayoutRes int layoutRes, String text,
|
||||||
LiveData<String> contactName, RequestType type,
|
RequestType type, ConversationRequest r) {
|
||||||
ConversationRequest<?> r) {
|
super(layoutRes, text, r);
|
||||||
super(layoutRes, text, contactName, r);
|
|
||||||
this.requestType = type;
|
this.requestType = type;
|
||||||
this.sessionId = r.getSessionId();
|
this.sessionId = r.getSessionId();
|
||||||
this.answered = r.wasAnswered();
|
this.answered = r.wasAnswered();
|
||||||
if (r instanceof InvitationRequest) {
|
if (r instanceof InvitationRequest) {
|
||||||
this.requestedGroupId = ((Shareable) r.getNameable()).getId();
|
this.requestedGroupId = ((Shareable) r.getNameable()).getId();
|
||||||
this.canBeOpened = ((InvitationRequest<?>) r).canBeOpened();
|
this.canBeOpened = ((InvitationRequest) r).canBeOpened();
|
||||||
} else {
|
} else {
|
||||||
this.requestedGroupId = null;
|
this.requestedGroupId = null;
|
||||||
this.canBeOpened = false;
|
this.canBeOpened = false;
|
||||||
|
|||||||
@@ -1,122 +0,0 @@
|
|||||||
package org.briarproject.briar.android.conversation;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.os.Bundle;
|
|
||||||
import android.view.LayoutInflater;
|
|
||||||
import android.view.View;
|
|
||||||
import android.view.ViewGroup;
|
|
||||||
import android.widget.TextView;
|
|
||||||
|
|
||||||
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.fragment.BaseFragment;
|
|
||||||
|
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
import javax.inject.Inject;
|
|
||||||
|
|
||||||
import androidx.annotation.Nullable;
|
|
||||||
import androidx.appcompat.widget.SwitchCompat;
|
|
||||||
import androidx.appcompat.widget.Toolbar;
|
|
||||||
import androidx.fragment.app.DialogFragment;
|
|
||||||
import androidx.fragment.app.FragmentActivity;
|
|
||||||
import androidx.lifecycle.ViewModelProvider;
|
|
||||||
|
|
||||||
import static org.briarproject.briar.android.conversation.ConversationActivity.CONTACT_ID;
|
|
||||||
import static org.briarproject.briar.api.autodelete.AutoDeleteConstants.NO_AUTO_DELETE_TIMER;
|
|
||||||
|
|
||||||
@MethodsNotNullByDefault
|
|
||||||
@ParametersNotNullByDefault
|
|
||||||
public class ConversationSettingsDialog extends DialogFragment {
|
|
||||||
|
|
||||||
final static String TAG = ConversationSettingsDialog.class.getName();
|
|
||||||
|
|
||||||
private static final Logger LOG = Logger.getLogger(TAG);
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
ViewModelProvider.Factory viewModelFactory;
|
|
||||||
|
|
||||||
private ConversationViewModel viewModel;
|
|
||||||
|
|
||||||
static ConversationSettingsDialog newInstance(ContactId contactId) {
|
|
||||||
Bundle args = new Bundle();
|
|
||||||
args.putInt(CONTACT_ID, contactId.getInt());
|
|
||||||
ConversationSettingsDialog dialog = new ConversationSettingsDialog();
|
|
||||||
dialog.setArguments(args);
|
|
||||||
return dialog;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onAttach(Context context) {
|
|
||||||
super.onAttach(context);
|
|
||||||
injectFragment(((BaseFragment.BaseFragmentListener) context)
|
|
||||||
.getActivityComponent());
|
|
||||||
}
|
|
||||||
|
|
||||||
public void injectFragment(ActivityComponent component) {
|
|
||||||
component.inject(this);
|
|
||||||
viewModel = new ViewModelProvider(requireActivity(), viewModelFactory)
|
|
||||||
.get(ConversationViewModel.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
|
||||||
super.onCreate(savedInstanceState);
|
|
||||||
setStyle(DialogFragment.STYLE_NO_FRAME,
|
|
||||||
R.style.BriarFullScreenDialogTheme);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
@Override
|
|
||||||
public View onCreateView(LayoutInflater inflater,
|
|
||||||
@Nullable ViewGroup container,
|
|
||||||
@Nullable Bundle savedInstanceState) {
|
|
||||||
View view = inflater.inflate(R.layout.fragment_conversation_settings,
|
|
||||||
container, false);
|
|
||||||
|
|
||||||
Bundle args = requireArguments();
|
|
||||||
int id = args.getInt(CONTACT_ID, -1);
|
|
||||||
if (id == -1) throw new IllegalStateException();
|
|
||||||
ContactId contactId = new ContactId(id);
|
|
||||||
|
|
||||||
FragmentActivity activity = requireActivity();
|
|
||||||
viewModel = new ViewModelProvider(activity, viewModelFactory)
|
|
||||||
.get(ConversationViewModel.class);
|
|
||||||
viewModel.setContactId(contactId);
|
|
||||||
|
|
||||||
Toolbar toolbar = view.findViewById(R.id.toolbar);
|
|
||||||
toolbar.setNavigationOnClickListener(v -> dismiss());
|
|
||||||
|
|
||||||
SwitchCompat switchDisappearingMessages = view.findViewById(
|
|
||||||
R.id.switchDisappearingMessages);
|
|
||||||
switchDisappearingMessages.setOnCheckedChangeListener(
|
|
||||||
(button, value) -> viewModel.setAutoDeleteTimerEnabled(value));
|
|
||||||
|
|
||||||
TextView buttonLearnMore =
|
|
||||||
view.findViewById(R.id.buttonLearnMore);
|
|
||||||
buttonLearnMore.setOnClickListener(e -> showLearnMoreDialog());
|
|
||||||
|
|
||||||
viewModel.getAutoDeleteTimer()
|
|
||||||
.observe(getViewLifecycleOwner(), timer -> {
|
|
||||||
LOG.info("Received auto delete timer: " + timer);
|
|
||||||
boolean disappearingMessages =
|
|
||||||
timer != NO_AUTO_DELETE_TIMER;
|
|
||||||
switchDisappearingMessages
|
|
||||||
.setChecked(disappearingMessages);
|
|
||||||
switchDisappearingMessages.setEnabled(true);
|
|
||||||
});
|
|
||||||
|
|
||||||
return view;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void showLearnMoreDialog() {
|
|
||||||
ConversationSettingsLearnMoreDialog
|
|
||||||
dialog = new ConversationSettingsLearnMoreDialog();
|
|
||||||
dialog.show(getChildFragmentManager(),
|
|
||||||
ConversationSettingsLearnMoreDialog.TAG);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,43 +0,0 @@
|
|||||||
package org.briarproject.briar.android.conversation;
|
|
||||||
|
|
||||||
import android.app.Dialog;
|
|
||||||
import android.os.Bundle;
|
|
||||||
import android.view.LayoutInflater;
|
|
||||||
import android.view.View;
|
|
||||||
|
|
||||||
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
|
|
||||||
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
|
||||||
import org.briarproject.briar.R;
|
|
||||||
|
|
||||||
import androidx.annotation.Nullable;
|
|
||||||
import androidx.appcompat.app.AlertDialog;
|
|
||||||
import androidx.fragment.app.DialogFragment;
|
|
||||||
import androidx.fragment.app.FragmentActivity;
|
|
||||||
|
|
||||||
@MethodsNotNullByDefault
|
|
||||||
@ParametersNotNullByDefault
|
|
||||||
public class ConversationSettingsLearnMoreDialog extends DialogFragment {
|
|
||||||
|
|
||||||
final static String TAG =
|
|
||||||
ConversationSettingsLearnMoreDialog.class.getName();
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
|
|
||||||
FragmentActivity activity = requireActivity();
|
|
||||||
|
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(activity,
|
|
||||||
R.style.OnboardingDialogTheme);
|
|
||||||
|
|
||||||
LayoutInflater inflater = LayoutInflater.from(builder.getContext());
|
|
||||||
View view = inflater.inflate(
|
|
||||||
R.layout.fragment_conversation_settings_learn_more, null);
|
|
||||||
builder.setView(view);
|
|
||||||
|
|
||||||
builder.setTitle(R.string.disappearing_messages_title);
|
|
||||||
builder.setPositiveButton(R.string.ok, null);
|
|
||||||
|
|
||||||
return builder.create();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -10,7 +10,6 @@ import org.briarproject.bramble.api.contact.ContactManager;
|
|||||||
import org.briarproject.bramble.api.db.DatabaseExecutor;
|
import org.briarproject.bramble.api.db.DatabaseExecutor;
|
||||||
import org.briarproject.bramble.api.db.DbException;
|
import org.briarproject.bramble.api.db.DbException;
|
||||||
import org.briarproject.bramble.api.db.NoSuchContactException;
|
import org.briarproject.bramble.api.db.NoSuchContactException;
|
||||||
import org.briarproject.bramble.api.db.Transaction;
|
|
||||||
import org.briarproject.bramble.api.db.TransactionManager;
|
import org.briarproject.bramble.api.db.TransactionManager;
|
||||||
import org.briarproject.bramble.api.event.Event;
|
import org.briarproject.bramble.api.event.Event;
|
||||||
import org.briarproject.bramble.api.event.EventBus;
|
import org.briarproject.bramble.api.event.EventBus;
|
||||||
@@ -29,22 +28,16 @@ import org.briarproject.briar.android.attachment.AttachmentResult;
|
|||||||
import org.briarproject.briar.android.attachment.AttachmentRetriever;
|
import org.briarproject.briar.android.attachment.AttachmentRetriever;
|
||||||
import org.briarproject.briar.android.contact.ContactItem;
|
import org.briarproject.briar.android.contact.ContactItem;
|
||||||
import org.briarproject.briar.android.util.UiUtils;
|
import org.briarproject.briar.android.util.UiUtils;
|
||||||
import org.briarproject.briar.android.view.TextSendController.SendState;
|
|
||||||
import org.briarproject.briar.android.viewmodel.DbViewModel;
|
import org.briarproject.briar.android.viewmodel.DbViewModel;
|
||||||
import org.briarproject.briar.android.viewmodel.LiveEvent;
|
import org.briarproject.briar.android.viewmodel.LiveEvent;
|
||||||
import org.briarproject.briar.android.viewmodel.MutableLiveEvent;
|
import org.briarproject.briar.android.viewmodel.MutableLiveEvent;
|
||||||
import org.briarproject.briar.api.attachment.AttachmentHeader;
|
import org.briarproject.briar.api.attachment.AttachmentHeader;
|
||||||
import org.briarproject.briar.api.autodelete.AutoDeleteManager;
|
|
||||||
import org.briarproject.briar.api.autodelete.UnexpectedTimerException;
|
|
||||||
import org.briarproject.briar.api.autodelete.event.AutoDeleteTimerMirroredEvent;
|
|
||||||
import org.briarproject.briar.api.avatar.event.AvatarUpdatedEvent;
|
import org.briarproject.briar.api.avatar.event.AvatarUpdatedEvent;
|
||||||
import org.briarproject.briar.api.conversation.ConversationManager;
|
|
||||||
import org.briarproject.briar.api.identity.AuthorInfo;
|
import org.briarproject.briar.api.identity.AuthorInfo;
|
||||||
import org.briarproject.briar.api.identity.AuthorManager;
|
import org.briarproject.briar.api.identity.AuthorManager;
|
||||||
import org.briarproject.briar.api.messaging.MessagingManager;
|
import org.briarproject.briar.api.messaging.MessagingManager;
|
||||||
import org.briarproject.briar.api.messaging.PrivateMessage;
|
import org.briarproject.briar.api.messaging.PrivateMessage;
|
||||||
import org.briarproject.briar.api.messaging.PrivateMessageFactory;
|
import org.briarproject.briar.api.messaging.PrivateMessageFactory;
|
||||||
import org.briarproject.briar.api.messaging.PrivateMessageFormat;
|
|
||||||
import org.briarproject.briar.api.messaging.PrivateMessageHeader;
|
import org.briarproject.briar.api.messaging.PrivateMessageHeader;
|
||||||
import org.briarproject.briar.api.messaging.event.AttachmentReceivedEvent;
|
import org.briarproject.briar.api.messaging.event.AttachmentReceivedEvent;
|
||||||
|
|
||||||
@@ -62,8 +55,6 @@ import androidx.lifecycle.MutableLiveData;
|
|||||||
|
|
||||||
import static androidx.lifecycle.Transformations.map;
|
import static androidx.lifecycle.Transformations.map;
|
||||||
import static java.util.Objects.requireNonNull;
|
import static java.util.Objects.requireNonNull;
|
||||||
import static java.util.concurrent.TimeUnit.DAYS;
|
|
||||||
import static java.util.logging.Level.INFO;
|
|
||||||
import static java.util.logging.Level.WARNING;
|
import static java.util.logging.Level.WARNING;
|
||||||
import static java.util.logging.Logger.getLogger;
|
import static java.util.logging.Logger.getLogger;
|
||||||
import static org.briarproject.bramble.util.LogUtils.logDuration;
|
import static org.briarproject.bramble.util.LogUtils.logDuration;
|
||||||
@@ -71,12 +62,6 @@ import static org.briarproject.bramble.util.LogUtils.logException;
|
|||||||
import static org.briarproject.bramble.util.LogUtils.now;
|
import static org.briarproject.bramble.util.LogUtils.now;
|
||||||
import static org.briarproject.briar.android.settings.SettingsFragment.SETTINGS_NAMESPACE;
|
import static org.briarproject.briar.android.settings.SettingsFragment.SETTINGS_NAMESPACE;
|
||||||
import static org.briarproject.briar.android.util.UiUtils.observeForeverOnce;
|
import static org.briarproject.briar.android.util.UiUtils.observeForeverOnce;
|
||||||
import static org.briarproject.briar.android.view.TextSendController.SendState.ERROR;
|
|
||||||
import static org.briarproject.briar.android.view.TextSendController.SendState.SENT;
|
|
||||||
import static org.briarproject.briar.android.view.TextSendController.SendState.UNEXPECTED_TIMER;
|
|
||||||
import static org.briarproject.briar.api.autodelete.AutoDeleteConstants.NO_AUTO_DELETE_TIMER;
|
|
||||||
import static org.briarproject.briar.api.messaging.PrivateMessageFormat.TEXT_IMAGES;
|
|
||||||
import static org.briarproject.briar.api.messaging.PrivateMessageFormat.TEXT_ONLY;
|
|
||||||
|
|
||||||
@NotNullByDefault
|
@NotNullByDefault
|
||||||
public class ConversationViewModel extends DbViewModel
|
public class ConversationViewModel extends DbViewModel
|
||||||
@@ -99,8 +84,6 @@ public class ConversationViewModel extends DbViewModel
|
|||||||
private final PrivateMessageFactory privateMessageFactory;
|
private final PrivateMessageFactory privateMessageFactory;
|
||||||
private final AttachmentRetriever attachmentRetriever;
|
private final AttachmentRetriever attachmentRetriever;
|
||||||
private final AttachmentCreator attachmentCreator;
|
private final AttachmentCreator attachmentCreator;
|
||||||
private final AutoDeleteManager autoDeleteManager;
|
|
||||||
private final ConversationManager conversationManager;
|
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private ContactId contactId = null;
|
private ContactId contactId = null;
|
||||||
@@ -109,7 +92,7 @@ public class ConversationViewModel extends DbViewModel
|
|||||||
private final LiveData<String> contactName = map(contactItem, c ->
|
private final LiveData<String> contactName = map(contactItem, c ->
|
||||||
UiUtils.getContactDisplayName(c.getContact()));
|
UiUtils.getContactDisplayName(c.getContact()));
|
||||||
private final LiveData<GroupId> messagingGroupId;
|
private final LiveData<GroupId> messagingGroupId;
|
||||||
private final MutableLiveData<PrivateMessageFormat> privateMessageFormat =
|
private final MutableLiveData<Boolean> imageSupport =
|
||||||
new MutableLiveData<>();
|
new MutableLiveData<>();
|
||||||
private final MutableLiveEvent<Boolean> showImageOnboarding =
|
private final MutableLiveEvent<Boolean> showImageOnboarding =
|
||||||
new MutableLiveEvent<>();
|
new MutableLiveEvent<>();
|
||||||
@@ -117,10 +100,8 @@ public class ConversationViewModel extends DbViewModel
|
|||||||
new MutableLiveEvent<>();
|
new MutableLiveEvent<>();
|
||||||
private final MutableLiveData<Boolean> showIntroductionAction =
|
private final MutableLiveData<Boolean> showIntroductionAction =
|
||||||
new MutableLiveData<>();
|
new MutableLiveData<>();
|
||||||
private final MutableLiveData<Long> autoDeleteTimer =
|
|
||||||
new MutableLiveData<>();
|
|
||||||
private final MutableLiveData<Boolean> contactDeleted =
|
private final MutableLiveData<Boolean> contactDeleted =
|
||||||
new MutableLiveData<>(false);
|
new MutableLiveData<>();
|
||||||
private final MutableLiveEvent<PrivateMessageHeader> addedHeader =
|
private final MutableLiveEvent<PrivateMessageHeader> addedHeader =
|
||||||
new MutableLiveEvent<>();
|
new MutableLiveEvent<>();
|
||||||
|
|
||||||
@@ -137,9 +118,7 @@ public class ConversationViewModel extends DbViewModel
|
|||||||
SettingsManager settingsManager,
|
SettingsManager settingsManager,
|
||||||
PrivateMessageFactory privateMessageFactory,
|
PrivateMessageFactory privateMessageFactory,
|
||||||
AttachmentRetriever attachmentRetriever,
|
AttachmentRetriever attachmentRetriever,
|
||||||
AttachmentCreator attachmentCreator,
|
AttachmentCreator attachmentCreator) {
|
||||||
AutoDeleteManager autoDeleteManager,
|
|
||||||
ConversationManager conversationManager) {
|
|
||||||
super(application, dbExecutor, lifecycleManager, db, androidExecutor);
|
super(application, dbExecutor, lifecycleManager, db, androidExecutor);
|
||||||
this.db = db;
|
this.db = db;
|
||||||
this.eventBus = eventBus;
|
this.eventBus = eventBus;
|
||||||
@@ -150,10 +129,10 @@ public class ConversationViewModel extends DbViewModel
|
|||||||
this.privateMessageFactory = privateMessageFactory;
|
this.privateMessageFactory = privateMessageFactory;
|
||||||
this.attachmentRetriever = attachmentRetriever;
|
this.attachmentRetriever = attachmentRetriever;
|
||||||
this.attachmentCreator = attachmentCreator;
|
this.attachmentCreator = attachmentCreator;
|
||||||
this.autoDeleteManager = autoDeleteManager;
|
|
||||||
this.conversationManager = conversationManager;
|
|
||||||
messagingGroupId = map(contactItem, c ->
|
messagingGroupId = map(contactItem, c ->
|
||||||
messagingManager.getContactGroup(c.getContact()).getId());
|
messagingManager.getContactGroup(c.getContact()).getId());
|
||||||
|
contactDeleted.setValue(false);
|
||||||
|
|
||||||
eventBus.addListener(this);
|
eventBus.addListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -173,11 +152,6 @@ public class ConversationViewModel extends DbViewModel
|
|||||||
runOnDbThread(() -> attachmentRetriever
|
runOnDbThread(() -> attachmentRetriever
|
||||||
.loadAttachmentItem(a.getMessageId()));
|
.loadAttachmentItem(a.getMessageId()));
|
||||||
}
|
}
|
||||||
} else if (e instanceof AutoDeleteTimerMirroredEvent) {
|
|
||||||
AutoDeleteTimerMirroredEvent a = (AutoDeleteTimerMirroredEvent) e;
|
|
||||||
if (a.getContactId().equals(contactId)) {
|
|
||||||
autoDeleteTimer.postValue(a.getNewTimer());
|
|
||||||
}
|
|
||||||
} else if (e instanceof AvatarUpdatedEvent) {
|
} else if (e instanceof AvatarUpdatedEvent) {
|
||||||
AvatarUpdatedEvent a = (AvatarUpdatedEvent) e;
|
AvatarUpdatedEvent a = (AvatarUpdatedEvent) e;
|
||||||
if (a.getContactId().equals(contactId)) {
|
if (a.getContactId().equals(contactId)) {
|
||||||
@@ -227,11 +201,6 @@ public class ConversationViewModel extends DbViewModel
|
|||||||
contactItem.postValue(new ContactItem(c, authorInfo));
|
contactItem.postValue(new ContactItem(c, authorInfo));
|
||||||
logDuration(LOG, "Loading contact", start);
|
logDuration(LOG, "Loading contact", start);
|
||||||
start = now();
|
start = now();
|
||||||
long timer = db.transactionWithResult(true, txn ->
|
|
||||||
autoDeleteManager.getAutoDeleteTimer(txn, contactId));
|
|
||||||
autoDeleteTimer.postValue(timer);
|
|
||||||
logDuration(LOG, "Getting auto-delete timer", start);
|
|
||||||
start = now();
|
|
||||||
checkFeaturesAndOnboarding(contactId);
|
checkFeaturesAndOnboarding(contactId);
|
||||||
logDuration(LOG, "Checking for image support", start);
|
logDuration(LOG, "Checking for image support", start);
|
||||||
} catch (NoSuchContactException e) {
|
} catch (NoSuchContactException e) {
|
||||||
@@ -266,6 +235,20 @@ public class ConversationViewModel extends DbViewModel
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@UiThread
|
||||||
|
void sendMessage(@Nullable String text,
|
||||||
|
List<AttachmentHeader> headers, long timestamp) {
|
||||||
|
// messagingGroupId is loaded with the contact
|
||||||
|
observeForeverOnce(messagingGroupId, groupId -> {
|
||||||
|
requireNonNull(groupId);
|
||||||
|
observeForeverOnce(imageSupport, hasImageSupport -> {
|
||||||
|
requireNonNull(hasImageSupport);
|
||||||
|
createMessage(groupId, text, headers, timestamp,
|
||||||
|
hasImageSupport);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@UiThread
|
@UiThread
|
||||||
public LiveData<AttachmentResult> storeAttachments(Collection<Uri> uris,
|
public LiveData<AttachmentResult> storeAttachments(Collection<Uri> uris,
|
||||||
@@ -292,12 +275,10 @@ public class ConversationViewModel extends DbViewModel
|
|||||||
|
|
||||||
@DatabaseExecutor
|
@DatabaseExecutor
|
||||||
private void checkFeaturesAndOnboarding(ContactId c) throws DbException {
|
private void checkFeaturesAndOnboarding(ContactId c) throws DbException {
|
||||||
// check if images and auto-deletion are supported
|
// check if images are supported
|
||||||
PrivateMessageFormat format = db.transactionWithResult(true, txn ->
|
boolean imagesSupported = db.transactionWithResult(true, txn ->
|
||||||
messagingManager.getContactMessageFormat(txn, c));
|
messagingManager.contactSupportsImages(txn, c));
|
||||||
if (LOG.isLoggable(INFO))
|
imageSupport.postValue(imagesSupported);
|
||||||
LOG.info("PrivateMessageFormat loaded: " + format.name());
|
|
||||||
privateMessageFormat.postValue(format);
|
|
||||||
|
|
||||||
// check if introductions are supported
|
// check if introductions are supported
|
||||||
Collection<Contact> contacts = contactManager.getContacts();
|
Collection<Contact> contacts = contactManager.getContacts();
|
||||||
@@ -306,7 +287,7 @@ public class ConversationViewModel extends DbViewModel
|
|||||||
|
|
||||||
// we only show one onboarding dialog at a time
|
// we only show one onboarding dialog at a time
|
||||||
Settings settings = settingsManager.getSettings(SETTINGS_NAMESPACE);
|
Settings settings = settingsManager.getSettings(SETTINGS_NAMESPACE);
|
||||||
if (format != TEXT_ONLY &&
|
if (imagesSupported &&
|
||||||
settings.getBoolean(SHOW_ONBOARDING_IMAGE, true)) {
|
settings.getBoolean(SHOW_ONBOARDING_IMAGE, true)) {
|
||||||
onOnboardingShown(SHOW_ONBOARDING_IMAGE);
|
onOnboardingShown(SHOW_ONBOARDING_IMAGE);
|
||||||
showImageOnboarding.postEvent(true);
|
showImageOnboarding.postEvent(true);
|
||||||
@@ -325,82 +306,39 @@ public class ConversationViewModel extends DbViewModel
|
|||||||
}
|
}
|
||||||
|
|
||||||
@UiThread
|
@UiThread
|
||||||
LiveData<SendState> sendMessage(@Nullable String text,
|
private void createMessage(GroupId groupId, @Nullable String text,
|
||||||
List<AttachmentHeader> headers, long expectedTimer) {
|
List<AttachmentHeader> headers, long timestamp,
|
||||||
MutableLiveData<SendState> liveData = new MutableLiveData<>();
|
boolean hasImageSupport) {
|
||||||
runOnDbThread(() -> {
|
|
||||||
try {
|
|
||||||
db.transaction(false, txn -> {
|
|
||||||
long start = now();
|
|
||||||
PrivateMessage m = createMessage(txn, text, headers,
|
|
||||||
expectedTimer);
|
|
||||||
messagingManager.addLocalMessage(txn, m);
|
|
||||||
logDuration(LOG, "Storing message", start);
|
|
||||||
Message message = m.getMessage();
|
|
||||||
PrivateMessageHeader h = new PrivateMessageHeader(
|
|
||||||
message.getId(), message.getGroupId(),
|
|
||||||
message.getTimestamp(), true, true, false, false,
|
|
||||||
m.hasText(), m.getAttachmentHeaders(),
|
|
||||||
m.getAutoDeleteTimer());
|
|
||||||
// TODO add text to cache when available here
|
|
||||||
MessageId id = message.getId();
|
|
||||||
txn.attach(() -> {
|
|
||||||
attachmentCreator.onAttachmentsSent(id);
|
|
||||||
liveData.setValue(SENT);
|
|
||||||
addedHeader.setEvent(h);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
} catch (UnexpectedTimerException e) {
|
|
||||||
liveData.postValue(UNEXPECTED_TIMER);
|
|
||||||
} catch (DbException e) {
|
|
||||||
logException(LOG, WARNING, e);
|
|
||||||
liveData.postValue(ERROR);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return liveData;
|
|
||||||
}
|
|
||||||
|
|
||||||
private PrivateMessage createMessage(Transaction txn, @Nullable String text,
|
|
||||||
List<AttachmentHeader> headers, long expectedTimer)
|
|
||||||
throws DbException {
|
|
||||||
// Sending is only possible (setReady(true)) after loading all messages
|
|
||||||
// which happens after the contact has been loaded.
|
|
||||||
// privateMessageFormat is loaded together with contact
|
|
||||||
Contact contact = requireNonNull(contactItem.getValue()).getContact();
|
|
||||||
GroupId groupId = messagingManager.getContactGroup(contact).getId();
|
|
||||||
PrivateMessageFormat format =
|
|
||||||
requireNonNull(privateMessageFormat.getValue());
|
|
||||||
long timestamp = conversationManager
|
|
||||||
.getTimestampForOutgoingMessage(txn, requireNonNull(contactId));
|
|
||||||
try {
|
try {
|
||||||
if (format == TEXT_ONLY) {
|
PrivateMessage pm;
|
||||||
return privateMessageFactory.createLegacyPrivateMessage(
|
if (hasImageSupport) {
|
||||||
groupId, timestamp, requireNonNull(text));
|
pm = privateMessageFactory.createPrivateMessage(groupId,
|
||||||
} else if (format == TEXT_IMAGES) {
|
|
||||||
return privateMessageFactory.createPrivateMessage(groupId,
|
|
||||||
timestamp, text, headers);
|
timestamp, text, headers);
|
||||||
} else {
|
} else {
|
||||||
long timer = autoDeleteManager
|
pm = privateMessageFactory.createLegacyPrivateMessage(
|
||||||
.getAutoDeleteTimer(txn, contactId, timestamp);
|
groupId, timestamp, requireNonNull(text));
|
||||||
if (timer != expectedTimer)
|
|
||||||
throw new UnexpectedTimerException();
|
|
||||||
return privateMessageFactory.createPrivateMessage(groupId,
|
|
||||||
timestamp, text, headers, timer);
|
|
||||||
}
|
}
|
||||||
|
storeMessage(pm);
|
||||||
} catch (FormatException e) {
|
} catch (FormatException e) {
|
||||||
throw new AssertionError(e);
|
throw new AssertionError(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void setAutoDeleteTimerEnabled(boolean enabled) {
|
@UiThread
|
||||||
final long timer = enabled ? DAYS.toMillis(7) : NO_AUTO_DELETE_TIMER;
|
private void storeMessage(PrivateMessage m) {
|
||||||
// ContactId is set before menu gets inflated and UI interaction
|
attachmentCreator.onAttachmentsSent(m.getMessage().getId());
|
||||||
final ContactId c = requireNonNull(contactId);
|
|
||||||
runOnDbThread(() -> {
|
runOnDbThread(() -> {
|
||||||
try {
|
try {
|
||||||
db.transaction(false, txn ->
|
long start = now();
|
||||||
autoDeleteManager.setAutoDeleteTimer(txn, c, timer));
|
messagingManager.addLocalMessage(m);
|
||||||
autoDeleteTimer.postValue(timer);
|
logDuration(LOG, "Storing message", start);
|
||||||
|
Message message = m.getMessage();
|
||||||
|
PrivateMessageHeader h = new PrivateMessageHeader(
|
||||||
|
message.getId(), message.getGroupId(),
|
||||||
|
message.getTimestamp(), true, true, false, false,
|
||||||
|
m.hasText(), m.getAttachmentHeaders());
|
||||||
|
// TODO add text to cache when available here
|
||||||
|
addedHeader.postEvent(h);
|
||||||
} catch (DbException e) {
|
} catch (DbException e) {
|
||||||
logException(LOG, WARNING, e);
|
logException(LOG, WARNING, e);
|
||||||
}
|
}
|
||||||
@@ -419,8 +357,8 @@ public class ConversationViewModel extends DbViewModel
|
|||||||
return contactName;
|
return contactName;
|
||||||
}
|
}
|
||||||
|
|
||||||
LiveData<PrivateMessageFormat> getPrivateMessageFormat() {
|
LiveData<Boolean> hasImageSupport() {
|
||||||
return privateMessageFormat;
|
return imageSupport;
|
||||||
}
|
}
|
||||||
|
|
||||||
LiveEvent<Boolean> showImageOnboarding() {
|
LiveEvent<Boolean> showImageOnboarding() {
|
||||||
@@ -435,10 +373,6 @@ public class ConversationViewModel extends DbViewModel
|
|||||||
return showIntroductionAction;
|
return showIntroductionAction;
|
||||||
}
|
}
|
||||||
|
|
||||||
LiveData<Long> getAutoDeleteTimer() {
|
|
||||||
return autoDeleteTimer;
|
|
||||||
}
|
|
||||||
|
|
||||||
LiveData<Boolean> isContactDeleted() {
|
LiveData<Boolean> isContactDeleted() {
|
||||||
return contactDeleted;
|
return contactDeleted;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,12 +60,10 @@ class ConversationVisitor implements
|
|||||||
}
|
}
|
||||||
if (h.isLocal()) {
|
if (h.isLocal()) {
|
||||||
item = new ConversationMessageItem(
|
item = new ConversationMessageItem(
|
||||||
R.layout.list_item_conversation_msg_out, h, contactName,
|
R.layout.list_item_conversation_msg_out, h, attachments);
|
||||||
attachments);
|
|
||||||
} else {
|
} else {
|
||||||
item = new ConversationMessageItem(
|
item = new ConversationMessageItem(
|
||||||
R.layout.list_item_conversation_msg_in, h, contactName,
|
R.layout.list_item_conversation_msg_in, h, attachments);
|
||||||
attachments);
|
|
||||||
}
|
}
|
||||||
if (h.hasText()) {
|
if (h.hasText()) {
|
||||||
String text = textCache.getText(h.getId());
|
String text = textCache.getText(h.getId());
|
||||||
@@ -81,15 +79,13 @@ class ConversationVisitor implements
|
|||||||
String text = ctx.getString(R.string.blogs_sharing_invitation_sent,
|
String text = ctx.getString(R.string.blogs_sharing_invitation_sent,
|
||||||
r.getName(), contactName.getValue());
|
r.getName(), contactName.getValue());
|
||||||
return new ConversationNoticeItem(
|
return new ConversationNoticeItem(
|
||||||
R.layout.list_item_conversation_notice_out, text,
|
R.layout.list_item_conversation_notice_out, text, r);
|
||||||
contactName, r);
|
|
||||||
} else {
|
} else {
|
||||||
String text = ctx.getString(
|
String text = ctx.getString(
|
||||||
R.string.blogs_sharing_invitation_received,
|
R.string.blogs_sharing_invitation_received,
|
||||||
contactName.getValue(), r.getName());
|
contactName.getValue(), r.getName());
|
||||||
return new ConversationRequestItem(
|
return new ConversationRequestItem(
|
||||||
R.layout.list_item_conversation_request, text, contactName,
|
R.layout.list_item_conversation_request, text, BLOG, r);
|
||||||
BLOG, r);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -108,8 +104,7 @@ class ConversationVisitor implements
|
|||||||
contactName.getValue());
|
contactName.getValue());
|
||||||
}
|
}
|
||||||
return new ConversationNoticeItem(
|
return new ConversationNoticeItem(
|
||||||
R.layout.list_item_conversation_notice_out, text,
|
R.layout.list_item_conversation_notice_out, text, r);
|
||||||
contactName, r);
|
|
||||||
} else {
|
} else {
|
||||||
String text;
|
String text;
|
||||||
if (r.wasAccepted()) {
|
if (r.wasAccepted()) {
|
||||||
@@ -122,8 +117,7 @@ class ConversationVisitor implements
|
|||||||
contactName.getValue());
|
contactName.getValue());
|
||||||
}
|
}
|
||||||
return new ConversationNoticeItem(
|
return new ConversationNoticeItem(
|
||||||
R.layout.list_item_conversation_notice_in, text,
|
R.layout.list_item_conversation_notice_in, text, r);
|
||||||
contactName, r);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -134,15 +128,13 @@ class ConversationVisitor implements
|
|||||||
String text = ctx.getString(R.string.forum_invitation_sent,
|
String text = ctx.getString(R.string.forum_invitation_sent,
|
||||||
r.getName(), contactName.getValue());
|
r.getName(), contactName.getValue());
|
||||||
return new ConversationNoticeItem(
|
return new ConversationNoticeItem(
|
||||||
R.layout.list_item_conversation_notice_out, text,
|
R.layout.list_item_conversation_notice_out, text, r);
|
||||||
contactName, r);
|
|
||||||
} else {
|
} else {
|
||||||
String text = ctx.getString(
|
String text = ctx.getString(
|
||||||
R.string.forum_invitation_received,
|
R.string.forum_invitation_received,
|
||||||
contactName.getValue(), r.getName());
|
contactName.getValue(), r.getName());
|
||||||
return new ConversationRequestItem(
|
return new ConversationRequestItem(
|
||||||
R.layout.list_item_conversation_request, text, contactName,
|
R.layout.list_item_conversation_request, text, FORUM, r);
|
||||||
FORUM, r);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -161,8 +153,7 @@ class ConversationVisitor implements
|
|||||||
contactName.getValue());
|
contactName.getValue());
|
||||||
}
|
}
|
||||||
return new ConversationNoticeItem(
|
return new ConversationNoticeItem(
|
||||||
R.layout.list_item_conversation_notice_out, text,
|
R.layout.list_item_conversation_notice_out, text, r);
|
||||||
contactName, r);
|
|
||||||
} else {
|
} else {
|
||||||
String text;
|
String text;
|
||||||
if (r.wasAccepted()) {
|
if (r.wasAccepted()) {
|
||||||
@@ -175,8 +166,7 @@ class ConversationVisitor implements
|
|||||||
contactName.getValue());
|
contactName.getValue());
|
||||||
}
|
}
|
||||||
return new ConversationNoticeItem(
|
return new ConversationNoticeItem(
|
||||||
R.layout.list_item_conversation_notice_in, text,
|
R.layout.list_item_conversation_notice_in, text, r);
|
||||||
contactName, r);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -188,15 +178,13 @@ class ConversationVisitor implements
|
|||||||
R.string.groups_invitations_invitation_sent,
|
R.string.groups_invitations_invitation_sent,
|
||||||
contactName.getValue(), r.getName());
|
contactName.getValue(), r.getName());
|
||||||
return new ConversationNoticeItem(
|
return new ConversationNoticeItem(
|
||||||
R.layout.list_item_conversation_notice_out, text,
|
R.layout.list_item_conversation_notice_out, text, r);
|
||||||
contactName, r);
|
|
||||||
} else {
|
} else {
|
||||||
String text = ctx.getString(
|
String text = ctx.getString(
|
||||||
R.string.groups_invitations_invitation_received,
|
R.string.groups_invitations_invitation_received,
|
||||||
contactName.getValue(), r.getName());
|
contactName.getValue(), r.getName());
|
||||||
return new ConversationRequestItem(
|
return new ConversationRequestItem(
|
||||||
R.layout.list_item_conversation_request, text, contactName,
|
R.layout.list_item_conversation_request, text, GROUP, r);
|
||||||
GROUP, r);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -215,8 +203,7 @@ class ConversationVisitor implements
|
|||||||
contactName.getValue());
|
contactName.getValue());
|
||||||
}
|
}
|
||||||
return new ConversationNoticeItem(
|
return new ConversationNoticeItem(
|
||||||
R.layout.list_item_conversation_notice_out, text,
|
R.layout.list_item_conversation_notice_out, text, r);
|
||||||
contactName, r);
|
|
||||||
} else {
|
} else {
|
||||||
String text;
|
String text;
|
||||||
if (r.wasAccepted()) {
|
if (r.wasAccepted()) {
|
||||||
@@ -229,8 +216,7 @@ class ConversationVisitor implements
|
|||||||
contactName.getValue());
|
contactName.getValue());
|
||||||
}
|
}
|
||||||
return new ConversationNoticeItem(
|
return new ConversationNoticeItem(
|
||||||
R.layout.list_item_conversation_notice_in, text,
|
R.layout.list_item_conversation_notice_in, text, r);
|
||||||
contactName, r);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -241,8 +227,7 @@ class ConversationVisitor implements
|
|||||||
String text = ctx.getString(R.string.introduction_request_sent,
|
String text = ctx.getString(R.string.introduction_request_sent,
|
||||||
contactName.getValue(), name);
|
contactName.getValue(), name);
|
||||||
return new ConversationNoticeItem(
|
return new ConversationNoticeItem(
|
||||||
R.layout.list_item_conversation_notice_out, text,
|
R.layout.list_item_conversation_notice_out, text, r);
|
||||||
contactName, r);
|
|
||||||
} else {
|
} else {
|
||||||
String text;
|
String text;
|
||||||
if (r.wasAnswered()) {
|
if (r.wasAnswered()) {
|
||||||
@@ -258,7 +243,7 @@ class ConversationVisitor implements
|
|||||||
contactName.getValue(), name);
|
contactName.getValue(), name);
|
||||||
}
|
}
|
||||||
return new ConversationRequestItem(
|
return new ConversationRequestItem(
|
||||||
R.layout.list_item_conversation_request, text, contactName,
|
R.layout.list_item_conversation_request, text,
|
||||||
INTRODUCTION, r);
|
INTRODUCTION, r);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -283,8 +268,7 @@ class ConversationVisitor implements
|
|||||||
introducedAuthor);
|
introducedAuthor);
|
||||||
}
|
}
|
||||||
return new ConversationNoticeItem(
|
return new ConversationNoticeItem(
|
||||||
R.layout.list_item_conversation_notice_out, text,
|
R.layout.list_item_conversation_notice_out, text, r);
|
||||||
contactName, r);
|
|
||||||
} else {
|
} else {
|
||||||
String text;
|
String text;
|
||||||
if (r.wasAccepted()) {
|
if (r.wasAccepted()) {
|
||||||
@@ -304,8 +288,7 @@ class ConversationVisitor implements
|
|||||||
introducedAuthor);
|
introducedAuthor);
|
||||||
}
|
}
|
||||||
return new ConversationNoticeItem(
|
return new ConversationNoticeItem(
|
||||||
R.layout.list_item_conversation_notice_in, text,
|
R.layout.list_item_conversation_notice_in, text, r);
|
||||||
contactName, r);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -35,8 +35,6 @@ import javax.inject.Inject;
|
|||||||
|
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.appcompat.app.ActionBar;
|
import androidx.appcompat.app.ActionBar;
|
||||||
import androidx.lifecycle.LiveData;
|
|
||||||
import androidx.lifecycle.MutableLiveData;
|
|
||||||
import de.hdodenhof.circleimageview.CircleImageView;
|
import de.hdodenhof.circleimageview.CircleImageView;
|
||||||
|
|
||||||
import static android.app.Activity.RESULT_OK;
|
import static android.app.Activity.RESULT_OK;
|
||||||
@@ -48,8 +46,6 @@ import static org.briarproject.bramble.util.LogUtils.logException;
|
|||||||
import static org.briarproject.briar.android.util.UiUtils.getContactDisplayName;
|
import static org.briarproject.briar.android.util.UiUtils.getContactDisplayName;
|
||||||
import static org.briarproject.briar.android.util.UiUtils.hideSoftKeyboard;
|
import static org.briarproject.briar.android.util.UiUtils.hideSoftKeyboard;
|
||||||
import static org.briarproject.briar.android.view.AuthorView.setAvatar;
|
import static org.briarproject.briar.android.view.AuthorView.setAvatar;
|
||||||
import static org.briarproject.briar.android.view.TextSendController.SendState;
|
|
||||||
import static org.briarproject.briar.android.view.TextSendController.SendState.SENT;
|
|
||||||
import static org.briarproject.briar.api.introduction.IntroductionConstants.MAX_INTRODUCTION_TEXT_LENGTH;
|
import static org.briarproject.briar.api.introduction.IntroductionConstants.MAX_INTRODUCTION_TEXT_LENGTH;
|
||||||
|
|
||||||
@MethodsNotNullByDefault
|
@MethodsNotNullByDefault
|
||||||
@@ -205,8 +201,8 @@ public class IntroductionMessageFragment extends BaseFragment
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LiveData<SendState> onSendClick(@Nullable String text,
|
public void onSendClick(@Nullable String text,
|
||||||
List<AttachmentHeader> headers, long expectedAutoDeleteTimer) {
|
List<AttachmentHeader> headers) {
|
||||||
// disable button to prevent accidental double invitations
|
// disable button to prevent accidental double invitations
|
||||||
ui.message.setReady(false);
|
ui.message.setReady(false);
|
||||||
|
|
||||||
@@ -216,7 +212,6 @@ public class IntroductionMessageFragment extends BaseFragment
|
|||||||
hideSoftKeyboard(ui.message);
|
hideSoftKeyboard(ui.message);
|
||||||
introductionActivity.setResult(RESULT_OK);
|
introductionActivity.setResult(RESULT_OK);
|
||||||
introductionActivity.supportFinishAfterTransition();
|
introductionActivity.supportFinishAfterTransition();
|
||||||
return new MutableLiveData<>(SENT);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void makeIntroduction(Contact c1, Contact c2,
|
private void makeIntroduction(Contact c1, Contact c2,
|
||||||
@@ -224,7 +219,8 @@ public class IntroductionMessageFragment extends BaseFragment
|
|||||||
introductionActivity.runOnDbThread(() -> {
|
introductionActivity.runOnDbThread(() -> {
|
||||||
// actually make the introduction
|
// actually make the introduction
|
||||||
try {
|
try {
|
||||||
introductionManager.makeIntroduction(c1, c2, text);
|
long timestamp = System.currentTimeMillis();
|
||||||
|
introductionManager.makeIntroduction(c1, c2, text, timestamp);
|
||||||
} catch (DbException e) {
|
} catch (DbException e) {
|
||||||
logException(LOG, WARNING, e);
|
logException(LOG, WARNING, e);
|
||||||
introductionError();
|
introductionError();
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
|||||||
|
|
||||||
import java.text.DateFormat;
|
import java.text.DateFormat;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.TimeZone;
|
import java.util.TimeZone;
|
||||||
import java.util.logging.Formatter;
|
import java.util.logging.Formatter;
|
||||||
@@ -17,6 +18,16 @@ import static java.util.Locale.US;
|
|||||||
@NotNullByDefault
|
@NotNullByDefault
|
||||||
public class BriefLogFormatter extends Formatter {
|
public class BriefLogFormatter extends Formatter {
|
||||||
|
|
||||||
|
public static String formatLog(Formatter formatter,
|
||||||
|
Collection<LogRecord> logRecords) {
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
for (LogRecord record : logRecords) {
|
||||||
|
String formatted = formatter.format(record);
|
||||||
|
sb.append(formatted).append('\n');
|
||||||
|
}
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
private final Object lock = new Object();
|
private final Object lock = new Object();
|
||||||
private final DateFormat dateFormat; // Locking: lock
|
private final DateFormat dateFormat; // Locking: lock
|
||||||
private final Date date; // Locking: lock
|
private final Date date; // Locking: lock
|
||||||
|
|||||||
@@ -21,6 +21,10 @@ public class CachingLogHandler extends Handler {
|
|||||||
// Locking: lock
|
// Locking: lock
|
||||||
private final Queue<LogRecord> recent = new LinkedList<>();
|
private final Queue<LogRecord> recent = new LinkedList<>();
|
||||||
|
|
||||||
|
// package-private constructor
|
||||||
|
CachingLogHandler() {
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void publish(LogRecord record) {
|
public void publish(LogRecord record) {
|
||||||
synchronized (lock) {
|
synchronized (lock) {
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package org.briarproject.briar.android.logging;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
import org.briarproject.bramble.util.AndroidUtils;
|
||||||
|
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
|
@NotNullByDefault
|
||||||
|
public interface LogDecrypter {
|
||||||
|
/**
|
||||||
|
* Returns decrypted log records from {@link AndroidUtils#getLogcatFile}
|
||||||
|
* or null if there was an error reading the logs.
|
||||||
|
*/
|
||||||
|
@Nullable
|
||||||
|
String decryptLogs(@Nullable byte[] logKey);
|
||||||
|
}
|
||||||
@@ -0,0 +1,61 @@
|
|||||||
|
package org.briarproject.briar.android.logging;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.crypto.SecretKey;
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
import org.briarproject.bramble.api.reporting.DevConfig;
|
||||||
|
import org.briarproject.bramble.api.transport.StreamReaderFactory;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.util.Scanner;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
|
import static java.util.logging.Level.WARNING;
|
||||||
|
import static java.util.logging.Logger.getLogger;
|
||||||
|
import static org.briarproject.bramble.util.LogUtils.logException;
|
||||||
|
|
||||||
|
@NotNullByDefault
|
||||||
|
class LogDecrypterImpl implements LogDecrypter {
|
||||||
|
|
||||||
|
private static final Logger LOG =
|
||||||
|
getLogger(LogDecrypterImpl.class.getName());
|
||||||
|
|
||||||
|
private final DevConfig devConfig;
|
||||||
|
private final StreamReaderFactory streamReaderFactory;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
LogDecrypterImpl(DevConfig devConfig,
|
||||||
|
StreamReaderFactory streamReaderFactory) {
|
||||||
|
this.devConfig = devConfig;
|
||||||
|
this.streamReaderFactory = streamReaderFactory;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public String decryptLogs(@Nullable byte[] logKey) {
|
||||||
|
if (logKey == null) return null;
|
||||||
|
SecretKey key = new SecretKey(logKey);
|
||||||
|
File logFile = devConfig.getLogcatFile();
|
||||||
|
try (InputStream in = new FileInputStream(logFile)) {
|
||||||
|
InputStream reader =
|
||||||
|
streamReaderFactory.createLogStreamReader(in, key);
|
||||||
|
Scanner s = new Scanner(reader);
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
while (s.hasNextLine()) sb.append(s.nextLine()).append("\n");
|
||||||
|
s.close();
|
||||||
|
return sb.toString();
|
||||||
|
} catch (IOException e) {
|
||||||
|
logException(LOG, WARNING, e);
|
||||||
|
return null;
|
||||||
|
} finally {
|
||||||
|
//noinspection ResultOfMethodCallIgnored
|
||||||
|
logFile.delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package org.briarproject.briar.android.logging;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
import org.briarproject.bramble.util.AndroidUtils;
|
||||||
|
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
|
@NotNullByDefault
|
||||||
|
public interface LogEncrypter {
|
||||||
|
/**
|
||||||
|
* Writes encrypted log records to {@link AndroidUtils#getLogcatFile}
|
||||||
|
* and returns the encryption key if everything went fine.
|
||||||
|
*/
|
||||||
|
@Nullable
|
||||||
|
byte[] encryptLogs();
|
||||||
|
}
|
||||||
@@ -0,0 +1,77 @@
|
|||||||
|
package org.briarproject.briar.android.logging;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.crypto.CryptoComponent;
|
||||||
|
import org.briarproject.bramble.api.crypto.SecretKey;
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
import org.briarproject.bramble.api.reporting.DevConfig;
|
||||||
|
import org.briarproject.bramble.api.transport.StreamWriter;
|
||||||
|
import org.briarproject.bramble.api.transport.StreamWriterFactory;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.OutputStream;
|
||||||
|
import java.io.OutputStreamWriter;
|
||||||
|
import java.io.Writer;
|
||||||
|
import java.util.logging.Formatter;
|
||||||
|
import java.util.logging.LogRecord;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
|
import static java.util.logging.Level.WARNING;
|
||||||
|
import static java.util.logging.Logger.getLogger;
|
||||||
|
import static org.briarproject.bramble.util.LogUtils.logException;
|
||||||
|
|
||||||
|
@NotNullByDefault
|
||||||
|
class LogEncrypterImpl implements LogEncrypter {
|
||||||
|
|
||||||
|
private static final Logger LOG =
|
||||||
|
getLogger(LogEncrypterImpl.class.getName());
|
||||||
|
|
||||||
|
private final DevConfig devConfig;
|
||||||
|
private final CachingLogHandler logHandler;
|
||||||
|
private final CryptoComponent crypto;
|
||||||
|
private final StreamWriterFactory streamWriterFactory;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
LogEncrypterImpl(DevConfig devConfig,
|
||||||
|
CachingLogHandler logHandler,
|
||||||
|
CryptoComponent crypto,
|
||||||
|
StreamWriterFactory streamWriterFactory) {
|
||||||
|
this.devConfig = devConfig;
|
||||||
|
this.logHandler = logHandler;
|
||||||
|
this.crypto = crypto;
|
||||||
|
this.streamWriterFactory = streamWriterFactory;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public byte[] encryptLogs() {
|
||||||
|
SecretKey logKey = crypto.generateSecretKey();
|
||||||
|
File logFile = devConfig.getLogcatFile();
|
||||||
|
try (OutputStream out = new FileOutputStream(logFile)) {
|
||||||
|
StreamWriter streamWriter =
|
||||||
|
streamWriterFactory.createLogStreamWriter(out, logKey);
|
||||||
|
Writer writer =
|
||||||
|
new OutputStreamWriter(streamWriter.getOutputStream());
|
||||||
|
writeLogString(writer);
|
||||||
|
writer.close();
|
||||||
|
return logKey.getBytes();
|
||||||
|
} catch (IOException e) {
|
||||||
|
logException(LOG, WARNING, e);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void writeLogString(Writer writer) throws IOException {
|
||||||
|
Formatter formatter = new BriefLogFormatter();
|
||||||
|
for (LogRecord record : logHandler.getRecentLogRecords()) {
|
||||||
|
String formatted = formatter.format(record);
|
||||||
|
writer.append(formatted).append('\n');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
package org.briarproject.briar.android.logging;
|
||||||
|
|
||||||
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
|
import dagger.Module;
|
||||||
|
import dagger.Provides;
|
||||||
|
|
||||||
|
@Module
|
||||||
|
public class LoggingModule {
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@Singleton
|
||||||
|
CachingLogHandler provideCachingLogHandler() {
|
||||||
|
return new CachingLogHandler();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@Singleton
|
||||||
|
LogEncrypter provideLogEncrypter(LogEncrypterImpl logEncrypter) {
|
||||||
|
return logEncrypter;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@Singleton
|
||||||
|
LogDecrypter provideLogDecrypter(LogDecrypterImpl logDecrypter) {
|
||||||
|
return logDecrypter;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -68,6 +68,7 @@ import static android.view.View.VISIBLE;
|
|||||||
import static androidx.core.view.GravityCompat.START;
|
import static androidx.core.view.GravityCompat.START;
|
||||||
import static androidx.drawerlayout.widget.DrawerLayout.LOCK_MODE_LOCKED_CLOSED;
|
import static androidx.drawerlayout.widget.DrawerLayout.LOCK_MODE_LOCKED_CLOSED;
|
||||||
import static androidx.fragment.app.FragmentManager.POP_BACK_STACK_INCLUSIVE;
|
import static androidx.fragment.app.FragmentManager.POP_BACK_STACK_INCLUSIVE;
|
||||||
|
import static androidx.lifecycle.Lifecycle.State.STARTED;
|
||||||
import static java.util.Objects.requireNonNull;
|
import static java.util.Objects.requireNonNull;
|
||||||
import static java.util.logging.Logger.getLogger;
|
import static java.util.logging.Logger.getLogger;
|
||||||
import static org.briarproject.bramble.api.lifecycle.LifecycleManager.LifecycleState.RUNNING;
|
import static org.briarproject.bramble.api.lifecycle.LifecycleManager.LifecycleState.RUNNING;
|
||||||
@@ -297,6 +298,12 @@ public class NavDrawerActivity extends BriarActivity implements
|
|||||||
finish();
|
finish();
|
||||||
} else if (fm.getBackStackEntryCount() == 0
|
} else if (fm.getBackStackEntryCount() == 0
|
||||||
&& fm.findFragmentByTag(ContactListFragment.TAG) == null) {
|
&& fm.findFragmentByTag(ContactListFragment.TAG) == null) {
|
||||||
|
// don't start fragments in the wrong part of lifecycle (#1904)
|
||||||
|
if (!getLifecycle().getCurrentState().isAtLeast(STARTED)) {
|
||||||
|
LOG.warning("Tried to start contacts fragment in state " +
|
||||||
|
getLifecycle().getCurrentState().name());
|
||||||
|
return;
|
||||||
|
}
|
||||||
/*
|
/*
|
||||||
* This makes sure that the first fragment (ContactListFragment) the
|
* This makes sure that the first fragment (ContactListFragment) the
|
||||||
* user sees is the same as the last fragment the user sees before
|
* user sees is the same as the last fragment the user sees before
|
||||||
|
|||||||
@@ -79,9 +79,10 @@ public class GroupActivity extends
|
|||||||
|
|
||||||
// start with group disabled and enable when not dissolved
|
// start with group disabled and enable when not dissolved
|
||||||
setGroupEnabled(false);
|
setGroupEnabled(false);
|
||||||
viewModel.isDissolved().observeEvent(this, dissolved -> {
|
viewModel.isDissolved().observe(this, dissolved -> {
|
||||||
setGroupEnabled(!dissolved);
|
setGroupEnabled(!dissolved);
|
||||||
if (dissolved) onGroupDissolved();
|
// only show dialog when no prior state
|
||||||
|
if (dissolved && state == null) onGroupDissolved();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -153,7 +154,7 @@ public class GroupActivity extends
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onReplyClick(GroupMessageItem item) {
|
public void onReplyClick(GroupMessageItem item) {
|
||||||
Boolean isDissolved = viewModel.isDissolved().getLastValue();
|
Boolean isDissolved = viewModel.isDissolved().getValue();
|
||||||
if (isDissolved != null && !isDissolved) super.onReplyClick(item);
|
if (isDissolved != null && !isDissolved) super.onReplyClick(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -22,8 +22,6 @@ import org.briarproject.bramble.api.system.AndroidExecutor;
|
|||||||
import org.briarproject.bramble.api.system.Clock;
|
import org.briarproject.bramble.api.system.Clock;
|
||||||
import org.briarproject.briar.android.sharing.SharingController;
|
import org.briarproject.briar.android.sharing.SharingController;
|
||||||
import org.briarproject.briar.android.threaded.ThreadListViewModel;
|
import org.briarproject.briar.android.threaded.ThreadListViewModel;
|
||||||
import org.briarproject.briar.android.viewmodel.LiveEvent;
|
|
||||||
import org.briarproject.briar.android.viewmodel.MutableLiveEvent;
|
|
||||||
import org.briarproject.briar.api.android.AndroidNotificationManager;
|
import org.briarproject.briar.api.android.AndroidNotificationManager;
|
||||||
import org.briarproject.briar.api.client.MessageTracker;
|
import org.briarproject.briar.api.client.MessageTracker;
|
||||||
import org.briarproject.briar.api.client.MessageTracker.GroupCount;
|
import org.briarproject.briar.api.client.MessageTracker.GroupCount;
|
||||||
@@ -71,8 +69,8 @@ class GroupViewModel extends ThreadListViewModel<GroupMessageItem> {
|
|||||||
private final MutableLiveData<PrivateGroup> privateGroup =
|
private final MutableLiveData<PrivateGroup> privateGroup =
|
||||||
new MutableLiveData<>();
|
new MutableLiveData<>();
|
||||||
private final MutableLiveData<Boolean> isCreator = new MutableLiveData<>();
|
private final MutableLiveData<Boolean> isCreator = new MutableLiveData<>();
|
||||||
private final MutableLiveEvent<Boolean> isDissolved =
|
private final MutableLiveData<Boolean> isDissolved =
|
||||||
new MutableLiveEvent<>();
|
new MutableLiveData<>();
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
GroupViewModel(Application application,
|
GroupViewModel(Application application,
|
||||||
@@ -129,7 +127,7 @@ class GroupViewModel extends ThreadListViewModel<GroupMessageItem> {
|
|||||||
} else if (e instanceof GroupDissolvedEvent) {
|
} else if (e instanceof GroupDissolvedEvent) {
|
||||||
GroupDissolvedEvent g = (GroupDissolvedEvent) e;
|
GroupDissolvedEvent g = (GroupDissolvedEvent) e;
|
||||||
if (g.getGroupId().equals(groupId)) {
|
if (g.getGroupId().equals(groupId)) {
|
||||||
isDissolved.setEvent(true);
|
isDissolved.setValue(true);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
super.eventOccurred(e);
|
super.eventOccurred(e);
|
||||||
@@ -164,7 +162,7 @@ class GroupViewModel extends ThreadListViewModel<GroupMessageItem> {
|
|||||||
loadList(txn -> {
|
loadList(txn -> {
|
||||||
// check first if group is dissolved
|
// check first if group is dissolved
|
||||||
isDissolved
|
isDissolved
|
||||||
.postEvent(privateGroupManager.isDissolved(txn, groupId));
|
.postValue(privateGroupManager.isDissolved(txn, groupId));
|
||||||
// now continue to load the items
|
// now continue to load the items
|
||||||
long start = now();
|
long start = now();
|
||||||
List<GroupMessageHeader> headers =
|
List<GroupMessageHeader> headers =
|
||||||
@@ -282,7 +280,7 @@ class GroupViewModel extends ThreadListViewModel<GroupMessageItem> {
|
|||||||
return isCreator;
|
return isCreator;
|
||||||
}
|
}
|
||||||
|
|
||||||
LiveEvent<Boolean> isDissolved() {
|
LiveData<Boolean> isDissolved() {
|
||||||
return isDissolved;
|
return isDissolved;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,8 +7,6 @@ import org.briarproject.bramble.api.crypto.CryptoExecutor;
|
|||||||
import org.briarproject.bramble.api.db.DatabaseExecutor;
|
import org.briarproject.bramble.api.db.DatabaseExecutor;
|
||||||
import org.briarproject.bramble.api.db.DbException;
|
import org.briarproject.bramble.api.db.DbException;
|
||||||
import org.briarproject.bramble.api.db.NoSuchContactException;
|
import org.briarproject.bramble.api.db.NoSuchContactException;
|
||||||
import org.briarproject.bramble.api.db.Transaction;
|
|
||||||
import org.briarproject.bramble.api.db.TransactionManager;
|
|
||||||
import org.briarproject.bramble.api.identity.IdentityManager;
|
import org.briarproject.bramble.api.identity.IdentityManager;
|
||||||
import org.briarproject.bramble.api.identity.LocalAuthor;
|
import org.briarproject.bramble.api.identity.LocalAuthor;
|
||||||
import org.briarproject.bramble.api.lifecycle.LifecycleManager;
|
import org.briarproject.bramble.api.lifecycle.LifecycleManager;
|
||||||
@@ -17,8 +15,6 @@ import org.briarproject.bramble.api.sync.GroupId;
|
|||||||
import org.briarproject.bramble.api.system.Clock;
|
import org.briarproject.bramble.api.system.Clock;
|
||||||
import org.briarproject.briar.android.contactselection.ContactSelectorControllerImpl;
|
import org.briarproject.briar.android.contactselection.ContactSelectorControllerImpl;
|
||||||
import org.briarproject.briar.android.controller.handler.ResultExceptionHandler;
|
import org.briarproject.briar.android.controller.handler.ResultExceptionHandler;
|
||||||
import org.briarproject.briar.api.autodelete.AutoDeleteManager;
|
|
||||||
import org.briarproject.briar.api.conversation.ConversationManager;
|
|
||||||
import org.briarproject.briar.api.identity.AuthorManager;
|
import org.briarproject.briar.api.identity.AuthorManager;
|
||||||
import org.briarproject.briar.api.privategroup.GroupMessage;
|
import org.briarproject.briar.api.privategroup.GroupMessage;
|
||||||
import org.briarproject.briar.api.privategroup.GroupMessageFactory;
|
import org.briarproject.briar.api.privategroup.GroupMessageFactory;
|
||||||
@@ -40,8 +36,6 @@ import javax.inject.Inject;
|
|||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
import static java.util.logging.Level.WARNING;
|
import static java.util.logging.Level.WARNING;
|
||||||
import static java.util.logging.Logger.getLogger;
|
|
||||||
import static org.briarproject.bramble.api.nullsafety.NullSafety.requireNonNull;
|
|
||||||
import static org.briarproject.bramble.util.LogUtils.logException;
|
import static org.briarproject.bramble.util.LogUtils.logException;
|
||||||
|
|
||||||
@Immutable
|
@Immutable
|
||||||
@@ -50,12 +44,9 @@ class CreateGroupControllerImpl extends ContactSelectorControllerImpl
|
|||||||
implements CreateGroupController {
|
implements CreateGroupController {
|
||||||
|
|
||||||
private static final Logger LOG =
|
private static final Logger LOG =
|
||||||
getLogger(CreateGroupControllerImpl.class.getName());
|
Logger.getLogger(CreateGroupControllerImpl.class.getName());
|
||||||
|
|
||||||
private final Executor cryptoExecutor;
|
private final Executor cryptoExecutor;
|
||||||
private final TransactionManager db;
|
|
||||||
private final AutoDeleteManager autoDeleteManager;
|
|
||||||
private final ConversationManager conversationManager;
|
|
||||||
private final ContactManager contactManager;
|
private final ContactManager contactManager;
|
||||||
private final IdentityManager identityManager;
|
private final IdentityManager identityManager;
|
||||||
private final PrivateGroupFactory groupFactory;
|
private final PrivateGroupFactory groupFactory;
|
||||||
@@ -66,27 +57,17 @@ class CreateGroupControllerImpl extends ContactSelectorControllerImpl
|
|||||||
private final Clock clock;
|
private final Clock clock;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
CreateGroupControllerImpl(
|
CreateGroupControllerImpl(@DatabaseExecutor Executor dbExecutor,
|
||||||
@DatabaseExecutor Executor dbExecutor,
|
|
||||||
@CryptoExecutor Executor cryptoExecutor,
|
@CryptoExecutor Executor cryptoExecutor,
|
||||||
TransactionManager db,
|
LifecycleManager lifecycleManager, ContactManager contactManager,
|
||||||
AutoDeleteManager autoDeleteManager,
|
AuthorManager authorManager, IdentityManager identityManager,
|
||||||
ConversationManager conversationManager,
|
|
||||||
LifecycleManager lifecycleManager,
|
|
||||||
ContactManager contactManager,
|
|
||||||
AuthorManager authorManager,
|
|
||||||
IdentityManager identityManager,
|
|
||||||
PrivateGroupFactory groupFactory,
|
PrivateGroupFactory groupFactory,
|
||||||
GroupMessageFactory groupMessageFactory,
|
GroupMessageFactory groupMessageFactory,
|
||||||
PrivateGroupManager groupManager,
|
PrivateGroupManager groupManager,
|
||||||
GroupInvitationFactory groupInvitationFactory,
|
GroupInvitationFactory groupInvitationFactory,
|
||||||
GroupInvitationManager groupInvitationManager,
|
GroupInvitationManager groupInvitationManager, Clock clock) {
|
||||||
Clock clock) {
|
|
||||||
super(dbExecutor, lifecycleManager, contactManager, authorManager);
|
super(dbExecutor, lifecycleManager, contactManager, authorManager);
|
||||||
this.cryptoExecutor = cryptoExecutor;
|
this.cryptoExecutor = cryptoExecutor;
|
||||||
this.db = db;
|
|
||||||
this.autoDeleteManager = autoDeleteManager;
|
|
||||||
this.conversationManager = conversationManager;
|
|
||||||
this.contactManager = contactManager;
|
this.contactManager = contactManager;
|
||||||
this.identityManager = identityManager;
|
this.identityManager = identityManager;
|
||||||
this.groupFactory = groupFactory;
|
this.groupFactory = groupFactory;
|
||||||
@@ -150,14 +131,16 @@ class CreateGroupControllerImpl extends ContactSelectorControllerImpl
|
|||||||
ResultExceptionHandler<Void, DbException> handler) {
|
ResultExceptionHandler<Void, DbException> handler) {
|
||||||
runOnDbThread(() -> {
|
runOnDbThread(() -> {
|
||||||
try {
|
try {
|
||||||
db.transaction(false, txn -> {
|
LocalAuthor localAuthor = identityManager.getLocalAuthor();
|
||||||
LocalAuthor localAuthor =
|
List<Contact> contacts = new ArrayList<>();
|
||||||
identityManager.getLocalAuthor(txn);
|
for (ContactId c : contactIds) {
|
||||||
List<InvitationContext> contexts =
|
try {
|
||||||
createInvitationContexts(txn, contactIds);
|
contacts.add(contactManager.getContact(c));
|
||||||
txn.attach(() -> signInvitations(g, localAuthor, contexts,
|
} catch (NoSuchContactException e) {
|
||||||
text, handler));
|
// Continue
|
||||||
});
|
}
|
||||||
|
}
|
||||||
|
signInvitations(g, localAuthor, contacts, text, handler);
|
||||||
} catch (DbException e) {
|
} catch (DbException e) {
|
||||||
logException(LOG, WARNING, e);
|
logException(LOG, WARNING, e);
|
||||||
handler.onException(e);
|
handler.onException(e);
|
||||||
@@ -165,32 +148,17 @@ class CreateGroupControllerImpl extends ContactSelectorControllerImpl
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<InvitationContext> createInvitationContexts(Transaction txn,
|
|
||||||
Collection<ContactId> contactIds) throws DbException {
|
|
||||||
List<InvitationContext> contexts = new ArrayList<>();
|
|
||||||
for (ContactId c : contactIds) {
|
|
||||||
try {
|
|
||||||
Contact contact = contactManager.getContact(txn, c);
|
|
||||||
long timestamp = conversationManager
|
|
||||||
.getTimestampForOutgoingMessage(txn, c);
|
|
||||||
long timer = autoDeleteManager.getAutoDeleteTimer(txn, c,
|
|
||||||
timestamp);
|
|
||||||
contexts.add(new InvitationContext(contact, timestamp, timer));
|
|
||||||
} catch (NoSuchContactException e) {
|
|
||||||
// Continue
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return contexts;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void signInvitations(GroupId g, LocalAuthor localAuthor,
|
private void signInvitations(GroupId g, LocalAuthor localAuthor,
|
||||||
List<InvitationContext> contexts, @Nullable String text,
|
Collection<Contact> contacts, @Nullable String text,
|
||||||
ResultExceptionHandler<Void, DbException> handler) {
|
ResultExceptionHandler<Void, DbException> handler) {
|
||||||
cryptoExecutor.execute(() -> {
|
cryptoExecutor.execute(() -> {
|
||||||
for (InvitationContext ctx : contexts) {
|
long timestamp = clock.currentTimeMillis();
|
||||||
ctx.signature = groupInvitationFactory.signInvitation(
|
List<InvitationContext> contexts = new ArrayList<>();
|
||||||
ctx.contact, g, ctx.timestamp,
|
for (Contact c : contacts) {
|
||||||
localAuthor.getPrivateKey());
|
byte[] signature = groupInvitationFactory.signInvitation(c, g,
|
||||||
|
timestamp, localAuthor.getPrivateKey());
|
||||||
|
contexts.add(new InvitationContext(c.getId(), timestamp,
|
||||||
|
signature));
|
||||||
}
|
}
|
||||||
sendInvitations(g, contexts, text, handler);
|
sendInvitations(g, contexts, text, handler);
|
||||||
});
|
});
|
||||||
@@ -201,12 +169,11 @@ class CreateGroupControllerImpl extends ContactSelectorControllerImpl
|
|||||||
ResultExceptionHandler<Void, DbException> handler) {
|
ResultExceptionHandler<Void, DbException> handler) {
|
||||||
runOnDbThread(() -> {
|
runOnDbThread(() -> {
|
||||||
try {
|
try {
|
||||||
for (InvitationContext ctx : contexts) {
|
for (InvitationContext context : contexts) {
|
||||||
try {
|
try {
|
||||||
groupInvitationManager.sendInvitation(g,
|
groupInvitationManager.sendInvitation(g,
|
||||||
ctx.contact.getId(), text, ctx.timestamp,
|
context.contactId, text, context.timestamp,
|
||||||
requireNonNull(ctx.signature),
|
context.signature);
|
||||||
ctx.autoDeleteTimer);
|
|
||||||
} catch (NoSuchContactException e) {
|
} catch (NoSuchContactException e) {
|
||||||
// Continue
|
// Continue
|
||||||
}
|
}
|
||||||
@@ -221,16 +188,15 @@ class CreateGroupControllerImpl extends ContactSelectorControllerImpl
|
|||||||
|
|
||||||
private static class InvitationContext {
|
private static class InvitationContext {
|
||||||
|
|
||||||
private final Contact contact;
|
private final ContactId contactId;
|
||||||
private final long timestamp, autoDeleteTimer;
|
private final long timestamp;
|
||||||
@Nullable
|
private final byte[] signature;
|
||||||
private byte[] signature = null;
|
|
||||||
|
|
||||||
private InvitationContext(Contact contact, long timestamp,
|
private InvitationContext(ContactId contactId, long timestamp,
|
||||||
long autoDeleteTimer) {
|
byte[] signature) {
|
||||||
this.contact = contact;
|
this.contactId = contactId;
|
||||||
this.timestamp = timestamp;
|
this.timestamp = timestamp;
|
||||||
this.autoDeleteTimer = autoDeleteTimer;
|
this.signature = signature;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,29 +1,40 @@
|
|||||||
package org.briarproject.briar.android.reporting;
|
package org.briarproject.briar.android.reporting;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.app.Application;
|
||||||
import android.os.Process;
|
import android.os.Process;
|
||||||
|
|
||||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
import org.briarproject.briar.android.logging.LogEncrypter;
|
||||||
|
|
||||||
import java.lang.Thread.UncaughtExceptionHandler;
|
import java.lang.Thread.UncaughtExceptionHandler;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
|
||||||
import static org.briarproject.briar.android.util.UiUtils.startDevReportActivity;
|
import static org.briarproject.briar.android.util.UiUtils.startDevReportActivity;
|
||||||
|
|
||||||
@NotNullByDefault
|
@NotNullByDefault
|
||||||
public class BriarExceptionHandler implements UncaughtExceptionHandler {
|
class BriarExceptionHandler implements UncaughtExceptionHandler {
|
||||||
|
|
||||||
private final Context ctx;
|
private final Application app;
|
||||||
|
private final LogEncrypter logEncrypter;
|
||||||
private final long appStartTime;
|
private final long appStartTime;
|
||||||
|
|
||||||
public BriarExceptionHandler(Context ctx) {
|
@Inject
|
||||||
this.ctx = ctx;
|
BriarExceptionHandler(Application app, LogEncrypter logEncrypter) {
|
||||||
this.appStartTime = System.currentTimeMillis();
|
this.app = app;
|
||||||
|
this.logEncrypter = logEncrypter;
|
||||||
|
appStartTime = System.currentTimeMillis();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void uncaughtException(Thread t, Throwable e) {
|
public void uncaughtException(Thread t, Throwable e) {
|
||||||
|
// encrypt logs to disk before handing over to new process
|
||||||
|
// the intent has limited space, so we can't reliably store them there.
|
||||||
|
byte[] logKey = logEncrypter.encryptLogs();
|
||||||
|
|
||||||
// activity runs in its own process, so we can kill the old one
|
// activity runs in its own process, so we can kill the old one
|
||||||
startDevReportActivity(ctx, CrashReportActivity.class, e, appStartTime);
|
startDevReportActivity(app.getApplicationContext(),
|
||||||
|
CrashReportActivity.class, e, appStartTime, logKey);
|
||||||
Process.killProcess(Process.myPid());
|
Process.killProcess(Process.myPid());
|
||||||
System.exit(10);
|
System.exit(10);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,8 +25,6 @@ import org.briarproject.bramble.api.Pair;
|
|||||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
import org.briarproject.briar.BuildConfig;
|
import org.briarproject.briar.BuildConfig;
|
||||||
import org.briarproject.briar.R;
|
import org.briarproject.briar.R;
|
||||||
import org.briarproject.briar.android.BriarApplication;
|
|
||||||
import org.briarproject.briar.android.logging.BriefLogFormatter;
|
|
||||||
import org.briarproject.briar.android.reporting.ReportData.MultiReportInfo;
|
import org.briarproject.briar.android.reporting.ReportData.MultiReportInfo;
|
||||||
import org.briarproject.briar.android.reporting.ReportData.ReportItem;
|
import org.briarproject.briar.android.reporting.ReportData.ReportItem;
|
||||||
import org.briarproject.briar.android.reporting.ReportData.SingleReportInfo;
|
import org.briarproject.briar.android.reporting.ReportData.SingleReportInfo;
|
||||||
@@ -41,8 +39,6 @@ import java.net.InetAddress;
|
|||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.logging.Formatter;
|
|
||||||
import java.util.logging.LogRecord;
|
|
||||||
|
|
||||||
import javax.annotation.concurrent.Immutable;
|
import javax.annotation.concurrent.Immutable;
|
||||||
|
|
||||||
@@ -74,8 +70,8 @@ class BriarReportCollector {
|
|||||||
this.ctx = ctx;
|
this.ctx = ctx;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ReportData collectReportData(@Nullable Throwable t,
|
ReportData collectReportData(@Nullable Throwable t, long appStartTime,
|
||||||
long appStartTime) {
|
String logs) {
|
||||||
ReportData reportData = new ReportData()
|
ReportData reportData = new ReportData()
|
||||||
.add(getBasicInfo(t))
|
.add(getBasicInfo(t))
|
||||||
.add(getDeviceInfo());
|
.add(getDeviceInfo());
|
||||||
@@ -86,7 +82,7 @@ class BriarReportCollector {
|
|||||||
.add(getStorage())
|
.add(getStorage())
|
||||||
.add(getConnectivity())
|
.add(getConnectivity())
|
||||||
.add(getBuildConfig())
|
.add(getBuildConfig())
|
||||||
.add(getLogcat())
|
.add(getLogcat(logs))
|
||||||
.add(getDeviceFeatures());
|
.add(getDeviceFeatures());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -313,15 +309,8 @@ class BriarReportCollector {
|
|||||||
buildConfig);
|
buildConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
private ReportItem getLogcat() {
|
private ReportItem getLogcat(String logs) {
|
||||||
BriarApplication app = (BriarApplication) ctx.getApplicationContext();
|
return new ReportItem("Logcat", R.string.dev_report_logcat, logs);
|
||||||
StringBuilder sb = new StringBuilder();
|
|
||||||
Formatter formatter = new BriefLogFormatter();
|
|
||||||
for (LogRecord record : app.getRecentLogRecords()) {
|
|
||||||
sb.append(formatter.format(record)).append('\n');
|
|
||||||
}
|
|
||||||
return new ReportItem("Logcat", R.string.dev_report_logcat,
|
|
||||||
sb.toString());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private ReportItem getDeviceFeatures() {
|
private ReportItem getDeviceFeatures() {
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ public class CrashReportActivity extends BaseActivity
|
|||||||
|
|
||||||
public static final String EXTRA_THROWABLE = "throwable";
|
public static final String EXTRA_THROWABLE = "throwable";
|
||||||
public static final String EXTRA_APP_START_TIME = "appStartTime";
|
public static final String EXTRA_APP_START_TIME = "appStartTime";
|
||||||
|
public static final String EXTRA_APP_LOGCAT = "logcat";
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
ViewModelProvider.Factory viewModelFactory;
|
ViewModelProvider.Factory viewModelFactory;
|
||||||
@@ -56,7 +57,8 @@ public class CrashReportActivity extends BaseActivity
|
|||||||
Intent intent = getIntent();
|
Intent intent = getIntent();
|
||||||
Throwable t = (Throwable) intent.getSerializableExtra(EXTRA_THROWABLE);
|
Throwable t = (Throwable) intent.getSerializableExtra(EXTRA_THROWABLE);
|
||||||
long appStartTime = intent.getLongExtra(EXTRA_APP_START_TIME, -1);
|
long appStartTime = intent.getLongExtra(EXTRA_APP_START_TIME, -1);
|
||||||
viewModel.init(t, appStartTime);
|
byte[] logKey = intent.getByteArrayExtra(EXTRA_APP_LOGCAT);
|
||||||
|
viewModel.init(t, appStartTime, logKey);
|
||||||
viewModel.getShowReport().observeEvent(this, show -> {
|
viewModel.getShowReport().observeEvent(this, show -> {
|
||||||
if (show) displayFragment(true);
|
if (show) displayFragment(true);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -15,4 +15,8 @@ public abstract class DevReportModule {
|
|||||||
@ViewModelKey(ReportViewModel.class)
|
@ViewModelKey(ReportViewModel.class)
|
||||||
abstract ViewModel bindReportViewModel(ReportViewModel reportViewModel);
|
abstract ViewModel bindReportViewModel(ReportViewModel reportViewModel);
|
||||||
|
|
||||||
|
@Binds
|
||||||
|
abstract Thread.UncaughtExceptionHandler bindUncaughtExceptionHandler(
|
||||||
|
BriarExceptionHandler handler);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,9 @@ import org.briarproject.bramble.api.plugin.TorConstants;
|
|||||||
import org.briarproject.bramble.api.reporting.DevReporter;
|
import org.briarproject.bramble.api.reporting.DevReporter;
|
||||||
import org.briarproject.bramble.util.AndroidUtils;
|
import org.briarproject.bramble.util.AndroidUtils;
|
||||||
import org.briarproject.briar.R;
|
import org.briarproject.briar.R;
|
||||||
|
import org.briarproject.briar.android.logging.BriefLogFormatter;
|
||||||
|
import org.briarproject.briar.android.logging.CachingLogHandler;
|
||||||
|
import org.briarproject.briar.android.logging.LogDecrypter;
|
||||||
import org.briarproject.briar.android.reporting.ReportData.MultiReportInfo;
|
import org.briarproject.briar.android.reporting.ReportData.MultiReportInfo;
|
||||||
import org.briarproject.briar.android.viewmodel.LiveEvent;
|
import org.briarproject.briar.android.viewmodel.LiveEvent;
|
||||||
import org.briarproject.briar.android.viewmodel.MutableLiveEvent;
|
import org.briarproject.briar.android.viewmodel.MutableLiveEvent;
|
||||||
@@ -19,6 +22,7 @@ import org.json.JSONException;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import java.util.logging.Formatter;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
@@ -36,13 +40,16 @@ import static java.util.logging.Logger.getLogger;
|
|||||||
import static org.briarproject.bramble.api.plugin.Plugin.State.ACTIVE;
|
import static org.briarproject.bramble.api.plugin.Plugin.State.ACTIVE;
|
||||||
import static org.briarproject.bramble.util.LogUtils.logException;
|
import static org.briarproject.bramble.util.LogUtils.logException;
|
||||||
import static org.briarproject.bramble.util.StringUtils.isNullOrEmpty;
|
import static org.briarproject.bramble.util.StringUtils.isNullOrEmpty;
|
||||||
|
import static org.briarproject.briar.android.logging.BriefLogFormatter.formatLog;
|
||||||
|
|
||||||
@NotNullByDefault
|
@NotNullByDefault
|
||||||
public class ReportViewModel extends AndroidViewModel {
|
class ReportViewModel extends AndroidViewModel {
|
||||||
|
|
||||||
private static final Logger LOG =
|
private static final Logger LOG =
|
||||||
getLogger(ReportViewModel.class.getName());
|
getLogger(ReportViewModel.class.getName());
|
||||||
|
|
||||||
|
private final CachingLogHandler logHandler;
|
||||||
|
private final LogDecrypter logDecrypter;
|
||||||
private final BriarReportCollector collector;
|
private final BriarReportCollector collector;
|
||||||
private final DevReporter reporter;
|
private final DevReporter reporter;
|
||||||
private final PluginManager pluginManager;
|
private final PluginManager pluginManager;
|
||||||
@@ -58,18 +65,39 @@ public class ReportViewModel extends AndroidViewModel {
|
|||||||
private boolean isFeedback;
|
private boolean isFeedback;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public ReportViewModel(@NonNull Application application,
|
ReportViewModel(@NonNull Application application,
|
||||||
DevReporter reporter, PluginManager pluginManager) {
|
CachingLogHandler logHandler,
|
||||||
|
LogDecrypter logDecrypter,
|
||||||
|
DevReporter reporter,
|
||||||
|
PluginManager pluginManager) {
|
||||||
super(application);
|
super(application);
|
||||||
this.collector = new BriarReportCollector(application);
|
collector = new BriarReportCollector(application);
|
||||||
|
this.logHandler = logHandler;
|
||||||
|
this.logDecrypter = logDecrypter;
|
||||||
this.reporter = reporter;
|
this.reporter = reporter;
|
||||||
this.pluginManager = pluginManager;
|
this.pluginManager = pluginManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
void init(@Nullable Throwable t, long appStartTime) {
|
void init(@Nullable Throwable t, long appStartTime,
|
||||||
|
@Nullable byte[] logKey) {
|
||||||
isFeedback = t == null;
|
isFeedback = t == null;
|
||||||
if (reportData.getValue() == null) new SingleShotAndroidExecutor(() -> {
|
if (reportData.getValue() == null) new SingleShotAndroidExecutor(() -> {
|
||||||
ReportData data = collector.collectReportData(t, appStartTime);
|
String decryptedLogs;
|
||||||
|
if (isFeedback) {
|
||||||
|
Formatter formatter = new BriefLogFormatter();
|
||||||
|
decryptedLogs =
|
||||||
|
formatLog(formatter, logHandler.getRecentLogRecords());
|
||||||
|
} else {
|
||||||
|
decryptedLogs = logDecrypter.decryptLogs(logKey);
|
||||||
|
if (decryptedLogs == null) {
|
||||||
|
// error decrypting logs, get logs from this process
|
||||||
|
Formatter formatter = new BriefLogFormatter();
|
||||||
|
decryptedLogs = formatLog(formatter,
|
||||||
|
logHandler.getRecentLogRecords());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ReportData data =
|
||||||
|
collector.collectReportData(t, appStartTime, decryptedLogs);
|
||||||
reportData.postValue(data);
|
reportData.postValue(data);
|
||||||
}).start();
|
}).start();
|
||||||
}
|
}
|
||||||
@@ -110,8 +138,8 @@ public class ReportViewModel extends AndroidViewModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The content of the report
|
* The content of the report that will be loaded after
|
||||||
* that will be loaded after {@link #init(Throwable, long)} was called.
|
* {@link #init(Throwable, long, byte[])} was called.
|
||||||
*/
|
*/
|
||||||
LiveData<ReportData> getReportData() {
|
LiveData<ReportData> getReportData() {
|
||||||
return reportData;
|
return reportData;
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ import org.briarproject.briar.android.fragment.BaseFragment;
|
|||||||
import org.briarproject.briar.android.view.LargeTextInputView;
|
import org.briarproject.briar.android.view.LargeTextInputView;
|
||||||
import org.briarproject.briar.android.view.TextSendController;
|
import org.briarproject.briar.android.view.TextSendController;
|
||||||
import org.briarproject.briar.android.view.TextSendController.SendListener;
|
import org.briarproject.briar.android.view.TextSendController.SendListener;
|
||||||
import org.briarproject.briar.android.view.TextSendController.SendState;
|
|
||||||
import org.briarproject.briar.api.attachment.AttachmentHeader;
|
import org.briarproject.briar.api.attachment.AttachmentHeader;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -23,10 +22,6 @@ import java.util.List;
|
|||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.annotation.StringRes;
|
import androidx.annotation.StringRes;
|
||||||
import androidx.annotation.UiThread;
|
import androidx.annotation.UiThread;
|
||||||
import androidx.lifecycle.LiveData;
|
|
||||||
import androidx.lifecycle.MutableLiveData;
|
|
||||||
|
|
||||||
import static org.briarproject.briar.android.view.TextSendController.SendState.SENT;
|
|
||||||
|
|
||||||
@MethodsNotNullByDefault
|
@MethodsNotNullByDefault
|
||||||
@ParametersNotNullByDefault
|
@ParametersNotNullByDefault
|
||||||
@@ -84,14 +79,13 @@ public abstract class BaseMessageFragment extends BaseFragment
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LiveData<SendState> onSendClick(@Nullable String text,
|
public void onSendClick(@Nullable String text,
|
||||||
List<AttachmentHeader> headers, long expectedAutoDeleteTimer) {
|
List<AttachmentHeader> headers) {
|
||||||
// disable button to prevent accidental double actions
|
// disable button to prevent accidental double actions
|
||||||
sendController.setReady(false);
|
sendController.setReady(false);
|
||||||
message.hideSoftKeyboard();
|
message.hideSoftKeyboard();
|
||||||
|
|
||||||
listener.onButtonClick(text);
|
listener.onButtonClick(text);
|
||||||
return new MutableLiveData<>(SENT);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@UiThread
|
@UiThread
|
||||||
|
|||||||
@@ -10,9 +10,11 @@ import org.briarproject.bramble.api.db.NoSuchGroupException;
|
|||||||
import org.briarproject.bramble.api.lifecycle.LifecycleManager;
|
import org.briarproject.bramble.api.lifecycle.LifecycleManager;
|
||||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
import org.briarproject.bramble.api.sync.GroupId;
|
import org.briarproject.bramble.api.sync.GroupId;
|
||||||
|
import org.briarproject.bramble.api.system.Clock;
|
||||||
import org.briarproject.briar.android.contactselection.ContactSelectorControllerImpl;
|
import org.briarproject.briar.android.contactselection.ContactSelectorControllerImpl;
|
||||||
import org.briarproject.briar.android.controller.handler.ExceptionHandler;
|
import org.briarproject.briar.android.controller.handler.ExceptionHandler;
|
||||||
import org.briarproject.briar.api.blog.BlogSharingManager;
|
import org.briarproject.briar.api.blog.BlogSharingManager;
|
||||||
|
import org.briarproject.briar.api.conversation.ConversationManager;
|
||||||
import org.briarproject.briar.api.identity.AuthorManager;
|
import org.briarproject.briar.api.identity.AuthorManager;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
@@ -24,7 +26,6 @@ import javax.annotation.concurrent.Immutable;
|
|||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
import static java.util.logging.Level.WARNING;
|
import static java.util.logging.Level.WARNING;
|
||||||
import static java.util.logging.Logger.getLogger;
|
|
||||||
import static org.briarproject.bramble.util.LogUtils.logException;
|
import static org.briarproject.bramble.util.LogUtils.logException;
|
||||||
|
|
||||||
@Immutable
|
@Immutable
|
||||||
@@ -33,17 +34,22 @@ class ShareBlogControllerImpl extends ContactSelectorControllerImpl
|
|||||||
implements ShareBlogController {
|
implements ShareBlogController {
|
||||||
|
|
||||||
private final static Logger LOG =
|
private final static Logger LOG =
|
||||||
getLogger(ShareBlogControllerImpl.class.getName());
|
Logger.getLogger(ShareBlogControllerImpl.class.getName());
|
||||||
|
|
||||||
|
private final ConversationManager conversationManager;
|
||||||
private final BlogSharingManager blogSharingManager;
|
private final BlogSharingManager blogSharingManager;
|
||||||
|
private final Clock clock;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
ShareBlogControllerImpl(@DatabaseExecutor Executor dbExecutor,
|
ShareBlogControllerImpl(@DatabaseExecutor Executor dbExecutor,
|
||||||
LifecycleManager lifecycleManager, ContactManager contactManager,
|
LifecycleManager lifecycleManager, ContactManager contactManager,
|
||||||
AuthorManager authorManager,
|
AuthorManager authorManager,
|
||||||
BlogSharingManager blogSharingManager) {
|
ConversationManager conversationManager,
|
||||||
|
BlogSharingManager blogSharingManager, Clock clock) {
|
||||||
super(dbExecutor, lifecycleManager, contactManager, authorManager);
|
super(dbExecutor, lifecycleManager, contactManager, authorManager);
|
||||||
|
this.conversationManager = conversationManager;
|
||||||
this.blogSharingManager = blogSharingManager;
|
this.blogSharingManager = blogSharingManager;
|
||||||
|
this.clock = clock;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -58,7 +64,10 @@ class ShareBlogControllerImpl extends ContactSelectorControllerImpl
|
|||||||
try {
|
try {
|
||||||
for (ContactId c : contacts) {
|
for (ContactId c : contacts) {
|
||||||
try {
|
try {
|
||||||
blogSharingManager.sendInvitation(g, c, text);
|
long time = Math.max(clock.currentTimeMillis(),
|
||||||
|
conversationManager.getGroupCount(c)
|
||||||
|
.getLatestMsgTime() + 1);
|
||||||
|
blogSharingManager.sendInvitation(g, c, text, time);
|
||||||
} catch (NoSuchContactException | NoSuchGroupException e) {
|
} catch (NoSuchContactException | NoSuchGroupException e) {
|
||||||
logException(LOG, WARNING, e);
|
logException(LOG, WARNING, e);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,8 +10,10 @@ import org.briarproject.bramble.api.db.NoSuchGroupException;
|
|||||||
import org.briarproject.bramble.api.lifecycle.LifecycleManager;
|
import org.briarproject.bramble.api.lifecycle.LifecycleManager;
|
||||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
import org.briarproject.bramble.api.sync.GroupId;
|
import org.briarproject.bramble.api.sync.GroupId;
|
||||||
|
import org.briarproject.bramble.api.system.Clock;
|
||||||
import org.briarproject.briar.android.contactselection.ContactSelectorControllerImpl;
|
import org.briarproject.briar.android.contactselection.ContactSelectorControllerImpl;
|
||||||
import org.briarproject.briar.android.controller.handler.ExceptionHandler;
|
import org.briarproject.briar.android.controller.handler.ExceptionHandler;
|
||||||
|
import org.briarproject.briar.api.conversation.ConversationManager;
|
||||||
import org.briarproject.briar.api.forum.ForumSharingManager;
|
import org.briarproject.briar.api.forum.ForumSharingManager;
|
||||||
import org.briarproject.briar.api.identity.AuthorManager;
|
import org.briarproject.briar.api.identity.AuthorManager;
|
||||||
|
|
||||||
@@ -24,7 +26,6 @@ import javax.annotation.concurrent.Immutable;
|
|||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
import static java.util.logging.Level.WARNING;
|
import static java.util.logging.Level.WARNING;
|
||||||
import static java.util.logging.Logger.getLogger;
|
|
||||||
import static org.briarproject.bramble.util.LogUtils.logException;
|
import static org.briarproject.bramble.util.LogUtils.logException;
|
||||||
|
|
||||||
@Immutable
|
@Immutable
|
||||||
@@ -33,17 +34,22 @@ class ShareForumControllerImpl extends ContactSelectorControllerImpl
|
|||||||
implements ShareForumController {
|
implements ShareForumController {
|
||||||
|
|
||||||
private final static Logger LOG =
|
private final static Logger LOG =
|
||||||
getLogger(ShareForumControllerImpl.class.getName());
|
Logger.getLogger(ShareForumControllerImpl.class.getName());
|
||||||
|
|
||||||
|
private final ConversationManager conversationManager;
|
||||||
private final ForumSharingManager forumSharingManager;
|
private final ForumSharingManager forumSharingManager;
|
||||||
|
private final Clock clock;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
ShareForumControllerImpl(@DatabaseExecutor Executor dbExecutor,
|
ShareForumControllerImpl(@DatabaseExecutor Executor dbExecutor,
|
||||||
LifecycleManager lifecycleManager, ContactManager contactManager,
|
LifecycleManager lifecycleManager, ContactManager contactManager,
|
||||||
AuthorManager authorManager,
|
AuthorManager authorManager,
|
||||||
ForumSharingManager forumSharingManager) {
|
ConversationManager conversationManager,
|
||||||
|
ForumSharingManager forumSharingManager, Clock clock) {
|
||||||
super(dbExecutor, lifecycleManager, contactManager, authorManager);
|
super(dbExecutor, lifecycleManager, contactManager, authorManager);
|
||||||
|
this.conversationManager = conversationManager;
|
||||||
this.forumSharingManager = forumSharingManager;
|
this.forumSharingManager = forumSharingManager;
|
||||||
|
this.clock = clock;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -58,7 +64,10 @@ class ShareForumControllerImpl extends ContactSelectorControllerImpl
|
|||||||
try {
|
try {
|
||||||
for (ContactId c : contacts) {
|
for (ContactId c : contacts) {
|
||||||
try {
|
try {
|
||||||
forumSharingManager.sendInvitation(g, c, text);
|
long time = Math.max(clock.currentTimeMillis(),
|
||||||
|
conversationManager.getGroupCount(c)
|
||||||
|
.getLatestMsgTime() + 1);
|
||||||
|
forumSharingManager.sendInvitation(g, c, text, time);
|
||||||
} catch (NoSuchContactException | NoSuchGroupException e) {
|
} catch (NoSuchContactException | NoSuchGroupException e) {
|
||||||
logException(LOG, WARNING, e);
|
logException(LOG, WARNING, e);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package org.briarproject.briar.android.splash;
|
package org.briarproject.briar.android.splash;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
@@ -7,6 +8,7 @@ import android.view.View;
|
|||||||
import android.view.View.OnClickListener;
|
import android.view.View.OnClickListener;
|
||||||
|
|
||||||
import org.briarproject.briar.R;
|
import org.briarproject.briar.R;
|
||||||
|
import org.briarproject.briar.android.Localizer;
|
||||||
|
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
|
||||||
@@ -27,6 +29,13 @@ public class ExpiredActivity extends AppCompatActivity
|
|||||||
findViewById(R.id.download_briar_button).setOnClickListener(this);
|
findViewById(R.id.download_briar_button).setOnClickListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void attachBaseContext(Context base) {
|
||||||
|
super.attachBaseContext(
|
||||||
|
Localizer.getInstance().setLocale(base));
|
||||||
|
Localizer.getInstance().setLocale(this);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
Uri uri = Uri.parse("https://briarproject.org/download.html");
|
Uri uri = Uri.parse("https://briarproject.org/download.html");
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ import org.briarproject.briar.android.view.BriarRecyclerView;
|
|||||||
import org.briarproject.briar.android.view.TextInputView;
|
import org.briarproject.briar.android.view.TextInputView;
|
||||||
import org.briarproject.briar.android.view.TextSendController;
|
import org.briarproject.briar.android.view.TextSendController;
|
||||||
import org.briarproject.briar.android.view.TextSendController.SendListener;
|
import org.briarproject.briar.android.view.TextSendController.SendListener;
|
||||||
import org.briarproject.briar.android.view.TextSendController.SendState;
|
|
||||||
import org.briarproject.briar.android.view.UnreadMessageButton;
|
import org.briarproject.briar.android.view.UnreadMessageButton;
|
||||||
import org.briarproject.briar.api.attachment.AttachmentHeader;
|
import org.briarproject.briar.api.attachment.AttachmentHeader;
|
||||||
|
|
||||||
@@ -30,13 +29,10 @@ import javax.annotation.Nullable;
|
|||||||
import androidx.annotation.CallSuper;
|
import androidx.annotation.CallSuper;
|
||||||
import androidx.annotation.StringRes;
|
import androidx.annotation.StringRes;
|
||||||
import androidx.appcompat.app.ActionBar;
|
import androidx.appcompat.app.ActionBar;
|
||||||
import androidx.lifecycle.LiveData;
|
|
||||||
import androidx.lifecycle.MutableLiveData;
|
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||||
|
|
||||||
import static androidx.recyclerview.widget.RecyclerView.NO_POSITION;
|
import static androidx.recyclerview.widget.RecyclerView.NO_POSITION;
|
||||||
import static org.briarproject.bramble.util.StringUtils.isNullOrEmpty;
|
import static org.briarproject.bramble.util.StringUtils.isNullOrEmpty;
|
||||||
import static org.briarproject.briar.android.view.TextSendController.SendState.SENT;
|
|
||||||
|
|
||||||
@MethodsNotNullByDefault
|
@MethodsNotNullByDefault
|
||||||
@ParametersNotNullByDefault
|
@ParametersNotNullByDefault
|
||||||
@@ -235,8 +231,8 @@ public abstract class ThreadListActivity<I extends ThreadItem, A extends ThreadI
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LiveData<SendState> onSendClick(@Nullable String text,
|
public void onSendClick(@Nullable String text,
|
||||||
List<AttachmentHeader> headers, long expectedAutoDeleteTimer) {
|
List<AttachmentHeader> headers) {
|
||||||
if (isNullOrEmpty(text)) throw new AssertionError();
|
if (isNullOrEmpty(text)) throw new AssertionError();
|
||||||
|
|
||||||
MessageId replyId = getViewModel().getReplyId();
|
MessageId replyId = getViewModel().getReplyId();
|
||||||
@@ -245,7 +241,6 @@ public abstract class ThreadListActivity<I extends ThreadItem, A extends ThreadI
|
|||||||
textInput.clearText();
|
textInput.clearText();
|
||||||
getViewModel().setReplyId(null);
|
getViewModel().setReplyId(null);
|
||||||
updateTextInput();
|
updateTextInput();
|
||||||
return new MutableLiveData<>(SENT);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract int getMaxTextLength();
|
protected abstract int getMaxTextLength();
|
||||||
|
|||||||
@@ -197,6 +197,10 @@ public abstract class ThreadListViewModel<I extends ThreadItem>
|
|||||||
*/
|
*/
|
||||||
@UiThread
|
@UiThread
|
||||||
protected void addItem(I item, boolean scrollToItem) {
|
protected void addItem(I item, boolean scrollToItem) {
|
||||||
|
// If items haven't loaded, we need to wait until they have.
|
||||||
|
// Since this was a R/W DB transaction, the load will pick up this item.
|
||||||
|
if (items.getValue() == null) return;
|
||||||
|
|
||||||
messageTree.add(item);
|
messageTree.add(item);
|
||||||
if (scrollToItem) this.scrollToItem.set(item.getId());
|
if (scrollToItem) this.scrollToItem.set(item.getId());
|
||||||
items.setValue(new LiveResult<>(messageTree.depthFirstOrder()));
|
items.setValue(new LiveResult<>(messageTree.depthFirstOrder()));
|
||||||
|
|||||||
@@ -97,6 +97,7 @@ import static java.util.concurrent.TimeUnit.DAYS;
|
|||||||
import static org.briarproject.bramble.util.AndroidUtils.getSupportedImageContentTypes;
|
import static org.briarproject.bramble.util.AndroidUtils.getSupportedImageContentTypes;
|
||||||
import static org.briarproject.briar.BuildConfig.APPLICATION_ID;
|
import static org.briarproject.briar.BuildConfig.APPLICATION_ID;
|
||||||
import static org.briarproject.briar.android.TestingConstants.EXPIRY_DATE;
|
import static org.briarproject.briar.android.TestingConstants.EXPIRY_DATE;
|
||||||
|
import static org.briarproject.briar.android.reporting.CrashReportActivity.EXTRA_APP_LOGCAT;
|
||||||
import static org.briarproject.briar.android.reporting.CrashReportActivity.EXTRA_APP_START_TIME;
|
import static org.briarproject.briar.android.reporting.CrashReportActivity.EXTRA_APP_START_TIME;
|
||||||
import static org.briarproject.briar.android.reporting.CrashReportActivity.EXTRA_THROWABLE;
|
import static org.briarproject.briar.android.reporting.CrashReportActivity.EXTRA_THROWABLE;
|
||||||
|
|
||||||
@@ -357,16 +358,17 @@ public class UiUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void triggerFeedback(Context ctx) {
|
public static void triggerFeedback(Context ctx) {
|
||||||
startDevReportActivity(ctx, FeedbackActivity.class, null, null);
|
startDevReportActivity(ctx, FeedbackActivity.class, null, null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void startDevReportActivity(Context ctx,
|
public static void startDevReportActivity(Context ctx,
|
||||||
Class<? extends FragmentActivity> activity, @Nullable Throwable t,
|
Class<? extends FragmentActivity> activity, @Nullable Throwable t,
|
||||||
@Nullable Long appStartTime) {
|
@Nullable Long appStartTime, @Nullable byte[] logKey) {
|
||||||
final Intent dialogIntent = new Intent(ctx, activity);
|
final Intent dialogIntent = new Intent(ctx, activity);
|
||||||
dialogIntent.setFlags(FLAG_ACTIVITY_NEW_TASK);
|
dialogIntent.setFlags(FLAG_ACTIVITY_NEW_TASK);
|
||||||
dialogIntent.putExtra(EXTRA_THROWABLE, t);
|
dialogIntent.putExtra(EXTRA_THROWABLE, t);
|
||||||
dialogIntent.putExtra(EXTRA_APP_START_TIME, appStartTime);
|
dialogIntent.putExtra(EXTRA_APP_START_TIME, appStartTime);
|
||||||
|
dialogIntent.putExtra(EXTRA_APP_LOGCAT, logKey);
|
||||||
ctx.startActivity(dialogIntent);
|
ctx.startActivity(dialogIntent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import android.util.AttributeSet;
|
|||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.FrameLayout;
|
import android.widget.FrameLayout;
|
||||||
import android.widget.ImageView;
|
|
||||||
import android.widget.ProgressBar;
|
import android.widget.ProgressBar;
|
||||||
|
|
||||||
import org.briarproject.briar.R;
|
import org.briarproject.briar.R;
|
||||||
@@ -20,7 +19,6 @@ import static java.util.Objects.requireNonNull;
|
|||||||
public class CompositeSendButton extends FrameLayout {
|
public class CompositeSendButton extends FrameLayout {
|
||||||
|
|
||||||
private final AppCompatImageButton sendButton, imageButton;
|
private final AppCompatImageButton sendButton, imageButton;
|
||||||
private final ImageView bombBadge;
|
|
||||||
private final ProgressBar progressBar;
|
private final ProgressBar progressBar;
|
||||||
|
|
||||||
private boolean hasImageSupport = false;
|
private boolean hasImageSupport = false;
|
||||||
@@ -34,7 +32,6 @@ public class CompositeSendButton extends FrameLayout {
|
|||||||
|
|
||||||
sendButton = findViewById(R.id.sendButton);
|
sendButton = findViewById(R.id.sendButton);
|
||||||
imageButton = findViewById(R.id.imageButton);
|
imageButton = findViewById(R.id.imageButton);
|
||||||
bombBadge = findViewById(R.id.bombBadge);
|
|
||||||
progressBar = findViewById(R.id.progressBar);
|
progressBar = findViewById(R.id.progressBar);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -74,10 +71,6 @@ public class CompositeSendButton extends FrameLayout {
|
|||||||
return hasImageSupport;
|
return hasImageSupport;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setBombVisible(boolean visible) {
|
|
||||||
bombBadge.setVisibility(visible ? VISIBLE : INVISIBLE);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void showImageButton(boolean showImageButton, boolean sendEnabled) {
|
public void showImageButton(boolean showImageButton, boolean sendEnabled) {
|
||||||
if (showImageButton) {
|
if (showImageButton) {
|
||||||
imageButton.setVisibility(VISIBLE);
|
imageButton.setVisibility(VISIBLE);
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ import androidx.annotation.Nullable;
|
|||||||
import androidx.annotation.UiThread;
|
import androidx.annotation.UiThread;
|
||||||
import androidx.appcompat.app.AlertDialog.Builder;
|
import androidx.appcompat.app.AlertDialog.Builder;
|
||||||
import androidx.customview.view.AbsSavedState;
|
import androidx.customview.view.AbsSavedState;
|
||||||
|
import androidx.lifecycle.LifecycleOwner;
|
||||||
import androidx.lifecycle.LiveData;
|
import androidx.lifecycle.LiveData;
|
||||||
import androidx.lifecycle.Observer;
|
import androidx.lifecycle.Observer;
|
||||||
import androidx.vectordrawable.graphics.drawable.VectorDrawableCompat;
|
import androidx.vectordrawable.graphics.drawable.VectorDrawableCompat;
|
||||||
@@ -38,7 +39,6 @@ import static androidx.core.content.ContextCompat.getColor;
|
|||||||
import static androidx.customview.view.AbsSavedState.EMPTY_STATE;
|
import static androidx.customview.view.AbsSavedState.EMPTY_STATE;
|
||||||
import static androidx.lifecycle.Lifecycle.State.DESTROYED;
|
import static androidx.lifecycle.Lifecycle.State.DESTROYED;
|
||||||
import static org.briarproject.briar.android.util.UiUtils.resolveColorAttribute;
|
import static org.briarproject.briar.android.util.UiUtils.resolveColorAttribute;
|
||||||
import static org.briarproject.briar.android.view.TextSendController.SendState.SENT;
|
|
||||||
import static org.briarproject.briar.api.messaging.MessagingConstants.MAX_ATTACHMENTS_PER_MESSAGE;
|
import static org.briarproject.briar.api.messaging.MessagingConstants.MAX_ATTACHMENTS_PER_MESSAGE;
|
||||||
|
|
||||||
@UiThread
|
@UiThread
|
||||||
@@ -52,6 +52,7 @@ public class TextAttachmentController extends TextSendController
|
|||||||
private final AttachmentManager attachmentManager;
|
private final AttachmentManager attachmentManager;
|
||||||
|
|
||||||
private final List<Uri> imageUris = new ArrayList<>();
|
private final List<Uri> imageUris = new ArrayList<>();
|
||||||
|
private final CharSequence textHint;
|
||||||
private boolean loadingUris = false;
|
private boolean loadingUris = false;
|
||||||
|
|
||||||
public TextAttachmentController(TextInputView v, ImagePreview imagePreview,
|
public TextAttachmentController(TextInputView v, ImagePreview imagePreview,
|
||||||
@@ -65,44 +66,23 @@ public class TextAttachmentController extends TextSendController
|
|||||||
|
|
||||||
sendButton = (CompositeSendButton) compositeSendButton;
|
sendButton = (CompositeSendButton) compositeSendButton;
|
||||||
sendButton.setOnImageClickListener(view -> onImageButtonClicked());
|
sendButton.setOnImageClickListener(view -> onImageButtonClicked());
|
||||||
|
|
||||||
|
textHint = textInput.getHint();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void updateViewState() {
|
protected void updateViewState() {
|
||||||
super.updateViewState();
|
textInput.setEnabled(ready && !loadingUris);
|
||||||
|
boolean sendEnabled = ready && !loadingUris &&
|
||||||
|
(!textIsEmpty || canSendEmptyText());
|
||||||
if (loadingUris) {
|
if (loadingUris) {
|
||||||
sendButton.showProgress(true);
|
sendButton.showProgress(true);
|
||||||
} else if (imageUris.isEmpty()) {
|
} else if (imageUris.isEmpty()) {
|
||||||
sendButton.showProgress(false);
|
sendButton.showProgress(false);
|
||||||
sendButton.showImageButton(textIsEmpty, isSendButtonEnabled());
|
sendButton.showImageButton(textIsEmpty, sendEnabled);
|
||||||
} else {
|
} else {
|
||||||
sendButton.showProgress(false);
|
sendButton.showProgress(false);
|
||||||
sendButton.showImageButton(false, isSendButtonEnabled());
|
sendButton.showImageButton(false, sendEnabled);
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected boolean isTextInputEnabled() {
|
|
||||||
return super.isTextInputEnabled() && !loadingUris;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected boolean isSendButtonEnabled() {
|
|
||||||
return super.isSendButtonEnabled() && !loadingUris;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected boolean isBombVisible() {
|
|
||||||
return super.isBombVisible() && (!textIsEmpty || !imageUris.isEmpty());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected CharSequence getCurrentTextHint() {
|
|
||||||
if (imageUris.isEmpty()) {
|
|
||||||
return super.getCurrentTextHint();
|
|
||||||
} else {
|
|
||||||
Context ctx = textInput.getContext();
|
|
||||||
return ctx.getString(R.string.image_caption_hint);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -111,17 +91,11 @@ public class TextAttachmentController extends TextSendController
|
|||||||
if (canSend()) {
|
if (canSend()) {
|
||||||
if (loadingUris) throw new AssertionError();
|
if (loadingUris) throw new AssertionError();
|
||||||
listener.onSendClick(textInput.getText(),
|
listener.onSendClick(textInput.getText(),
|
||||||
attachmentManager.getAttachmentHeadersForSending(),
|
attachmentManager.getAttachmentHeadersForSending());
|
||||||
expectedTimer).observe(listener, this::onSendStateChanged);
|
reset();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onSendStateChanged(SendState sendState) {
|
|
||||||
super.onSendStateChanged(sendState);
|
|
||||||
if (sendState == SENT) reset();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean canSendEmptyText() {
|
protected boolean canSendEmptyText() {
|
||||||
return !imageUris.isEmpty();
|
return !imageUris.isEmpty();
|
||||||
@@ -180,7 +154,6 @@ public class TextAttachmentController extends TextSendController
|
|||||||
private void onNewUris(boolean restart, List<Uri> newUris) {
|
private void onNewUris(boolean restart, List<Uri> newUris) {
|
||||||
if (newUris.isEmpty()) return;
|
if (newUris.isEmpty()) return;
|
||||||
if (loadingUris) throw new AssertionError();
|
if (loadingUris) throw new AssertionError();
|
||||||
if (textIsEmpty) onStartingMessage();
|
|
||||||
loadingUris = true;
|
loadingUris = true;
|
||||||
if (newUris.size() > MAX_ATTACHMENTS_PER_MESSAGE) {
|
if (newUris.size() > MAX_ATTACHMENTS_PER_MESSAGE) {
|
||||||
newUris = newUris.subList(0, MAX_ATTACHMENTS_PER_MESSAGE);
|
newUris = newUris.subList(0, MAX_ATTACHMENTS_PER_MESSAGE);
|
||||||
@@ -188,6 +161,7 @@ public class TextAttachmentController extends TextSendController
|
|||||||
}
|
}
|
||||||
imageUris.addAll(newUris);
|
imageUris.addAll(newUris);
|
||||||
updateViewState();
|
updateViewState();
|
||||||
|
textInput.setHint(R.string.image_caption_hint);
|
||||||
List<ImagePreviewItem> items = ImagePreviewItem.fromUris(imageUris);
|
List<ImagePreviewItem> items = ImagePreviewItem.fromUris(imageUris);
|
||||||
imagePreview.showPreview(items);
|
imagePreview.showPreview(items);
|
||||||
// store attachments and show preview when successful
|
// store attachments and show preview when successful
|
||||||
@@ -233,6 +207,8 @@ public class TextAttachmentController extends TextSendController
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void reset() {
|
private void reset() {
|
||||||
|
// restore hint
|
||||||
|
textInput.setHint(textHint);
|
||||||
// hide image layout
|
// hide image layout
|
||||||
imagePreview.setVisibility(GONE);
|
imagePreview.setVisibility(GONE);
|
||||||
// reset image URIs
|
// reset image URIs
|
||||||
@@ -327,7 +303,7 @@ public class TextAttachmentController extends TextSendController
|
|||||||
}
|
}
|
||||||
|
|
||||||
@UiThread
|
@UiThread
|
||||||
public interface AttachmentListener extends SendListener {
|
public interface AttachmentListener extends SendListener, LifecycleOwner {
|
||||||
|
|
||||||
void onAttachImage(Intent intent);
|
void onAttachImage(Intent intent);
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,7 @@
|
|||||||
package org.briarproject.briar.android.view;
|
package org.briarproject.briar.android.view;
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.Toast;
|
|
||||||
|
|
||||||
import com.google.android.material.snackbar.Snackbar;
|
import com.google.android.material.snackbar.Snackbar;
|
||||||
|
|
||||||
@@ -14,20 +12,11 @@ import org.briarproject.briar.api.attachment.AttachmentHeader;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import androidx.annotation.CallSuper;
|
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.annotation.UiThread;
|
import androidx.annotation.UiThread;
|
||||||
import androidx.appcompat.app.AlertDialog;
|
|
||||||
import androidx.lifecycle.LifecycleOwner;
|
|
||||||
import androidx.lifecycle.LiveData;
|
|
||||||
|
|
||||||
import static android.widget.Toast.LENGTH_LONG;
|
|
||||||
import static com.google.android.material.snackbar.Snackbar.LENGTH_SHORT;
|
import static com.google.android.material.snackbar.Snackbar.LENGTH_SHORT;
|
||||||
import static java.util.Collections.emptyList;
|
import static java.util.Collections.emptyList;
|
||||||
import static org.briarproject.briar.android.view.TextSendController.SendState.ERROR;
|
|
||||||
import static org.briarproject.briar.android.view.TextSendController.SendState.SENT;
|
|
||||||
import static org.briarproject.briar.android.view.TextSendController.SendState.UNEXPECTED_TIMER;
|
|
||||||
import static org.briarproject.briar.api.autodelete.AutoDeleteConstants.NO_AUTO_DELETE_TIMER;
|
|
||||||
|
|
||||||
@UiThread
|
@UiThread
|
||||||
@NotNullByDefault
|
@NotNullByDefault
|
||||||
@@ -37,12 +26,8 @@ public class TextSendController implements TextInputListener {
|
|||||||
protected final View compositeSendButton;
|
protected final View compositeSendButton;
|
||||||
protected final SendListener listener;
|
protected final SendListener listener;
|
||||||
|
|
||||||
protected boolean textIsEmpty = true;
|
protected boolean ready = true, textIsEmpty = true;
|
||||||
private boolean ready = true;
|
|
||||||
private long currentTimer = NO_AUTO_DELETE_TIMER;
|
|
||||||
protected long expectedTimer = NO_AUTO_DELETE_TIMER;
|
|
||||||
|
|
||||||
private final CharSequence defaultHint;
|
|
||||||
private final boolean allowEmptyText;
|
private final boolean allowEmptyText;
|
||||||
|
|
||||||
public TextSendController(TextInputView v, SendListener listener,
|
public TextSendController(TextInputView v, SendListener listener,
|
||||||
@@ -51,91 +36,31 @@ public class TextSendController implements TextInputListener {
|
|||||||
this.compositeSendButton.setOnClickListener(view -> onSendEvent());
|
this.compositeSendButton.setOnClickListener(view -> onSendEvent());
|
||||||
this.listener = listener;
|
this.listener = listener;
|
||||||
this.textInput = v.getEmojiTextInputView();
|
this.textInput = v.getEmojiTextInputView();
|
||||||
this.defaultHint = textInput.getHint();
|
|
||||||
this.allowEmptyText = allowEmptyText;
|
this.allowEmptyText = allowEmptyText;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onTextIsEmptyChanged(boolean isEmpty) {
|
public void onTextIsEmptyChanged(boolean isEmpty) {
|
||||||
textIsEmpty = isEmpty;
|
textIsEmpty = isEmpty;
|
||||||
if (!isEmpty) onStartingMessage();
|
|
||||||
updateViewState();
|
updateViewState();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSendEvent() {
|
public void onSendEvent() {
|
||||||
if (canSend()) {
|
if (canSend()) {
|
||||||
listener.onSendClick(textInput.getText(), emptyList(),
|
listener.onSendClick(textInput.getText(), emptyList());
|
||||||
expectedTimer).observe(listener, this::onSendStateChanged);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@CallSuper
|
|
||||||
protected void onSendStateChanged(SendState sendState) {
|
|
||||||
if (sendState == SENT) {
|
|
||||||
textInput.clearText();
|
|
||||||
} else if (sendState == UNEXPECTED_TIMER) {
|
|
||||||
boolean enabled = expectedTimer == NO_AUTO_DELETE_TIMER;
|
|
||||||
showTimerChangedDialog(enabled);
|
|
||||||
} else if (sendState == ERROR) {
|
|
||||||
Toast.makeText(textInput.getContext(), R.string.message_error,
|
|
||||||
LENGTH_LONG).show();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Call whenever the user starts a new message,
|
|
||||||
* either by entering text or adding an attachment.
|
|
||||||
* This updates the expected auto-delete timer to the current value.
|
|
||||||
*/
|
|
||||||
protected void onStartingMessage() {
|
|
||||||
expectedTimer = currentTimer;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setReady(boolean ready) {
|
public void setReady(boolean ready) {
|
||||||
this.ready = ready;
|
this.ready = ready;
|
||||||
updateViewState();
|
updateViewState();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the current auto delete timer and updates the UI accordingly.
|
|
||||||
*/
|
|
||||||
public void setAutoDeleteTimer(long timer) {
|
|
||||||
currentTimer = timer;
|
|
||||||
updateViewState();
|
|
||||||
}
|
|
||||||
|
|
||||||
@CallSuper
|
|
||||||
protected void updateViewState() {
|
protected void updateViewState() {
|
||||||
textInput.setEnabled(isTextInputEnabled());
|
textInput.setEnabled(ready);
|
||||||
textInput.setHint(getCurrentTextHint());
|
compositeSendButton
|
||||||
compositeSendButton.setEnabled(isSendButtonEnabled());
|
.setEnabled(ready && (!textIsEmpty || canSendEmptyText()));
|
||||||
if (compositeSendButton instanceof CompositeSendButton) {
|
|
||||||
CompositeSendButton sendButton =
|
|
||||||
(CompositeSendButton) compositeSendButton;
|
|
||||||
sendButton.setBombVisible(isBombVisible());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected boolean isTextInputEnabled() {
|
|
||||||
return ready;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected boolean isSendButtonEnabled() {
|
|
||||||
return ready && (!textIsEmpty || canSendEmptyText());
|
|
||||||
}
|
|
||||||
|
|
||||||
protected boolean isBombVisible() {
|
|
||||||
return currentTimer != NO_AUTO_DELETE_TIMER;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected CharSequence getCurrentTextHint() {
|
|
||||||
if (currentTimer == NO_AUTO_DELETE_TIMER) {
|
|
||||||
return defaultHint;
|
|
||||||
} else {
|
|
||||||
Context ctx = textInput.getContext();
|
|
||||||
return ctx.getString(R.string.message_hint_auto_delete);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected final boolean canSend() {
|
protected final boolean canSend() {
|
||||||
@@ -151,23 +76,6 @@ public class TextSendController implements TextInputListener {
|
|||||||
return allowEmptyText;
|
return allowEmptyText;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showTimerChangedDialog(boolean enabled) {
|
|
||||||
Context ctx = textInput.getContext();
|
|
||||||
int message =
|
|
||||||
enabled ? R.string.auto_delete_changed_warning_message_enabled :
|
|
||||||
R.string.auto_delete_changed_warning_message_disabled;
|
|
||||||
new AlertDialog.Builder(ctx, R.style.BriarDialogTheme)
|
|
||||||
.setTitle(R.string.auto_delete_changed_warning_title)
|
|
||||||
.setMessage(message)
|
|
||||||
.setPositiveButton(R.string.auto_delete_changed_warning_send,
|
|
||||||
(dialog, which) -> {
|
|
||||||
expectedTimer = currentTimer;
|
|
||||||
onSendEvent();
|
|
||||||
})
|
|
||||||
.setNegativeButton(R.string.cancel, null)
|
|
||||||
.show();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public Parcelable onSaveInstanceState(@Nullable Parcelable superState) {
|
public Parcelable onSaveInstanceState(@Nullable Parcelable superState) {
|
||||||
return superState;
|
return superState;
|
||||||
@@ -178,11 +86,9 @@ public class TextSendController implements TextInputListener {
|
|||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum SendState {SENT, ERROR, UNEXPECTED_TIMER}
|
@UiThread
|
||||||
|
public interface SendListener {
|
||||||
public interface SendListener extends LifecycleOwner {
|
void onSendClick(@Nullable String text, List<AttachmentHeader> headers);
|
||||||
LiveData<SendState> onSendClick(@Nullable String text,
|
|
||||||
List<AttachmentHeader> headers, long expectedAutoDeleteTimer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,7 +39,8 @@ public interface AndroidNotificationManager {
|
|||||||
String BLOG_CHANNEL_ID = "blogs";
|
String BLOG_CHANNEL_ID = "blogs";
|
||||||
// Channels are sorted by channel ID in the Settings app, so use IDs
|
// Channels are sorted by channel ID in the Settings app, so use IDs
|
||||||
// that will sort below the main channels such as contacts
|
// that will sort below the main channels such as contacts
|
||||||
String ONGOING_CHANNEL_ID = "zForegroundService";
|
String ONGOING_CHANNEL_OLD_ID = "zForegroundService";
|
||||||
|
String ONGOING_CHANNEL_ID = "zForegroundService2";
|
||||||
String FAILURE_CHANNEL_ID = "zStartupFailure";
|
String FAILURE_CHANNEL_ID = "zStartupFailure";
|
||||||
String REMINDER_CHANNEL_ID = "zSignInReminder";
|
String REMINDER_CHANNEL_ID = "zSignInReminder";
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +0,0 @@
|
|||||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
android:width="16dp"
|
|
||||||
android:height="16dp"
|
|
||||||
android:viewportWidth="24"
|
|
||||||
android:viewportHeight="24">
|
|
||||||
<path
|
|
||||||
android:fillColor="#FFFFFF"
|
|
||||||
android:pathData="M11.25,6A3.25,3.25 0 0,1 14.5,2.75A3.25,3.25 0 0,1 17.75,6C17.75,6.42 18.08,6.75 18.5,6.75C18.92,6.75 19.25,6.42 19.25,6V5.25H20.75V6A2.25,2.25 0 0,1 18.5,8.25A2.25,2.25 0 0,1 16.25,6A1.75,1.75 0 0,0 14.5,4.25A1.75,1.75 0 0,0 12.75,6H14V7.29C16.89,8.15 19,10.83 19,14A7,7 0 0,1 12,21A7,7 0 0,1 5,14C5,10.83 7.11,8.15 10,7.29V6H11.25M22,6H24V7H22V6M19,4V2H20V4H19M20.91,4.38L22.33,2.96L23.04,3.67L21.62,5.09L20.91,4.38Z" />
|
|
||||||
</vector>
|
|
||||||
@@ -1,71 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent">
|
|
||||||
|
|
||||||
<androidx.appcompat.widget.Toolbar
|
|
||||||
android:id="@+id/toolbar"
|
|
||||||
style="@style/BriarToolbar"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
|
||||||
app:layout_constraintTop_toTopOf="parent"
|
|
||||||
app:navigationIcon="@drawable/abc_ic_ab_back_material"
|
|
||||||
app:title="@string/disappearing_messages_title" />
|
|
||||||
|
|
||||||
<ScrollView
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="0dp"
|
|
||||||
android:paddingHorizontal="@dimen/margin_large"
|
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
|
||||||
app:layout_constraintTop_toBottomOf="@id/toolbar">
|
|
||||||
|
|
||||||
<androidx.constraintlayout.widget.ConstraintLayout
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content">
|
|
||||||
|
|
||||||
<ImageView
|
|
||||||
android:id="@+id/imageViewBomb"
|
|
||||||
android:layout_width="64dp"
|
|
||||||
android:layout_height="64dp"
|
|
||||||
android:layout_marginTop="16dp"
|
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
|
||||||
app:layout_constraintTop_toTopOf="parent"
|
|
||||||
app:srcCompat="@drawable/ic_bomb"
|
|
||||||
app:tint="?attr/colorControlNormal"
|
|
||||||
tools:ignore="ContentDescription" />
|
|
||||||
|
|
||||||
<androidx.appcompat.widget.SwitchCompat
|
|
||||||
android:id="@+id/switchDisappearingMessages"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginTop="16dp"
|
|
||||||
android:enabled="false"
|
|
||||||
android:text="@string/disappearing_messages_summary"
|
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
|
||||||
app:layout_constraintTop_toBottomOf="@+id/imageViewBomb" />
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/buttonLearnMore"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginTop="@dimen/margin_large"
|
|
||||||
android:clickable="true"
|
|
||||||
android:focusable="true"
|
|
||||||
android:text="@string/learn_more"
|
|
||||||
android:textColor="@color/briar_text_link"
|
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
|
||||||
app:layout_constraintTop_toBottomOf="@+id/switchDisappearingMessages" />
|
|
||||||
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
|
||||||
|
|
||||||
</ScrollView>
|
|
||||||
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
android:paddingHorizontal="?dialogPreferredPadding">
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/textView"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:text="@string/disappearing_messages_explanation_long"
|
|
||||||
android:textColor="?android:attr/textColorSecondary"
|
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
|
||||||
app:layout_constraintTop_toTopOf="parent" />
|
|
||||||
|
|
||||||
</ScrollView>
|
|
||||||
@@ -112,7 +112,6 @@
|
|||||||
android:textColor="@color/briar_primary"
|
android:textColor="@color/briar_primary"
|
||||||
android:textIsSelectable="true"
|
android:textIsSelectable="true"
|
||||||
android:textSize="18sp"
|
android:textSize="18sp"
|
||||||
android:typeface="monospace"
|
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toBottomOf="@+id/yourLinkIcon"
|
app:layout_constraintTop_toBottomOf="@+id/yourLinkIcon"
|
||||||
|
|||||||
@@ -139,10 +139,10 @@
|
|||||||
<Space
|
<Space
|
||||||
android:id="@+id/space"
|
android:id="@+id/space"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="0dp"
|
android:layout_height="wrap_content"
|
||||||
|
app:layout_constrainedHeight="true"
|
||||||
app:layout_constraintBottom_toTopOf="@+id/addButton"
|
app:layout_constraintBottom_toTopOf="@+id/addButton"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
app:layout_constraintHeight_default="wrap"
|
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toBottomOf="@+id/contactNameLayout" />
|
app:layout_constraintTop_toBottomOf="@+id/contactNameLayout" />
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
|
||||||
<!-- This layout is only used indirectly by cloning and setting its ConstraintSet -->
|
|
||||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
@@ -70,16 +68,6 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
tools:text="Dec 24, 13:37" />
|
tools:text="Dec 24, 13:37" />
|
||||||
|
|
||||||
<ImageView
|
|
||||||
android:id="@+id/bomb"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginStart="4dp"
|
|
||||||
android:layout_marginEnd="4dp"
|
|
||||||
app:srcCompat="@drawable/ic_bomb"
|
|
||||||
app:tint="?android:attr/textColorSecondary"
|
|
||||||
tools:ignore="ContentDescription" />
|
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
|
||||||
<!-- This layout is only used indirectly by cloning and setting its ConstraintSet -->
|
|
||||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
@@ -60,8 +58,7 @@
|
|||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
app:layout_constraintHorizontal_bias="1.0"
|
app:layout_constraintHorizontal_bias="1.0"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toBottomOf="@+id/text"
|
app:layout_constraintTop_toBottomOf="@+id/text">
|
||||||
tools:ignore="UseCompoundDrawables">
|
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/time"
|
android:id="@+id/time"
|
||||||
@@ -70,16 +67,6 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
tools:text="Dec 24, 13:37" />
|
tools:text="Dec 24, 13:37" />
|
||||||
|
|
||||||
<ImageView
|
|
||||||
android:id="@+id/bomb"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginStart="4dp"
|
|
||||||
android:layout_marginEnd="4dp"
|
|
||||||
app:srcCompat="@drawable/ic_bomb"
|
|
||||||
app:tint="?android:attr/textColorSecondary"
|
|
||||||
tools:ignore="ContentDescription" />
|
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
|
|||||||
@@ -1,19 +1,14 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:background="@drawable/list_item_background_selectable"
|
android:background="@drawable/list_item_background_selectable">
|
||||||
android:orientation="vertical">
|
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
We need to wrap the actual layout, because we want to
|
We need to wrap the actual layout, because
|
||||||
* clone the ConstraintLayout's constraints in the ViewHolder
|
* we want to clone the ConstraintLayout's constraints in the ViewHolder
|
||||||
* have a selectable frame around the message bubble
|
* we want to have a selectable frame around the message bubble
|
||||||
* insert a top notice with its own independent width
|
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<include layout="@layout/list_item_conversation_top_notice_in" />
|
|
||||||
|
|
||||||
<include layout="@layout/list_item_conversation_msg_in_content" />
|
<include layout="@layout/list_item_conversation_msg_in_content" />
|
||||||
|
|
||||||
</LinearLayout>
|
</FrameLayout>
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
|
||||||
<!-- This layout gets wrapped in *_msg_in.xml -->
|
|
||||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
@@ -70,17 +68,6 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
tools:text="Dec 24, 13:37" />
|
tools:text="Dec 24, 13:37" />
|
||||||
|
|
||||||
<ImageView
|
|
||||||
android:id="@+id/bomb"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginStart="4dp"
|
|
||||||
android:layout_marginLeft="4dp"
|
|
||||||
app:srcCompat="@drawable/ic_bomb"
|
|
||||||
app:tint="?android:attr/textColorSecondary"
|
|
||||||
tools:ignore="ContentDescription"
|
|
||||||
tools:visibility="visible" />
|
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
|
|||||||
@@ -1,14 +1,10 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:background="@drawable/list_item_background_selectable"
|
android:background="@drawable/list_item_background_selectable">
|
||||||
android:orientation="vertical"
|
|
||||||
android:paddingTop="@dimen/message_bubble_margin">
|
|
||||||
|
|
||||||
<include layout="@layout/list_item_conversation_top_notice_out" />
|
|
||||||
|
|
||||||
<androidx.constraintlayout.widget.ConstraintLayout
|
<androidx.constraintlayout.widget.ConstraintLayout
|
||||||
android:id="@+id/layout"
|
android:id="@+id/layout"
|
||||||
@@ -77,26 +73,15 @@
|
|||||||
style="@style/TextMessage.Timestamp"
|
style="@style/TextMessage.Timestamp"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginEnd="4dp"
|
android:layout_marginEnd="6dp"
|
||||||
android:layout_marginRight="4dp"
|
android:layout_marginRight="6dp"
|
||||||
android:textColor="@color/private_message_date_inverse"
|
android:textColor="@color/private_message_date_inverse"
|
||||||
tools:text="Dec 24, 13:37" />
|
tools:text="Dec 24, 13:37" />
|
||||||
|
|
||||||
<ImageView
|
|
||||||
android:id="@+id/bomb"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginEnd="4dp"
|
|
||||||
android:layout_marginRight="4dp"
|
|
||||||
app:srcCompat="@drawable/ic_bomb"
|
|
||||||
app:tint="@color/private_message_date_inverse"
|
|
||||||
tools:ignore="ContentDescription" />
|
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:id="@+id/status"
|
android:id="@+id/status"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
app:tint="@color/private_message_date_inverse"
|
|
||||||
tools:ignore="ContentDescription"
|
tools:ignore="ContentDescription"
|
||||||
tools:src="@drawable/message_delivered" />
|
tools:src="@drawable/message_delivered" />
|
||||||
|
|
||||||
@@ -104,4 +89,4 @@
|
|||||||
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
|
|
||||||
</LinearLayout>
|
</FrameLayout>
|
||||||
@@ -5,9 +5,8 @@
|
|||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:background="@drawable/list_item_background_selectable"
|
android:background="@drawable/list_item_background_selectable"
|
||||||
android:orientation="vertical">
|
android:orientation="vertical"
|
||||||
|
android:paddingTop="@dimen/message_bubble_margin">
|
||||||
<include layout="@layout/list_item_conversation_top_notice_in" />
|
|
||||||
|
|
||||||
<com.vanniktech.emoji.EmojiTextView
|
<com.vanniktech.emoji.EmojiTextView
|
||||||
android:id="@+id/msgText"
|
android:id="@+id/msgText"
|
||||||
@@ -16,13 +15,11 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginStart="@dimen/message_bubble_margin_tail"
|
android:layout_marginStart="@dimen/message_bubble_margin_tail"
|
||||||
android:layout_marginLeft="@dimen/message_bubble_margin_tail"
|
android:layout_marginLeft="@dimen/message_bubble_margin_tail"
|
||||||
android:layout_marginTop="@dimen/message_bubble_margin"
|
|
||||||
android:layout_marginEnd="@dimen/message_bubble_margin_non_tail"
|
android:layout_marginEnd="@dimen/message_bubble_margin_non_tail"
|
||||||
android:layout_marginRight="@dimen/message_bubble_margin_non_tail"
|
android:layout_marginRight="@dimen/message_bubble_margin_non_tail"
|
||||||
android:background="@drawable/msg_in_top"
|
android:background="@drawable/msg_in_top"
|
||||||
android:elevation="@dimen/message_bubble_elevation"
|
android:elevation="@dimen/message_bubble_elevation"
|
||||||
tools:text="Short message"
|
tools:text="Short message" />
|
||||||
tools:visibility="visible" />
|
|
||||||
|
|
||||||
<androidx.constraintlayout.widget.ConstraintLayout
|
<androidx.constraintlayout.widget.ConstraintLayout
|
||||||
android:id="@+id/layout"
|
android:id="@+id/layout"
|
||||||
@@ -51,28 +48,10 @@
|
|||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginTop="@dimen/message_bubble_timestamp_margin"
|
android:layout_marginTop="@dimen/message_bubble_timestamp_margin"
|
||||||
app:layout_constraintEnd_toStartOf="@+id/bomb"
|
app:layout_constraintEnd_toEndOf="@+id/text"
|
||||||
app:layout_constraintHorizontal_bias="1.0"
|
|
||||||
app:layout_constraintHorizontal_chainStyle="packed"
|
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
|
||||||
app:layout_constraintTop_toBottomOf="@+id/text"
|
app:layout_constraintTop_toBottomOf="@+id/text"
|
||||||
tools:text="Dec 24, 13:37" />
|
tools:text="Dec 24, 13:37" />
|
||||||
|
|
||||||
<ImageView
|
|
||||||
android:id="@+id/bomb"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginStart="4dp"
|
|
||||||
android:layout_marginLeft="4dp"
|
|
||||||
android:layout_marginTop="@dimen/message_bubble_timestamp_margin"
|
|
||||||
app:layout_constraintEnd_toEndOf="@+id/text"
|
|
||||||
app:layout_constraintStart_toEndOf="@+id/time"
|
|
||||||
app:layout_constraintTop_toBottomOf="@+id/text"
|
|
||||||
app:srcCompat="@drawable/ic_bomb"
|
|
||||||
app:tint="?android:attr/textColorSecondary"
|
|
||||||
tools:ignore="ContentDescription"
|
|
||||||
tools:visibility="visible" />
|
|
||||||
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
@@ -8,8 +8,6 @@
|
|||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
android:paddingTop="@dimen/message_bubble_margin">
|
android:paddingTop="@dimen/message_bubble_margin">
|
||||||
|
|
||||||
<include layout="@layout/list_item_conversation_top_notice_out" />
|
|
||||||
|
|
||||||
<com.vanniktech.emoji.EmojiTextView
|
<com.vanniktech.emoji.EmojiTextView
|
||||||
android:id="@+id/msgText"
|
android:id="@+id/msgText"
|
||||||
style="@style/TextMessage"
|
style="@style/TextMessage"
|
||||||
@@ -17,14 +15,12 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginStart="@dimen/message_bubble_margin_non_tail"
|
android:layout_marginStart="@dimen/message_bubble_margin_non_tail"
|
||||||
android:layout_marginLeft="@dimen/message_bubble_margin_non_tail"
|
android:layout_marginLeft="@dimen/message_bubble_margin_non_tail"
|
||||||
android:layout_marginTop="@dimen/message_bubble_margin"
|
|
||||||
android:layout_marginEnd="@dimen/message_bubble_margin_tail"
|
android:layout_marginEnd="@dimen/message_bubble_margin_tail"
|
||||||
android:layout_marginRight="@dimen/message_bubble_margin_tail"
|
android:layout_marginRight="@dimen/message_bubble_margin_tail"
|
||||||
android:background="@drawable/msg_out_top"
|
android:background="@drawable/msg_out_top"
|
||||||
android:elevation="@dimen/message_bubble_elevation"
|
android:elevation="@dimen/message_bubble_elevation"
|
||||||
android:textColor="@color/briar_text_primary_inverse"
|
android:textColor="@color/briar_text_primary_inverse"
|
||||||
tools:text="This is a long long long message that spans over several lines.\n\nIt ends here."
|
tools:text="This is a long long long message that spans over several lines.\n\nIt ends here." />
|
||||||
tools:visibility="visible" />
|
|
||||||
|
|
||||||
<androidx.constraintlayout.widget.ConstraintLayout
|
<androidx.constraintlayout.widget.ConstraintLayout
|
||||||
android:id="@+id/layout"
|
android:id="@+id/layout"
|
||||||
@@ -59,29 +55,15 @@
|
|||||||
app:layout_constraintTop_toBottomOf="@+id/text"
|
app:layout_constraintTop_toBottomOf="@+id/text"
|
||||||
tools:text="Dec 24, 13:37" />
|
tools:text="Dec 24, 13:37" />
|
||||||
|
|
||||||
<ImageView
|
|
||||||
android:id="@+id/bomb"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginStart="4dp"
|
|
||||||
android:layout_marginLeft="4dp"
|
|
||||||
app:layout_constraintBottom_toBottomOf="@+id/time"
|
|
||||||
app:layout_constraintStart_toEndOf="@+id/time"
|
|
||||||
app:layout_constraintTop_toTopOf="@+id/time"
|
|
||||||
app:srcCompat="@drawable/ic_bomb"
|
|
||||||
app:tint="@color/private_message_date_inverse"
|
|
||||||
tools:ignore="ContentDescription" />
|
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:id="@+id/status"
|
android:id="@+id/status"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginStart="4dp"
|
android:layout_marginStart="@dimen/margin_medium"
|
||||||
android:layout_marginLeft="4dp"
|
android:layout_marginLeft="@dimen/margin_medium"
|
||||||
app:layout_constraintBottom_toBottomOf="@+id/time"
|
app:layout_constraintBottom_toBottomOf="@+id/time"
|
||||||
app:layout_constraintStart_toEndOf="@+id/bomb"
|
app:layout_constraintStart_toEndOf="@+id/time"
|
||||||
app:layout_constraintTop_toTopOf="@+id/time"
|
app:layout_constraintTop_toTopOf="@+id/time"
|
||||||
app:tint="@color/private_message_date_inverse"
|
|
||||||
tools:ignore="ContentDescription"
|
tools:ignore="ContentDescription"
|
||||||
tools:src="@drawable/message_delivered" />
|
tools:src="@drawable/message_delivered" />
|
||||||
|
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user