Merge "Moved domain suffix enforcement setting to WifiConfigStore." into mnc-dev
diff --git a/service/java/com/android/server/wifi/WifiConfigStore.java b/service/java/com/android/server/wifi/WifiConfigStore.java
index 56bb9c0..652899e 100644
--- a/service/java/com/android/server/wifi/WifiConfigStore.java
+++ b/service/java/com/android/server/wifi/WifiConfigStore.java
@@ -2333,6 +2333,9 @@
                 } else if (config != null) {
                     switch (key) {
                         case SSID_KEY:
+                            if (config.isPasspoint()) {
+                                break;
+                            }
                             ssid = value;
                             if (config.SSID != null && !config.SSID.equals(ssid)) {
                                 loge("Error parsing network history file, mismatched SSIDs");
diff --git a/service/java/com/android/server/wifi/WifiServiceImpl.java b/service/java/com/android/server/wifi/WifiServiceImpl.java
index 3734a67..46058ad 100644
--- a/service/java/com/android/server/wifi/WifiServiceImpl.java
+++ b/service/java/com/android/server/wifi/WifiServiceImpl.java
@@ -444,7 +444,15 @@
             if (mInIdleMode) {
                 // Need to send an immediate scan result broadcast in case the
                 // caller is waiting for a result ..
-                mWifiStateMachine.sendScanResultsAvailableBroadcast(/* scanSucceeded = */ false);
+
+                // clear calling identity to send broadcast
+                long callingIdentity = Binder.clearCallingIdentity();
+                try {
+                    mWifiStateMachine.sendScanResultsAvailableBroadcast(/* scanSucceeded = */ false);
+                } finally {
+                    // restore calling identity
+                    Binder.restoreCallingIdentity(callingIdentity);
+                }
                 mScanPending = true;
                 return;
             }
diff --git a/service/java/com/android/server/wifi/WifiStateMachine.java b/service/java/com/android/server/wifi/WifiStateMachine.java
index 2c543b7..70b64db 100644
--- a/service/java/com/android/server/wifi/WifiStateMachine.java
+++ b/service/java/com/android/server/wifi/WifiStateMachine.java
@@ -4485,8 +4485,13 @@
         final boolean linkChanged = !newLp.equals(mLinkProperties);
         final boolean wasProvisioned = isProvisioned(mLinkProperties);
         final boolean isProvisioned = isProvisioned(newLp);
-        final boolean lostIPv4Provisioning =
-                mLinkProperties.hasIPv4Address() && !newLp.hasIPv4Address();
+        // TODO: Teach LinkProperties how to understand static assignment
+        // and simplify all this provisioning change detection logic by
+        // unifying it under LinkProperties.compareProvisioning().
+        final boolean lostProvisioning =
+                (wasProvisioned && !isProvisioned) ||
+                (mLinkProperties.hasIPv4Address() && !newLp.hasIPv4Address()) ||
+                (mLinkProperties.isIPv6Provisioned() && !newLp.isIPv6Provisioned());
         final DetailedState detailedState = getNetworkDetailedState();
 
         if (linkChanged) {
@@ -4501,6 +4506,12 @@
             if (mNetworkAgent != null) mNetworkAgent.sendLinkProperties(mLinkProperties);
         }
 
+        if (lostProvisioning) {
+            log("Lost IP layer provisioning!" +
+                    " was: " + mLinkProperties +
+                    " now: " + newLp);
+        }
+
         if (DBG) {
             StringBuilder sb = new StringBuilder();
             sb.append("updateLinkProperties nid: " + mLastNetworkId);
@@ -4557,7 +4568,7 @@
                 // DHCP failed. If we're not already provisioned, or we had IPv4 and now lost it,
                 // give up and disconnect.
                 // If we're already provisioned (e.g., IPv6-only network), stay connected.
-                if (!isProvisioned || lostIPv4Provisioning) {
+                if (!isProvisioned || lostProvisioning) {
                     sendMessage(CMD_IP_CONFIGURATION_LOST);
                 } else {
                     // DHCP failed, but we're provisioned (e.g., if we're on an IPv6-only network).
@@ -4588,7 +4599,7 @@
 
             case CMD_UPDATE_LINKPROPERTIES:
                 // IP addresses, DNS servers, etc. changed. Act accordingly.
-                if (wasProvisioned && !isProvisioned) {
+                if (lostProvisioning) {
                     // We no longer have a usable network configuration. Disconnect.
                     sendMessage(CMD_IP_CONFIGURATION_LOST);
                 } else if (!wasProvisioned && isProvisioned) {
diff --git a/service/java/com/android/server/wifi/anqp/IPAddressTypeAvailabilityElement.java b/service/java/com/android/server/wifi/anqp/IPAddressTypeAvailabilityElement.java
index 26ed721..8d71a3b 100644
--- a/service/java/com/android/server/wifi/anqp/IPAddressTypeAvailabilityElement.java
+++ b/service/java/com/android/server/wifi/anqp/IPAddressTypeAvailabilityElement.java
@@ -29,7 +29,7 @@
         mV6Availability = IPv6Availability.values()[ipField & 0x3];
 
         ipField = (ipField >> 2) & 0x3f;
-        mV4Availability = ipField <= IPv4Availability.values().length ?
+        mV4Availability = ipField < IPv4Availability.values().length ?
                 IPv4Availability.values()[ipField] :
                 IPv4Availability.Unknown;
     }