Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move BlobProvider storage out of cache and into internal storage.
- Loading branch information
1 parent
37d9718
commit 80f3504
Showing
5 changed files
with
103 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
app/src/main/java/org/thoughtcrime/securesms/migrations/BlobStorageLocationMigrationJob.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters