diff options
author | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2020-03-09 09:23:38 +0000 |
---|---|---|
committer | Chiachang Wang <chiachangwang@google.com> | 2020-03-10 02:13:14 +0000 |
commit | faac06e3e1412364512e46f38e63c6d2ca7548c1 (patch) | |
tree | 4fad8113a7070a3306e668816b072b01619ff607 /src | |
parent | 046a14ee618731ad5ef8c6b6c79bf0d84ab00fa6 (diff) |
Use redirect URL to start webview
NetworkMonitor will detect captive portal and may get a redirect
URL from WiFi AP. Redirect URL should able to send to captive
portal app to open the webview instead of detecting again by
captive portal app.
Bug: 134892996
Test: Manually test with captive portal AP
Test: atest NetworkStackTests NetworkStackNextTests
Change-Id: Idf363c79b7243a899121be8a68b32d0541dff14f
Merged-In: Idf363c79b7243a899121be8a68b32d0541dff14f
Diffstat (limited to 'src')
-rw-r--r-- | src/android/net/util/NetworkStackUtils.java | 30 | ||||
-rw-r--r-- | src/com/android/server/connectivity/NetworkMonitor.java | 33 |
2 files changed, 61 insertions, 2 deletions
diff --git a/src/android/net/util/NetworkStackUtils.java b/src/android/net/util/NetworkStackUtils.java index d147b45..9d913fc 100644 --- a/src/android/net/util/NetworkStackUtils.java +++ b/src/android/net/util/NetworkStackUtils.java @@ -141,6 +141,14 @@ public class NetworkStackUtils { */ public static final String DHCP_IP_CONFLICT_DETECT_VERSION = "dhcp_ip_conflict_detect_version"; + /** + * Minimum module version at which to enable dismissal CaptivePortalLogin app in validated + * network feature. CaptivePortalLogin app will also use validation facilities in + * {@link NetworkMonitor} to perform portal validation if feature is enabled. + */ + public static final String DISMISS_PORTAL_IN_VALIDATED_NETWORK = + "dismiss_portal_in_validated_network"; + static { System.loadLibrary("networkstackutilsjni"); } @@ -270,12 +278,32 @@ public class NetworkStackUtils { */ public static boolean isFeatureEnabled(@NonNull Context context, @NonNull String namespace, @NonNull String name) { + final int propertyVersion = getDeviceConfigPropertyInt(namespace, name, + 0 /* default value */); + return isFeatureEnabled(context, namespace, name, false); + } + + /** + * Check whether or not one specific experimental feature for a particular namespace from + * {@link DeviceConfig} is enabled by comparing NetworkStack module version {@link NetworkStack} + * with current version of property. If this property version is valid, the corresponding + * experimental feature would be enabled, otherwise disabled. + * @param context The global context information about an app environment. + * @param namespace The namespace containing the property to look up. + * @param name The name of the property to look up. + * @param defaultEnabled The value to return if the property does not exist or its value is + * null. + * @return true if this feature is enabled, or false if disabled. + */ + public static boolean isFeatureEnabled(@NonNull Context context, @NonNull String namespace, + @NonNull String name, boolean defaultEnabled) { try { final int propertyVersion = getDeviceConfigPropertyInt(namespace, name, 0 /* default value */); final long packageVersion = context.getPackageManager().getPackageInfo( context.getPackageName(), 0).getLongVersionCode(); - return (propertyVersion != 0 && packageVersion >= (long) propertyVersion); + return (propertyVersion == 0 && defaultEnabled) + || (propertyVersion != 0 && packageVersion >= (long) propertyVersion); } catch (NameNotFoundException e) { Log.e(TAG, "Could not find the package name", e); return false; diff --git a/src/com/android/server/connectivity/NetworkMonitor.java b/src/com/android/server/connectivity/NetworkMonitor.java index e914a55..438080c 100644 --- a/src/com/android/server/connectivity/NetworkMonitor.java +++ b/src/com/android/server/connectivity/NetworkMonitor.java @@ -65,6 +65,7 @@ import static android.net.util.NetworkStackUtils.CAPTIVE_PORTAL_MODE_PROMPT; import static android.net.util.NetworkStackUtils.CAPTIVE_PORTAL_OTHER_FALLBACK_URLS; import static android.net.util.NetworkStackUtils.CAPTIVE_PORTAL_USER_AGENT; import static android.net.util.NetworkStackUtils.CAPTIVE_PORTAL_USE_HTTPS; +import static android.net.util.NetworkStackUtils.DISMISS_PORTAL_IN_VALIDATED_NETWORK; import static android.net.util.NetworkStackUtils.isEmpty; import static android.provider.DeviceConfig.NAMESPACE_CONNECTIVITY; @@ -960,7 +961,11 @@ public class NetworkMonitor extends StateMachine { final Network network = new Network(mCleartextDnsNetwork); appExtras.putParcelable(ConnectivityManager.EXTRA_NETWORK, network); final CaptivePortalProbeResult probeRes = mLastPortalProbeResult; - appExtras.putString(EXTRA_CAPTIVE_PORTAL_URL, probeRes.detectUrl); + // Use redirect URL from AP if exists. + final String portalUrl = + (useRedirectUrlForPortal() && probeRes.redirectUrl != null) + ? probeRes.redirectUrl : probeRes.detectUrl; + appExtras.putString(EXTRA_CAPTIVE_PORTAL_URL, portalUrl); if (probeRes.probeSpec != null) { final String encodedSpec = probeRes.probeSpec.getEncodedSpec(); appExtras.putString(EXTRA_CAPTIVE_PORTAL_PROBE_SPEC, encodedSpec); @@ -977,6 +982,15 @@ public class NetworkMonitor extends StateMachine { } } + private boolean useRedirectUrlForPortal() { + // It must match the conditions in CaptivePortalLogin in which the redirect URL is not + // used to validate that the portal is gone. + final boolean aboveQ = + ShimUtils.isReleaseOrDevelopmentApiAbove(Build.VERSION_CODES.Q); + return aboveQ && mDependencies.isFeatureEnabled(mContext, NAMESPACE_CONNECTIVITY, + DISMISS_PORTAL_IN_VALIDATED_NETWORK, aboveQ /* defaultEnabled */); + } + @Override public void exit() { if (mLaunchCaptivePortalAppBroadcastReceiver != null) { @@ -2385,6 +2399,23 @@ public class NetworkMonitor extends StateMachine { NetworkMonitorUtils.PERMISSION_ACCESS_NETWORK_CONDITIONS); } + /** + * Check whether or not one specific experimental feature for a particular namespace from + * {@link DeviceConfig} is enabled by comparing NetworkStack module version + * {@link NetworkStack} with current version of property. If this property version is valid, + * the corresponding experimental feature would be enabled, otherwise disabled. + * @param context The global context information about an app environment. + * @param namespace The namespace containing the property to look up. + * @param name The name of the property to look up. + * @param defaultEnabled The value to return if the property does not exist or its value is + * null. + * @return true if this feature is enabled, or false if disabled. + */ + public boolean isFeatureEnabled(@NonNull Context context, @NonNull String namespace, + @NonNull String name, boolean defaultEnabled) { + return NetworkStackUtils.isFeatureEnabled(context, namespace, name, defaultEnabled); + } + public static final Dependencies DEFAULT = new Dependencies(); } |