diff --git a/app/src/main/java/org/thoughtcrime/securesms/database/RecipientDatabase.kt b/app/src/main/java/org/thoughtcrime/securesms/database/RecipientDatabase.kt index 722cfcc1e..5fce3d0b0 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/database/RecipientDatabase.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/database/RecipientDatabase.kt @@ -1025,17 +1025,24 @@ open class RecipientDatabase(context: Context, databaseHelper: SignalDatabase) : val profileName = ProfileName.fromParts(update.new.givenName.orElse(null), update.new.familyName.orElse(null)) val localKey = ProfileKeyUtil.profileKeyOptional(update.old.profileKey.orElse(null)) val remoteKey = ProfileKeyUtil.profileKeyOptional(update.new.profileKey.orElse(null)) - val profileKey = remoteKey.or(localKey).map { obj: ProfileKey -> obj.serialize() }.map { source: ByteArray? -> Base64.encodeBytes(source!!) }.orElse(null) + val profileKey: String? = remoteKey.or(localKey).map { obj: ProfileKey -> obj.serialize() }.map { source: ByteArray? -> Base64.encodeBytes(source!!) }.orElse(null) if (!remoteKey.isPresent) { - Log.w(TAG, "Got an empty profile key while applying an account record update!") + Log.w(TAG, "Got an empty profile key while applying an account record update! The parsed local key is ${if (localKey.isPresent) "present" else "not present"}. The raw local key is ${if (update.old.profileKey.isPresent) "present" else "not present"}. The resulting key is ${if (profileKey != null) "present" else "not present"}.") } val values = ContentValues().apply { put(PROFILE_GIVEN_NAME, profileName.givenName) put(PROFILE_FAMILY_NAME, profileName.familyName) put(PROFILE_JOINED_NAME, profileName.toString()) - put(PROFILE_KEY, profileKey) + + if (profileKey != null) { + put(PROFILE_KEY, profileKey) + } else { + Log.w(TAG, "Avoided attempt to apply null profile key in account record update!") + } + put(STORAGE_SERVICE_ID, Base64.encodeBytes(update.new.id.raw)) + if (update.new.hasUnknownFields()) { put(STORAGE_PROTO, Base64.encodeBytes(Objects.requireNonNull(update.new.serializeUnknownFields()))) } else { diff --git a/app/src/main/java/org/thoughtcrime/securesms/storage/StorageSyncValidations.java b/app/src/main/java/org/thoughtcrime/securesms/storage/StorageSyncValidations.java index 11cb806dd..bf906189d 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/storage/StorageSyncValidations.java +++ b/app/src/main/java/org/thoughtcrime/securesms/storage/StorageSyncValidations.java @@ -146,6 +146,10 @@ public final class StorageSyncValidations { throw new SelfAddedAsContactError(); } } + + if (insert.getAccount().isPresent() && !insert.getAccount().get().getProfileKey().isPresent()) { + Log.w(TAG, "Uploading a null profile key in our AccountRecord!"); + } } }