Chromium Code Reviews| Index: net/android/java/src/org/chromium/net/NetworkChangeNotifierAutoDetect.java |
| diff --git a/net/android/java/src/org/chromium/net/NetworkChangeNotifierAutoDetect.java b/net/android/java/src/org/chromium/net/NetworkChangeNotifierAutoDetect.java |
| index 6096ad73cd73776d0f872bc6f9b68a66f5fe8ccc..73c7c86dcd841a80ab01cf7c15af0a23aa6a3423 100644 |
| --- a/net/android/java/src/org/chromium/net/NetworkChangeNotifierAutoDetect.java |
| +++ b/net/android/java/src/org/chromium/net/NetworkChangeNotifierAutoDetect.java |
| @@ -29,6 +29,8 @@ import android.os.Build; |
| import android.telephony.TelephonyManager; |
| import android.util.Log; |
| +import org.chromium.base.ApplicationState; |
| +import org.chromium.base.ApplicationStatus; |
| import org.chromium.base.ThreadUtils; |
| import org.chromium.base.VisibleForTesting; |
| import org.chromium.base.metrics.RecordHistogram; |
| @@ -97,12 +99,55 @@ public class NetworkChangeNotifierAutoDetect extends BroadcastReceiver { |
| } |
| /** |
| + * @return the info of the network that is available to this app. |
| + */ |
| + @TargetApi(Build.VERSION_CODES.M) |
| + NetworkInfo getNetworkInfo() { |
| + NetworkInfo networkInfo = mConnectivityManager.getActiveNetworkInfo(); |
| + if (networkInfo == null) { |
| + return null; |
| + } |
| + |
| + if (networkInfo.isConnected()) { |
| + return networkInfo; |
| + } |
| + |
| + // Current active network is not connected. Check if the network connectivity is blocked |
|
pauljensen
2017/01/07 02:32:38
Can we combine and simplify this comment and the o
tbansal1
2017/01/09 18:11:14
Done.
|
| + // even though there is a network available that has Internet capability. This may |
| + // happen because Android may not have updated the network access permissions for |
| + // this app. See https://crbug.com/677365 for more details. |
| + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { |
| + // https://crbug.com/677365 affects only Marshmallow and higher versions on which |
| + // data access may be restricted to the background apps. |
| + return null; |
| + } |
| + |
| + if (networkInfo.getDetailedState() != NetworkInfo.DetailedState.BLOCKED) { |
| + // Network state is not blocked which implies that network access is |
| + // unavailable (not just blocked to this app). |
| + return null; |
| + } |
| + |
| + if (ApplicationStatus.getStateForApplication() |
| + != ApplicationState.HAS_RUNNING_ACTIVITIES) { |
| + // The app is not in the foreground. |
| + return null; |
| + } |
| + |
| + // Network corresponding to networkInfo is BLOCKED which implies that it is blocked for |
| + // this app. However, since this app is in foreground, so the network access must be |
| + // restored to this app even though Android may not have updated the network access |
| + // permissions for this app. See https://crbug.com/677365 for more details. |
| + return networkInfo; |
| + } |
| + |
| + /** |
| * Returns connection type and status information about the current |
| * default network. |
| */ |
| NetworkState getNetworkState(WifiManagerDelegate wifiManagerDelegate) { |
| - final NetworkInfo networkInfo = mConnectivityManager.getActiveNetworkInfo(); |
| - if (networkInfo == null || !networkInfo.isConnected()) { |
| + final NetworkInfo networkInfo = getNetworkInfo(); |
| + if (networkInfo == null) { |
| return new NetworkState(false, -1, -1, null); |
| } |
| // If Wifi, then fetch SSID also |