OSDN Git Service

DO NOT MERGE ANYWHERE: GnssLocationProvider: listening to conn lost event
authorKevin Tang <zhikait@codeaurora.org>
Thu, 11 May 2017 02:36:20 +0000 (19:36 -0700)
committerZheng Zhang <zhzh@google.com>
Wed, 23 Aug 2017 18:22:59 +0000 (18:22 +0000)
The HAL layer now gets onLost notificaiton as well
as connectivity available.  This keeps HAL layer
better informed on what the on what the real
connection status is, for things like assistance
download.

Fixes: 34076506
Test: GPS works, even after delete all, and assistance
downloads wait politely when in airplane mode.

Change-Id: I4b5fb782f9370b0a45282c8a9dd5920120d449fb

services/core/java/com/android/server/location/GnssLocationProvider.java

index ea76d72..bd947fb 100644 (file)
@@ -465,6 +465,11 @@ public class GnssLocationProvider implements LocationProviderInterface {
             }
             sendMessage(UPDATE_NETWORK_STATE, 0 /*arg*/, network);
         }
+
+        @Override
+        public void onLost(Network network) {
+            sendMessage(UPDATE_NETWORK_STATE, 0 /*arg*/, network);
+        }
     };
 
     /**
@@ -828,11 +833,21 @@ public class GnssLocationProvider implements LocationProviderInterface {
     private void handleUpdateNetworkState(Network network) {
         // retrieve NetworkInfo for this UID
         NetworkInfo info = mConnMgr.getNetworkInfo(network);
-        if (info == null) {
-            return;
+
+        boolean networkAvailable = false;
+        boolean isConnected = false;
+        int type = ConnectivityManager.TYPE_NONE;
+        boolean isRoaming = false;
+        String apnName = null;
+
+        if (info != null) {
+            networkAvailable = info.isAvailable() && TelephonyManager.getDefault().getDataEnabled();
+            isConnected = info.isConnected();
+            type = info.getType();
+            isRoaming = info.isRoaming();
+            apnName = info.getExtraInfo();
         }
 
-        boolean isConnected = info.isConnected();
         if (DEBUG) {
             String message = String.format(
                     "UpdateNetworkState, state=%s, connected=%s, info=%s, capabilities=%S",
@@ -844,8 +859,6 @@ public class GnssLocationProvider implements LocationProviderInterface {
         }
 
         if (native_is_agps_ril_supported()) {
-            boolean dataEnabled = TelephonyManager.getDefault().getDataEnabled();
-            boolean networkAvailable = info.isAvailable() && dataEnabled;
             String defaultApn = getSelectedApn();
             if (defaultApn == null) {
                 defaultApn = "dummy-apn";
@@ -853,10 +866,10 @@ public class GnssLocationProvider implements LocationProviderInterface {
 
             native_update_network_state(
                     isConnected,
-                    info.getType(),
-                    info.isRoaming(),
+                    type,
+                    isRoaming,
                     networkAvailable,
-                    info.getExtraInfo(),
+                    apnName,
                     defaultApn);
         } else if (DEBUG) {
             Log.d(TAG, "Skipped network state update because GPS HAL AGPS-RIL is not  supported");
@@ -864,7 +877,6 @@ public class GnssLocationProvider implements LocationProviderInterface {
 
         if (mAGpsDataConnectionState == AGPS_DATA_CONNECTION_OPENING) {
             if (isConnected) {
-                String apnName = info.getExtraInfo();
                 if (apnName == null) {
                     // assign a dummy value in the case of C2K as otherwise we will have a runtime
                     // exception in the following call to native_agps_data_conn_open