mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-12 10:49:06 +01:00
Remove debug logging from setup process.
This commit is contained in:
@@ -15,7 +15,6 @@ import java.util.List;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import static android.content.Context.MODE_PRIVATE;
|
||||
import static java.util.logging.Level.INFO;
|
||||
|
||||
public class AndroidUtils {
|
||||
|
||||
@@ -59,57 +58,28 @@ public class AndroidUtils {
|
||||
&& !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) {
|
||||
// Clear and commit shared preferences
|
||||
for (SharedPreferences prefs : clear) {
|
||||
boolean cleared = prefs.edit().clear().commit();
|
||||
if (LOG.isLoggable(INFO)) {
|
||||
if (cleared) LOG.info("Cleared shared preferences");
|
||||
else LOG.info("Could not clear shared preferences");
|
||||
}
|
||||
if (!prefs.edit().clear().commit())
|
||||
LOG.warning("Could not clear shared preferences");
|
||||
}
|
||||
// Delete files, except lib and shared_prefs directories
|
||||
File dataDir = new File(ctx.getApplicationInfo().dataDir);
|
||||
if (LOG.isLoggable(INFO))
|
||||
LOG.info("Deleting app data from " + dataDir.getAbsolutePath());
|
||||
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) {
|
||||
String name = child.getName();
|
||||
if (!name.equals("lib") && !name.equals("shared_prefs")) {
|
||||
if (LOG.isLoggable(INFO))
|
||||
LOG.info("Deleting " + child.getAbsolutePath());
|
||||
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
|
||||
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");
|
||||
}
|
||||
if (!new File(dataDir, "cache").mkdir())
|
||||
LOG.warning("Could not recreate cache dir");
|
||||
}
|
||||
|
||||
public static File getReportDir(Context ctx) {
|
||||
|
||||
@@ -13,7 +13,7 @@ import java.util.logging.Logger;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import static java.util.logging.Level.INFO;
|
||||
import static java.util.logging.Level.WARNING;
|
||||
|
||||
@NotNullByDefault
|
||||
public class IoUtils {
|
||||
@@ -25,18 +25,21 @@ public class IoUtils {
|
||||
delete(f);
|
||||
} else if (f.isDirectory()) {
|
||||
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);
|
||||
}
|
||||
delete(f);
|
||||
}
|
||||
}
|
||||
|
||||
private static void delete(File f) {
|
||||
boolean deleted = f.delete();
|
||||
if (LOG.isLoggable(INFO)) {
|
||||
if (deleted) LOG.info("Deleted " + f.getAbsolutePath());
|
||||
else LOG.info("Could not delete " + f.getAbsolutePath());
|
||||
}
|
||||
if (!f.delete() && LOG.isLoggable(WARNING))
|
||||
LOG.warning("Could not delete " + f.getAbsolutePath());
|
||||
}
|
||||
|
||||
public static void copyAndClose(InputStream in, OutputStream out) {
|
||||
|
||||
@@ -19,7 +19,6 @@ import java.util.logging.Logger;
|
||||
import javax.annotation.Nullable;
|
||||
import javax.inject.Inject;
|
||||
|
||||
import static java.util.logging.Level.INFO;
|
||||
import static java.util.logging.Level.WARNING;
|
||||
|
||||
@NotNullByDefault
|
||||
@@ -156,21 +155,16 @@ public class ConfigControllerImpl implements ConfigController {
|
||||
SharedPreferences defaultPrefs =
|
||||
PreferenceManager.getDefaultSharedPreferences(ctx);
|
||||
AndroidUtils.deleteAppData(ctx, briarPrefs, defaultPrefs);
|
||||
AndroidUtils.logDataDirContents(ctx);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean accountExists() {
|
||||
String hex = getEncryptedDatabaseKey();
|
||||
boolean exists = hex != null && databaseConfig.databaseExists();
|
||||
if (LOG.isLoggable(INFO)) LOG.info("Account exists: " + exists);
|
||||
return exists;
|
||||
return hex != null && databaseConfig.databaseExists();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean accountSignedIn() {
|
||||
boolean signedIn = databaseConfig.getEncryptionKey() != null;
|
||||
if (LOG.isLoggable(INFO)) LOG.info("Signed in: " + signedIn);
|
||||
return signedIn;
|
||||
return databaseConfig.getEncryptionKey() != null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,6 @@ import org.briarproject.bramble.api.crypto.PasswordStrengthEstimator;
|
||||
import org.briarproject.bramble.api.crypto.SecretKey;
|
||||
import org.briarproject.bramble.api.db.DatabaseConfig;
|
||||
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.UiResultHandler;
|
||||
|
||||
@@ -103,14 +102,11 @@ public class SetupControllerImpl extends PasswordControllerImpl
|
||||
if (password == null) throw new IllegalStateException();
|
||||
cryptoExecutor.execute(() -> {
|
||||
LOG.info("Creating account");
|
||||
AndroidUtils.logDataDirContents(setupActivity);
|
||||
databaseConfig.setLocalAuthorName(authorName);
|
||||
SecretKey key = crypto.generateSecretKey();
|
||||
databaseConfig.setEncryptionKey(key);
|
||||
String hex = encryptDatabaseKey(key, password);
|
||||
storeEncryptedDatabaseKey(hex);
|
||||
LOG.info("Created account");
|
||||
AndroidUtils.logDataDirContents(setupActivity);
|
||||
resultHandler.onResult(null);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@ import android.support.v7.preference.PreferenceManager;
|
||||
import android.transition.Fade;
|
||||
|
||||
import org.briarproject.bramble.api.system.AndroidExecutor;
|
||||
import org.briarproject.bramble.util.AndroidUtils;
|
||||
import org.briarproject.briar.R;
|
||||
import org.briarproject.briar.android.activity.ActivityComponent;
|
||||
import org.briarproject.briar.android.activity.BaseActivity;
|
||||
@@ -45,11 +44,9 @@ public class SplashScreenActivity extends BaseActivity {
|
||||
setContentView(R.layout.splash);
|
||||
|
||||
if (configController.accountSignedIn()) {
|
||||
LOG.info("Already signed in, not showing splash screen");
|
||||
startActivity(new Intent(this, OpenDatabaseActivity.class));
|
||||
finish();
|
||||
} else {
|
||||
LOG.info("Showing splash screen");
|
||||
new Handler().postDelayed(() -> {
|
||||
startNextActivity();
|
||||
supportFinishAfterTransition();
|
||||
@@ -67,7 +64,6 @@ public class SplashScreenActivity extends BaseActivity {
|
||||
LOG.info("Expired");
|
||||
startActivity(new Intent(this, ExpiredActivity.class));
|
||||
} else {
|
||||
AndroidUtils.logDataDirContents(this);
|
||||
if (configController.accountExists()) {
|
||||
LOG.info("Account exists");
|
||||
startActivity(new Intent(this, OpenDatabaseActivity.class));
|
||||
@@ -80,10 +76,8 @@ public class SplashScreenActivity extends BaseActivity {
|
||||
}
|
||||
|
||||
private void setPreferencesDefaults() {
|
||||
androidExecutor.runOnBackgroundThread(() -> {
|
||||
PreferenceManager.setDefaultValues(SplashScreenActivity.this,
|
||||
R.xml.panic_preferences, false);
|
||||
LOG.info("Finished setting panic preference defaults");
|
||||
});
|
||||
androidExecutor.runOnBackgroundThread(() ->
|
||||
PreferenceManager.setDefaultValues(SplashScreenActivity.this,
|
||||
R.xml.panic_preferences, false));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user