Keep device state always updated

Tasker app showed up a bug where we can be out of sync with screen state
if we only received broadcasts when wifi is toggled on. Always receive
updates.

Bug: 8689583
Change-Id: Iad457c9768ed421765adb6a15d5f42ecf682da38
diff --git a/services/java/com/android/server/wifi/WifiService.java b/services/java/com/android/server/wifi/WifiService.java
index 9560199..5cf1966 100644
--- a/services/java/com/android/server/wifi/WifiService.java
+++ b/services/java/com/android/server/wifi/WifiService.java
@@ -121,8 +121,6 @@
      * on this */
     private WorkSource mScanWorkSource;
 
-    private boolean mIsReceiverRegistered = false;
-
     /**
      * Asynchronous channel to WifiStateMachine
      */
@@ -272,6 +270,11 @@
                         }
                     }
                 }, new IntentFilter(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION));
+
+        // Adding optimizations of only receiving broadcasts when wifi is enabled
+        // can result in race conditions when apps toggle wifi in the background
+        // without active user involvement. Always receive broadcasts.
+        registerForBroadcasts();
     }
 
     private WifiController mWifiController;
@@ -421,17 +424,6 @@
         }
 
         mWifiController.sendMessage(CMD_WIFI_TOGGLED);
-
-        if (enable) {
-            if (!mIsReceiverRegistered) {
-                registerForBroadcasts();
-                mIsReceiverRegistered = true;
-            }
-        } else if (mIsReceiverRegistered) {
-            mContext.unregisterReceiver(mReceiver);
-            mIsReceiverRegistered = false;
-        }
-
         return true;
     }