mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-18 05:39:53 +01:00
Merge branch '1219-account-exists' into 'master'
Add logging to debug account creation and deletion See merge request akwizgran/briar!793
This commit is contained in:
@@ -6,15 +6,22 @@ import android.os.Build;
|
|||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Scanner;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import static android.content.Context.MODE_PRIVATE;
|
import static android.content.Context.MODE_PRIVATE;
|
||||||
|
import static java.util.logging.Level.INFO;
|
||||||
|
|
||||||
public class AndroidUtils {
|
public class AndroidUtils {
|
||||||
|
|
||||||
|
private static final Logger LOG =
|
||||||
|
Logger.getLogger(AndroidUtils.class.getName());
|
||||||
|
|
||||||
// Fake Bluetooth address returned by BluetoothAdapter on API 23 and later
|
// Fake Bluetooth address returned by BluetoothAdapter on API 23 and later
|
||||||
private static final String FAKE_BLUETOOTH_ADDRESS = "02:00:00:00:00:00";
|
private static final String FAKE_BLUETOOTH_ADDRESS = "02:00:00:00:00:00";
|
||||||
|
|
||||||
@@ -51,17 +58,66 @@ public class AndroidUtils {
|
|||||||
&& !address.equals(FAKE_BLUETOOTH_ADDRESS);
|
&& !address.equals(FAKE_BLUETOOTH_ADDRESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void logDataDirContents(Context ctx) {
|
||||||
|
if (LOG.isLoggable(INFO)) {
|
||||||
|
LOG.info("Contents of data directory:");
|
||||||
|
logFileOrDir(new File(ctx.getApplicationInfo().dataDir));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void logFileOrDir(File f) {
|
||||||
|
LOG.info(f.getAbsolutePath() + " " + f.length());
|
||||||
|
if (f.isDirectory()) {
|
||||||
|
File[] children = f.listFiles();
|
||||||
|
if (children == null) {
|
||||||
|
LOG.info("Could not list files in " + f.getAbsolutePath());
|
||||||
|
} else {
|
||||||
|
for (File child : children) logFileOrDir(child);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static File getSharedPrefsFile(Context ctx, String name) {
|
||||||
|
File dataDir = new File(ctx.getApplicationInfo().dataDir);
|
||||||
|
File prefsDir = new File(dataDir, "shared_prefs");
|
||||||
|
return new File(prefsDir, name + ".xml");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void logFileContents(File f) {
|
||||||
|
if (LOG.isLoggable(INFO)) {
|
||||||
|
LOG.info("Contents of " + f.getAbsolutePath() + ":");
|
||||||
|
try {
|
||||||
|
Scanner s = new Scanner(f);
|
||||||
|
while (s.hasNextLine()) LOG.info(s.nextLine());
|
||||||
|
s.close();
|
||||||
|
} catch (FileNotFoundException e) {
|
||||||
|
LOG.info(f.getAbsolutePath() + " not found");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static void deleteAppData(Context ctx) {
|
public static void deleteAppData(Context ctx) {
|
||||||
File dataDir = new File(ctx.getApplicationInfo().dataDir);
|
File dataDir = new File(ctx.getApplicationInfo().dataDir);
|
||||||
|
if (LOG.isLoggable(INFO))
|
||||||
|
LOG.info("Deleting app data from " + dataDir.getAbsolutePath());
|
||||||
File[] children = dataDir.listFiles();
|
File[] children = dataDir.listFiles();
|
||||||
if (children != null) {
|
if (children != null) {
|
||||||
for (File child : children) {
|
for (File child : children) {
|
||||||
if (!child.getName().equals("lib"))
|
if (!child.getName().equals("lib")) {
|
||||||
|
if (LOG.isLoggable(INFO))
|
||||||
|
LOG.info("Deleting " + child.getAbsolutePath());
|
||||||
IoUtils.deleteFileOrDir(child);
|
IoUtils.deleteFileOrDir(child);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} else if (LOG.isLoggable(INFO)) {
|
||||||
|
LOG.info("Could not list files in " + dataDir.getAbsolutePath());
|
||||||
}
|
}
|
||||||
// Recreate the cache dir as some OpenGL drivers expect it to exist
|
// Recreate the cache dir as some OpenGL drivers expect it to exist
|
||||||
new File(dataDir, "cache").mkdir();
|
boolean recreated = new File(dataDir, "cache").mkdir();
|
||||||
|
if (LOG.isLoggable(INFO)) {
|
||||||
|
if (recreated) LOG.info("Recreated cache dir");
|
||||||
|
else LOG.info("Could not recreate cache dir");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static File getReportDir(Context ctx) {
|
public static File getReportDir(Context ctx) {
|
||||||
|
|||||||
@@ -9,25 +9,37 @@ import java.io.IOException;
|
|||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
import static java.util.logging.Level.INFO;
|
||||||
|
|
||||||
@NotNullByDefault
|
@NotNullByDefault
|
||||||
public class IoUtils {
|
public class IoUtils {
|
||||||
|
|
||||||
|
private static final Logger LOG = Logger.getLogger(IoUtils.class.getName());
|
||||||
|
|
||||||
public static void deleteFileOrDir(File f) {
|
public static void deleteFileOrDir(File f) {
|
||||||
if (f.isFile()) {
|
if (f.isFile()) {
|
||||||
f.delete();
|
delete(f);
|
||||||
} else if (f.isDirectory()) {
|
} else if (f.isDirectory()) {
|
||||||
File[] children = f.listFiles();
|
File[] children = f.listFiles();
|
||||||
if (children != null)
|
if (children != null)
|
||||||
for (File child : children) deleteFileOrDir(child);
|
for (File child : children) deleteFileOrDir(child);
|
||||||
f.delete();
|
delete(f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void copyAndClose(InputStream in, OutputStream out)
|
private static void delete(File f) {
|
||||||
throws IOException {
|
boolean deleted = f.delete();
|
||||||
|
if (LOG.isLoggable(INFO)) {
|
||||||
|
if (deleted) LOG.info("Deleted " + f.getAbsolutePath());
|
||||||
|
else LOG.info("Could not delete " + f.getAbsolutePath());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void copyAndClose(InputStream in, OutputStream out) {
|
||||||
byte[] buf = new byte[4096];
|
byte[] buf = new byte[4096];
|
||||||
try {
|
try {
|
||||||
while (true) {
|
while (true) {
|
||||||
|
|||||||
@@ -0,0 +1,94 @@
|
|||||||
|
package org.briarproject.briar.android;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.crypto.SecretKey;
|
||||||
|
import org.briarproject.bramble.api.db.DatabaseConfig;
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
import static java.util.logging.Level.INFO;
|
||||||
|
|
||||||
|
@NotNullByDefault
|
||||||
|
class AndroidDatabaseConfig implements DatabaseConfig {
|
||||||
|
|
||||||
|
private static final Logger LOG =
|
||||||
|
Logger.getLogger(AndroidDatabaseConfig.class.getName());
|
||||||
|
|
||||||
|
private final File dir;
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
private volatile SecretKey key = null;
|
||||||
|
@Nullable
|
||||||
|
private volatile String nickname = null;
|
||||||
|
|
||||||
|
AndroidDatabaseConfig(File dir) {
|
||||||
|
this.dir = dir;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean databaseExists() {
|
||||||
|
// FIXME should not run on UiThread #620
|
||||||
|
if (!dir.isDirectory()) {
|
||||||
|
if (LOG.isLoggable(INFO))
|
||||||
|
LOG.info(dir.getAbsolutePath() + " is not a directory");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
File[] files = dir.listFiles();
|
||||||
|
if (LOG.isLoggable(INFO)) {
|
||||||
|
if (files == null) {
|
||||||
|
LOG.info("Could not list files in " + dir.getAbsolutePath());
|
||||||
|
} else {
|
||||||
|
LOG.info("Files in " + dir.getAbsolutePath() + ":");
|
||||||
|
for (File f : files) LOG.info(f.getName());
|
||||||
|
}
|
||||||
|
LOG.info("Database exists: " + (files != null && files.length > 0));
|
||||||
|
}
|
||||||
|
return files != null && files.length > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public File getDatabaseDirectory() {
|
||||||
|
File dir = this.dir;
|
||||||
|
if (LOG.isLoggable(INFO))
|
||||||
|
LOG.info("Database directory: " + dir.getAbsolutePath());
|
||||||
|
return dir;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setEncryptionKey(SecretKey key) {
|
||||||
|
LOG.info("Setting database key");
|
||||||
|
this.key = key;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setLocalAuthorName(String nickname) {
|
||||||
|
LOG.info("Setting local author name");
|
||||||
|
this.nickname = nickname;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Nullable
|
||||||
|
public String getLocalAuthorName() {
|
||||||
|
String nickname = this.nickname;
|
||||||
|
if (LOG.isLoggable(INFO))
|
||||||
|
LOG.info("Local author name has been set: " + (nickname != null));
|
||||||
|
return nickname;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Nullable
|
||||||
|
public SecretKey getEncryptionKey() {
|
||||||
|
SecretKey key = this.key;
|
||||||
|
if (LOG.isLoggable(INFO))
|
||||||
|
LOG.info("Database key has been set: " + (key != null));
|
||||||
|
return key;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long getMaxSize() {
|
||||||
|
return Long.MAX_VALUE;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,7 +5,6 @@ import android.content.SharedPreferences;
|
|||||||
|
|
||||||
import org.briarproject.bramble.api.crypto.CryptoComponent;
|
import org.briarproject.bramble.api.crypto.CryptoComponent;
|
||||||
import org.briarproject.bramble.api.crypto.PublicKey;
|
import org.briarproject.bramble.api.crypto.PublicKey;
|
||||||
import org.briarproject.bramble.api.crypto.SecretKey;
|
|
||||||
import org.briarproject.bramble.api.db.DatabaseConfig;
|
import org.briarproject.bramble.api.db.DatabaseConfig;
|
||||||
import org.briarproject.bramble.api.event.EventBus;
|
import org.briarproject.bramble.api.event.EventBus;
|
||||||
import org.briarproject.bramble.api.lifecycle.LifecycleManager;
|
import org.briarproject.bramble.api.lifecycle.LifecycleManager;
|
||||||
@@ -23,7 +22,6 @@ import org.briarproject.briar.api.android.ScreenFilterMonitor;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.security.GeneralSecurityException;
|
import java.security.GeneralSecurityException;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
@@ -87,51 +85,7 @@ public class AppModule {
|
|||||||
File dir = app.getApplicationContext().getDir("db", MODE_PRIVATE);
|
File dir = app.getApplicationContext().getDir("db", MODE_PRIVATE);
|
||||||
@MethodsNotNullByDefault
|
@MethodsNotNullByDefault
|
||||||
@ParametersNotNullByDefault
|
@ParametersNotNullByDefault
|
||||||
DatabaseConfig databaseConfig = new DatabaseConfig() {
|
DatabaseConfig databaseConfig = new AndroidDatabaseConfig(dir);
|
||||||
|
|
||||||
private volatile SecretKey key;
|
|
||||||
private volatile String nickname;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean databaseExists() {
|
|
||||||
// FIXME should not run on UiThread #620
|
|
||||||
if (!dir.isDirectory()) return false;
|
|
||||||
File[] files = dir.listFiles();
|
|
||||||
return files != null && files.length > 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public File getDatabaseDirectory() {
|
|
||||||
return dir;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setEncryptionKey(SecretKey key) {
|
|
||||||
this.key = key;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setLocalAuthorName(String nickname) {
|
|
||||||
this.nickname = nickname;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@Nullable
|
|
||||||
public String getLocalAuthorName() {
|
|
||||||
return nickname;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@Nullable
|
|
||||||
public SecretKey getEncryptionKey() {
|
|
||||||
return key;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public long getMaxSize() {
|
|
||||||
return Long.MAX_VALUE;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
return databaseConfig;
|
return databaseConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -204,4 +158,5 @@ public class AppModule {
|
|||||||
lifecycleManager.registerService(dozeWatchdog);
|
lifecycleManager.registerService(dozeWatchdog);
|
||||||
return dozeWatchdog;
|
return dozeWatchdog;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ import android.content.pm.Signature;
|
|||||||
import android.support.annotation.UiThread;
|
import android.support.annotation.UiThread;
|
||||||
|
|
||||||
import org.briarproject.bramble.api.lifecycle.Service;
|
import org.briarproject.bramble.api.lifecycle.Service;
|
||||||
import org.briarproject.bramble.api.lifecycle.ServiceException;
|
|
||||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
import org.briarproject.bramble.api.system.AndroidExecutor;
|
import org.briarproject.bramble.api.system.AndroidExecutor;
|
||||||
import org.briarproject.bramble.util.StringUtils;
|
import org.briarproject.bramble.util.StringUtils;
|
||||||
@@ -196,7 +195,7 @@ class ScreenFilterMonitorImpl implements ScreenFilterMonitor, Service {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void startService() throws ServiceException {
|
public void startService() {
|
||||||
if (used.getAndSet(true)) throw new IllegalStateException();
|
if (used.getAndSet(true)) throw new IllegalStateException();
|
||||||
androidExecutor.runOnUiThread(() -> {
|
androidExecutor.runOnUiThread(() -> {
|
||||||
IntentFilter filter = new IntentFilter();
|
IntentFilter filter = new IntentFilter();
|
||||||
@@ -212,7 +211,7 @@ class ScreenFilterMonitorImpl implements ScreenFilterMonitor, Service {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void stopService() throws ServiceException {
|
public void stopService() {
|
||||||
androidExecutor.runOnUiThread(() -> {
|
androidExecutor.runOnUiThread(() -> {
|
||||||
if (receiver != null) app.unregisterReceiver(receiver);
|
if (receiver != null) app.unregisterReceiver(receiver);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -7,12 +7,19 @@ import org.briarproject.bramble.api.db.DatabaseConfig;
|
|||||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
import org.briarproject.bramble.util.AndroidUtils;
|
import org.briarproject.bramble.util.AndroidUtils;
|
||||||
|
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
import static java.util.logging.Level.INFO;
|
||||||
|
|
||||||
@NotNullByDefault
|
@NotNullByDefault
|
||||||
public class ConfigControllerImpl implements ConfigController {
|
public class ConfigControllerImpl implements ConfigController {
|
||||||
|
|
||||||
|
private static final Logger LOG =
|
||||||
|
Logger.getLogger(ConfigControllerImpl.class.getName());
|
||||||
|
|
||||||
private static final String PREF_DB_KEY = "key";
|
private static final String PREF_DB_KEY = "key";
|
||||||
|
|
||||||
private final SharedPreferences briarPrefs;
|
private final SharedPreferences briarPrefs;
|
||||||
@@ -23,17 +30,20 @@ public class ConfigControllerImpl implements ConfigController {
|
|||||||
DatabaseConfig databaseConfig) {
|
DatabaseConfig databaseConfig) {
|
||||||
this.briarPrefs = briarPrefs;
|
this.briarPrefs = briarPrefs;
|
||||||
this.databaseConfig = databaseConfig;
|
this.databaseConfig = databaseConfig;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Nullable
|
@Nullable
|
||||||
public String getEncryptedDatabaseKey() {
|
public String getEncryptedDatabaseKey() {
|
||||||
return briarPrefs.getString(PREF_DB_KEY, null);
|
String key = briarPrefs.getString(PREF_DB_KEY, null);
|
||||||
|
if (LOG.isLoggable(INFO))
|
||||||
|
LOG.info("Got database key from preferences: " + (key != null));
|
||||||
|
return key;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void storeEncryptedDatabaseKey(String hex) {
|
public void storeEncryptedDatabaseKey(String hex) {
|
||||||
|
LOG.info("Storing database key in preferences");
|
||||||
SharedPreferences.Editor editor = briarPrefs.edit();
|
SharedPreferences.Editor editor = briarPrefs.edit();
|
||||||
editor.putString(PREF_DB_KEY, hex);
|
editor.putString(PREF_DB_KEY, hex);
|
||||||
editor.apply();
|
editor.apply();
|
||||||
@@ -41,21 +51,27 @@ public class ConfigControllerImpl implements ConfigController {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void deleteAccount(Context ctx) {
|
public void deleteAccount(Context ctx) {
|
||||||
|
LOG.info("Deleting account");
|
||||||
SharedPreferences.Editor editor = briarPrefs.edit();
|
SharedPreferences.Editor editor = briarPrefs.edit();
|
||||||
editor.clear();
|
editor.clear();
|
||||||
editor.apply();
|
editor.apply();
|
||||||
AndroidUtils.deleteAppData(ctx);
|
AndroidUtils.deleteAppData(ctx);
|
||||||
|
AndroidUtils.logDataDirContents(ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean accountExists() {
|
public boolean accountExists() {
|
||||||
String hex = getEncryptedDatabaseKey();
|
String hex = getEncryptedDatabaseKey();
|
||||||
return hex != null && databaseConfig.databaseExists();
|
boolean exists = hex != null && databaseConfig.databaseExists();
|
||||||
|
if (LOG.isLoggable(INFO)) LOG.info("Account exists: " + exists);
|
||||||
|
return exists;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean accountSignedIn() {
|
public boolean accountSignedIn() {
|
||||||
return databaseConfig.getEncryptionKey() != null;
|
boolean signedIn = databaseConfig.getEncryptionKey() != null;
|
||||||
|
if (LOG.isLoggable(INFO)) LOG.info("Signed in: " + signedIn);
|
||||||
|
return signedIn;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,10 +9,12 @@ import org.briarproject.bramble.api.crypto.PasswordStrengthEstimator;
|
|||||||
import org.briarproject.bramble.api.crypto.SecretKey;
|
import org.briarproject.bramble.api.crypto.SecretKey;
|
||||||
import org.briarproject.bramble.api.db.DatabaseConfig;
|
import org.briarproject.bramble.api.db.DatabaseConfig;
|
||||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
import org.briarproject.bramble.util.AndroidUtils;
|
||||||
import org.briarproject.briar.android.controller.handler.ResultHandler;
|
import org.briarproject.briar.android.controller.handler.ResultHandler;
|
||||||
import org.briarproject.briar.android.controller.handler.UiResultHandler;
|
import org.briarproject.briar.android.controller.handler.UiResultHandler;
|
||||||
|
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
@@ -20,8 +22,11 @@ import javax.inject.Inject;
|
|||||||
public class SetupControllerImpl extends PasswordControllerImpl
|
public class SetupControllerImpl extends PasswordControllerImpl
|
||||||
implements SetupController {
|
implements SetupController {
|
||||||
|
|
||||||
|
private static final Logger LOG =
|
||||||
|
Logger.getLogger(SetupControllerImpl.class.getName());
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private SetupActivity setupActivity;
|
private volatile SetupActivity setupActivity;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
SetupControllerImpl(SharedPreferences briarPrefs,
|
SetupControllerImpl(SharedPreferences briarPrefs,
|
||||||
@@ -39,6 +44,7 @@ public class SetupControllerImpl extends PasswordControllerImpl
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean needToShowDozeFragment() {
|
public boolean needToShowDozeFragment() {
|
||||||
|
SetupActivity setupActivity = this.setupActivity;
|
||||||
if (setupActivity == null) throw new IllegalStateException();
|
if (setupActivity == null) throw new IllegalStateException();
|
||||||
return DozeView.needsToBeShown(setupActivity) ||
|
return DozeView.needsToBeShown(setupActivity) ||
|
||||||
HuaweiView.needsToBeShown(setupActivity);
|
HuaweiView.needsToBeShown(setupActivity);
|
||||||
@@ -46,31 +52,35 @@ public class SetupControllerImpl extends PasswordControllerImpl
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setAuthorName(String authorName) {
|
public void setAuthorName(String authorName) {
|
||||||
|
SetupActivity setupActivity = this.setupActivity;
|
||||||
if (setupActivity == null) throw new IllegalStateException();
|
if (setupActivity == null) throw new IllegalStateException();
|
||||||
setupActivity.setAuthorName(authorName);
|
setupActivity.setAuthorName(authorName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setPassword(String password) {
|
public void setPassword(String password) {
|
||||||
|
SetupActivity setupActivity = this.setupActivity;
|
||||||
if (setupActivity == null) throw new IllegalStateException();
|
if (setupActivity == null) throw new IllegalStateException();
|
||||||
setupActivity.setPassword(password);
|
setupActivity.setPassword(password);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void showPasswordFragment() {
|
public void showPasswordFragment() {
|
||||||
|
SetupActivity setupActivity = this.setupActivity;
|
||||||
if (setupActivity == null) throw new IllegalStateException();
|
if (setupActivity == null) throw new IllegalStateException();
|
||||||
setupActivity.showPasswordFragment();
|
setupActivity.showPasswordFragment();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void showDozeFragment() {
|
public void showDozeFragment() {
|
||||||
|
SetupActivity setupActivity = this.setupActivity;
|
||||||
if (setupActivity == null) throw new IllegalStateException();
|
if (setupActivity == null) throw new IllegalStateException();
|
||||||
setupActivity.showDozeFragment();
|
setupActivity.showDozeFragment();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void createAccount() {
|
public void createAccount() {
|
||||||
if (setupActivity == null) throw new IllegalStateException();
|
SetupActivity setupActivity = this.setupActivity;
|
||||||
UiResultHandler<Void> resultHandler =
|
UiResultHandler<Void> resultHandler =
|
||||||
new UiResultHandler<Void>(setupActivity) {
|
new UiResultHandler<Void>(setupActivity) {
|
||||||
@Override
|
@Override
|
||||||
@@ -85,17 +95,22 @@ public class SetupControllerImpl extends PasswordControllerImpl
|
|||||||
|
|
||||||
// Package access for testing
|
// Package access for testing
|
||||||
void createAccount(ResultHandler<Void> resultHandler) {
|
void createAccount(ResultHandler<Void> resultHandler) {
|
||||||
|
SetupActivity setupActivity = this.setupActivity;
|
||||||
if (setupActivity == null) throw new IllegalStateException();
|
if (setupActivity == null) throw new IllegalStateException();
|
||||||
String authorName = setupActivity.getAuthorName();
|
String authorName = setupActivity.getAuthorName();
|
||||||
if (authorName == null) throw new IllegalStateException();
|
if (authorName == null) throw new IllegalStateException();
|
||||||
String password = setupActivity.getPassword();
|
String password = setupActivity.getPassword();
|
||||||
if (password == null) throw new IllegalStateException();
|
if (password == null) throw new IllegalStateException();
|
||||||
cryptoExecutor.execute(() -> {
|
cryptoExecutor.execute(() -> {
|
||||||
|
LOG.info("Creating account");
|
||||||
|
AndroidUtils.logDataDirContents(setupActivity);
|
||||||
databaseConfig.setLocalAuthorName(authorName);
|
databaseConfig.setLocalAuthorName(authorName);
|
||||||
SecretKey key = crypto.generateSecretKey();
|
SecretKey key = crypto.generateSecretKey();
|
||||||
databaseConfig.setEncryptionKey(key);
|
databaseConfig.setEncryptionKey(key);
|
||||||
String hex = encryptDatabaseKey(key, password);
|
String hex = encryptDatabaseKey(key, password);
|
||||||
storeEncryptedDatabaseKey(hex);
|
storeEncryptedDatabaseKey(hex);
|
||||||
|
LOG.info("Created account");
|
||||||
|
AndroidUtils.logDataDirContents(setupActivity);
|
||||||
resultHandler.onResult(null);
|
resultHandler.onResult(null);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import android.support.v7.preference.PreferenceManager;
|
|||||||
import android.transition.Fade;
|
import android.transition.Fade;
|
||||||
|
|
||||||
import org.briarproject.bramble.api.system.AndroidExecutor;
|
import org.briarproject.bramble.api.system.AndroidExecutor;
|
||||||
|
import org.briarproject.bramble.util.AndroidUtils;
|
||||||
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.BaseActivity;
|
import org.briarproject.briar.android.activity.BaseActivity;
|
||||||
@@ -44,9 +45,11 @@ public class SplashScreenActivity extends BaseActivity {
|
|||||||
setContentView(R.layout.splash);
|
setContentView(R.layout.splash);
|
||||||
|
|
||||||
if (configController.accountSignedIn()) {
|
if (configController.accountSignedIn()) {
|
||||||
|
LOG.info("Already signed in, not showing splash screen");
|
||||||
startActivity(new Intent(this, OpenDatabaseActivity.class));
|
startActivity(new Intent(this, OpenDatabaseActivity.class));
|
||||||
finish();
|
finish();
|
||||||
} else {
|
} else {
|
||||||
|
LOG.info("Showing splash screen");
|
||||||
new Handler().postDelayed(() -> {
|
new Handler().postDelayed(() -> {
|
||||||
startNextActivity();
|
startNextActivity();
|
||||||
supportFinishAfterTransition();
|
supportFinishAfterTransition();
|
||||||
@@ -64,9 +67,12 @@ public class SplashScreenActivity extends BaseActivity {
|
|||||||
LOG.info("Expired");
|
LOG.info("Expired");
|
||||||
startActivity(new Intent(this, ExpiredActivity.class));
|
startActivity(new Intent(this, ExpiredActivity.class));
|
||||||
} else {
|
} else {
|
||||||
|
AndroidUtils.logDataDirContents(this);
|
||||||
if (configController.accountExists()) {
|
if (configController.accountExists()) {
|
||||||
|
LOG.info("Account exists");
|
||||||
startActivity(new Intent(this, OpenDatabaseActivity.class));
|
startActivity(new Intent(this, OpenDatabaseActivity.class));
|
||||||
} else {
|
} else {
|
||||||
|
LOG.info("Account does not exist");
|
||||||
configController.deleteAccount(this);
|
configController.deleteAccount(this);
|
||||||
startActivity(new Intent(this, SetupActivity.class));
|
startActivity(new Intent(this, SetupActivity.class));
|
||||||
}
|
}
|
||||||
@@ -74,8 +80,10 @@ public class SplashScreenActivity extends BaseActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void setPreferencesDefaults() {
|
private void setPreferencesDefaults() {
|
||||||
androidExecutor.runOnBackgroundThread(() ->
|
androidExecutor.runOnBackgroundThread(() -> {
|
||||||
PreferenceManager.setDefaultValues(SplashScreenActivity.this,
|
PreferenceManager.setDefaultValues(SplashScreenActivity.this,
|
||||||
R.xml.panic_preferences, false));
|
R.xml.panic_preferences, false);
|
||||||
|
LOG.info("Finished setting panic preference defaults");
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package org.briarproject.briar.android.login;
|
package org.briarproject.briar.android.login;
|
||||||
|
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
|
import android.content.pm.ApplicationInfo;
|
||||||
|
|
||||||
import org.briarproject.bramble.api.crypto.CryptoComponent;
|
import org.briarproject.bramble.api.crypto.CryptoComponent;
|
||||||
import org.briarproject.bramble.api.crypto.PasswordStrengthEstimator;
|
import org.briarproject.bramble.api.crypto.PasswordStrengthEstimator;
|
||||||
@@ -8,10 +9,13 @@ import org.briarproject.bramble.api.crypto.SecretKey;
|
|||||||
import org.briarproject.bramble.api.db.DatabaseConfig;
|
import org.briarproject.bramble.api.db.DatabaseConfig;
|
||||||
import org.briarproject.bramble.test.BrambleMockTestCase;
|
import org.briarproject.bramble.test.BrambleMockTestCase;
|
||||||
import org.briarproject.bramble.test.ImmediateExecutor;
|
import org.briarproject.bramble.test.ImmediateExecutor;
|
||||||
|
import org.briarproject.bramble.test.TestUtils;
|
||||||
import org.jmock.Expectations;
|
import org.jmock.Expectations;
|
||||||
import org.jmock.lib.legacy.ClassImposteriser;
|
import org.jmock.lib.legacy.ClassImposteriser;
|
||||||
|
import org.junit.After;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
@@ -40,6 +44,7 @@ public class SetupControllerImplTest extends BrambleMockTestCase {
|
|||||||
private final String encryptedHex = "010203";
|
private final String encryptedHex = "010203";
|
||||||
private final byte[] encryptedBytes = new byte[] {1, 2, 3};
|
private final byte[] encryptedBytes = new byte[] {1, 2, 3};
|
||||||
private final SecretKey key = getSecretKey();
|
private final SecretKey key = getSecretKey();
|
||||||
|
private final File testDir = TestUtils.getTestDirectory();
|
||||||
|
|
||||||
public SetupControllerImplTest() {
|
public SetupControllerImplTest() {
|
||||||
context.setImposteriser(ClassImposteriser.INSTANCE);
|
context.setImposteriser(ClassImposteriser.INSTANCE);
|
||||||
@@ -50,6 +55,11 @@ public class SetupControllerImplTest extends BrambleMockTestCase {
|
|||||||
@SuppressWarnings("ResultOfMethodCallIgnored")
|
@SuppressWarnings("ResultOfMethodCallIgnored")
|
||||||
public void testCreateAccount() {
|
public void testCreateAccount() {
|
||||||
context.checking(new Expectations() {{
|
context.checking(new Expectations() {{
|
||||||
|
// Allow the contents of the data directory to be logged
|
||||||
|
allowing(setupActivity).getApplicationInfo();
|
||||||
|
will(returnValue(new ApplicationInfo() {{
|
||||||
|
dataDir = testDir.getAbsolutePath();
|
||||||
|
}}));
|
||||||
// Set the author name and password
|
// Set the author name and password
|
||||||
oneOf(setupActivity).setAuthorName(authorName);
|
oneOf(setupActivity).setAuthorName(authorName);
|
||||||
oneOf(setupActivity).setPassword(password);
|
oneOf(setupActivity).setPassword(password);
|
||||||
@@ -84,4 +94,9 @@ public class SetupControllerImplTest extends BrambleMockTestCase {
|
|||||||
s.createAccount(result -> called.set(true));
|
s.createAccount(result -> called.set(true));
|
||||||
assertTrue(called.get());
|
assertTrue(called.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@After
|
||||||
|
public void tearDown() {
|
||||||
|
TestUtils.deleteTestDirectory(testDir);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user