Skip to content

Fix scheduled SMS delayed delivery and missing dispatches (solves #35) - #39

Merged
mirarr-app merged 2 commits into
mirarr-app:mainfrom
parsaosun2-png:fix/scheduled-messages-issue-35
Nov 22, 2026
Merged

mirarr-app merged 2 commits into
mirarr-app:mainfrom
parsaosun2-png:fix/scheduled-messages-issue-35

Conversation

@parsaosun2-png

@parsaosun2-png parsaosun2-png commented Nov 22, 2026 •

Copy link
Copy Markdown

Summary

Solves #35.

Fixes an issue where messages scheduled for a specific time were delivered late (minutes to hours), never sent until the app was reopened or "Send now" was tapped, or remained indefinitely stuck in the "Scheduled" state. Also bumps version to 1.3.18 (versionCode = 32).

Root Cause

  1. Doze Mode Alarm Deferral: Without USE_EXACT_ALARM on Android 13+ and falling back to alarmManager.set(...) instead of setAndAllowWhileIdle(...) when exact alarms were restricted, alarms were batched and deferred to Doze maintenance windows.
  2. CPU Suspend during SMS Radio Transmission: Background dispatches were not protected with a PowerManager.PARTIAL_WAKE_LOCK. When the device was asleep, the CPU suspended while awaiting carrier radio ACK (up to 20s), halting dispatch.
  3. Intent Collisions & Cancellation: PendingIntent lacked data URIs and used % 100000 request codes, risking collisions, while cancel() used FLAG_NO_CREATE which failed if not cached.
  4. Missing Overdue Sweeps: Overdue messages were not automatically swept when reopening or resuming the app.
  5. UI Thread Blocking and Concurrency: ChatViewModel was not deduplicating manual "Send now" triggers against in-flight dispatches.

Key Changes

  • Version Bump: Bumped to 1.3.18 (versionCode 32) across app/build.gradle.kts, metadata/com.miss.ga.yml, and added fastlane changelogs for English and Persian.
  • Permissions & Manifest: Declared USE_EXACT_ALARM in AndroidManifest.xml and registered fast boot, time-change, and exact alarm permission change broadcast receivers.
  • ScheduledSmsManager:
    • Guarded dispatches with a 30s PARTIAL_WAKE_LOCK safely released in finally.
    • Used setAndAllowWhileIdle for fallback alarm paths.
    • Added unique data URIs (misga://scheduled_sms/{id}) and masked 31-bit request codes.
    • Implemented isDispatching checks to prevent duplicate sends.
    • Added immediate async dispatch for past/overdue messages.
  • MainActivity: Sweeps overdue messages asynchronously on onCreate and onResume.
  • ChatViewModel & UI:
    • Non-blocking overdue dispatch on conversation load.
    • Guarded "Send now" and "Cancel" against in-flight dispatches and reflected sending status in ScheduledMessagesBanner.
    • Removed remember from exact alarm check in ScheduleMessageDialog so permission changes from settings reflect immediately.
  • Unit Tests: Added tests in ScheduledMessageTest for overdue filtering, boundary conditions, request code & URI uniqueness, and fast-boot action constants.

Verification

  • Tested with ./gradlew test --rerun-tasks (all 24 tasks passed cleanly).
  • Built debug APK cleanly with ./gradlew assembleDebug.

@mirarr-app
mirarr-app merged commit b82ec1f into mirarr-app:main Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants