Skip to content

fix(auth): replace deprecated NetworkInfo with NetworkCapabilities in LoginActivity#3352

Open
William17738 wants to merge 2 commits intomicrog:masterfrom
William17738:fix/login-network-check-android14
Open

fix(auth): replace deprecated NetworkInfo with NetworkCapabilities in LoginActivity#3352
William17738 wants to merge 2 commits intomicrog:masterfrom
William17738:fix/login-network-check-android14

Conversation

@William17738
Copy link

@William17738 William17738 commented Mar 21, 2026

Summary

  • Replace deprecated ConnectivityManager.getActiveNetworkInfo() with NetworkCapabilities API (Android M+) in LoginActivity.start()
  • Retain fallback to NetworkInfo.isConnected() for Android versions below M
  • No behavioral change on devices where the old API works correctly

Problem

On Android 14, getActiveNetworkInfo() returns null for 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

// Before (deprecated, fails on Android 14 with VPN):
NetworkInfo networkInfo = cm.getActiveNetworkInfo();
if (networkInfo != null && networkInfo.isConnected())

// After (works with VPN/proxy connections):
if (SDK_INT >= Build.VERSION_CODES.M) {
    Network network = cm.getActiveNetwork();
    NetworkCapabilities caps = cm.getNetworkCapabilities(network);
    return caps != null && caps.hasCapability(NET_CAPABILITY_INTERNET);
} else {
    NetworkInfo networkInfo = cm.getActiveNetworkInfo();
    return networkInfo != null && networkInfo.isConnected();
}

Test plan

  • Verify login works on Android 14 stock ROM (Honor/Huawei) with VPN active
  • Verify login works on Android 14 stock ROM with WiFi only (no VPN)
  • Verify login still shows "no network" error when truly offline
  • Verify no regression on Android < M (fallback path)

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

William17738 and others added 2 commits March 22, 2026 02:24
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>
@ale5000-git
Copy link
Member

ale5000-git commented Mar 22, 2026

Also according to the documentation NetworkCapabilities was added in API level 21 (Lollipop).

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.

2 participants