Fix network reload when config is restored

With scan mode opted in, supplicant connection is not shut
down even when wifi is turned off. This is a problem since
networks need to be reloaded when wifi is turned off and turned on
and this currently happens only on a supplicant connection.

Fix to handle this for scan mode state.

Bug: 8714796
Change-Id: I7d66c39fb51018fb52e783341222cea993993893
diff --git a/wifi/java/android/net/wifi/WifiConfigStore.java b/wifi/java/android/net/wifi/WifiConfigStore.java
index 23a4e71..9418de1 100644
--- a/wifi/java/android/net/wifi/WifiConfigStore.java
+++ b/wifi/java/android/net/wifi/WifiConfigStore.java
@@ -156,7 +156,7 @@
      * Fetch the list of configured networks
      * and enable all stored networks in supplicant.
      */
-    void initialize() {
+    void loadAndEnableAllNetworks() {
         if (DBG) log("Loading config and enabling all networks");
         loadConfiguredNetworks();
         enableAllNetworks();
diff --git a/wifi/java/android/net/wifi/WifiStateMachine.java b/wifi/java/android/net/wifi/WifiStateMachine.java
index 2c3df95..9cae2cb 100644
--- a/wifi/java/android/net/wifi/WifiStateMachine.java
+++ b/wifi/java/android/net/wifi/WifiStateMachine.java
@@ -1111,6 +1111,7 @@
         pw.println("mUserWantsSuspendOpt " + mUserWantsSuspendOpt);
         pw.println("mSuspendOptNeedsDisabled " + mSuspendOptNeedsDisabled);
         pw.println("Supplicant status " + mWifiNative.status());
+        pw.println("mEnableBackgroundScan " + mEnableBackgroundScan);
         pw.println();
         mWifiConfigStore.dump(fd, pw, args);
     }
@@ -2121,7 +2122,7 @@
                     mLastSignalLevel = -1;
 
                     mWifiInfo.setMacAddress(mWifiNative.getMacAddress());
-                    mWifiConfigStore.initialize();
+                    mWifiConfigStore.loadAndEnableAllNetworks();
                     initializeWpsDetails();
 
                     sendSupplicantConnectionChangedBroadcast(true);
@@ -2657,9 +2658,13 @@
         public void exit() {
             if (mLastOperationMode == SCAN_ONLY_WITH_WIFI_OFF_MODE) {
                 setWifiState(WIFI_STATE_ENABLED);
+                // Load and re-enable networks when going back to enabled state
+                // This is essential for networks to show up after restore
+                mWifiConfigStore.loadAndEnableAllNetworks();
                 mWifiP2pChannel.sendMessage(CMD_ENABLE_P2P);
+            } else {
+                mWifiConfigStore.enableAllNetworks();
             }
-            mWifiConfigStore.enableAllNetworks();
             mWifiNative.reconnect();
         }
         @Override