mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-11 18:29:05 +01:00
Compare commits
168 Commits
1881-threa
...
social-bac
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
995a053241 | ||
|
|
265d1da566 | ||
|
|
b6d57a492b | ||
|
|
943f107232 | ||
|
|
09e024ea5e | ||
|
|
2486a60fea | ||
|
|
365fa58928 | ||
|
|
45d2e2ce06 | ||
|
|
b1f5d71a4e | ||
|
|
d47c18b392 | ||
|
|
8ed58eaada | ||
|
|
8478097a3c | ||
|
|
0440c5c7c8 | ||
|
|
58db654a9b | ||
|
|
c3d137a73c | ||
|
|
db7825d7f6 | ||
|
|
24059adbd6 | ||
|
|
7d128988a7 | ||
|
|
9499a078a6 | ||
|
|
6483b0ed87 | ||
|
|
af097dc859 | ||
|
|
3adc6d002c | ||
|
|
0658e90c65 | ||
|
|
6d0aebd7ec | ||
|
|
0faccfe5a3 | ||
|
|
c19c40bdc8 | ||
|
|
363da96709 | ||
|
|
e9c2cb2cc5 | ||
|
|
505124a22f | ||
|
|
9b750291d1 | ||
|
|
9c829ec7c9 | ||
|
|
1b9ba41110 | ||
|
|
fa39e7c824 | ||
|
|
37fb3bd79f | ||
|
|
1c5e89b100 | ||
|
|
6dc6a34d29 | ||
|
|
35b2b8c9d2 | ||
|
|
e3ff8a80e5 | ||
|
|
e09fedd79f | ||
|
|
6c3df2a3d4 | ||
|
|
a9edf43df2 | ||
|
|
d91d2e0070 | ||
|
|
58f803a48a | ||
|
|
ac9c71f7eb | ||
|
|
b3292f86ab | ||
|
|
28d2697e38 | ||
|
|
8e4b309a12 | ||
|
|
8a1333e8f2 | ||
|
|
bd2a671f9f | ||
|
|
845be86113 | ||
|
|
25bbb5aa36 | ||
|
|
57605d55ce | ||
|
|
6c079e172a | ||
|
|
a101229f73 | ||
|
|
3f7f53774b | ||
|
|
9beb4d7b81 | ||
|
|
378112c00c | ||
|
|
451a3238be | ||
|
|
bf6dd0d924 | ||
|
|
085e25cc14 | ||
|
|
033c9f4d59 | ||
|
|
5f7bc4a143 | ||
|
|
4972c554dc | ||
|
|
44e33e3d1a | ||
|
|
5212bb7a01 | ||
|
|
83aad185cd | ||
|
|
c318dcfb5f | ||
|
|
10610930c0 | ||
|
|
2af236b733 | ||
|
|
d46a513208 | ||
|
|
022357fb4c | ||
|
|
a576d7abf8 | ||
|
|
008877a9da | ||
|
|
01bc94c241 | ||
|
|
03c1f9c99a | ||
|
|
0b9e4915dc | ||
|
|
55e5600214 | ||
|
|
4c357fe87a | ||
|
|
6a7ceb4a68 | ||
|
|
d917e9d642 | ||
|
|
c7f6270b2a | ||
|
|
681b151c8b | ||
|
|
b86b0f5fbc | ||
|
|
dc138c713f | ||
|
|
7da49ae6df | ||
|
|
3c61f499d9 | ||
|
|
fbe839d9ca | ||
|
|
f2638c9db2 | ||
|
|
808166931e | ||
|
|
77d0c16530 | ||
|
|
c991cfb926 | ||
|
|
dcda13db64 | ||
|
|
ff4640b789 | ||
|
|
a2426e3b2a | ||
|
|
0bc4bf232f | ||
|
|
2ed44aa2a8 | ||
|
|
8496ab0a6a | ||
|
|
b57d811b4a | ||
|
|
4077e28999 | ||
|
|
292fb6d3b1 | ||
|
|
4ead7cd4a1 | ||
|
|
513e696238 | ||
|
|
f160efb0e7 | ||
|
|
a6c2000d81 | ||
|
|
a38a3139d9 | ||
|
|
4c8adaa02b | ||
|
|
8a534b4503 | ||
|
|
e5b2275c82 | ||
|
|
5159593825 | ||
|
|
a546fecc01 | ||
|
|
3e7e37f5f6 | ||
|
|
d095ba0b15 | ||
|
|
7fab97d26c | ||
|
|
6fbc82ee27 | ||
|
|
885b03cfd7 | ||
|
|
f81bfcafeb | ||
|
|
f36f1cf3d4 | ||
|
|
7d6a63d866 | ||
|
|
15ebdf8dd5 | ||
|
|
db2c235283 | ||
|
|
e5bd43469e | ||
|
|
9366c184d8 | ||
|
|
73d2c964d4 | ||
|
|
fb2b4209cf | ||
|
|
a04b512497 | ||
|
|
3d9515e308 | ||
|
|
1b19b331b1 | ||
|
|
d151a2d7f7 | ||
|
|
9712a4b849 | ||
|
|
cf1ac5e3e5 | ||
|
|
cb859e998d | ||
|
|
0b9345f867 | ||
|
|
12988120d1 | ||
|
|
8d6c866e62 | ||
|
|
8f82cf3c73 | ||
|
|
21112ce092 | ||
|
|
21ee3ea00d | ||
|
|
bb964101b3 | ||
|
|
d796eff0f6 | ||
|
|
700ea2b387 | ||
|
|
e4a66615a7 | ||
|
|
6e3a7d8d0c | ||
|
|
166b5d4add | ||
|
|
0fd59a26f6 | ||
|
|
4162bf990a | ||
|
|
09cfadbf7e | ||
|
|
3fb27dbb12 | ||
|
|
ae4a04bada | ||
|
|
831c65b647 | ||
|
|
afcd38b84c | ||
|
|
d670179e30 | ||
|
|
998c435b13 | ||
|
|
4a0327a62b | ||
|
|
70532732c8 | ||
|
|
d69406dfe3 | ||
|
|
98619df867 | ||
|
|
f2eca0fdb6 | ||
|
|
c62a57e8b2 | ||
|
|
239c4a27ad | ||
|
|
e5d78a858d | ||
|
|
5c1bcdeb9d | ||
|
|
6c1f5450cb | ||
|
|
0d070cf422 | ||
|
|
d34d66c691 | ||
|
|
6005d156eb | ||
|
|
94dd75f24b | ||
|
|
c93e5441b0 | ||
|
|
8ec8cc927b |
@@ -2,6 +2,7 @@ image: briar/ci-image-android:latest
|
||||
|
||||
stages:
|
||||
- test
|
||||
- optional_tests
|
||||
- check_reproducibility
|
||||
|
||||
test:
|
||||
@@ -31,3 +32,33 @@ 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"
|
||||
only:
|
||||
- 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
Normal file
14
.idea/dictionaries/briar.xml
generated
Normal file
@@ -0,0 +1,14 @@
|
||||
<component name="ProjectDictionaryState">
|
||||
<dictionary name="briar">
|
||||
<words>
|
||||
<w>briar</w>
|
||||
<w>briarproject</w>
|
||||
<w>emoji</w>
|
||||
<w>encrypter</w>
|
||||
<w>identicon</w>
|
||||
<w>introducee</w>
|
||||
<w>introducer</w>
|
||||
<w>onboarding</w>
|
||||
</words>
|
||||
</dictionary>
|
||||
</component>
|
||||
24
.idea/runConfigurations/BridgeTest.xml
generated
Normal file
24
.idea/runConfigurations/BridgeTest.xml
generated
Normal file
@@ -0,0 +1,24 @@
|
||||
<component name="ProjectRunConfigurationManager">
|
||||
<configuration default="false" name="BridgeTest" type="AndroidJUnit" factoryName="Android JUnit" nameIsGenerated="true">
|
||||
<module name="briar.bramble-java" />
|
||||
<useClassPathOnly />
|
||||
<extension name="coverage">
|
||||
<pattern>
|
||||
<option name="PATTERN" value="org.briarproject.bramble.plugin.tor.*" />
|
||||
<option name="ENABLED" value="true" />
|
||||
</pattern>
|
||||
</extension>
|
||||
<option name="PACKAGE_NAME" value="org.briarproject.bramble.plugin.tor" />
|
||||
<option name="MAIN_CLASS_NAME" value="org.briarproject.bramble.plugin.tor.BridgeTest" />
|
||||
<option name="METHOD_NAME" value="" />
|
||||
<option name="TEST_OBJECT" value="class" />
|
||||
<option name="PARAMETERS" value="" />
|
||||
<option name="WORKING_DIRECTORY" value="$MODULE_DIR$" />
|
||||
<envs>
|
||||
<env name="OPTIONAL_TESTS" value="org.briarproject.bramble.plugin.tor.BridgeTest" />
|
||||
</envs>
|
||||
<method v="2">
|
||||
<option name="Android.Gradle.BeforeRunTask" enabled="true" />
|
||||
</method>
|
||||
</configuration>
|
||||
</component>
|
||||
@@ -11,8 +11,8 @@ android {
|
||||
defaultConfig {
|
||||
minSdkVersion 16
|
||||
targetSdkVersion 29
|
||||
versionCode 10213
|
||||
versionName "1.2.13"
|
||||
versionCode 10216
|
||||
versionName "1.2.16"
|
||||
consumerProguardFiles 'proguard-rules.txt'
|
||||
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
@@ -38,8 +38,8 @@ configurations {
|
||||
|
||||
dependencies {
|
||||
implementation project(path: ':bramble-core', configuration: 'default')
|
||||
tor 'org.briarproject:tor-android:0.3.5.12@zip'
|
||||
tor 'org.briarproject:obfs4proxy-android:0.0.11-2@zip'
|
||||
tor 'org.briarproject:tor-android:0.3.5.13@zip'
|
||||
tor 'org.briarproject:obfs4proxy-android:0.0.12-dev-40245c4a@zip'
|
||||
|
||||
annotationProcessor 'com.google.dagger:dagger-compiler:2.24'
|
||||
|
||||
|
||||
@@ -31,6 +31,7 @@ public class AndroidUtils {
|
||||
private static final String FAKE_BLUETOOTH_ADDRESS = "02:00:00:00:00:00";
|
||||
|
||||
private static final String STORED_REPORTS = "dev-reports";
|
||||
private static final String STORED_LOGCAT = "dev-logcat";
|
||||
|
||||
public static Collection<String> getSupportedArchitectures() {
|
||||
List<String> abis = new ArrayList<>();
|
||||
@@ -107,6 +108,10 @@ public class AndroidUtils {
|
||||
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.
|
||||
* 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.bouncycastle:bcpkix-jdk15on:1.56:bcpkix-jdk15on-1.56.jar:7043dee4e9e7175e93e0b36f45b1ec1ecb893c5f755667e8b916eb8dd201c6ca',
|
||||
'org.bouncycastle:bcprov-jdk15on:1.56:bcprov-jdk15on-1.56.jar:963e1ee14f808ffb99897d848ddcdb28fa91ddda867eb18d303e82728f878349',
|
||||
'org.briarproject:obfs4proxy-android:0.0.11-2:obfs4proxy-android-0.0.11-2.zip:57e55cbe87aa2aac210fdbb6cd8cdeafe15f825406a08ebf77a8b787aa2c6a8a',
|
||||
'org.briarproject:tor-android:0.3.5.12:tor-android-0.3.5.12.zip:db71fb3290acff79d572af0752570eaf6aad7c4d88c9b9aa0b4d5afe2b9ead9c',
|
||||
'org.briarproject:obfs4proxy-android:0.0.12-dev-40245c4a:obfs4proxy-android-0.0.12-dev-40245c4a.zip:8ab05a8f8391be2cb5ab2b665c281a06d9e3a756bd0f95a40a36ca927866ea82',
|
||||
'org.briarproject:tor-android:0.3.5.13:tor-android-0.3.5.13.zip:e0978db136731dae07774b722970cdae1e462fb5adc82845dd80a7e2d87f356c',
|
||||
'org.checkerframework:checker-compat-qual:2.5.3:checker-compat-qual-2.5.3.jar:d76b9afea61c7c082908023f0cbc1427fab9abd2df915c8b8a3e7a509bccbc6d',
|
||||
'org.checkerframework:checker-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',
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
package org.briarproject.bramble.crypto;
|
||||
package org.briarproject.bramble.api.crypto;
|
||||
|
||||
import org.briarproject.bramble.api.crypto.SecretKey;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
|
||||
import java.security.GeneralSecurityException;
|
||||
|
||||
@NotNullByDefault
|
||||
interface AuthenticatedCipher {
|
||||
public interface AuthenticatedCipher {
|
||||
|
||||
/**
|
||||
* Initializes this cipher for encryption or decryption with a key and an
|
||||
@@ -19,4 +19,10 @@ public interface StreamDecrypterFactory {
|
||||
*/
|
||||
StreamDecrypter createContactExchangeStreamDecrypter(InputStream in,
|
||||
SecretKey headerKey);
|
||||
|
||||
/**
|
||||
* Creates a {@link StreamDecrypter} for decrypting a log stream.
|
||||
*/
|
||||
StreamDecrypter createLogStreamDecrypter(InputStream in,
|
||||
SecretKey headerKey);
|
||||
}
|
||||
|
||||
@@ -17,6 +17,12 @@ public interface StreamEncrypterFactory {
|
||||
* Creates a {@link StreamEncrypter} for encrypting a contact exchange
|
||||
* stream.
|
||||
*/
|
||||
StreamEncrypter createContactExchangeStreamDecrypter(OutputStream out,
|
||||
StreamEncrypter createContactExchangeStreamEncrypter(OutputStream out,
|
||||
SecretKey headerKey);
|
||||
|
||||
/**
|
||||
* Creates a {@link StreamEncrypter} for encrypting a log stream.
|
||||
*/
|
||||
StreamEncrypter createLogStreamEncrypter(OutputStream out,
|
||||
SecretKey headerKey);
|
||||
}
|
||||
|
||||
@@ -26,6 +26,11 @@ public interface IdentityManager {
|
||||
*/
|
||||
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.
|
||||
*/
|
||||
|
||||
@@ -74,6 +74,13 @@ public interface TransportPropertyManager {
|
||||
TransportProperties getRemoteProperties(ContactId c, TransportId t)
|
||||
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
|
||||
* given transport.
|
||||
|
||||
@@ -13,4 +13,6 @@ public interface DevConfig {
|
||||
String getDevOnionAddress();
|
||||
|
||||
File getReportDir();
|
||||
|
||||
File getLogcatFile();
|
||||
}
|
||||
|
||||
@@ -16,8 +16,13 @@ public interface StreamReaderFactory {
|
||||
|
||||
/**
|
||||
* Creates an {@link InputStream InputStream} for reading from a contact
|
||||
* exchangestream.
|
||||
* exchange stream.
|
||||
*/
|
||||
InputStream createContactExchangeStreamReader(InputStream in,
|
||||
SecretKey headerKey);
|
||||
|
||||
/**
|
||||
* Creates an {@link InputStream} for reading from a log stream.
|
||||
*/
|
||||
InputStream createLogStreamReader(InputStream in, SecretKey headerKey);
|
||||
}
|
||||
|
||||
@@ -7,17 +7,19 @@ import java.io.OutputStream;
|
||||
|
||||
@NotNullByDefault
|
||||
public interface StreamWriterFactory {
|
||||
|
||||
/**
|
||||
* Creates an {@link OutputStream OutputStream} for writing to a
|
||||
* transport stream
|
||||
* Creates a {@link StreamWriter} for writing to a transport stream.
|
||||
*/
|
||||
StreamWriter createStreamWriter(OutputStream out, StreamContext ctx);
|
||||
|
||||
/**
|
||||
* Creates an {@link OutputStream OutputStream} for writing to a contact
|
||||
* exchange stream.
|
||||
* Creates a {@link StreamWriter} for writing to a contact exchange stream.
|
||||
*/
|
||||
StreamWriter createContactExchangeStreamWriter(OutputStream out,
|
||||
SecretKey headerKey);
|
||||
|
||||
/**
|
||||
* Creates a {@link StreamWriter} for writing to a log stream.
|
||||
*/
|
||||
StreamWriter createLogStreamWriter(OutputStream out, SecretKey headerKey);
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import net.i2p.crypto.eddsa.KeyPairGenerator;
|
||||
|
||||
import org.briarproject.bramble.api.crypto.AgreementPrivateKey;
|
||||
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.DecryptionException;
|
||||
import org.briarproject.bramble.api.crypto.KeyPair;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
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.KeyAgreementCrypto;
|
||||
import org.briarproject.bramble.api.crypto.PasswordStrengthEstimator;
|
||||
|
||||
@@ -9,14 +9,16 @@ import java.util.logging.Logger;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import static java.lang.Math.min;
|
||||
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.now;
|
||||
|
||||
class ScryptKdf implements PasswordBasedKdf {
|
||||
|
||||
private static final Logger LOG =
|
||||
Logger.getLogger(ScryptKdf.class.getName());
|
||||
getLogger(ScryptKdf.class.getName());
|
||||
|
||||
private static final int MIN_COST = 256; // Min parameter N
|
||||
private static final int MAX_COST = 1024 * 1024; // Max parameter N
|
||||
@@ -33,10 +35,20 @@ class ScryptKdf implements PasswordBasedKdf {
|
||||
|
||||
@Override
|
||||
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
|
||||
int cost = MIN_COST;
|
||||
while (cost * 2 <= MAX_COST && measureDuration(cost) * 2 <= TARGET_MS)
|
||||
while (cost * 2 <= maxCost && measureDuration(cost) * 2 <= TARGET_MS) {
|
||||
cost *= 2;
|
||||
}
|
||||
if (LOG.isLoggable(INFO))
|
||||
LOG.info("KDF cost parameter " + cost);
|
||||
return cost;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
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.StreamDecrypter;
|
||||
import org.briarproject.bramble.api.crypto.StreamDecrypterFactory;
|
||||
@@ -36,4 +37,10 @@ class StreamDecrypterFactoryImpl implements StreamDecrypterFactory {
|
||||
SecretKey headerKey) {
|
||||
return new StreamDecrypterImpl(in, cipherProvider.get(), 0, headerKey);
|
||||
}
|
||||
|
||||
@Override
|
||||
public StreamDecrypter createLogStreamDecrypter(InputStream in,
|
||||
SecretKey headerKey) {
|
||||
return createContactExchangeStreamDecrypter(in, headerKey);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package org.briarproject.bramble.crypto;
|
||||
|
||||
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.StreamDecrypter;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
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.SecretKey;
|
||||
import org.briarproject.bramble.api.crypto.StreamEncrypter;
|
||||
@@ -51,7 +52,7 @@ class StreamEncrypterFactoryImpl implements StreamEncrypterFactory {
|
||||
}
|
||||
|
||||
@Override
|
||||
public StreamEncrypter createContactExchangeStreamDecrypter(
|
||||
public StreamEncrypter createContactExchangeStreamEncrypter(
|
||||
OutputStream out, SecretKey headerKey) {
|
||||
AuthenticatedCipher cipher = cipherProvider.get();
|
||||
byte[] streamHeaderNonce = new byte[STREAM_HEADER_NONCE_LENGTH];
|
||||
@@ -60,4 +61,10 @@ class StreamEncrypterFactoryImpl implements StreamEncrypterFactory {
|
||||
return new StreamEncrypterImpl(out, cipher, 0, null, streamHeaderNonce,
|
||||
headerKey, frameKey);
|
||||
}
|
||||
|
||||
@Override
|
||||
public StreamEncrypter createLogStreamEncrypter(OutputStream out,
|
||||
SecretKey headerKey) {
|
||||
return createContactExchangeStreamEncrypter(out, headerKey);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
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.StreamEncrypter;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package org.briarproject.bramble.crypto;
|
||||
|
||||
import org.briarproject.bramble.api.crypto.AuthenticatedCipher;
|
||||
import org.briarproject.bramble.api.crypto.SecretKey;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.spongycastle.crypto.DataLengthException;
|
||||
|
||||
@@ -118,6 +118,11 @@ class IdentityManagerImpl implements IdentityManager, OpenDatabaseHook {
|
||||
return cached.getLocalAuthor();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Identity getIdentity(Transaction txn) throws DbException {
|
||||
return getCachedIdentity(txn);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LocalAuthor getLocalAuthor(Transaction txn) throws DbException {
|
||||
return getCachedIdentity(txn).getLocalAuthor();
|
||||
|
||||
@@ -294,7 +294,13 @@ class TransportPropertyManagerImpl implements TransportPropertyManager,
|
||||
public TransportProperties getRemoteProperties(ContactId c, TransportId t)
|
||||
throws DbException {
|
||||
return db.transactionWithResult(true, txn ->
|
||||
getRemoteProperties(txn, db.getContact(txn, c), t));
|
||||
getRemoteProperties(txn, c, t));
|
||||
}
|
||||
|
||||
@Override
|
||||
public TransportProperties getRemoteProperties(Transaction txn,
|
||||
ContactId c, TransportId t) throws DbException {
|
||||
return getRemoteProperties(txn, db.getContact(txn, c), t);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -24,15 +24,21 @@ class StreamReaderFactoryImpl implements StreamReaderFactory {
|
||||
|
||||
@Override
|
||||
public InputStream createStreamReader(InputStream in, StreamContext ctx) {
|
||||
return new StreamReaderImpl(
|
||||
streamDecrypterFactory.createStreamDecrypter(in, ctx));
|
||||
return new StreamReaderImpl(streamDecrypterFactory
|
||||
.createStreamDecrypter(in, ctx));
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream createContactExchangeStreamReader(InputStream in,
|
||||
SecretKey headerKey) {
|
||||
return new StreamReaderImpl(
|
||||
streamDecrypterFactory.createContactExchangeStreamDecrypter(in,
|
||||
headerKey));
|
||||
return new StreamReaderImpl(streamDecrypterFactory
|
||||
.createContactExchangeStreamDecrypter(in, headerKey));
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream createLogStreamReader(InputStream in,
|
||||
SecretKey headerKey) {
|
||||
return new StreamReaderImpl(streamDecrypterFactory
|
||||
.createLogStreamDecrypter(in, headerKey));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,15 +26,21 @@ class StreamWriterFactoryImpl implements StreamWriterFactory {
|
||||
@Override
|
||||
public StreamWriter createStreamWriter(OutputStream out,
|
||||
StreamContext ctx) {
|
||||
return new StreamWriterImpl(
|
||||
streamEncrypterFactory.createStreamEncrypter(out, ctx));
|
||||
return new StreamWriterImpl(streamEncrypterFactory
|
||||
.createStreamEncrypter(out, ctx));
|
||||
}
|
||||
|
||||
@Override
|
||||
public StreamWriter createContactExchangeStreamWriter(OutputStream out,
|
||||
SecretKey headerKey) {
|
||||
return new StreamWriterImpl(
|
||||
streamEncrypterFactory.createContactExchangeStreamDecrypter(out,
|
||||
headerKey));
|
||||
return new StreamWriterImpl(streamEncrypterFactory
|
||||
.createContactExchangeStreamEncrypter(out, headerKey));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public StreamWriter createLogStreamWriter(OutputStream out,
|
||||
SecretKey headerKey) {
|
||||
return new StreamWriterImpl(streamEncrypterFactory
|
||||
.createLogStreamEncrypter(out, headerKey));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,14 @@
|
||||
Bridge obfs4 192.95.36.142:443 CDF2E852BF539B82BD10E27E9115A31734E378C2 cert=qUVQ0srL1JI/vO6V6m/24anYXiJD3QP2HgzUKQtQ7GRqqUvs7P+tG43RtAqdhLOALP7DJQ iat-mode=1
|
||||
Bridge obfs4 38.229.1.78:80 C8CBDB2464FC9804A69531437BCF2BE31FDD2EE4 cert=Hmyfd2ev46gGY7NoVxA9ngrPF2zCZtzskRTzoWXbxNkzeVnGFPWmrTtILRyqCTjHR+s9dg iat-mode=1
|
||||
Bridge obfs4 37.218.245.14:38224 D9A82D2F9C2F65A18407B1D2B764F130847F8B5D cert=bjRaMrr1BRiAW8IE9U5z27fQaYgOhX1UCmOpg2pFpoMvo6ZgQMzLsaTzzQNTlm7hNcb+Sg iat-mode=0
|
||||
Bridge obfs4 85.31.186.98:443 011F2599C0E9B27EE74B353155E244813763C3E5 cert=ayq0XzCwhpdysn5o0EyDUbmSOx3X/oTEbzDMvczHOdBJKlvIdHHLJGkZARtT4dcBFArPPg iat-mode=0
|
||||
Bridge obfs4 85.31.186.26:443 91A6354697E6B02A386312F68D82CF86824D3606 cert=PBwr+S8JTVZo6MPdHnkTwXJPILWADLqfMGoVvhZClMq/Urndyd42BwX9YFJHZnBB3H0XCw iat-mode=0
|
||||
Bridge obfs4 193.11.166.194:27015 2D82C2E354D531A68469ADF7F878FA6060C6BACA cert=4TLQPJrTSaDffMK7Nbao6LC7G9OW/NHkUwIdjLSS3KYf0Nv4/nQiiI8dY2TcsQx01NniOg iat-mode=0
|
||||
Bridge obfs4 193.11.166.194:27020 86AC7B8D430DAC4117E9F42C9EAED18133863AAF cert=0LDeJH4JzMDtkJJrFphJCiPqKx7loozKN7VNfuukMGfHO0Z8OGdzHVkhVAOfo1mUdv9cMg iat-mode=0
|
||||
Bridge obfs4 193.11.166.194:27025 1AE2C08904527FEA90C4C4F8C1083EA59FBC6FAF cert=ItvYZzW5tn6v3G4UnQa6Qz04Npro6e81AP70YujmK/KXwDFPTs3aHXcHp4n8Vt6w/bv8cA iat-mode=0
|
||||
Bridge obfs4 209.148.46.65:443 74FAD13168806246602538555B5521A0383A1875 cert=ssH+9rP8dG2NLDN2XuFw63hIO/9MNNinLmxQDpVa+7kTOa9/m+tGWT1SmSYpQ9uTBGa6Hw iat-mode=0
|
||||
Bridge obfs4 146.57.248.225:22 10A6CD36A537FCE513A322361547444B393989F0 cert=K1gDtDAIcUfeLqbstggjIw2rtgIKqdIhUlHp82XRqNSq/mtAjp1BIC9vHKJ2FAEpGssTPw iat-mode=0
|
||||
Bridge obfs4 45.145.95.6:27015 C5B7CD6946FF10C5B3E89691A7D3F2C122D2117C cert=TD7PbUO0/0k6xYHMPW3vJxICfkMZNdkRrb63Zhl5j9dW3iRGiCx0A7mPhe5T2EDzQ35+Zw iat-mode=0
|
||||
Bridge obfs4 51.222.13.177:80 5EDAC3B810E12B01F6FD8050D2FD3E277B289A08 cert=2uplIpLQ0q9+0qMFrK5pkaYRDOe460LL9WHBvatgkuRr/SL31wBOEupaMMJ6koRE6Ld0ew iat-mode=0
|
||||
Bridge obfs4 78.46.188.239:37356 5A2D2F4158D0453E00C7C176978D3F41D69C45DB cert=3c0SwxpOisbohNxEc4tb875RVW8eOu1opRTVXJhafaKA/PNNtI7ElQIVOVZg1AdL5bxGCw iat-mode=0
|
||||
Bridge obfs4 52.15.78.72:9443 02069A3C5362476936B62BA6F5ACC41ABD573A9B cert=ijYG/OKc7kqu2YzKNFfeXN7/BG2BOgfEP2KyYEiGDQthnHbsOiTWHeIG0WJVW+BckzDgKw iat-mode=0
|
||||
Bridge obfs4 13.58.29.242:9443 0C58939A77DA6B6B29D4B5236A75865659607AE0 cert=OylWIEHb/ezpq1zWxW0sgKRn+9ARH2eOcQOZ8/Gew+4l+oKOhQ2jUX/Y+FSl61JorXZUWA iat-mode=0
|
||||
Bridge obfs4 45.33.37.112:9443 60A609BB4ABE8D46E634AE81ED29ADAB7776B399 cert=t5v19WmNv5Sc2YPNr8RQids365W7MY8zJwQVkOxBjUMFomMWARDzsbYpcWLLcw0J9Gm+BQ iat-mode=0
|
||||
Bridge meek_lite 0.0.2.0:2 97700DFE9F483596DDA6264C4D7DF7641E1E39CE url=https://meek.azureedge.net/ front=ajax.aspnetcdn.com
|
||||
Bridge meek_lite 192.0.2.2:2 97700DFE9F483596DDA6264C4D7DF7641E1E39CE url=https://meek.azureedge.net/ front=ajax.aspnetcdn.com
|
||||
@@ -1,5 +1,6 @@
|
||||
package org.briarproject.bramble.crypto;
|
||||
|
||||
import org.briarproject.bramble.api.crypto.AuthenticatedCipher;
|
||||
import org.briarproject.bramble.api.crypto.SecretKey;
|
||||
import org.briarproject.bramble.test.BrambleTestCase;
|
||||
import org.briarproject.bramble.test.TestUtils;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package org.briarproject.bramble.crypto;
|
||||
|
||||
import org.briarproject.bramble.api.crypto.AuthenticatedCipher;
|
||||
import org.briarproject.bramble.api.crypto.SecretKey;
|
||||
import org.briarproject.bramble.test.BrambleTestCase;
|
||||
import org.briarproject.bramble.test.TestUtils;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package org.briarproject.bramble.crypto;
|
||||
|
||||
import org.briarproject.bramble.api.crypto.AuthenticatedCipher;
|
||||
import org.briarproject.bramble.api.crypto.SecretKey;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package org.briarproject.bramble.crypto;
|
||||
|
||||
import org.briarproject.bramble.api.crypto.AuthenticatedCipher;
|
||||
import org.briarproject.bramble.api.crypto.SecretKey;
|
||||
import org.briarproject.bramble.test.BrambleTestCase;
|
||||
import org.briarproject.bramble.util.StringUtils;
|
||||
|
||||
@@ -16,8 +16,8 @@ dependencies {
|
||||
implementation fileTree(dir: 'libs', include: '*.jar')
|
||||
implementation 'net.java.dev.jna:jna:4.5.2'
|
||||
implementation 'net.java.dev.jna:jna-platform:4.5.2'
|
||||
tor 'org.briarproject:tor:0.3.5.12@zip'
|
||||
tor 'org.briarproject:obfs4proxy:0.0.7@zip'
|
||||
tor 'org.briarproject:tor:0.3.5.13@zip'
|
||||
tor 'org.briarproject:obfs4proxy:0.0.12-dev-40245c4a@zip'
|
||||
|
||||
annotationProcessor 'com.google.dagger:dagger-compiler:2.24'
|
||||
|
||||
|
||||
@@ -53,7 +53,7 @@ public class BridgeTest extends BrambleTestCase {
|
||||
return component.getCircumventionProvider().getBridges(false);
|
||||
}
|
||||
|
||||
private final static long TIMEOUT = SECONDS.toMillis(30);
|
||||
private final static long TIMEOUT = SECONDS.toMillis(60);
|
||||
|
||||
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:1.9.4:ant-1.9.4.jar:649ae0730251de07b8913f49286d46bba7b92d47c5f332610aa426c4f02161d8',
|
||||
'org.beanshell:bsh:1.3.0:bsh-1.3.0.jar:9b04edc75d19db54f1b4e8b5355e9364384c6cf71eb0a1b9724c159d779879f8',
|
||||
'org.briarproject:obfs4proxy:0.0.7:obfs4proxy-0.0.7.zip:5b2f693262ce43a7e130f7cc7d5d1617925330640a2eb6d71085e95df8ee0642',
|
||||
'org.briarproject:tor:0.3.5.12:tor-0.3.5.12.zip:2f542c4befd216f2226bf7c76e3b8b2d99af6f146a8cb28bf727f42014587006',
|
||||
'org.briarproject:obfs4proxy:0.0.12-dev-40245c4a:obfs4proxy-0.0.12-dev-40245c4a.zip:172029e7058b3a83ac93ac4991a44bf76e16ce8d46f558f5836d57da3cb3a766',
|
||||
'org.briarproject:tor:0.3.5.13:tor-0.3.5.13.zip:1c5f0b821ee2aadb0ea04aa96caab3ca0a08370cce8de81c2dfe04d172f8a2a0',
|
||||
'org.checkerframework:checker-compat-qual:2.5.3:checker-compat-qual-2.5.3.jar:d76b9afea61c7c082908023f0cbc1427fab9abd2df915c8b8a3e7a509bccbc6d',
|
||||
'org.checkerframework:checker-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',
|
||||
|
||||
1
briar-android/artwork/notification_signout.svg
Normal file
1
briar-android/artwork/notification_signout.svg
Normal file
@@ -0,0 +1 @@
|
||||
<?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>
|
||||
|
After Width: | Height: | Size: 423 B |
@@ -22,9 +22,11 @@ android {
|
||||
defaultConfig {
|
||||
minSdkVersion 16
|
||||
targetSdkVersion 29
|
||||
versionCode 10213
|
||||
versionName "1.2.13"
|
||||
applicationId "org.briarproject.briar.android"
|
||||
versionCode 10216
|
||||
versionName "1.2.16"
|
||||
applicationId "org.briarproject.briar.socialbackup"
|
||||
|
||||
vectorDrawables.useSupportLibrary = true
|
||||
buildConfigField "String", "GitHash",
|
||||
"\"${getStdout(['git', 'rev-parse', '--short=7', 'HEAD'], 'No commit hash')}\""
|
||||
def now = (long) (System.currentTimeMillis() / 1000)
|
||||
@@ -99,6 +101,7 @@ dependencies {
|
||||
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
|
||||
implementation 'com.google.android.material:material:1.2.1'
|
||||
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.trustedintents:trustedintents:0.2'
|
||||
@@ -134,6 +137,7 @@ dependencies {
|
||||
testImplementation "org.jmock:jmock:$jmockVersion"
|
||||
testImplementation "org.jmock:jmock-junit4:$jmockVersion"
|
||||
testImplementation "org.jmock:jmock-legacy:$jmockVersion"
|
||||
testAnnotationProcessor "com.google.dagger:dagger-compiler:2.24"
|
||||
|
||||
androidTestImplementation project(path: ':bramble-api', configuration: 'testOutput')
|
||||
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
|
||||
|
||||
@@ -40,3 +40,5 @@
|
||||
|
||||
# Dependency injection annotations, needed for UI tests on older API levels
|
||||
-keep class javax.inject.**
|
||||
|
||||
-keep class com.sun.jna.** { *; }
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<string name="app_name" translatable="false">Briar Debug</string>
|
||||
<string name="app_package" translatable="false">org.briarproject.briar.android.debug</string>
|
||||
<string name="app_name" translatable="false">Briar SB Debug</string>
|
||||
<string name="app_package" translatable="false">org.briarproject.briar.socialbackup.debug</string>
|
||||
</resources>
|
||||
|
||||
@@ -134,6 +134,42 @@
|
||||
</intent-filter>
|
||||
</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.RecoverActivity"
|
||||
android:label="@string/activity_name_recovery"
|
||||
android:parentActivityName="org.briarproject.briar.android.account.NewOrRecoverActivity">
|
||||
<meta-data
|
||||
android:name="android.support.PARENT_ACTIVITY"
|
||||
android:value="org.briarproject.briar.android.account.NewOrRecoverActivity" />
|
||||
</activity>
|
||||
|
||||
<activity
|
||||
android:name="org.briarproject.briar.android.socialbackup.CustodianHelpRecoverActivity"
|
||||
android:label="@string/activity_name_custodian_help_recovery"
|
||||
android:parentActivityName="org.briarproject.briar.android.conversation.ConversationActivity">
|
||||
<meta-data
|
||||
android:name="android.support.PARENT_ACTIVITY"
|
||||
android:value="org.briarproject.briar.android.conversation.ConversationActivity" />
|
||||
</activity>
|
||||
|
||||
<activity
|
||||
android:name="org.briarproject.briar.android.conversation.ConversationActivity"
|
||||
android:label="@string/app_name"
|
||||
|
||||
@@ -13,6 +13,7 @@ import org.briarproject.bramble.api.contact.ContactExchangeManager;
|
||||
import org.briarproject.bramble.api.contact.ContactManager;
|
||||
import org.briarproject.bramble.api.crypto.CryptoExecutor;
|
||||
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.TransactionManager;
|
||||
import org.briarproject.bramble.api.event.EventBus;
|
||||
@@ -34,6 +35,7 @@ import org.briarproject.briar.BriarCoreModule;
|
||||
import org.briarproject.briar.android.attachment.AttachmentModule;
|
||||
import org.briarproject.briar.android.attachment.media.MediaModule;
|
||||
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.view.EmojiTextInputView;
|
||||
import org.briarproject.briar.api.android.AndroidNotificationManager;
|
||||
@@ -58,7 +60,9 @@ import org.briarproject.briar.api.privategroup.PrivateGroupFactory;
|
||||
import org.briarproject.briar.api.privategroup.PrivateGroupManager;
|
||||
import org.briarproject.briar.api.privategroup.invitation.GroupInvitationFactory;
|
||||
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.socialbackup.SocialBackupManagerImpl_Factory;
|
||||
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
@@ -179,6 +183,14 @@ public interface AndroidComponent
|
||||
|
||||
AndroidWakeLockManager wakeLockManager();
|
||||
|
||||
CachingLogHandler logHandler();
|
||||
|
||||
Thread.UncaughtExceptionHandler exceptionHandler();
|
||||
|
||||
SocialBackupManager socialBackupManager();
|
||||
|
||||
DatabaseComponent databaseComponent();
|
||||
|
||||
void inject(SignInReminderReceiver briarService);
|
||||
|
||||
void inject(BriarService briarService);
|
||||
|
||||
@@ -255,7 +255,7 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager,
|
||||
R.string.ongoing_notification_title;
|
||||
int text = locked ? R.string.lock_tap_to_unlock :
|
||||
R.string.ongoing_notification_text;
|
||||
int icon = locked ? R.drawable.startup_lock :
|
||||
int icon = locked ? R.drawable.notification_lock :
|
||||
R.drawable.notification_ongoing;
|
||||
// Ongoing foreground notification that shows BriarService is running
|
||||
NotificationCompat.Builder b =
|
||||
@@ -624,7 +624,7 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager,
|
||||
|
||||
NotificationCompat.Builder b =
|
||||
new NotificationCompat.Builder(appContext, REMINDER_CHANNEL_ID);
|
||||
b.setSmallIcon(R.drawable.ic_signout);
|
||||
b.setSmallIcon(R.drawable.notification_signout);
|
||||
b.setColor(getColor(appContext, R.color.briar_primary));
|
||||
b.setContentTitle(
|
||||
appContext.getText(R.string.reminder_notification_title));
|
||||
|
||||
@@ -33,12 +33,13 @@ import org.briarproject.briar.android.account.SetupModule;
|
||||
import org.briarproject.briar.android.contact.ContactListModule;
|
||||
import org.briarproject.briar.android.forum.ForumModule;
|
||||
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.navdrawer.NavDrawerModule;
|
||||
import org.briarproject.briar.android.privategroup.conversation.GroupConversationModule;
|
||||
import org.briarproject.briar.android.settings.SettingsModule;
|
||||
import org.briarproject.briar.android.privategroup.list.GroupListModule;
|
||||
import org.briarproject.briar.android.reporting.DevReportModule;
|
||||
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.viewmodel.ViewModelModule;
|
||||
@@ -47,6 +48,7 @@ import org.briarproject.briar.api.android.DozeWatchdog;
|
||||
import org.briarproject.briar.api.android.LockManager;
|
||||
import org.briarproject.briar.api.android.ScreenFilterMonitor;
|
||||
import org.briarproject.briar.api.test.TestAvatarCreator;
|
||||
import org.briarproject.briar.socialbackup.AndroidDarkCrystalModule;
|
||||
|
||||
import java.io.File;
|
||||
import java.security.GeneralSecurityException;
|
||||
@@ -74,12 +76,14 @@ import static org.briarproject.briar.android.TestingConstants.IS_DEBUG_BUILD;
|
||||
SetupModule.class,
|
||||
DozeHelperModule.class,
|
||||
ContactExchangeModule.class,
|
||||
LoggingModule.class,
|
||||
LoginModule.class,
|
||||
NavDrawerModule.class,
|
||||
ViewModelModule.class,
|
||||
SettingsModule.class,
|
||||
DevReportModule.class,
|
||||
ContactListModule.class,
|
||||
AndroidDarkCrystalModule.class,
|
||||
// below need to be within same scope as ViewModelProvider.Factory
|
||||
ForumModule.class,
|
||||
GroupListModule.class,
|
||||
@@ -192,6 +196,11 @@ public class AppModule {
|
||||
public File getReportDir() {
|
||||
return AndroidUtils.getReportDir(app.getApplicationContext());
|
||||
}
|
||||
|
||||
@Override
|
||||
public File getLogcatFile() {
|
||||
return AndroidUtils.getLogcatFile(app.getApplicationContext());
|
||||
}
|
||||
};
|
||||
return devConfig;
|
||||
}
|
||||
|
||||
@@ -6,9 +6,6 @@ import android.content.SharedPreferences;
|
||||
import org.briarproject.bramble.BrambleApplication;
|
||||
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
|
||||
* directly to the Briar application object.
|
||||
@@ -17,8 +14,6 @@ public interface BriarApplication extends BrambleApplication {
|
||||
|
||||
Class<? extends Activity> ENTRY_ACTIVITY = NavDrawerActivity.class;
|
||||
|
||||
Collection<LogRecord> getRecentLogRecords();
|
||||
|
||||
AndroidComponent getApplicationComponent();
|
||||
|
||||
SharedPreferences getDefaultSharedPreferences();
|
||||
|
||||
@@ -20,12 +20,10 @@ import org.briarproject.bramble.BrambleCoreEagerSingletons;
|
||||
import org.briarproject.briar.BriarCoreEagerSingletons;
|
||||
import org.briarproject.briar.R;
|
||||
import org.briarproject.briar.android.logging.CachingLogHandler;
|
||||
import org.briarproject.briar.android.reporting.BriarExceptionHandler;
|
||||
import org.briarproject.briar.android.util.UiUtils;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.lang.Thread.UncaughtExceptionHandler;
|
||||
import java.util.logging.Handler;
|
||||
import java.util.logging.LogRecord;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
@@ -42,22 +40,18 @@ public class BriarApplicationImpl extends Application
|
||||
private static final Logger LOG =
|
||||
getLogger(BriarApplicationImpl.class.getName());
|
||||
|
||||
private final CachingLogHandler logHandler = new CachingLogHandler();
|
||||
private final BriarExceptionHandler exceptionHandler =
|
||||
new BriarExceptionHandler(this);
|
||||
|
||||
private AndroidComponent applicationComponent;
|
||||
private volatile SharedPreferences prefs;
|
||||
|
||||
@Override
|
||||
protected void attachBaseContext(Context base) {
|
||||
Thread.setDefaultUncaughtExceptionHandler(exceptionHandler);
|
||||
if (prefs == null)
|
||||
prefs = PreferenceManager.getDefaultSharedPreferences(base);
|
||||
// Loading the language needs to be done here.
|
||||
Localizer.initialize(prefs);
|
||||
super.attachBaseContext(
|
||||
Localizer.getInstance().setLocale(base));
|
||||
Localizer.getInstance().setLocale(this);
|
||||
setTheme(base, prefs);
|
||||
}
|
||||
|
||||
@@ -67,6 +61,11 @@ public class BriarApplicationImpl extends Application
|
||||
|
||||
if (IS_DEBUG_BUILD) enableStrictMode();
|
||||
|
||||
applicationComponent = createApplicationComponent();
|
||||
UncaughtExceptionHandler exceptionHandler =
|
||||
applicationComponent.exceptionHandler();
|
||||
Thread.setDefaultUncaughtExceptionHandler(exceptionHandler);
|
||||
|
||||
Logger rootLogger = getLogger("");
|
||||
Handler[] handlers = rootLogger.getHandlers();
|
||||
// Disable the Android logger for release builds
|
||||
@@ -78,12 +77,12 @@ public class BriarApplicationImpl extends Application
|
||||
// Restore the default handlers after the level raising handler
|
||||
for (Handler handler : handlers) rootLogger.addHandler(handler);
|
||||
}
|
||||
CachingLogHandler logHandler = applicationComponent.logHandler();
|
||||
rootLogger.addHandler(logHandler);
|
||||
rootLogger.setLevel(IS_DEBUG_BUILD ? FINE : INFO);
|
||||
|
||||
LOG.info("Created");
|
||||
|
||||
applicationComponent = createApplicationComponent();
|
||||
EmojiManager.install(new GoogleEmojiProvider());
|
||||
}
|
||||
|
||||
@@ -136,11 +135,6 @@ public class BriarApplicationImpl extends Application
|
||||
return applicationComponent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<LogRecord> getRecentLogRecords() {
|
||||
return logHandler.getRecentLogRecords();
|
||||
}
|
||||
|
||||
@Override
|
||||
public AndroidComponent getApplicationComponent() {
|
||||
return applicationComponent;
|
||||
|
||||
@@ -37,7 +37,7 @@ import javax.inject.Inject;
|
||||
import androidx.core.app.NotificationCompat;
|
||||
|
||||
import static android.app.NotificationManager.IMPORTANCE_DEFAULT;
|
||||
import static android.app.NotificationManager.IMPORTANCE_NONE;
|
||||
import static android.app.NotificationManager.IMPORTANCE_LOW;
|
||||
import static android.app.PendingIntent.FLAG_UPDATE_CURRENT;
|
||||
import static android.content.Intent.ACTION_SHUTDOWN;
|
||||
import static android.content.Intent.FLAG_ACTIVITY_CLEAR_TASK;
|
||||
@@ -46,6 +46,7 @@ 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_NO_ANIMATION;
|
||||
import static android.os.Build.VERSION.SDK_INT;
|
||||
import static android.os.Process.myPid;
|
||||
import static androidx.core.app.NotificationCompat.VISIBILITY_SECRET;
|
||||
import static java.util.logging.Level.INFO;
|
||||
import static java.util.logging.Level.WARNING;
|
||||
@@ -56,8 +57,10 @@ 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_NOTIFICATION_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.LockManager.ACTION_LOCK;
|
||||
import static org.briarproject.briar.api.android.LockManager.EXTRA_PID;
|
||||
|
||||
public class BriarService extends Service {
|
||||
|
||||
@@ -120,11 +123,17 @@ public class BriarService extends Service {
|
||||
if (SDK_INT >= 26) {
|
||||
NotificationManager nm = (NotificationManager)
|
||||
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(
|
||||
ONGOING_CHANNEL_ID,
|
||||
getString(R.string.ongoing_notification_title),
|
||||
IMPORTANCE_NONE);
|
||||
IMPORTANCE_LOW);
|
||||
ongoingChannel.setLockscreenVisibility(VISIBILITY_SECRET);
|
||||
ongoingChannel.setShowBadge(false);
|
||||
nm.createNotificationChannel(ongoingChannel);
|
||||
NotificationChannel failureChannel = new NotificationChannel(
|
||||
FAILURE_CHANNEL_ID,
|
||||
@@ -170,6 +179,7 @@ public class BriarService extends Service {
|
||||
@Override
|
||||
protected void attachBaseContext(Context base) {
|
||||
super.attachBaseContext(Localizer.getInstance().setLocale(base));
|
||||
Localizer.getInstance().setLocale(this);
|
||||
}
|
||||
|
||||
private void showStartupFailureNotification(StartResult result) {
|
||||
@@ -202,7 +212,12 @@ public class BriarService extends Service {
|
||||
@Override
|
||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||
if (ACTION_LOCK.equals(intent.getAction())) {
|
||||
lockManager.setLocked(true);
|
||||
int pid = intent.getIntExtra(EXTRA_PID, -1);
|
||||
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
|
||||
}
|
||||
|
||||
@@ -68,7 +68,21 @@ public class Localizer {
|
||||
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) {
|
||||
Resources res = context.getResources();
|
||||
Configuration conf = res.getConfiguration();
|
||||
@@ -82,7 +96,7 @@ public class Localizer {
|
||||
Locale.setDefault(locale);
|
||||
if (SDK_INT >= 17) {
|
||||
conf.setLocale(locale);
|
||||
context.createConfigurationContext(conf);
|
||||
context = context.createConfigurationContext(conf);
|
||||
} else
|
||||
conf.locale = locale;
|
||||
//noinspection deprecation
|
||||
|
||||
@@ -32,8 +32,10 @@ import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
|
||||
import static android.app.AlarmManager.ELAPSED_REALTIME;
|
||||
import static android.app.PendingIntent.FLAG_UPDATE_CURRENT;
|
||||
import static android.app.PendingIntent.getService;
|
||||
import static android.content.Context.ALARM_SERVICE;
|
||||
import static android.os.Process.myPid;
|
||||
import static android.os.SystemClock.elapsedRealtime;
|
||||
import static java.util.concurrent.TimeUnit.MINUTES;
|
||||
import static java.util.logging.Level.WARNING;
|
||||
@@ -75,23 +77,25 @@ public class LockManagerImpl implements LockManager, Service, EventListener {
|
||||
LockManagerImpl(Application app, SettingsManager settingsManager,
|
||||
AndroidNotificationManager notificationManager,
|
||||
@DatabaseExecutor Executor dbExecutor) {
|
||||
this.appContext = app.getApplicationContext();
|
||||
appContext = app.getApplicationContext();
|
||||
this.settingsManager = settingsManager;
|
||||
this.notificationManager = notificationManager;
|
||||
this.dbExecutor = dbExecutor;
|
||||
this.alarmManager =
|
||||
alarmManager =
|
||||
(AlarmManager) appContext.getSystemService(ALARM_SERVICE);
|
||||
Intent i =
|
||||
new Intent(ACTION_LOCK, null, appContext, BriarService.class);
|
||||
this.lockIntent = getService(appContext, 0, i, 0);
|
||||
this.timeoutNever = Integer.valueOf(
|
||||
i.putExtra(EXTRA_PID, myPid());
|
||||
// When not using FLAG_UPDATE_CURRENT, the intent might have no extras
|
||||
lockIntent = getService(appContext, 0, i, FLAG_UPDATE_CURRENT);
|
||||
timeoutNever = Integer.parseInt(
|
||||
appContext.getString(R.string.pref_lock_timeout_value_never));
|
||||
this.timeoutDefault = Integer.valueOf(
|
||||
timeoutDefault = Integer.parseInt(
|
||||
appContext.getString(R.string.pref_lock_timeout_value_default));
|
||||
this.timeoutMinutes = timeoutNever;
|
||||
timeoutMinutes = timeoutNever;
|
||||
|
||||
// setting this in the constructor makes #getValue() @NonNull
|
||||
this.lockable.setValue(false);
|
||||
lockable.setValue(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -148,7 +152,7 @@ public class LockManagerImpl implements LockManager, Service, EventListener {
|
||||
boolean oldValue = lockable.getValue();
|
||||
boolean newValue = hasScreenLock(appContext) && lockableSetting;
|
||||
if (oldValue != newValue) {
|
||||
this.lockable.setValue(newValue);
|
||||
lockable.setValue(newValue);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
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 org.briarproject.briar.android.socialbackup.RecoverActivity;
|
||||
|
||||
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,
|
||||
RecoverAccountListener {
|
||||
|
||||
@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 recoverAccountChosen() {
|
||||
finish();
|
||||
Intent i = new Intent(this, RecoverActivity.class);
|
||||
i.addFlags(FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_CLEAR_TOP |
|
||||
FLAG_ACTIVITY_CLEAR_TASK | FLAG_ACTIVITY_TASK_ON_HOME);
|
||||
startActivity(i);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public void runOnDbThread(Runnable runnable) {
|
||||
throw new RuntimeException("Don't use this deprecated method here.");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
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 setupNewAccountListener;
|
||||
protected RecoverAccountListener recoverAccountListener;
|
||||
|
||||
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 newAccountButton = view.findViewById(R.id.buttonSetupNewAccount);
|
||||
newAccountButton.setOnClickListener(e -> {
|
||||
setupNewAccountListener.setupNewAccountChosen();
|
||||
});
|
||||
|
||||
Button recoverAccountButton = view.findViewById(R.id.buttonRestoreAccount);
|
||||
recoverAccountButton.setOnClickListener(e -> {
|
||||
recoverAccountListener.recoverAccountChosen();
|
||||
});
|
||||
return view;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttach(Context context) {
|
||||
super.onAttach(context);
|
||||
setupNewAccountListener = (SetupNewAccountChosenListener) context;
|
||||
recoverAccountListener = (RecoverAccountListener) context;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUniqueTag() {
|
||||
return TAG;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void injectFragment(ActivityComponent component) {
|
||||
component.inject(this);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package org.briarproject.briar.android.account;
|
||||
|
||||
import androidx.annotation.UiThread;
|
||||
|
||||
public interface RecoverAccountListener {
|
||||
@UiThread
|
||||
void recoverAccountChosen();
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
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
|
||||
protected void onActivityResult(int requestCode, int resultCode,
|
||||
Intent data) {
|
||||
@Nullable Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
if (requestCode == REQUEST_KEYGUARD_UNLOCK) {
|
||||
if (resultCode == RESULT_OK) unlock();
|
||||
|
||||
@@ -2,10 +2,13 @@ package org.briarproject.briar.android.activity;
|
||||
|
||||
import android.app.Activity;
|
||||
|
||||
import org.briarproject.bramble.api.db.DatabaseComponent;
|
||||
import org.briarproject.briar.android.AndroidComponent;
|
||||
import org.briarproject.briar.android.StartupFailureActivity;
|
||||
import org.briarproject.briar.android.account.AuthorNameFragment;
|
||||
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.SetupActivity;
|
||||
import org.briarproject.briar.android.account.UnlockActivity;
|
||||
@@ -77,20 +80,32 @@ import org.briarproject.briar.android.sharing.ShareBlogFragment;
|
||||
import org.briarproject.briar.android.sharing.ShareForumActivity;
|
||||
import org.briarproject.briar.android.sharing.ShareForumFragment;
|
||||
import org.briarproject.briar.android.sharing.SharingModule;
|
||||
//import org.briarproject.briar.android.socialbackup.CustodianDisplayFragment;
|
||||
import org.briarproject.briar.android.socialbackup.CustodianHelpRecoverActivity;
|
||||
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.OwnerRecoveryModeExplainerFragment;
|
||||
import org.briarproject.briar.android.socialbackup.RecoverActivity;
|
||||
import org.briarproject.briar.android.socialbackup.ShardQrCodeFragment;
|
||||
import org.briarproject.briar.android.socialbackup.ShardsSentFragment;
|
||||
import org.briarproject.briar.android.socialbackup.ThresholdSelectorFragment;
|
||||
import org.briarproject.briar.android.socialbackup.creation.CreateBackupModule;
|
||||
import org.briarproject.briar.android.splash.SplashScreenActivity;
|
||||
import org.briarproject.briar.android.test.TestDataActivity;
|
||||
|
||||
import dagger.Component;
|
||||
|
||||
@ActivityScope
|
||||
@Component(modules = {
|
||||
@Component(modules ={
|
||||
ActivityModule.class,
|
||||
BlogModule.class,
|
||||
CreateGroupModule.class,
|
||||
GroupInvitationModule.class,
|
||||
GroupMemberModule.class,
|
||||
GroupRevealModule.class,
|
||||
SharingModule.SharingLegacyModule.class
|
||||
SharingModule.SharingLegacyModule.class,
|
||||
CreateBackupModule.class
|
||||
}, dependencies = AndroidComponent.class)
|
||||
public interface ActivityComponent {
|
||||
|
||||
@@ -182,6 +197,10 @@ public interface ActivityComponent {
|
||||
|
||||
void inject(CrashReportActivity crashReportActivity);
|
||||
|
||||
void inject(NewOrRecoverActivity newOrRecoverActivity);
|
||||
|
||||
void inject(CustodianHelpRecoverActivity custodianHelpRecoverActivity);
|
||||
|
||||
// Fragments
|
||||
|
||||
void inject(AuthorNameFragment fragment);
|
||||
@@ -238,4 +257,23 @@ public interface ActivityComponent {
|
||||
|
||||
void inject(ConfirmAvatarDialogFragment fragment);
|
||||
|
||||
void inject(ThresholdSelectorFragment thresholdSelectorFragment);
|
||||
|
||||
void inject(ShardQrCodeFragment shardQrCodeFragment);
|
||||
|
||||
void inject(DistributedBackupActivity distributedBackupActivity);
|
||||
|
||||
void inject(RecoverActivity recoverActivity);
|
||||
|
||||
void inject(DatabaseComponent databaseComponent);
|
||||
|
||||
void inject(CustodianSelectorFragment custodianSelectorFragment);
|
||||
|
||||
void inject(ShardsSentFragment shardsSentFragment);
|
||||
|
||||
void inject(OwnerRecoveryModeExplainerFragment ownerRecoveryModeExplainerFragment);
|
||||
|
||||
void inject(ExistingBackupFragment existingBackupFragment);
|
||||
|
||||
void inject(NewOrRecoverFragment newOrRecoverFragment);
|
||||
}
|
||||
|
||||
@@ -109,6 +109,7 @@ public abstract class BaseActivity extends AppCompatActivity
|
||||
protected void attachBaseContext(Context base) {
|
||||
super.attachBaseContext(
|
||||
Localizer.getInstance().setLocale(base));
|
||||
Localizer.getInstance().setLocale(this);
|
||||
}
|
||||
|
||||
public ActivityComponent getActivityComponent() {
|
||||
|
||||
@@ -124,7 +124,7 @@ public class AddContactViewModel extends DbViewModel {
|
||||
return addContactResult;
|
||||
}
|
||||
|
||||
public void updatePendingContact(String name, PendingContact p) {
|
||||
void updatePendingContact(String name, PendingContact p) {
|
||||
runOnDbThread(() -> {
|
||||
try {
|
||||
contactManager.removePendingContact(p.getId());
|
||||
|
||||
@@ -29,11 +29,11 @@ import org.briarproject.briar.android.fragment.BaseFragment;
|
||||
import javax.annotation.Nullable;
|
||||
import javax.inject.Inject;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.StringRes;
|
||||
import androidx.appcompat.app.AlertDialog.Builder;
|
||||
import androidx.lifecycle.LifecycleOwner;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
import androidx.lifecycle.ViewModelProviders;
|
||||
|
||||
import static android.view.View.INVISIBLE;
|
||||
import static android.view.View.VISIBLE;
|
||||
@@ -48,6 +48,7 @@ import static org.briarproject.briar.android.util.UiUtils.getDialogIcon;
|
||||
public class NicknameFragment extends BaseFragment {
|
||||
|
||||
private static final String TAG = NicknameFragment.class.getName();
|
||||
private static final String SAVED_LINK = "savedLink";
|
||||
|
||||
@Inject
|
||||
ViewModelProvider.Factory viewModelFactory;
|
||||
@@ -67,6 +68,20 @@ public class NicknameFragment extends BaseFragment {
|
||||
@Override
|
||||
public void injectFragment(ActivityComponent component) {
|
||||
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
|
||||
@@ -74,14 +89,9 @@ public class NicknameFragment extends BaseFragment {
|
||||
public View onCreateView(LayoutInflater inflater,
|
||||
@Nullable ViewGroup container,
|
||||
@Nullable Bundle savedInstanceState) {
|
||||
if (getActivity() == null || getContext() == null) return null;
|
||||
|
||||
View v = inflater.inflate(R.layout.fragment_nickname,
|
||||
container, false);
|
||||
|
||||
viewModel = ViewModelProviders.of(getActivity(), viewModelFactory)
|
||||
.get(AddContactViewModel.class);
|
||||
|
||||
contactNameLayout = v.findViewById(R.id.contactNameLayout);
|
||||
contactNameInput = v.findViewById(R.id.contactNameInput);
|
||||
|
||||
@@ -93,6 +103,12 @@ public class NicknameFragment extends BaseFragment {
|
||||
return v;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(@NonNull Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
outState.putString(SAVED_LINK, viewModel.getRemoteHandshakeLink());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private String getNicknameOrNull() {
|
||||
Editable text = contactNameInput.getText();
|
||||
|
||||
@@ -56,8 +56,11 @@ public abstract class BaseContactSelectorFragment<I extends SelectableContactIte
|
||||
|
||||
Bundle args = requireArguments();
|
||||
byte[] b = args.getByteArray(GROUP_ID);
|
||||
if (b == null) throw new IllegalStateException("No GroupId");
|
||||
groupId = new GroupId(b);
|
||||
// if (b == null) throw new IllegalStateException("No GroupId");
|
||||
// TODO find what the groupId should be when selecting custodians
|
||||
if (b != null) {
|
||||
groupId = new GroupId(b);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -18,7 +18,7 @@ public abstract class ContactSelectorFragment extends
|
||||
|
||||
public static final String TAG = ContactSelectorFragment.class.getName();
|
||||
|
||||
private Menu menu;
|
||||
protected Menu menu;
|
||||
|
||||
@Override
|
||||
protected ContactSelectorAdapter getAdapter(Context context,
|
||||
|
||||
@@ -3,6 +3,7 @@ package org.briarproject.briar.android.conversation;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Bundle;
|
||||
import android.os.Parcelable;
|
||||
import android.transition.Slide;
|
||||
@@ -51,6 +52,7 @@ import org.briarproject.briar.android.conversation.ConversationVisitor.TextCache
|
||||
import org.briarproject.briar.android.forum.ForumActivity;
|
||||
import org.briarproject.briar.android.introduction.IntroductionActivity;
|
||||
import org.briarproject.briar.android.privategroup.conversation.GroupActivity;
|
||||
import org.briarproject.briar.android.socialbackup.CustodianHelpRecoverActivity;
|
||||
import org.briarproject.briar.android.util.BriarSnackbarBuilder;
|
||||
import org.briarproject.briar.android.view.BriarRecyclerView;
|
||||
import org.briarproject.briar.android.view.ImagePreview;
|
||||
@@ -105,6 +107,7 @@ import androidx.recyclerview.selection.SelectionTracker.SelectionObserver;
|
||||
import androidx.recyclerview.selection.StorageStrategy;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import androidx.vectordrawable.graphics.drawable.VectorDrawableCompat;
|
||||
import de.hdodenhof.circleimageview.CircleImageView;
|
||||
import uk.co.samuelwall.materialtaptargetprompt.MaterialTapTargetPrompt;
|
||||
|
||||
@@ -394,6 +397,12 @@ public class ConversationActivity extends BriarActivity
|
||||
case R.id.action_social_remove_person:
|
||||
askToRemoveContact();
|
||||
return true;
|
||||
case R.id.action_help_recover_account:
|
||||
if (contactId == null) return false;
|
||||
Intent i = new Intent(this, CustodianHelpRecoverActivity.class);
|
||||
i.putExtra(CONTACT_ID, contactId.getInt());
|
||||
startActivity(i);
|
||||
return true;
|
||||
default:
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
@@ -479,12 +488,10 @@ public class ConversationActivity extends BriarActivity
|
||||
@UiThread
|
||||
private void displayContactOnlineStatus() {
|
||||
if (connectionRegistry.isConnected(contactId)) {
|
||||
toolbarStatus.setImageDrawable(ContextCompat.getDrawable(
|
||||
ConversationActivity.this, R.drawable.contact_online));
|
||||
toolbarStatus.setImageResource(R.drawable.contact_online);
|
||||
toolbarStatus.setContentDescription(getString(R.string.online));
|
||||
} else {
|
||||
toolbarStatus.setImageDrawable(ContextCompat.getDrawable(
|
||||
ConversationActivity.this, R.drawable.contact_offline));
|
||||
toolbarStatus.setImageResource(R.drawable.contact_offline);
|
||||
toolbarStatus.setContentDescription(getString(R.string.offline));
|
||||
}
|
||||
}
|
||||
@@ -935,13 +942,16 @@ public class ConversationActivity extends BriarActivity
|
||||
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,
|
||||
R.style.OnboardingDialogTheme).setTarget(target)
|
||||
.setPrimaryText(R.string.introduction_onboarding_title)
|
||||
.setSecondaryText(R.string.introduction_onboarding_text)
|
||||
.setIcon(R.drawable.ic_more_vert_accent)
|
||||
.setBackgroundColour(
|
||||
ContextCompat.getColor(this, R.color.briar_primary))
|
||||
.setIconDrawable(drawable)
|
||||
.setBackgroundColour(color)
|
||||
.show();
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ package org.briarproject.briar.android.conversation;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.briar.api.conversation.ConversationRequest;
|
||||
import org.briarproject.briar.api.conversation.ConversationResponse;
|
||||
import org.briarproject.briar.api.socialbackup.ShardMessageHeader;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import javax.annotation.concurrent.NotThreadSafe;
|
||||
@@ -30,6 +31,13 @@ class ConversationNoticeItem extends ConversationItem {
|
||||
this.msgText = null;
|
||||
}
|
||||
|
||||
ConversationNoticeItem(@LayoutRes int layoutRes, String text,
|
||||
ShardMessageHeader r) {
|
||||
super(layoutRes, r);
|
||||
this.text = text;
|
||||
this.msgText = null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
String getMsgText() {
|
||||
return msgText;
|
||||
|
||||
@@ -16,6 +16,7 @@ import org.briarproject.briar.api.introduction.IntroductionResponse;
|
||||
import org.briarproject.briar.api.messaging.PrivateMessageHeader;
|
||||
import org.briarproject.briar.api.privategroup.invitation.GroupInvitationRequest;
|
||||
import org.briarproject.briar.api.privategroup.invitation.GroupInvitationResponse;
|
||||
import org.briarproject.briar.api.socialbackup.ShardMessageHeader;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -292,6 +293,19 @@ class ConversationVisitor implements
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConversationItem visitShardMessage(ShardMessageHeader r) {
|
||||
if (r.isLocal()) {
|
||||
String text = ctx.getString(R.string.social_backup_shard_sent);
|
||||
return new ConversationNoticeItem(
|
||||
R.layout.list_item_conversation_notice_out, text, r);
|
||||
} else {
|
||||
String text = ctx.getString(R.string.social_backup_shard_received);
|
||||
return new ConversationNoticeItem(
|
||||
R.layout.list_item_conversation_notice_in, text, r);
|
||||
}
|
||||
}
|
||||
|
||||
interface TextCache {
|
||||
@Nullable
|
||||
String getText(MessageId m);
|
||||
|
||||
@@ -79,12 +79,6 @@ public class ForumActivity extends
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
viewModel.clearForumPostNotification();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int request, int result,
|
||||
@Nullable Intent data) {
|
||||
@@ -109,16 +103,16 @@ public class ForumActivity extends
|
||||
// Handle presses on the action bar items
|
||||
int itemId = item.getItemId();
|
||||
if (itemId == R.id.action_forum_share) {
|
||||
Intent i2 = new Intent(this, ShareForumActivity.class);
|
||||
i2.setFlags(FLAG_ACTIVITY_CLEAR_TOP);
|
||||
i2.putExtra(GROUP_ID, groupId.getBytes());
|
||||
startActivityForResult(i2, REQUEST_SHARE_FORUM);
|
||||
Intent i = new Intent(this, ShareForumActivity.class);
|
||||
i.setFlags(FLAG_ACTIVITY_CLEAR_TOP);
|
||||
i.putExtra(GROUP_ID, groupId.getBytes());
|
||||
startActivityForResult(i, REQUEST_SHARE_FORUM);
|
||||
return true;
|
||||
} else if (itemId == R.id.action_forum_sharing_status) {
|
||||
Intent i3 = new Intent(this, ForumSharingStatusActivity.class);
|
||||
i3.setFlags(FLAG_ACTIVITY_CLEAR_TOP);
|
||||
i3.putExtra(GROUP_ID, groupId.getBytes());
|
||||
startActivity(i3);
|
||||
Intent i = new Intent(this, ForumSharingStatusActivity.class);
|
||||
i.setFlags(FLAG_ACTIVITY_CLEAR_TOP);
|
||||
i.putExtra(GROUP_ID, groupId.getBytes());
|
||||
startActivity(i);
|
||||
return true;
|
||||
} else if (itemId == R.id.action_forum_delete) {
|
||||
showUnsubscribeDialog();
|
||||
|
||||
@@ -26,7 +26,6 @@ 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.client.PostHeader;
|
||||
import org.briarproject.briar.api.forum.Forum;
|
||||
import org.briarproject.briar.api.forum.ForumInvitationResponse;
|
||||
import org.briarproject.briar.api.forum.ForumManager;
|
||||
@@ -94,8 +93,9 @@ class ForumViewModel extends ThreadListViewModel<ForumPostItem> {
|
||||
ForumPostReceivedEvent f = (ForumPostReceivedEvent) e;
|
||||
if (f.getGroupId().equals(groupId)) {
|
||||
LOG.info("Forum post received, adding...");
|
||||
ForumPostItem item = buildItem(f.getHeader(), f.getText());
|
||||
addItem(item);
|
||||
ForumPostItem item =
|
||||
new ForumPostItem(f.getHeader(), f.getText());
|
||||
addItem(item, false);
|
||||
}
|
||||
} else if (e instanceof ForumInvitationResponseReceivedEvent) {
|
||||
ForumInvitationResponseReceivedEvent f =
|
||||
@@ -116,7 +116,7 @@ class ForumViewModel extends ThreadListViewModel<ForumPostItem> {
|
||||
}
|
||||
}
|
||||
|
||||
void clearForumPostNotification() {
|
||||
protected void clearNotifications() {
|
||||
notificationManager.clearForumPostNotification(groupId);
|
||||
}
|
||||
|
||||
@@ -140,10 +140,22 @@ class ForumViewModel extends ThreadListViewModel<ForumPostItem> {
|
||||
List<ForumPostHeader> headers =
|
||||
forumManager.getPostHeaders(txn, groupId);
|
||||
logDuration(LOG, "Loading headers", start);
|
||||
return createItems(txn, headers, this::buildItem);
|
||||
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) {
|
||||
@@ -171,26 +183,15 @@ class ForumViewModel extends ThreadListViewModel<ForumPostItem> {
|
||||
}
|
||||
|
||||
private void storePost(ForumPost msg, String text) {
|
||||
runOnDbThread(() -> {
|
||||
try {
|
||||
long start = now();
|
||||
ForumPostHeader header = forumManager.addLocalPost(msg);
|
||||
addItemAsync(buildItem(header, text));
|
||||
logDuration(LOG, "Storing forum post", start);
|
||||
} catch (DbException e) {
|
||||
logException(LOG, WARNING, e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private ForumPostItem buildItem(ForumPostHeader header, String text) {
|
||||
return new ForumPostItem(header, text);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String loadMessageText(Transaction txn, PostHeader header)
|
||||
throws DbException {
|
||||
return forumManager.getPostText(txn, header.getId());
|
||||
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
|
||||
@@ -205,18 +206,13 @@ class ForumViewModel extends ThreadListViewModel<ForumPostItem> {
|
||||
}
|
||||
|
||||
public void loadSharingContacts() {
|
||||
runOnDbThread(() -> {
|
||||
try {
|
||||
Collection<Contact> contacts =
|
||||
forumSharingManager.getSharedWith(groupId);
|
||||
Collection<ContactId> contactIds =
|
||||
new ArrayList<>(contacts.size());
|
||||
for (Contact c : contacts) contactIds.add(c.getId());
|
||||
sharingController.addAll(contactIds);
|
||||
} catch (DbException e) {
|
||||
logException(LOG, WARNING, e);
|
||||
}
|
||||
});
|
||||
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() {
|
||||
|
||||
@@ -2,7 +2,7 @@ package org.briarproject.briar.android.keyagreement;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
class CameraException extends IOException {
|
||||
public class CameraException extends IOException {
|
||||
|
||||
CameraException(String message) {
|
||||
super(message);
|
||||
|
||||
@@ -30,7 +30,7 @@ import static java.util.logging.Level.WARNING;
|
||||
@SuppressWarnings("deprecation")
|
||||
@MethodsNotNullByDefault
|
||||
@ParametersNotNullByDefault
|
||||
class QrCodeDecoder implements PreviewConsumer, PreviewCallback {
|
||||
public class QrCodeDecoder implements PreviewConsumer, PreviewCallback {
|
||||
|
||||
private static final Logger LOG =
|
||||
Logger.getLogger(QrCodeDecoder.class.getName());
|
||||
@@ -41,7 +41,7 @@ class QrCodeDecoder implements PreviewConsumer, PreviewCallback {
|
||||
private Camera camera = null;
|
||||
private int cameraIndex = 0;
|
||||
|
||||
QrCodeDecoder(ResultCallback callback) {
|
||||
public QrCodeDecoder(ResultCallback callback) {
|
||||
this.callback = callback;
|
||||
}
|
||||
|
||||
@@ -142,7 +142,7 @@ class QrCodeDecoder implements PreviewConsumer, PreviewCallback {
|
||||
}
|
||||
|
||||
@NotNullByDefault
|
||||
interface ResultCallback {
|
||||
public interface ResultCallback {
|
||||
|
||||
void handleResult(Result result);
|
||||
}
|
||||
|
||||
@@ -21,13 +21,13 @@ import static java.util.logging.Level.WARNING;
|
||||
import static org.briarproject.bramble.util.LogUtils.logException;
|
||||
|
||||
@NotNullByDefault
|
||||
class QrCodeUtils {
|
||||
public class QrCodeUtils {
|
||||
|
||||
private static final Logger LOG =
|
||||
Logger.getLogger(QrCodeUtils.class.getName());
|
||||
|
||||
@Nullable
|
||||
static Bitmap createQrCode(DisplayMetrics dm, String input) {
|
||||
public static Bitmap createQrCode(DisplayMetrics dm, String input) {
|
||||
int smallestDimen = Math.min(dm.widthPixels, dm.heightPixels);
|
||||
try {
|
||||
// Generate QR code
|
||||
|
||||
@@ -4,6 +4,7 @@ import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
import java.util.TimeZone;
|
||||
import java.util.logging.Formatter;
|
||||
@@ -17,6 +18,16 @@ import static java.util.Locale.US;
|
||||
@NotNullByDefault
|
||||
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 DateFormat dateFormat; // Locking: lock
|
||||
private final Date date; // Locking: lock
|
||||
|
||||
@@ -21,6 +21,10 @@ public class CachingLogHandler extends Handler {
|
||||
// Locking: lock
|
||||
private final Queue<LogRecord> recent = new LinkedList<>();
|
||||
|
||||
// package-private constructor
|
||||
CachingLogHandler() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void publish(LogRecord record) {
|
||||
synchronized (lock) {
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package org.briarproject.briar.android.logging;
|
||||
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.util.AndroidUtils;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
@NotNullByDefault
|
||||
public interface LogDecrypter {
|
||||
/**
|
||||
* Returns decrypted log records from {@link AndroidUtils#getLogcatFile}
|
||||
* or null if there was an error reading the logs.
|
||||
*/
|
||||
@Nullable
|
||||
String decryptLogs(@Nullable byte[] logKey);
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package org.briarproject.briar.android.logging;
|
||||
|
||||
import org.briarproject.bramble.api.crypto.SecretKey;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.reporting.DevConfig;
|
||||
import org.briarproject.bramble.api.transport.StreamReaderFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Scanner;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import static java.util.logging.Level.WARNING;
|
||||
import static java.util.logging.Logger.getLogger;
|
||||
import static org.briarproject.bramble.util.LogUtils.logException;
|
||||
|
||||
@NotNullByDefault
|
||||
class LogDecrypterImpl implements LogDecrypter {
|
||||
|
||||
private static final Logger LOG =
|
||||
getLogger(LogDecrypterImpl.class.getName());
|
||||
|
||||
private final DevConfig devConfig;
|
||||
private final StreamReaderFactory streamReaderFactory;
|
||||
|
||||
@Inject
|
||||
LogDecrypterImpl(DevConfig devConfig,
|
||||
StreamReaderFactory streamReaderFactory) {
|
||||
this.devConfig = devConfig;
|
||||
this.streamReaderFactory = streamReaderFactory;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String decryptLogs(@Nullable byte[] logKey) {
|
||||
if (logKey == null) return null;
|
||||
SecretKey key = new SecretKey(logKey);
|
||||
File logFile = devConfig.getLogcatFile();
|
||||
try (InputStream in = new FileInputStream(logFile)) {
|
||||
InputStream reader =
|
||||
streamReaderFactory.createLogStreamReader(in, key);
|
||||
Scanner s = new Scanner(reader);
|
||||
StringBuilder sb = new StringBuilder();
|
||||
while (s.hasNextLine()) sb.append(s.nextLine()).append("\n");
|
||||
s.close();
|
||||
return sb.toString();
|
||||
} catch (IOException e) {
|
||||
logException(LOG, WARNING, e);
|
||||
return null;
|
||||
} finally {
|
||||
//noinspection ResultOfMethodCallIgnored
|
||||
logFile.delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package org.briarproject.briar.android.logging;
|
||||
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.util.AndroidUtils;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
@NotNullByDefault
|
||||
public interface LogEncrypter {
|
||||
/**
|
||||
* Writes encrypted log records to {@link AndroidUtils#getLogcatFile}
|
||||
* and returns the encryption key if everything went fine.
|
||||
*/
|
||||
@Nullable
|
||||
byte[] encryptLogs();
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
package org.briarproject.briar.android.logging;
|
||||
|
||||
import org.briarproject.bramble.api.crypto.CryptoComponent;
|
||||
import org.briarproject.bramble.api.crypto.SecretKey;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.reporting.DevConfig;
|
||||
import org.briarproject.bramble.api.transport.StreamWriter;
|
||||
import org.briarproject.bramble.api.transport.StreamWriterFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.Writer;
|
||||
import java.util.logging.Formatter;
|
||||
import java.util.logging.LogRecord;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import static java.util.logging.Level.WARNING;
|
||||
import static java.util.logging.Logger.getLogger;
|
||||
import static org.briarproject.bramble.util.LogUtils.logException;
|
||||
|
||||
@NotNullByDefault
|
||||
class LogEncrypterImpl implements LogEncrypter {
|
||||
|
||||
private static final Logger LOG =
|
||||
getLogger(LogEncrypterImpl.class.getName());
|
||||
|
||||
private final DevConfig devConfig;
|
||||
private final CachingLogHandler logHandler;
|
||||
private final CryptoComponent crypto;
|
||||
private final StreamWriterFactory streamWriterFactory;
|
||||
|
||||
@Inject
|
||||
LogEncrypterImpl(DevConfig devConfig,
|
||||
CachingLogHandler logHandler,
|
||||
CryptoComponent crypto,
|
||||
StreamWriterFactory streamWriterFactory) {
|
||||
this.devConfig = devConfig;
|
||||
this.logHandler = logHandler;
|
||||
this.crypto = crypto;
|
||||
this.streamWriterFactory = streamWriterFactory;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public byte[] encryptLogs() {
|
||||
SecretKey logKey = crypto.generateSecretKey();
|
||||
File logFile = devConfig.getLogcatFile();
|
||||
try (OutputStream out = new FileOutputStream(logFile)) {
|
||||
StreamWriter streamWriter =
|
||||
streamWriterFactory.createLogStreamWriter(out, logKey);
|
||||
Writer writer =
|
||||
new OutputStreamWriter(streamWriter.getOutputStream());
|
||||
writeLogString(writer);
|
||||
writer.close();
|
||||
return logKey.getBytes();
|
||||
} catch (IOException e) {
|
||||
logException(LOG, WARNING, e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private void writeLogString(Writer writer) throws IOException {
|
||||
Formatter formatter = new BriefLogFormatter();
|
||||
for (LogRecord record : logHandler.getRecentLogRecords()) {
|
||||
String formatted = formatter.format(record);
|
||||
writer.append(formatted).append('\n');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package org.briarproject.briar.android.logging;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import dagger.Module;
|
||||
import dagger.Provides;
|
||||
|
||||
@Module
|
||||
public class LoggingModule {
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
CachingLogHandler provideCachingLogHandler() {
|
||||
return new CachingLogHandler();
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
LogEncrypter provideLogEncrypter(LogEncrypterImpl logEncrypter) {
|
||||
return logEncrypter;
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
LogDecrypter provideLogDecrypter(LogDecrypterImpl logDecrypter) {
|
||||
return logDecrypter;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,17 +1,13 @@
|
||||
package org.briarproject.briar.android.login;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.drawable.Drawable;
|
||||
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.briar.R;
|
||||
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
|
||||
import static androidx.core.content.ContextCompat.getColor;
|
||||
import static androidx.core.content.ContextCompat.getDrawable;
|
||||
import static androidx.core.graphics.drawable.DrawableCompat.setTint;
|
||||
import static java.util.Objects.requireNonNull;
|
||||
import static org.briarproject.briar.android.util.UiUtils.getDialogIcon;
|
||||
|
||||
@NotNullByDefault
|
||||
class LoginUtils {
|
||||
@@ -19,9 +15,7 @@ class LoginUtils {
|
||||
static AlertDialog createKeyStrengthenerErrorDialog(Context ctx) {
|
||||
AlertDialog.Builder builder =
|
||||
new AlertDialog.Builder(ctx, R.style.BriarDialogTheme);
|
||||
Drawable icon = getDrawable(ctx, R.drawable.alerts_and_states_error);
|
||||
setTint(requireNonNull(icon), getColor(ctx, R.color.color_primary));
|
||||
builder.setIcon(icon);
|
||||
builder.setIcon(getDialogIcon(ctx, R.drawable.alerts_and_states_error));
|
||||
builder.setTitle(R.string.dialog_title_cannot_check_password);
|
||||
builder.setMessage(R.string.dialog_message_cannot_check_password);
|
||||
builder.setPositiveButton(R.string.ok, null);
|
||||
|
||||
@@ -7,6 +7,7 @@ import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
|
||||
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
||||
import org.briarproject.briar.R;
|
||||
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.activity.ActivityComponent;
|
||||
import org.briarproject.briar.android.activity.BaseActivity;
|
||||
@@ -107,7 +108,7 @@ public class StartupActivity extends BaseActivity implements
|
||||
private void onAccountDeleted() {
|
||||
setResult(RESULT_CANCELED);
|
||||
finish();
|
||||
Intent i = new Intent(this, SetupActivity.class);
|
||||
Intent i = new Intent(this, NewOrRecoverActivity.class);
|
||||
i.addFlags(FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_CLEAR_TOP |
|
||||
FLAG_ACTIVITY_CLEAR_TASK | FLAG_ACTIVITY_TASK_ON_HOME);
|
||||
startActivity(i);
|
||||
|
||||
@@ -2,6 +2,7 @@ package org.briarproject.briar.android.navdrawer;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.content.res.Configuration;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
@@ -59,6 +60,7 @@ import androidx.fragment.app.FragmentTransaction;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
import androidx.lifecycle.ViewModelProviders;
|
||||
import androidx.vectordrawable.graphics.drawable.VectorDrawableCompat;
|
||||
import uk.co.samuelwall.materialtaptargetprompt.MaterialTapTargetPrompt;
|
||||
|
||||
import static android.view.View.GONE;
|
||||
@@ -66,6 +68,7 @@ import static android.view.View.VISIBLE;
|
||||
import static androidx.core.view.GravityCompat.START;
|
||||
import static androidx.drawerlayout.widget.DrawerLayout.LOCK_MODE_LOCKED_CLOSED;
|
||||
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.logging.Logger.getLogger;
|
||||
import static org.briarproject.bramble.api.lifecycle.LifecycleManager.LifecycleState.RUNNING;
|
||||
@@ -295,6 +298,12 @@ public class NavDrawerActivity extends BriarActivity implements
|
||||
finish();
|
||||
} else if (fm.getBackStackEntryCount() == 0
|
||||
&& 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
|
||||
* user sees is the same as the last fragment the user sees before
|
||||
@@ -433,8 +442,7 @@ public class NavDrawerActivity extends BriarActivity implements
|
||||
Transport t = getItem(position);
|
||||
|
||||
ImageView icon = view.findViewById(R.id.imageView);
|
||||
icon.setImageDrawable(ContextCompat.getDrawable(
|
||||
NavDrawerActivity.this, t.iconDrawable));
|
||||
icon.setImageResource(t.iconDrawable);
|
||||
icon.setColorFilter(ContextCompat.getColor(
|
||||
NavDrawerActivity.this, t.iconColor));
|
||||
|
||||
@@ -476,11 +484,13 @@ public class NavDrawerActivity extends BriarActivity implements
|
||||
private void showTransportsOnboarding(boolean show, ImageView imageView) {
|
||||
if (show) {
|
||||
int color = resolveColorAttribute(this, R.attr.colorControlNormal);
|
||||
Drawable drawable = VectorDrawableCompat
|
||||
.create(getResources(), R.drawable.transport_tor, null);
|
||||
new MaterialTapTargetPrompt.Builder(NavDrawerActivity.this,
|
||||
R.style.OnboardingDialogTheme).setTarget(imageView)
|
||||
.setPrimaryText(R.string.network_settings_title)
|
||||
.setSecondaryText(R.string.transports_onboarding_text)
|
||||
.setIcon(R.drawable.transport_tor)
|
||||
.setIconDrawable(drawable)
|
||||
.setIconDrawableColourFilter(color)
|
||||
.setBackgroundColour(
|
||||
ContextCompat.getColor(this, R.color.briar_primary))
|
||||
|
||||
@@ -141,8 +141,7 @@ public class TransportsActivity extends BriarActivity {
|
||||
Transport t = getItem(position);
|
||||
|
||||
ImageView icon = view.findViewById(R.id.icon);
|
||||
icon.setImageDrawable(ContextCompat.getDrawable(
|
||||
TransportsActivity.this, t.iconDrawable));
|
||||
icon.setImageResource(t.iconDrawable);
|
||||
icon.setColorFilter(ContextCompat.getColor(
|
||||
TransportsActivity.this, t.iconColor));
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@ import androidx.lifecycle.ViewModelProvider;
|
||||
|
||||
import static android.view.View.GONE;
|
||||
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.util.UiUtils.observeOnce;
|
||||
import static org.briarproject.briar.api.privategroup.PrivateGroupConstants.MAX_GROUP_POST_TEXT_LENGTH;
|
||||
@@ -80,16 +81,11 @@ public class GroupActivity extends
|
||||
setGroupEnabled(false);
|
||||
viewModel.isDissolved().observe(this, dissolved -> {
|
||||
setGroupEnabled(!dissolved);
|
||||
if (dissolved) onGroupDissolved();
|
||||
// only show dialog when no prior state
|
||||
if (dissolved && state == null) onGroupDissolved();
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
viewModel.clearGroupMessageNotifications();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
// Inflate the menu items for use in the action bar
|
||||
@@ -116,26 +112,26 @@ public class GroupActivity extends
|
||||
startActivity(i);
|
||||
return true;
|
||||
} else if (itemId == R.id.action_group_reveal) {
|
||||
if (viewModel.isCreator().getValue())
|
||||
if (requireNonNull(viewModel.isCreator().getValue()))
|
||||
throw new IllegalStateException();
|
||||
Intent i = new Intent(this, RevealContactsActivity.class);
|
||||
i.putExtra(GROUP_ID, groupId.getBytes());
|
||||
startActivity(i);
|
||||
return true;
|
||||
} else if (itemId == R.id.action_group_invite) {
|
||||
if (!viewModel.isCreator().getValue())
|
||||
if (!requireNonNull(viewModel.isCreator().getValue()))
|
||||
throw new IllegalStateException();
|
||||
Intent i = new Intent(this, GroupInviteActivity.class);
|
||||
i.putExtra(GROUP_ID, groupId.getBytes());
|
||||
startActivityForResult(i, REQUEST_GROUP_INVITE);
|
||||
return true;
|
||||
} else if (itemId == R.id.action_group_leave) {
|
||||
if (viewModel.isCreator().getValue())
|
||||
if (requireNonNull(viewModel.isCreator().getValue()))
|
||||
throw new IllegalStateException();
|
||||
showLeaveGroupDialog();
|
||||
return true;
|
||||
} else if (itemId == R.id.action_group_dissolve) {
|
||||
if (!viewModel.isCreator().getValue())
|
||||
if (!requireNonNull(viewModel.isCreator().getValue()))
|
||||
throw new IllegalStateException();
|
||||
showDissolveGroupDialog();
|
||||
return true;
|
||||
@@ -158,7 +154,8 @@ public class GroupActivity extends
|
||||
|
||||
@Override
|
||||
public void onReplyClick(GroupMessageItem item) {
|
||||
if (!viewModel.isDissolved().getValue()) super.onReplyClick(item);
|
||||
Boolean isDissolved = viewModel.isDissolved().getValue();
|
||||
if (isDissolved != null && !isDissolved) super.onReplyClick(item);
|
||||
}
|
||||
|
||||
private void setGroupEnabled(boolean enabled) {
|
||||
@@ -201,7 +198,7 @@ public class GroupActivity extends
|
||||
viewModel.deletePrivateGroup();
|
||||
}
|
||||
|
||||
public void onGroupDissolved() {
|
||||
private void onGroupDissolved() {
|
||||
AlertDialog.Builder builder =
|
||||
new AlertDialog.Builder(this, R.style.BriarDialogTheme);
|
||||
builder.setTitle(getString(R.string.groups_dissolved_dialog_title));
|
||||
|
||||
@@ -25,7 +25,6 @@ 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.client.PostHeader;
|
||||
import org.briarproject.briar.api.privategroup.GroupMember;
|
||||
import org.briarproject.briar.api.privategroup.GroupMessage;
|
||||
import org.briarproject.briar.api.privategroup.GroupMessageFactory;
|
||||
@@ -103,7 +102,10 @@ class GroupViewModel extends ThreadListViewModel<GroupMessageItem> {
|
||||
if (!g.isLocal() && g.getGroupId().equals(groupId)) {
|
||||
LOG.info("Group message received, adding...");
|
||||
GroupMessageItem item = buildItem(g.getHeader(), g.getText());
|
||||
addItem(item);
|
||||
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();
|
||||
@@ -133,12 +135,12 @@ class GroupViewModel extends ThreadListViewModel<GroupMessageItem> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setGroupId(GroupId groupId) {
|
||||
super.setGroupId(groupId);
|
||||
protected void performInitialLoad() {
|
||||
super.performInitialLoad();
|
||||
loadPrivateGroup(groupId);
|
||||
}
|
||||
|
||||
public void clearGroupMessageNotifications() {
|
||||
protected void clearNotifications() {
|
||||
notificationManager.clearGroupMessageNotification(groupId);
|
||||
}
|
||||
|
||||
@@ -166,10 +168,28 @@ class GroupViewModel extends ThreadListViewModel<GroupMessageItem> {
|
||||
List<GroupMessageHeader> headers =
|
||||
privateGroupManager.getHeaders(txn, groupId);
|
||||
logDuration(LOG, "Loading headers", start);
|
||||
return createItems(txn, headers, this::buildItem);
|
||||
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);
|
||||
@@ -177,16 +197,6 @@ class GroupViewModel extends ThreadListViewModel<GroupMessageItem> {
|
||||
return new GroupMessageItem(header, text);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String loadMessageText(
|
||||
Transaction txn, PostHeader header) throws DbException {
|
||||
if (header instanceof JoinMessageHeader) {
|
||||
// will be looked up later
|
||||
return "";
|
||||
}
|
||||
return privateGroupManager.getMessageText(txn, header.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createAndStoreMessage(String text,
|
||||
@Nullable MessageId parentId) {
|
||||
@@ -217,17 +227,15 @@ class GroupViewModel extends ThreadListViewModel<GroupMessageItem> {
|
||||
}
|
||||
|
||||
private void storePost(GroupMessage msg, String text) {
|
||||
runOnDbThread(() -> {
|
||||
try {
|
||||
long start = now();
|
||||
GroupMessageHeader header =
|
||||
privateGroupManager.addLocalMessage(msg);
|
||||
addItemAsync(buildItem(header, text));
|
||||
logDuration(LOG, "Storing group message", start);
|
||||
} catch (DbException e) {
|
||||
logException(LOG, WARNING, e);
|
||||
}
|
||||
});
|
||||
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
|
||||
@@ -242,20 +250,16 @@ class GroupViewModel extends ThreadListViewModel<GroupMessageItem> {
|
||||
}
|
||||
|
||||
public void loadSharingContacts() {
|
||||
runOnDbThread(() -> {
|
||||
try {
|
||||
Collection<GroupMember> members =
|
||||
privateGroupManager.getMembers(groupId);
|
||||
Collection<ContactId> contactIds = new ArrayList<>();
|
||||
for (GroupMember m : members) {
|
||||
if (m.getContactId() != null)
|
||||
contactIds.add(m.getContactId());
|
||||
}
|
||||
sharingController.addAll(contactIds);
|
||||
} catch (DbException e) {
|
||||
logException(LOG, WARNING, e);
|
||||
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() {
|
||||
|
||||
@@ -16,7 +16,7 @@ class JoinMessageItem extends GroupMessageItem {
|
||||
|
||||
JoinMessageItem(JoinMessageHeader h, String text) {
|
||||
super(h, text);
|
||||
this.isInitial = h.isInitial();
|
||||
isInitial = h.isInitial();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,29 +1,40 @@
|
||||
package org.briarproject.briar.android.reporting;
|
||||
|
||||
import android.content.Context;
|
||||
import android.app.Application;
|
||||
import android.os.Process;
|
||||
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.briar.android.logging.LogEncrypter;
|
||||
|
||||
import java.lang.Thread.UncaughtExceptionHandler;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import static org.briarproject.briar.android.util.UiUtils.startDevReportActivity;
|
||||
|
||||
@NotNullByDefault
|
||||
public class BriarExceptionHandler implements UncaughtExceptionHandler {
|
||||
class BriarExceptionHandler implements UncaughtExceptionHandler {
|
||||
|
||||
private final Context ctx;
|
||||
private final Application app;
|
||||
private final LogEncrypter logEncrypter;
|
||||
private final long appStartTime;
|
||||
|
||||
public BriarExceptionHandler(Context ctx) {
|
||||
this.ctx = ctx;
|
||||
this.appStartTime = System.currentTimeMillis();
|
||||
@Inject
|
||||
BriarExceptionHandler(Application app, LogEncrypter logEncrypter) {
|
||||
this.app = app;
|
||||
this.logEncrypter = logEncrypter;
|
||||
appStartTime = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
@Override
|
||||
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
|
||||
startDevReportActivity(ctx, CrashReportActivity.class, e, appStartTime);
|
||||
startDevReportActivity(app.getApplicationContext(),
|
||||
CrashReportActivity.class, e, appStartTime, logKey);
|
||||
Process.killProcess(Process.myPid());
|
||||
System.exit(10);
|
||||
}
|
||||
|
||||
@@ -25,8 +25,6 @@ import org.briarproject.bramble.api.Pair;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.briar.BuildConfig;
|
||||
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.ReportItem;
|
||||
import org.briarproject.briar.android.reporting.ReportData.SingleReportInfo;
|
||||
@@ -41,8 +39,6 @@ import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.logging.Formatter;
|
||||
import java.util.logging.LogRecord;
|
||||
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
|
||||
@@ -74,8 +70,8 @@ class BriarReportCollector {
|
||||
this.ctx = ctx;
|
||||
}
|
||||
|
||||
public ReportData collectReportData(@Nullable Throwable t,
|
||||
long appStartTime) {
|
||||
ReportData collectReportData(@Nullable Throwable t, long appStartTime,
|
||||
String logs) {
|
||||
ReportData reportData = new ReportData()
|
||||
.add(getBasicInfo(t))
|
||||
.add(getDeviceInfo());
|
||||
@@ -86,7 +82,7 @@ class BriarReportCollector {
|
||||
.add(getStorage())
|
||||
.add(getConnectivity())
|
||||
.add(getBuildConfig())
|
||||
.add(getLogcat())
|
||||
.add(getLogcat(logs))
|
||||
.add(getDeviceFeatures());
|
||||
}
|
||||
|
||||
@@ -313,15 +309,8 @@ class BriarReportCollector {
|
||||
buildConfig);
|
||||
}
|
||||
|
||||
private ReportItem getLogcat() {
|
||||
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 getLogcat(String logs) {
|
||||
return new ReportItem("Logcat", R.string.dev_report_logcat, logs);
|
||||
}
|
||||
|
||||
private ReportItem getDeviceFeatures() {
|
||||
|
||||
@@ -35,6 +35,7 @@ public class CrashReportActivity extends BaseActivity
|
||||
|
||||
public static final String EXTRA_THROWABLE = "throwable";
|
||||
public static final String EXTRA_APP_START_TIME = "appStartTime";
|
||||
public static final String EXTRA_APP_LOGCAT = "logcat";
|
||||
|
||||
@Inject
|
||||
ViewModelProvider.Factory viewModelFactory;
|
||||
@@ -56,7 +57,8 @@ public class CrashReportActivity extends BaseActivity
|
||||
Intent intent = getIntent();
|
||||
Throwable t = (Throwable) intent.getSerializableExtra(EXTRA_THROWABLE);
|
||||
long appStartTime = intent.getLongExtra(EXTRA_APP_START_TIME, -1);
|
||||
viewModel.init(t, appStartTime);
|
||||
byte[] logKey = intent.getByteArrayExtra(EXTRA_APP_LOGCAT);
|
||||
viewModel.init(t, appStartTime, logKey);
|
||||
viewModel.getShowReport().observeEvent(this, show -> {
|
||||
if (show) displayFragment(true);
|
||||
});
|
||||
|
||||
@@ -15,4 +15,8 @@ public abstract class DevReportModule {
|
||||
@ViewModelKey(ReportViewModel.class)
|
||||
abstract ViewModel bindReportViewModel(ReportViewModel reportViewModel);
|
||||
|
||||
@Binds
|
||||
abstract Thread.UncaughtExceptionHandler bindUncaughtExceptionHandler(
|
||||
BriarExceptionHandler handler);
|
||||
|
||||
}
|
||||
|
||||
@@ -11,6 +11,9 @@ import org.briarproject.bramble.api.plugin.TorConstants;
|
||||
import org.briarproject.bramble.api.reporting.DevReporter;
|
||||
import org.briarproject.bramble.util.AndroidUtils;
|
||||
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.viewmodel.LiveEvent;
|
||||
import org.briarproject.briar.android.viewmodel.MutableLiveEvent;
|
||||
@@ -19,6 +22,7 @@ import org.json.JSONException;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Formatter;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javax.inject.Inject;
|
||||
@@ -36,13 +40,16 @@ import static java.util.logging.Logger.getLogger;
|
||||
import static org.briarproject.bramble.api.plugin.Plugin.State.ACTIVE;
|
||||
import static org.briarproject.bramble.util.LogUtils.logException;
|
||||
import static org.briarproject.bramble.util.StringUtils.isNullOrEmpty;
|
||||
import static org.briarproject.briar.android.logging.BriefLogFormatter.formatLog;
|
||||
|
||||
@NotNullByDefault
|
||||
public class ReportViewModel extends AndroidViewModel {
|
||||
class ReportViewModel extends AndroidViewModel {
|
||||
|
||||
private static final Logger LOG =
|
||||
getLogger(ReportViewModel.class.getName());
|
||||
|
||||
private final CachingLogHandler logHandler;
|
||||
private final LogDecrypter logDecrypter;
|
||||
private final BriarReportCollector collector;
|
||||
private final DevReporter reporter;
|
||||
private final PluginManager pluginManager;
|
||||
@@ -58,18 +65,39 @@ public class ReportViewModel extends AndroidViewModel {
|
||||
private boolean isFeedback;
|
||||
|
||||
@Inject
|
||||
public ReportViewModel(@NonNull Application application,
|
||||
DevReporter reporter, PluginManager pluginManager) {
|
||||
ReportViewModel(@NonNull Application application,
|
||||
CachingLogHandler logHandler,
|
||||
LogDecrypter logDecrypter,
|
||||
DevReporter reporter,
|
||||
PluginManager pluginManager) {
|
||||
super(application);
|
||||
this.collector = new BriarReportCollector(application);
|
||||
collector = new BriarReportCollector(application);
|
||||
this.logHandler = logHandler;
|
||||
this.logDecrypter = logDecrypter;
|
||||
this.reporter = reporter;
|
||||
this.pluginManager = pluginManager;
|
||||
}
|
||||
|
||||
void init(@Nullable Throwable t, long appStartTime) {
|
||||
void init(@Nullable Throwable t, long appStartTime,
|
||||
@Nullable byte[] logKey) {
|
||||
isFeedback = t == null;
|
||||
if (reportData.getValue() == null) new SingleShotAndroidExecutor(() -> {
|
||||
ReportData data = collector.collectReportData(t, appStartTime);
|
||||
String decryptedLogs;
|
||||
if (isFeedback) {
|
||||
Formatter formatter = new BriefLogFormatter();
|
||||
decryptedLogs =
|
||||
formatLog(formatter, logHandler.getRecentLogRecords());
|
||||
} else {
|
||||
decryptedLogs = logDecrypter.decryptLogs(logKey);
|
||||
if (decryptedLogs == null) {
|
||||
// error decrypting logs, get logs from this process
|
||||
Formatter formatter = new BriefLogFormatter();
|
||||
decryptedLogs = formatLog(formatter,
|
||||
logHandler.getRecentLogRecords());
|
||||
}
|
||||
}
|
||||
ReportData data =
|
||||
collector.collectReportData(t, appStartTime, decryptedLogs);
|
||||
reportData.postValue(data);
|
||||
}).start();
|
||||
}
|
||||
@@ -110,8 +138,8 @@ public class ReportViewModel extends AndroidViewModel {
|
||||
}
|
||||
|
||||
/**
|
||||
* The content of the report
|
||||
* that will be loaded after {@link #init(Throwable, long)} was called.
|
||||
* The content of the report that will be loaded after
|
||||
* {@link #init(Throwable, long, byte[])} was called.
|
||||
*/
|
||||
LiveData<ReportData> getReportData() {
|
||||
return reportData;
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package org.briarproject.briar.android.sharing;
|
||||
|
||||
import org.briarproject.bramble.api.contact.ContactId;
|
||||
import org.briarproject.bramble.api.db.DatabaseExecutor;
|
||||
import org.briarproject.bramble.api.event.EventBus;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
|
||||
@@ -28,7 +27,7 @@ public interface SharingController {
|
||||
/**
|
||||
* Adds a collection of contacts to be tracked.
|
||||
*/
|
||||
@DatabaseExecutor
|
||||
@UiThread
|
||||
void addAll(Collection<ContactId> contacts);
|
||||
|
||||
/**
|
||||
|
||||
@@ -2,14 +2,12 @@ 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.db.DatabaseExecutor;
|
||||
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 org.briarproject.bramble.api.system.AndroidExecutor;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
@@ -26,7 +24,6 @@ public class SharingControllerImpl implements SharingController, EventListener {
|
||||
|
||||
private final EventBus eventBus;
|
||||
private final ConnectionRegistry connectionRegistry;
|
||||
private final AndroidExecutor executor;
|
||||
|
||||
// UI thread
|
||||
private final Set<ContactId> contacts = new HashSet<>();
|
||||
@@ -35,11 +32,9 @@ public class SharingControllerImpl implements SharingController, EventListener {
|
||||
|
||||
@Inject
|
||||
SharingControllerImpl(EventBus eventBus,
|
||||
ConnectionRegistry connectionRegistry,
|
||||
AndroidExecutor executor) {
|
||||
ConnectionRegistry connectionRegistry) {
|
||||
this.eventBus = eventBus;
|
||||
this.connectionRegistry = connectionRegistry;
|
||||
this.executor = executor;
|
||||
eventBus.addListener(this);
|
||||
}
|
||||
|
||||
@@ -78,13 +73,11 @@ public class SharingControllerImpl implements SharingController, EventListener {
|
||||
return online;
|
||||
}
|
||||
|
||||
@UiThread
|
||||
@Override
|
||||
@DatabaseExecutor
|
||||
public void addAll(Collection<ContactId> c) {
|
||||
executor.runOnUiThread(() -> {
|
||||
contacts.addAll(c);
|
||||
updateLiveData();
|
||||
});
|
||||
contacts.addAll(c);
|
||||
updateLiveData();
|
||||
}
|
||||
|
||||
@UiThread
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
package org.briarproject.briar.android.socialbackup;
|
||||
|
||||
import android.content.Intent;
|
||||
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.fragment.BaseFragment;
|
||||
import org.briarproject.briar.api.socialbackup.SocialBackupManager;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import static org.briarproject.briar.android.conversation.ConversationActivity.CONTACT_ID;
|
||||
|
||||
public class CustodianHelpRecoverActivity extends BriarActivity implements
|
||||
BaseFragment.BaseFragmentListener, CustodianScanQrButtonListener {
|
||||
@Override
|
||||
public void injectActivity(ActivityComponent component) {
|
||||
component.inject(this);
|
||||
}
|
||||
|
||||
@Inject
|
||||
public SocialBackupManager socialBackupManager;
|
||||
|
||||
@Inject
|
||||
public DatabaseComponent db;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_recover); // TODO change this
|
||||
|
||||
Intent intent = getIntent();
|
||||
int id = intent.getIntExtra(CONTACT_ID, -1);
|
||||
if (id == -1) throw new IllegalStateException("No ContactId");
|
||||
ContactId contactId = new ContactId(id);
|
||||
|
||||
// check if we have a shard for this secret owner
|
||||
try {
|
||||
db.transaction(false, txn -> {
|
||||
if (!socialBackupManager.amCustodian(txn, contactId)) {
|
||||
throw new DbException();
|
||||
}
|
||||
CustodianRecoveryModeExplainerFragment fragment =
|
||||
new CustodianRecoveryModeExplainerFragment();
|
||||
showInitialFragment(fragment);
|
||||
});
|
||||
} catch (DbException e) {
|
||||
// TODO improve this
|
||||
Toast.makeText(this,
|
||||
"You do not hold a backup shard from this contact",
|
||||
Toast.LENGTH_SHORT).show();
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void scanQrButtonClicked() {
|
||||
// TODO scan qr code
|
||||
finish();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
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.Button;
|
||||
|
||||
import org.briarproject.briar.android.fragment.BaseFragment;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import org.briarproject.briar.R;
|
||||
|
||||
public class CustodianRecoveryModeExplainerFragment extends BaseFragment {
|
||||
|
||||
protected CustodianScanQrButtonListener listener;
|
||||
|
||||
public static final String TAG = CustodianRecoveryModeExplainerFragment.class.getName();
|
||||
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
requireActivity().setTitle(R.string.title_help_recover);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable
|
||||
ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
View view = inflater.inflate(R.layout.fragment_recovery_custodian_explainer,
|
||||
container, false);
|
||||
|
||||
Button button = view.findViewById(R.id.button);
|
||||
button.setOnClickListener(e -> listener.scanQrButtonClicked());
|
||||
return view;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttach(Context context) {
|
||||
super.onAttach(context);
|
||||
listener = (CustodianScanQrButtonListener) context;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUniqueTag() {
|
||||
return TAG;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
package org.briarproject.briar.android.socialbackup;
|
||||
|
||||
import androidx.annotation.UiThread;
|
||||
|
||||
public interface CustodianScanQrButtonListener {
|
||||
@UiThread
|
||||
void scanQrButtonClicked();
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package org.briarproject.briar.android.socialbackup;
|
||||
import org.briarproject.bramble.api.crypto.SecretKey;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
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 javax.inject.Inject;
|
||||
|
||||
import dagger.Provides;
|
||||
|
||||
import static org.briarproject.briar.socialbackup.SocialBackupConstants.SECRET_ID_BYTES;
|
||||
|
||||
@NotNullByDefault
|
||||
public class DarkCrystalImpl implements DarkCrystal {
|
||||
|
||||
@Inject
|
||||
DarkCrystalImpl() {
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
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,
|
||||
ShardsSentFragment.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);
|
||||
|
||||
try {
|
||||
db.transaction(false, txn -> {
|
||||
BackupMetadata backupMetadata =
|
||||
socialBackupManager.getBackupMetadata(txn);
|
||||
if (backupMetadata == null) throw new DbException();
|
||||
ExistingBackupFragment fragment =
|
||||
ExistingBackupFragment.newInstance(backupMetadata);
|
||||
showInitialFragment(fragment);
|
||||
});
|
||||
} catch (DbException e) {
|
||||
CustodianSelectorFragment fragment =
|
||||
CustodianSelectorFragment.newInstance();
|
||||
showInitialFragment(fragment);
|
||||
}
|
||||
}
|
||||
|
||||
@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) {
|
||||
try {
|
||||
db.transaction(false, txn -> {
|
||||
socialBackupManager
|
||||
.createBackup(txn, (List<ContactId>) custodians,
|
||||
threshold);
|
||||
ShardsSentFragment fragment = new ShardsSentFragment();
|
||||
showNextFragment(fragment);
|
||||
});
|
||||
} catch (DbException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void shardsSentDismissed() {
|
||||
finish();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package org.briarproject.briar.android.socialbackup;
|
||||
|
||||
import androidx.annotation.UiThread;
|
||||
|
||||
public interface ExplainerDismissedListener {
|
||||
@UiThread
|
||||
void explainerDismissed();
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
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.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 OwnerRecoveryModeExplainerFragment extends BaseFragment {
|
||||
|
||||
protected ExplainerDismissedListener listener;
|
||||
public static final String TAG =
|
||||
OwnerRecoveryModeExplainerFragment.class.getName();
|
||||
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
requireActivity().setTitle(R.string.title_recovery_mode);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater,
|
||||
@Nullable ViewGroup container,
|
||||
@Nullable Bundle savedInstanceState) {
|
||||
View view = inflater.inflate(R.layout.fragment_recovery_owner_explainer,
|
||||
container, false);
|
||||
Button button = view.findViewById(R.id.beginButton);
|
||||
button.setOnClickListener(e -> listener.explainerDismissed());
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttach(Context context) {
|
||||
super.onAttach(context);
|
||||
listener = (ExplainerDismissedListener) context;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void injectFragment(ActivityComponent component) {
|
||||
component.inject(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUniqueTag() {
|
||||
return TAG;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
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.Button;
|
||||
import android.widget.TextView;
|
||||
|
||||
import org.briarproject.briar.R;
|
||||
import org.briarproject.briar.android.fragment.BaseFragment;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
public class OwnerRecoveryModeMainFragment extends BaseFragment {
|
||||
|
||||
protected ScanQrButtonListener listener;
|
||||
|
||||
public static final String NUM_RECOVERED = "num_recovered";
|
||||
|
||||
public static final String TAG =
|
||||
OwnerRecoveryModeMainFragment.class.getName();
|
||||
|
||||
public static OwnerRecoveryModeMainFragment newInstance(int numRecovered) {
|
||||
Bundle args = new Bundle();
|
||||
args.putInt(NUM_RECOVERED, numRecovered);
|
||||
OwnerRecoveryModeMainFragment fragment =
|
||||
new OwnerRecoveryModeMainFragment();
|
||||
fragment.setArguments(args);
|
||||
return fragment;
|
||||
}
|
||||
|
||||
private int numShards;
|
||||
|
||||
@Override
|
||||
public String getUniqueTag() {
|
||||
return TAG;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
requireActivity().setTitle(R.string.title_recovery_mode);
|
||||
|
||||
Bundle args = requireArguments();
|
||||
numShards = args.getInt(NUM_RECOVERED);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater,
|
||||
@Nullable ViewGroup container,
|
||||
@Nullable Bundle savedInstanceState) {
|
||||
View view = inflater.inflate(R.layout.fragment_recovery_owner_main,
|
||||
container, false);
|
||||
|
||||
TextView textViewCount = view.findViewById(R.id.textViewShardCount);
|
||||
textViewCount.setText(String.format("%d", numShards));
|
||||
|
||||
Button button = view.findViewById(R.id.button);
|
||||
button.setOnClickListener(e -> listener.scanQrButtonClicked());
|
||||
return view;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttach(Context context) {
|
||||
super.onAttach(context);
|
||||
listener = (ScanQrButtonListener) context;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,179 @@
|
||||
package org.briarproject.briar.android.socialbackup;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.widget.Toast;
|
||||
|
||||
import org.briarproject.bramble.api.keyagreement.KeyAgreementResult;
|
||||
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 javax.annotation.Nullable;
|
||||
|
||||
import androidx.annotation.UiThread;
|
||||
import androidx.core.app.ActivityCompat;
|
||||
|
||||
import static android.Manifest.permission.CAMERA;
|
||||
import static android.content.pm.PackageManager.PERMISSION_GRANTED;
|
||||
import static org.briarproject.briar.android.activity.RequestCodes.REQUEST_PERMISSION_CAMERA_LOCATION;
|
||||
|
||||
public class RecoverActivity extends BaseActivity implements
|
||||
BaseFragment.BaseFragmentListener, ExplainerDismissedListener,
|
||||
ScanQrButtonListener, ShardQrCodeFragment.ShardQrCodeEventListener {
|
||||
|
||||
@Override
|
||||
public void keyAgreementFailed() {
|
||||
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String keyAgreementWaiting() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String keyAgreementStarted() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyAgreementAborted(boolean remoteAborted) {
|
||||
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String keyAgreementFinished(KeyAgreementResult result) {
|
||||
return null;
|
||||
}
|
||||
|
||||
private enum Permission {
|
||||
UNKNOWN, GRANTED, SHOW_RATIONALE, PERMANENTLY_DENIED
|
||||
}
|
||||
|
||||
private Permission cameraPermission = Permission.UNKNOWN;
|
||||
|
||||
|
||||
private int numRecovered;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_recover);
|
||||
|
||||
numRecovered = 0; // TODO - retrieve this from somewhere
|
||||
|
||||
// only show the explainer if we have no shards
|
||||
if (numRecovered == 0) {
|
||||
OwnerRecoveryModeExplainerFragment fragment =
|
||||
new OwnerRecoveryModeExplainerFragment();
|
||||
showInitialFragment(fragment);
|
||||
} else {
|
||||
OwnerRecoveryModeMainFragment fragment =
|
||||
OwnerRecoveryModeMainFragment.newInstance(numRecovered);
|
||||
showInitialFragment(fragment);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void injectActivity(ActivityComponent component) {
|
||||
component.inject(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void explainerDismissed() {
|
||||
OwnerRecoveryModeMainFragment fragment =
|
||||
OwnerRecoveryModeMainFragment.newInstance(numRecovered);
|
||||
showNextFragment(fragment);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void scanQrButtonClicked() {
|
||||
if (checkPermissions()) showQrCodeFragment();
|
||||
}
|
||||
|
||||
|
||||
private void showQrCodeFragment() {
|
||||
ShardQrCodeFragment f = ShardQrCodeFragment.newInstance();
|
||||
showNextFragment(f);
|
||||
}
|
||||
|
||||
private void requestPermissions() {
|
||||
String[] permissions = new String[] {CAMERA};
|
||||
ActivityCompat.requestPermissions(this, permissions,
|
||||
REQUEST_PERMISSION_CAMERA_LOCATION);
|
||||
}
|
||||
|
||||
@Override
|
||||
@UiThread
|
||||
public void onRequestPermissionsResult(int requestCode,
|
||||
String[] permissions, int[] grantResults) {
|
||||
if (requestCode != REQUEST_PERMISSION_CAMERA_LOCATION)
|
||||
throw new AssertionError();
|
||||
if (gotPermission(CAMERA, permissions, grantResults)) {
|
||||
cameraPermission = Permission.GRANTED;
|
||||
} else if (shouldShowRationale(CAMERA)) {
|
||||
cameraPermission = Permission.SHOW_RATIONALE;
|
||||
} else {
|
||||
cameraPermission = Permission.PERMANENTLY_DENIED;
|
||||
}
|
||||
// If a permission dialog has been shown, showing the QR code fragment
|
||||
// on this call path would cause a crash due to
|
||||
// https://code.google.com/p/android/issues/detail?id=190966.
|
||||
// In that case the isResumed flag prevents the fragment from being
|
||||
// shown here, and showQrCodeFragmentIfAllowed() will be called again
|
||||
// from onPostResume().
|
||||
if (checkPermissions()) showQrCodeFragment();
|
||||
}
|
||||
|
||||
private boolean gotPermission(String permission, String[] permissions,
|
||||
int[] grantResults) {
|
||||
for (int i = 0; i < permissions.length; i++) {
|
||||
if (permission.equals(permissions[i]))
|
||||
return grantResults[i] == PERMISSION_GRANTED;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean shouldShowRationale(String permission) {
|
||||
return ActivityCompat.shouldShowRequestPermissionRationale(this,
|
||||
permission);
|
||||
}
|
||||
|
||||
private boolean checkPermissions() {
|
||||
if (areEssentialPermissionsGranted()) return true;
|
||||
// If an essential permission has been permanently denied, ask the
|
||||
// user to change the setting
|
||||
if (cameraPermission == Permission.PERMANENTLY_DENIED) {
|
||||
Toast.makeText(this,
|
||||
"camera permission is denied",
|
||||
Toast.LENGTH_SHORT).show();
|
||||
// showDenialDialog(R.string.permission_camera_title,
|
||||
// R.string.permission_camera_denied_body);
|
||||
return false;
|
||||
}
|
||||
if (cameraPermission == Permission.SHOW_RATIONALE) {
|
||||
// showRationale(R.string.permission_camera_title,
|
||||
// R.string.permission_camera_request_body);
|
||||
Toast.makeText(this,
|
||||
"camera permission - show rationale",
|
||||
Toast.LENGTH_SHORT).show();
|
||||
} else {
|
||||
requestPermissions();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public void runOnDbThread(Runnable runnable) {
|
||||
throw new RuntimeException("Don't use this deprecated method here.");
|
||||
}
|
||||
|
||||
private boolean areEssentialPermissionsGranted() {
|
||||
return cameraPermission == Permission.GRANTED;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package org.briarproject.briar.android.socialbackup;
|
||||
|
||||
import androidx.annotation.UiThread;
|
||||
|
||||
public interface ScanQrButtonListener {
|
||||
@UiThread
|
||||
void scanQrButtonClicked();
|
||||
}
|
||||
@@ -0,0 +1,381 @@
|
||||
package org.briarproject.briar.android.socialbackup;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.os.Bundle;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.google.zxing.Result;
|
||||
|
||||
import org.briarproject.bramble.api.UnsupportedVersionException;
|
||||
import org.briarproject.bramble.api.event.Event;
|
||||
import org.briarproject.bramble.api.event.EventBus;
|
||||
import org.briarproject.bramble.api.keyagreement.KeyAgreementResult;
|
||||
import org.briarproject.bramble.api.keyagreement.KeyAgreementTask;
|
||||
import org.briarproject.bramble.api.keyagreement.Payload;
|
||||
import org.briarproject.bramble.api.keyagreement.PayloadEncoder;
|
||||
import org.briarproject.bramble.api.keyagreement.PayloadParser;
|
||||
import org.briarproject.bramble.api.keyagreement.event.KeyAgreementAbortedEvent;
|
||||
import org.briarproject.bramble.api.keyagreement.event.KeyAgreementFailedEvent;
|
||||
import org.briarproject.bramble.api.keyagreement.event.KeyAgreementFinishedEvent;
|
||||
import org.briarproject.bramble.api.keyagreement.event.KeyAgreementListeningEvent;
|
||||
import org.briarproject.bramble.api.keyagreement.event.KeyAgreementStartedEvent;
|
||||
import org.briarproject.bramble.api.keyagreement.event.KeyAgreementWaitingEvent;
|
||||
import org.briarproject.bramble.api.lifecycle.IoExecutor;
|
||||
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
||||
import org.briarproject.briar.R;
|
||||
import org.briarproject.briar.android.activity.ActivityComponent;
|
||||
import org.briarproject.briar.android.fragment.BaseEventFragment;
|
||||
import org.briarproject.briar.android.keyagreement.CameraException;
|
||||
import org.briarproject.briar.android.keyagreement.CameraView;
|
||||
import org.briarproject.briar.android.keyagreement.ContactExchangeErrorFragment;
|
||||
import org.briarproject.briar.android.keyagreement.QrCodeDecoder;
|
||||
import org.briarproject.briar.android.keyagreement.QrCodeUtils;
|
||||
import org.briarproject.briar.android.view.QrCodeView;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Provider;
|
||||
|
||||
import androidx.annotation.UiThread;
|
||||
|
||||
import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_NOSENSOR;
|
||||
import static android.view.View.INVISIBLE;
|
||||
import static android.view.View.VISIBLE;
|
||||
import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
|
||||
import static android.widget.LinearLayout.HORIZONTAL;
|
||||
import static android.widget.Toast.LENGTH_LONG;
|
||||
import static java.util.logging.Level.INFO;
|
||||
import static java.util.logging.Level.WARNING;
|
||||
import static org.briarproject.bramble.util.LogUtils.logException;
|
||||
|
||||
@MethodsNotNullByDefault
|
||||
@ParametersNotNullByDefault
|
||||
public class ShardQrCodeFragment extends BaseEventFragment
|
||||
implements QrCodeDecoder.ResultCallback, QrCodeView.FullscreenListener {
|
||||
|
||||
static final String TAG = org.briarproject.briar.android.keyagreement.KeyAgreementFragment.class.getName();
|
||||
|
||||
private static final Logger LOG = Logger.getLogger(TAG);
|
||||
@SuppressWarnings("CharsetObjectCanBeUsed") // Requires minSdkVersion >= 19
|
||||
private static final Charset ISO_8859_1 = Charset.forName("ISO-8859-1");
|
||||
|
||||
@Inject
|
||||
Provider<KeyAgreementTask> keyAgreementTaskProvider;
|
||||
@Inject
|
||||
PayloadEncoder payloadEncoder;
|
||||
@Inject
|
||||
PayloadParser payloadParser;
|
||||
@Inject
|
||||
@IoExecutor
|
||||
Executor ioExecutor;
|
||||
@Inject
|
||||
EventBus eventBus;
|
||||
|
||||
private CameraView cameraView;
|
||||
private LinearLayout cameraOverlay;
|
||||
private View statusView;
|
||||
private QrCodeView qrCodeView;
|
||||
private TextView status;
|
||||
|
||||
private boolean gotRemotePayload;
|
||||
private volatile boolean gotLocalPayload;
|
||||
private KeyAgreementTask task;
|
||||
private ShardQrCodeEventListener
|
||||
listener;
|
||||
|
||||
public static ShardQrCodeFragment newInstance() {
|
||||
Bundle args = new Bundle();
|
||||
ShardQrCodeFragment
|
||||
fragment = new ShardQrCodeFragment();
|
||||
fragment.setArguments(args);
|
||||
return fragment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttach(Context context) {
|
||||
super.onAttach(context);
|
||||
listener = (ShardQrCodeEventListener) context;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void injectFragment(ActivityComponent component) {
|
||||
component.inject(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUniqueTag() {
|
||||
return TAG;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater,
|
||||
@Nullable ViewGroup container,
|
||||
@Nullable Bundle savedInstanceState) {
|
||||
return inflater.inflate(R.layout.fragment_keyagreement_qr, container,
|
||||
false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
cameraView = view.findViewById(R.id.camera_view);
|
||||
cameraOverlay = view.findViewById(R.id.camera_overlay);
|
||||
statusView = view.findViewById(R.id.status_container);
|
||||
status = view.findViewById(R.id.connect_status);
|
||||
qrCodeView = view.findViewById(R.id.qr_code_view);
|
||||
qrCodeView.setFullscreenListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
requireActivity().setRequestedOrientation(SCREEN_ORIENTATION_NOSENSOR);
|
||||
cameraView.setPreviewConsumer(new QrCodeDecoder(this));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
try {
|
||||
cameraView.start();
|
||||
} catch (CameraException e) {
|
||||
logCameraExceptionAndFinish(e);
|
||||
}
|
||||
startListening();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFullscreen(boolean fullscreen) {
|
||||
LinearLayout.LayoutParams statusParams, qrCodeParams;
|
||||
if (fullscreen) {
|
||||
// Grow the QR code view to fill its parent
|
||||
statusParams = new LinearLayout.LayoutParams(0, 0, 0f);
|
||||
qrCodeParams = new LinearLayout.LayoutParams(MATCH_PARENT, MATCH_PARENT, 1f);
|
||||
} else {
|
||||
// Shrink the QR code view to fill half its parent
|
||||
if (cameraOverlay.getOrientation() == HORIZONTAL) {
|
||||
statusParams = new LinearLayout.LayoutParams(0, MATCH_PARENT, 1f);
|
||||
qrCodeParams = new LinearLayout.LayoutParams(0, MATCH_PARENT, 1f);
|
||||
} else {
|
||||
statusParams = new LinearLayout.LayoutParams(MATCH_PARENT, 0, 1f);
|
||||
qrCodeParams = new LinearLayout.LayoutParams(MATCH_PARENT, 0, 1f);
|
||||
}
|
||||
}
|
||||
statusView.setLayoutParams(statusParams);
|
||||
qrCodeView.setLayoutParams(qrCodeParams);
|
||||
cameraOverlay.invalidate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop() {
|
||||
super.onStop();
|
||||
stopListening();
|
||||
try {
|
||||
cameraView.stop();
|
||||
} catch (CameraException e) {
|
||||
logCameraExceptionAndFinish(e);
|
||||
}
|
||||
}
|
||||
|
||||
@UiThread
|
||||
private void logCameraExceptionAndFinish(CameraException e) {
|
||||
logException(LOG, WARNING, e);
|
||||
Toast.makeText(getActivity(), R.string.camera_error,
|
||||
LENGTH_LONG).show();
|
||||
finish();
|
||||
}
|
||||
|
||||
@UiThread
|
||||
private void startListening() {
|
||||
KeyAgreementTask oldTask = task;
|
||||
KeyAgreementTask newTask = keyAgreementTaskProvider.get();
|
||||
task = newTask;
|
||||
ioExecutor.execute(() -> {
|
||||
if (oldTask != null) oldTask.stopListening();
|
||||
newTask.listen();
|
||||
});
|
||||
}
|
||||
|
||||
@UiThread
|
||||
private void stopListening() {
|
||||
KeyAgreementTask oldTask = task;
|
||||
ioExecutor.execute(() -> {
|
||||
if (oldTask != null) oldTask.stopListening();
|
||||
});
|
||||
}
|
||||
|
||||
@UiThread
|
||||
private void reset() {
|
||||
// If we've stopped the camera view, restart it
|
||||
if (gotRemotePayload) {
|
||||
try {
|
||||
cameraView.start();
|
||||
} catch (CameraException e) {
|
||||
logCameraExceptionAndFinish(e);
|
||||
return;
|
||||
}
|
||||
}
|
||||
statusView.setVisibility(INVISIBLE);
|
||||
cameraView.setVisibility(VISIBLE);
|
||||
gotRemotePayload = false;
|
||||
gotLocalPayload = false;
|
||||
startListening();
|
||||
}
|
||||
|
||||
@UiThread
|
||||
private void qrCodeScanned(String content) {
|
||||
try {
|
||||
byte[] payloadBytes = content.getBytes(ISO_8859_1);
|
||||
if (LOG.isLoggable(INFO))
|
||||
LOG.info("Remote payload is " + payloadBytes.length + " bytes");
|
||||
Payload remotePayload = payloadParser.parse(payloadBytes);
|
||||
gotRemotePayload = true;
|
||||
cameraView.stop();
|
||||
cameraView.setVisibility(INVISIBLE);
|
||||
statusView.setVisibility(VISIBLE);
|
||||
status.setText(R.string.connecting_to_device);
|
||||
task.connectAndRunProtocol(remotePayload);
|
||||
} catch (UnsupportedVersionException e) {
|
||||
reset();
|
||||
String msg;
|
||||
if (e.isTooOld()) {
|
||||
msg = getString(R.string.qr_code_too_old,
|
||||
getString(R.string.app_name));
|
||||
} else {
|
||||
msg = getString(R.string.qr_code_too_new,
|
||||
getString(R.string.app_name));
|
||||
}
|
||||
showNextFragment(ContactExchangeErrorFragment.newInstance(msg));
|
||||
} catch (CameraException e) {
|
||||
logCameraExceptionAndFinish(e);
|
||||
} catch (IOException | IllegalArgumentException e) {
|
||||
LOG.log(WARNING, "QR Code Invalid", e);
|
||||
reset();
|
||||
Toast.makeText(getActivity(), R.string.qr_code_invalid,
|
||||
LENGTH_LONG).show();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void eventOccurred(Event e) {
|
||||
if (e instanceof KeyAgreementListeningEvent) {
|
||||
KeyAgreementListeningEvent event = (KeyAgreementListeningEvent) e;
|
||||
gotLocalPayload = true;
|
||||
setQrCode(event.getLocalPayload());
|
||||
} else if (e instanceof KeyAgreementFailedEvent) {
|
||||
keyAgreementFailed();
|
||||
} else if (e instanceof KeyAgreementWaitingEvent) {
|
||||
keyAgreementWaiting();
|
||||
} else if (e instanceof KeyAgreementStartedEvent) {
|
||||
keyAgreementStarted();
|
||||
} else if (e instanceof KeyAgreementAbortedEvent) {
|
||||
KeyAgreementAbortedEvent event = (KeyAgreementAbortedEvent) e;
|
||||
keyAgreementAborted(event.didRemoteAbort());
|
||||
} else if (e instanceof KeyAgreementFinishedEvent) {
|
||||
keyAgreementFinished(((KeyAgreementFinishedEvent) e).getResult());
|
||||
}
|
||||
}
|
||||
|
||||
@UiThread
|
||||
private void keyAgreementFailed() {
|
||||
reset();
|
||||
listener.keyAgreementFailed();
|
||||
}
|
||||
|
||||
@UiThread
|
||||
private void keyAgreementWaiting() {
|
||||
status.setText(listener.keyAgreementWaiting());
|
||||
}
|
||||
|
||||
@UiThread
|
||||
private void keyAgreementStarted() {
|
||||
qrCodeView.setVisibility(INVISIBLE);
|
||||
statusView.setVisibility(VISIBLE);
|
||||
status.setText(listener.keyAgreementStarted());
|
||||
}
|
||||
|
||||
@UiThread
|
||||
private void keyAgreementAborted(boolean remoteAborted) {
|
||||
reset();
|
||||
listener.keyAgreementAborted(remoteAborted);
|
||||
}
|
||||
|
||||
@UiThread
|
||||
private void keyAgreementFinished(KeyAgreementResult result) {
|
||||
statusView.setVisibility(VISIBLE);
|
||||
status.setText(listener.keyAgreementFinished(result));
|
||||
}
|
||||
|
||||
private void setQrCode(Payload localPayload) {
|
||||
Context context = getContext();
|
||||
if (context == null) return;
|
||||
DisplayMetrics dm = context.getResources().getDisplayMetrics();
|
||||
ioExecutor.execute(() -> {
|
||||
byte[] payloadBytes = payloadEncoder.encode(localPayload);
|
||||
if (LOG.isLoggable(INFO)) {
|
||||
LOG.info("Local payload is " + payloadBytes.length
|
||||
+ " bytes");
|
||||
}
|
||||
// Use ISO 8859-1 to encode bytes directly as a string
|
||||
String content = new String(payloadBytes, ISO_8859_1);
|
||||
Bitmap qrCode = QrCodeUtils.createQrCode(dm, content);
|
||||
runOnUiThreadUnlessDestroyed(() -> qrCodeView.setQrCode(qrCode));
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleResult(Result result) {
|
||||
runOnUiThreadUnlessDestroyed(() -> {
|
||||
LOG.info("Got result from decoder");
|
||||
// Ignore results until the KeyAgreementTask is ready
|
||||
if (!gotLocalPayload) return;
|
||||
if (!gotRemotePayload) qrCodeScanned(result.getText());
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void finish() {
|
||||
getActivity().getSupportFragmentManager().popBackStack();
|
||||
}
|
||||
|
||||
@NotNullByDefault
|
||||
interface ShardQrCodeEventListener {
|
||||
|
||||
@UiThread
|
||||
void keyAgreementFailed();
|
||||
|
||||
// Should return a string to be displayed as status.
|
||||
@UiThread
|
||||
@Nullable
|
||||
String keyAgreementWaiting();
|
||||
|
||||
// Should return a string to be displayed as status.
|
||||
@UiThread
|
||||
@Nullable
|
||||
String keyAgreementStarted();
|
||||
|
||||
// Will show an error fragment.
|
||||
@UiThread
|
||||
void keyAgreementAborted(boolean remoteAborted);
|
||||
|
||||
// Should return a string to be displayed as status.
|
||||
@UiThread
|
||||
@Nullable
|
||||
String keyAgreementFinished(KeyAgreementResult result);
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user