mirror of
https://github.com/signalapp/Signal-Android.git
synced 2025-12-23 04:28:35 +00:00
Clean up a bunch of warnings.
This commit is contained in:
committed by
Cody Henthorne
parent
ff882edeae
commit
3a8c324c12
@@ -1,3 +1,5 @@
|
|||||||
|
@file:Suppress("DEPRECATION")
|
||||||
|
|
||||||
package org.thoughtcrime.securesms.database.helpers.migration
|
package org.thoughtcrime.securesms.database.helpers.migration
|
||||||
|
|
||||||
import android.app.Application
|
import android.app.Application
|
||||||
@@ -56,6 +58,7 @@ import java.util.UUID
|
|||||||
* Adding an urgent flag to message envelopes to help with notifications. Need to track flag in
|
* Adding an urgent flag to message envelopes to help with notifications. Need to track flag in
|
||||||
* MSL table so can be resent with the correct urgency.
|
* MSL table so can be resent with the correct urgency.
|
||||||
*/
|
*/
|
||||||
|
@Suppress("ClassName")
|
||||||
object V149_LegacyMigrations : SignalDatabaseMigration {
|
object V149_LegacyMigrations : SignalDatabaseMigration {
|
||||||
|
|
||||||
private val TAG: String = SignalDatabaseMigrations.TAG
|
private val TAG: String = SignalDatabaseMigrations.TAG
|
||||||
@@ -242,7 +245,7 @@ object V149_LegacyMigrations : SignalDatabaseMigration {
|
|||||||
val contentType: String? = cursor.getString(cursor.getColumnIndexOrThrow("ct"))
|
val contentType: String? = cursor.getString(cursor.getColumnIndexOrThrow("ct"))
|
||||||
if (contentType != null && !contentType.startsWith("video")) {
|
if (contentType != null && !contentType.startsWith("video")) {
|
||||||
val thumbnailPath: String = cursor.getString(cursor.getColumnIndexOrThrow("thumbnail"))
|
val thumbnailPath: String = cursor.getString(cursor.getColumnIndexOrThrow("thumbnail"))
|
||||||
val thumbnailFile: File = File(thumbnailPath)
|
val thumbnailFile = File(thumbnailPath)
|
||||||
thumbnailFile.delete()
|
thumbnailFile.delete()
|
||||||
db.update("part", update, "_id = ?", arrayOf(id.toString()))
|
db.update("part", update, "_id = ?", arrayOf(id.toString()))
|
||||||
}
|
}
|
||||||
@@ -383,7 +386,7 @@ object V149_LegacyMigrations : SignalDatabaseMigration {
|
|||||||
val messageSoundUri: Uri? = if (messageSound != null) Uri.parse(messageSound) else null
|
val messageSoundUri: Uri? = if (messageSound != null) Uri.parse(messageSound) else null
|
||||||
val vibrateState: Int = cursor.getInt(cursor.getColumnIndexOrThrow("vibrate"))
|
val vibrateState: Int = cursor.getInt(cursor.getColumnIndexOrThrow("vibrate"))
|
||||||
var displayName: String? = NotificationChannels.getInstance().getChannelDisplayNameFor(systemName, profileName, null, address)
|
var displayName: String? = NotificationChannels.getInstance().getChannelDisplayNameFor(systemName, profileName, null, address)
|
||||||
val vibrateEnabled: Boolean = if (vibrateState == 0) SignalStore.settings().isMessageVibrateEnabled() else vibrateState == 1
|
val vibrateEnabled: Boolean = if (vibrateState == 0) SignalStore.settings().isMessageVibrateEnabled else vibrateState == 1
|
||||||
if (GroupId.isEncodedGroup(address)) {
|
if (GroupId.isEncodedGroup(address)) {
|
||||||
db.rawQuery("SELECT title FROM groups WHERE group_id = ?", arrayOf(address)).use { groupCursor ->
|
db.rawQuery("SELECT title FROM groups WHERE group_id = ?", arrayOf(address)).use { groupCursor ->
|
||||||
if (groupCursor != null && groupCursor.moveToFirst()) {
|
if (groupCursor != null && groupCursor.moveToFirst()) {
|
||||||
@@ -654,7 +657,7 @@ object V149_LegacyMigrations : SignalDatabaseMigration {
|
|||||||
if (oldVersion < NOTIFICATION_RECIPIENT_IDS && Build.VERSION.SDK_INT >= 26) {
|
if (oldVersion < NOTIFICATION_RECIPIENT_IDS && Build.VERSION.SDK_INT >= 26) {
|
||||||
val notificationManager = ServiceUtil.getNotificationManager(context)
|
val notificationManager = ServiceUtil.getNotificationManager(context)
|
||||||
val channels = Stream.of(notificationManager.notificationChannels)
|
val channels = Stream.of(notificationManager.notificationChannels)
|
||||||
.filter { c: NotificationChannel -> c.getId().startsWith("contact_") }
|
.filter { c: NotificationChannel -> c.id.startsWith("contact_") }
|
||||||
.toList()
|
.toList()
|
||||||
|
|
||||||
Log.i(TAG, "Migrating " + channels.size + " channels to use RecipientId's.")
|
Log.i(TAG, "Migrating " + channels.size + " channels to use RecipientId's.")
|
||||||
@@ -862,7 +865,7 @@ object V149_LegacyMigrations : SignalDatabaseMigration {
|
|||||||
if (oldVersion < TRANSFER_FILE_CLEANUP) {
|
if (oldVersion < TRANSFER_FILE_CLEANUP) {
|
||||||
val partsDirectory: File = context.getDir("parts", Context.MODE_PRIVATE)
|
val partsDirectory: File = context.getDir("parts", Context.MODE_PRIVATE)
|
||||||
if (partsDirectory.exists()) {
|
if (partsDirectory.exists()) {
|
||||||
val transferFiles = partsDirectory.listFiles { dir: File?, name: String -> name.startsWith("transfer") }
|
val transferFiles: Array<File> = partsDirectory.listFiles { _: File?, name: String -> name.startsWith("transfer") } ?: emptyArray()
|
||||||
var deleteCount = 0
|
var deleteCount = 0
|
||||||
Log.i(TAG, "Found " + transferFiles.size + " dangling transfer files.")
|
Log.i(TAG, "Found " + transferFiles.size + " dangling transfer files.")
|
||||||
for (file: File in transferFiles) {
|
for (file: File in transferFiles) {
|
||||||
@@ -887,7 +890,7 @@ object V149_LegacyMigrations : SignalDatabaseMigration {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (oldVersion < AVATAR_LOCATION_MIGRATION) {
|
if (oldVersion < AVATAR_LOCATION_MIGRATION) {
|
||||||
val oldAvatarDirectory = File(context.getFilesDir(), "avatars")
|
val oldAvatarDirectory = File(context.filesDir, "avatars")
|
||||||
if (!FileUtils.deleteDirectory(oldAvatarDirectory)) {
|
if (!FileUtils.deleteDirectory(oldAvatarDirectory)) {
|
||||||
Log.w(TAG, "Failed to delete avatar directory.")
|
Log.w(TAG, "Failed to delete avatar directory.")
|
||||||
}
|
}
|
||||||
@@ -931,7 +934,7 @@ object V149_LegacyMigrations : SignalDatabaseMigration {
|
|||||||
while (cursor != null && cursor.moveToNext()) {
|
while (cursor != null && cursor.moveToNext()) {
|
||||||
val id: Long = cursor.getLong(cursor.getColumnIndexOrThrow("_id"))
|
val id: Long = cursor.getLong(cursor.getColumnIndexOrThrow("_id"))
|
||||||
val name: String = cursor.getString(cursor.getColumnIndexOrThrow("system_display_name"))
|
val name: String = cursor.getString(cursor.getColumnIndexOrThrow("system_display_name"))
|
||||||
val values: ContentValues = ContentValues()
|
val values = ContentValues()
|
||||||
values.put("color", ContactColorsLegacy.generateForV2(name).serialize())
|
values.put("color", ContactColorsLegacy.generateForV2(name).serialize())
|
||||||
db.update("recipient", values, "_id = ?", arrayOf(id.toString()))
|
db.update("recipient", values, "_id = ?", arrayOf(id.toString()))
|
||||||
}
|
}
|
||||||
@@ -979,7 +982,7 @@ object V149_LegacyMigrations : SignalDatabaseMigration {
|
|||||||
db.update("part", values, "_data = ?", arrayOf(data))
|
db.update("part", values, "_data = ?", arrayOf(data))
|
||||||
count++
|
count++
|
||||||
} else {
|
} else {
|
||||||
Log.w(TAG, "[QuoteCleanup] Failed to delete " + data)
|
Log.w(TAG, "[QuoteCleanup] Failed to delete $data")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1065,15 +1068,15 @@ object V149_LegacyMigrations : SignalDatabaseMigration {
|
|||||||
var deleted = 0
|
var deleted = 0
|
||||||
db.rawQuery("SELECT thumbnail FROM part WHERE thumbnail NOT NULL", null).use { cursor ->
|
db.rawQuery("SELECT thumbnail FROM part WHERE thumbnail NOT NULL", null).use { cursor ->
|
||||||
if (cursor != null) {
|
if (cursor != null) {
|
||||||
total = cursor.getCount()
|
total = cursor.count
|
||||||
Log.w(TAG, "Found " + total + " thumbnails to delete.")
|
Log.w(TAG, "Found $total thumbnails to delete.")
|
||||||
}
|
}
|
||||||
while (cursor != null && cursor.moveToNext()) {
|
while (cursor != null && cursor.moveToNext()) {
|
||||||
val file: File = File(CursorUtil.requireString(cursor, "thumbnail"))
|
val file = File(CursorUtil.requireString(cursor, "thumbnail"))
|
||||||
if (file.delete()) {
|
if (file.delete()) {
|
||||||
deleted++
|
deleted++
|
||||||
} else {
|
} else {
|
||||||
Log.w(TAG, "Failed to delete file! " + file.getAbsolutePath())
|
Log.w(TAG, "Failed to delete file! " + file.absolutePath)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1127,7 +1130,7 @@ object V149_LegacyMigrations : SignalDatabaseMigration {
|
|||||||
val rangeLength: Int = CursorUtil.requireInt(cursor, "range_length")
|
val rangeLength: Int = CursorUtil.requireInt(cursor, "range_length")
|
||||||
val body: String? = CursorUtil.requireString(cursor, "body")
|
val body: String? = CursorUtil.requireString(cursor, "body")
|
||||||
|
|
||||||
if ((body != null) && (rangeStart < body.length) && (body.get(rangeStart) != '\uFFFC')) {
|
if ((body != null) && (rangeStart < body.length) && (body[rangeStart] != '\uFFFC')) {
|
||||||
idsToDelete.add(mentionId)
|
idsToDelete.add(mentionId)
|
||||||
} else {
|
} else {
|
||||||
val tuple: Triple<Long, Int, Int> = Triple(messageId, rangeStart, rangeLength)
|
val tuple: Triple<Long, Int, Int> = Triple(messageId, rangeStart, rangeLength)
|
||||||
@@ -1141,7 +1144,7 @@ object V149_LegacyMigrations : SignalDatabaseMigration {
|
|||||||
|
|
||||||
if (Util.hasItems(idsToDelete)) {
|
if (Util.hasItems(idsToDelete)) {
|
||||||
val ids: String = TextUtils.join(",", idsToDelete)
|
val ids: String = TextUtils.join(",", idsToDelete)
|
||||||
db.delete("mention", "_id in (" + ids + ")", null)
|
db.delete("mention", "_id in ($ids)", null)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1373,9 +1376,9 @@ object V149_LegacyMigrations : SignalDatabaseMigration {
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
val hasReceiveLaterThanNotified: Boolean = ReactionList.parseFrom(reactions)
|
val hasReceiveLaterThanNotified: Boolean = ReactionList.parseFrom(reactions)
|
||||||
.getReactionsList()
|
.reactionsList
|
||||||
.stream()
|
.stream()
|
||||||
.anyMatch { r: ReactionList.Reaction -> r.getReceivedTime() > notifiedTimestamp }
|
.anyMatch { r: ReactionList.Reaction -> r.receivedTime > notifiedTimestamp }
|
||||||
if (!hasReceiveLaterThanNotified) {
|
if (!hasReceiveLaterThanNotified) {
|
||||||
smsIds.add(cursor.getLong(cursor.getColumnIndexOrThrow("_id")))
|
smsIds.add(cursor.getLong(cursor.getColumnIndexOrThrow("_id")))
|
||||||
}
|
}
|
||||||
@@ -1400,9 +1403,9 @@ object V149_LegacyMigrations : SignalDatabaseMigration {
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
val hasReceiveLaterThanNotified: Boolean = ReactionList.parseFrom(reactions)
|
val hasReceiveLaterThanNotified: Boolean = ReactionList.parseFrom(reactions)
|
||||||
.getReactionsList()
|
.reactionsList
|
||||||
.stream()
|
.stream()
|
||||||
.anyMatch { r: ReactionList.Reaction -> r.getReceivedTime() > notifiedTimestamp }
|
.anyMatch { r: ReactionList.Reaction -> r.receivedTime > notifiedTimestamp }
|
||||||
if (!hasReceiveLaterThanNotified) {
|
if (!hasReceiveLaterThanNotified) {
|
||||||
mmsIds.add(cursor.getLong(cursor.getColumnIndexOrThrow("_id")))
|
mmsIds.add(cursor.getLong(cursor.getColumnIndexOrThrow("_id")))
|
||||||
}
|
}
|
||||||
@@ -1428,7 +1431,7 @@ object V149_LegacyMigrations : SignalDatabaseMigration {
|
|||||||
deleteCount = db.update("recipient", deleteValues, "storage_service_key NOT NULL AND (dirty = 3 OR group_type = 1 OR (group_type = 0 AND registered = 2))", null)
|
deleteCount = db.update("recipient", deleteValues, "storage_service_key NOT NULL AND (dirty = 3 OR group_type = 1 OR (group_type = 0 AND registered = 2))", null)
|
||||||
|
|
||||||
db.query("recipient", arrayOf("_id"), "storage_service_key IS NULL AND (dirty = 2 OR registered = 1)", null, null, null, null).use { cursor ->
|
db.query("recipient", arrayOf("_id"), "storage_service_key IS NULL AND (dirty = 2 OR registered = 1)", null, null, null, null).use { cursor ->
|
||||||
insertCount = cursor.getCount()
|
insertCount = cursor.count
|
||||||
while (cursor.moveToNext()) {
|
while (cursor.moveToNext()) {
|
||||||
val insertValues = ContentValues().apply {
|
val insertValues = ContentValues().apply {
|
||||||
put("storage_service_key", Base64.encodeBytes(StorageSyncHelper.generateKey()))
|
put("storage_service_key", Base64.encodeBytes(StorageSyncHelper.generateKey()))
|
||||||
@@ -1439,7 +1442,7 @@ object V149_LegacyMigrations : SignalDatabaseMigration {
|
|||||||
}
|
}
|
||||||
|
|
||||||
db.query("recipient", arrayOf("_id"), "storage_service_key NOT NULL AND dirty = 1", null, null, null, null).use { cursor ->
|
db.query("recipient", arrayOf("_id"), "storage_service_key NOT NULL AND dirty = 1", null, null, null, null).use { cursor ->
|
||||||
updateCount = cursor.getCount()
|
updateCount = cursor.count
|
||||||
while (cursor.moveToNext()) {
|
while (cursor.moveToNext()) {
|
||||||
val updateValues = ContentValues().apply {
|
val updateValues = ContentValues().apply {
|
||||||
put("storage_service_key", Base64.encodeBytes(StorageSyncHelper.generateKey()))
|
put("storage_service_key", Base64.encodeBytes(StorageSyncHelper.generateKey()))
|
||||||
@@ -1497,7 +1500,7 @@ object V149_LegacyMigrations : SignalDatabaseMigration {
|
|||||||
db.query("recipient", arrayOf("_id"), "color IS NULL", null, null, null, null).use { cursor ->
|
db.query("recipient", arrayOf("_id"), "color IS NULL", null, null, null, null).use { cursor ->
|
||||||
while (cursor.moveToNext()) {
|
while (cursor.moveToNext()) {
|
||||||
val id: Long = cursor.getInt(cursor.getColumnIndexOrThrow("_id")).toLong()
|
val id: Long = cursor.getInt(cursor.getColumnIndexOrThrow("_id")).toLong()
|
||||||
val values: ContentValues = ContentValues(1)
|
val values = ContentValues(1)
|
||||||
values.put("color", AvatarColor.random().serialize())
|
values.put("color", AvatarColor.random().serialize())
|
||||||
db.update("recipient", values, "_id = ?", arrayOf(id.toString()))
|
db.update("recipient", values, "_id = ?", arrayOf(id.toString()))
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user