Repository navigation
fix(checkin): Stop network callback self-loop on Android 14+ - #352
Merged
Merged
Conversation
|
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
force-pushed
the
fix/checkin-loop
branch
from
November 15, 2026 03:55
5438835 to
8319a6c
Compare
Author
Done — marked the changes with RE changes start / RE changes end as requested. |
|
Thanks for the help |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What / Why
TriggerReceiveruses the deprecatedgetActiveNetworkInfo()to decide whetherthere is connectivity. On Android 14+ with GmsCore installed as a user app,
ConnectivityService.filterNetworkStateForUid()can rewrite the returnedNetworkInfotoDetailedState.BLOCKEDwhen the calling UID is subject to aper-UID background-data / Data-Saver policy.
isConnected()is thenfalseeven though the underlying network is
CONNECTEDandVALIDATED. Thedeprecated API does not return
nullhere.The receiver therefore takes the "no network" branch and registers a new
NetworkRequest(INTERNET)whose PendingIntent points back at itself. Therequest is already satisfied, so ConnectivityService fires
onAvailableimmediately — several hundred callbacks/second,
system_serverat ~300% CPUand ~1.5-2.0 A idle drain. The class already had an unused
registeredflag,but no deduplication, no
unregisterNetworkCallbackand no backoff.Changes
Only
TriggerReceiver.javais touched (+55 / -18).hasInternet()usesgetActiveNetwork()+NetworkCapabilities.hasCapability(NET_CAPABILITY_INTERNET)on API 23+,keeping the legacy
NetworkInfofallback for the module's minSdk 21.EXTRA_NETWORK_REQUESTextra means the callback fired, sothe request is satisfied: run the check-in and never re-register from inside
the callback. The previously unused
registeredflag now deduplicatespending 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
NULLin some configurations, and anyROM/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
BLOCKEDstate to the per-UID network policy:getActiveNetworkInfo()BLOCKED connected=falseCONNECTED connected=trueBLOCKED connected=falseUID=10385 blockedReasons1000010000netpolicy effectiveDATA_SAVERNONE(+METERED_USER_EXEMPTED)DATA_SAVERCONNECTED,VALIDATEDVALIDATEDis a network-level capability;BLOCKEDis a UID-level policyresult 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
Gradle buildworkflow_dispatchruns on this branch(43427959694 / 43427964401) completed successfully.
arm64-v8adebug APK built from this branch on thesame device and ran the deterministic reproduction (Check-in enabled,
lastCheckin=0, explicitandroid.server.checkin.CHECKINbroadcast):system_serverNetReassign/Sending PendingIntentCheckinServicerecordsCheckinServicedid start, so this is not a false negative from a missingbroadcast 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#*#*usesforce=trueand is unaffected.Data Saver / background-data restrictions.
else ifbranch came from upstream f806e1b; 5d52342 only fixedPendingIntent mutability. Both upstream master and this fork carry the
original logic.
Related