Fix use of incorrect network type to identify network availability.
b/22068911
Currently only MOBILE and WIFI connections can be used to request
NTP time and XTRA data. Using the wrong connection type has the side
effect of assuming incorrectly that a connection might not be
available.
Change-Id: I1d7d1ed2dc31db80efb48acbd07e486e3d39adac
diff --git a/services/core/java/com/android/server/location/GpsLocationProvider.java b/services/core/java/com/android/server/location/GpsLocationProvider.java
index ba5f516..e230ab6 100644
--- a/services/core/java/com/android/server/location/GpsLocationProvider.java
+++ b/services/core/java/com/android/server/location/GpsLocationProvider.java
@@ -445,22 +445,14 @@
} else if (action.equals(Intents.WAP_PUSH_RECEIVED_ACTION)) {
checkWapSuplInit(intent);
} else if (action.equals(ConnectivityManager.CONNECTIVITY_ACTION)) {
- // retrieve NetworkInfo result for this UID
- NetworkInfo info =
- intent.getParcelableExtra(ConnectivityManager.EXTRA_NETWORK_INFO);
- ConnectivityManager connManager = (ConnectivityManager)
- mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
- info = connManager.getNetworkInfo(info.getType());
-
- int networkState;
- if (intent.getBooleanExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY, false) ||
- !info.isConnected()) {
- networkState = LocationProvider.TEMPORARILY_UNAVAILABLE;
- } else {
- networkState = LocationProvider.AVAILABLE;
+ // retrieve NetworkType result for this UID
+ int networkType = intent.getIntExtra(ConnectivityManager.EXTRA_NETWORK_TYPE, -1);
+ if (DEBUG) Log.d(TAG, "Connectivity action, type=" + networkType);
+ if (networkType == ConnectivityManager.TYPE_MOBILE
+ || networkType == ConnectivityManager.TYPE_WIFI
+ || networkType == ConnectivityManager.TYPE_MOBILE_SUPL) {
+ updateNetworkState(networkType);
}
-
- updateNetworkState(networkState, info);
} else if (PowerManager.ACTION_POWER_SAVE_MODE_CHANGED.equals(action)
|| PowerManager.ACTION_DEVICE_IDLE_MODE_CHANGED.equals(action)
|| Intent.ACTION_SCREEN_OFF.equals(action)
@@ -732,13 +724,19 @@
return PROPERTIES;
}
- public void updateNetworkState(int state, NetworkInfo info) {
- sendMessage(UPDATE_NETWORK_STATE, state, info);
+ public void updateNetworkState(int networkType) {
+ sendMessage(UPDATE_NETWORK_STATE, networkType, null /*obj*/);
}
- private void handleUpdateNetworkState(int state, NetworkInfo info) {
- mNetworkAvailable = (state == LocationProvider.AVAILABLE);
-
+ private void handleUpdateNetworkState(int networkType) {
+ ConnectivityManager connectivityManager = (ConnectivityManager) mContext
+ .getSystemService(Context.CONNECTIVITY_SERVICE);
+ NetworkInfo mobileInfo =
+ connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
+ NetworkInfo wifiInfo = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
+ mNetworkAvailable = (mobileInfo != null && mobileInfo.isConnected())
+ || (wifiInfo != null && wifiInfo.isConnected());
+ NetworkInfo info = connectivityManager.getNetworkInfo(networkType);
if (DEBUG) {
Log.d(TAG, "updateNetworkState " + (mNetworkAvailable ? "available" : "unavailable")
+ " info: " + info);
@@ -764,7 +762,7 @@
if (info != null && info.getType() == ConnectivityManager.TYPE_MOBILE_SUPL
&& mAGpsDataConnectionState == AGPS_DATA_CONNECTION_OPENING) {
- if (mNetworkAvailable) {
+ if (info.isConnected()) {
String apnName = info.getExtraInfo();
if (apnName == null) {
/* Assign a dummy value in the case of C2K as otherwise we will have a runtime
@@ -1967,7 +1965,7 @@
handleSetRequest(gpsRequest.request, gpsRequest.source);
break;
case UPDATE_NETWORK_STATE:
- handleUpdateNetworkState(msg.arg1, (NetworkInfo)msg.obj);
+ handleUpdateNetworkState(msg.arg1);
break;
case INJECT_NTP_TIME:
handleInjectNtpTime();