Skip to content

Fix MCS disconnects on aggressive OEM process managers#3667

Open
areteruhiro wants to merge 1 commit into
microg:masterfrom
areteruhiro:fix/xiaomi-mcs-foreground-service
Open

Fix MCS disconnects on aggressive OEM process managers#3667
areteruhiro wants to merge 1 commit into
microg:masterfrom
areteruhiro:fix/xiaomi-mcs-foreground-service

Conversation

@areteruhiro

Copy link
Copy Markdown

Summary

Keep the long-lived MCS connection in a foreground service even when the app is exempt from battery optimizations.

Problem

On a Xiaomi device, Cloud Messaging connected briefly and then immediately returned to the disconnected state. The device log showed Xiaomi's low-memory killer terminating the persistent process within seconds:

Kill 'app.revanced.android.gms:persistent' ..., oom_score_adj 905

The current ForegroundServiceContext skips foreground-service mode when PowerManager.isIgnoringBatteryOptimizations() returns true. On this device, the battery exemption did not prevent the OEM process manager from assigning the persistent process a cached OOM score and killing it.

Once the persistent process was killed, the MCS socket disappeared and Cloud Messaging reported that it was disconnected.

Changes

  • Add an opt-in forceForeground mode to ForegroundServiceContext.
  • Use it when starting the MCS connection and heartbeat service.
  • Preserve the existing behavior for all other callers.

Verification

  • :play-services-core:assembleMapboxDefaultDebug --no-daemon --no-configuration-cache --max-workers=1
  • Build completed successfully and produced the Mapbox/default debug APK.
  • The change only touches ForegroundServiceContext.java and TriggerReceiver.java.

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.

1 participant