Skip to content

Unthrottled NotificationManagerService:post wakelock loop (2,116+ wakeups) prevents device deep sleep / Doze #156

Description

@dusk-exhale-paging

During an extended battery trace (21 hours on battery, 18 hours screen-off), com.sameerasw.airsync accumulated 2,116 partial wakelocks under NotificationManagerService:post:com.sameerasw.airsync.
​A detailed timestamp analysis of the batterystats transaction history reveals that AirSync calls NotificationManager.notify() in sustained, 1-second consecutive bursts while the screen is off. This repeatedly resets DeviceIdleController and forces the Linux kernel to abort hardware suspend.
​Batterystats Log Extracts:

Wake lock NotificationManagerService:post:com.sameerasw.airsync: 7m 55s 667ms partial (2116 times) max=492 actual=523992 realtime
Foreground services: 21h 18m 3s 734ms realtime (running)


```text
Apk com.sameerasw.airsync:
  Service com.sameerasw.airsync.service.MacMediaPlayerService:
    Starts: 61, launches: 61
  Service com.sameerasw.airsync.service.AirSyncService:
    Created for: 17h 29m 9s uptime
  Service com.sameerasw.airsync.service.WakeupService:
    Created for: 17h 29m 9s uptime
```[span_40](start_span)[span_40](end_span)

**Consecutive 1-Second Post Frequency (Sample from `batterystats -b`):**

```text
09-23 09:32:41.518 +wake_lock=u0a530:"NotificationManagerService:post:com.sameerasw.airsync"
09-23 09:32:42.436 +wake_lock=u0a530:"NotificationManagerService:post:com.sameerasw.airsync"
09-23 09:32:43.753 +wake_lock=u0a530:"NotificationManagerService:post:com.sameerasw.airsync"
09-23 09:32:44.436 +wake_lock=u0a530:"NotificationManagerService:post:com.sameerasw.airsync"
09-23 09:32:45.041 +wake_lock=u0a530:"NotificationManagerService:post:com.sameerasw.airsync" wake_reason="Abort: ... userspace-abort"
09-23 09:32:46.791 +wake_lock=u0a530:"NotificationManagerService:post:com.sameerasw.airsync"
09-23 09:32:47.671 +wake_lock=u0a530:"NotificationManagerService:post:com.sameerasw.airsync"

09-23 09:34:07.100 +wake_lock=u0a530:"NotificationManagerService:post:com.sameerasw.airsync"
09-23 09:34:07.825 +wake_lock=u0a530:"NotificationManagerService:post:com.sameerasw.airsync"
09-23 09:34:09.594 +wake_lock=u0a530:"NotificationManagerService:post:com.sameerasw.airsync"
09-23 09:34:10.327 +wake_lock=u0a530:"NotificationManagerService:post:com.sameerasw.airsync"
09-23 09:34:11.088 +wake_lock=u0a530:"NotificationManagerService:post:com.sameerasw.airsync"
09-23 09:34:11.900 +wake_lock=u0a530:"NotificationManagerService:post:com.sameerasw.airsync"

09-23 09:48:02.571 +wake_lock=u0a530:"NotificationManagerService:post:com.sameerasw.airsync"
09-23 09:48:03.460 +wake_lock=u0a530:"NotificationManagerService:post:com.sameerasw.airsync"
09-23 09:48:04.801 +wake_lock=u0a530:"NotificationManagerService:post:com.sameerasw.airsync"
09-23 09:48:05.726 +wake_lock=u0a530:"NotificationManagerService:post:com.sameerasw.airsync"
09-23 09:48:06.543 +wake_lock=u0a530:"NotificationManagerService:post:com.sameerasw.airsync"
09-23 09:48:07.500 +wake_lock=u0a530:"NotificationManagerService:post:com.sameerasw.airsync"
09-23 09:48:08.886 +wake_lock=u0a530:"NotificationManagerService:post:com.sameerasw.airsync"
```[span_41](start_span)[span_41](end_span)[span_42](start_span)[span_42](end_span)

**Observed Impact:**
* Because each notification post invokes system server wakeups[span_43](start_span)[span_43](end_span)[span_44](start_span)[span_44](end_span), the kernel fails to enter suspend (`userspace-abort`, `Abort: Device alarmtimer.5.auto failed to suspend: error -16`)[span_45](start_span)[span_45](end_span)[span_46](start_span)[span_46](end_span).
* Over 14 hours of screen-off uptime out of 18 hours[span_47](start_span)[span_47](end_span), causing severe idle battery drain.

**Root Cause Hypothesis & Recommendations:**
1. **Media Progress Ticker:** The 1-second cadence strongly suggests `MacMediaPlayerService` is updating media playback position/elapsed time inside a notification continuously[span_48](start_span)[span_48](end_span)[span_49](start_span)[span_49](end_span). On Android, media progress should rely on `MediaSessionCompat` / `PlaybackStateCompat` timestamps so the OS interpolates time on the client side, rather than pushing `.notify()` updates every second.
2. **Diff State Payloads:** Avoid calling `NotificationManagerCompat.notify()` unless the visible payload (title, artist, connection state, or battery level) has actually changed.
3. **Screen-Off Throttling:** When the display is off (`Intent.ACTION_SCREEN_OFF`), suspend continuous notification updates entirely or throttle them to coarse intervals.

***

---

### Immediate Workaround for Your Phone

While waiting for an app update, stop AirSync from keeping your phone awake overnight:

```bash
cmd appops set com.sameerasw.airsync RUN_ANY_IN_BACKGROUND ignore

Verification: cmd appops get com.sameerasw.airsync RUN_ANY_IN_BACKGROUND (returns ignore).
What it does: Freezes AirSync when the phone is locked so it cannot spin background notification loops.  
To revert later: cmd appops set com.sameerasw.airsync RUN_ANY_IN_BACKGROUND default.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions