Move logging into a database.

This commit is contained in:
Greyson Parrelli
2021-07-19 18:30:04 -04:00
parent 0b85852621
commit 7419da7247
27 changed files with 723 additions and 442 deletions

View File

@@ -78,9 +78,10 @@ public class ApplicationMigrations {
static final int SENDER_KEY_2 = 36;
static final int DB_AUTOINCREMENT = 37;
static final int ATTACHMENT_CLEANUP = 38;
static final int LOG_CLEANUP = 39;
}
public static final int CURRENT_VERSION = 38;
public static final int CURRENT_VERSION = 39;
/**
* This *must* be called after the {@link JobManager} has been instantiated, but *before* the call
@@ -342,6 +343,10 @@ public class ApplicationMigrations {
jobs.put(Version.ATTACHMENT_CLEANUP, new AttachmentCleanupMigrationJob());
}
if (lastSeenVersion < Version.LOG_CLEANUP) {
jobs.put(Version.LOG_CLEANUP, new DeleteDeprecatedLogsMigrationJob());
}
return jobs;
}

View File

@@ -0,0 +1,72 @@
package org.thoughtcrime.securesms.migrations;
import androidx.annotation.NonNull;
import org.signal.core.util.logging.Log;
import org.thoughtcrime.securesms.jobmanager.Data;
import org.thoughtcrime.securesms.jobmanager.Job;
import java.io.File;
/**
* We moved from storing logs in encrypted files to just storing them in an encrypted database. So we need to delete the leftover files.
*/
public class DeleteDeprecatedLogsMigrationJob extends MigrationJob {
private static final String TAG = Log.tag(DeleteDeprecatedLogsMigrationJob.class);
public static final String KEY = "DeleteDeprecatedLogsMigrationJob";
public DeleteDeprecatedLogsMigrationJob() {
this(new Parameters.Builder().build());
}
private DeleteDeprecatedLogsMigrationJob(@NonNull Parameters parameters) {
super(parameters);
}
@Override
public @NonNull String getFactoryKey() {
return KEY;
}
@Override
boolean isUiBlocking() {
return false;
}
@Override
void performMigration() {
File logDir = new File(context.getCacheDir(), "log");
if (logDir.exists()) {
File[] files = logDir.listFiles();
int count = 0;
if (files != null) {
for (File f : files) {
count += f.delete() ? 1 : 0;
}
}
if (!logDir.delete()) {
Log.w(TAG, "Failed to delete log directory.");
}
Log.i(TAG, "Deleted " + count + " log files.");
} else {
Log.w(TAG, "Log directory does not exist.");
}
}
@Override
boolean shouldRetry(@NonNull Exception e) {
return false;
}
public static final class Factory implements Job.Factory<DeleteDeprecatedLogsMigrationJob> {
@Override
public @NonNull DeleteDeprecatedLogsMigrationJob create(@NonNull Parameters parameters, @NonNull Data data) {
return new DeleteDeprecatedLogsMigrationJob(parameters);
}
}
}