mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-19 22:29:53 +01:00
Merge branch '1219-remove-debug-logging' into 'master'
Remove debug logging from setup process See merge request akwizgran/briar!819
This commit is contained in:
@@ -15,7 +15,6 @@ import java.util.List;
|
|||||||
import java.util.logging.Logger;
|
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 {
|
||||||
|
|
||||||
@@ -59,57 +58,28 @@ 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 void deleteAppData(Context ctx, SharedPreferences... clear) {
|
public static void deleteAppData(Context ctx, SharedPreferences... clear) {
|
||||||
// Clear and commit shared preferences
|
// Clear and commit shared preferences
|
||||||
for (SharedPreferences prefs : clear) {
|
for (SharedPreferences prefs : clear) {
|
||||||
boolean cleared = prefs.edit().clear().commit();
|
if (!prefs.edit().clear().commit())
|
||||||
if (LOG.isLoggable(INFO)) {
|
LOG.warning("Could not clear shared preferences");
|
||||||
if (cleared) LOG.info("Cleared shared preferences");
|
|
||||||
else LOG.info("Could not clear shared preferences");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// Delete files, except lib and shared_prefs directories
|
// Delete files, except lib and shared_prefs directories
|
||||||
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) {
|
||||||
|
LOG.warning("Could not list files in app data dir");
|
||||||
|
} else {
|
||||||
for (File child : children) {
|
for (File child : children) {
|
||||||
String name = child.getName();
|
String name = child.getName();
|
||||||
if (!name.equals("lib") && !name.equals("shared_prefs")) {
|
if (!name.equals("lib") && !name.equals("shared_prefs")) {
|
||||||
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
|
||||||
boolean recreated = new File(dataDir, "cache").mkdir();
|
if (!new File(dataDir, "cache").mkdir())
|
||||||
if (LOG.isLoggable(INFO)) {
|
LOG.warning("Could not recreate cache dir");
|
||||||
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) {
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import java.util.logging.Logger;
|
|||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
import static java.util.logging.Level.INFO;
|
import static java.util.logging.Level.WARNING;
|
||||||
|
|
||||||
@NotNullByDefault
|
@NotNullByDefault
|
||||||
public class IoUtils {
|
public class IoUtils {
|
||||||
@@ -25,18 +25,21 @@ public class IoUtils {
|
|||||||
delete(f);
|
delete(f);
|
||||||
} else if (f.isDirectory()) {
|
} else if (f.isDirectory()) {
|
||||||
File[] children = f.listFiles();
|
File[] children = f.listFiles();
|
||||||
if (children != null)
|
if (children == null) {
|
||||||
|
if (LOG.isLoggable(WARNING)) {
|
||||||
|
LOG.warning("Could not list files in "
|
||||||
|
+ f.getAbsolutePath());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
for (File child : children) deleteFileOrDir(child);
|
for (File child : children) deleteFileOrDir(child);
|
||||||
|
}
|
||||||
delete(f);
|
delete(f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void delete(File f) {
|
private static void delete(File f) {
|
||||||
boolean deleted = f.delete();
|
if (!f.delete() && LOG.isLoggable(WARNING))
|
||||||
if (LOG.isLoggable(INFO)) {
|
LOG.warning("Could not delete " + f.getAbsolutePath());
|
||||||
if (deleted) LOG.info("Deleted " + f.getAbsolutePath());
|
|
||||||
else LOG.info("Could not delete " + f.getAbsolutePath());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void copyAndClose(InputStream in, OutputStream out) {
|
public static void copyAndClose(InputStream in, OutputStream out) {
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ 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;
|
|
||||||
import static java.util.logging.Level.WARNING;
|
import static java.util.logging.Level.WARNING;
|
||||||
|
|
||||||
@NotNullByDefault
|
@NotNullByDefault
|
||||||
@@ -156,21 +155,16 @@ public class ConfigControllerImpl implements ConfigController {
|
|||||||
SharedPreferences defaultPrefs =
|
SharedPreferences defaultPrefs =
|
||||||
PreferenceManager.getDefaultSharedPreferences(ctx);
|
PreferenceManager.getDefaultSharedPreferences(ctx);
|
||||||
AndroidUtils.deleteAppData(ctx, briarPrefs, defaultPrefs);
|
AndroidUtils.deleteAppData(ctx, briarPrefs, defaultPrefs);
|
||||||
AndroidUtils.logDataDirContents(ctx);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean accountExists() {
|
public boolean accountExists() {
|
||||||
String hex = getEncryptedDatabaseKey();
|
String hex = getEncryptedDatabaseKey();
|
||||||
boolean exists = hex != null && databaseConfig.databaseExists();
|
return hex != null && databaseConfig.databaseExists();
|
||||||
if (LOG.isLoggable(INFO)) LOG.info("Account exists: " + exists);
|
|
||||||
return exists;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean accountSignedIn() {
|
public boolean accountSignedIn() {
|
||||||
boolean signedIn = databaseConfig.getEncryptionKey() != null;
|
return databaseConfig.getEncryptionKey() != null;
|
||||||
if (LOG.isLoggable(INFO)) LOG.info("Signed in: " + signedIn);
|
|
||||||
return signedIn;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ 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;
|
||||||
|
|
||||||
@@ -103,14 +102,11 @@ public class SetupControllerImpl extends PasswordControllerImpl
|
|||||||
if (password == null) throw new IllegalStateException();
|
if (password == null) throw new IllegalStateException();
|
||||||
cryptoExecutor.execute(() -> {
|
cryptoExecutor.execute(() -> {
|
||||||
LOG.info("Creating account");
|
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,7 +8,6 @@ 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;
|
||||||
@@ -45,11 +44,9 @@ 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();
|
||||||
@@ -67,7 +64,6 @@ 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");
|
LOG.info("Account exists");
|
||||||
startActivity(new Intent(this, OpenDatabaseActivity.class));
|
startActivity(new Intent(this, OpenDatabaseActivity.class));
|
||||||
@@ -80,10 +76,8 @@ 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");
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user