Skip to content

refactor(android): centralize notification ID management into a single NotificationIds object #259

Description

@SERDUN

Problem

Notification IDs are currently scattered across multiple classes with no shared contract:

Location ID Type
ActiveCallNotificationBuilder.NOTIFICATION_ID 1 fixed
IncomingCallService.PLACEHOLDER_NOTIFICATION_ID 3 fixed
StandaloneCallService.NOTIFICATION_ID 97 fixed
IncomingCallNotificationBuilder.notificationId(callId) ≥ 1000 dynamic (callId.hashCode)

There is no single place to understand the full ID space, verify there are no collisions, or safely add a new notification type. The MIN_CALL_NOTIFICATION_ID = 1000 threshold that separates fixed IDs from dynamic per-call IDs is defined inside IncomingCallNotificationBuilder — invisible to anyone working in another class.

Proposed solution

Introduce a single NotificationIds object that owns all notification ID constants and the per-call ID derivation:

object NotificationIds {
    const val ACTIVE_CALL = 1
    const val INCOMING_CALL_PLACEHOLDER = 3
    const val STANDALONE_CALL = 97

    // Per-call IDs are dynamically derived and kept above this threshold
    // to guarantee no collision with the fixed IDs above.
    private const val CALL_ID_MIN = 1000

    fun forCall(callId: String): Int =
        (callId.hashCode() and Int.MAX_VALUE).coerceAtLeast(CALL_ID_MIN)
}

All existing constants and notificationId(callId) usages are migrated to reference NotificationIds.

Benefits

  • The full notification ID space is visible in one place
  • Collisions between fixed and dynamic IDs are impossible to introduce accidentally
  • Adding a new notification type requires updating one file, making conflicts obvious
  • The CALL_ID_MIN = 1000 boundary is self-documenting in context

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions