fix(auth): replace deprecated NetworkInfo with NetworkCapabilities in LoginActivity#3352
Open
William17738 wants to merge 2 commits intomicrog:masterfrom
Open
fix(auth): replace deprecated NetworkInfo with NetworkCapabilities in LoginActivity#3352William17738 wants to merge 2 commits intomicrog:masterfrom
William17738 wants to merge 2 commits intomicrog:masterfrom
Conversation
Replace deprecated NetworkInfo.isConnected() with NetworkCapabilities.hasCapability(NET_CAPABILITY_INTERNET) on Android M+, with fallback to the old API for older versions. The deprecated getActiveNetworkInfo() returns null on Android 14 for non-system apps using VPN connections, causing the login screen to incorrectly show "no network" on devices like Honor/Huawei where microG is installed as a user app rather than a system app. The new NetworkCapabilities API correctly detects VPN and proxy connections, fixing Google Account login on stock ROM devices. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Member
|
Also according to the documentation NetworkCapabilities was added in API level 21 (Lollipop). |
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.
Summary
ConnectivityManager.getActiveNetworkInfo()withNetworkCapabilitiesAPI (Android M+) inLoginActivity.start()NetworkInfo.isConnected()for Android versions below MProblem
On Android 14,
getActiveNetworkInfo()returnsnullfor non-system apps when the active connection is a VPN (e.g. Clash, v2ray). This causes the login screen to show the "no network" error even though the device has internet access.This primarily affects users on stock ROMs (Honor, Huawei) where microG is installed as a user app rather than a system app. Custom ROM users are unaffected because microG is typically installed as a privileged system app, which has access to the deprecated API.
Fix
Test plan
Scope
This PR only touches
LoginActivity.java. There are 3 other call sites using the same deprecated API (TriggerReceiver,McsService,gcm/TriggerReceiver) which could be addressed in a follow-up PR.🤖 Generated with Claude Code