Skip to content

fix(checkin): Stop network callback self-loop on Android 14+ - #352

Merged
LisoUseInAIKyrios merged 1 commit into
MorpheApp:devfrom
Kosakanao:fix/checkin-loop
Nov 15, 2026
Merged

LisoUseInAIKyrios merged 1 commit into
MorpheApp:devfrom
Kosakanao:fix/checkin-loop

Conversation

@Kosakanao

Copy link
Copy Markdown

What / Why

TriggerReceiver uses the deprecated getActiveNetworkInfo() to decide whether
there is connectivity. On Android 14+ with GmsCore installed as a user app,
ConnectivityService.filterNetworkStateForUid() can rewrite the returned
NetworkInfo to DetailedState.BLOCKED when the calling UID is subject to a
per-UID background-data / Data-Saver policy. isConnected() is then false
even though the underlying network is CONNECTED and VALIDATED. The
deprecated API does not return null here.

The receiver therefore takes the "no network" branch and registers a new
NetworkRequest(INTERNET) whose PendingIntent points back at itself. The
request is already satisfied, so ConnectivityService fires onAvailable
immediately — several hundred callbacks/second, system_server at ~300% CPU
and ~1.5-2.0 A idle drain. The class already had an unused registered flag,
but no deduplication, no unregisterNetworkCallback and no backoff.

Changes

Only TriggerReceiver.java is touched (+55 / -18).

  1. Correctness — hasInternet() uses getActiveNetwork() +
    NetworkCapabilities.hasCapability(NET_CAPABILITY_INTERNET) on API 23+,
    keeping the legacy NetworkInfo fallback for the module's minSdk 21.
  2. Safety — an EXTRA_NETWORK_REQUEST extra means the callback fired, so
    the request is satisfied: run the check-in and never re-register from inside
    the callback. The previously unused registered flag now deduplicates
    pending retries, plus a 60 s minimum retry interval.

Layer 2 is the actual fix. Replacing the API alone is not sufficient: on
this device the modern API also returns NULL in some configurations, and any
ROM/policy edge case could still enter the retry branch. With layer 2, no
network-API result can produce an unbounded loop.

Root-cause evidence

A read-only Xposed probe hooked the three ConnectivityManager methods inside
the GmsCore process. A reversible system-side experiment then pinned the
BLOCKED state to the per-UID network policy:

baseline exempted exemption removed
getActiveNetworkInfo() BLOCKED connected=false CONNECTED connected=true BLOCKED connected=false
UID=10385 blockedReasons 10000 gone / 0 10000
netpolicy effective DATA_SAVER NONE (+METERED_USER_EXEMPTED) DATA_SAVER
underlying Wi-Fi CONNECTED, VALIDATED identical identical
cmd netpolicy add restrict-background-whitelist 10385
# blockedReasons 10000 -> 0; effective=DATA_SAVER -> NONE
# getActiveNetworkInfo() -> CONNECTED connected=true
cmd netpolicy remove restrict-background-whitelist 10385   # restored

VALIDATED is a network-level capability; BLOCKED is a UID-level policy
result applied by filterNetworkStateForUid() /
isNetworkWithLinkPropertiesBlocked(). They are not contradictory.
getActiveNetwork() does not go through that UID filter; getActiveNetworkInfo()
does. Three repeated measurements on the unpatched build gave the same result.

Verification

  • Two Gradle build workflow_dispatch runs on this branch
    (43427959694 / 43427964401) completed successfully.
  • Installed the single-ABI arm64-v8a debug APK built from this branch on the
    same device and ran the deterministic reproduction (Check-in enabled,
    lastCheckin=0, explicit android.server.checkin.CHECKIN broadcast):
T+0 T+15 s T+30 s unpatched baseline
system_server 2% 2% 2% 289-344%
NetReassign / Sending PendingIntent 0 / 0 1 / 1 1 / 1 (no growth) ~4000 / ~4000
CheckinService records 0 3 3 always 0 during the storm

CheckinService did start, so this is not a false negative from a missing
broadcast or a disabled check-in. The device was rolled back to the original
signed APK with its data restored afterwards.

Caveat: replacing the package changes the app UID, so the patched build was
not under the exact same per-UID policy entry. This shows the same deterministic
trigger no longer produces the loop, not a strictly identical per-UID A/B —
which is precisely the property layer 2 guarantees.

Notes

  • *#*#CHECKIN#*#* uses force=true and is unaffected.
  • User workaround: disable Google device registration, or exempt GmsCore from
    Data Saver / background-data restrictions.
  • The else if branch came from upstream f806e1b; 5d52342 only fixed
    PendingIntent mutability. Both upstream master and this fork carry the
    original logic.

Related

@Kosakanao
Kosakanao changed the base branch from main to dev November 13, 2026 16:31
@error-reporting

error-reporting commented Nov 14, 2026 •

Copy link
Copy Markdown

please mark the changes you made with // RE changes start and // RE changes end

getActiveNetworkInfo() (deprecated since API 29) returns a UID-filtered
NetworkInfo. When the GmsCore UID is blocked by a background-data / Data-Saver
policy, ConnectivityService rewrites it to DetailedState.BLOCKED, so
isConnected() is false even though the underlying network is CONNECTED and
VALIDATED. It does NOT return null.

The "no network" branch then registered a new network callback on every
callback, whose PendingIntent pointed back to TriggerReceiver. The request was
immediately satisfied, producing several hundred callbacks/second and pinning
system_server at ~300% CPU.

Use getActiveNetwork()/NetworkCapabilities for the connectivity check, but note
this alone is insufficient: the modern API can also return NULL in some
configurations on this device. The actual safety property is treating callback
arrival as proof of connectivity, deduplicating the retry registration and
rate-limiting it, so no per-UID policy edge case can produce an unbounded loop.

Observed directly with a read-only Xposed probe inside the GmsCore process and
pinned down with a reversible `cmd netpolicy add/remove
restrict-background-whitelist` experiment: the blocked status is produced by
the per-UID Data-Saver / background-data policy while the underlying Wi-Fi
stays CONNECTED and VALIDATED.
@Kosakanao

Copy link
Copy Markdown
Author

please mark the changes you made with // RE changes start and // RE changes end

Done — marked the changes with RE changes start / RE changes end as requested.
No logic changed; force-pushed to fix/checkin-loop (head 8319a6c).

@LisoUseInAIKyrios LisoUseInAIKyrios changed the title fix(checkin): stop network callback self-loop on Android 14+ fix(checkin): Stop network callback self-loop on Android 14+ Nov 15, 2026
@LisoUseInAIKyrios
LisoUseInAIKyrios merged commit 4c5f275 into MorpheApp:dev Nov 15, 2026
2 checks passed
@LisoUseInAIKyrios

Copy link
Copy Markdown

Thanks for the help

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