mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-18 21:59:54 +01:00
Compare commits
5 Commits
new-or-rec
...
1821-bluet
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bb8333660b | ||
|
|
9925c799a1 | ||
|
|
3ee2d2112c | ||
|
|
da5b2c194a | ||
|
|
244d03a718 |
@@ -2,7 +2,6 @@ image: briar/ci-image-android:latest
|
|||||||
|
|
||||||
stages:
|
stages:
|
||||||
- test
|
- test
|
||||||
- optional_tests
|
|
||||||
- check_reproducibility
|
- check_reproducibility
|
||||||
|
|
||||||
test:
|
test:
|
||||||
@@ -32,33 +31,3 @@ test_reproducible:
|
|||||||
- "curl -X POST -F token=${RELEASE_CHECK_TOKEN} -F ref=master -F variables[RELEASE_TAG]=${CI_COMMIT_REF_NAME} https://code.briarproject.org/api/v4/projects/61/trigger/pipeline"
|
- "curl -X POST -F token=${RELEASE_CHECK_TOKEN} -F ref=master -F variables[RELEASE_TAG]=${CI_COMMIT_REF_NAME} https://code.briarproject.org/api/v4/projects/61/trigger/pipeline"
|
||||||
only:
|
only:
|
||||||
- tags
|
- tags
|
||||||
|
|
||||||
.optional_tests:
|
|
||||||
stage: optional_tests
|
|
||||||
before_script:
|
|
||||||
- set -e
|
|
||||||
- export GRADLE_USER_HOME=$PWD/.gradle
|
|
||||||
|
|
||||||
cache:
|
|
||||||
paths:
|
|
||||||
- .gradle/wrapper
|
|
||||||
- .gradle/caches
|
|
||||||
|
|
||||||
script:
|
|
||||||
- OPTIONAL_TESTS=org.briarproject.bramble.plugin.tor.BridgeTest ./gradlew --info bramble-java:test --tests BridgeTest
|
|
||||||
|
|
||||||
after_script:
|
|
||||||
# these file change every time but should not be cached
|
|
||||||
- rm -f $GRADLE_USER_HOME/caches/modules-2/modules-2.lock
|
|
||||||
- rm -fr $GRADLE_USER_HOME/caches/*/plugin-resolution/
|
|
||||||
|
|
||||||
manual_tests:
|
|
||||||
extends: .optional_tests
|
|
||||||
when: manual
|
|
||||||
except:
|
|
||||||
- tags
|
|
||||||
|
|
||||||
pre_release_tests:
|
|
||||||
extends: .optional_tests
|
|
||||||
only:
|
|
||||||
- tags
|
|
||||||
|
|||||||
14
.idea/dictionaries/briar.xml
generated
14
.idea/dictionaries/briar.xml
generated
@@ -1,14 +0,0 @@
|
|||||||
<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 10216
|
versionCode 10213
|
||||||
versionName "1.2.16"
|
versionName "1.2.13"
|
||||||
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.13@zip'
|
tor 'org.briarproject:tor-android:0.3.5.12@zip'
|
||||||
tor 'org.briarproject:obfs4proxy-android:0.0.12-dev-40245c4a@zip'
|
tor 'org.briarproject:obfs4proxy-android:0.0.11-2@zip'
|
||||||
|
|
||||||
annotationProcessor 'com.google.dagger:dagger-compiler:2.24'
|
annotationProcessor 'com.google.dagger:dagger-compiler:2.24'
|
||||||
|
|
||||||
|
|||||||
@@ -31,7 +31,6 @@ 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<>();
|
||||||
@@ -108,10 +107,6 @@ 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.12-dev-40245c4a:obfs4proxy-android-0.0.12-dev-40245c4a.zip:8ab05a8f8391be2cb5ab2b665c281a06d9e3a756bd0f95a40a36ca927866ea82',
|
'org.briarproject:obfs4proxy-android:0.0.11-2:obfs4proxy-android-0.0.11-2.zip:57e55cbe87aa2aac210fdbb6cd8cdeafe15f825406a08ebf77a8b787aa2c6a8a',
|
||||||
'org.briarproject:tor-android:0.3.5.13:tor-android-0.3.5.13.zip:e0978db136731dae07774b722970cdae1e462fb5adc82845dd80a7e2d87f356c',
|
'org.briarproject:tor-android:0.3.5.12:tor-android-0.3.5.12.zip:db71fb3290acff79d572af0752570eaf6aad7c4d88c9b9aa0b4d5afe2b9ead9c',
|
||||||
'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',
|
||||||
|
|||||||
@@ -19,10 +19,4 @@ 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,12 +17,6 @@ public interface StreamEncrypterFactory {
|
|||||||
* Creates a {@link StreamEncrypter} for encrypting a contact exchange
|
* Creates a {@link StreamEncrypter} for encrypting a contact exchange
|
||||||
* stream.
|
* stream.
|
||||||
*/
|
*/
|
||||||
StreamEncrypter createContactExchangeStreamEncrypter(OutputStream out,
|
StreamEncrypter createContactExchangeStreamDecrypter(OutputStream out,
|
||||||
SecretKey headerKey);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a {@link StreamEncrypter} for encrypting a log stream.
|
|
||||||
*/
|
|
||||||
StreamEncrypter createLogStreamEncrypter(OutputStream out,
|
|
||||||
SecretKey headerKey);
|
SecretKey headerKey);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,11 +26,6 @@ public interface IdentityManager {
|
|||||||
*/
|
*/
|
||||||
void registerIdentity(Identity i);
|
void registerIdentity(Identity i);
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the cached local identity or loads it from the database.
|
|
||||||
*/
|
|
||||||
Identity getIdentity(Transaction txn) throws DbException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the cached local identity or loads it from the database.
|
* Returns the cached local identity or loads it from the database.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -74,13 +74,6 @@ public interface TransportPropertyManager {
|
|||||||
TransportProperties getRemoteProperties(ContactId c, TransportId t)
|
TransportProperties getRemoteProperties(ContactId c, TransportId t)
|
||||||
throws DbException;
|
throws DbException;
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the remote transport properties for the given contact and
|
|
||||||
* transport.
|
|
||||||
*/
|
|
||||||
TransportProperties getRemoteProperties(Transaction txn, ContactId c,
|
|
||||||
TransportId t) throws DbException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Merges the given properties with the existing local properties for the
|
* Merges the given properties with the existing local properties for the
|
||||||
* given transport.
|
* given transport.
|
||||||
|
|||||||
@@ -13,6 +13,4 @@ public interface DevConfig {
|
|||||||
String getDevOnionAddress();
|
String getDevOnionAddress();
|
||||||
|
|
||||||
File getReportDir();
|
File getReportDir();
|
||||||
|
|
||||||
File getLogcatFile();
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,13 +16,8 @@ public interface StreamReaderFactory {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an {@link InputStream InputStream} for reading from a contact
|
* Creates an {@link InputStream InputStream} for reading from a contact
|
||||||
* exchange stream.
|
* exchangestream.
|
||||||
*/
|
*/
|
||||||
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,19 +7,17 @@ import java.io.OutputStream;
|
|||||||
|
|
||||||
@NotNullByDefault
|
@NotNullByDefault
|
||||||
public interface StreamWriterFactory {
|
public interface StreamWriterFactory {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a {@link StreamWriter} for writing to a transport stream.
|
* Creates an {@link OutputStream OutputStream} for writing to a
|
||||||
|
* transport stream
|
||||||
*/
|
*/
|
||||||
StreamWriter createStreamWriter(OutputStream out, StreamContext ctx);
|
StreamWriter createStreamWriter(OutputStream out, StreamContext ctx);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a {@link StreamWriter} for writing to a contact exchange stream.
|
* Creates an {@link OutputStream OutputStream} for writing to a contact
|
||||||
|
* 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);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,12 @@
|
|||||||
package org.briarproject.bramble.api.crypto;
|
package org.briarproject.bramble.crypto;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.crypto.SecretKey;
|
||||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
|
||||||
import java.security.GeneralSecurityException;
|
import java.security.GeneralSecurityException;
|
||||||
|
|
||||||
@NotNullByDefault
|
@NotNullByDefault
|
||||||
public interface AuthenticatedCipher {
|
interface AuthenticatedCipher {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes this cipher for encryption or decryption with a key and an
|
* Initializes this cipher for encryption or decryption with a key and an
|
||||||
@@ -6,7 +6,6 @@ import net.i2p.crypto.eddsa.KeyPairGenerator;
|
|||||||
|
|
||||||
import org.briarproject.bramble.api.crypto.AgreementPrivateKey;
|
import org.briarproject.bramble.api.crypto.AgreementPrivateKey;
|
||||||
import org.briarproject.bramble.api.crypto.AgreementPublicKey;
|
import org.briarproject.bramble.api.crypto.AgreementPublicKey;
|
||||||
import org.briarproject.bramble.api.crypto.AuthenticatedCipher;
|
|
||||||
import org.briarproject.bramble.api.crypto.CryptoComponent;
|
import org.briarproject.bramble.api.crypto.CryptoComponent;
|
||||||
import org.briarproject.bramble.api.crypto.DecryptionException;
|
import org.briarproject.bramble.api.crypto.DecryptionException;
|
||||||
import org.briarproject.bramble.api.crypto.KeyPair;
|
import org.briarproject.bramble.api.crypto.KeyPair;
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package org.briarproject.bramble.crypto;
|
package org.briarproject.bramble.crypto;
|
||||||
|
|
||||||
import org.briarproject.bramble.api.crypto.AuthenticatedCipher;
|
|
||||||
import org.briarproject.bramble.api.crypto.CryptoComponent;
|
import org.briarproject.bramble.api.crypto.CryptoComponent;
|
||||||
import org.briarproject.bramble.api.crypto.KeyAgreementCrypto;
|
import org.briarproject.bramble.api.crypto.KeyAgreementCrypto;
|
||||||
import org.briarproject.bramble.api.crypto.PasswordStrengthEstimator;
|
import org.briarproject.bramble.api.crypto.PasswordStrengthEstimator;
|
||||||
|
|||||||
@@ -9,16 +9,14 @@ 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 =
|
||||||
getLogger(ScryptKdf.class.getName());
|
Logger.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
|
||||||
@@ -35,20 +33,10 @@ 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 <= maxCost && measureDuration(cost) * 2 <= TARGET_MS) {
|
while (cost * 2 <= MAX_COST && 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;
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package org.briarproject.bramble.crypto;
|
package org.briarproject.bramble.crypto;
|
||||||
|
|
||||||
import org.briarproject.bramble.api.crypto.AuthenticatedCipher;
|
|
||||||
import org.briarproject.bramble.api.crypto.SecretKey;
|
import org.briarproject.bramble.api.crypto.SecretKey;
|
||||||
import org.briarproject.bramble.api.crypto.StreamDecrypter;
|
import org.briarproject.bramble.api.crypto.StreamDecrypter;
|
||||||
import org.briarproject.bramble.api.crypto.StreamDecrypterFactory;
|
import org.briarproject.bramble.api.crypto.StreamDecrypterFactory;
|
||||||
@@ -37,10 +36,4 @@ 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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package org.briarproject.bramble.crypto;
|
package org.briarproject.bramble.crypto;
|
||||||
|
|
||||||
import org.briarproject.bramble.api.FormatException;
|
import org.briarproject.bramble.api.FormatException;
|
||||||
import org.briarproject.bramble.api.crypto.AuthenticatedCipher;
|
|
||||||
import org.briarproject.bramble.api.crypto.SecretKey;
|
import org.briarproject.bramble.api.crypto.SecretKey;
|
||||||
import org.briarproject.bramble.api.crypto.StreamDecrypter;
|
import org.briarproject.bramble.api.crypto.StreamDecrypter;
|
||||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package org.briarproject.bramble.crypto;
|
package org.briarproject.bramble.crypto;
|
||||||
|
|
||||||
import org.briarproject.bramble.api.crypto.AuthenticatedCipher;
|
|
||||||
import org.briarproject.bramble.api.crypto.CryptoComponent;
|
import org.briarproject.bramble.api.crypto.CryptoComponent;
|
||||||
import org.briarproject.bramble.api.crypto.SecretKey;
|
import org.briarproject.bramble.api.crypto.SecretKey;
|
||||||
import org.briarproject.bramble.api.crypto.StreamEncrypter;
|
import org.briarproject.bramble.api.crypto.StreamEncrypter;
|
||||||
@@ -52,7 +51,7 @@ class StreamEncrypterFactoryImpl implements StreamEncrypterFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public StreamEncrypter createContactExchangeStreamEncrypter(
|
public StreamEncrypter createContactExchangeStreamDecrypter(
|
||||||
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];
|
||||||
@@ -61,10 +60,4 @@ 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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package org.briarproject.bramble.crypto;
|
package org.briarproject.bramble.crypto;
|
||||||
|
|
||||||
import org.briarproject.bramble.api.crypto.AuthenticatedCipher;
|
|
||||||
import org.briarproject.bramble.api.crypto.SecretKey;
|
import org.briarproject.bramble.api.crypto.SecretKey;
|
||||||
import org.briarproject.bramble.api.crypto.StreamEncrypter;
|
import org.briarproject.bramble.api.crypto.StreamEncrypter;
|
||||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package org.briarproject.bramble.crypto;
|
package org.briarproject.bramble.crypto;
|
||||||
|
|
||||||
import org.briarproject.bramble.api.crypto.AuthenticatedCipher;
|
|
||||||
import org.briarproject.bramble.api.crypto.SecretKey;
|
import org.briarproject.bramble.api.crypto.SecretKey;
|
||||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
import org.spongycastle.crypto.DataLengthException;
|
import org.spongycastle.crypto.DataLengthException;
|
||||||
|
|||||||
@@ -118,11 +118,6 @@ class IdentityManagerImpl implements IdentityManager, OpenDatabaseHook {
|
|||||||
return cached.getLocalAuthor();
|
return cached.getLocalAuthor();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public Identity getIdentity(Transaction txn) throws DbException {
|
|
||||||
return getCachedIdentity(txn);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LocalAuthor getLocalAuthor(Transaction txn) throws DbException {
|
public LocalAuthor getLocalAuthor(Transaction txn) throws DbException {
|
||||||
return getCachedIdentity(txn).getLocalAuthor();
|
return getCachedIdentity(txn).getLocalAuthor();
|
||||||
|
|||||||
@@ -294,13 +294,7 @@ class TransportPropertyManagerImpl implements TransportPropertyManager,
|
|||||||
public TransportProperties getRemoteProperties(ContactId c, TransportId t)
|
public TransportProperties getRemoteProperties(ContactId c, TransportId t)
|
||||||
throws DbException {
|
throws DbException {
|
||||||
return db.transactionWithResult(true, txn ->
|
return db.transactionWithResult(true, txn ->
|
||||||
getRemoteProperties(txn, c, t));
|
getRemoteProperties(txn, db.getContact(txn, c), t));
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public TransportProperties getRemoteProperties(Transaction txn,
|
|
||||||
ContactId c, TransportId t) throws DbException {
|
|
||||||
return getRemoteProperties(txn, db.getContact(txn, c), t);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -24,21 +24,15 @@ class StreamReaderFactoryImpl implements StreamReaderFactory {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public InputStream createStreamReader(InputStream in, StreamContext ctx) {
|
public InputStream createStreamReader(InputStream in, StreamContext ctx) {
|
||||||
return new StreamReaderImpl(streamDecrypterFactory
|
return new StreamReaderImpl(
|
||||||
.createStreamDecrypter(in, ctx));
|
streamDecrypterFactory.createStreamDecrypter(in, ctx));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public InputStream createContactExchangeStreamReader(InputStream in,
|
public InputStream createContactExchangeStreamReader(InputStream in,
|
||||||
SecretKey headerKey) {
|
SecretKey headerKey) {
|
||||||
return new StreamReaderImpl(streamDecrypterFactory
|
return new StreamReaderImpl(
|
||||||
.createContactExchangeStreamDecrypter(in, headerKey));
|
streamDecrypterFactory.createContactExchangeStreamDecrypter(in,
|
||||||
}
|
headerKey));
|
||||||
|
|
||||||
@Override
|
|
||||||
public InputStream createLogStreamReader(InputStream in,
|
|
||||||
SecretKey headerKey) {
|
|
||||||
return new StreamReaderImpl(streamDecrypterFactory
|
|
||||||
.createLogStreamDecrypter(in, headerKey));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,21 +26,15 @@ class StreamWriterFactoryImpl implements StreamWriterFactory {
|
|||||||
@Override
|
@Override
|
||||||
public StreamWriter createStreamWriter(OutputStream out,
|
public StreamWriter createStreamWriter(OutputStream out,
|
||||||
StreamContext ctx) {
|
StreamContext ctx) {
|
||||||
return new StreamWriterImpl(streamEncrypterFactory
|
return new StreamWriterImpl(
|
||||||
.createStreamEncrypter(out, ctx));
|
streamEncrypterFactory.createStreamEncrypter(out, ctx));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public StreamWriter createContactExchangeStreamWriter(OutputStream out,
|
public StreamWriter createContactExchangeStreamWriter(OutputStream out,
|
||||||
SecretKey headerKey) {
|
SecretKey headerKey) {
|
||||||
return new StreamWriterImpl(streamEncrypterFactory
|
return new StreamWriterImpl(
|
||||||
.createContactExchangeStreamEncrypter(out, headerKey));
|
streamEncrypterFactory.createContactExchangeStreamDecrypter(out,
|
||||||
|
headerKey));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
@Override
|
|
||||||
public StreamWriter createLogStreamWriter(OutputStream out,
|
|
||||||
SecretKey headerKey) {
|
|
||||||
return new StreamWriterImpl(streamEncrypterFactory
|
|
||||||
.createLogStreamEncrypter(out, headerKey));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
package org.briarproject.bramble.crypto;
|
package org.briarproject.bramble.crypto;
|
||||||
|
|
||||||
import org.briarproject.bramble.api.crypto.AuthenticatedCipher;
|
|
||||||
import org.briarproject.bramble.api.crypto.SecretKey;
|
import org.briarproject.bramble.api.crypto.SecretKey;
|
||||||
import org.briarproject.bramble.test.BrambleTestCase;
|
import org.briarproject.bramble.test.BrambleTestCase;
|
||||||
import org.briarproject.bramble.test.TestUtils;
|
import org.briarproject.bramble.test.TestUtils;
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package org.briarproject.bramble.crypto;
|
package org.briarproject.bramble.crypto;
|
||||||
|
|
||||||
import org.briarproject.bramble.api.crypto.AuthenticatedCipher;
|
|
||||||
import org.briarproject.bramble.api.crypto.SecretKey;
|
import org.briarproject.bramble.api.crypto.SecretKey;
|
||||||
import org.briarproject.bramble.test.BrambleTestCase;
|
import org.briarproject.bramble.test.BrambleTestCase;
|
||||||
import org.briarproject.bramble.test.TestUtils;
|
import org.briarproject.bramble.test.TestUtils;
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package org.briarproject.bramble.crypto;
|
package org.briarproject.bramble.crypto;
|
||||||
|
|
||||||
import org.briarproject.bramble.api.crypto.AuthenticatedCipher;
|
|
||||||
import org.briarproject.bramble.api.crypto.SecretKey;
|
import org.briarproject.bramble.api.crypto.SecretKey;
|
||||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package org.briarproject.bramble.crypto;
|
package org.briarproject.bramble.crypto;
|
||||||
|
|
||||||
import org.briarproject.bramble.api.crypto.AuthenticatedCipher;
|
|
||||||
import org.briarproject.bramble.api.crypto.SecretKey;
|
import org.briarproject.bramble.api.crypto.SecretKey;
|
||||||
import org.briarproject.bramble.test.BrambleTestCase;
|
import org.briarproject.bramble.test.BrambleTestCase;
|
||||||
import org.briarproject.bramble.util.StringUtils;
|
import org.briarproject.bramble.util.StringUtils;
|
||||||
|
|||||||
@@ -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.13@zip'
|
tor 'org.briarproject:tor:0.3.5.12@zip'
|
||||||
tor 'org.briarproject:obfs4proxy:0.0.12-dev-40245c4a@zip'
|
tor 'org.briarproject:obfs4proxy:0.0.7@zip'
|
||||||
|
|
||||||
annotationProcessor 'com.google.dagger:dagger-compiler:2.24'
|
annotationProcessor 'com.google.dagger:dagger-compiler:2.24'
|
||||||
|
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ public class BridgeTest extends BrambleTestCase {
|
|||||||
return component.getCircumventionProvider().getBridges(false);
|
return component.getCircumventionProvider().getBridges(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final static long TIMEOUT = SECONDS.toMillis(60);
|
private final static long TIMEOUT = SECONDS.toMillis(30);
|
||||||
|
|
||||||
private final static Logger LOG = getLogger(BridgeTest.class.getName());
|
private final static Logger LOG = getLogger(BridgeTest.class.getName());
|
||||||
|
|
||||||
|
|||||||
@@ -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.12-dev-40245c4a:obfs4proxy-0.0.12-dev-40245c4a.zip:172029e7058b3a83ac93ac4991a44bf76e16ce8d46f558f5836d57da3cb3a766',
|
'org.briarproject:obfs4proxy:0.0.7:obfs4proxy-0.0.7.zip:5b2f693262ce43a7e130f7cc7d5d1617925330640a2eb6d71085e95df8ee0642',
|
||||||
'org.briarproject:tor:0.3.5.13:tor-0.3.5.13.zip:1c5f0b821ee2aadb0ea04aa96caab3ca0a08370cce8de81c2dfe04d172f8a2a0',
|
'org.briarproject:tor:0.3.5.12:tor-0.3.5.12.zip:2f542c4befd216f2226bf7c76e3b8b2d99af6f146a8cb28bf727f42014587006',
|
||||||
'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',
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="24" height="24" viewBox="0 0 24 24"><path d="M16,17V14H9V10H16V7L21,12L16,17M14,2A2,2 0 0,1 16,4V6H14V4H5V20H14V18H16V20A2,2 0 0,1 14,22H5A2,2 0 0,1 3,20V4A2,2 0 0,1 5,2H14Z" /></svg>
|
|
||||||
|
Before Width: | Height: | Size: 423 B |
@@ -22,11 +22,9 @@ android {
|
|||||||
defaultConfig {
|
defaultConfig {
|
||||||
minSdkVersion 16
|
minSdkVersion 16
|
||||||
targetSdkVersion 29
|
targetSdkVersion 29
|
||||||
versionCode 10216
|
versionCode 10213
|
||||||
versionName "1.2.16"
|
versionName "1.2.13"
|
||||||
applicationId "org.briarproject.briar.android"
|
applicationId "org.briarproject.briar.android"
|
||||||
|
|
||||||
vectorDrawables.useSupportLibrary = true
|
|
||||||
buildConfigField "String", "GitHash",
|
buildConfigField "String", "GitHash",
|
||||||
"\"${getStdout(['git', 'rev-parse', '--short=7', 'HEAD'], 'No commit hash')}\""
|
"\"${getStdout(['git', 'rev-parse', '--short=7', 'HEAD'], 'No commit hash')}\""
|
||||||
def now = (long) (System.currentTimeMillis() / 1000)
|
def now = (long) (System.currentTimeMillis() / 1000)
|
||||||
@@ -101,7 +99,6 @@ dependencies {
|
|||||||
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
|
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
|
||||||
implementation 'com.google.android.material:material:1.2.1'
|
implementation 'com.google.android.material:material:1.2.1'
|
||||||
implementation 'androidx.recyclerview:recyclerview-selection:1.1.0-rc03'
|
implementation 'androidx.recyclerview:recyclerview-selection:1.1.0-rc03'
|
||||||
implementation 'org.magmacollective.darkcrystal:dark-crystal-secret-sharing-wrapper:1.1.0'
|
|
||||||
|
|
||||||
implementation 'info.guardianproject.panic:panic:1.0'
|
implementation 'info.guardianproject.panic:panic:1.0'
|
||||||
implementation 'info.guardianproject.trustedintents:trustedintents:0.2'
|
implementation 'info.guardianproject.trustedintents:trustedintents:0.2'
|
||||||
@@ -137,7 +134,6 @@ 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'
|
||||||
|
|||||||
@@ -134,34 +134,6 @@
|
|||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
|
|
||||||
<activity
|
|
||||||
android:name="org.briarproject.briar.android.account.NewOrRecoverActivity"
|
|
||||||
android:label="@string/activity_name_new_or_recover_account"
|
|
||||||
android:parentActivityName="org.briarproject.briar.android.login.StartupActivity">
|
|
||||||
<meta-data
|
|
||||||
android:name="android.support.PARENT_ACTIVITY"
|
|
||||||
android:value="org.briarproject.briar.android.login.StartupActivity" />
|
|
||||||
</activity>
|
|
||||||
|
|
||||||
<activity
|
|
||||||
android:name="org.briarproject.briar.android.socialbackup.DistributedBackupActivity"
|
|
||||||
android:label="@string/activity_name_distributed_backup"
|
|
||||||
android:parentActivityName="org.briarproject.briar.android.settings.SettingsActivity">
|
|
||||||
<meta-data
|
|
||||||
android:name="android.support.PARENT_ACTIVITY"
|
|
||||||
android:value="org.briarproject.briar.android.settings.SettingsActivity" />
|
|
||||||
</activity>
|
|
||||||
|
|
||||||
<activity
|
|
||||||
android:name="org.briarproject.briar.android.socialbackup.OldDistributedBackupActivity"
|
|
||||||
android:label="@string/activity_name_old_distributed_backup"
|
|
||||||
android:parentActivityName="org.briarproject.briar.android.settings.SettingsActivity">
|
|
||||||
<meta-data
|
|
||||||
android:name="android.support.PARENT_ACTIVITY"
|
|
||||||
android:value="org.briarproject.briar.android.settings.SettingsActivity" />
|
|
||||||
</activity>
|
|
||||||
|
|
||||||
|
|
||||||
<activity
|
<activity
|
||||||
android:name="org.briarproject.briar.android.conversation.ConversationActivity"
|
android:name="org.briarproject.briar.android.conversation.ConversationActivity"
|
||||||
android:label="@string/app_name"
|
android:label="@string/app_name"
|
||||||
@@ -476,6 +448,12 @@
|
|||||||
android:label="@string/pending_contact_requests"
|
android:label="@string/pending_contact_requests"
|
||||||
android:theme="@style/BriarTheme" />
|
android:theme="@style/BriarTheme" />
|
||||||
|
|
||||||
|
<activity
|
||||||
|
android:name=".android.bluetoothsetup.BluetoothSetupActivity"
|
||||||
|
android:label="Bluetooth Setup"
|
||||||
|
android:theme="@style/BriarTheme"
|
||||||
|
android:windowSoftInputMode="adjustResize|stateHidden" />
|
||||||
|
|
||||||
</application>
|
</application>
|
||||||
|
|
||||||
<queries>
|
<queries>
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ import org.briarproject.bramble.api.contact.ContactExchangeManager;
|
|||||||
import org.briarproject.bramble.api.contact.ContactManager;
|
import org.briarproject.bramble.api.contact.ContactManager;
|
||||||
import org.briarproject.bramble.api.crypto.CryptoExecutor;
|
import org.briarproject.bramble.api.crypto.CryptoExecutor;
|
||||||
import org.briarproject.bramble.api.crypto.PasswordStrengthEstimator;
|
import org.briarproject.bramble.api.crypto.PasswordStrengthEstimator;
|
||||||
import org.briarproject.bramble.api.db.DatabaseComponent;
|
|
||||||
import org.briarproject.bramble.api.db.DatabaseExecutor;
|
import org.briarproject.bramble.api.db.DatabaseExecutor;
|
||||||
import org.briarproject.bramble.api.db.TransactionManager;
|
import org.briarproject.bramble.api.db.TransactionManager;
|
||||||
import org.briarproject.bramble.api.event.EventBus;
|
import org.briarproject.bramble.api.event.EventBus;
|
||||||
@@ -35,7 +34,6 @@ 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;
|
||||||
@@ -60,9 +58,7 @@ import org.briarproject.briar.api.privategroup.PrivateGroupFactory;
|
|||||||
import org.briarproject.briar.api.privategroup.PrivateGroupManager;
|
import org.briarproject.briar.api.privategroup.PrivateGroupManager;
|
||||||
import org.briarproject.briar.api.privategroup.invitation.GroupInvitationFactory;
|
import org.briarproject.briar.api.privategroup.invitation.GroupInvitationFactory;
|
||||||
import org.briarproject.briar.api.privategroup.invitation.GroupInvitationManager;
|
import org.briarproject.briar.api.privategroup.invitation.GroupInvitationManager;
|
||||||
import org.briarproject.briar.api.socialbackup.SocialBackupManager;
|
|
||||||
import org.briarproject.briar.api.test.TestDataCreator;
|
import org.briarproject.briar.api.test.TestDataCreator;
|
||||||
import org.briarproject.briar.socialbackup.SocialBackupManagerImpl_Factory;
|
|
||||||
|
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
|
|
||||||
@@ -183,13 +179,6 @@ public interface AndroidComponent
|
|||||||
|
|
||||||
AndroidWakeLockManager wakeLockManager();
|
AndroidWakeLockManager wakeLockManager();
|
||||||
|
|
||||||
CachingLogHandler logHandler();
|
|
||||||
|
|
||||||
Thread.UncaughtExceptionHandler exceptionHandler();
|
|
||||||
|
|
||||||
SocialBackupManager socialBackupManager();
|
|
||||||
DatabaseComponent databaseComponent();
|
|
||||||
|
|
||||||
void inject(SignInReminderReceiver briarService);
|
void inject(SignInReminderReceiver briarService);
|
||||||
|
|
||||||
void inject(BriarService briarService);
|
void inject(BriarService briarService);
|
||||||
|
|||||||
@@ -255,7 +255,7 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager,
|
|||||||
R.string.ongoing_notification_title;
|
R.string.ongoing_notification_title;
|
||||||
int text = locked ? R.string.lock_tap_to_unlock :
|
int text = locked ? R.string.lock_tap_to_unlock :
|
||||||
R.string.ongoing_notification_text;
|
R.string.ongoing_notification_text;
|
||||||
int icon = locked ? R.drawable.notification_lock :
|
int icon = locked ? R.drawable.startup_lock :
|
||||||
R.drawable.notification_ongoing;
|
R.drawable.notification_ongoing;
|
||||||
// Ongoing foreground notification that shows BriarService is running
|
// Ongoing foreground notification that shows BriarService is running
|
||||||
NotificationCompat.Builder b =
|
NotificationCompat.Builder b =
|
||||||
@@ -624,7 +624,7 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager,
|
|||||||
|
|
||||||
NotificationCompat.Builder b =
|
NotificationCompat.Builder b =
|
||||||
new NotificationCompat.Builder(appContext, REMINDER_CHANNEL_ID);
|
new NotificationCompat.Builder(appContext, REMINDER_CHANNEL_ID);
|
||||||
b.setSmallIcon(R.drawable.notification_signout);
|
b.setSmallIcon(R.drawable.ic_signout);
|
||||||
b.setColor(getColor(appContext, R.color.briar_primary));
|
b.setColor(getColor(appContext, R.color.briar_primary));
|
||||||
b.setContentTitle(
|
b.setContentTitle(
|
||||||
appContext.getText(R.string.reminder_notification_title));
|
appContext.getText(R.string.reminder_notification_title));
|
||||||
|
|||||||
@@ -30,17 +30,15 @@ import org.briarproject.bramble.util.StringUtils;
|
|||||||
import org.briarproject.briar.android.account.DozeHelperModule;
|
import org.briarproject.briar.android.account.DozeHelperModule;
|
||||||
import org.briarproject.briar.android.account.LockManagerImpl;
|
import org.briarproject.briar.android.account.LockManagerImpl;
|
||||||
import org.briarproject.briar.android.account.SetupModule;
|
import org.briarproject.briar.android.account.SetupModule;
|
||||||
|
import org.briarproject.briar.android.bluetoothsetup.BluetoothSetupModule;
|
||||||
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.list.GroupListModule;
|
import org.briarproject.briar.android.privategroup.list.GroupListModule;
|
||||||
import org.briarproject.briar.android.reporting.DevReportModule;
|
import org.briarproject.briar.android.reporting.DevReportModule;
|
||||||
import org.briarproject.briar.android.settings.SettingsModule;
|
import org.briarproject.briar.android.settings.SettingsModule;
|
||||||
import org.briarproject.briar.android.sharing.SharingModule;
|
|
||||||
import org.briarproject.briar.android.test.TestAvatarCreatorImpl;
|
import org.briarproject.briar.android.test.TestAvatarCreatorImpl;
|
||||||
import org.briarproject.briar.android.viewmodel.ViewModelModule;
|
import org.briarproject.briar.android.viewmodel.ViewModelModule;
|
||||||
import org.briarproject.briar.api.android.AndroidNotificationManager;
|
import org.briarproject.briar.api.android.AndroidNotificationManager;
|
||||||
@@ -75,18 +73,16 @@ import static org.briarproject.briar.android.TestingConstants.IS_DEBUG_BUILD;
|
|||||||
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,
|
||||||
SettingsModule.class,
|
SettingsModule.class,
|
||||||
DevReportModule.class,
|
DevReportModule.class,
|
||||||
ContactListModule.class,
|
ContactListModule.class,
|
||||||
|
BluetoothSetupModule.class,
|
||||||
// below need to be within same scope as ViewModelProvider.Factory
|
// below need to be within same scope as ViewModelProvider.Factory
|
||||||
ForumModule.class,
|
ForumModule.BindsModule.class,
|
||||||
GroupListModule.class,
|
GroupListModule.class,
|
||||||
GroupConversationModule.class,
|
|
||||||
SharingModule.class,
|
|
||||||
})
|
})
|
||||||
public class AppModule {
|
public class AppModule {
|
||||||
|
|
||||||
@@ -194,11 +190,6 @@ 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;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,9 @@ 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.
|
||||||
@@ -14,6 +17,8 @@ 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,10 +20,12 @@ 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.lang.Thread.UncaughtExceptionHandler;
|
import java.util.Collection;
|
||||||
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;
|
||||||
@@ -40,18 +42,22 @@ 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -61,11 +67,6 @@ 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
|
||||||
@@ -77,12 +78,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());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -135,6 +136,11 @@ 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_LOW;
|
import static android.app.NotificationManager.IMPORTANCE_NONE;
|
||||||
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;
|
||||||
@@ -46,7 +46,6 @@ import static android.content.Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS;
|
|||||||
import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK;
|
import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK;
|
||||||
import static android.content.Intent.FLAG_ACTIVITY_NO_ANIMATION;
|
import static android.content.Intent.FLAG_ACTIVITY_NO_ANIMATION;
|
||||||
import static android.os.Build.VERSION.SDK_INT;
|
import static android.os.Build.VERSION.SDK_INT;
|
||||||
import static android.os.Process.myPid;
|
|
||||||
import static androidx.core.app.NotificationCompat.VISIBILITY_SECRET;
|
import static androidx.core.app.NotificationCompat.VISIBILITY_SECRET;
|
||||||
import static java.util.logging.Level.INFO;
|
import static java.util.logging.Level.INFO;
|
||||||
import static java.util.logging.Level.WARNING;
|
import static java.util.logging.Level.WARNING;
|
||||||
@@ -57,10 +56,8 @@ 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;
|
||||||
import static org.briarproject.briar.api.android.LockManager.EXTRA_PID;
|
|
||||||
|
|
||||||
public class BriarService extends Service {
|
public class BriarService extends Service {
|
||||||
|
|
||||||
@@ -123,17 +120,11 @@ 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_LOW);
|
IMPORTANCE_NONE);
|
||||||
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,
|
||||||
@@ -179,7 +170,6 @@ 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) {
|
||||||
@@ -212,12 +202,7 @@ public class BriarService extends Service {
|
|||||||
@Override
|
@Override
|
||||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||||
if (ACTION_LOCK.equals(intent.getAction())) {
|
if (ACTION_LOCK.equals(intent.getAction())) {
|
||||||
int pid = intent.getIntExtra(EXTRA_PID, -1);
|
lockManager.setLocked(true);
|
||||||
if (pid == myPid()) lockManager.setLocked(true);
|
|
||||||
else if (LOG.isLoggable(WARNING)) {
|
|
||||||
LOG.warning("Tried to lock process " + pid + " but this is " +
|
|
||||||
myPid());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return START_NOT_STICKY; // Don't restart automatically if killed
|
return START_NOT_STICKY; // Don't restart automatically if killed
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -68,21 +68,7 @@ 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();
|
||||||
@@ -96,7 +82,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 = context.createConfigurationContext(conf);
|
context.createConfigurationContext(conf);
|
||||||
} else
|
} else
|
||||||
conf.locale = locale;
|
conf.locale = locale;
|
||||||
//noinspection deprecation
|
//noinspection deprecation
|
||||||
|
|||||||
@@ -32,10 +32,8 @@ import androidx.lifecycle.LiveData;
|
|||||||
import androidx.lifecycle.MutableLiveData;
|
import androidx.lifecycle.MutableLiveData;
|
||||||
|
|
||||||
import static android.app.AlarmManager.ELAPSED_REALTIME;
|
import static android.app.AlarmManager.ELAPSED_REALTIME;
|
||||||
import static android.app.PendingIntent.FLAG_UPDATE_CURRENT;
|
|
||||||
import static android.app.PendingIntent.getService;
|
import static android.app.PendingIntent.getService;
|
||||||
import static android.content.Context.ALARM_SERVICE;
|
import static android.content.Context.ALARM_SERVICE;
|
||||||
import static android.os.Process.myPid;
|
|
||||||
import static android.os.SystemClock.elapsedRealtime;
|
import static android.os.SystemClock.elapsedRealtime;
|
||||||
import static java.util.concurrent.TimeUnit.MINUTES;
|
import static java.util.concurrent.TimeUnit.MINUTES;
|
||||||
import static java.util.logging.Level.WARNING;
|
import static java.util.logging.Level.WARNING;
|
||||||
@@ -77,25 +75,23 @@ public class LockManagerImpl implements LockManager, Service, EventListener {
|
|||||||
LockManagerImpl(Application app, SettingsManager settingsManager,
|
LockManagerImpl(Application app, SettingsManager settingsManager,
|
||||||
AndroidNotificationManager notificationManager,
|
AndroidNotificationManager notificationManager,
|
||||||
@DatabaseExecutor Executor dbExecutor) {
|
@DatabaseExecutor Executor dbExecutor) {
|
||||||
appContext = app.getApplicationContext();
|
this.appContext = app.getApplicationContext();
|
||||||
this.settingsManager = settingsManager;
|
this.settingsManager = settingsManager;
|
||||||
this.notificationManager = notificationManager;
|
this.notificationManager = notificationManager;
|
||||||
this.dbExecutor = dbExecutor;
|
this.dbExecutor = dbExecutor;
|
||||||
alarmManager =
|
this.alarmManager =
|
||||||
(AlarmManager) appContext.getSystemService(ALARM_SERVICE);
|
(AlarmManager) appContext.getSystemService(ALARM_SERVICE);
|
||||||
Intent i =
|
Intent i =
|
||||||
new Intent(ACTION_LOCK, null, appContext, BriarService.class);
|
new Intent(ACTION_LOCK, null, appContext, BriarService.class);
|
||||||
i.putExtra(EXTRA_PID, myPid());
|
this.lockIntent = getService(appContext, 0, i, 0);
|
||||||
// When not using FLAG_UPDATE_CURRENT, the intent might have no extras
|
this.timeoutNever = Integer.valueOf(
|
||||||
lockIntent = getService(appContext, 0, i, FLAG_UPDATE_CURRENT);
|
|
||||||
timeoutNever = Integer.parseInt(
|
|
||||||
appContext.getString(R.string.pref_lock_timeout_value_never));
|
appContext.getString(R.string.pref_lock_timeout_value_never));
|
||||||
timeoutDefault = Integer.parseInt(
|
this.timeoutDefault = Integer.valueOf(
|
||||||
appContext.getString(R.string.pref_lock_timeout_value_default));
|
appContext.getString(R.string.pref_lock_timeout_value_default));
|
||||||
timeoutMinutes = timeoutNever;
|
this.timeoutMinutes = timeoutNever;
|
||||||
|
|
||||||
// setting this in the constructor makes #getValue() @NonNull
|
// setting this in the constructor makes #getValue() @NonNull
|
||||||
lockable.setValue(false);
|
this.lockable.setValue(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -152,7 +148,7 @@ public class LockManagerImpl implements LockManager, Service, EventListener {
|
|||||||
boolean oldValue = lockable.getValue();
|
boolean oldValue = lockable.getValue();
|
||||||
boolean newValue = hasScreenLock(appContext) && lockableSetting;
|
boolean newValue = hasScreenLock(appContext) && lockableSetting;
|
||||||
if (oldValue != newValue) {
|
if (oldValue != newValue) {
|
||||||
lockable.setValue(newValue);
|
this.lockable.setValue(newValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,47 +0,0 @@
|
|||||||
package org.briarproject.briar.android.account;
|
|
||||||
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.os.Bundle;
|
|
||||||
|
|
||||||
import org.briarproject.briar.R;
|
|
||||||
import org.briarproject.briar.android.activity.ActivityComponent;
|
|
||||||
import org.briarproject.briar.android.activity.BaseActivity;
|
|
||||||
import org.briarproject.briar.android.fragment.BaseFragment;
|
|
||||||
|
|
||||||
import static android.content.Intent.FLAG_ACTIVITY_CLEAR_TASK;
|
|
||||||
import static android.content.Intent.FLAG_ACTIVITY_CLEAR_TOP;
|
|
||||||
import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK;
|
|
||||||
import static android.content.Intent.FLAG_ACTIVITY_TASK_ON_HOME;
|
|
||||||
|
|
||||||
public class NewOrRecoverActivity extends BaseActivity implements
|
|
||||||
BaseFragment.BaseFragmentListener, SetupNewAccountChosenListener {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void injectActivity(ActivityComponent component) {
|
|
||||||
component.inject(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCreate(Bundle state) {
|
|
||||||
super.onCreate(state);
|
|
||||||
// fade-in after splash screen instead of default animation
|
|
||||||
overridePendingTransition(R.anim.fade_in, R.anim.fade_out);
|
|
||||||
setContentView(R.layout.activity_fragment_container);
|
|
||||||
NewOrRecoverFragment fragment = NewOrRecoverFragment.newInstance();
|
|
||||||
showInitialFragment(fragment);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setupNewAccountChosen () {
|
|
||||||
finish();
|
|
||||||
Intent i = new Intent(this, SetupActivity.class);
|
|
||||||
i.addFlags(FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_CLEAR_TOP |
|
|
||||||
FLAG_ACTIVITY_CLEAR_TASK | FLAG_ACTIVITY_TASK_ON_HOME);
|
|
||||||
startActivity(i);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void runOnDbThread(Runnable runnable) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,63 +0,0 @@
|
|||||||
package org.briarproject.briar.android.account;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.os.Bundle;
|
|
||||||
import android.view.LayoutInflater;
|
|
||||||
import android.view.View;
|
|
||||||
import android.view.ViewGroup;
|
|
||||||
import android.widget.Button;
|
|
||||||
|
|
||||||
import org.briarproject.briar.R;
|
|
||||||
import org.briarproject.briar.android.activity.ActivityComponent;
|
|
||||||
import org.briarproject.briar.android.fragment.BaseFragment;
|
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
import androidx.annotation.Nullable;
|
|
||||||
|
|
||||||
public class NewOrRecoverFragment extends BaseFragment {
|
|
||||||
|
|
||||||
public static final String TAG = NewOrRecoverFragment.class.getName();
|
|
||||||
|
|
||||||
protected SetupNewAccountChosenListener listener;
|
|
||||||
|
|
||||||
public static NewOrRecoverFragment newInstance() {
|
|
||||||
Bundle bundle = new Bundle();
|
|
||||||
NewOrRecoverFragment fragment = new NewOrRecoverFragment();
|
|
||||||
fragment.setArguments(bundle);
|
|
||||||
return fragment;
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
|
||||||
super.onCreate(savedInstanceState);
|
|
||||||
requireActivity().setTitle(R.string.setup_title);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
@Override
|
|
||||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable
|
|
||||||
ViewGroup container, @Nullable Bundle savedInstanceState) {
|
|
||||||
View view = inflater.inflate(R.layout.fragment_new_or_recover,
|
|
||||||
container, false);
|
|
||||||
Button button = view.findViewById(R.id.buttonSetupNewAccount);
|
|
||||||
button.setOnClickListener(e -> {
|
|
||||||
listener.setupNewAccountChosen();
|
|
||||||
});
|
|
||||||
return view;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onAttach(Context context) {
|
|
||||||
super.onAttach(context);
|
|
||||||
listener = (SetupNewAccountChosenListener) context;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getUniqueTag() {
|
|
||||||
return TAG;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void injectFragment(ActivityComponent component) {
|
|
||||||
component.inject(this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
package org.briarproject.briar.android.account;
|
|
||||||
|
|
||||||
import androidx.annotation.UiThread;
|
|
||||||
|
|
||||||
public interface SetupNewAccountChosenListener {
|
|
||||||
@UiThread
|
|
||||||
void setupNewAccountChosen();
|
|
||||||
}
|
|
||||||
@@ -77,7 +77,7 @@ public class UnlockActivity extends BaseActivity {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onActivityResult(int requestCode, int resultCode,
|
protected void onActivityResult(int requestCode, int resultCode,
|
||||||
@Nullable Intent data) {
|
Intent data) {
|
||||||
super.onActivityResult(requestCode, resultCode, data);
|
super.onActivityResult(requestCode, resultCode, data);
|
||||||
if (requestCode == REQUEST_KEYGUARD_UNLOCK) {
|
if (requestCode == REQUEST_KEYGUARD_UNLOCK) {
|
||||||
if (resultCode == RESULT_OK) unlock();
|
if (resultCode == RESULT_OK) unlock();
|
||||||
|
|||||||
@@ -2,13 +2,10 @@ package org.briarproject.briar.android.activity;
|
|||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
|
|
||||||
import org.briarproject.bramble.api.db.DatabaseComponent;
|
|
||||||
import org.briarproject.briar.android.AndroidComponent;
|
import org.briarproject.briar.android.AndroidComponent;
|
||||||
import org.briarproject.briar.android.StartupFailureActivity;
|
import org.briarproject.briar.android.StartupFailureActivity;
|
||||||
import org.briarproject.briar.android.account.AuthorNameFragment;
|
import org.briarproject.briar.android.account.AuthorNameFragment;
|
||||||
import org.briarproject.briar.android.account.DozeFragment;
|
import org.briarproject.briar.android.account.DozeFragment;
|
||||||
import org.briarproject.briar.android.account.NewOrRecoverActivity;
|
|
||||||
import org.briarproject.briar.android.account.NewOrRecoverFragment;
|
|
||||||
import org.briarproject.briar.android.account.SetPasswordFragment;
|
import org.briarproject.briar.android.account.SetPasswordFragment;
|
||||||
import org.briarproject.briar.android.account.SetupActivity;
|
import org.briarproject.briar.android.account.SetupActivity;
|
||||||
import org.briarproject.briar.android.account.UnlockActivity;
|
import org.briarproject.briar.android.account.UnlockActivity;
|
||||||
@@ -23,6 +20,10 @@ import org.briarproject.briar.android.blog.ReblogFragment;
|
|||||||
import org.briarproject.briar.android.blog.RssFeedImportActivity;
|
import org.briarproject.briar.android.blog.RssFeedImportActivity;
|
||||||
import org.briarproject.briar.android.blog.RssFeedManageActivity;
|
import org.briarproject.briar.android.blog.RssFeedManageActivity;
|
||||||
import org.briarproject.briar.android.blog.WriteBlogPostActivity;
|
import org.briarproject.briar.android.blog.WriteBlogPostActivity;
|
||||||
|
import org.briarproject.briar.android.bluetoothsetup.BluetoothSetupActivity;
|
||||||
|
import org.briarproject.briar.android.bluetoothsetup.BluetoothSetupChooseFragment;
|
||||||
|
import org.briarproject.briar.android.bluetoothsetup.BluetoothSetupPendingFragment;
|
||||||
|
import org.briarproject.briar.android.bluetoothsetup.BluetoothSetupStartFragment;
|
||||||
import org.briarproject.briar.android.contact.ContactListFragment;
|
import org.briarproject.briar.android.contact.ContactListFragment;
|
||||||
import org.briarproject.briar.android.contact.add.remote.AddContactActivity;
|
import org.briarproject.briar.android.contact.add.remote.AddContactActivity;
|
||||||
import org.briarproject.briar.android.contact.add.remote.LinkExchangeFragment;
|
import org.briarproject.briar.android.contact.add.remote.LinkExchangeFragment;
|
||||||
@@ -35,6 +36,7 @@ import org.briarproject.briar.android.conversation.ImageFragment;
|
|||||||
import org.briarproject.briar.android.forum.CreateForumActivity;
|
import org.briarproject.briar.android.forum.CreateForumActivity;
|
||||||
import org.briarproject.briar.android.forum.ForumActivity;
|
import org.briarproject.briar.android.forum.ForumActivity;
|
||||||
import org.briarproject.briar.android.forum.ForumListFragment;
|
import org.briarproject.briar.android.forum.ForumListFragment;
|
||||||
|
import org.briarproject.briar.android.forum.ForumModule;
|
||||||
import org.briarproject.briar.android.fragment.ScreenFilterDialogFragment;
|
import org.briarproject.briar.android.fragment.ScreenFilterDialogFragment;
|
||||||
import org.briarproject.briar.android.introduction.ContactChooserFragment;
|
import org.briarproject.briar.android.introduction.ContactChooserFragment;
|
||||||
import org.briarproject.briar.android.introduction.IntroductionActivity;
|
import org.briarproject.briar.android.introduction.IntroductionActivity;
|
||||||
@@ -52,6 +54,7 @@ import org.briarproject.briar.android.navdrawer.TransportsActivity;
|
|||||||
import org.briarproject.briar.android.panic.PanicPreferencesActivity;
|
import org.briarproject.briar.android.panic.PanicPreferencesActivity;
|
||||||
import org.briarproject.briar.android.panic.PanicResponderActivity;
|
import org.briarproject.briar.android.panic.PanicResponderActivity;
|
||||||
import org.briarproject.briar.android.privategroup.conversation.GroupActivity;
|
import org.briarproject.briar.android.privategroup.conversation.GroupActivity;
|
||||||
|
import org.briarproject.briar.android.privategroup.conversation.GroupConversationModule;
|
||||||
import org.briarproject.briar.android.privategroup.creation.CreateGroupActivity;
|
import org.briarproject.briar.android.privategroup.creation.CreateGroupActivity;
|
||||||
import org.briarproject.briar.android.privategroup.creation.CreateGroupFragment;
|
import org.briarproject.briar.android.privategroup.creation.CreateGroupFragment;
|
||||||
import org.briarproject.briar.android.privategroup.creation.CreateGroupModule;
|
import org.briarproject.briar.android.privategroup.creation.CreateGroupModule;
|
||||||
@@ -80,31 +83,22 @@ import org.briarproject.briar.android.sharing.ShareBlogFragment;
|
|||||||
import org.briarproject.briar.android.sharing.ShareForumActivity;
|
import org.briarproject.briar.android.sharing.ShareForumActivity;
|
||||||
import org.briarproject.briar.android.sharing.ShareForumFragment;
|
import org.briarproject.briar.android.sharing.ShareForumFragment;
|
||||||
import org.briarproject.briar.android.sharing.SharingModule;
|
import org.briarproject.briar.android.sharing.SharingModule;
|
||||||
//import org.briarproject.briar.android.socialbackup.CustodianDisplayFragment;
|
|
||||||
import org.briarproject.briar.android.socialbackup.CustodianSelectorFragment;
|
|
||||||
import org.briarproject.briar.android.socialbackup.DistributedBackupActivity;
|
|
||||||
import org.briarproject.briar.android.socialbackup.ExistingBackupFragment;
|
|
||||||
import org.briarproject.briar.android.socialbackup.OldDistributedBackupActivity;
|
|
||||||
import org.briarproject.briar.android.socialbackup.ShardsSentFragment;
|
|
||||||
import org.briarproject.briar.android.socialbackup.ThresholdSelectorFragment;
|
|
||||||
import org.briarproject.briar.android.socialbackup.creation.CreateBackupController;
|
|
||||||
import org.briarproject.briar.android.socialbackup.creation.CreateBackupModule;
|
|
||||||
import org.briarproject.briar.android.splash.SplashScreenActivity;
|
import org.briarproject.briar.android.splash.SplashScreenActivity;
|
||||||
import org.briarproject.briar.android.test.TestDataActivity;
|
import org.briarproject.briar.android.test.TestDataActivity;
|
||||||
import org.h2.util.New;
|
|
||||||
|
|
||||||
import dagger.Component;
|
import dagger.Component;
|
||||||
|
|
||||||
@ActivityScope
|
@ActivityScope
|
||||||
@Component(modules ={
|
@Component(modules = {
|
||||||
ActivityModule.class,
|
ActivityModule.class,
|
||||||
BlogModule.class,
|
BlogModule.class,
|
||||||
CreateGroupModule.class,
|
CreateGroupModule.class,
|
||||||
|
ForumModule.class,
|
||||||
GroupInvitationModule.class,
|
GroupInvitationModule.class,
|
||||||
|
GroupConversationModule.class,
|
||||||
GroupMemberModule.class,
|
GroupMemberModule.class,
|
||||||
GroupRevealModule.class,
|
GroupRevealModule.class,
|
||||||
SharingModule.SharingLegacyModule.class,
|
SharingModule.class
|
||||||
CreateBackupModule.class
|
|
||||||
}, dependencies = AndroidComponent.class)
|
}, dependencies = AndroidComponent.class)
|
||||||
public interface ActivityComponent {
|
public interface ActivityComponent {
|
||||||
|
|
||||||
@@ -196,7 +190,7 @@ public interface ActivityComponent {
|
|||||||
|
|
||||||
void inject(CrashReportActivity crashReportActivity);
|
void inject(CrashReportActivity crashReportActivity);
|
||||||
|
|
||||||
void inject(NewOrRecoverActivity newOrRecoverActivity);
|
void inject(BluetoothSetupActivity activity);
|
||||||
|
|
||||||
// Fragments
|
// Fragments
|
||||||
|
|
||||||
@@ -254,21 +248,10 @@ public interface ActivityComponent {
|
|||||||
|
|
||||||
void inject(ConfirmAvatarDialogFragment fragment);
|
void inject(ConfirmAvatarDialogFragment fragment);
|
||||||
|
|
||||||
void inject(ThresholdSelectorFragment thresholdSelectorFragment);
|
void inject(BluetoothSetupStartFragment fragment);
|
||||||
|
|
||||||
void inject(DistributedBackupActivity distributedBackupActivity);
|
void inject(BluetoothSetupChooseFragment fragment);
|
||||||
// void inject(CreateBackupController createBackupController);
|
|
||||||
// void inject(CustodianDisplayFragment custodianDisplayFragment);
|
|
||||||
|
|
||||||
void inject(DatabaseComponent databaseComponent);
|
void inject(BluetoothSetupPendingFragment fragment);
|
||||||
|
|
||||||
void inject(CustodianSelectorFragment custodianSelectorFragment);
|
|
||||||
|
|
||||||
void inject(ShardsSentFragment shardsSentFragment);
|
|
||||||
|
|
||||||
void inject(ExistingBackupFragment existingBackupFragment);
|
|
||||||
|
|
||||||
void inject(NewOrRecoverFragment newOrRecoverFragment);
|
|
||||||
|
|
||||||
void inject(OldDistributedBackupActivity oldDistributedBackupActivity);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import org.briarproject.briar.android.BriarApplication;
|
|||||||
import org.briarproject.briar.android.DestroyableContext;
|
import org.briarproject.briar.android.DestroyableContext;
|
||||||
import org.briarproject.briar.android.Localizer;
|
import org.briarproject.briar.android.Localizer;
|
||||||
import org.briarproject.briar.android.controller.ActivityLifecycleController;
|
import org.briarproject.briar.android.controller.ActivityLifecycleController;
|
||||||
|
import org.briarproject.briar.android.forum.ForumModule;
|
||||||
import org.briarproject.briar.android.fragment.BaseFragment;
|
import org.briarproject.briar.android.fragment.BaseFragment;
|
||||||
import org.briarproject.briar.android.fragment.ScreenFilterDialogFragment;
|
import org.briarproject.briar.android.fragment.ScreenFilterDialogFragment;
|
||||||
import org.briarproject.briar.android.util.UiUtils;
|
import org.briarproject.briar.android.util.UiUtils;
|
||||||
@@ -86,6 +87,7 @@ public abstract class BaseActivity extends AppCompatActivity
|
|||||||
activityComponent = DaggerActivityComponent.builder()
|
activityComponent = DaggerActivityComponent.builder()
|
||||||
.androidComponent(applicationComponent)
|
.androidComponent(applicationComponent)
|
||||||
.activityModule(getActivityModule())
|
.activityModule(getActivityModule())
|
||||||
|
.forumModule(getForumModule())
|
||||||
.build();
|
.build();
|
||||||
injectActivity(activityComponent);
|
injectActivity(activityComponent);
|
||||||
super.onCreate(state);
|
super.onCreate(state);
|
||||||
@@ -109,7 +111,6 @@ 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() {
|
||||||
@@ -121,6 +122,11 @@ public abstract class BaseActivity extends AppCompatActivity
|
|||||||
return new ActivityModule(this);
|
return new ActivityModule(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO use a test module where this is used in tests
|
||||||
|
protected ForumModule getForumModule() {
|
||||||
|
return new ForumModule();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onStart() {
|
protected void onStart() {
|
||||||
super.onStart();
|
super.onStart();
|
||||||
|
|||||||
@@ -160,6 +160,7 @@ public abstract class BriarActivity extends BaseActivity {
|
|||||||
* @param ownLayout true if the custom toolbar brings its own layout
|
* @param ownLayout true if the custom toolbar brings its own layout
|
||||||
* @return the Toolbar object or null if content view did not contain one
|
* @return the Toolbar object or null if content view did not contain one
|
||||||
*/
|
*/
|
||||||
|
@Nullable
|
||||||
protected Toolbar setUpCustomToolbar(boolean ownLayout) {
|
protected Toolbar setUpCustomToolbar(boolean ownLayout) {
|
||||||
// Custom Toolbar
|
// Custom Toolbar
|
||||||
Toolbar toolbar = findViewById(R.id.toolbar);
|
Toolbar toolbar = findViewById(R.id.toolbar);
|
||||||
|
|||||||
@@ -0,0 +1,60 @@
|
|||||||
|
package org.briarproject.briar.android.bluetoothsetup;
|
||||||
|
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.view.MenuItem;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
|
||||||
|
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
||||||
|
import org.briarproject.briar.R;
|
||||||
|
import org.briarproject.briar.android.activity.ActivityComponent;
|
||||||
|
import org.briarproject.briar.android.activity.BriarActivity;
|
||||||
|
import org.briarproject.briar.android.fragment.BaseFragment.BaseFragmentListener;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
import androidx.appcompat.app.ActionBar;
|
||||||
|
import androidx.lifecycle.ViewModelProvider;
|
||||||
|
|
||||||
|
@MethodsNotNullByDefault
|
||||||
|
@ParametersNotNullByDefault
|
||||||
|
public class BluetoothSetupActivity extends BriarActivity implements
|
||||||
|
BaseFragmentListener {
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
ViewModelProvider.Factory viewModelFactory;
|
||||||
|
private BluetoothSetupViewModel viewModel;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void injectActivity(ActivityComponent component) {
|
||||||
|
component.inject(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreate(@Nullable Bundle state) {
|
||||||
|
super.onCreate(state);
|
||||||
|
setContentView(R.layout.activity_fragment_container);
|
||||||
|
|
||||||
|
ActionBar ab = getSupportActionBar();
|
||||||
|
if (ab != null) {
|
||||||
|
ab.setDisplayHomeAsUpEnabled(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
viewModel = new ViewModelProvider(this, viewModelFactory)
|
||||||
|
.get(BluetoothSetupViewModel.class);
|
||||||
|
|
||||||
|
if (state == null) {
|
||||||
|
showInitialFragment(new BluetoothSetupStartFragment());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
|
if (item.getItemId() == android.R.id.home) {
|
||||||
|
onBackPressed();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return super.onOptionsItemSelected(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,72 @@
|
|||||||
|
package org.briarproject.briar.android.bluetoothsetup;
|
||||||
|
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.Button;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
|
||||||
|
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
||||||
|
import org.briarproject.briar.R;
|
||||||
|
import org.briarproject.briar.android.activity.ActivityComponent;
|
||||||
|
import org.briarproject.briar.android.fragment.BaseFragment;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
import androidx.lifecycle.ViewModelProvider;
|
||||||
|
|
||||||
|
@MethodsNotNullByDefault
|
||||||
|
@ParametersNotNullByDefault
|
||||||
|
public class BluetoothSetupChooseFragment extends BaseFragment {
|
||||||
|
private static final String TAG =
|
||||||
|
BluetoothSetupChooseFragment.class.getName();
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
ViewModelProvider.Factory viewModelFactory;
|
||||||
|
|
||||||
|
private BluetoothSetupViewModel viewModel;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getUniqueTag() {
|
||||||
|
return TAG;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void injectFragment(ActivityComponent component) {
|
||||||
|
component.inject(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public View onCreateView(LayoutInflater inflater,
|
||||||
|
@Nullable ViewGroup container,
|
||||||
|
@Nullable Bundle savedInstanceState) {
|
||||||
|
if (getActivity() == null || getContext() == null) return null;
|
||||||
|
|
||||||
|
viewModel = new ViewModelProvider(requireActivity())
|
||||||
|
.get(BluetoothSetupViewModel.class);
|
||||||
|
|
||||||
|
View v =
|
||||||
|
inflater.inflate(R.layout.fragment_bluetooth_setup_choose,
|
||||||
|
container, false);
|
||||||
|
|
||||||
|
// TODO to enable when user picks a device from list
|
||||||
|
|
||||||
|
Button continueButton = v.findViewById(R.id.continueButton);
|
||||||
|
continueButton.setOnClickListener(view -> {
|
||||||
|
showNextFragment(new BluetoothSetupPendingFragment());
|
||||||
|
});
|
||||||
|
continueButton.setEnabled(true);
|
||||||
|
|
||||||
|
// RecyclerView devices = v.findViewById(R.id.devices);
|
||||||
|
// devices.setHasFixedSize(true);
|
||||||
|
// final LinearLayoutManager layoutManager =
|
||||||
|
// new LinearLayoutManager(getActivity(),
|
||||||
|
// LinearLayoutManager.VERTICAL, false);
|
||||||
|
// devices.setLayoutManager(layoutManager);
|
||||||
|
|
||||||
|
return v;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
package org.briarproject.briar.android.bluetoothsetup;
|
||||||
|
|
||||||
|
import org.briarproject.briar.android.viewmodel.ViewModelKey;
|
||||||
|
|
||||||
|
import androidx.lifecycle.ViewModel;
|
||||||
|
import dagger.Binds;
|
||||||
|
import dagger.Module;
|
||||||
|
import dagger.multibindings.IntoMap;
|
||||||
|
|
||||||
|
@Module
|
||||||
|
public abstract class BluetoothSetupModule {
|
||||||
|
|
||||||
|
@Binds
|
||||||
|
@IntoMap
|
||||||
|
@ViewModelKey(BluetoothSetupViewModel.class)
|
||||||
|
abstract ViewModel bindBluetoothSetupViewModel(
|
||||||
|
BluetoothSetupViewModel bluetoothSetupViewModel);
|
||||||
|
}
|
||||||
@@ -0,0 +1,59 @@
|
|||||||
|
package org.briarproject.briar.android.bluetoothsetup;
|
||||||
|
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
|
||||||
|
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
||||||
|
import org.briarproject.briar.R;
|
||||||
|
import org.briarproject.briar.android.activity.ActivityComponent;
|
||||||
|
import org.briarproject.briar.android.fragment.BaseFragment;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
import androidx.lifecycle.ViewModelProvider;
|
||||||
|
|
||||||
|
@MethodsNotNullByDefault
|
||||||
|
@ParametersNotNullByDefault
|
||||||
|
public class BluetoothSetupPendingFragment extends BaseFragment {
|
||||||
|
private static final String TAG =
|
||||||
|
BluetoothSetupPendingFragment.class.getName();
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
ViewModelProvider.Factory viewModelFactory;
|
||||||
|
|
||||||
|
private BluetoothSetupViewModel viewModel;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getUniqueTag() {
|
||||||
|
return TAG;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void injectFragment(ActivityComponent component) {
|
||||||
|
component.inject(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public View onCreateView(LayoutInflater inflater,
|
||||||
|
@Nullable ViewGroup container,
|
||||||
|
@Nullable Bundle savedInstanceState) {
|
||||||
|
if (getActivity() == null || getContext() == null) return null;
|
||||||
|
|
||||||
|
viewModel = new ViewModelProvider(requireActivity())
|
||||||
|
.get(BluetoothSetupViewModel.class);
|
||||||
|
|
||||||
|
View v = inflater.inflate(R.layout.fragment_bluetooth_setup_pending,
|
||||||
|
container, false);
|
||||||
|
|
||||||
|
return v;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void onContinueButtonClicked() {
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,65 @@
|
|||||||
|
package org.briarproject.briar.android.bluetoothsetup;
|
||||||
|
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.Button;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
|
||||||
|
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
||||||
|
import org.briarproject.briar.R;
|
||||||
|
import org.briarproject.briar.android.activity.ActivityComponent;
|
||||||
|
import org.briarproject.briar.android.fragment.BaseFragment;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
import androidx.lifecycle.ViewModelProvider;
|
||||||
|
|
||||||
|
@MethodsNotNullByDefault
|
||||||
|
@ParametersNotNullByDefault
|
||||||
|
public class BluetoothSetupStartFragment extends BaseFragment {
|
||||||
|
private static final String TAG =
|
||||||
|
BluetoothSetupStartFragment.class.getName();
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
ViewModelProvider.Factory viewModelFactory;
|
||||||
|
|
||||||
|
private BluetoothSetupViewModel viewModel;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getUniqueTag() {
|
||||||
|
return TAG;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void injectFragment(ActivityComponent component) {
|
||||||
|
component.inject(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public View onCreateView(LayoutInflater inflater,
|
||||||
|
@Nullable ViewGroup container,
|
||||||
|
@Nullable Bundle savedInstanceState) {
|
||||||
|
if (getActivity() == null || getContext() == null) return null;
|
||||||
|
|
||||||
|
viewModel = new ViewModelProvider(requireActivity())
|
||||||
|
.get(BluetoothSetupViewModel.class);
|
||||||
|
|
||||||
|
View v = inflater.inflate(R.layout.fragment_bluetooth_setup_start,
|
||||||
|
container, false);
|
||||||
|
|
||||||
|
// TODO device-BT and BT-plugin needs to be enabled at this point
|
||||||
|
|
||||||
|
Button startButton = v.findViewById(R.id.startButton);
|
||||||
|
startButton.setOnClickListener(view -> {
|
||||||
|
showNextFragment(new BluetoothSetupChooseFragment());
|
||||||
|
});
|
||||||
|
startButton.setEnabled(true);
|
||||||
|
|
||||||
|
return v;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
package org.briarproject.briar.android.bluetoothsetup;
|
||||||
|
|
||||||
|
import android.app.Application;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.db.DatabaseExecutor;
|
||||||
|
import org.briarproject.bramble.api.db.TransactionManager;
|
||||||
|
import org.briarproject.bramble.api.lifecycle.LifecycleManager;
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
import org.briarproject.bramble.api.system.AndroidExecutor;
|
||||||
|
import org.briarproject.briar.android.viewmodel.DbViewModel;
|
||||||
|
|
||||||
|
import java.util.concurrent.Executor;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
import static java.util.logging.Logger.getLogger;
|
||||||
|
|
||||||
|
@NotNullByDefault
|
||||||
|
public class BluetoothSetupViewModel extends DbViewModel {
|
||||||
|
|
||||||
|
private final static Logger LOG =
|
||||||
|
getLogger(BluetoothSetupViewModel.class.getName());
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
BluetoothSetupViewModel(Application application,
|
||||||
|
@DatabaseExecutor Executor dbExecutor,
|
||||||
|
LifecycleManager lifecycleManager,
|
||||||
|
TransactionManager db,
|
||||||
|
AndroidExecutor androidExecutor) {
|
||||||
|
super(application, dbExecutor, lifecycleManager, db, androidExecutor);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -15,6 +15,7 @@ import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
|
|||||||
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
||||||
import org.briarproject.briar.R;
|
import org.briarproject.briar.R;
|
||||||
import org.briarproject.briar.android.activity.ActivityComponent;
|
import org.briarproject.briar.android.activity.ActivityComponent;
|
||||||
|
import org.briarproject.briar.android.bluetoothsetup.BluetoothSetupActivity;
|
||||||
import org.briarproject.briar.android.contact.BaseContactListAdapter.OnContactClickListener;
|
import org.briarproject.briar.android.contact.BaseContactListAdapter.OnContactClickListener;
|
||||||
import org.briarproject.briar.android.contact.add.remote.AddContactActivity;
|
import org.briarproject.briar.android.contact.add.remote.AddContactActivity;
|
||||||
import org.briarproject.briar.android.contact.add.remote.PendingContactListActivity;
|
import org.briarproject.briar.android.contact.add.remote.PendingContactListActivity;
|
||||||
@@ -134,6 +135,11 @@ public class ContactListFragment extends BaseFragment
|
|||||||
case R.id.action_add_contact_remotely:
|
case R.id.action_add_contact_remotely:
|
||||||
startActivity(
|
startActivity(
|
||||||
new Intent(getContext(), AddContactActivity.class));
|
new Intent(getContext(), AddContactActivity.class));
|
||||||
|
return;
|
||||||
|
case R.id.action_bluetooth_setup:
|
||||||
|
startActivity(
|
||||||
|
new Intent(getContext(),
|
||||||
|
BluetoothSetupActivity.class));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -124,7 +124,7 @@ public class AddContactViewModel extends DbViewModel {
|
|||||||
return addContactResult;
|
return addContactResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
void updatePendingContact(String name, PendingContact p) {
|
public 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,7 +48,6 @@ 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;
|
||||||
@@ -68,20 +67,6 @@ 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
|
||||||
@@ -89,9 +74,14 @@ 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);
|
||||||
|
|
||||||
@@ -103,12 +93,6 @@ 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();
|
||||||
|
|||||||
@@ -56,11 +56,8 @@ public abstract class BaseContactSelectorFragment<I extends SelectableContactIte
|
|||||||
|
|
||||||
Bundle args = requireArguments();
|
Bundle args = requireArguments();
|
||||||
byte[] b = args.getByteArray(GROUP_ID);
|
byte[] b = args.getByteArray(GROUP_ID);
|
||||||
// if (b == null) throw new IllegalStateException("No GroupId");
|
if (b == null) throw new IllegalStateException("No GroupId");
|
||||||
// TODO find what the groupId should be when selecting custodians
|
groupId = new GroupId(b);
|
||||||
if (b != null) {
|
|
||||||
groupId = new GroupId(b);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ public abstract class ContactSelectorFragment extends
|
|||||||
|
|
||||||
public static final String TAG = ContactSelectorFragment.class.getName();
|
public static final String TAG = ContactSelectorFragment.class.getName();
|
||||||
|
|
||||||
protected Menu menu;
|
private Menu menu;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ContactSelectorAdapter getAdapter(Context context,
|
protected ContactSelectorAdapter getAdapter(Context context,
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import java.util.Collection;
|
|||||||
|
|
||||||
import androidx.annotation.UiThread;
|
import androidx.annotation.UiThread;
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
@NotNullByDefault
|
@NotNullByDefault
|
||||||
public interface SharingController {
|
public interface SharingController {
|
||||||
|
|
||||||
|
|||||||
@@ -18,7 +18,6 @@ import javax.inject.Inject;
|
|||||||
|
|
||||||
import androidx.annotation.UiThread;
|
import androidx.annotation.UiThread;
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
@NotNullByDefault
|
@NotNullByDefault
|
||||||
public class SharingControllerImpl implements SharingController, EventListener {
|
public class SharingControllerImpl implements SharingController, EventListener {
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package org.briarproject.briar.android.conversation;
|
|||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.graphics.drawable.Drawable;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
import android.transition.Slide;
|
import android.transition.Slide;
|
||||||
@@ -106,7 +105,6 @@ import androidx.recyclerview.selection.SelectionTracker.SelectionObserver;
|
|||||||
import androidx.recyclerview.selection.StorageStrategy;
|
import androidx.recyclerview.selection.StorageStrategy;
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
import androidx.vectordrawable.graphics.drawable.VectorDrawableCompat;
|
|
||||||
import de.hdodenhof.circleimageview.CircleImageView;
|
import de.hdodenhof.circleimageview.CircleImageView;
|
||||||
import uk.co.samuelwall.materialtaptargetprompt.MaterialTapTargetPrompt;
|
import uk.co.samuelwall.materialtaptargetprompt.MaterialTapTargetPrompt;
|
||||||
|
|
||||||
@@ -481,10 +479,12 @@ public class ConversationActivity extends BriarActivity
|
|||||||
@UiThread
|
@UiThread
|
||||||
private void displayContactOnlineStatus() {
|
private void displayContactOnlineStatus() {
|
||||||
if (connectionRegistry.isConnected(contactId)) {
|
if (connectionRegistry.isConnected(contactId)) {
|
||||||
toolbarStatus.setImageResource(R.drawable.contact_online);
|
toolbarStatus.setImageDrawable(ContextCompat.getDrawable(
|
||||||
|
ConversationActivity.this, R.drawable.contact_online));
|
||||||
toolbarStatus.setContentDescription(getString(R.string.online));
|
toolbarStatus.setContentDescription(getString(R.string.online));
|
||||||
} else {
|
} else {
|
||||||
toolbarStatus.setImageResource(R.drawable.contact_offline);
|
toolbarStatus.setImageDrawable(ContextCompat.getDrawable(
|
||||||
|
ConversationActivity.this, R.drawable.contact_offline));
|
||||||
toolbarStatus.setContentDescription(getString(R.string.offline));
|
toolbarStatus.setContentDescription(getString(R.string.offline));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -935,16 +935,13 @@ public class ConversationActivity extends BriarActivity
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int color =
|
|
||||||
ContextCompat.getColor(this, R.color.briar_primary);
|
|
||||||
Drawable drawable = VectorDrawableCompat
|
|
||||||
.create(getResources(), R.drawable.ic_more_vert_accent, null);
|
|
||||||
new MaterialTapTargetPrompt.Builder(ConversationActivity.this,
|
new MaterialTapTargetPrompt.Builder(ConversationActivity.this,
|
||||||
R.style.OnboardingDialogTheme).setTarget(target)
|
R.style.OnboardingDialogTheme).setTarget(target)
|
||||||
.setPrimaryText(R.string.introduction_onboarding_title)
|
.setPrimaryText(R.string.introduction_onboarding_title)
|
||||||
.setSecondaryText(R.string.introduction_onboarding_text)
|
.setSecondaryText(R.string.introduction_onboarding_text)
|
||||||
.setIconDrawable(drawable)
|
.setIcon(R.drawable.ic_more_vert_accent)
|
||||||
.setBackgroundColour(color)
|
.setBackgroundColour(
|
||||||
|
ContextCompat.getColor(this, R.color.briar_primary))
|
||||||
.show();
|
.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,54 +6,52 @@ import android.os.Bundle;
|
|||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuInflater;
|
import android.view.MenuInflater;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.contact.ContactId;
|
||||||
|
import org.briarproject.bramble.api.db.DbException;
|
||||||
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
|
||||||
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
||||||
import org.briarproject.briar.R;
|
import org.briarproject.briar.R;
|
||||||
import org.briarproject.briar.android.activity.ActivityComponent;
|
import org.briarproject.briar.android.activity.ActivityComponent;
|
||||||
|
import org.briarproject.briar.android.controller.handler.UiResultExceptionHandler;
|
||||||
|
import org.briarproject.briar.android.forum.ForumController.ForumListener;
|
||||||
import org.briarproject.briar.android.sharing.ForumSharingStatusActivity;
|
import org.briarproject.briar.android.sharing.ForumSharingStatusActivity;
|
||||||
import org.briarproject.briar.android.sharing.ShareForumActivity;
|
import org.briarproject.briar.android.sharing.ShareForumActivity;
|
||||||
import org.briarproject.briar.android.threaded.ThreadItemAdapter;
|
import org.briarproject.briar.android.threaded.ThreadItemAdapter;
|
||||||
import org.briarproject.briar.android.threaded.ThreadListActivity;
|
import org.briarproject.briar.android.threaded.ThreadListActivity;
|
||||||
import org.briarproject.briar.android.threaded.ThreadListViewModel;
|
import org.briarproject.briar.android.threaded.ThreadListController;
|
||||||
|
import org.briarproject.briar.api.forum.Forum;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
import androidx.appcompat.app.AlertDialog;
|
import androidx.appcompat.app.AlertDialog;
|
||||||
import androidx.appcompat.widget.Toolbar;
|
import androidx.appcompat.widget.Toolbar;
|
||||||
import androidx.lifecycle.ViewModelProvider;
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||||
|
|
||||||
import static android.content.Intent.FLAG_ACTIVITY_CLEAR_TOP;
|
import static android.content.Intent.FLAG_ACTIVITY_CLEAR_TOP;
|
||||||
|
import static android.widget.Toast.LENGTH_SHORT;
|
||||||
import static org.briarproject.briar.android.activity.RequestCodes.REQUEST_SHARE_FORUM;
|
import static org.briarproject.briar.android.activity.RequestCodes.REQUEST_SHARE_FORUM;
|
||||||
import static org.briarproject.briar.android.util.UiUtils.observeOnce;
|
|
||||||
import static org.briarproject.briar.api.forum.ForumConstants.MAX_FORUM_POST_TEXT_LENGTH;
|
import static org.briarproject.briar.api.forum.ForumConstants.MAX_FORUM_POST_TEXT_LENGTH;
|
||||||
|
|
||||||
@MethodsNotNullByDefault
|
@MethodsNotNullByDefault
|
||||||
@ParametersNotNullByDefault
|
@ParametersNotNullByDefault
|
||||||
public class ForumActivity extends
|
public class ForumActivity extends
|
||||||
ThreadListActivity<ForumPostItem, ThreadItemAdapter<ForumPostItem>> {
|
ThreadListActivity<Forum, ForumPostItem, ThreadItemAdapter<ForumPostItem>>
|
||||||
|
implements ForumListener {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
ViewModelProvider.Factory viewModelFactory;
|
ForumController forumController;
|
||||||
|
|
||||||
private ForumViewModel viewModel;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void injectActivity(ActivityComponent component) {
|
public void injectActivity(ActivityComponent component) {
|
||||||
component.inject(this);
|
component.inject(this);
|
||||||
viewModel = new ViewModelProvider(this, viewModelFactory)
|
|
||||||
.get(ForumViewModel.class);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ThreadListViewModel<ForumPostItem> getViewModel() {
|
protected ThreadListController<Forum, ForumPostItem> getController() {
|
||||||
return viewModel;
|
return forumController;
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected ThreadItemAdapter<ForumPostItem> createAdapter() {
|
|
||||||
return new ThreadItemAdapter<>(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -61,27 +59,36 @@ public class ForumActivity extends
|
|||||||
super.onCreate(state);
|
super.onCreate(state);
|
||||||
|
|
||||||
Toolbar toolbar = setUpCustomToolbar(false);
|
Toolbar toolbar = setUpCustomToolbar(false);
|
||||||
// Open member list on Toolbar click
|
|
||||||
toolbar.setOnClickListener(v -> {
|
|
||||||
Intent i = new Intent(ForumActivity.this,
|
|
||||||
ForumSharingStatusActivity.class);
|
|
||||||
i.putExtra(GROUP_ID, groupId.getBytes());
|
|
||||||
startActivity(i);
|
|
||||||
});
|
|
||||||
|
|
||||||
String groupName = getIntent().getStringExtra(GROUP_NAME);
|
Intent i = getIntent();
|
||||||
if (groupName != null) {
|
String groupName = i.getStringExtra(GROUP_NAME);
|
||||||
setTitle(groupName);
|
if (groupName != null) setTitle(groupName);
|
||||||
} else {
|
else loadNamedGroup();
|
||||||
observeOnce(viewModel.loadForum(), this, forum ->
|
|
||||||
setTitle(forum.getName())
|
// Open member list on Toolbar click
|
||||||
);
|
if (toolbar != null) {
|
||||||
|
toolbar.setOnClickListener(v -> {
|
||||||
|
Intent i1 = new Intent(ForumActivity.this,
|
||||||
|
ForumSharingStatusActivity.class);
|
||||||
|
i1.putExtra(GROUP_ID, groupId.getBytes());
|
||||||
|
startActivity(i1);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onActivityResult(int request, int result,
|
protected void onNamedGroupLoaded(Forum forum) {
|
||||||
@Nullable Intent data) {
|
setTitle(forum.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected ThreadItemAdapter<ForumPostItem> createAdapter(
|
||||||
|
LinearLayoutManager layoutManager) {
|
||||||
|
return new ThreadItemAdapter<>(this, layoutManager);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onActivityResult(int request, int result, Intent data) {
|
||||||
super.onActivityResult(request, result, data);
|
super.onActivityResult(request, result, data);
|
||||||
|
|
||||||
if (request == REQUEST_SHARE_FORUM && result == RESULT_OK) {
|
if (request == REQUEST_SHARE_FORUM && result == RESULT_OK) {
|
||||||
@@ -94,31 +101,32 @@ public class ForumActivity extends
|
|||||||
// Inflate the menu items for use in the action bar
|
// Inflate the menu items for use in the action bar
|
||||||
MenuInflater inflater = getMenuInflater();
|
MenuInflater inflater = getMenuInflater();
|
||||||
inflater.inflate(R.menu.forum_actions, menu);
|
inflater.inflate(R.menu.forum_actions, menu);
|
||||||
super.onCreateOptionsMenu(menu);
|
|
||||||
return true;
|
return super.onCreateOptionsMenu(menu);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
// Handle presses on the action bar items
|
// Handle presses on the action bar items
|
||||||
int itemId = item.getItemId();
|
switch (item.getItemId()) {
|
||||||
if (itemId == R.id.action_forum_share) {
|
case R.id.action_forum_share:
|
||||||
Intent i = new Intent(this, ShareForumActivity.class);
|
Intent i2 = new Intent(this, ShareForumActivity.class);
|
||||||
i.setFlags(FLAG_ACTIVITY_CLEAR_TOP);
|
i2.setFlags(FLAG_ACTIVITY_CLEAR_TOP);
|
||||||
i.putExtra(GROUP_ID, groupId.getBytes());
|
i2.putExtra(GROUP_ID, groupId.getBytes());
|
||||||
startActivityForResult(i, REQUEST_SHARE_FORUM);
|
startActivityForResult(i2, REQUEST_SHARE_FORUM);
|
||||||
return true;
|
return true;
|
||||||
} else if (itemId == R.id.action_forum_sharing_status) {
|
case R.id.action_forum_sharing_status:
|
||||||
Intent i = new Intent(this, ForumSharingStatusActivity.class);
|
Intent i3 = new Intent(this, ForumSharingStatusActivity.class);
|
||||||
i.setFlags(FLAG_ACTIVITY_CLEAR_TOP);
|
i3.setFlags(FLAG_ACTIVITY_CLEAR_TOP);
|
||||||
i.putExtra(GROUP_ID, groupId.getBytes());
|
i3.putExtra(GROUP_ID, groupId.getBytes());
|
||||||
startActivity(i);
|
startActivity(i3);
|
||||||
return true;
|
return true;
|
||||||
} else if (itemId == R.id.action_forum_delete) {
|
case R.id.action_forum_delete:
|
||||||
showUnsubscribeDialog();
|
showUnsubscribeDialog();
|
||||||
return true;
|
return true;
|
||||||
|
default:
|
||||||
|
return super.onOptionsItemSelected(item);
|
||||||
}
|
}
|
||||||
return super.onOptionsItemSelected(item);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -127,7 +135,7 @@ public class ForumActivity extends
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void showUnsubscribeDialog() {
|
private void showUnsubscribeDialog() {
|
||||||
OnClickListener okListener = (dialog, which) -> viewModel.deleteForum();
|
OnClickListener okListener = (dialog, which) -> deleteForum();
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(this,
|
AlertDialog.Builder builder = new AlertDialog.Builder(this,
|
||||||
R.style.BriarDialogTheme);
|
R.style.BriarDialogTheme);
|
||||||
builder.setTitle(getString(R.string.dialog_title_leave_forum));
|
builder.setTitle(getString(R.string.dialog_title_leave_forum));
|
||||||
@@ -137,4 +145,27 @@ public class ForumActivity extends
|
|||||||
builder.show();
|
builder.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void deleteForum() {
|
||||||
|
forumController.deleteNamedGroup(
|
||||||
|
new UiResultExceptionHandler<Void, DbException>(this) {
|
||||||
|
@Override
|
||||||
|
public void onResultUi(Void v) {
|
||||||
|
Toast.makeText(ForumActivity.this,
|
||||||
|
R.string.forum_left_toast, LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onExceptionUi(DbException exception) {
|
||||||
|
handleException(exception);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onForumLeft(ContactId c) {
|
||||||
|
sharingController.remove(c);
|
||||||
|
setToolbarSubTitle(sharingController.getTotalCount(),
|
||||||
|
sharingController.getOnlineCount());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
package org.briarproject.briar.android.forum;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.contact.ContactId;
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
import org.briarproject.briar.android.threaded.ThreadListController;
|
||||||
|
import org.briarproject.briar.api.forum.Forum;
|
||||||
|
|
||||||
|
import androidx.annotation.UiThread;
|
||||||
|
|
||||||
|
@NotNullByDefault
|
||||||
|
interface ForumController extends ThreadListController<Forum, ForumPostItem> {
|
||||||
|
|
||||||
|
interface ForumListener extends ThreadListListener<ForumPostItem> {
|
||||||
|
@UiThread
|
||||||
|
void onForumLeft(ContactId c);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,185 @@
|
|||||||
|
package org.briarproject.briar.android.forum;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.contact.Contact;
|
||||||
|
import org.briarproject.bramble.api.contact.ContactId;
|
||||||
|
import org.briarproject.bramble.api.crypto.CryptoExecutor;
|
||||||
|
import org.briarproject.bramble.api.db.DatabaseExecutor;
|
||||||
|
import org.briarproject.bramble.api.db.DbException;
|
||||||
|
import org.briarproject.bramble.api.event.Event;
|
||||||
|
import org.briarproject.bramble.api.event.EventBus;
|
||||||
|
import org.briarproject.bramble.api.identity.IdentityManager;
|
||||||
|
import org.briarproject.bramble.api.identity.LocalAuthor;
|
||||||
|
import org.briarproject.bramble.api.lifecycle.LifecycleManager;
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
import org.briarproject.bramble.api.sync.MessageId;
|
||||||
|
import org.briarproject.bramble.api.system.Clock;
|
||||||
|
import org.briarproject.briar.android.controller.handler.ResultExceptionHandler;
|
||||||
|
import org.briarproject.briar.android.forum.ForumController.ForumListener;
|
||||||
|
import org.briarproject.briar.android.threaded.ThreadListControllerImpl;
|
||||||
|
import org.briarproject.briar.api.android.AndroidNotificationManager;
|
||||||
|
import org.briarproject.briar.api.client.MessageTracker;
|
||||||
|
import org.briarproject.briar.api.client.MessageTracker.GroupCount;
|
||||||
|
import org.briarproject.briar.api.forum.Forum;
|
||||||
|
import org.briarproject.briar.api.forum.ForumInvitationResponse;
|
||||||
|
import org.briarproject.briar.api.forum.ForumManager;
|
||||||
|
import org.briarproject.briar.api.forum.ForumPost;
|
||||||
|
import org.briarproject.briar.api.forum.ForumPostHeader;
|
||||||
|
import org.briarproject.briar.api.forum.ForumSharingManager;
|
||||||
|
import org.briarproject.briar.api.forum.event.ForumInvitationResponseReceivedEvent;
|
||||||
|
import org.briarproject.briar.api.forum.event.ForumPostReceivedEvent;
|
||||||
|
import org.briarproject.briar.api.sharing.event.ContactLeftShareableEvent;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.concurrent.Executor;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
import static java.lang.Math.max;
|
||||||
|
import static java.util.logging.Level.WARNING;
|
||||||
|
import static org.briarproject.bramble.util.LogUtils.logException;
|
||||||
|
|
||||||
|
@NotNullByDefault
|
||||||
|
class ForumControllerImpl extends
|
||||||
|
ThreadListControllerImpl<Forum, ForumPostItem, ForumPostHeader, ForumPost, ForumListener>
|
||||||
|
implements ForumController {
|
||||||
|
|
||||||
|
private static final Logger LOG =
|
||||||
|
Logger.getLogger(ForumControllerImpl.class.getName());
|
||||||
|
|
||||||
|
private final ForumManager forumManager;
|
||||||
|
private final ForumSharingManager forumSharingManager;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
ForumControllerImpl(@DatabaseExecutor Executor dbExecutor,
|
||||||
|
LifecycleManager lifecycleManager, IdentityManager identityManager,
|
||||||
|
@CryptoExecutor Executor cryptoExecutor,
|
||||||
|
ForumManager forumManager, ForumSharingManager forumSharingManager,
|
||||||
|
EventBus eventBus, Clock clock, MessageTracker messageTracker,
|
||||||
|
AndroidNotificationManager notificationManager) {
|
||||||
|
super(dbExecutor, lifecycleManager, identityManager, cryptoExecutor,
|
||||||
|
eventBus, clock, notificationManager, messageTracker);
|
||||||
|
this.forumManager = forumManager;
|
||||||
|
this.forumSharingManager = forumSharingManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onActivityStart() {
|
||||||
|
super.onActivityStart();
|
||||||
|
notificationManager.clearForumPostNotification(getGroupId());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void eventOccurred(Event e) {
|
||||||
|
super.eventOccurred(e);
|
||||||
|
|
||||||
|
if (e instanceof ForumPostReceivedEvent) {
|
||||||
|
ForumPostReceivedEvent f = (ForumPostReceivedEvent) e;
|
||||||
|
if (f.getGroupId().equals(getGroupId())) {
|
||||||
|
LOG.info("Forum post received, adding...");
|
||||||
|
listener.onItemReceived(buildItem(f.getHeader(), f.getText()));
|
||||||
|
}
|
||||||
|
} else if (e instanceof ForumInvitationResponseReceivedEvent) {
|
||||||
|
ForumInvitationResponseReceivedEvent f =
|
||||||
|
(ForumInvitationResponseReceivedEvent) e;
|
||||||
|
ForumInvitationResponse r = f.getMessageHeader();
|
||||||
|
if (r.getShareableId().equals(getGroupId()) && r.wasAccepted()) {
|
||||||
|
LOG.info("Forum invitation was accepted");
|
||||||
|
listener.onInvitationAccepted(f.getContactId());
|
||||||
|
}
|
||||||
|
} else if (e instanceof ContactLeftShareableEvent) {
|
||||||
|
ContactLeftShareableEvent c = (ContactLeftShareableEvent) e;
|
||||||
|
if (c.getGroupId().equals(getGroupId())) {
|
||||||
|
LOG.info("Forum left by contact");
|
||||||
|
listener.onForumLeft(c.getContactId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Forum loadNamedGroup() throws DbException {
|
||||||
|
return forumManager.getForum(getGroupId());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Collection<ForumPostHeader> loadHeaders() throws DbException {
|
||||||
|
return forumManager.getPostHeaders(getGroupId());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String loadMessageText(ForumPostHeader h) throws DbException {
|
||||||
|
return forumManager.getPostText(h.getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void markRead(MessageId id) throws DbException {
|
||||||
|
forumManager.setReadFlag(getGroupId(), id, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void loadSharingContacts(
|
||||||
|
ResultExceptionHandler<Collection<ContactId>, DbException> handler) {
|
||||||
|
runOnDbThread(() -> {
|
||||||
|
try {
|
||||||
|
Collection<Contact> contacts =
|
||||||
|
forumSharingManager.getSharedWith(getGroupId());
|
||||||
|
Collection<ContactId> contactIds =
|
||||||
|
new ArrayList<>(contacts.size());
|
||||||
|
for (Contact c : contacts) contactIds.add(c.getId());
|
||||||
|
handler.onResult(contactIds);
|
||||||
|
} catch (DbException e) {
|
||||||
|
logException(LOG, WARNING, e);
|
||||||
|
handler.onException(e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void createAndStoreMessage(String text,
|
||||||
|
@Nullable ForumPostItem parentItem,
|
||||||
|
ResultExceptionHandler<ForumPostItem, DbException> handler) {
|
||||||
|
runOnDbThread(() -> {
|
||||||
|
try {
|
||||||
|
LocalAuthor author = identityManager.getLocalAuthor();
|
||||||
|
GroupCount count = forumManager.getGroupCount(getGroupId());
|
||||||
|
long timestamp = max(count.getLatestMsgTime() + 1,
|
||||||
|
clock.currentTimeMillis());
|
||||||
|
MessageId parentId = parentItem != null ?
|
||||||
|
parentItem.getId() : null;
|
||||||
|
createMessage(text, timestamp, parentId, author, handler);
|
||||||
|
} catch (DbException e) {
|
||||||
|
logException(LOG, WARNING, e);
|
||||||
|
handler.onException(e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void createMessage(String text, long timestamp,
|
||||||
|
@Nullable MessageId parentId, LocalAuthor author,
|
||||||
|
ResultExceptionHandler<ForumPostItem, DbException> handler) {
|
||||||
|
cryptoExecutor.execute(() -> {
|
||||||
|
LOG.info("Creating forum post...");
|
||||||
|
ForumPost msg = forumManager.createLocalPost(getGroupId(), text,
|
||||||
|
timestamp, parentId, author);
|
||||||
|
storePost(msg, text, handler);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected ForumPostHeader addLocalMessage(ForumPost p) throws DbException {
|
||||||
|
return forumManager.addLocalPost(p);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void deleteNamedGroup(Forum forum) throws DbException {
|
||||||
|
forumManager.removeForum(forum);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected ForumPostItem buildItem(ForumPostHeader header, String text) {
|
||||||
|
return new ForumPostItem(header, text);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,23 +1,32 @@
|
|||||||
package org.briarproject.briar.android.forum;
|
package org.briarproject.briar.android.forum;
|
||||||
|
|
||||||
|
import org.briarproject.briar.android.activity.ActivityScope;
|
||||||
|
import org.briarproject.briar.android.activity.BaseActivity;
|
||||||
import org.briarproject.briar.android.viewmodel.ViewModelKey;
|
import org.briarproject.briar.android.viewmodel.ViewModelKey;
|
||||||
|
|
||||||
import androidx.lifecycle.ViewModel;
|
import androidx.lifecycle.ViewModel;
|
||||||
import dagger.Binds;
|
import dagger.Binds;
|
||||||
import dagger.Module;
|
import dagger.Module;
|
||||||
|
import dagger.Provides;
|
||||||
import dagger.multibindings.IntoMap;
|
import dagger.multibindings.IntoMap;
|
||||||
|
|
||||||
@Module
|
@Module
|
||||||
public interface ForumModule {
|
public class ForumModule {
|
||||||
|
|
||||||
@Binds
|
@Module
|
||||||
@IntoMap
|
public interface BindsModule {
|
||||||
@ViewModelKey(ForumListViewModel.class)
|
@Binds
|
||||||
ViewModel bindForumListViewModel(ForumListViewModel forumListViewModel);
|
@IntoMap
|
||||||
|
@ViewModelKey(ForumListViewModel.class)
|
||||||
|
ViewModel bindForumListViewModel(ForumListViewModel forumListViewModel);
|
||||||
|
}
|
||||||
|
|
||||||
@Binds
|
@ActivityScope
|
||||||
@IntoMap
|
@Provides
|
||||||
@ViewModelKey(ForumViewModel.class)
|
ForumController provideForumController(BaseActivity activity,
|
||||||
ViewModel bindForumViewModel(ForumViewModel forumViewModel);
|
ForumControllerImpl forumController) {
|
||||||
|
activity.addLifecycleController(forumController);
|
||||||
|
return forumController;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import org.briarproject.bramble.api.sync.MessageId;
|
|||||||
import org.briarproject.briar.android.threaded.ThreadItem;
|
import org.briarproject.briar.android.threaded.ThreadItem;
|
||||||
import org.briarproject.briar.api.forum.ForumPostHeader;
|
import org.briarproject.briar.api.forum.ForumPostHeader;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
import javax.annotation.concurrent.NotThreadSafe;
|
import javax.annotation.concurrent.NotThreadSafe;
|
||||||
|
|
||||||
@NotThreadSafe
|
@NotThreadSafe
|
||||||
@@ -16,4 +17,9 @@ class ForumPostItem extends ThreadItem {
|
|||||||
h.getAuthorInfo(), h.isRead());
|
h.getAuthorInfo(), h.isRead());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ForumPostItem(MessageId messageId, @Nullable MessageId parentId,
|
||||||
|
String text, long timestamp, Author author, AuthorInfo authorInfo) {
|
||||||
|
super(messageId, parentId, text, timestamp, author, authorInfo, true);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,231 +0,0 @@
|
|||||||
package org.briarproject.briar.android.forum;
|
|
||||||
|
|
||||||
import android.app.Application;
|
|
||||||
import android.widget.Toast;
|
|
||||||
|
|
||||||
import org.briarproject.bramble.api.contact.Contact;
|
|
||||||
import org.briarproject.bramble.api.contact.ContactId;
|
|
||||||
import org.briarproject.bramble.api.crypto.CryptoExecutor;
|
|
||||||
import org.briarproject.bramble.api.db.DatabaseExecutor;
|
|
||||||
import org.briarproject.bramble.api.db.DbException;
|
|
||||||
import org.briarproject.bramble.api.db.Transaction;
|
|
||||||
import org.briarproject.bramble.api.db.TransactionManager;
|
|
||||||
import org.briarproject.bramble.api.event.Event;
|
|
||||||
import org.briarproject.bramble.api.event.EventBus;
|
|
||||||
import org.briarproject.bramble.api.identity.IdentityManager;
|
|
||||||
import org.briarproject.bramble.api.identity.LocalAuthor;
|
|
||||||
import org.briarproject.bramble.api.lifecycle.LifecycleManager;
|
|
||||||
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
|
|
||||||
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
|
||||||
import org.briarproject.bramble.api.sync.MessageId;
|
|
||||||
import org.briarproject.bramble.api.system.AndroidExecutor;
|
|
||||||
import org.briarproject.bramble.api.system.Clock;
|
|
||||||
import org.briarproject.briar.R;
|
|
||||||
import org.briarproject.briar.android.sharing.SharingController;
|
|
||||||
import org.briarproject.briar.android.threaded.ThreadListViewModel;
|
|
||||||
import org.briarproject.briar.api.android.AndroidNotificationManager;
|
|
||||||
import org.briarproject.briar.api.client.MessageTracker;
|
|
||||||
import org.briarproject.briar.api.client.MessageTracker.GroupCount;
|
|
||||||
import org.briarproject.briar.api.forum.Forum;
|
|
||||||
import org.briarproject.briar.api.forum.ForumInvitationResponse;
|
|
||||||
import org.briarproject.briar.api.forum.ForumManager;
|
|
||||||
import org.briarproject.briar.api.forum.ForumPost;
|
|
||||||
import org.briarproject.briar.api.forum.ForumPostHeader;
|
|
||||||
import org.briarproject.briar.api.forum.ForumSharingManager;
|
|
||||||
import org.briarproject.briar.api.forum.event.ForumInvitationResponseReceivedEvent;
|
|
||||||
import org.briarproject.briar.api.forum.event.ForumPostReceivedEvent;
|
|
||||||
import org.briarproject.briar.api.sharing.event.ContactLeftShareableEvent;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.concurrent.Executor;
|
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
import javax.inject.Inject;
|
|
||||||
|
|
||||||
import androidx.lifecycle.LiveData;
|
|
||||||
import androidx.lifecycle.MutableLiveData;
|
|
||||||
|
|
||||||
import static android.widget.Toast.LENGTH_SHORT;
|
|
||||||
import static java.lang.Math.max;
|
|
||||||
import static java.util.logging.Level.WARNING;
|
|
||||||
import static java.util.logging.Logger.getLogger;
|
|
||||||
import static org.briarproject.bramble.util.LogUtils.logDuration;
|
|
||||||
import static org.briarproject.bramble.util.LogUtils.logException;
|
|
||||||
import static org.briarproject.bramble.util.LogUtils.now;
|
|
||||||
|
|
||||||
@MethodsNotNullByDefault
|
|
||||||
@ParametersNotNullByDefault
|
|
||||||
class ForumViewModel extends ThreadListViewModel<ForumPostItem> {
|
|
||||||
|
|
||||||
private static final Logger LOG = getLogger(ForumViewModel.class.getName());
|
|
||||||
|
|
||||||
private final ForumManager forumManager;
|
|
||||||
private final ForumSharingManager forumSharingManager;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
ForumViewModel(Application application,
|
|
||||||
@DatabaseExecutor Executor dbExecutor,
|
|
||||||
LifecycleManager lifecycleManager,
|
|
||||||
TransactionManager db,
|
|
||||||
AndroidExecutor androidExecutor,
|
|
||||||
IdentityManager identityManager,
|
|
||||||
AndroidNotificationManager notificationManager,
|
|
||||||
SharingController sharingController,
|
|
||||||
@CryptoExecutor Executor cryptoExecutor,
|
|
||||||
Clock clock,
|
|
||||||
MessageTracker messageTracker,
|
|
||||||
EventBus eventBus,
|
|
||||||
ForumManager forumManager,
|
|
||||||
ForumSharingManager forumSharingManager) {
|
|
||||||
super(application, dbExecutor, lifecycleManager, db, androidExecutor,
|
|
||||||
identityManager, notificationManager, sharingController,
|
|
||||||
cryptoExecutor, clock, messageTracker, eventBus);
|
|
||||||
this.forumManager = forumManager;
|
|
||||||
this.forumSharingManager = forumSharingManager;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void eventOccurred(Event e) {
|
|
||||||
if (e instanceof ForumPostReceivedEvent) {
|
|
||||||
ForumPostReceivedEvent f = (ForumPostReceivedEvent) e;
|
|
||||||
if (f.getGroupId().equals(groupId)) {
|
|
||||||
LOG.info("Forum post received, adding...");
|
|
||||||
ForumPostItem item =
|
|
||||||
new ForumPostItem(f.getHeader(), f.getText());
|
|
||||||
addItem(item, false);
|
|
||||||
}
|
|
||||||
} else if (e instanceof ForumInvitationResponseReceivedEvent) {
|
|
||||||
ForumInvitationResponseReceivedEvent f =
|
|
||||||
(ForumInvitationResponseReceivedEvent) e;
|
|
||||||
ForumInvitationResponse r = f.getMessageHeader();
|
|
||||||
if (r.getShareableId().equals(groupId) && r.wasAccepted()) {
|
|
||||||
LOG.info("Forum invitation was accepted");
|
|
||||||
sharingController.add(f.getContactId());
|
|
||||||
}
|
|
||||||
} else if (e instanceof ContactLeftShareableEvent) {
|
|
||||||
ContactLeftShareableEvent c = (ContactLeftShareableEvent) e;
|
|
||||||
if (c.getGroupId().equals(groupId)) {
|
|
||||||
LOG.info("Forum left by contact");
|
|
||||||
sharingController.remove(c.getContactId());
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
super.eventOccurred(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void clearNotifications() {
|
|
||||||
notificationManager.clearForumPostNotification(groupId);
|
|
||||||
}
|
|
||||||
|
|
||||||
LiveData<Forum> loadForum() {
|
|
||||||
MutableLiveData<Forum> forum = new MutableLiveData<>();
|
|
||||||
runOnDbThread(() -> {
|
|
||||||
try {
|
|
||||||
Forum f = forumManager.getForum(groupId);
|
|
||||||
forum.postValue(f);
|
|
||||||
} catch (DbException e) {
|
|
||||||
logException(LOG, WARNING, e);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return forum;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void loadItems() {
|
|
||||||
loadList(txn -> {
|
|
||||||
long start = now();
|
|
||||||
List<ForumPostHeader> headers =
|
|
||||||
forumManager.getPostHeaders(txn, groupId);
|
|
||||||
logDuration(LOG, "Loading headers", start);
|
|
||||||
start = now();
|
|
||||||
List<ForumPostItem> items = new ArrayList<>();
|
|
||||||
for (ForumPostHeader header : headers) {
|
|
||||||
items.add(loadItem(txn, header));
|
|
||||||
}
|
|
||||||
logDuration(LOG, "Loading bodies and creating items", start);
|
|
||||||
return items;
|
|
||||||
}, this::setItems);
|
|
||||||
}
|
|
||||||
|
|
||||||
private ForumPostItem loadItem(Transaction txn, ForumPostHeader header)
|
|
||||||
throws DbException {
|
|
||||||
String text = forumManager.getPostText(txn, header.getId());
|
|
||||||
return new ForumPostItem(header, text);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void createAndStoreMessage(String text,
|
|
||||||
@Nullable MessageId parentId) {
|
|
||||||
runOnDbThread(() -> {
|
|
||||||
try {
|
|
||||||
LocalAuthor author = identityManager.getLocalAuthor();
|
|
||||||
GroupCount count = forumManager.getGroupCount(groupId);
|
|
||||||
long timestamp = max(count.getLatestMsgTime() + 1,
|
|
||||||
clock.currentTimeMillis());
|
|
||||||
createMessage(text, timestamp, parentId, author);
|
|
||||||
} catch (DbException e) {
|
|
||||||
logException(LOG, WARNING, e);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private void createMessage(String text, long timestamp,
|
|
||||||
@Nullable MessageId parentId, LocalAuthor author) {
|
|
||||||
cryptoExecutor.execute(() -> {
|
|
||||||
LOG.info("Creating forum post...");
|
|
||||||
ForumPost msg = forumManager.createLocalPost(groupId, text,
|
|
||||||
timestamp, parentId, author);
|
|
||||||
storePost(msg, text);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private void storePost(ForumPost msg, String text) {
|
|
||||||
runOnDbThread(false, txn -> {
|
|
||||||
long start = now();
|
|
||||||
ForumPostHeader header = forumManager.addLocalPost(txn, msg);
|
|
||||||
logDuration(LOG, "Storing forum post", start);
|
|
||||||
txn.attach(() -> {
|
|
||||||
ForumPostItem item = new ForumPostItem(header, text);
|
|
||||||
addItem(item, true);
|
|
||||||
});
|
|
||||||
}, e -> logException(LOG, WARNING, e));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void markItemRead(ForumPostItem item) {
|
|
||||||
runOnDbThread(() -> {
|
|
||||||
try {
|
|
||||||
forumManager.setReadFlag(groupId, item.getId(), true);
|
|
||||||
} catch (DbException e) {
|
|
||||||
logException(LOG, WARNING, e);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public void loadSharingContacts() {
|
|
||||||
runOnDbThread(true, txn -> {
|
|
||||||
Collection<Contact> contacts =
|
|
||||||
forumSharingManager.getSharedWith(txn, groupId);
|
|
||||||
Collection<ContactId> contactIds = new ArrayList<>(contacts.size());
|
|
||||||
for (Contact c : contacts) contactIds.add(c.getId());
|
|
||||||
txn.attach(() -> sharingController.addAll(contactIds));
|
|
||||||
}, e -> logException(LOG, WARNING, e));
|
|
||||||
}
|
|
||||||
|
|
||||||
void deleteForum() {
|
|
||||||
runOnDbThread(() -> {
|
|
||||||
try {
|
|
||||||
Forum f = forumManager.getForum(groupId);
|
|
||||||
forumManager.removeForum(f);
|
|
||||||
} catch (DbException e) {
|
|
||||||
logException(LOG, WARNING, e);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
Toast.makeText(getApplication(), R.string.forum_left_toast,
|
|
||||||
LENGTH_SHORT).show();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -4,7 +4,6 @@ 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;
|
||||||
@@ -18,16 +17,6 @@ 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,10 +21,6 @@ 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) {
|
||||||
|
|||||||
@@ -1,16 +0,0 @@
|
|||||||
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);
|
|
||||||
}
|
|
||||||
@@ -1,61 +0,0 @@
|
|||||||
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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
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();
|
|
||||||
}
|
|
||||||
@@ -1,77 +0,0 @@
|
|||||||
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');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,13 +1,17 @@
|
|||||||
package org.briarproject.briar.android.login;
|
package org.briarproject.briar.android.login;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.graphics.drawable.Drawable;
|
||||||
|
|
||||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
import org.briarproject.briar.R;
|
import org.briarproject.briar.R;
|
||||||
|
|
||||||
import androidx.appcompat.app.AlertDialog;
|
import androidx.appcompat.app.AlertDialog;
|
||||||
|
|
||||||
import static org.briarproject.briar.android.util.UiUtils.getDialogIcon;
|
import static androidx.core.content.ContextCompat.getColor;
|
||||||
|
import static androidx.core.content.ContextCompat.getDrawable;
|
||||||
|
import static androidx.core.graphics.drawable.DrawableCompat.setTint;
|
||||||
|
import static java.util.Objects.requireNonNull;
|
||||||
|
|
||||||
@NotNullByDefault
|
@NotNullByDefault
|
||||||
class LoginUtils {
|
class LoginUtils {
|
||||||
@@ -15,7 +19,9 @@ class LoginUtils {
|
|||||||
static AlertDialog createKeyStrengthenerErrorDialog(Context ctx) {
|
static AlertDialog createKeyStrengthenerErrorDialog(Context ctx) {
|
||||||
AlertDialog.Builder builder =
|
AlertDialog.Builder builder =
|
||||||
new AlertDialog.Builder(ctx, R.style.BriarDialogTheme);
|
new AlertDialog.Builder(ctx, R.style.BriarDialogTheme);
|
||||||
builder.setIcon(getDialogIcon(ctx, R.drawable.alerts_and_states_error));
|
Drawable icon = getDrawable(ctx, R.drawable.alerts_and_states_error);
|
||||||
|
setTint(requireNonNull(icon), getColor(ctx, R.color.color_primary));
|
||||||
|
builder.setIcon(icon);
|
||||||
builder.setTitle(R.string.dialog_title_cannot_check_password);
|
builder.setTitle(R.string.dialog_title_cannot_check_password);
|
||||||
builder.setMessage(R.string.dialog_message_cannot_check_password);
|
builder.setMessage(R.string.dialog_message_cannot_check_password);
|
||||||
builder.setPositiveButton(R.string.ok, null);
|
builder.setPositiveButton(R.string.ok, null);
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
|
|||||||
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
||||||
import org.briarproject.briar.R;
|
import org.briarproject.briar.R;
|
||||||
import org.briarproject.briar.android.BriarService;
|
import org.briarproject.briar.android.BriarService;
|
||||||
import org.briarproject.briar.android.account.NewOrRecoverActivity;
|
|
||||||
import org.briarproject.briar.android.account.SetupActivity;
|
import org.briarproject.briar.android.account.SetupActivity;
|
||||||
import org.briarproject.briar.android.activity.ActivityComponent;
|
import org.briarproject.briar.android.activity.ActivityComponent;
|
||||||
import org.briarproject.briar.android.activity.BaseActivity;
|
import org.briarproject.briar.android.activity.BaseActivity;
|
||||||
@@ -108,7 +107,7 @@ public class StartupActivity extends BaseActivity implements
|
|||||||
private void onAccountDeleted() {
|
private void onAccountDeleted() {
|
||||||
setResult(RESULT_CANCELED);
|
setResult(RESULT_CANCELED);
|
||||||
finish();
|
finish();
|
||||||
Intent i = new Intent(this, NewOrRecoverActivity.class);
|
Intent i = new Intent(this, SetupActivity.class);
|
||||||
i.addFlags(FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_CLEAR_TOP |
|
i.addFlags(FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_CLEAR_TOP |
|
||||||
FLAG_ACTIVITY_CLEAR_TASK | FLAG_ACTIVITY_TASK_ON_HOME);
|
FLAG_ACTIVITY_CLEAR_TASK | FLAG_ACTIVITY_TASK_ON_HOME);
|
||||||
startActivity(i);
|
startActivity(i);
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package org.briarproject.briar.android.navdrawer;
|
|||||||
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.res.Configuration;
|
import android.content.res.Configuration;
|
||||||
import android.graphics.drawable.Drawable;
|
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
@@ -60,7 +59,6 @@ import androidx.fragment.app.FragmentTransaction;
|
|||||||
import androidx.lifecycle.MutableLiveData;
|
import androidx.lifecycle.MutableLiveData;
|
||||||
import androidx.lifecycle.ViewModelProvider;
|
import androidx.lifecycle.ViewModelProvider;
|
||||||
import androidx.lifecycle.ViewModelProviders;
|
import androidx.lifecycle.ViewModelProviders;
|
||||||
import androidx.vectordrawable.graphics.drawable.VectorDrawableCompat;
|
|
||||||
import uk.co.samuelwall.materialtaptargetprompt.MaterialTapTargetPrompt;
|
import uk.co.samuelwall.materialtaptargetprompt.MaterialTapTargetPrompt;
|
||||||
|
|
||||||
import static android.view.View.GONE;
|
import static android.view.View.GONE;
|
||||||
@@ -68,7 +66,6 @@ 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;
|
||||||
@@ -298,12 +295,6 @@ 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
|
||||||
@@ -442,7 +433,8 @@ public class NavDrawerActivity extends BriarActivity implements
|
|||||||
Transport t = getItem(position);
|
Transport t = getItem(position);
|
||||||
|
|
||||||
ImageView icon = view.findViewById(R.id.imageView);
|
ImageView icon = view.findViewById(R.id.imageView);
|
||||||
icon.setImageResource(t.iconDrawable);
|
icon.setImageDrawable(ContextCompat.getDrawable(
|
||||||
|
NavDrawerActivity.this, t.iconDrawable));
|
||||||
icon.setColorFilter(ContextCompat.getColor(
|
icon.setColorFilter(ContextCompat.getColor(
|
||||||
NavDrawerActivity.this, t.iconColor));
|
NavDrawerActivity.this, t.iconColor));
|
||||||
|
|
||||||
@@ -484,13 +476,11 @@ public class NavDrawerActivity extends BriarActivity implements
|
|||||||
private void showTransportsOnboarding(boolean show, ImageView imageView) {
|
private void showTransportsOnboarding(boolean show, ImageView imageView) {
|
||||||
if (show) {
|
if (show) {
|
||||||
int color = resolveColorAttribute(this, R.attr.colorControlNormal);
|
int color = resolveColorAttribute(this, R.attr.colorControlNormal);
|
||||||
Drawable drawable = VectorDrawableCompat
|
|
||||||
.create(getResources(), R.drawable.transport_tor, null);
|
|
||||||
new MaterialTapTargetPrompt.Builder(NavDrawerActivity.this,
|
new MaterialTapTargetPrompt.Builder(NavDrawerActivity.this,
|
||||||
R.style.OnboardingDialogTheme).setTarget(imageView)
|
R.style.OnboardingDialogTheme).setTarget(imageView)
|
||||||
.setPrimaryText(R.string.network_settings_title)
|
.setPrimaryText(R.string.network_settings_title)
|
||||||
.setSecondaryText(R.string.transports_onboarding_text)
|
.setSecondaryText(R.string.transports_onboarding_text)
|
||||||
.setIconDrawable(drawable)
|
.setIcon(R.drawable.transport_tor)
|
||||||
.setIconDrawableColourFilter(color)
|
.setIconDrawableColourFilter(color)
|
||||||
.setBackgroundColour(
|
.setBackgroundColour(
|
||||||
ContextCompat.getColor(this, R.color.briar_primary))
|
ContextCompat.getColor(this, R.color.briar_primary))
|
||||||
|
|||||||
@@ -141,7 +141,8 @@ public class TransportsActivity extends BriarActivity {
|
|||||||
Transport t = getItem(position);
|
Transport t = getItem(position);
|
||||||
|
|
||||||
ImageView icon = view.findViewById(R.id.icon);
|
ImageView icon = view.findViewById(R.id.icon);
|
||||||
icon.setImageResource(t.iconDrawable);
|
icon.setImageDrawable(ContextCompat.getDrawable(
|
||||||
|
TransportsActivity.this, t.iconDrawable));
|
||||||
icon.setColorFilter(ContextCompat.getColor(
|
icon.setColorFilter(ContextCompat.getColor(
|
||||||
TransportsActivity.this, t.iconColor));
|
TransportsActivity.this, t.iconColor));
|
||||||
|
|
||||||
|
|||||||
@@ -1,60 +1,67 @@
|
|||||||
package org.briarproject.briar.android.privategroup.conversation;
|
package org.briarproject.briar.android.privategroup.conversation;
|
||||||
|
|
||||||
|
import android.content.DialogInterface;
|
||||||
|
import android.content.DialogInterface.OnClickListener;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuInflater;
|
import android.view.MenuInflater;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.contact.ContactId;
|
||||||
|
import org.briarproject.bramble.api.db.DbException;
|
||||||
|
import org.briarproject.bramble.api.identity.AuthorId;
|
||||||
|
import org.briarproject.bramble.api.identity.LocalAuthor;
|
||||||
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
|
||||||
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
||||||
import org.briarproject.briar.R;
|
import org.briarproject.briar.R;
|
||||||
import org.briarproject.briar.android.activity.ActivityComponent;
|
import org.briarproject.briar.android.activity.ActivityComponent;
|
||||||
|
import org.briarproject.briar.android.controller.handler.UiExceptionHandler;
|
||||||
|
import org.briarproject.briar.android.controller.handler.UiResultExceptionHandler;
|
||||||
|
import org.briarproject.briar.android.privategroup.conversation.GroupController.GroupListener;
|
||||||
import org.briarproject.briar.android.privategroup.creation.GroupInviteActivity;
|
import org.briarproject.briar.android.privategroup.creation.GroupInviteActivity;
|
||||||
import org.briarproject.briar.android.privategroup.memberlist.GroupMemberListActivity;
|
import org.briarproject.briar.android.privategroup.memberlist.GroupMemberListActivity;
|
||||||
import org.briarproject.briar.android.privategroup.reveal.RevealContactsActivity;
|
import org.briarproject.briar.android.privategroup.reveal.RevealContactsActivity;
|
||||||
import org.briarproject.briar.android.threaded.ThreadListActivity;
|
import org.briarproject.briar.android.threaded.ThreadListActivity;
|
||||||
import org.briarproject.briar.android.threaded.ThreadListViewModel;
|
import org.briarproject.briar.android.threaded.ThreadListController;
|
||||||
|
import org.briarproject.briar.api.privategroup.PrivateGroup;
|
||||||
|
import org.briarproject.briar.api.privategroup.Visibility;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
import androidx.appcompat.app.AlertDialog;
|
import androidx.appcompat.app.AlertDialog;
|
||||||
import androidx.appcompat.widget.Toolbar;
|
import androidx.appcompat.widget.Toolbar;
|
||||||
import androidx.lifecycle.ViewModelProvider;
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||||
|
|
||||||
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 org.briarproject.bramble.api.nullsafety.NullSafety.requireNonNull;
|
|
||||||
import static org.briarproject.briar.android.activity.RequestCodes.REQUEST_GROUP_INVITE;
|
import static org.briarproject.briar.android.activity.RequestCodes.REQUEST_GROUP_INVITE;
|
||||||
import static org.briarproject.briar.android.util.UiUtils.observeOnce;
|
|
||||||
import static org.briarproject.briar.api.privategroup.PrivateGroupConstants.MAX_GROUP_POST_TEXT_LENGTH;
|
import static org.briarproject.briar.api.privategroup.PrivateGroupConstants.MAX_GROUP_POST_TEXT_LENGTH;
|
||||||
|
|
||||||
@MethodsNotNullByDefault
|
@MethodsNotNullByDefault
|
||||||
@ParametersNotNullByDefault
|
@ParametersNotNullByDefault
|
||||||
public class GroupActivity extends
|
public class GroupActivity extends
|
||||||
ThreadListActivity<GroupMessageItem, GroupMessageAdapter> {
|
ThreadListActivity<PrivateGroup, GroupMessageItem, GroupMessageAdapter>
|
||||||
|
implements GroupListener, OnClickListener {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
ViewModelProvider.Factory viewModelFactory;
|
GroupController controller;
|
||||||
|
|
||||||
private GroupViewModel viewModel;
|
@Nullable
|
||||||
|
private Boolean isCreator = null;
|
||||||
|
private boolean isDissolved = false;
|
||||||
|
private MenuItem revealMenuItem, inviteMenuItem, leaveMenuItem,
|
||||||
|
dissolveMenuItem;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void injectActivity(ActivityComponent component) {
|
public void injectActivity(ActivityComponent component) {
|
||||||
component.inject(this);
|
component.inject(this);
|
||||||
viewModel = new ViewModelProvider(this, viewModelFactory)
|
|
||||||
.get(GroupViewModel.class);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ThreadListViewModel<GroupMessageItem> getViewModel() {
|
protected ThreadListController<PrivateGroup, GroupMessageItem> getController() {
|
||||||
return viewModel;
|
return controller;
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected GroupMessageAdapter createAdapter() {
|
|
||||||
return new GroupMessageAdapter(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -62,28 +69,65 @@ public class GroupActivity extends
|
|||||||
super.onCreate(state);
|
super.onCreate(state);
|
||||||
|
|
||||||
Toolbar toolbar = setUpCustomToolbar(false);
|
Toolbar toolbar = setUpCustomToolbar(false);
|
||||||
// Open member list on Toolbar click
|
|
||||||
toolbar.setOnClickListener(v -> {
|
|
||||||
Intent i = new Intent(GroupActivity.this,
|
|
||||||
GroupMemberListActivity.class);
|
|
||||||
i.putExtra(GROUP_ID, groupId.getBytes());
|
|
||||||
startActivity(i);
|
|
||||||
});
|
|
||||||
|
|
||||||
String groupName = getIntent().getStringExtra(GROUP_NAME);
|
Intent i = getIntent();
|
||||||
|
String groupName = i.getStringExtra(GROUP_NAME);
|
||||||
if (groupName != null) setTitle(groupName);
|
if (groupName != null) setTitle(groupName);
|
||||||
observeOnce(viewModel.getPrivateGroup(), this, privateGroup ->
|
loadNamedGroup();
|
||||||
setTitle(privateGroup.getName())
|
|
||||||
);
|
// Open member list on Toolbar click
|
||||||
observeOnce(viewModel.isCreator(), this, adapter::setIsCreator);
|
if (toolbar != null) {
|
||||||
|
toolbar.setOnClickListener(v -> {
|
||||||
|
Intent i1 = new Intent(GroupActivity.this,
|
||||||
|
GroupMemberListActivity.class);
|
||||||
|
i1.putExtra(GROUP_ID, groupId.getBytes());
|
||||||
|
startActivity(i1);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// start with group disabled and enable when not dissolved
|
|
||||||
setGroupEnabled(false);
|
setGroupEnabled(false);
|
||||||
viewModel.isDissolved().observe(this, dissolved -> {
|
}
|
||||||
setGroupEnabled(!dissolved);
|
|
||||||
// only show dialog when no prior state
|
@Override
|
||||||
if (dissolved && state == null) onGroupDissolved();
|
protected GroupMessageAdapter createAdapter(
|
||||||
});
|
LinearLayoutManager layoutManager) {
|
||||||
|
return new GroupMessageAdapter(this, layoutManager);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void loadItems() {
|
||||||
|
controller.isDissolved(
|
||||||
|
new UiResultExceptionHandler<Boolean, DbException>(this) {
|
||||||
|
@Override
|
||||||
|
public void onResultUi(Boolean isDissolved) {
|
||||||
|
setGroupEnabled(!isDissolved);
|
||||||
|
GroupActivity.super.loadItems();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onExceptionUi(DbException exception) {
|
||||||
|
handleException(exception);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onNamedGroupLoaded(PrivateGroup group) {
|
||||||
|
setTitle(group.getName());
|
||||||
|
controller.loadLocalAuthor(
|
||||||
|
new UiResultExceptionHandler<LocalAuthor, DbException>(this) {
|
||||||
|
@Override
|
||||||
|
public void onResultUi(LocalAuthor author) {
|
||||||
|
isCreator = group.getCreator().equals(author);
|
||||||
|
adapter.setPerspective(isCreator);
|
||||||
|
showMenuItems();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onExceptionUi(DbException exception) {
|
||||||
|
handleException(exception);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -92,61 +136,74 @@ public class GroupActivity extends
|
|||||||
MenuInflater inflater = getMenuInflater();
|
MenuInflater inflater = getMenuInflater();
|
||||||
inflater.inflate(R.menu.group_actions, menu);
|
inflater.inflate(R.menu.group_actions, menu);
|
||||||
|
|
||||||
// show items based on role (which will not change, so observe once)
|
revealMenuItem = menu.findItem(R.id.action_group_reveal);
|
||||||
observeOnce(viewModel.isCreator(), this, isCreator -> {
|
inviteMenuItem = menu.findItem(R.id.action_group_invite);
|
||||||
menu.findItem(R.id.action_group_reveal).setVisible(!isCreator);
|
leaveMenuItem = menu.findItem(R.id.action_group_leave);
|
||||||
menu.findItem(R.id.action_group_invite).setVisible(isCreator);
|
dissolveMenuItem = menu.findItem(R.id.action_group_dissolve);
|
||||||
menu.findItem(R.id.action_group_leave).setVisible(!isCreator);
|
|
||||||
menu.findItem(R.id.action_group_dissolve).setVisible(isCreator);
|
// all role-dependent items are invisible until we know our role
|
||||||
});
|
revealMenuItem.setVisible(false);
|
||||||
super.onCreateOptionsMenu(menu);
|
inviteMenuItem.setVisible(false);
|
||||||
return true;
|
leaveMenuItem.setVisible(false);
|
||||||
|
dissolveMenuItem.setVisible(false);
|
||||||
|
|
||||||
|
// show items based on role
|
||||||
|
showMenuItems();
|
||||||
|
|
||||||
|
return super.onCreateOptionsMenu(menu);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
int itemId = item.getItemId();
|
switch (item.getItemId()) {
|
||||||
if (itemId == R.id.action_group_member_list) {
|
case R.id.action_group_member_list:
|
||||||
Intent i = new Intent(this, GroupMemberListActivity.class);
|
Intent i1 = new Intent(this, GroupMemberListActivity.class);
|
||||||
i.putExtra(GROUP_ID, groupId.getBytes());
|
i1.putExtra(GROUP_ID, groupId.getBytes());
|
||||||
startActivity(i);
|
startActivity(i1);
|
||||||
return true;
|
return true;
|
||||||
} else if (itemId == R.id.action_group_reveal) {
|
case R.id.action_group_reveal:
|
||||||
if (requireNonNull(viewModel.isCreator().getValue()))
|
if (isCreator == null || isCreator)
|
||||||
throw new IllegalStateException();
|
throw new IllegalStateException();
|
||||||
Intent i = new Intent(this, RevealContactsActivity.class);
|
Intent i2 = new Intent(this, RevealContactsActivity.class);
|
||||||
i.putExtra(GROUP_ID, groupId.getBytes());
|
i2.putExtra(GROUP_ID, groupId.getBytes());
|
||||||
startActivity(i);
|
startActivity(i2);
|
||||||
return true;
|
return true;
|
||||||
} else if (itemId == R.id.action_group_invite) {
|
case R.id.action_group_invite:
|
||||||
if (!requireNonNull(viewModel.isCreator().getValue()))
|
if (isCreator == null || !isCreator)
|
||||||
throw new IllegalStateException();
|
throw new IllegalStateException();
|
||||||
Intent i = new Intent(this, GroupInviteActivity.class);
|
Intent i3 = new Intent(this, GroupInviteActivity.class);
|
||||||
i.putExtra(GROUP_ID, groupId.getBytes());
|
i3.putExtra(GROUP_ID, groupId.getBytes());
|
||||||
startActivityForResult(i, REQUEST_GROUP_INVITE);
|
startActivityForResult(i3, REQUEST_GROUP_INVITE);
|
||||||
return true;
|
return true;
|
||||||
} else if (itemId == R.id.action_group_leave) {
|
case R.id.action_group_leave:
|
||||||
if (requireNonNull(viewModel.isCreator().getValue()))
|
if (isCreator == null || isCreator)
|
||||||
throw new IllegalStateException();
|
throw new IllegalStateException();
|
||||||
showLeaveGroupDialog();
|
showLeaveGroupDialog();
|
||||||
return true;
|
return true;
|
||||||
} else if (itemId == R.id.action_group_dissolve) {
|
case R.id.action_group_dissolve:
|
||||||
if (!requireNonNull(viewModel.isCreator().getValue()))
|
if (isCreator == null || !isCreator)
|
||||||
throw new IllegalStateException();
|
throw new IllegalStateException();
|
||||||
showDissolveGroupDialog();
|
showDissolveGroupDialog();
|
||||||
return true;
|
default:
|
||||||
|
return super.onOptionsItemSelected(item);
|
||||||
}
|
}
|
||||||
return super.onOptionsItemSelected(item);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onActivityResult(int request, int result,
|
protected void onActivityResult(int request, int result, Intent data) {
|
||||||
@Nullable Intent data) {
|
|
||||||
if (request == REQUEST_GROUP_INVITE && result == RESULT_OK) {
|
if (request == REQUEST_GROUP_INVITE && result == RESULT_OK) {
|
||||||
displaySnackbar(R.string.groups_invitation_sent);
|
displaySnackbar(R.string.groups_invitation_sent);
|
||||||
} else super.onActivityResult(request, result, data);
|
} else super.onActivityResult(request, result, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onItemReceived(GroupMessageItem item) {
|
||||||
|
super.onItemReceived(item);
|
||||||
|
if (item instanceof JoinMessageItem) {
|
||||||
|
if (((JoinMessageItem) item).isInitial()) loadSharingContacts();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected int getMaxTextLength() {
|
protected int getMaxTextLength() {
|
||||||
return MAX_GROUP_POST_TEXT_LENGTH;
|
return MAX_GROUP_POST_TEXT_LENGTH;
|
||||||
@@ -154,11 +211,11 @@ public class GroupActivity extends
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onReplyClick(GroupMessageItem item) {
|
public void onReplyClick(GroupMessageItem item) {
|
||||||
Boolean isDissolved = viewModel.isDissolved().getValue();
|
if (!isDissolved) super.onReplyClick(item);
|
||||||
if (isDissolved != null && !isDissolved) super.onReplyClick(item);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setGroupEnabled(boolean enabled) {
|
private void setGroupEnabled(boolean enabled) {
|
||||||
|
isDissolved = !enabled;
|
||||||
sendController.setReady(enabled);
|
sendController.setReady(enabled);
|
||||||
list.getRecyclerView().setAlpha(enabled ? 1f : 0.5f);
|
list.getRecyclerView().setAlpha(enabled ? 1f : 0.5f);
|
||||||
|
|
||||||
@@ -170,13 +227,21 @@ public class GroupActivity extends
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void showMenuItems() {
|
||||||
|
// we need to have the menu items and know if we are the creator
|
||||||
|
if (leaveMenuItem == null || isCreator == null) return;
|
||||||
|
revealMenuItem.setVisible(!isCreator);
|
||||||
|
inviteMenuItem.setVisible(isCreator);
|
||||||
|
leaveMenuItem.setVisible(!isCreator);
|
||||||
|
dissolveMenuItem.setVisible(isCreator);
|
||||||
|
}
|
||||||
|
|
||||||
private void showLeaveGroupDialog() {
|
private void showLeaveGroupDialog() {
|
||||||
AlertDialog.Builder builder =
|
AlertDialog.Builder builder =
|
||||||
new AlertDialog.Builder(this, R.style.BriarDialogTheme);
|
new AlertDialog.Builder(this, R.style.BriarDialogTheme);
|
||||||
builder.setTitle(getString(R.string.groups_leave_dialog_title));
|
builder.setTitle(getString(R.string.groups_leave_dialog_title));
|
||||||
builder.setMessage(getString(R.string.groups_leave_dialog_message));
|
builder.setMessage(getString(R.string.groups_leave_dialog_message));
|
||||||
builder.setNegativeButton(R.string.dialog_button_leave,
|
builder.setNegativeButton(R.string.dialog_button_leave, this);
|
||||||
(d, w) -> deleteGroup());
|
|
||||||
builder.setPositiveButton(R.string.cancel, null);
|
builder.setPositiveButton(R.string.cancel, null);
|
||||||
builder.show();
|
builder.show();
|
||||||
}
|
}
|
||||||
@@ -186,19 +251,37 @@ public class GroupActivity extends
|
|||||||
new AlertDialog.Builder(this, R.style.BriarDialogTheme);
|
new AlertDialog.Builder(this, R.style.BriarDialogTheme);
|
||||||
builder.setTitle(getString(R.string.groups_dissolve_dialog_title));
|
builder.setTitle(getString(R.string.groups_dissolve_dialog_title));
|
||||||
builder.setMessage(getString(R.string.groups_dissolve_dialog_message));
|
builder.setMessage(getString(R.string.groups_dissolve_dialog_message));
|
||||||
builder.setNegativeButton(R.string.groups_dissolve_button,
|
builder.setNegativeButton(R.string.groups_dissolve_button, this);
|
||||||
(d, w) -> deleteGroup());
|
|
||||||
builder.setPositiveButton(R.string.cancel, null);
|
builder.setPositiveButton(R.string.cancel, null);
|
||||||
builder.show();
|
builder.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void deleteGroup() {
|
@Override
|
||||||
// The activity is going to be destroyed by the
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
// GroupRemovedEvent being fired
|
controller.deleteNamedGroup(
|
||||||
viewModel.deletePrivateGroup();
|
new UiExceptionHandler<DbException>(this) {
|
||||||
|
// The activity is going to be destroyed by the
|
||||||
|
// GroupRemovedEvent being fired
|
||||||
|
@Override
|
||||||
|
public void onExceptionUi(DbException exception) {
|
||||||
|
handleException(exception);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onGroupDissolved() {
|
@Override
|
||||||
|
public void onContactRelationshipRevealed(AuthorId memberId, ContactId c,
|
||||||
|
Visibility v) {
|
||||||
|
adapter.updateVisibility(memberId, v);
|
||||||
|
|
||||||
|
sharingController.add(c);
|
||||||
|
setToolbarSubTitle(sharingController.getTotalCount(),
|
||||||
|
sharingController.getOnlineCount());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onGroupDissolved() {
|
||||||
|
setGroupEnabled(false);
|
||||||
AlertDialog.Builder builder =
|
AlertDialog.Builder builder =
|
||||||
new AlertDialog.Builder(this, R.style.BriarDialogTheme);
|
new AlertDialog.Builder(this, R.style.BriarDialogTheme);
|
||||||
builder.setTitle(getString(R.string.groups_dissolved_dialog_title));
|
builder.setTitle(getString(R.string.groups_dissolved_dialog_title));
|
||||||
|
|||||||
@@ -0,0 +1,33 @@
|
|||||||
|
package org.briarproject.briar.android.privategroup.conversation;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.contact.ContactId;
|
||||||
|
import org.briarproject.bramble.api.db.DbException;
|
||||||
|
import org.briarproject.bramble.api.identity.AuthorId;
|
||||||
|
import org.briarproject.bramble.api.identity.LocalAuthor;
|
||||||
|
import org.briarproject.briar.android.controller.handler.ResultExceptionHandler;
|
||||||
|
import org.briarproject.briar.android.threaded.ThreadListController;
|
||||||
|
import org.briarproject.briar.api.privategroup.PrivateGroup;
|
||||||
|
import org.briarproject.briar.api.privategroup.Visibility;
|
||||||
|
|
||||||
|
import androidx.annotation.UiThread;
|
||||||
|
|
||||||
|
public interface GroupController
|
||||||
|
extends ThreadListController<PrivateGroup, GroupMessageItem> {
|
||||||
|
|
||||||
|
void loadLocalAuthor(
|
||||||
|
ResultExceptionHandler<LocalAuthor, DbException> handler);
|
||||||
|
|
||||||
|
void isDissolved(
|
||||||
|
ResultExceptionHandler<Boolean, DbException> handler);
|
||||||
|
|
||||||
|
interface GroupListener extends ThreadListListener<GroupMessageItem> {
|
||||||
|
|
||||||
|
@UiThread
|
||||||
|
void onContactRelationshipRevealed(AuthorId memberId,
|
||||||
|
ContactId contactId, Visibility v);
|
||||||
|
|
||||||
|
@UiThread
|
||||||
|
void onGroupDissolved();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,242 @@
|
|||||||
|
package org.briarproject.briar.android.privategroup.conversation;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.contact.ContactId;
|
||||||
|
import org.briarproject.bramble.api.crypto.CryptoExecutor;
|
||||||
|
import org.briarproject.bramble.api.db.DatabaseExecutor;
|
||||||
|
import org.briarproject.bramble.api.db.DbException;
|
||||||
|
import org.briarproject.bramble.api.event.Event;
|
||||||
|
import org.briarproject.bramble.api.event.EventBus;
|
||||||
|
import org.briarproject.bramble.api.identity.IdentityManager;
|
||||||
|
import org.briarproject.bramble.api.identity.LocalAuthor;
|
||||||
|
import org.briarproject.bramble.api.lifecycle.LifecycleManager;
|
||||||
|
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
|
||||||
|
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
||||||
|
import org.briarproject.bramble.api.sync.MessageId;
|
||||||
|
import org.briarproject.bramble.api.system.Clock;
|
||||||
|
import org.briarproject.briar.android.controller.handler.ResultExceptionHandler;
|
||||||
|
import org.briarproject.briar.android.privategroup.conversation.GroupController.GroupListener;
|
||||||
|
import org.briarproject.briar.android.threaded.ThreadListControllerImpl;
|
||||||
|
import org.briarproject.briar.api.android.AndroidNotificationManager;
|
||||||
|
import org.briarproject.briar.api.client.MessageTracker;
|
||||||
|
import org.briarproject.briar.api.client.MessageTracker.GroupCount;
|
||||||
|
import org.briarproject.briar.api.privategroup.GroupMember;
|
||||||
|
import org.briarproject.briar.api.privategroup.GroupMessage;
|
||||||
|
import org.briarproject.briar.api.privategroup.GroupMessageFactory;
|
||||||
|
import org.briarproject.briar.api.privategroup.GroupMessageHeader;
|
||||||
|
import org.briarproject.briar.api.privategroup.JoinMessageHeader;
|
||||||
|
import org.briarproject.briar.api.privategroup.PrivateGroup;
|
||||||
|
import org.briarproject.briar.api.privategroup.PrivateGroupManager;
|
||||||
|
import org.briarproject.briar.api.privategroup.event.ContactRelationshipRevealedEvent;
|
||||||
|
import org.briarproject.briar.api.privategroup.event.GroupDissolvedEvent;
|
||||||
|
import org.briarproject.briar.api.privategroup.event.GroupInvitationResponseReceivedEvent;
|
||||||
|
import org.briarproject.briar.api.privategroup.event.GroupMessageAddedEvent;
|
||||||
|
import org.briarproject.briar.api.privategroup.invitation.GroupInvitationResponse;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.concurrent.Executor;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
import static java.lang.Math.max;
|
||||||
|
import static java.util.logging.Level.WARNING;
|
||||||
|
import static org.briarproject.bramble.util.LogUtils.logException;
|
||||||
|
|
||||||
|
@MethodsNotNullByDefault
|
||||||
|
@ParametersNotNullByDefault
|
||||||
|
class GroupControllerImpl extends
|
||||||
|
ThreadListControllerImpl<PrivateGroup, GroupMessageItem, GroupMessageHeader, GroupMessage, GroupListener>
|
||||||
|
implements GroupController {
|
||||||
|
|
||||||
|
private static final Logger LOG =
|
||||||
|
Logger.getLogger(GroupControllerImpl.class.getName());
|
||||||
|
|
||||||
|
private final PrivateGroupManager privateGroupManager;
|
||||||
|
private final GroupMessageFactory groupMessageFactory;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
GroupControllerImpl(@DatabaseExecutor Executor dbExecutor,
|
||||||
|
LifecycleManager lifecycleManager, IdentityManager identityManager,
|
||||||
|
@CryptoExecutor Executor cryptoExecutor,
|
||||||
|
PrivateGroupManager privateGroupManager,
|
||||||
|
GroupMessageFactory groupMessageFactory, EventBus eventBus,
|
||||||
|
MessageTracker messageTracker, Clock clock,
|
||||||
|
AndroidNotificationManager notificationManager) {
|
||||||
|
super(dbExecutor, lifecycleManager, identityManager, cryptoExecutor,
|
||||||
|
eventBus, clock, notificationManager, messageTracker);
|
||||||
|
this.privateGroupManager = privateGroupManager;
|
||||||
|
this.groupMessageFactory = groupMessageFactory;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onActivityStart() {
|
||||||
|
super.onActivityStart();
|
||||||
|
notificationManager.clearGroupMessageNotification(getGroupId());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void eventOccurred(Event e) {
|
||||||
|
super.eventOccurred(e);
|
||||||
|
|
||||||
|
if (e instanceof GroupMessageAddedEvent) {
|
||||||
|
GroupMessageAddedEvent g = (GroupMessageAddedEvent) e;
|
||||||
|
if (!g.isLocal() && g.getGroupId().equals(getGroupId())) {
|
||||||
|
LOG.info("Group message received, adding...");
|
||||||
|
listener.onItemReceived(buildItem(g.getHeader(), g.getText()));
|
||||||
|
}
|
||||||
|
} else if (e instanceof ContactRelationshipRevealedEvent) {
|
||||||
|
ContactRelationshipRevealedEvent c =
|
||||||
|
(ContactRelationshipRevealedEvent) e;
|
||||||
|
if (getGroupId().equals(c.getGroupId())) {
|
||||||
|
listener.onContactRelationshipRevealed(c.getMemberId(),
|
||||||
|
c.getContactId(), c.getVisibility());
|
||||||
|
}
|
||||||
|
} else if (e instanceof GroupInvitationResponseReceivedEvent) {
|
||||||
|
GroupInvitationResponseReceivedEvent g =
|
||||||
|
(GroupInvitationResponseReceivedEvent) e;
|
||||||
|
GroupInvitationResponse r = g.getMessageHeader();
|
||||||
|
if (getGroupId().equals(r.getShareableId()) && r.wasAccepted()) {
|
||||||
|
listener.onInvitationAccepted(g.getContactId());
|
||||||
|
}
|
||||||
|
} else if (e instanceof GroupDissolvedEvent) {
|
||||||
|
GroupDissolvedEvent g = (GroupDissolvedEvent) e;
|
||||||
|
if (getGroupId().equals(g.getGroupId())) {
|
||||||
|
listener.onGroupDissolved();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected PrivateGroup loadNamedGroup() throws DbException {
|
||||||
|
return privateGroupManager.getPrivateGroup(getGroupId());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Collection<GroupMessageHeader> loadHeaders() throws DbException {
|
||||||
|
return privateGroupManager.getHeaders(getGroupId());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String loadMessageText(GroupMessageHeader header)
|
||||||
|
throws DbException {
|
||||||
|
if (header instanceof JoinMessageHeader) {
|
||||||
|
// will be looked up later
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
return privateGroupManager.getMessageText(header.getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void markRead(MessageId id) throws DbException {
|
||||||
|
privateGroupManager.setReadFlag(getGroupId(), id, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void loadSharingContacts(
|
||||||
|
ResultExceptionHandler<Collection<ContactId>, DbException> handler) {
|
||||||
|
runOnDbThread(() -> {
|
||||||
|
try {
|
||||||
|
Collection<GroupMember> members =
|
||||||
|
privateGroupManager.getMembers(getGroupId());
|
||||||
|
Collection<ContactId> contactIds = new ArrayList<>();
|
||||||
|
for (GroupMember m : members) {
|
||||||
|
if (m.getContactId() != null)
|
||||||
|
contactIds.add(m.getContactId());
|
||||||
|
}
|
||||||
|
handler.onResult(contactIds);
|
||||||
|
} catch (DbException e) {
|
||||||
|
logException(LOG, WARNING, e);
|
||||||
|
handler.onException(e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void createAndStoreMessage(String text,
|
||||||
|
@Nullable GroupMessageItem parentItem,
|
||||||
|
ResultExceptionHandler<GroupMessageItem, DbException> handler) {
|
||||||
|
runOnDbThread(() -> {
|
||||||
|
try {
|
||||||
|
LocalAuthor author = identityManager.getLocalAuthor();
|
||||||
|
MessageId parentId = null;
|
||||||
|
MessageId previousMsgId =
|
||||||
|
privateGroupManager.getPreviousMsgId(getGroupId());
|
||||||
|
GroupCount count =
|
||||||
|
privateGroupManager.getGroupCount(getGroupId());
|
||||||
|
long timestamp = count.getLatestMsgTime();
|
||||||
|
if (parentItem != null) parentId = parentItem.getId();
|
||||||
|
timestamp = max(clock.currentTimeMillis(), timestamp + 1);
|
||||||
|
createMessage(text, timestamp, parentId, author, previousMsgId,
|
||||||
|
handler);
|
||||||
|
} catch (DbException e) {
|
||||||
|
logException(LOG, WARNING, e);
|
||||||
|
handler.onException(e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void createMessage(String text, long timestamp,
|
||||||
|
@Nullable MessageId parentId, LocalAuthor author,
|
||||||
|
MessageId previousMsgId,
|
||||||
|
ResultExceptionHandler<GroupMessageItem, DbException> handler) {
|
||||||
|
cryptoExecutor.execute(() -> {
|
||||||
|
LOG.info("Creating group message...");
|
||||||
|
GroupMessage msg = groupMessageFactory
|
||||||
|
.createGroupMessage(getGroupId(), timestamp,
|
||||||
|
parentId, author, text, previousMsgId);
|
||||||
|
storePost(msg, text, handler);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected GroupMessageHeader addLocalMessage(GroupMessage message)
|
||||||
|
throws DbException {
|
||||||
|
return privateGroupManager.addLocalMessage(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void deleteNamedGroup(PrivateGroup group) throws DbException {
|
||||||
|
privateGroupManager.removePrivateGroup(group.getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected GroupMessageItem buildItem(GroupMessageHeader header,
|
||||||
|
String text) {
|
||||||
|
if (header instanceof JoinMessageHeader) {
|
||||||
|
return new JoinMessageItem((JoinMessageHeader) header, text);
|
||||||
|
}
|
||||||
|
return new GroupMessageItem(header, text);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void loadLocalAuthor(
|
||||||
|
ResultExceptionHandler<LocalAuthor, DbException> handler) {
|
||||||
|
runOnDbThread(() -> {
|
||||||
|
try {
|
||||||
|
LocalAuthor author = identityManager.getLocalAuthor();
|
||||||
|
handler.onResult(author);
|
||||||
|
} catch (DbException e) {
|
||||||
|
logException(LOG, WARNING, e);
|
||||||
|
handler.onException(e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void isDissolved(
|
||||||
|
ResultExceptionHandler<Boolean, DbException> handler) {
|
||||||
|
runOnDbThread(() -> {
|
||||||
|
try {
|
||||||
|
boolean isDissolved =
|
||||||
|
privateGroupManager.isDissolved(getGroupId());
|
||||||
|
handler.onResult(isDissolved);
|
||||||
|
} catch (DbException e) {
|
||||||
|
logException(LOG, WARNING, e);
|
||||||
|
handler.onException(e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,18 +1,19 @@
|
|||||||
package org.briarproject.briar.android.privategroup.conversation;
|
package org.briarproject.briar.android.privategroup.conversation;
|
||||||
|
|
||||||
import org.briarproject.briar.android.viewmodel.ViewModelKey;
|
import org.briarproject.briar.android.activity.ActivityScope;
|
||||||
|
import org.briarproject.briar.android.activity.BaseActivity;
|
||||||
|
|
||||||
import androidx.lifecycle.ViewModel;
|
|
||||||
import dagger.Binds;
|
|
||||||
import dagger.Module;
|
import dagger.Module;
|
||||||
import dagger.multibindings.IntoMap;
|
import dagger.Provides;
|
||||||
|
|
||||||
@Module
|
@Module
|
||||||
public interface GroupConversationModule {
|
public class GroupConversationModule {
|
||||||
|
|
||||||
@Binds
|
|
||||||
@IntoMap
|
|
||||||
@ViewModelKey(GroupViewModel.class)
|
|
||||||
ViewModel bindGroupViewModel(GroupViewModel groupViewModel);
|
|
||||||
|
|
||||||
|
@ActivityScope
|
||||||
|
@Provides
|
||||||
|
GroupController provideGroupController(BaseActivity activity,
|
||||||
|
GroupControllerImpl groupController) {
|
||||||
|
activity.addLifecycleController(groupController);
|
||||||
|
return groupController;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,14 +4,19 @@ import android.view.LayoutInflater;
|
|||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.identity.AuthorId;
|
||||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
import org.briarproject.briar.R;
|
import org.briarproject.briar.R;
|
||||||
import org.briarproject.briar.android.threaded.BaseThreadItemViewHolder;
|
import org.briarproject.briar.android.threaded.BaseThreadItemViewHolder;
|
||||||
import org.briarproject.briar.android.threaded.ThreadItemAdapter;
|
import org.briarproject.briar.android.threaded.ThreadItemAdapter;
|
||||||
import org.briarproject.briar.android.threaded.ThreadPostViewHolder;
|
import org.briarproject.briar.android.threaded.ThreadPostViewHolder;
|
||||||
|
import org.briarproject.briar.api.privategroup.Visibility;
|
||||||
|
|
||||||
import androidx.annotation.LayoutRes;
|
import androidx.annotation.LayoutRes;
|
||||||
import androidx.annotation.UiThread;
|
import androidx.annotation.UiThread;
|
||||||
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||||
|
|
||||||
|
import static androidx.recyclerview.widget.RecyclerView.NO_POSITION;
|
||||||
|
|
||||||
@UiThread
|
@UiThread
|
||||||
@NotNullByDefault
|
@NotNullByDefault
|
||||||
@@ -19,14 +24,15 @@ class GroupMessageAdapter extends ThreadItemAdapter<GroupMessageItem> {
|
|||||||
|
|
||||||
private boolean isCreator = false;
|
private boolean isCreator = false;
|
||||||
|
|
||||||
GroupMessageAdapter(ThreadItemListener<GroupMessageItem> listener) {
|
GroupMessageAdapter(ThreadItemListener<GroupMessageItem> listener,
|
||||||
super(listener);
|
LinearLayoutManager layoutManager) {
|
||||||
|
super(listener, layoutManager);
|
||||||
}
|
}
|
||||||
|
|
||||||
@LayoutRes
|
@LayoutRes
|
||||||
@Override
|
@Override
|
||||||
public int getItemViewType(int position) {
|
public int getItemViewType(int position) {
|
||||||
GroupMessageItem item = getItem(position);
|
GroupMessageItem item = items.get(position);
|
||||||
return item.getLayout();
|
return item.getLayout();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -41,9 +47,30 @@ class GroupMessageAdapter extends ThreadItemAdapter<GroupMessageItem> {
|
|||||||
return new ThreadPostViewHolder<>(v);
|
return new ThreadPostViewHolder<>(v);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setIsCreator(boolean isCreator) {
|
void setPerspective(boolean isCreator) {
|
||||||
this.isCreator = isCreator;
|
this.isCreator = isCreator;
|
||||||
notifyDataSetChanged();
|
notifyDataSetChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void updateVisibility(AuthorId memberId, Visibility v) {
|
||||||
|
int position = findItemPosition(memberId);
|
||||||
|
if (position != NO_POSITION) {
|
||||||
|
GroupMessageItem item = items.get(position);
|
||||||
|
if (item instanceof JoinMessageItem) {
|
||||||
|
((JoinMessageItem) item).setVisibility(v);
|
||||||
|
notifyItemChanged(findItemPosition(item), item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private int findItemPosition(AuthorId a) {
|
||||||
|
int count = items.size();
|
||||||
|
for (int i = 0; i < count; i++) {
|
||||||
|
GroupMessageItem item = items.get(i);
|
||||||
|
if (item.getAuthor().getId().equals(a))
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
return NO_POSITION; // Not found
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,287 +0,0 @@
|
|||||||
package org.briarproject.briar.android.privategroup.conversation;
|
|
||||||
|
|
||||||
import android.app.Application;
|
|
||||||
|
|
||||||
import org.briarproject.bramble.api.contact.ContactId;
|
|
||||||
import org.briarproject.bramble.api.crypto.CryptoExecutor;
|
|
||||||
import org.briarproject.bramble.api.db.DatabaseExecutor;
|
|
||||||
import org.briarproject.bramble.api.db.DbException;
|
|
||||||
import org.briarproject.bramble.api.db.Transaction;
|
|
||||||
import org.briarproject.bramble.api.db.TransactionManager;
|
|
||||||
import org.briarproject.bramble.api.event.Event;
|
|
||||||
import org.briarproject.bramble.api.event.EventBus;
|
|
||||||
import org.briarproject.bramble.api.identity.Author;
|
|
||||||
import org.briarproject.bramble.api.identity.IdentityManager;
|
|
||||||
import org.briarproject.bramble.api.identity.LocalAuthor;
|
|
||||||
import org.briarproject.bramble.api.lifecycle.LifecycleManager;
|
|
||||||
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
|
|
||||||
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
|
||||||
import org.briarproject.bramble.api.sync.GroupId;
|
|
||||||
import org.briarproject.bramble.api.sync.MessageId;
|
|
||||||
import org.briarproject.bramble.api.system.AndroidExecutor;
|
|
||||||
import org.briarproject.bramble.api.system.Clock;
|
|
||||||
import org.briarproject.briar.android.sharing.SharingController;
|
|
||||||
import org.briarproject.briar.android.threaded.ThreadListViewModel;
|
|
||||||
import org.briarproject.briar.api.android.AndroidNotificationManager;
|
|
||||||
import org.briarproject.briar.api.client.MessageTracker;
|
|
||||||
import org.briarproject.briar.api.client.MessageTracker.GroupCount;
|
|
||||||
import org.briarproject.briar.api.privategroup.GroupMember;
|
|
||||||
import org.briarproject.briar.api.privategroup.GroupMessage;
|
|
||||||
import org.briarproject.briar.api.privategroup.GroupMessageFactory;
|
|
||||||
import org.briarproject.briar.api.privategroup.GroupMessageHeader;
|
|
||||||
import org.briarproject.briar.api.privategroup.JoinMessageHeader;
|
|
||||||
import org.briarproject.briar.api.privategroup.PrivateGroup;
|
|
||||||
import org.briarproject.briar.api.privategroup.PrivateGroupManager;
|
|
||||||
import org.briarproject.briar.api.privategroup.event.ContactRelationshipRevealedEvent;
|
|
||||||
import org.briarproject.briar.api.privategroup.event.GroupDissolvedEvent;
|
|
||||||
import org.briarproject.briar.api.privategroup.event.GroupInvitationResponseReceivedEvent;
|
|
||||||
import org.briarproject.briar.api.privategroup.event.GroupMessageAddedEvent;
|
|
||||||
import org.briarproject.briar.api.privategroup.invitation.GroupInvitationResponse;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.concurrent.Executor;
|
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
import javax.inject.Inject;
|
|
||||||
|
|
||||||
import androidx.lifecycle.LiveData;
|
|
||||||
import androidx.lifecycle.MutableLiveData;
|
|
||||||
|
|
||||||
import static java.lang.Math.max;
|
|
||||||
import static java.util.logging.Level.WARNING;
|
|
||||||
import static java.util.logging.Logger.getLogger;
|
|
||||||
import static org.briarproject.bramble.util.LogUtils.logDuration;
|
|
||||||
import static org.briarproject.bramble.util.LogUtils.logException;
|
|
||||||
import static org.briarproject.bramble.util.LogUtils.now;
|
|
||||||
|
|
||||||
@MethodsNotNullByDefault
|
|
||||||
@ParametersNotNullByDefault
|
|
||||||
class GroupViewModel extends ThreadListViewModel<GroupMessageItem> {
|
|
||||||
|
|
||||||
private static final Logger LOG = getLogger(GroupViewModel.class.getName());
|
|
||||||
|
|
||||||
private final PrivateGroupManager privateGroupManager;
|
|
||||||
private final GroupMessageFactory groupMessageFactory;
|
|
||||||
|
|
||||||
private final MutableLiveData<PrivateGroup> privateGroup =
|
|
||||||
new MutableLiveData<>();
|
|
||||||
private final MutableLiveData<Boolean> isCreator = new MutableLiveData<>();
|
|
||||||
private final MutableLiveData<Boolean> isDissolved =
|
|
||||||
new MutableLiveData<>();
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
GroupViewModel(Application application,
|
|
||||||
@DatabaseExecutor Executor dbExecutor,
|
|
||||||
LifecycleManager lifecycleManager,
|
|
||||||
TransactionManager db,
|
|
||||||
AndroidExecutor androidExecutor,
|
|
||||||
EventBus eventBus,
|
|
||||||
IdentityManager identityManager,
|
|
||||||
AndroidNotificationManager notificationManager,
|
|
||||||
SharingController sharingController,
|
|
||||||
@CryptoExecutor Executor cryptoExecutor,
|
|
||||||
Clock clock,
|
|
||||||
MessageTracker messageTracker,
|
|
||||||
PrivateGroupManager privateGroupManager,
|
|
||||||
GroupMessageFactory groupMessageFactory) {
|
|
||||||
super(application, dbExecutor, lifecycleManager, db, androidExecutor,
|
|
||||||
identityManager, notificationManager, sharingController,
|
|
||||||
cryptoExecutor, clock, messageTracker, eventBus);
|
|
||||||
this.privateGroupManager = privateGroupManager;
|
|
||||||
this.groupMessageFactory = groupMessageFactory;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void eventOccurred(Event e) {
|
|
||||||
if (e instanceof GroupMessageAddedEvent) {
|
|
||||||
GroupMessageAddedEvent g = (GroupMessageAddedEvent) e;
|
|
||||||
// only act on non-local messages in this group
|
|
||||||
if (!g.isLocal() && g.getGroupId().equals(groupId)) {
|
|
||||||
LOG.info("Group message received, adding...");
|
|
||||||
GroupMessageItem item = buildItem(g.getHeader(), g.getText());
|
|
||||||
addItem(item, false);
|
|
||||||
// In case the join message comes from the creator,
|
|
||||||
// we need to reload the sharing contacts
|
|
||||||
// in case it was delayed and the sharing count is wrong (#850).
|
|
||||||
if (item instanceof JoinMessageItem &&
|
|
||||||
(((JoinMessageItem) item).isInitial())) {
|
|
||||||
loadSharingContacts();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (e instanceof GroupInvitationResponseReceivedEvent) {
|
|
||||||
GroupInvitationResponseReceivedEvent g =
|
|
||||||
(GroupInvitationResponseReceivedEvent) e;
|
|
||||||
GroupInvitationResponse r = g.getMessageHeader();
|
|
||||||
if (r.getShareableId().equals(groupId) && r.wasAccepted()) {
|
|
||||||
sharingController.add(g.getContactId());
|
|
||||||
}
|
|
||||||
} else if (e instanceof ContactRelationshipRevealedEvent) {
|
|
||||||
ContactRelationshipRevealedEvent c =
|
|
||||||
(ContactRelationshipRevealedEvent) e;
|
|
||||||
if (c.getGroupId().equals(groupId)) {
|
|
||||||
sharingController.add(c.getContactId());
|
|
||||||
}
|
|
||||||
} else if (e instanceof GroupDissolvedEvent) {
|
|
||||||
GroupDissolvedEvent g = (GroupDissolvedEvent) e;
|
|
||||||
if (g.getGroupId().equals(groupId)) {
|
|
||||||
isDissolved.setValue(true);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
super.eventOccurred(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void performInitialLoad() {
|
|
||||||
super.performInitialLoad();
|
|
||||||
loadPrivateGroup(groupId);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void clearNotifications() {
|
|
||||||
notificationManager.clearGroupMessageNotification(groupId);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void loadPrivateGroup(GroupId groupId) {
|
|
||||||
runOnDbThread(() -> {
|
|
||||||
try {
|
|
||||||
PrivateGroup g = privateGroupManager.getPrivateGroup(groupId);
|
|
||||||
privateGroup.postValue(g);
|
|
||||||
Author author = identityManager.getLocalAuthor();
|
|
||||||
isCreator.postValue(g.getCreator().equals(author));
|
|
||||||
} catch (DbException e) {
|
|
||||||
logException(LOG, WARNING, e);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void loadItems() {
|
|
||||||
loadList(txn -> {
|
|
||||||
// check first if group is dissolved
|
|
||||||
isDissolved
|
|
||||||
.postValue(privateGroupManager.isDissolved(txn, groupId));
|
|
||||||
// now continue to load the items
|
|
||||||
long start = now();
|
|
||||||
List<GroupMessageHeader> headers =
|
|
||||||
privateGroupManager.getHeaders(txn, groupId);
|
|
||||||
logDuration(LOG, "Loading headers", start);
|
|
||||||
start = now();
|
|
||||||
List<GroupMessageItem> items = new ArrayList<>();
|
|
||||||
for (GroupMessageHeader header : headers) {
|
|
||||||
items.add(loadItem(txn, header));
|
|
||||||
}
|
|
||||||
logDuration(LOG, "Loading bodies and creating items", start);
|
|
||||||
return items;
|
|
||||||
}, this::setItems);
|
|
||||||
}
|
|
||||||
|
|
||||||
private GroupMessageItem loadItem(Transaction txn,
|
|
||||||
GroupMessageHeader header) throws DbException {
|
|
||||||
String text;
|
|
||||||
if (header instanceof JoinMessageHeader) {
|
|
||||||
// will be looked up later
|
|
||||||
text = "";
|
|
||||||
} else {
|
|
||||||
text = privateGroupManager.getMessageText(txn, header.getId());
|
|
||||||
}
|
|
||||||
return buildItem(header, text);
|
|
||||||
}
|
|
||||||
|
|
||||||
private GroupMessageItem buildItem(GroupMessageHeader header, String text) {
|
|
||||||
if (header instanceof JoinMessageHeader) {
|
|
||||||
return new JoinMessageItem((JoinMessageHeader) header, text);
|
|
||||||
}
|
|
||||||
return new GroupMessageItem(header, text);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void createAndStoreMessage(String text,
|
|
||||||
@Nullable MessageId parentId) {
|
|
||||||
runOnDbThread(() -> {
|
|
||||||
try {
|
|
||||||
LocalAuthor author = identityManager.getLocalAuthor();
|
|
||||||
MessageId previousMsgId =
|
|
||||||
privateGroupManager.getPreviousMsgId(groupId);
|
|
||||||
GroupCount count = privateGroupManager.getGroupCount(groupId);
|
|
||||||
long timestamp = count.getLatestMsgTime();
|
|
||||||
timestamp = max(clock.currentTimeMillis(), timestamp + 1);
|
|
||||||
createMessage(text, timestamp, parentId, author, previousMsgId);
|
|
||||||
} catch (DbException e) {
|
|
||||||
logException(LOG, WARNING, e);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private void createMessage(String text, long timestamp,
|
|
||||||
@Nullable MessageId parentId, LocalAuthor author,
|
|
||||||
MessageId previousMsgId) {
|
|
||||||
cryptoExecutor.execute(() -> {
|
|
||||||
LOG.info("Creating group message...");
|
|
||||||
GroupMessage msg = groupMessageFactory.createGroupMessage(groupId,
|
|
||||||
timestamp, parentId, author, text, previousMsgId);
|
|
||||||
storePost(msg, text);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private void storePost(GroupMessage msg, String text) {
|
|
||||||
runOnDbThread(false, txn -> {
|
|
||||||
long start = now();
|
|
||||||
GroupMessageHeader header =
|
|
||||||
privateGroupManager.addLocalMessage(txn, msg);
|
|
||||||
logDuration(LOG, "Storing group message", start);
|
|
||||||
txn.attach(() ->
|
|
||||||
addItem(buildItem(header, text), true)
|
|
||||||
);
|
|
||||||
}, e -> logException(LOG, WARNING, e));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void markItemRead(GroupMessageItem item) {
|
|
||||||
runOnDbThread(() -> {
|
|
||||||
try {
|
|
||||||
privateGroupManager.setReadFlag(groupId, item.getId(), true);
|
|
||||||
} catch (DbException e) {
|
|
||||||
logException(LOG, WARNING, e);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public void loadSharingContacts() {
|
|
||||||
runOnDbThread(true, txn -> {
|
|
||||||
Collection<GroupMember> members =
|
|
||||||
privateGroupManager.getMembers(txn, groupId);
|
|
||||||
Collection<ContactId> contactIds = new ArrayList<>();
|
|
||||||
for (GroupMember m : members) {
|
|
||||||
if (m.getContactId() != null)
|
|
||||||
contactIds.add(m.getContactId());
|
|
||||||
}
|
|
||||||
txn.attach(() -> sharingController.addAll(contactIds));
|
|
||||||
}, e -> logException(LOG, WARNING, e));
|
|
||||||
}
|
|
||||||
|
|
||||||
void deletePrivateGroup() {
|
|
||||||
runOnDbThread(() -> {
|
|
||||||
try {
|
|
||||||
privateGroupManager.removePrivateGroup(groupId);
|
|
||||||
} catch (DbException e) {
|
|
||||||
logException(LOG, WARNING, e);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
LiveData<PrivateGroup> getPrivateGroup() {
|
|
||||||
return privateGroup;
|
|
||||||
}
|
|
||||||
|
|
||||||
LiveData<Boolean> isCreator() {
|
|
||||||
return isCreator;
|
|
||||||
}
|
|
||||||
|
|
||||||
LiveData<Boolean> isDissolved() {
|
|
||||||
return isDissolved;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -2,6 +2,7 @@ package org.briarproject.briar.android.privategroup.conversation;
|
|||||||
|
|
||||||
import org.briarproject.briar.R;
|
import org.briarproject.briar.R;
|
||||||
import org.briarproject.briar.api.privategroup.JoinMessageHeader;
|
import org.briarproject.briar.api.privategroup.JoinMessageHeader;
|
||||||
|
import org.briarproject.briar.api.privategroup.Visibility;
|
||||||
|
|
||||||
import javax.annotation.concurrent.NotThreadSafe;
|
import javax.annotation.concurrent.NotThreadSafe;
|
||||||
|
|
||||||
@@ -12,11 +13,13 @@ import androidx.annotation.UiThread;
|
|||||||
@NotThreadSafe
|
@NotThreadSafe
|
||||||
class JoinMessageItem extends GroupMessageItem {
|
class JoinMessageItem extends GroupMessageItem {
|
||||||
|
|
||||||
|
private Visibility visibility;
|
||||||
private final boolean isInitial;
|
private final boolean isInitial;
|
||||||
|
|
||||||
JoinMessageItem(JoinMessageHeader h, String text) {
|
JoinMessageItem(JoinMessageHeader h, String text) {
|
||||||
super(h, text);
|
super(h, text);
|
||||||
isInitial = h.isInitial();
|
this.visibility = h.getVisibility();
|
||||||
|
this.isInitial = h.isInitial();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -30,6 +33,14 @@ class JoinMessageItem extends GroupMessageItem {
|
|||||||
return R.layout.list_item_group_join_notice;
|
return R.layout.list_item_group_join_notice;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Visibility getVisibility() {
|
||||||
|
return visibility;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setVisibility(Visibility visibility) {
|
||||||
|
this.visibility = visibility;
|
||||||
|
}
|
||||||
|
|
||||||
boolean isInitial() {
|
boolean isInitial() {
|
||||||
return isInitial;
|
return isInitial;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,40 +1,29 @@
|
|||||||
package org.briarproject.briar.android.reporting;
|
package org.briarproject.briar.android.reporting;
|
||||||
|
|
||||||
import android.app.Application;
|
import android.content.Context;
|
||||||
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
|
||||||
class BriarExceptionHandler implements UncaughtExceptionHandler {
|
public class BriarExceptionHandler implements UncaughtExceptionHandler {
|
||||||
|
|
||||||
private final Application app;
|
private final Context ctx;
|
||||||
private final LogEncrypter logEncrypter;
|
|
||||||
private final long appStartTime;
|
private final long appStartTime;
|
||||||
|
|
||||||
@Inject
|
public BriarExceptionHandler(Context ctx) {
|
||||||
BriarExceptionHandler(Application app, LogEncrypter logEncrypter) {
|
this.ctx = ctx;
|
||||||
this.app = app;
|
this.appStartTime = System.currentTimeMillis();
|
||||||
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(app.getApplicationContext(),
|
startDevReportActivity(ctx, CrashReportActivity.class, e, appStartTime);
|
||||||
CrashReportActivity.class, e, appStartTime, logKey);
|
|
||||||
Process.killProcess(Process.myPid());
|
Process.killProcess(Process.myPid());
|
||||||
System.exit(10);
|
System.exit(10);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,6 +25,8 @@ 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;
|
||||||
@@ -39,6 +41,8 @@ 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;
|
||||||
|
|
||||||
@@ -70,8 +74,8 @@ class BriarReportCollector {
|
|||||||
this.ctx = ctx;
|
this.ctx = ctx;
|
||||||
}
|
}
|
||||||
|
|
||||||
ReportData collectReportData(@Nullable Throwable t, long appStartTime,
|
public ReportData collectReportData(@Nullable Throwable t,
|
||||||
String logs) {
|
long appStartTime) {
|
||||||
ReportData reportData = new ReportData()
|
ReportData reportData = new ReportData()
|
||||||
.add(getBasicInfo(t))
|
.add(getBasicInfo(t))
|
||||||
.add(getDeviceInfo());
|
.add(getDeviceInfo());
|
||||||
@@ -82,7 +86,7 @@ class BriarReportCollector {
|
|||||||
.add(getStorage())
|
.add(getStorage())
|
||||||
.add(getConnectivity())
|
.add(getConnectivity())
|
||||||
.add(getBuildConfig())
|
.add(getBuildConfig())
|
||||||
.add(getLogcat(logs))
|
.add(getLogcat())
|
||||||
.add(getDeviceFeatures());
|
.add(getDeviceFeatures());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -309,8 +313,15 @@ class BriarReportCollector {
|
|||||||
buildConfig);
|
buildConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
private ReportItem getLogcat(String logs) {
|
private ReportItem getLogcat() {
|
||||||
return new ReportItem("Logcat", R.string.dev_report_logcat, logs);
|
BriarApplication app = (BriarApplication) ctx.getApplicationContext();
|
||||||
|
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,7 +35,6 @@ 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;
|
||||||
@@ -57,8 +56,7 @@ 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);
|
||||||
byte[] logKey = intent.getByteArrayExtra(EXTRA_APP_LOGCAT);
|
viewModel.init(t, appStartTime);
|
||||||
viewModel.init(t, appStartTime, logKey);
|
|
||||||
viewModel.getShowReport().observeEvent(this, show -> {
|
viewModel.getShowReport().observeEvent(this, show -> {
|
||||||
if (show) displayFragment(true);
|
if (show) displayFragment(true);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -15,8 +15,4 @@ 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,9 +11,6 @@ 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;
|
||||||
@@ -22,7 +19,6 @@ 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;
|
||||||
@@ -40,16 +36,13 @@ 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
|
||||||
class ReportViewModel extends AndroidViewModel {
|
public 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;
|
||||||
@@ -65,39 +58,18 @@ class ReportViewModel extends AndroidViewModel {
|
|||||||
private boolean isFeedback;
|
private boolean isFeedback;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
ReportViewModel(@NonNull Application application,
|
public ReportViewModel(@NonNull Application application,
|
||||||
CachingLogHandler logHandler,
|
DevReporter reporter, PluginManager pluginManager) {
|
||||||
LogDecrypter logDecrypter,
|
|
||||||
DevReporter reporter,
|
|
||||||
PluginManager pluginManager) {
|
|
||||||
super(application);
|
super(application);
|
||||||
collector = new BriarReportCollector(application);
|
this.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(() -> {
|
||||||
String decryptedLogs;
|
ReportData data = collector.collectReportData(t, appStartTime);
|
||||||
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();
|
||||||
}
|
}
|
||||||
@@ -138,8 +110,8 @@ class ReportViewModel extends AndroidViewModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The content of the report that will be loaded after
|
* The content of the report
|
||||||
* {@link #init(Throwable, long, byte[])} was called.
|
* that will be loaded after {@link #init(Throwable, long)} was called.
|
||||||
*/
|
*/
|
||||||
LiveData<ReportData> getReportData() {
|
LiveData<ReportData> getReportData() {
|
||||||
return reportData;
|
return reportData;
|
||||||
|
|||||||
@@ -1,54 +0,0 @@
|
|||||||
package org.briarproject.briar.android.sharing;
|
|
||||||
|
|
||||||
import org.briarproject.bramble.api.contact.ContactId;
|
|
||||||
import org.briarproject.bramble.api.event.EventBus;
|
|
||||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
|
|
||||||
import androidx.annotation.UiThread;
|
|
||||||
import androidx.lifecycle.LiveData;
|
|
||||||
|
|
||||||
@NotNullByDefault
|
|
||||||
public interface SharingController {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Call this when the owning ViewModel gets cleared,
|
|
||||||
* so the {@link EventBus} can get unregistered.
|
|
||||||
*/
|
|
||||||
void onCleared();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds one contact to be tracked.
|
|
||||||
*/
|
|
||||||
@UiThread
|
|
||||||
void add(ContactId c);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds a collection of contacts to be tracked.
|
|
||||||
*/
|
|
||||||
@UiThread
|
|
||||||
void addAll(Collection<ContactId> contacts);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Call this when the contact identified by c is no longer sharing
|
|
||||||
* the given group identified by GroupId g.
|
|
||||||
*/
|
|
||||||
@UiThread
|
|
||||||
void remove(ContactId c);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the total number of contacts that have been added.
|
|
||||||
*/
|
|
||||||
LiveData<SharingInfo> getSharingInfo();
|
|
||||||
|
|
||||||
class SharingInfo {
|
|
||||||
public final int total, online;
|
|
||||||
|
|
||||||
SharingInfo(int total, int online) {
|
|
||||||
this.total = total;
|
|
||||||
this.online = online;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,102 +0,0 @@
|
|||||||
package org.briarproject.briar.android.sharing;
|
|
||||||
|
|
||||||
import org.briarproject.bramble.api.connection.ConnectionRegistry;
|
|
||||||
import org.briarproject.bramble.api.contact.ContactId;
|
|
||||||
import org.briarproject.bramble.api.event.Event;
|
|
||||||
import org.briarproject.bramble.api.event.EventBus;
|
|
||||||
import org.briarproject.bramble.api.event.EventListener;
|
|
||||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
|
||||||
import org.briarproject.bramble.api.plugin.event.ContactConnectedEvent;
|
|
||||||
import org.briarproject.bramble.api.plugin.event.ContactDisconnectedEvent;
|
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import javax.inject.Inject;
|
|
||||||
|
|
||||||
import androidx.annotation.UiThread;
|
|
||||||
import androidx.lifecycle.LiveData;
|
|
||||||
import androidx.lifecycle.MutableLiveData;
|
|
||||||
|
|
||||||
@NotNullByDefault
|
|
||||||
public class SharingControllerImpl implements SharingController, EventListener {
|
|
||||||
|
|
||||||
private final EventBus eventBus;
|
|
||||||
private final ConnectionRegistry connectionRegistry;
|
|
||||||
|
|
||||||
// UI thread
|
|
||||||
private final Set<ContactId> contacts = new HashSet<>();
|
|
||||||
private final MutableLiveData<SharingInfo> sharingInfo =
|
|
||||||
new MutableLiveData<>();
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
SharingControllerImpl(EventBus eventBus,
|
|
||||||
ConnectionRegistry connectionRegistry) {
|
|
||||||
this.eventBus = eventBus;
|
|
||||||
this.connectionRegistry = connectionRegistry;
|
|
||||||
eventBus.addListener(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCleared() {
|
|
||||||
eventBus.removeListener(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void eventOccurred(Event e) {
|
|
||||||
if (e instanceof ContactConnectedEvent) {
|
|
||||||
setConnected(((ContactConnectedEvent) e).getContactId());
|
|
||||||
} else if (e instanceof ContactDisconnectedEvent) {
|
|
||||||
setConnected(((ContactDisconnectedEvent) e).getContactId());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@UiThread
|
|
||||||
private void setConnected(ContactId c) {
|
|
||||||
if (contacts.contains(c)) {
|
|
||||||
updateLiveData();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@UiThread
|
|
||||||
private void updateLiveData() {
|
|
||||||
int online = getOnlineCount();
|
|
||||||
sharingInfo.setValue(new SharingInfo(contacts.size(), online));
|
|
||||||
}
|
|
||||||
|
|
||||||
private int getOnlineCount() {
|
|
||||||
int online = 0;
|
|
||||||
for (ContactId c : contacts) {
|
|
||||||
if (connectionRegistry.isConnected(c)) online++;
|
|
||||||
}
|
|
||||||
return online;
|
|
||||||
}
|
|
||||||
|
|
||||||
@UiThread
|
|
||||||
@Override
|
|
||||||
public void addAll(Collection<ContactId> c) {
|
|
||||||
contacts.addAll(c);
|
|
||||||
updateLiveData();
|
|
||||||
}
|
|
||||||
|
|
||||||
@UiThread
|
|
||||||
@Override
|
|
||||||
public void add(ContactId c) {
|
|
||||||
contacts.add(c);
|
|
||||||
updateLiveData();
|
|
||||||
}
|
|
||||||
|
|
||||||
@UiThread
|
|
||||||
@Override
|
|
||||||
public void remove(ContactId c) {
|
|
||||||
contacts.remove(c);
|
|
||||||
updateLiveData();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public LiveData<SharingInfo> getSharingInfo() {
|
|
||||||
return sharingInfo;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -9,47 +9,36 @@ import dagger.Provides;
|
|||||||
@Module
|
@Module
|
||||||
public class SharingModule {
|
public class SharingModule {
|
||||||
|
|
||||||
@Module
|
@ActivityScope
|
||||||
@Deprecated
|
@Provides
|
||||||
public static class SharingLegacyModule {
|
ShareForumController provideShareForumController(
|
||||||
|
ShareForumControllerImpl shareForumController) {
|
||||||
@ActivityScope
|
return shareForumController;
|
||||||
@Provides
|
|
||||||
ShareForumController provideShareForumController(
|
|
||||||
ShareForumControllerImpl shareForumController) {
|
|
||||||
return shareForumController;
|
|
||||||
}
|
|
||||||
|
|
||||||
@ActivityScope
|
|
||||||
@Provides
|
|
||||||
BlogInvitationController provideInvitationBlogController(
|
|
||||||
BaseActivity activity,
|
|
||||||
BlogInvitationControllerImpl blogInvitationController) {
|
|
||||||
activity.addLifecycleController(blogInvitationController);
|
|
||||||
return blogInvitationController;
|
|
||||||
}
|
|
||||||
|
|
||||||
@ActivityScope
|
|
||||||
@Provides
|
|
||||||
ForumInvitationController provideInvitationForumController(
|
|
||||||
BaseActivity activity,
|
|
||||||
ForumInvitationControllerImpl forumInvitationController) {
|
|
||||||
activity.addLifecycleController(forumInvitationController);
|
|
||||||
return forumInvitationController;
|
|
||||||
}
|
|
||||||
|
|
||||||
@ActivityScope
|
|
||||||
@Provides
|
|
||||||
ShareBlogController provideShareBlogController(
|
|
||||||
ShareBlogControllerImpl shareBlogController) {
|
|
||||||
return shareBlogController;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ActivityScope
|
||||||
@Provides
|
@Provides
|
||||||
SharingController provideSharingController(
|
BlogInvitationController provideInvitationBlogController(
|
||||||
SharingControllerImpl sharingController) {
|
BaseActivity activity,
|
||||||
return sharingController;
|
BlogInvitationControllerImpl blogInvitationController) {
|
||||||
|
activity.addLifecycleController(blogInvitationController);
|
||||||
|
return blogInvitationController;
|
||||||
|
}
|
||||||
|
|
||||||
|
@ActivityScope
|
||||||
|
@Provides
|
||||||
|
ForumInvitationController provideInvitationForumController(
|
||||||
|
BaseActivity activity,
|
||||||
|
ForumInvitationControllerImpl forumInvitationController) {
|
||||||
|
activity.addLifecycleController(forumInvitationController);
|
||||||
|
return forumInvitationController;
|
||||||
|
}
|
||||||
|
|
||||||
|
@ActivityScope
|
||||||
|
@Provides
|
||||||
|
ShareBlogController provideShareBlogController(
|
||||||
|
ShareBlogControllerImpl shareBlogController) {
|
||||||
|
return shareBlogController;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,93 +0,0 @@
|
|||||||
package org.briarproject.briar.android.socialbackup;
|
|
||||||
|
|
||||||
import android.os.Bundle;
|
|
||||||
import android.view.MenuItem;
|
|
||||||
import android.widget.Toast;
|
|
||||||
|
|
||||||
import org.briarproject.bramble.api.contact.ContactId;
|
|
||||||
import org.briarproject.bramble.api.db.DbException;
|
|
||||||
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
|
|
||||||
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
|
||||||
import org.briarproject.bramble.api.sync.GroupId;
|
|
||||||
import org.briarproject.briar.R;
|
|
||||||
import org.briarproject.briar.android.activity.ActivityComponent;
|
|
||||||
import org.briarproject.briar.android.socialbackup.creation.CreateBackupController;
|
|
||||||
import org.briarproject.briar.android.contactselection.BaseContactSelectorAdapter;
|
|
||||||
import org.briarproject.briar.android.contactselection.ContactSelectorController;
|
|
||||||
import org.briarproject.briar.android.contactselection.ContactSelectorFragment;
|
|
||||||
import org.briarproject.briar.android.contactselection.SelectableContactItem;
|
|
||||||
import org.briarproject.briar.android.controller.handler.ResultExceptionHandler;
|
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
|
|
||||||
import javax.inject.Inject;
|
|
||||||
|
|
||||||
import androidx.annotation.Nullable;
|
|
||||||
|
|
||||||
import static java.util.Objects.requireNonNull;
|
|
||||||
|
|
||||||
@MethodsNotNullByDefault
|
|
||||||
@ParametersNotNullByDefault
|
|
||||||
public class CustodianSelectorFragment extends ContactSelectorFragment {
|
|
||||||
|
|
||||||
public static final String TAG = CustodianSelectorFragment.class.getName();
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
CreateBackupController controller;
|
|
||||||
|
|
||||||
public static CustodianSelectorFragment newInstance() {
|
|
||||||
Bundle args = new Bundle();
|
|
||||||
|
|
||||||
CustodianSelectorFragment fragment = new CustodianSelectorFragment();
|
|
||||||
fragment.setArguments(args);
|
|
||||||
|
|
||||||
return fragment;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void injectFragment(ActivityComponent component) {
|
|
||||||
component.inject(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
|
||||||
super.onCreate(savedInstanceState);
|
|
||||||
|
|
||||||
requireActivity().setTitle(R.string.title_select_custodians);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected ContactSelectorController<SelectableContactItem> getController() {
|
|
||||||
return controller;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getUniqueTag() {
|
|
||||||
return TAG;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onSelectionChanged() {
|
|
||||||
super.onSelectionChanged();
|
|
||||||
if (menu == null) return;
|
|
||||||
MenuItem item = menu.findItem(R.id.action_contacts_selected);
|
|
||||||
if (item == null) return;
|
|
||||||
|
|
||||||
BaseContactSelectorAdapter a = adapter;
|
|
||||||
selectedContacts = a.getSelectedContactIds();
|
|
||||||
|
|
||||||
int n = selectedContacts.size();
|
|
||||||
int min = 2;
|
|
||||||
boolean enough = n >= min;
|
|
||||||
|
|
||||||
item.setVisible(enough);
|
|
||||||
if (n == 0) {
|
|
||||||
Toast.makeText(getContext(), String.format(getString(R.string.select_at_least_n_contacts), min),
|
|
||||||
Toast.LENGTH_SHORT).show();
|
|
||||||
} else if (n < min) {
|
|
||||||
Toast.makeText(getContext(), String.format(getString(R.string.select_at_least_n_more_contacts), min - n),
|
|
||||||
Toast.LENGTH_SHORT).show();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,46 +0,0 @@
|
|||||||
package org.briarproject.briar.android.socialbackup;
|
|
||||||
import org.briarproject.bramble.api.crypto.SecretKey;
|
|
||||||
import org.briarproject.briar.api.socialbackup.Shard;
|
|
||||||
import org.briarproject.briar.api.socialbackup.DarkCrystal;
|
|
||||||
import org.magmacollective.darkcrystal.secretsharingwrapper.SecretSharingWrapper;
|
|
||||||
|
|
||||||
import java.security.GeneralSecurityException;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Random;
|
|
||||||
|
|
||||||
import static org.briarproject.briar.socialbackup.SocialBackupConstants.SECRET_ID_BYTES;
|
|
||||||
|
|
||||||
public class DarkCrystalImpl implements DarkCrystal {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<Shard> createShards(SecretKey secret, int numShards,
|
|
||||||
int threshold) {
|
|
||||||
Random random = new Random();
|
|
||||||
byte[] secretId = new byte[SECRET_ID_BYTES];
|
|
||||||
random.nextBytes(secretId);
|
|
||||||
List<byte[]> shardsBytes = SecretSharingWrapper.share(secret.getBytes(), numShards, threshold);
|
|
||||||
List<Shard> shards = new ArrayList<>(numShards);
|
|
||||||
for (byte[] shardBytes : shardsBytes) {
|
|
||||||
shards.add(new Shard(secretId, shardBytes));
|
|
||||||
}
|
|
||||||
return shards;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public SecretKey combineShards(List<Shard> shards) throws
|
|
||||||
GeneralSecurityException {
|
|
||||||
// Check each shard has the same secret Id
|
|
||||||
byte[] secretId = shards.get(0).getSecretId();
|
|
||||||
for (Shard shard : shards) {
|
|
||||||
if (!Arrays.equals(shard.getSecretId(), secretId)) throw new GeneralSecurityException();
|
|
||||||
}
|
|
||||||
List<byte[]> shardsBytes = new ArrayList<>(shards.size());
|
|
||||||
for (Shard shard : shards) {
|
|
||||||
shardsBytes.add(shard.getShard());
|
|
||||||
}
|
|
||||||
byte[] secretBytes = SecretSharingWrapper.combine(shardsBytes);
|
|
||||||
return new SecretKey(secretBytes);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,85 +0,0 @@
|
|||||||
package org.briarproject.briar.android.socialbackup;
|
|
||||||
|
|
||||||
import android.os.Bundle;
|
|
||||||
import android.widget.Toast;
|
|
||||||
|
|
||||||
import org.briarproject.bramble.api.contact.ContactId;
|
|
||||||
import org.briarproject.bramble.api.db.DatabaseComponent;
|
|
||||||
import org.briarproject.bramble.api.db.DbException;
|
|
||||||
import org.briarproject.briar.R;
|
|
||||||
import org.briarproject.briar.android.activity.ActivityComponent;
|
|
||||||
import org.briarproject.briar.android.activity.BriarActivity;
|
|
||||||
import org.briarproject.briar.android.contactselection.ContactSelectorListener;
|
|
||||||
import org.briarproject.briar.android.fragment.BaseFragment;
|
|
||||||
import org.briarproject.briar.api.socialbackup.BackupMetadata;
|
|
||||||
import org.briarproject.briar.api.socialbackup.SocialBackupManager;
|
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import javax.inject.Inject;
|
|
||||||
|
|
||||||
public class DistributedBackupActivity extends BriarActivity implements
|
|
||||||
BaseFragment.BaseFragmentListener, ContactSelectorListener,
|
|
||||||
ThresholdDefinedListener, ShardsSentDismissedListener {
|
|
||||||
|
|
||||||
private Collection<ContactId> custodians;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
public SocialBackupManager socialBackupManager;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
public DatabaseComponent db;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void injectActivity(ActivityComponent component) {
|
|
||||||
component.inject(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
|
||||||
super.onCreate(savedInstanceState);
|
|
||||||
setContentView(R.layout.activity_distributed_backup);
|
|
||||||
// TODO here we should check if we already have a backup
|
|
||||||
|
|
||||||
try {
|
|
||||||
db.transaction(false, txn -> {
|
|
||||||
BackupMetadata backupMetadata = socialBackupManager.getBackupMetadata(txn);
|
|
||||||
if (backupMetadata == null) {
|
|
||||||
CustodianSelectorFragment fragment =
|
|
||||||
CustodianSelectorFragment.newInstance();
|
|
||||||
showInitialFragment(fragment);
|
|
||||||
} else {
|
|
||||||
ExistingBackupFragment fragment = ExistingBackupFragment.newInstance(backupMetadata);
|
|
||||||
showInitialFragment(fragment);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} catch (DbException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void contactsSelected(Collection<ContactId> contacts) {
|
|
||||||
Toast.makeText(this,
|
|
||||||
String.format("selected %d contacts", contacts.size()),
|
|
||||||
Toast.LENGTH_SHORT).show();
|
|
||||||
custodians = contacts;
|
|
||||||
ThresholdSelectorFragment fragment = ThresholdSelectorFragment.newInstance(contacts.size());
|
|
||||||
showNextFragment(fragment);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void thresholdDefined(int threshold) throws DbException {
|
|
||||||
db.transaction(false, txn -> {
|
|
||||||
socialBackupManager.createBackup(txn, (List<ContactId>) custodians, threshold);
|
|
||||||
ShardsSentFragment fragment = new ShardsSentFragment();
|
|
||||||
showNextFragment(fragment);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void shardsSentDismissed() {
|
|
||||||
finish();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,85 +0,0 @@
|
|||||||
package org.briarproject.briar.android.socialbackup;
|
|
||||||
|
|
||||||
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.identity.Author;
|
|
||||||
import org.briarproject.briar.R;
|
|
||||||
import org.briarproject.briar.android.activity.ActivityComponent;
|
|
||||||
import org.briarproject.briar.android.fragment.BaseFragment;
|
|
||||||
import org.briarproject.briar.api.socialbackup.BackupMetadata;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
import androidx.annotation.Nullable;
|
|
||||||
|
|
||||||
public class ExistingBackupFragment extends BaseFragment {
|
|
||||||
|
|
||||||
private static final String THRESHOLD = "threshold";
|
|
||||||
private static final String CUSTODIANS = "custodians";
|
|
||||||
public static final String TAG = ExistingBackupFragment.class.getName();
|
|
||||||
|
|
||||||
public static ExistingBackupFragment newInstance(
|
|
||||||
BackupMetadata backupMetadata) {
|
|
||||||
Bundle bundle = new Bundle();
|
|
||||||
List<Author> custodians = backupMetadata.getCustodians();
|
|
||||||
ArrayList custodianNames = new ArrayList();
|
|
||||||
for (Author custodian : custodians) {
|
|
||||||
custodianNames.add(custodian.getName());
|
|
||||||
}
|
|
||||||
bundle.putStringArrayList(CUSTODIANS, custodianNames);
|
|
||||||
bundle.putInt(THRESHOLD, backupMetadata.getThreshold());
|
|
||||||
ExistingBackupFragment fragment = new ExistingBackupFragment();
|
|
||||||
fragment.setArguments(bundle);
|
|
||||||
return fragment;
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
|
||||||
super.onCreate(savedInstanceState);
|
|
||||||
requireActivity().setTitle(R.string.title_distributed_backup);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
@Override
|
|
||||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable
|
|
||||||
ViewGroup container, @Nullable Bundle savedInstanceState) {
|
|
||||||
View view = inflater.inflate(R.layout.fragment_existing_backup,
|
|
||||||
container, false);
|
|
||||||
Bundle args = requireArguments();
|
|
||||||
ArrayList<String> custodianNames = args.getStringArrayList(CUSTODIANS);
|
|
||||||
String custodianNamesString = "";
|
|
||||||
for (String custodianName : custodianNames) {
|
|
||||||
custodianNamesString += custodianName + ", ";
|
|
||||||
}
|
|
||||||
TextView textViewThreshold = view.findViewById(R.id.textViewThreshold);
|
|
||||||
textViewThreshold.setText(String.format("%d of %d contacts needed to restore account", args.getInt(THRESHOLD), custodianNames.size()));
|
|
||||||
TextView textViewCustodians = view.findViewById(R.id.textViewCustodians);
|
|
||||||
textViewCustodians.setText(custodianNamesString);
|
|
||||||
return view;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onAttach(Context context) {
|
|
||||||
super.onAttach(context);
|
|
||||||
// listener = (ShardsSentDismissedListener) context;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getUniqueTag() {
|
|
||||||
return TAG;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void injectFragment(ActivityComponent component) {
|
|
||||||
component.inject(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user