Clean up dangling wallpapers.

This commit is contained in:
Greyson Parrelli 2024-10-09 09:58:00 -04:00
parent 3381d20bd7
commit 95d8abfb46
5 changed files with 82 additions and 1 deletions

View file

@ -2073,6 +2073,36 @@ open class RecipientTable(context: Context, databaseHelper: SignalDatabase) : Da
.run() .run()
} }
/**
* A follow up to [migrateWallpaperUri]. This clears out any remaining wallpapers using the old URI scheme, which implies
* that they were not migrated, which would only happen if they could not be read or were no longer found (the latter being
* more common, as this would happen after restoring a backup).
*/
fun clearMissingFileWallpapersPostMigration(): Int {
return writableDatabase
.update(TABLE_NAME)
.values(
WALLPAPER to null,
WALLPAPER_URI to null
)
.where("$WALLPAPER_URI LIKE ?", "%wallpaper%")
.run()
}
/**
* Our current backup system does not backup file wallpapers. So we should clear them post-restore to avoid any weird UI issues.
*/
fun clearFileWallpapersPostBackupRestore() {
writableDatabase
.update(TABLE_NAME)
.values(
WALLPAPER to null,
WALLPAPER_URI to null
)
.where("$WALLPAPER_URI NOT NULL")
.run()
}
fun getPhoneNumberDiscoverability(id: RecipientId): PhoneNumberDiscoverableState? { fun getPhoneNumberDiscoverability(id: RecipientId): PhoneNumberDiscoverableState? {
return readableDatabase return readableDatabase
.select(PHONE_NUMBER_DISCOVERABLE) .select(PHONE_NUMBER_DISCOVERABLE)

View file

@ -300,6 +300,7 @@ open class SignalDatabase(private val context: Application, databaseSecret: Data
instance!!.messageTable.trimEntriesForExpiredMessages() instance!!.messageTable.trimEntriesForExpiredMessages()
instance!!.reactionTable.deleteAbandonedReactions() instance!!.reactionTable.deleteAbandonedReactions()
instance!!.searchTable.fullyResetTables(useTransaction = false) instance!!.searchTable.fullyResetTables(useTransaction = false)
instance!!.recipientTable.clearFileWallpapersPostBackupRestore()
instance!!.rawWritableDatabase.execSQL("DROP TABLE IF EXISTS key_value") instance!!.rawWritableDatabase.execSQL("DROP TABLE IF EXISTS key_value")
instance!!.rawWritableDatabase.execSQL("DROP TABLE IF EXISTS megaphone") instance!!.rawWritableDatabase.execSQL("DROP TABLE IF EXISTS megaphone")
instance!!.rawWritableDatabase.execSQL("DROP TABLE IF EXISTS job_spec") instance!!.rawWritableDatabase.execSQL("DROP TABLE IF EXISTS job_spec")

View file

@ -96,6 +96,7 @@ import org.thoughtcrime.securesms.migrations.TrimByLengthSettingsMigrationJob;
import org.thoughtcrime.securesms.migrations.UpdateSmsJobsMigrationJob; import org.thoughtcrime.securesms.migrations.UpdateSmsJobsMigrationJob;
import org.thoughtcrime.securesms.migrations.UserNotificationMigrationJob; import org.thoughtcrime.securesms.migrations.UserNotificationMigrationJob;
import org.thoughtcrime.securesms.migrations.UuidMigrationJob; import org.thoughtcrime.securesms.migrations.UuidMigrationJob;
import org.thoughtcrime.securesms.migrations.WallpaperCleanupMigrationJob;
import org.thoughtcrime.securesms.migrations.WallpaperStorageMigrationJob; import org.thoughtcrime.securesms.migrations.WallpaperStorageMigrationJob;
import java.util.Arrays; import java.util.Arrays;
@ -318,6 +319,7 @@ public final class JobManagerFactories {
put(UpdateSmsJobsMigrationJob.KEY, new UpdateSmsJobsMigrationJob.Factory()); put(UpdateSmsJobsMigrationJob.KEY, new UpdateSmsJobsMigrationJob.Factory());
put(UserNotificationMigrationJob.KEY, new UserNotificationMigrationJob.Factory()); put(UserNotificationMigrationJob.KEY, new UserNotificationMigrationJob.Factory());
put(UuidMigrationJob.KEY, new UuidMigrationJob.Factory()); put(UuidMigrationJob.KEY, new UuidMigrationJob.Factory());
put(WallpaperCleanupMigrationJob.KEY, new WallpaperCleanupMigrationJob.Factory());
put(WallpaperStorageMigrationJob.KEY, new WallpaperStorageMigrationJob.Factory()); put(WallpaperStorageMigrationJob.KEY, new WallpaperStorageMigrationJob.Factory());
// Dead jobs // Dead jobs

View file

@ -159,9 +159,10 @@ public class ApplicationMigrations {
static final int WALLPAPER_MIGRATION = 115; static final int WALLPAPER_MIGRATION = 115;
static final int BACKFILL_DIGESTS_V3 = 116; static final int BACKFILL_DIGESTS_V3 = 116;
static final int SVR2_ENCLAVE_UPDATE_2 = 117; static final int SVR2_ENCLAVE_UPDATE_2 = 117;
static final int WALLPAPER_MIGRATION_CLEANUP = 118;
} }
public static final int CURRENT_VERSION = 117; public static final int CURRENT_VERSION = 118;
/** /**
* This *must* be called after the {@link JobManager} has been instantiated, but *before* the call * This *must* be called after the {@link JobManager} has been instantiated, but *before* the call
@ -728,6 +729,10 @@ public class ApplicationMigrations {
jobs.put(Version.SVR2_ENCLAVE_UPDATE_2, new Svr2MirrorMigrationJob()); jobs.put(Version.SVR2_ENCLAVE_UPDATE_2, new Svr2MirrorMigrationJob());
} }
if (lastSeenVersion < Version.WALLPAPER_MIGRATION_CLEANUP) {
jobs.put(Version.WALLPAPER_MIGRATION_CLEANUP, new WallpaperCleanupMigrationJob());
}
return jobs; return jobs;
} }

View file

@ -0,0 +1,43 @@
/*
* Copyright 2024 Signal Messenger, LLC
* SPDX-License-Identifier: AGPL-3.0-only
*/
package org.thoughtcrime.securesms.migrations
import org.signal.core.util.logging.Log
import org.thoughtcrime.securesms.database.SignalDatabase
import org.thoughtcrime.securesms.jobmanager.Job
/**
* [WallpaperStorageMigrationJob] left some stragglers in the DB for wallpapers that couldn't be found on disk. This cleans those up.
* It'd be great if we could do this in a database migration, but unfortunately we need to ensure that the aforementioned
* [WallpaperStorageMigrationJob] finished.
*/
internal class WallpaperCleanupMigrationJob(parameters: Parameters = Parameters.Builder().build()) : MigrationJob(parameters) {
companion object {
private val TAG = Log.tag(WallpaperCleanupMigrationJob::class.java)
const val KEY = "WallpaperCleanupMigrationJob"
}
override fun getFactoryKey(): String = KEY
override fun isUiBlocking(): Boolean = false
override fun performMigration() {
val count = SignalDatabase.recipients.clearMissingFileWallpapersPostMigration()
if (count > 0) {
Log.w(TAG, "There were $count legacy wallpapers that needed to be cleared.")
} else {
Log.i(TAG, "No legacy wallpapers needed to be cleared.")
}
}
override fun shouldRetry(e: Exception): Boolean = false
class Factory : Job.Factory<WallpaperCleanupMigrationJob> {
override fun create(parameters: Parameters, serializedData: ByteArray?): WallpaperCleanupMigrationJob {
return WallpaperCleanupMigrationJob(parameters)
}
}
}