mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-24 19:00:26 +01:00
Move BlobProvider storage out of cache and into internal storage.
This commit is contained in:
@@ -40,7 +40,7 @@ public class ApplicationMigrations {
|
||||
|
||||
private static final int LEGACY_CANONICAL_VERSION = 455;
|
||||
|
||||
public static final int CURRENT_VERSION = 26;
|
||||
public static final int CURRENT_VERSION = 27;
|
||||
|
||||
private static final class Version {
|
||||
static final int LEGACY = 1;
|
||||
@@ -69,6 +69,7 @@ public class ApplicationMigrations {
|
||||
static final int GV1_MIGRATION = 24;
|
||||
static final int USER_NOTIFICATION = 25;
|
||||
static final int DAY_BY_DAY_STICKERS = 26;
|
||||
static final int BLOB_LOCATION = 27;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -291,6 +292,10 @@ public class ApplicationMigrations {
|
||||
jobs.put(Version.DAY_BY_DAY_STICKERS, new StickerDayByDayMigrationJob());
|
||||
}
|
||||
|
||||
if (lastSeenVersion < Version.BLOB_LOCATION) {
|
||||
jobs.put(Version.BLOB_LOCATION, new BlobStorageLocationMigrationJob());
|
||||
}
|
||||
|
||||
return jobs;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
package org.thoughtcrime.securesms.migrations;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
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 files stored by {@link org.thoughtcrime.securesms.providers.BlobProvider} from the cache
|
||||
* into internal storage, so we gotta move any existing multi-session files.
|
||||
*/
|
||||
public class BlobStorageLocationMigrationJob extends MigrationJob {
|
||||
|
||||
private static final String TAG = Log.tag(BlobStorageLocationMigrationJob.class);
|
||||
|
||||
public static final String KEY = "BlobStorageLocationMigrationJob";
|
||||
|
||||
BlobStorageLocationMigrationJob() {
|
||||
this(new Job.Parameters.Builder().build());
|
||||
}
|
||||
|
||||
private BlobStorageLocationMigrationJob(@NonNull Parameters parameters) {
|
||||
super(parameters);
|
||||
}
|
||||
|
||||
@Override
|
||||
boolean isUiBlocking() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
void performMigration() {
|
||||
File oldDirectory = new File(context.getCacheDir(), "multi_session_blobs");
|
||||
|
||||
File[] oldFiles = oldDirectory.listFiles();
|
||||
|
||||
if (oldFiles == null) {
|
||||
Log.i(TAG, "No files to move.");
|
||||
return;
|
||||
}
|
||||
|
||||
Log.i(TAG, "Preparing to move " + oldFiles.length + " files.");
|
||||
|
||||
File newDirectory = context.getDir("multi_session_blobs", Context.MODE_PRIVATE);
|
||||
|
||||
for (File oldFile : oldFiles) {
|
||||
if (oldFile.renameTo(new File(newDirectory, oldFile.getName()))) {
|
||||
Log.i(TAG, "Successfully moved file: " + oldFile.getName());
|
||||
} else {
|
||||
Log.w(TAG, "Failed to move file! " + oldFile.getAbsolutePath());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
boolean shouldRetry(@NonNull Exception e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull String getFactoryKey() {
|
||||
return KEY;
|
||||
}
|
||||
|
||||
public static class Factory implements Job.Factory<BlobStorageLocationMigrationJob> {
|
||||
|
||||
@Override
|
||||
public @NonNull BlobStorageLocationMigrationJob create(@NonNull Parameters parameters, @NonNull Data data) {
|
||||
return new BlobStorageLocationMigrationJob(parameters);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user