Add logging around overrides in notification profiles.

This commit is contained in:
Michelle Tang
2025-09-15 13:00:23 -04:00
committed by Greyson Parrelli
parent 0b71b1837c
commit a575626abb
2 changed files with 9 additions and 0 deletions

View File

@@ -2,6 +2,7 @@ package org.thoughtcrime.securesms.notifications.profiles
import android.content.Context import android.content.Context
import org.signal.core.util.concurrent.SignalExecutors import org.signal.core.util.concurrent.SignalExecutors
import org.signal.core.util.logging.Log
import org.thoughtcrime.securesms.R import org.thoughtcrime.securesms.R
import org.thoughtcrime.securesms.database.SignalDatabase import org.thoughtcrime.securesms.database.SignalDatabase
import org.thoughtcrime.securesms.keyvalue.NotificationProfileValues import org.thoughtcrime.securesms.keyvalue.NotificationProfileValues
@@ -22,6 +23,8 @@ import java.time.ZoneId
*/ */
object NotificationProfiles { object NotificationProfiles {
val TAG = Log.tag(NotificationProfiles::class.java)
@JvmStatic @JvmStatic
@JvmOverloads @JvmOverloads
fun getActiveProfile(profiles: List<NotificationProfile>, now: Long = System.currentTimeMillis(), zoneId: ZoneId = ZoneId.systemDefault()): NotificationProfile? { fun getActiveProfile(profiles: List<NotificationProfile>, now: Long = System.currentTimeMillis(), zoneId: ZoneId = ZoneId.systemDefault()): NotificationProfile? {
@@ -39,6 +42,7 @@ object NotificationProfiles {
} }
if (shouldClearManualOverride(manualProfile, scheduledProfile)) { if (shouldClearManualOverride(manualProfile, scheduledProfile)) {
Log.i(TAG, "Clearing manual override")
SignalExecutors.UNBOUNDED.execute { SignalExecutors.UNBOUNDED.execute {
SignalDatabase.recipients.markNeedsSync(Recipient.self().id) SignalDatabase.recipients.markNeedsSync(Recipient.self().id)
StorageSyncHelper.scheduleSyncForDataChange() StorageSyncHelper.scheduleSyncForDataChange()

View File

@@ -210,6 +210,7 @@ object StorageSyncHelper {
private fun getNotificationProfileManualOverride(): AccountRecord.NotificationProfileManualOverride { private fun getNotificationProfileManualOverride(): AccountRecord.NotificationProfileManualOverride {
val profile = SignalDatabase.notificationProfiles.getProfile(SignalStore.notificationProfile.manuallyEnabledProfile) val profile = SignalDatabase.notificationProfiles.getProfile(SignalStore.notificationProfile.manuallyEnabledProfile)
return if (profile != null && profile.deletedTimestampMs == 0L) { return if (profile != null && profile.deletedTimestampMs == 0L) {
Log.i(TAG, "Setting a manually enabled profile ${profile.id}")
// From [StorageService.proto], end timestamp should be unset if no timespan was chosen in the UI // From [StorageService.proto], end timestamp should be unset if no timespan was chosen in the UI
val endTimestamp = if (SignalStore.notificationProfile.manuallyEnabledUntil == Long.MAX_VALUE) 0 else SignalStore.notificationProfile.manuallyEnabledUntil val endTimestamp = if (SignalStore.notificationProfile.manuallyEnabledUntil == Long.MAX_VALUE) 0 else SignalStore.notificationProfile.manuallyEnabledUntil
AccountRecord.NotificationProfileManualOverride( AccountRecord.NotificationProfileManualOverride(
@@ -219,6 +220,7 @@ object StorageSyncHelper {
) )
) )
} else if (SignalStore.notificationProfile.manuallyDisabledAt != 0L) { } else if (SignalStore.notificationProfile.manuallyDisabledAt != 0L) {
Log.i(TAG, "Setting a manually disabled profile ${SignalStore.notificationProfile.manuallyDisabledAt}")
AccountRecord.NotificationProfileManualOverride( AccountRecord.NotificationProfileManualOverride(
disabledAtTimestampMs = SignalStore.notificationProfile.manuallyDisabledAt disabledAtTimestampMs = SignalStore.notificationProfile.manuallyDisabledAt
) )
@@ -296,6 +298,7 @@ object StorageSyncHelper {
if (update.new.proto.notificationProfileManualOverride != null) { if (update.new.proto.notificationProfileManualOverride != null) {
if (update.new.proto.notificationProfileManualOverride!!.enabled != null) { if (update.new.proto.notificationProfileManualOverride!!.enabled != null) {
Log.i(TAG, "Found a remote enabled notification override")
val remoteProfile = update.new.proto.notificationProfileManualOverride!!.enabled!! val remoteProfile = update.new.proto.notificationProfileManualOverride!!.enabled!!
val remoteId = UuidUtil.parseOrNull(remoteProfile.id) val remoteId = UuidUtil.parseOrNull(remoteProfile.id)
val remoteEndTime = if (remoteProfile.endAtTimestampMs == 0L) Long.MAX_VALUE else remoteProfile.endAtTimestampMs val remoteEndTime = if (remoteProfile.endAtTimestampMs == 0L) Long.MAX_VALUE else remoteProfile.endAtTimestampMs
@@ -309,12 +312,14 @@ object StorageSyncHelper {
if (localProfile == null) { if (localProfile == null) {
Log.w(TAG, "Unable to find local notification profile with given remote id") Log.w(TAG, "Unable to find local notification profile with given remote id")
} else { } else {
Log.i(TAG, "Setting manually enabled profile to ${localProfile.id}")
SignalStore.notificationProfile.manuallyEnabledProfile = localProfile.id SignalStore.notificationProfile.manuallyEnabledProfile = localProfile.id
SignalStore.notificationProfile.manuallyEnabledUntil = remoteEndTime SignalStore.notificationProfile.manuallyEnabledUntil = remoteEndTime
SignalStore.notificationProfile.manuallyDisabledAt = System.currentTimeMillis() SignalStore.notificationProfile.manuallyDisabledAt = System.currentTimeMillis()
} }
} }
} else if (update.new.proto.notificationProfileManualOverride!!.disabledAtTimestampMs != null) { } else if (update.new.proto.notificationProfileManualOverride!!.disabledAtTimestampMs != null) {
Log.i(TAG, "Found a remote disabled notification override for ${update.new.proto.notificationProfileManualOverride!!.disabledAtTimestampMs!!}")
SignalStore.notificationProfile.manuallyEnabledProfile = 0 SignalStore.notificationProfile.manuallyEnabledProfile = 0
SignalStore.notificationProfile.manuallyEnabledUntil = 0 SignalStore.notificationProfile.manuallyEnabledUntil = 0
SignalStore.notificationProfile.manuallyDisabledAt = update.new.proto.notificationProfileManualOverride!!.disabledAtTimestampMs!! SignalStore.notificationProfile.manuallyDisabledAt = update.new.proto.notificationProfileManualOverride!!.disabledAtTimestampMs!!