mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-16 12:49:55 +01:00
Compare commits
1 Commits
1387-persi
...
1764-fix-c
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8a94a1708f |
@@ -1,9 +0,0 @@
|
|||||||
Translations for this project are managed through Transifex:
|
|
||||||
|
|
||||||
https://transifex.com/otf/briar
|
|
||||||
|
|
||||||
If you'd like to volunteer as a translator, please create a Transifex account and request to be
|
|
||||||
added to the project's translation team. The Localization Lab has some instructions and advice for
|
|
||||||
translators here:
|
|
||||||
|
|
||||||
https://wiki.localizationlab.org/index.php/Briar
|
|
||||||
@@ -9,10 +9,8 @@ import org.briarproject.bramble.api.account.AccountManager;
|
|||||||
import org.briarproject.bramble.api.crypto.CryptoComponent;
|
import org.briarproject.bramble.api.crypto.CryptoComponent;
|
||||||
import org.briarproject.bramble.api.db.DatabaseConfig;
|
import org.briarproject.bramble.api.db.DatabaseConfig;
|
||||||
import org.briarproject.bramble.api.identity.IdentityManager;
|
import org.briarproject.bramble.api.identity.IdentityManager;
|
||||||
import org.briarproject.bramble.api.logging.PersistentLogManager;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
@@ -22,21 +20,17 @@ import javax.annotation.Nullable;
|
|||||||
import javax.annotation.concurrent.GuardedBy;
|
import javax.annotation.concurrent.GuardedBy;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
import static android.content.Context.MODE_PRIVATE;
|
|
||||||
import static android.os.Build.VERSION.SDK_INT;
|
import static android.os.Build.VERSION.SDK_INT;
|
||||||
import static java.util.Arrays.asList;
|
import static java.util.Arrays.asList;
|
||||||
import static java.util.logging.Level.INFO;
|
import static java.util.logging.Level.INFO;
|
||||||
import static java.util.logging.Level.WARNING;
|
|
||||||
import static java.util.logging.Logger.getLogger;
|
|
||||||
import static org.briarproject.bramble.util.IoUtils.deleteFileOrDir;
|
import static org.briarproject.bramble.util.IoUtils.deleteFileOrDir;
|
||||||
import static org.briarproject.bramble.util.LogUtils.logException;
|
|
||||||
import static org.briarproject.bramble.util.LogUtils.logFileOrDir;
|
import static org.briarproject.bramble.util.LogUtils.logFileOrDir;
|
||||||
|
|
||||||
class AndroidAccountManager extends AccountManagerImpl
|
class AndroidAccountManager extends AccountManagerImpl
|
||||||
implements AccountManager {
|
implements AccountManager {
|
||||||
|
|
||||||
private static final Logger LOG =
|
private static final Logger LOG =
|
||||||
getLogger(AndroidAccountManager.class.getName());
|
Logger.getLogger(AndroidAccountManager.class.getName());
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Directories that shouldn't be deleted when deleting the user's account.
|
* Directories that shouldn't be deleted when deleting the user's account.
|
||||||
@@ -46,16 +40,13 @@ class AndroidAccountManager extends AccountManagerImpl
|
|||||||
|
|
||||||
protected final Context appContext;
|
protected final Context appContext;
|
||||||
private final SharedPreferences prefs;
|
private final SharedPreferences prefs;
|
||||||
private final PersistentLogManager logManager;
|
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
AndroidAccountManager(DatabaseConfig databaseConfig,
|
AndroidAccountManager(DatabaseConfig databaseConfig,
|
||||||
CryptoComponent crypto, IdentityManager identityManager,
|
CryptoComponent crypto, IdentityManager identityManager,
|
||||||
SharedPreferences prefs, PersistentLogManager logManager,
|
SharedPreferences prefs, Application app) {
|
||||||
Application app) {
|
|
||||||
super(databaseConfig, crypto, identityManager);
|
super(databaseConfig, crypto, identityManager);
|
||||||
this.prefs = prefs;
|
this.prefs = prefs;
|
||||||
this.logManager = logManager;
|
|
||||||
appContext = app.getApplicationContext();
|
appContext = app.getApplicationContext();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -83,7 +74,6 @@ class AndroidAccountManager extends AccountManagerImpl
|
|||||||
LOG.info("Contents of account directory after deleting:");
|
LOG.info("Contents of account directory after deleting:");
|
||||||
logFileOrDir(LOG, INFO, getDataDir());
|
logFileOrDir(LOG, INFO, getDataDir());
|
||||||
}
|
}
|
||||||
replacePersistentLogger();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -144,13 +134,4 @@ class AndroidAccountManager extends AccountManagerImpl
|
|||||||
private void addIfNotNull(Set<File> files, @Nullable File file) {
|
private void addIfNotNull(Set<File> files, @Nullable File file) {
|
||||||
if (file != null) files.add(file);
|
if (file != null) files.add(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void replacePersistentLogger() {
|
|
||||||
File logDir = appContext.getDir("log", MODE_PRIVATE);
|
|
||||||
try {
|
|
||||||
logManager.addLogHandler(logDir, getLogger(""));
|
|
||||||
} catch (IOException e) {
|
|
||||||
logException(LOG, WARNING, e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import android.content.pm.ApplicationInfo;
|
|||||||
import org.briarproject.bramble.api.crypto.CryptoComponent;
|
import org.briarproject.bramble.api.crypto.CryptoComponent;
|
||||||
import org.briarproject.bramble.api.db.DatabaseConfig;
|
import org.briarproject.bramble.api.db.DatabaseConfig;
|
||||||
import org.briarproject.bramble.api.identity.IdentityManager;
|
import org.briarproject.bramble.api.identity.IdentityManager;
|
||||||
import org.briarproject.bramble.api.logging.PersistentLogManager;
|
|
||||||
import org.briarproject.bramble.test.BrambleMockTestCase;
|
import org.briarproject.bramble.test.BrambleMockTestCase;
|
||||||
import org.jmock.Expectations;
|
import org.jmock.Expectations;
|
||||||
import org.jmock.lib.legacy.ClassImposteriser;
|
import org.jmock.lib.legacy.ClassImposteriser;
|
||||||
@@ -16,9 +15,7 @@ import org.junit.Before;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
import static android.content.Context.MODE_PRIVATE;
|
|
||||||
import static junit.framework.Assert.assertFalse;
|
import static junit.framework.Assert.assertFalse;
|
||||||
import static junit.framework.Assert.assertTrue;
|
import static junit.framework.Assert.assertTrue;
|
||||||
import static org.briarproject.bramble.test.TestUtils.deleteTestDirectory;
|
import static org.briarproject.bramble.test.TestUtils.deleteTestDirectory;
|
||||||
@@ -30,8 +27,6 @@ public class AndroidAccountManagerTest extends BrambleMockTestCase {
|
|||||||
context.mock(SharedPreferences.class, "prefs");
|
context.mock(SharedPreferences.class, "prefs");
|
||||||
private final SharedPreferences defaultPrefs =
|
private final SharedPreferences defaultPrefs =
|
||||||
context.mock(SharedPreferences.class, "defaultPrefs");
|
context.mock(SharedPreferences.class, "defaultPrefs");
|
||||||
private final PersistentLogManager logManager =
|
|
||||||
context.mock(PersistentLogManager.class);
|
|
||||||
private final DatabaseConfig databaseConfig =
|
private final DatabaseConfig databaseConfig =
|
||||||
context.mock(DatabaseConfig.class);
|
context.mock(DatabaseConfig.class);
|
||||||
private final CryptoComponent crypto = context.mock(CryptoComponent.class);
|
private final CryptoComponent crypto = context.mock(CryptoComponent.class);
|
||||||
@@ -45,7 +40,6 @@ public class AndroidAccountManagerTest extends BrambleMockTestCase {
|
|||||||
private final File testDir = getTestDirectory();
|
private final File testDir = getTestDirectory();
|
||||||
private final File keyDir = new File(testDir, "key");
|
private final File keyDir = new File(testDir, "key");
|
||||||
private final File dbDir = new File(testDir, "db");
|
private final File dbDir = new File(testDir, "db");
|
||||||
private final File logDir = new File(testDir, "log");
|
|
||||||
|
|
||||||
private AndroidAccountManager accountManager;
|
private AndroidAccountManager accountManager;
|
||||||
|
|
||||||
@@ -67,7 +61,7 @@ public class AndroidAccountManagerTest extends BrambleMockTestCase {
|
|||||||
will(returnValue(app));
|
will(returnValue(app));
|
||||||
}});
|
}});
|
||||||
accountManager = new AndroidAccountManager(databaseConfig, crypto,
|
accountManager = new AndroidAccountManager(databaseConfig, crypto,
|
||||||
identityManager, prefs, logManager, app) {
|
identityManager, prefs, app) {
|
||||||
@Override
|
@Override
|
||||||
SharedPreferences getDefaultSharedPreferences() {
|
SharedPreferences getDefaultSharedPreferences() {
|
||||||
return defaultPrefs;
|
return defaultPrefs;
|
||||||
@@ -115,15 +109,10 @@ public class AndroidAccountManagerTest extends BrambleMockTestCase {
|
|||||||
will(returnValue(cacheDir));
|
will(returnValue(cacheDir));
|
||||||
oneOf(app).getExternalCacheDir();
|
oneOf(app).getExternalCacheDir();
|
||||||
will(returnValue(externalCacheDir));
|
will(returnValue(externalCacheDir));
|
||||||
oneOf(app).getDir("log", MODE_PRIVATE);
|
|
||||||
will(returnValue(logDir));
|
|
||||||
oneOf(logManager).addLogHandler(with(logDir),
|
|
||||||
with(any(Logger.class)));
|
|
||||||
}});
|
}});
|
||||||
|
|
||||||
assertTrue(dbDir.mkdirs());
|
assertTrue(dbDir.mkdirs());
|
||||||
assertTrue(keyDir.mkdirs());
|
assertTrue(keyDir.mkdirs());
|
||||||
assertTrue(logDir.mkdirs());
|
|
||||||
assertTrue(codeCacheDir.mkdirs());
|
assertTrue(codeCacheDir.mkdirs());
|
||||||
assertTrue(codeCacheFile.createNewFile());
|
assertTrue(codeCacheFile.createNewFile());
|
||||||
assertTrue(libDir.mkdirs());
|
assertTrue(libDir.mkdirs());
|
||||||
@@ -141,7 +130,6 @@ public class AndroidAccountManagerTest extends BrambleMockTestCase {
|
|||||||
|
|
||||||
assertFalse(dbDir.exists());
|
assertFalse(dbDir.exists());
|
||||||
assertFalse(keyDir.exists());
|
assertFalse(keyDir.exists());
|
||||||
assertFalse(logDir.exists());
|
|
||||||
assertTrue(codeCacheDir.exists());
|
assertTrue(codeCacheDir.exists());
|
||||||
assertTrue(codeCacheFile.exists());
|
assertTrue(codeCacheFile.exists());
|
||||||
assertTrue(libDir.exists());
|
assertTrue(libDir.exists());
|
||||||
|
|||||||
@@ -1,16 +1,8 @@
|
|||||||
package org.briarproject.bramble.api;
|
package org.briarproject.bramble.api;
|
||||||
|
|
||||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
|
||||||
|
|
||||||
import java.util.Hashtable;
|
import java.util.Hashtable;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
|
|
||||||
import static org.briarproject.bramble.util.StringUtils.fromHexString;
|
|
||||||
import static org.briarproject.bramble.util.StringUtils.toHexString;
|
|
||||||
|
|
||||||
@NotNullByDefault
|
|
||||||
public abstract class StringMap extends Hashtable<String, String> {
|
public abstract class StringMap extends Hashtable<String, String> {
|
||||||
|
|
||||||
protected StringMap(Map<String, String> m) {
|
protected StringMap(Map<String, String> m) {
|
||||||
@@ -60,19 +52,4 @@ public abstract class StringMap extends Hashtable<String, String> {
|
|||||||
public void putLong(String key, long value) {
|
public void putLong(String key, long value) {
|
||||||
put(key, String.valueOf(value));
|
put(key, String.valueOf(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
|
||||||
public byte[] getBytes(String key) {
|
|
||||||
String s = get(key);
|
|
||||||
if (s == null) return null;
|
|
||||||
try {
|
|
||||||
return fromHexString(s);
|
|
||||||
} catch (IllegalArgumentException e) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void putBytes(String key, byte[] value) {
|
|
||||||
put(key, toHexString(value));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,10 +19,4 @@ public interface StreamDecrypterFactory {
|
|||||||
*/
|
*/
|
||||||
StreamDecrypter createContactExchangeStreamDecrypter(InputStream in,
|
StreamDecrypter createContactExchangeStreamDecrypter(InputStream in,
|
||||||
SecretKey headerKey);
|
SecretKey headerKey);
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a {@link StreamDecrypter} for decrypting a log stream.
|
|
||||||
*/
|
|
||||||
StreamDecrypter createLogStreamDecrypter(InputStream in,
|
|
||||||
SecretKey headerKey);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,12 +17,6 @@ public interface StreamEncrypterFactory {
|
|||||||
* Creates a {@link StreamEncrypter} for encrypting a contact exchange
|
* Creates a {@link StreamEncrypter} for encrypting a contact exchange
|
||||||
* stream.
|
* stream.
|
||||||
*/
|
*/
|
||||||
StreamEncrypter createContactExchangeStreamEncrypter(OutputStream out,
|
StreamEncrypter createContactExchangeStreamDecrypter(OutputStream out,
|
||||||
SecretKey headerKey);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a {@link StreamEncrypter} for encrypting a log stream.
|
|
||||||
*/
|
|
||||||
StreamEncrypter createLogStreamEncrypter(OutputStream out,
|
|
||||||
SecretKey headerKey);
|
SecretKey headerKey);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,46 +0,0 @@
|
|||||||
package org.briarproject.bramble.api.logging;
|
|
||||||
|
|
||||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
|
||||||
import org.briarproject.bramble.api.settings.Settings;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.Scanner;
|
|
||||||
import java.util.logging.Handler;
|
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
@NotNullByDefault
|
|
||||||
public interface PersistentLogManager {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The namespace of the (@link Settings) where the log key is stored.
|
|
||||||
*/
|
|
||||||
String LOG_SETTINGS_NAMESPACE = "log";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The {@link Settings} key under which the log key is stored.
|
|
||||||
*/
|
|
||||||
String LOG_KEY_KEY = "logKey";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates and returns a persistent log handler that stores its logs in
|
|
||||||
* the given directory.
|
|
||||||
*/
|
|
||||||
Handler createLogHandler(File dir) throws IOException;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a persistent log handler that stores its logs in the given
|
|
||||||
* directory and adds the handler to the given logger, replacing any
|
|
||||||
* existing persistent log handler.
|
|
||||||
*/
|
|
||||||
void addLogHandler(File dir, Logger logger) throws IOException;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a {@link Scanner} for reading the persistent log entries stored
|
|
||||||
* in the given directory.
|
|
||||||
*
|
|
||||||
* @param old True if the previous session's log should be loaded, or false
|
|
||||||
* if the current session's log should be loaded
|
|
||||||
*/
|
|
||||||
Scanner getPersistedLog(File dir, boolean old) throws IOException;
|
|
||||||
}
|
|
||||||
@@ -16,13 +16,8 @@ public interface StreamReaderFactory {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an {@link InputStream InputStream} for reading from a contact
|
* Creates an {@link InputStream InputStream} for reading from a contact
|
||||||
* exchange stream.
|
* exchangestream.
|
||||||
*/
|
*/
|
||||||
InputStream createContactExchangeStreamReader(InputStream in,
|
InputStream createContactExchangeStreamReader(InputStream in,
|
||||||
SecretKey headerKey);
|
SecretKey headerKey);
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates an {@link InputStream} for reading from a log stream.
|
|
||||||
*/
|
|
||||||
InputStream createLogStreamReader(InputStream in, SecretKey headerKey);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,18 +9,15 @@ import java.io.OutputStream;
|
|||||||
public interface StreamWriterFactory {
|
public interface StreamWriterFactory {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a {@link StreamWriter} for writing to a transport stream.
|
* Creates an {@link OutputStream OutputStream} for writing to a
|
||||||
|
* transport stream
|
||||||
*/
|
*/
|
||||||
StreamWriter createStreamWriter(OutputStream out, StreamContext ctx);
|
StreamWriter createStreamWriter(OutputStream out, StreamContext ctx);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a {@link StreamWriter} for writing to a contact exchange stream.
|
* Creates an {@link OutputStream OutputStream} for writing to a contact
|
||||||
|
* exchange stream.
|
||||||
*/
|
*/
|
||||||
StreamWriter createContactExchangeStreamWriter(OutputStream out,
|
StreamWriter createContactExchangeStreamWriter(OutputStream out,
|
||||||
SecretKey headerKey);
|
SecretKey headerKey);
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a {@link StreamWriter} for writing to a log stream.
|
|
||||||
*/
|
|
||||||
StreamWriter createLogStreamWriter(OutputStream out, SecretKey headerKey);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ import org.briarproject.bramble.identity.IdentityModule;
|
|||||||
import org.briarproject.bramble.io.IoModule;
|
import org.briarproject.bramble.io.IoModule;
|
||||||
import org.briarproject.bramble.keyagreement.KeyAgreementModule;
|
import org.briarproject.bramble.keyagreement.KeyAgreementModule;
|
||||||
import org.briarproject.bramble.lifecycle.LifecycleModule;
|
import org.briarproject.bramble.lifecycle.LifecycleModule;
|
||||||
import org.briarproject.bramble.logging.LoggingModule;
|
|
||||||
import org.briarproject.bramble.plugin.PluginModule;
|
import org.briarproject.bramble.plugin.PluginModule;
|
||||||
import org.briarproject.bramble.properties.PropertiesModule;
|
import org.briarproject.bramble.properties.PropertiesModule;
|
||||||
import org.briarproject.bramble.record.RecordModule;
|
import org.briarproject.bramble.record.RecordModule;
|
||||||
@@ -42,7 +41,6 @@ import dagger.Module;
|
|||||||
IoModule.class,
|
IoModule.class,
|
||||||
KeyAgreementModule.class,
|
KeyAgreementModule.class,
|
||||||
LifecycleModule.class,
|
LifecycleModule.class,
|
||||||
LoggingModule.class,
|
|
||||||
PluginModule.class,
|
PluginModule.class,
|
||||||
PropertiesModule.class,
|
PropertiesModule.class,
|
||||||
RecordModule.class,
|
RecordModule.class,
|
||||||
|
|||||||
@@ -36,10 +36,4 @@ class StreamDecrypterFactoryImpl implements StreamDecrypterFactory {
|
|||||||
SecretKey headerKey) {
|
SecretKey headerKey) {
|
||||||
return new StreamDecrypterImpl(in, cipherProvider.get(), 0, headerKey);
|
return new StreamDecrypterImpl(in, cipherProvider.get(), 0, headerKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public StreamDecrypter createLogStreamDecrypter(InputStream in,
|
|
||||||
SecretKey headerKey) {
|
|
||||||
return createContactExchangeStreamDecrypter(in, headerKey);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ class StreamEncrypterFactoryImpl implements StreamEncrypterFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public StreamEncrypter createContactExchangeStreamEncrypter(
|
public StreamEncrypter createContactExchangeStreamDecrypter(
|
||||||
OutputStream out, SecretKey headerKey) {
|
OutputStream out, SecretKey headerKey) {
|
||||||
AuthenticatedCipher cipher = cipherProvider.get();
|
AuthenticatedCipher cipher = cipherProvider.get();
|
||||||
byte[] streamHeaderNonce = new byte[STREAM_HEADER_NONCE_LENGTH];
|
byte[] streamHeaderNonce = new byte[STREAM_HEADER_NONCE_LENGTH];
|
||||||
@@ -60,10 +60,4 @@ class StreamEncrypterFactoryImpl implements StreamEncrypterFactory {
|
|||||||
return new StreamEncrypterImpl(out, cipher, 0, null, streamHeaderNonce,
|
return new StreamEncrypterImpl(out, cipher, 0, null, streamHeaderNonce,
|
||||||
headerKey, frameKey);
|
headerKey, frameKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public StreamEncrypter createLogStreamEncrypter(OutputStream out,
|
|
||||||
SecretKey headerKey) {
|
|
||||||
return createContactExchangeStreamEncrypter(out, headerKey);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,43 +0,0 @@
|
|||||||
package org.briarproject.bramble.logging;
|
|
||||||
|
|
||||||
import java.io.OutputStream;
|
|
||||||
import java.util.concurrent.Executor;
|
|
||||||
import java.util.concurrent.ScheduledExecutorService;
|
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
|
||||||
import java.util.logging.Formatter;
|
|
||||||
import java.util.logging.LogRecord;
|
|
||||||
import java.util.logging.StreamHandler;
|
|
||||||
|
|
||||||
import static java.util.concurrent.TimeUnit.MILLISECONDS;
|
|
||||||
|
|
||||||
class FlushingStreamHandler extends StreamHandler {
|
|
||||||
|
|
||||||
private static final int FLUSH_DELAY_MS = 5_000;
|
|
||||||
|
|
||||||
private final ScheduledExecutorService scheduler;
|
|
||||||
private final Executor ioExecutor;
|
|
||||||
private final AtomicBoolean flushScheduled = new AtomicBoolean(false);
|
|
||||||
|
|
||||||
FlushingStreamHandler(ScheduledExecutorService scheduler,
|
|
||||||
Executor ioExecutor, OutputStream out, Formatter formatter) {
|
|
||||||
super(out, formatter);
|
|
||||||
this.scheduler = scheduler;
|
|
||||||
this.ioExecutor = ioExecutor;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void publish(LogRecord record) {
|
|
||||||
super.publish(record);
|
|
||||||
if (!flushScheduled.getAndSet(true)) {
|
|
||||||
scheduler.schedule(this::scheduledFlush,
|
|
||||||
FLUSH_DELAY_MS, MILLISECONDS);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void scheduledFlush() {
|
|
||||||
ioExecutor.execute(() -> {
|
|
||||||
flushScheduled.set(false);
|
|
||||||
flush();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
package org.briarproject.bramble.logging;
|
|
||||||
|
|
||||||
import org.briarproject.bramble.api.lifecycle.LifecycleManager;
|
|
||||||
import org.briarproject.bramble.api.logging.PersistentLogManager;
|
|
||||||
|
|
||||||
import java.util.logging.Formatter;
|
|
||||||
|
|
||||||
import javax.inject.Singleton;
|
|
||||||
|
|
||||||
import dagger.Module;
|
|
||||||
import dagger.Provides;
|
|
||||||
|
|
||||||
@Module
|
|
||||||
public class LoggingModule {
|
|
||||||
|
|
||||||
@Provides
|
|
||||||
Formatter provideFormatter() {
|
|
||||||
return new BriefLogFormatter();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Provides
|
|
||||||
@Singleton
|
|
||||||
PersistentLogManager providePersistentLogManager(
|
|
||||||
LifecycleManager lifecycleManager,
|
|
||||||
PersistentLogManagerImpl persistentLogManager) {
|
|
||||||
lifecycleManager.registerOpenDatabaseHook(persistentLogManager);
|
|
||||||
return persistentLogManager;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,177 +0,0 @@
|
|||||||
package org.briarproject.bramble.logging;
|
|
||||||
|
|
||||||
import org.briarproject.bramble.api.crypto.CryptoComponent;
|
|
||||||
import org.briarproject.bramble.api.crypto.SecretKey;
|
|
||||||
import org.briarproject.bramble.api.db.DatabaseComponent;
|
|
||||||
import org.briarproject.bramble.api.db.DbException;
|
|
||||||
import org.briarproject.bramble.api.db.Transaction;
|
|
||||||
import org.briarproject.bramble.api.lifecycle.IoExecutor;
|
|
||||||
import org.briarproject.bramble.api.lifecycle.LifecycleManager.OpenDatabaseHook;
|
|
||||||
import org.briarproject.bramble.api.lifecycle.ShutdownManager;
|
|
||||||
import org.briarproject.bramble.api.logging.PersistentLogManager;
|
|
||||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
|
||||||
import org.briarproject.bramble.api.settings.Settings;
|
|
||||||
import org.briarproject.bramble.api.system.Scheduler;
|
|
||||||
import org.briarproject.bramble.api.transport.StreamReaderFactory;
|
|
||||||
import org.briarproject.bramble.api.transport.StreamWriter;
|
|
||||||
import org.briarproject.bramble.api.transport.StreamWriterFactory;
|
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.FileOutputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.OutputStream;
|
|
||||||
import java.util.Scanner;
|
|
||||||
import java.util.concurrent.Executor;
|
|
||||||
import java.util.concurrent.ScheduledExecutorService;
|
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
|
||||||
import java.util.logging.Formatter;
|
|
||||||
import java.util.logging.Handler;
|
|
||||||
import java.util.logging.Logger;
|
|
||||||
import java.util.logging.StreamHandler;
|
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
import javax.annotation.concurrent.ThreadSafe;
|
|
||||||
import javax.inject.Inject;
|
|
||||||
|
|
||||||
import static java.util.logging.Level.WARNING;
|
|
||||||
import static java.util.logging.Logger.getLogger;
|
|
||||||
import static org.briarproject.bramble.util.LogUtils.logException;
|
|
||||||
|
|
||||||
@ThreadSafe
|
|
||||||
@NotNullByDefault
|
|
||||||
class PersistentLogManagerImpl implements PersistentLogManager,
|
|
||||||
OpenDatabaseHook {
|
|
||||||
|
|
||||||
private static final Logger LOG =
|
|
||||||
getLogger(PersistentLogManagerImpl.class.getName());
|
|
||||||
|
|
||||||
private static final String LOG_FILE = "briar.log";
|
|
||||||
private static final String OLD_LOG_FILE = "briar.log.old";
|
|
||||||
|
|
||||||
private final ScheduledExecutorService scheduler;
|
|
||||||
private final Executor ioExecutor;
|
|
||||||
private final ShutdownManager shutdownManager;
|
|
||||||
private final DatabaseComponent db;
|
|
||||||
private final StreamReaderFactory streamReaderFactory;
|
|
||||||
private final StreamWriterFactory streamWriterFactory;
|
|
||||||
private final Formatter formatter;
|
|
||||||
private final SecretKey logKey;
|
|
||||||
private final AtomicReference<Integer> shutdownHookHandle =
|
|
||||||
new AtomicReference<>();
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
private volatile SecretKey oldLogKey = null;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
PersistentLogManagerImpl(
|
|
||||||
@Scheduler ScheduledExecutorService scheduler,
|
|
||||||
@IoExecutor Executor ioExecutor,
|
|
||||||
ShutdownManager shutdownManager,
|
|
||||||
DatabaseComponent db,
|
|
||||||
StreamReaderFactory streamReaderFactory,
|
|
||||||
StreamWriterFactory streamWriterFactory,
|
|
||||||
Formatter formatter,
|
|
||||||
CryptoComponent crypto) {
|
|
||||||
this.scheduler = scheduler;
|
|
||||||
this.ioExecutor = ioExecutor;
|
|
||||||
this.shutdownManager = shutdownManager;
|
|
||||||
this.db = db;
|
|
||||||
this.streamReaderFactory = streamReaderFactory;
|
|
||||||
this.streamWriterFactory = streamWriterFactory;
|
|
||||||
this.formatter = formatter;
|
|
||||||
logKey = crypto.generateSecretKey();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onDatabaseOpened(Transaction txn) throws DbException {
|
|
||||||
Settings s = db.getSettings(txn, LOG_SETTINGS_NAMESPACE);
|
|
||||||
// Load the old log key, if any
|
|
||||||
byte[] oldKeyBytes = s.getBytes(LOG_KEY_KEY);
|
|
||||||
if (oldKeyBytes != null && oldKeyBytes.length == SecretKey.LENGTH) {
|
|
||||||
LOG.info("Loaded old log key");
|
|
||||||
oldLogKey = new SecretKey(oldKeyBytes);
|
|
||||||
}
|
|
||||||
// Store the current log key
|
|
||||||
s.putBytes(LOG_KEY_KEY, logKey.getBytes());
|
|
||||||
db.mergeSettings(txn, s, LOG_SETTINGS_NAMESPACE);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Handler createLogHandler(File dir) throws IOException {
|
|
||||||
File logFile = new File(dir, LOG_FILE);
|
|
||||||
File oldLogFile = new File(dir, OLD_LOG_FILE);
|
|
||||||
if (oldLogFile.exists() && !oldLogFile.delete())
|
|
||||||
LOG.warning("Failed to delete old log file");
|
|
||||||
if (logFile.exists() && !logFile.renameTo(oldLogFile))
|
|
||||||
LOG.warning("Failed to rename log file");
|
|
||||||
try {
|
|
||||||
OutputStream out = new FileOutputStream(logFile);
|
|
||||||
StreamWriter writer =
|
|
||||||
streamWriterFactory.createLogStreamWriter(out, logKey);
|
|
||||||
StreamHandler handler = new FlushingStreamHandler(scheduler,
|
|
||||||
ioExecutor, writer.getOutputStream(), formatter);
|
|
||||||
// Flush the log and terminate the stream at shutdown
|
|
||||||
Runnable shutdownHook = () -> {
|
|
||||||
LOG.info("Shutting down");
|
|
||||||
handler.flush();
|
|
||||||
try {
|
|
||||||
writer.sendEndOfStream();
|
|
||||||
} catch (IOException e) {
|
|
||||||
logException(LOG, WARNING, e);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
int handle = shutdownManager.addShutdownHook(shutdownHook);
|
|
||||||
// If a previous handler registered a shutdown hook, remove it
|
|
||||||
Integer oldHandle = shutdownHookHandle.getAndSet(handle);
|
|
||||||
if (oldHandle != null) {
|
|
||||||
shutdownManager.removeShutdownHook(oldHandle);
|
|
||||||
}
|
|
||||||
return handler;
|
|
||||||
} catch (SecurityException e) {
|
|
||||||
throw new IOException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void addLogHandler(File dir, Logger logger) throws IOException {
|
|
||||||
for (Handler h : logger.getHandlers()) {
|
|
||||||
if (h instanceof FlushingStreamHandler) logger.removeHandler(h);
|
|
||||||
}
|
|
||||||
logger.addHandler(createLogHandler(dir));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Scanner getPersistedLog(File dir, boolean old)
|
|
||||||
throws IOException {
|
|
||||||
if (old) {
|
|
||||||
SecretKey oldLogKey = this.oldLogKey;
|
|
||||||
if (oldLogKey == null) {
|
|
||||||
LOG.info("Old log key has not been loaded");
|
|
||||||
return emptyScanner();
|
|
||||||
}
|
|
||||||
return getPersistedLog(new File(dir, OLD_LOG_FILE), oldLogKey);
|
|
||||||
} else {
|
|
||||||
return getPersistedLog(new File(dir, LOG_FILE), logKey);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private Scanner getPersistedLog(File logFile, SecretKey key)
|
|
||||||
throws IOException {
|
|
||||||
if (logFile.exists()) {
|
|
||||||
LOG.info("Reading log file");
|
|
||||||
InputStream in = new FileInputStream(logFile);
|
|
||||||
return new Scanner(streamReaderFactory.createLogStreamReader(in,
|
|
||||||
key));
|
|
||||||
} else {
|
|
||||||
LOG.info("Log file does not exist");
|
|
||||||
return emptyScanner();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private Scanner emptyScanner() {
|
|
||||||
return new Scanner(new ByteArrayInputStream(new byte[0]));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -24,21 +24,15 @@ class StreamReaderFactoryImpl implements StreamReaderFactory {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public InputStream createStreamReader(InputStream in, StreamContext ctx) {
|
public InputStream createStreamReader(InputStream in, StreamContext ctx) {
|
||||||
return new StreamReaderImpl(streamDecrypterFactory
|
return new StreamReaderImpl(
|
||||||
.createStreamDecrypter(in, ctx));
|
streamDecrypterFactory.createStreamDecrypter(in, ctx));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public InputStream createContactExchangeStreamReader(InputStream in,
|
public InputStream createContactExchangeStreamReader(InputStream in,
|
||||||
SecretKey headerKey) {
|
SecretKey headerKey) {
|
||||||
return new StreamReaderImpl(streamDecrypterFactory
|
return new StreamReaderImpl(
|
||||||
.createContactExchangeStreamDecrypter(in, headerKey));
|
streamDecrypterFactory.createContactExchangeStreamDecrypter(in,
|
||||||
}
|
headerKey));
|
||||||
|
|
||||||
@Override
|
|
||||||
public InputStream createLogStreamReader(InputStream in,
|
|
||||||
SecretKey headerKey) {
|
|
||||||
return new StreamReaderImpl(streamDecrypterFactory
|
|
||||||
.createLogStreamDecrypter(in, headerKey));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,21 +26,15 @@ class StreamWriterFactoryImpl implements StreamWriterFactory {
|
|||||||
@Override
|
@Override
|
||||||
public StreamWriter createStreamWriter(OutputStream out,
|
public StreamWriter createStreamWriter(OutputStream out,
|
||||||
StreamContext ctx) {
|
StreamContext ctx) {
|
||||||
return new StreamWriterImpl(streamEncrypterFactory
|
return new StreamWriterImpl(
|
||||||
.createStreamEncrypter(out, ctx));
|
streamEncrypterFactory.createStreamEncrypter(out, ctx));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public StreamWriter createContactExchangeStreamWriter(OutputStream out,
|
public StreamWriter createContactExchangeStreamWriter(OutputStream out,
|
||||||
SecretKey headerKey) {
|
SecretKey headerKey) {
|
||||||
return new StreamWriterImpl(streamEncrypterFactory
|
return new StreamWriterImpl(
|
||||||
.createContactExchangeStreamEncrypter(out, headerKey));
|
streamEncrypterFactory.createContactExchangeStreamDecrypter(out,
|
||||||
}
|
headerKey));
|
||||||
|
|
||||||
@Override
|
|
||||||
public StreamWriter createLogStreamWriter(OutputStream out,
|
|
||||||
SecretKey headerKey) {
|
|
||||||
return new StreamWriterImpl(streamEncrypterFactory
|
|
||||||
.createLogStreamEncrypter(out, headerKey));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -6,7 +6,6 @@ import android.content.SharedPreferences;
|
|||||||
import org.briarproject.bramble.api.crypto.CryptoComponent;
|
import org.briarproject.bramble.api.crypto.CryptoComponent;
|
||||||
import org.briarproject.bramble.api.db.DatabaseConfig;
|
import org.briarproject.bramble.api.db.DatabaseConfig;
|
||||||
import org.briarproject.bramble.api.identity.IdentityManager;
|
import org.briarproject.bramble.api.identity.IdentityManager;
|
||||||
import org.briarproject.bramble.api.logging.PersistentLogManager;
|
|
||||||
import org.briarproject.briar.R;
|
import org.briarproject.briar.R;
|
||||||
import org.briarproject.briar.android.Localizer;
|
import org.briarproject.briar.android.Localizer;
|
||||||
import org.briarproject.briar.android.util.UiUtils;
|
import org.briarproject.briar.android.util.UiUtils;
|
||||||
@@ -18,8 +17,8 @@ class BriarAccountManager extends AndroidAccountManager {
|
|||||||
@Inject
|
@Inject
|
||||||
BriarAccountManager(DatabaseConfig databaseConfig, CryptoComponent crypto,
|
BriarAccountManager(DatabaseConfig databaseConfig, CryptoComponent crypto,
|
||||||
IdentityManager identityManager, SharedPreferences prefs,
|
IdentityManager identityManager, SharedPreferences prefs,
|
||||||
PersistentLogManager logManager, Application app) {
|
Application app) {
|
||||||
super(databaseConfig, crypto, identityManager, prefs, logManager, app);
|
super(databaseConfig, crypto, identityManager, prefs, app);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -20,7 +20,6 @@ import org.briarproject.bramble.api.keyagreement.PayloadEncoder;
|
|||||||
import org.briarproject.bramble.api.keyagreement.PayloadParser;
|
import org.briarproject.bramble.api.keyagreement.PayloadParser;
|
||||||
import org.briarproject.bramble.api.lifecycle.IoExecutor;
|
import org.briarproject.bramble.api.lifecycle.IoExecutor;
|
||||||
import org.briarproject.bramble.api.lifecycle.LifecycleManager;
|
import org.briarproject.bramble.api.lifecycle.LifecycleManager;
|
||||||
import org.briarproject.bramble.api.logging.PersistentLogManager;
|
|
||||||
import org.briarproject.bramble.api.plugin.PluginManager;
|
import org.briarproject.bramble.api.plugin.PluginManager;
|
||||||
import org.briarproject.bramble.api.settings.SettingsManager;
|
import org.briarproject.bramble.api.settings.SettingsManager;
|
||||||
import org.briarproject.bramble.api.system.AndroidExecutor;
|
import org.briarproject.bramble.api.system.AndroidExecutor;
|
||||||
@@ -57,7 +56,6 @@ import org.briarproject.briar.api.privategroup.invitation.GroupInvitationManager
|
|||||||
import org.briarproject.briar.api.test.TestDataCreator;
|
import org.briarproject.briar.api.test.TestDataCreator;
|
||||||
|
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
import java.util.logging.Formatter;
|
|
||||||
|
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
@@ -167,10 +165,6 @@ public interface AndroidComponent
|
|||||||
|
|
||||||
FeatureFlags featureFlags();
|
FeatureFlags featureFlags();
|
||||||
|
|
||||||
PersistentLogManager persistentLogManager();
|
|
||||||
|
|
||||||
Formatter formatter();
|
|
||||||
|
|
||||||
void inject(SignInReminderReceiver briarService);
|
void inject(SignInReminderReceiver briarService);
|
||||||
|
|
||||||
void inject(BriarService briarService);
|
void inject(BriarService briarService);
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import android.os.StrictMode;
|
|||||||
import android.os.StrictMode.ThreadPolicy;
|
import android.os.StrictMode.ThreadPolicy;
|
||||||
import android.os.StrictMode.VmPolicy;
|
import android.os.StrictMode.VmPolicy;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
import com.vanniktech.emoji.EmojiManager;
|
import com.vanniktech.emoji.EmojiManager;
|
||||||
import com.vanniktech.emoji.google.GoogleEmojiProvider;
|
import com.vanniktech.emoji.google.GoogleEmojiProvider;
|
||||||
@@ -19,7 +20,6 @@ import org.acra.ReportingInteractionMode;
|
|||||||
import org.acra.annotation.ReportsCrashes;
|
import org.acra.annotation.ReportsCrashes;
|
||||||
import org.briarproject.bramble.BrambleAndroidEagerSingletons;
|
import org.briarproject.bramble.BrambleAndroidEagerSingletons;
|
||||||
import org.briarproject.bramble.BrambleCoreEagerSingletons;
|
import org.briarproject.bramble.BrambleCoreEagerSingletons;
|
||||||
import org.briarproject.bramble.api.logging.PersistentLogManager;
|
|
||||||
import org.briarproject.briar.BriarCoreEagerSingletons;
|
import org.briarproject.briar.BriarCoreEagerSingletons;
|
||||||
import org.briarproject.briar.BuildConfig;
|
import org.briarproject.briar.BuildConfig;
|
||||||
import org.briarproject.briar.R;
|
import org.briarproject.briar.R;
|
||||||
@@ -29,8 +29,6 @@ import org.briarproject.briar.android.reporting.BriarReportSenderFactory;
|
|||||||
import org.briarproject.briar.android.reporting.DevReportActivity;
|
import org.briarproject.briar.android.reporting.DevReportActivity;
|
||||||
import org.briarproject.briar.android.util.UiUtils;
|
import org.briarproject.briar.android.util.UiUtils;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.logging.Handler;
|
import java.util.logging.Handler;
|
||||||
import java.util.logging.LogRecord;
|
import java.util.logging.LogRecord;
|
||||||
@@ -39,7 +37,6 @@ import java.util.logging.Logger;
|
|||||||
import static android.app.ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND;
|
import static android.app.ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND;
|
||||||
import static java.util.logging.Level.FINE;
|
import static java.util.logging.Level.FINE;
|
||||||
import static java.util.logging.Level.INFO;
|
import static java.util.logging.Level.INFO;
|
||||||
import static java.util.logging.Level.WARNING;
|
|
||||||
import static java.util.logging.Logger.getLogger;
|
import static java.util.logging.Logger.getLogger;
|
||||||
import static org.acra.ReportField.ANDROID_VERSION;
|
import static org.acra.ReportField.ANDROID_VERSION;
|
||||||
import static org.acra.ReportField.APP_VERSION_CODE;
|
import static org.acra.ReportField.APP_VERSION_CODE;
|
||||||
@@ -58,7 +55,6 @@ import static org.acra.ReportField.REPORT_ID;
|
|||||||
import static org.acra.ReportField.STACK_TRACE;
|
import static org.acra.ReportField.STACK_TRACE;
|
||||||
import static org.acra.ReportField.USER_APP_START_DATE;
|
import static org.acra.ReportField.USER_APP_START_DATE;
|
||||||
import static org.acra.ReportField.USER_CRASH_DATE;
|
import static org.acra.ReportField.USER_CRASH_DATE;
|
||||||
import static org.briarproject.bramble.util.LogUtils.logException;
|
|
||||||
import static org.briarproject.briar.android.TestingConstants.IS_DEBUG_BUILD;
|
import static org.briarproject.briar.android.TestingConstants.IS_DEBUG_BUILD;
|
||||||
|
|
||||||
@ReportsCrashes(
|
@ReportsCrashes(
|
||||||
@@ -101,6 +97,7 @@ public class BriarApplicationImpl extends Application
|
|||||||
Localizer.initialize(prefs);
|
Localizer.initialize(prefs);
|
||||||
super.attachBaseContext(
|
super.attachBaseContext(
|
||||||
Localizer.getInstance().setLocale(base));
|
Localizer.getInstance().setLocale(base));
|
||||||
|
Localizer.getInstance().setLocale(this);
|
||||||
setTheme(base, prefs);
|
setTheme(base, prefs);
|
||||||
ACRA.init(this);
|
ACRA.init(this);
|
||||||
}
|
}
|
||||||
@@ -125,19 +122,9 @@ public class BriarApplicationImpl extends Application
|
|||||||
rootLogger.addHandler(logHandler);
|
rootLogger.addHandler(logHandler);
|
||||||
rootLogger.setLevel(IS_DEBUG_BUILD ? FINE : INFO);
|
rootLogger.setLevel(IS_DEBUG_BUILD ? FINE : INFO);
|
||||||
|
|
||||||
applicationComponent = createApplicationComponent();
|
|
||||||
|
|
||||||
PersistentLogManager logManager =
|
|
||||||
applicationComponent.persistentLogManager();
|
|
||||||
File logDir = getDir("log", MODE_PRIVATE);
|
|
||||||
try {
|
|
||||||
rootLogger.addHandler(logManager.createLogHandler(logDir));
|
|
||||||
} catch (IOException e) {
|
|
||||||
logException(LOG, WARNING, e);
|
|
||||||
}
|
|
||||||
|
|
||||||
LOG.info("Created");
|
LOG.info("Created");
|
||||||
|
|
||||||
|
applicationComponent = createApplicationComponent();
|
||||||
EmojiManager.install(new GoogleEmojiProvider());
|
EmojiManager.install(new GoogleEmojiProvider());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -160,6 +147,7 @@ public class BriarApplicationImpl extends Application
|
|||||||
@Override
|
@Override
|
||||||
public void onConfigurationChanged(Configuration newConfig) {
|
public void onConfigurationChanged(Configuration newConfig) {
|
||||||
super.onConfigurationChanged(newConfig);
|
super.onConfigurationChanged(newConfig);
|
||||||
|
Log.d("language", "BriarApplicationImpl#onConfigurationChanged()");
|
||||||
Localizer.getInstance().setLocale(this);
|
Localizer.getInstance().setLocale(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import android.content.IntentFilter;
|
|||||||
import android.content.ServiceConnection;
|
import android.content.ServiceConnection;
|
||||||
import android.os.Binder;
|
import android.os.Binder;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
import org.briarproject.bramble.api.account.AccountManager;
|
import org.briarproject.bramble.api.account.AccountManager;
|
||||||
import org.briarproject.bramble.api.crypto.SecretKey;
|
import org.briarproject.bramble.api.crypto.SecretKey;
|
||||||
@@ -160,7 +161,9 @@ public class BriarService extends Service {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void attachBaseContext(Context base) {
|
protected void attachBaseContext(Context base) {
|
||||||
|
Log.d("language", "BriarService#attachBaseContext()");
|
||||||
super.attachBaseContext(Localizer.getInstance().setLocale(base));
|
super.attachBaseContext(Localizer.getInstance().setLocale(base));
|
||||||
|
Localizer.getInstance().setLocale(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showStartupFailureNotification(StartResult result) {
|
private void showStartupFailureNotification(StartResult result) {
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import android.content.Context;
|
|||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.content.res.Configuration;
|
import android.content.res.Configuration;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
|
||||||
@@ -26,22 +27,29 @@ public class Localizer {
|
|||||||
private Localizer(SharedPreferences sharedPreferences) {
|
private Localizer(SharedPreferences sharedPreferences) {
|
||||||
this(Locale.getDefault(), getLocaleFromTag(
|
this(Locale.getDefault(), getLocaleFromTag(
|
||||||
sharedPreferences.getString(LANGUAGE, "default")));
|
sharedPreferences.getString(LANGUAGE, "default")));
|
||||||
|
Log.d("language", "preference: " +
|
||||||
|
sharedPreferences.getString(LANGUAGE, "default"));
|
||||||
}
|
}
|
||||||
|
|
||||||
private Localizer(Locale systemLocale, @Nullable Locale userLocale) {
|
private Localizer(Locale systemLocale, @Nullable Locale userLocale) {
|
||||||
this.systemLocale = systemLocale;
|
this.systemLocale = systemLocale;
|
||||||
if (userLocale == null) locale = systemLocale;
|
if (userLocale == null) locale = systemLocale;
|
||||||
else locale = userLocale;
|
else locale = userLocale;
|
||||||
|
Log.d("language", "Localizer() system locale: " + systemLocale);
|
||||||
|
Log.d("language", "Localizer() current locale: " + locale);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Instantiate the Localizer.
|
// Instantiate the Localizer.
|
||||||
public static synchronized void initialize(SharedPreferences prefs) {
|
public static synchronized void initialize(SharedPreferences prefs) {
|
||||||
|
Log.d("language", "Localizer#initialize()");
|
||||||
|
Log.d("language", "sdk: " + SDK_INT);
|
||||||
if (INSTANCE == null)
|
if (INSTANCE == null)
|
||||||
INSTANCE = new Localizer(prefs);
|
INSTANCE = new Localizer(prefs);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reinstantiate the Localizer with the system locale
|
// Reinstantiate the Localizer with the system locale
|
||||||
public static synchronized void reinitialize() {
|
public static synchronized void reinitialize() {
|
||||||
|
Log.d("language", "Localizer#reinitialize()");
|
||||||
if (INSTANCE != null)
|
if (INSTANCE != null)
|
||||||
INSTANCE = new Localizer(INSTANCE.systemLocale, null);
|
INSTANCE = new Localizer(INSTANCE.systemLocale, null);
|
||||||
}
|
}
|
||||||
@@ -72,17 +80,20 @@ public class Localizer {
|
|||||||
public Context setLocale(Context context) {
|
public Context setLocale(Context context) {
|
||||||
Resources res = context.getResources();
|
Resources res = context.getResources();
|
||||||
Configuration conf = res.getConfiguration();
|
Configuration conf = res.getConfiguration();
|
||||||
|
|
||||||
Locale currentLocale;
|
Locale currentLocale;
|
||||||
if (SDK_INT >= 24) {
|
if (SDK_INT >= 24) {
|
||||||
currentLocale = conf.getLocales().get(0);
|
currentLocale = conf.getLocales().get(0);
|
||||||
} else
|
} else
|
||||||
currentLocale = conf.locale;
|
currentLocale = conf.locale;
|
||||||
|
Log.d("language", "current locale: " + currentLocale);
|
||||||
if (locale.equals(currentLocale))
|
if (locale.equals(currentLocale))
|
||||||
return context;
|
return context;
|
||||||
|
Log.d("language", "set locale: " + locale);
|
||||||
Locale.setDefault(locale);
|
Locale.setDefault(locale);
|
||||||
if (SDK_INT >= 17) {
|
if (SDK_INT >= 17) {
|
||||||
conf.setLocale(locale);
|
conf.setLocale(locale);
|
||||||
context.createConfigurationContext(conf);
|
context = context.createConfigurationContext(conf);
|
||||||
} else
|
} else
|
||||||
conf.locale = locale;
|
conf.locale = locale;
|
||||||
//noinspection deprecation
|
//noinspection deprecation
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package org.briarproject.briar.android.activity;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.util.Log;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.view.ViewGroup.LayoutParams;
|
import android.view.ViewGroup.LayoutParams;
|
||||||
@@ -36,6 +37,7 @@ import javax.inject.Inject;
|
|||||||
import androidx.annotation.LayoutRes;
|
import androidx.annotation.LayoutRes;
|
||||||
import androidx.annotation.UiThread;
|
import androidx.annotation.UiThread;
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
import androidx.appcompat.view.ContextThemeWrapper;
|
||||||
import androidx.appcompat.widget.Toolbar;
|
import androidx.appcompat.widget.Toolbar;
|
||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
import androidx.fragment.app.FragmentManager;
|
import androidx.fragment.app.FragmentManager;
|
||||||
@@ -106,12 +108,24 @@ public abstract class BaseActivity extends AppCompatActivity
|
|||||||
for (ActivityLifecycleController alc : lifecycleControllers) {
|
for (ActivityLifecycleController alc : lifecycleControllers) {
|
||||||
alc.onActivityCreate(this);
|
alc.onActivityCreate(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Log.d("language", "BaseActivity#onCreate()");
|
||||||
|
Context baseContext = getBaseContext();
|
||||||
|
Log.d("language", "Context: " + getBaseContext().toString());
|
||||||
|
if (baseContext instanceof ContextThemeWrapper) {
|
||||||
|
ContextThemeWrapper wrapper = (ContextThemeWrapper) baseContext;
|
||||||
|
Context wrapped = wrapper.getBaseContext();
|
||||||
|
Log.d("language", "Wrapped: " + wrapped.toString());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void attachBaseContext(Context base) {
|
protected void attachBaseContext(Context base) {
|
||||||
|
Log.d("language", "BaseActivity#attachBaseContext()");
|
||||||
|
Log.d("language", "Context: " + base.toString());
|
||||||
super.attachBaseContext(
|
super.attachBaseContext(
|
||||||
Localizer.getInstance().setLocale(base));
|
Localizer.getInstance().setLocale(base));
|
||||||
|
Localizer.getInstance().setLocale(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ActivityComponent getActivityComponent() {
|
public ActivityComponent getActivityComponent() {
|
||||||
|
|||||||
@@ -16,7 +16,5 @@ public interface RequestCodes {
|
|||||||
int REQUEST_KEYGUARD_UNLOCK = 12;
|
int REQUEST_KEYGUARD_UNLOCK = 12;
|
||||||
int REQUEST_ATTACH_IMAGE = 13;
|
int REQUEST_ATTACH_IMAGE = 13;
|
||||||
int REQUEST_SAVE_ATTACHMENT = 14;
|
int REQUEST_SAVE_ATTACHMENT = 14;
|
||||||
int REQUEST_EXPORT_LOG = 15;
|
|
||||||
int REQUEST_EXPORT_OLD_LOG = 16;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package org.briarproject.bramble.logging;
|
package org.briarproject.briar.android.logging;
|
||||||
|
|
||||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
|
||||||
@@ -47,7 +47,6 @@ public class BriefLogFormatter extends Formatter {
|
|||||||
sb.append('\n');
|
sb.append('\n');
|
||||||
appendThrowable(sb, t);
|
appendThrowable(sb, t);
|
||||||
}
|
}
|
||||||
sb.append('\n');
|
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -14,21 +14,17 @@ import android.os.Looper;
|
|||||||
import org.acra.builder.ReportBuilder;
|
import org.acra.builder.ReportBuilder;
|
||||||
import org.acra.builder.ReportPrimer;
|
import org.acra.builder.ReportPrimer;
|
||||||
import org.briarproject.bramble.api.Pair;
|
import org.briarproject.bramble.api.Pair;
|
||||||
import org.briarproject.bramble.api.logging.PersistentLogManager;
|
|
||||||
import org.briarproject.briar.BuildConfig;
|
import org.briarproject.briar.BuildConfig;
|
||||||
import org.briarproject.briar.android.AndroidComponent;
|
|
||||||
import org.briarproject.briar.android.BriarApplication;
|
import org.briarproject.briar.android.BriarApplication;
|
||||||
|
import org.briarproject.briar.android.logging.BriefLogFormatter;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.LinkedList;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Scanner;
|
|
||||||
import java.util.concurrent.Callable;
|
import java.util.concurrent.Callable;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.concurrent.FutureTask;
|
import java.util.concurrent.FutureTask;
|
||||||
@@ -41,7 +37,6 @@ import static android.bluetooth.BluetoothAdapter.SCAN_MODE_CONNECTABLE;
|
|||||||
import static android.bluetooth.BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE;
|
import static android.bluetooth.BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE;
|
||||||
import static android.content.Context.ACTIVITY_SERVICE;
|
import static android.content.Context.ACTIVITY_SERVICE;
|
||||||
import static android.content.Context.CONNECTIVITY_SERVICE;
|
import static android.content.Context.CONNECTIVITY_SERVICE;
|
||||||
import static android.content.Context.MODE_PRIVATE;
|
|
||||||
import static android.content.Context.WIFI_P2P_SERVICE;
|
import static android.content.Context.WIFI_P2P_SERVICE;
|
||||||
import static android.content.Context.WIFI_SERVICE;
|
import static android.content.Context.WIFI_SERVICE;
|
||||||
import static android.net.ConnectivityManager.TYPE_MOBILE;
|
import static android.net.ConnectivityManager.TYPE_MOBILE;
|
||||||
@@ -56,8 +51,6 @@ import static org.briarproject.bramble.util.StringUtils.isNullOrEmpty;
|
|||||||
|
|
||||||
public class BriarReportPrimer implements ReportPrimer {
|
public class BriarReportPrimer implements ReportPrimer {
|
||||||
|
|
||||||
private static final int MAX_PERSISTED_LOG_LINES = 1_000;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void primeReport(@NonNull Context ctx,
|
public void primeReport(@NonNull Context ctx,
|
||||||
@NonNull ReportBuilder builder) {
|
@NonNull ReportBuilder builder) {
|
||||||
@@ -88,23 +81,13 @@ public class BriarReportPrimer implements ReportPrimer {
|
|||||||
// Log
|
// Log
|
||||||
BriarApplication app =
|
BriarApplication app =
|
||||||
(BriarApplication) ctx.getApplicationContext();
|
(BriarApplication) ctx.getApplicationContext();
|
||||||
AndroidComponent appComponent = app.getApplicationComponent();
|
|
||||||
PersistentLogManager logManager =
|
|
||||||
appComponent.persistentLogManager();
|
|
||||||
Formatter formatter = appComponent.formatter();
|
|
||||||
|
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
|
Formatter formatter = new BriefLogFormatter();
|
||||||
for (LogRecord record : app.getRecentLogRecords()) {
|
for (LogRecord record : app.getRecentLogRecords()) {
|
||||||
sb.append(formatter.format(record));
|
sb.append(formatter.format(record)).append('\n');
|
||||||
}
|
}
|
||||||
customData.put("Log", sb.toString());
|
customData.put("Log", sb.toString());
|
||||||
|
|
||||||
customData.put("Persisted log",
|
|
||||||
getPersistedLog(ctx, logManager, false));
|
|
||||||
|
|
||||||
customData.put("Previous persisted log",
|
|
||||||
getPersistedLog(ctx, logManager, true));
|
|
||||||
|
|
||||||
// System memory
|
// System memory
|
||||||
Object o = ctx.getSystemService(ACTIVITY_SERVICE);
|
Object o = ctx.getSystemService(ACTIVITY_SERVICE);
|
||||||
ActivityManager am = (ActivityManager) o;
|
ActivityManager am = (ActivityManager) o;
|
||||||
@@ -269,27 +252,6 @@ public class BriarReportPrimer implements ReportPrimer {
|
|||||||
|
|
||||||
return unmodifiableMap(customData);
|
return unmodifiableMap(customData);
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getPersistedLog(Context ctx,
|
|
||||||
PersistentLogManager logManager, boolean old) {
|
|
||||||
File logDir = ctx.getDir("log", MODE_PRIVATE);
|
|
||||||
StringBuilder sb = new StringBuilder();
|
|
||||||
try {
|
|
||||||
Scanner scanner = logManager.getPersistedLog(logDir, old);
|
|
||||||
LinkedList<String> lines = new LinkedList<>();
|
|
||||||
int numLines = 0;
|
|
||||||
while (scanner.hasNextLine()) {
|
|
||||||
lines.add(scanner.nextLine());
|
|
||||||
if (numLines == MAX_PERSISTED_LOG_LINES) lines.pollFirst();
|
|
||||||
else numLines++;
|
|
||||||
}
|
|
||||||
scanner.close();
|
|
||||||
for (String line : lines) sb.append(line).append('\n');
|
|
||||||
} catch (IOException e) {
|
|
||||||
sb.append("Could not recover persisted log: ").append(e);
|
|
||||||
}
|
|
||||||
return sb.toString();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class SingleShotAndroidExecutor extends Thread {
|
private static class SingleShotAndroidExecutor extends Thread {
|
||||||
|
|||||||
@@ -1,65 +1,18 @@
|
|||||||
package org.briarproject.briar.android.settings;
|
package org.briarproject.briar.android.settings;
|
||||||
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.net.Uri;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.widget.Toast;
|
|
||||||
|
|
||||||
import org.briarproject.bramble.api.lifecycle.IoExecutor;
|
|
||||||
import org.briarproject.bramble.api.logging.PersistentLogManager;
|
|
||||||
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
|
|
||||||
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
|
||||||
import org.briarproject.briar.R;
|
import org.briarproject.briar.R;
|
||||||
import org.briarproject.briar.android.activity.ActivityComponent;
|
import org.briarproject.briar.android.activity.ActivityComponent;
|
||||||
import org.briarproject.briar.android.activity.BriarActivity;
|
import org.briarproject.briar.android.activity.BriarActivity;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileOutputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.OutputStream;
|
|
||||||
import java.io.PrintWriter;
|
|
||||||
import java.util.Scanner;
|
|
||||||
import java.util.concurrent.Executor;
|
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
import javax.inject.Inject;
|
|
||||||
|
|
||||||
import androidx.annotation.RequiresApi;
|
|
||||||
import androidx.appcompat.app.ActionBar;
|
import androidx.appcompat.app.ActionBar;
|
||||||
|
|
||||||
import static android.content.Intent.ACTION_CREATE_DOCUMENT;
|
|
||||||
import static android.content.Intent.CATEGORY_OPENABLE;
|
|
||||||
import static android.content.Intent.EXTRA_TITLE;
|
|
||||||
import static android.os.Build.VERSION.SDK_INT;
|
|
||||||
import static android.os.Environment.DIRECTORY_DOWNLOADS;
|
|
||||||
import static android.os.Environment.getExternalStoragePublicDirectory;
|
|
||||||
import static android.widget.Toast.LENGTH_LONG;
|
|
||||||
import static java.util.logging.Level.WARNING;
|
|
||||||
import static java.util.logging.Logger.getLogger;
|
|
||||||
import static org.briarproject.bramble.util.LogUtils.logException;
|
|
||||||
import static org.briarproject.briar.android.activity.RequestCodes.REQUEST_EXPORT_LOG;
|
|
||||||
import static org.briarproject.briar.android.activity.RequestCodes.REQUEST_EXPORT_OLD_LOG;
|
|
||||||
|
|
||||||
@MethodsNotNullByDefault
|
|
||||||
@ParametersNotNullByDefault
|
|
||||||
public class SettingsActivity extends BriarActivity {
|
public class SettingsActivity extends BriarActivity {
|
||||||
|
|
||||||
private static final Logger LOG =
|
|
||||||
getLogger(SettingsActivity.class.getName());
|
|
||||||
|
|
||||||
private static final String LOG_EXPORT_FILENAME = "briar-log.txt";
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
@IoExecutor
|
|
||||||
Executor ioExecutor;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
PersistentLogManager logManager;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(@Nullable Bundle bundle) {
|
public void onCreate(Bundle bundle) {
|
||||||
super.onCreate(bundle);
|
super.onCreate(bundle);
|
||||||
|
|
||||||
ActionBar actionBar = getSupportActionBar();
|
ActionBar actionBar = getSupportActionBar();
|
||||||
@@ -84,96 +37,4 @@ public class SettingsActivity extends BriarActivity {
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onActivityResult(int request, int result,
|
|
||||||
@Nullable Intent data) {
|
|
||||||
super.onActivityResult(request, result, data);
|
|
||||||
if (request == REQUEST_EXPORT_LOG && result == RESULT_OK &&
|
|
||||||
data != null && data.getData() != null) {
|
|
||||||
exportLog(false, data.getData());
|
|
||||||
} else if (request == REQUEST_EXPORT_OLD_LOG && result == RESULT_OK &&
|
|
||||||
data != null && data.getData() != null) {
|
|
||||||
exportLog(true, data.getData());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void exportLog(boolean old, Uri uri) {
|
|
||||||
copyLog(old, () -> getOutputStream(uri));
|
|
||||||
}
|
|
||||||
|
|
||||||
private void copyLog(boolean old, OutputStreamProvider osp) {
|
|
||||||
ioExecutor.execute(() -> {
|
|
||||||
try {
|
|
||||||
File logDir = getApplication().getDir("log", MODE_PRIVATE);
|
|
||||||
Scanner scanner = logManager.getPersistedLog(logDir, old);
|
|
||||||
if (!scanner.hasNextLine()) {
|
|
||||||
scanner.close();
|
|
||||||
runOnUiThreadUnlessDestroyed(() ->
|
|
||||||
Toast.makeText(getApplication(), "Log is empty",
|
|
||||||
LENGTH_LONG).show());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
PrintWriter w = new PrintWriter(osp.getOutputStream());
|
|
||||||
while (scanner.hasNextLine()) w.println(scanner.nextLine());
|
|
||||||
w.flush();
|
|
||||||
w.close();
|
|
||||||
scanner.close();
|
|
||||||
runOnUiThreadUnlessDestroyed(() ->
|
|
||||||
Toast.makeText(getApplication(), "Log exported",
|
|
||||||
LENGTH_LONG).show());
|
|
||||||
} catch (IOException e) {
|
|
||||||
logException(LOG, WARNING, e);
|
|
||||||
runOnUiThreadUnlessDestroyed(() ->
|
|
||||||
Toast.makeText(getApplication(), "Failed to export log",
|
|
||||||
LENGTH_LONG).show());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
void onExportLogClick(boolean old) {
|
|
||||||
if (SDK_INT >= 19) {
|
|
||||||
Intent intent = getExportLogIntent();
|
|
||||||
int request = old ? REQUEST_EXPORT_OLD_LOG : REQUEST_EXPORT_LOG;
|
|
||||||
startActivityForResult(intent, request);
|
|
||||||
} else {
|
|
||||||
exportLog(old);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@RequiresApi(api = 19)
|
|
||||||
private Intent getExportLogIntent() {
|
|
||||||
Intent intent = new Intent(ACTION_CREATE_DOCUMENT);
|
|
||||||
intent.addCategory(CATEGORY_OPENABLE);
|
|
||||||
intent.setType("text/plain");
|
|
||||||
intent.putExtra(EXTRA_TITLE, LOG_EXPORT_FILENAME);
|
|
||||||
return intent;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void exportLog(boolean old) {
|
|
||||||
File file = getLogOutputFile();
|
|
||||||
copyLog(old, () -> getOutputStream(file));
|
|
||||||
}
|
|
||||||
|
|
||||||
private File getLogOutputFile() {
|
|
||||||
File path = getExternalStoragePublicDirectory(DIRECTORY_DOWNLOADS);
|
|
||||||
//noinspection ResultOfMethodCallIgnored
|
|
||||||
path.mkdirs();
|
|
||||||
return new File(path, LOG_EXPORT_FILENAME);
|
|
||||||
}
|
|
||||||
|
|
||||||
private OutputStream getOutputStream(File file) throws IOException {
|
|
||||||
return new FileOutputStream(file);
|
|
||||||
}
|
|
||||||
|
|
||||||
private OutputStream getOutputStream(Uri uri) throws IOException {
|
|
||||||
OutputStream os =
|
|
||||||
getApplication().getContentResolver().openOutputStream(uri);
|
|
||||||
if (os == null) throw new IOException();
|
|
||||||
return os;
|
|
||||||
}
|
|
||||||
|
|
||||||
private interface OutputStreamProvider {
|
|
||||||
OutputStream getOutputStream() throws IOException;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package org.briarproject.briar.android.settings;
|
package org.briarproject.briar.android.settings;
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
|
||||||
import android.annotation.TargetApi;
|
import android.annotation.TargetApi;
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
@@ -75,7 +74,6 @@ import static android.widget.Toast.LENGTH_SHORT;
|
|||||||
import static androidx.core.view.ViewCompat.LAYOUT_DIRECTION_LTR;
|
import static androidx.core.view.ViewCompat.LAYOUT_DIRECTION_LTR;
|
||||||
import static java.util.logging.Level.INFO;
|
import static java.util.logging.Level.INFO;
|
||||||
import static java.util.logging.Level.WARNING;
|
import static java.util.logging.Level.WARNING;
|
||||||
import static java.util.logging.Logger.getLogger;
|
|
||||||
import static org.briarproject.bramble.api.plugin.Plugin.PREF_PLUGIN_ENABLE;
|
import static org.briarproject.bramble.api.plugin.Plugin.PREF_PLUGIN_ENABLE;
|
||||||
import static org.briarproject.bramble.api.plugin.TorConstants.DEFAULT_PREF_TOR_MOBILE;
|
import static org.briarproject.bramble.api.plugin.TorConstants.DEFAULT_PREF_TOR_MOBILE;
|
||||||
import static org.briarproject.bramble.api.plugin.TorConstants.DEFAULT_PREF_TOR_NETWORK;
|
import static org.briarproject.bramble.api.plugin.TorConstants.DEFAULT_PREF_TOR_NETWORK;
|
||||||
@@ -135,7 +133,7 @@ public class SettingsFragment extends PreferenceFragmentCompat
|
|||||||
"pref_key_tor_only_when_charging";
|
"pref_key_tor_only_when_charging";
|
||||||
|
|
||||||
private static final Logger LOG =
|
private static final Logger LOG =
|
||||||
getLogger(SettingsFragment.class.getName());
|
Logger.getLogger(SettingsFragment.class.getName());
|
||||||
|
|
||||||
private SettingsActivity listener;
|
private SettingsActivity listener;
|
||||||
private ListPreference language;
|
private ListPreference language;
|
||||||
@@ -253,25 +251,8 @@ public class SettingsFragment extends PreferenceFragmentCompat
|
|||||||
throw new RuntimeException("Boom!");
|
throw new RuntimeException("Boom!");
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
findPreference("pref_key_export_log").setOnPreferenceClickListener(
|
|
||||||
preference -> {
|
|
||||||
((SettingsActivity) requireActivity())
|
|
||||||
.onExportLogClick(false);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
);
|
|
||||||
findPreference("pref_key_export_old_log")
|
|
||||||
.setOnPreferenceClickListener(
|
|
||||||
preference -> {
|
|
||||||
((SettingsActivity) requireActivity())
|
|
||||||
.onExportLogClick(true);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
);
|
|
||||||
} else {
|
} else {
|
||||||
findPreference("pref_key_explode").setVisible(false);
|
findPreference("pref_key_explode").setVisible(false);
|
||||||
findPreference("pref_key_export_log").setVisible(false);
|
|
||||||
findPreference("pref_key_export_old_log").setVisible(false);
|
|
||||||
findPreference("pref_key_test_data").setVisible(false);
|
findPreference("pref_key_test_data").setVisible(false);
|
||||||
PreferenceGroup testing =
|
PreferenceGroup testing =
|
||||||
findPreference("pref_key_explode").getParent();
|
findPreference("pref_key_explode").getParent();
|
||||||
@@ -350,7 +331,6 @@ public class SettingsFragment extends PreferenceFragmentCompat
|
|||||||
return direction == LAYOUT_DIRECTION_LTR;
|
return direction == LAYOUT_DIRECTION_LTR;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressLint("StringFormatInvalid")
|
|
||||||
private void setTorNetworkSummary(int torNetworkSetting) {
|
private void setTorNetworkSummary(int torNetworkSetting) {
|
||||||
if (torNetworkSetting != PREF_TOR_NETWORK_AUTOMATIC) {
|
if (torNetworkSetting != PREF_TOR_NETWORK_AUTOMATIC) {
|
||||||
torNetwork.setSummary("%s"); // use setting value
|
torNetwork.setSummary("%s"); // use setting value
|
||||||
|
|||||||
@@ -227,16 +227,6 @@
|
|||||||
android:targetPackage="@string/app_package"/>
|
android:targetPackage="@string/app_package"/>
|
||||||
</Preference>
|
</Preference>
|
||||||
|
|
||||||
<Preference
|
|
||||||
android:key="pref_key_export_log"
|
|
||||||
android:title="Export Current Log to SD Card"
|
|
||||||
app:iconSpaceReserved="false"/>
|
|
||||||
|
|
||||||
<Preference
|
|
||||||
android:key="pref_key_export_old_log"
|
|
||||||
android:title="Export Previous Log to SD Card"
|
|
||||||
app:iconSpaceReserved="false"/>
|
|
||||||
|
|
||||||
<Preference
|
<Preference
|
||||||
android:key="pref_key_explode"
|
android:key="pref_key_explode"
|
||||||
android:title="Crash"
|
android:title="Crash"
|
||||||
|
|||||||
@@ -68,8 +68,7 @@ Returns a JSON array of contacts:
|
|||||||
"alias" : "A local nickname",
|
"alias" : "A local nickname",
|
||||||
"handshakePublicKey": "XnYRd7a7E4CTqgAvh4hCxh/YZ0EPscxknB9ZcEOpSzY=",
|
"handshakePublicKey": "XnYRd7a7E4CTqgAvh4hCxh/YZ0EPscxknB9ZcEOpSzY=",
|
||||||
"verified": true,
|
"verified": true,
|
||||||
"lastChatActivity": 1557838312175,
|
"lastChatActivity": 1557838312175
|
||||||
"connected": false
|
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -393,19 +392,3 @@ will no longer work on making this `pendingContact` become `contact`.
|
|||||||
"type": "event"
|
"type": "event"
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
### A contact connected or disconnected
|
|
||||||
|
|
||||||
When Briar establishes a connection to a contact (the contact comes online),
|
|
||||||
it sends a `ContactConnectedEvent`.
|
|
||||||
When the last connection is lost (the contact goes offline), it sends a `ContactDisconnectedEvent`.
|
|
||||||
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"data": {
|
|
||||||
"contactId": 1
|
|
||||||
},
|
|
||||||
"name": "ContactConnectedEvent",
|
|
||||||
"type": "event"
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import com.fasterxml.jackson.databind.ObjectMapper
|
|||||||
import io.javalin.http.BadRequestResponse
|
import io.javalin.http.BadRequestResponse
|
||||||
import io.javalin.http.Context
|
import io.javalin.http.Context
|
||||||
import io.javalin.http.NotFoundResponse
|
import io.javalin.http.NotFoundResponse
|
||||||
import org.briarproject.bramble.api.connection.ConnectionRegistry
|
|
||||||
import org.briarproject.bramble.api.contact.ContactManager
|
import org.briarproject.bramble.api.contact.ContactManager
|
||||||
import org.briarproject.bramble.api.contact.HandshakeLinkConstants.LINK_REGEX
|
import org.briarproject.bramble.api.contact.HandshakeLinkConstants.LINK_REGEX
|
||||||
import org.briarproject.bramble.api.contact.PendingContactId
|
import org.briarproject.bramble.api.contact.PendingContactId
|
||||||
@@ -17,8 +16,6 @@ import org.briarproject.bramble.api.db.NoSuchPendingContactException
|
|||||||
import org.briarproject.bramble.api.event.Event
|
import org.briarproject.bramble.api.event.Event
|
||||||
import org.briarproject.bramble.api.event.EventListener
|
import org.briarproject.bramble.api.event.EventListener
|
||||||
import org.briarproject.bramble.api.identity.AuthorConstants.MAX_AUTHOR_NAME_LENGTH
|
import org.briarproject.bramble.api.identity.AuthorConstants.MAX_AUTHOR_NAME_LENGTH
|
||||||
import org.briarproject.bramble.api.plugin.event.ContactConnectedEvent
|
|
||||||
import org.briarproject.bramble.api.plugin.event.ContactDisconnectedEvent
|
|
||||||
import org.briarproject.bramble.util.StringUtils.toUtf8
|
import org.briarproject.bramble.util.StringUtils.toUtf8
|
||||||
import org.briarproject.briar.api.conversation.ConversationManager
|
import org.briarproject.briar.api.conversation.ConversationManager
|
||||||
import org.briarproject.briar.headless.event.WebSocketController
|
import org.briarproject.briar.headless.event.WebSocketController
|
||||||
@@ -35,8 +32,6 @@ internal const val EVENT_CONTACT_ADDED = "ContactAddedEvent"
|
|||||||
internal const val EVENT_PENDING_CONTACT_STATE_CHANGED = "PendingContactStateChangedEvent"
|
internal const val EVENT_PENDING_CONTACT_STATE_CHANGED = "PendingContactStateChangedEvent"
|
||||||
internal const val EVENT_PENDING_CONTACT_ADDED = "PendingContactAddedEvent"
|
internal const val EVENT_PENDING_CONTACT_ADDED = "PendingContactAddedEvent"
|
||||||
internal const val EVENT_PENDING_CONTACT_REMOVED = "PendingContactRemovedEvent"
|
internal const val EVENT_PENDING_CONTACT_REMOVED = "PendingContactRemovedEvent"
|
||||||
internal const val EVENT_CONTACT_CONNECTED = "ContactConnectedEvent"
|
|
||||||
internal const val EVENT_CONTACT_DISCONNECTED = "ContactDisconnectedEvent"
|
|
||||||
|
|
||||||
@Immutable
|
@Immutable
|
||||||
@Singleton
|
@Singleton
|
||||||
@@ -46,8 +41,7 @@ constructor(
|
|||||||
private val contactManager: ContactManager,
|
private val contactManager: ContactManager,
|
||||||
private val conversationManager: ConversationManager,
|
private val conversationManager: ConversationManager,
|
||||||
private val objectMapper: ObjectMapper,
|
private val objectMapper: ObjectMapper,
|
||||||
private val webSocket: WebSocketController,
|
private val webSocket: WebSocketController
|
||||||
private val connectionRegistry: ConnectionRegistry
|
|
||||||
) : ContactController, EventListener {
|
) : ContactController, EventListener {
|
||||||
|
|
||||||
override fun eventOccurred(e: Event) = when (e) {
|
override fun eventOccurred(e: Event) = when (e) {
|
||||||
@@ -63,12 +57,6 @@ constructor(
|
|||||||
is PendingContactRemovedEvent -> {
|
is PendingContactRemovedEvent -> {
|
||||||
webSocket.sendEvent(EVENT_PENDING_CONTACT_REMOVED, e.output())
|
webSocket.sendEvent(EVENT_PENDING_CONTACT_REMOVED, e.output())
|
||||||
}
|
}
|
||||||
is ContactConnectedEvent -> {
|
|
||||||
webSocket.sendEvent(EVENT_CONTACT_CONNECTED, e.output())
|
|
||||||
}
|
|
||||||
is ContactDisconnectedEvent -> {
|
|
||||||
webSocket.sendEvent(EVENT_CONTACT_DISCONNECTED, e.output())
|
|
||||||
}
|
|
||||||
else -> {
|
else -> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -76,8 +64,7 @@ constructor(
|
|||||||
override fun list(ctx: Context): Context {
|
override fun list(ctx: Context): Context {
|
||||||
val contacts = contactManager.contacts.map { contact ->
|
val contacts = contactManager.contacts.map { contact ->
|
||||||
val latestMsgTime = conversationManager.getGroupCount(contact.id).latestMsgTime
|
val latestMsgTime = conversationManager.getGroupCount(contact.id).latestMsgTime
|
||||||
val connected = connectionRegistry.isConnected(contact.id)
|
contact.output(latestMsgTime)
|
||||||
contact.output(latestMsgTime, connected)
|
|
||||||
}
|
}
|
||||||
return ctx.json(contacts)
|
return ctx.json(contacts)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,17 +2,15 @@ package org.briarproject.briar.headless.contact
|
|||||||
|
|
||||||
import org.briarproject.bramble.api.contact.Contact
|
import org.briarproject.bramble.api.contact.Contact
|
||||||
import org.briarproject.bramble.api.contact.event.ContactAddedEvent
|
import org.briarproject.bramble.api.contact.event.ContactAddedEvent
|
||||||
import org.briarproject.bramble.api.plugin.event.ContactConnectedEvent
|
|
||||||
import org.briarproject.bramble.api.plugin.event.ContactDisconnectedEvent
|
|
||||||
import org.briarproject.bramble.identity.output
|
import org.briarproject.bramble.identity.output
|
||||||
|
import org.briarproject.briar.api.conversation.ConversationManager
|
||||||
import org.briarproject.briar.headless.json.JsonDict
|
import org.briarproject.briar.headless.json.JsonDict
|
||||||
|
|
||||||
internal fun Contact.output(latestMsgTime: Long, connected: Boolean) = JsonDict(
|
internal fun Contact.output(latestMsgTime: Long) = JsonDict(
|
||||||
"contactId" to id.int,
|
"contactId" to id.int,
|
||||||
"author" to author.output(),
|
"author" to author.output(),
|
||||||
"verified" to isVerified,
|
"verified" to isVerified,
|
||||||
"lastChatActivity" to latestMsgTime,
|
"lastChatActivity" to latestMsgTime
|
||||||
"connected" to connected
|
|
||||||
).apply {
|
).apply {
|
||||||
alias?.let { put("alias", it) }
|
alias?.let { put("alias", it) }
|
||||||
handshakePublicKey?.let { put("handshakePublicKey", it.encoded) }
|
handshakePublicKey?.let { put("handshakePublicKey", it.encoded) }
|
||||||
@@ -22,11 +20,3 @@ internal fun ContactAddedEvent.output() = JsonDict(
|
|||||||
"contactId" to contactId.int,
|
"contactId" to contactId.int,
|
||||||
"verified" to isVerified
|
"verified" to isVerified
|
||||||
)
|
)
|
||||||
|
|
||||||
internal fun ContactConnectedEvent.output() = JsonDict(
|
|
||||||
"contactId" to contactId.int
|
|
||||||
)
|
|
||||||
|
|
||||||
internal fun ContactDisconnectedEvent.output() = JsonDict(
|
|
||||||
"contactId" to contactId.int
|
|
||||||
)
|
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import com.fasterxml.jackson.databind.ObjectMapper
|
|||||||
import io.javalin.http.Context
|
import io.javalin.http.Context
|
||||||
import io.javalin.http.util.ContextUtil
|
import io.javalin.http.util.ContextUtil
|
||||||
import io.mockk.mockk
|
import io.mockk.mockk
|
||||||
import org.briarproject.bramble.api.connection.ConnectionRegistry
|
|
||||||
import org.briarproject.bramble.api.contact.Contact
|
import org.briarproject.bramble.api.contact.Contact
|
||||||
import org.briarproject.bramble.api.contact.ContactManager
|
import org.briarproject.bramble.api.contact.ContactManager
|
||||||
import org.briarproject.bramble.api.identity.Author
|
import org.briarproject.bramble.api.identity.Author
|
||||||
@@ -27,7 +26,6 @@ abstract class ControllerTest {
|
|||||||
protected val contactManager = mockk<ContactManager>()
|
protected val contactManager = mockk<ContactManager>()
|
||||||
protected val conversationManager = mockk<ConversationManager>()
|
protected val conversationManager = mockk<ConversationManager>()
|
||||||
protected val identityManager = mockk<IdentityManager>()
|
protected val identityManager = mockk<IdentityManager>()
|
||||||
protected val connectionRegistry = mockk<ConnectionRegistry>()
|
|
||||||
protected val clock = mockk<Clock>()
|
protected val clock = mockk<Clock>()
|
||||||
protected val ctx = mockk<Context>()
|
protected val ctx = mockk<Context>()
|
||||||
|
|
||||||
|
|||||||
@@ -20,8 +20,6 @@ import org.briarproject.bramble.api.contact.event.PendingContactStateChangedEven
|
|||||||
import org.briarproject.bramble.api.db.NoSuchContactException
|
import org.briarproject.bramble.api.db.NoSuchContactException
|
||||||
import org.briarproject.bramble.api.db.NoSuchPendingContactException
|
import org.briarproject.bramble.api.db.NoSuchPendingContactException
|
||||||
import org.briarproject.bramble.api.identity.AuthorConstants.MAX_AUTHOR_NAME_LENGTH
|
import org.briarproject.bramble.api.identity.AuthorConstants.MAX_AUTHOR_NAME_LENGTH
|
||||||
import org.briarproject.bramble.api.plugin.event.ContactConnectedEvent
|
|
||||||
import org.briarproject.bramble.api.plugin.event.ContactDisconnectedEvent
|
|
||||||
import org.briarproject.bramble.identity.output
|
import org.briarproject.bramble.identity.output
|
||||||
import org.briarproject.bramble.test.TestUtils.getPendingContact
|
import org.briarproject.bramble.test.TestUtils.getPendingContact
|
||||||
import org.briarproject.bramble.test.TestUtils.getRandomBytes
|
import org.briarproject.bramble.test.TestUtils.getRandomBytes
|
||||||
@@ -31,7 +29,6 @@ import org.briarproject.briar.headless.json.JsonDict
|
|||||||
import org.junit.jupiter.api.Assertions.assertNotNull
|
import org.junit.jupiter.api.Assertions.assertNotNull
|
||||||
import org.junit.jupiter.api.Assertions.assertThrows
|
import org.junit.jupiter.api.Assertions.assertThrows
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
import kotlin.random.Random
|
|
||||||
|
|
||||||
internal class ContactControllerTest : ControllerTest() {
|
internal class ContactControllerTest : ControllerTest() {
|
||||||
|
|
||||||
@@ -41,8 +38,7 @@ internal class ContactControllerTest : ControllerTest() {
|
|||||||
contactManager,
|
contactManager,
|
||||||
conversationManager,
|
conversationManager,
|
||||||
objectMapper,
|
objectMapper,
|
||||||
webSocketController,
|
webSocketController
|
||||||
connectionRegistry
|
|
||||||
)
|
)
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -54,11 +50,9 @@ internal class ContactControllerTest : ControllerTest() {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testList() {
|
fun testList() {
|
||||||
val connected = Random.nextBoolean()
|
|
||||||
every { contactManager.contacts } returns listOf(contact)
|
every { contactManager.contacts } returns listOf(contact)
|
||||||
every { conversationManager.getGroupCount(contact.id).latestMsgTime } returns timestamp
|
every { conversationManager.getGroupCount(contact.id).latestMsgTime } returns timestamp
|
||||||
every { connectionRegistry.isConnected(contact.id) } returns connected
|
every { ctx.json(listOf(contact.output(timestamp))) } returns ctx
|
||||||
every { ctx.json(listOf(contact.output(timestamp, connected))) } returns ctx
|
|
||||||
controller.list(ctx)
|
controller.list(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -273,37 +267,8 @@ internal class ContactControllerTest : ControllerTest() {
|
|||||||
controller.eventOccurred(event)
|
controller.eventOccurred(event)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
fun testContactConnectedEvent() {
|
|
||||||
val event = ContactConnectedEvent(contact.id)
|
|
||||||
|
|
||||||
every {
|
|
||||||
webSocketController.sendEvent(
|
|
||||||
EVENT_CONTACT_CONNECTED,
|
|
||||||
event.output()
|
|
||||||
)
|
|
||||||
} just runs
|
|
||||||
|
|
||||||
controller.eventOccurred(event)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun testContactDisconnectedEvent() {
|
|
||||||
val event = ContactDisconnectedEvent(contact.id)
|
|
||||||
|
|
||||||
every {
|
|
||||||
webSocketController.sendEvent(
|
|
||||||
EVENT_CONTACT_DISCONNECTED,
|
|
||||||
event.output()
|
|
||||||
)
|
|
||||||
} just runs
|
|
||||||
|
|
||||||
controller.eventOccurred(event)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testOutputContact() {
|
fun testOutputContact() {
|
||||||
val connected = Random.nextBoolean()
|
|
||||||
assertNotNull(contact.handshakePublicKey)
|
assertNotNull(contact.handshakePublicKey)
|
||||||
val json = """
|
val json = """
|
||||||
{
|
{
|
||||||
@@ -312,11 +277,10 @@ internal class ContactControllerTest : ControllerTest() {
|
|||||||
"alias" : "${contact.alias}",
|
"alias" : "${contact.alias}",
|
||||||
"handshakePublicKey": ${toJson(contact.handshakePublicKey!!.encoded)},
|
"handshakePublicKey": ${toJson(contact.handshakePublicKey!!.encoded)},
|
||||||
"verified": ${contact.isVerified},
|
"verified": ${contact.isVerified},
|
||||||
"lastChatActivity": $timestamp,
|
"lastChatActivity": $timestamp
|
||||||
"connected": $connected
|
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
assertJsonEquals(json, contact.output(timestamp, connected))
|
assertJsonEquals(json, contact.output(timestamp))
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -394,26 +358,4 @@ internal class ContactControllerTest : ControllerTest() {
|
|||||||
assertJsonEquals(json, event.output())
|
assertJsonEquals(json, event.output())
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
fun testOutputContactConnectedEvent() {
|
|
||||||
val event = ContactConnectedEvent(contact.id)
|
|
||||||
val json = """
|
|
||||||
{
|
|
||||||
"contactId": ${contact.id.int}
|
|
||||||
}
|
|
||||||
"""
|
|
||||||
assertJsonEquals(json, event.output())
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun testOutputContactDisconnectedEvent() {
|
|
||||||
val event = ContactDisconnectedEvent(contact.id)
|
|
||||||
val json = """
|
|
||||||
{
|
|
||||||
"contactId": ${contact.id.int}
|
|
||||||
}
|
|
||||||
"""
|
|
||||||
assertJsonEquals(json, event.output())
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user