cherry-pick 288b4ac94571e6f77036831708e7bb7c31874688 into froyo

Killing the WifiWatchdogService thread from
WifiService can cause messages to be handled on
a dead thread. Quit the thread on the broadcast
instead.

A couple of more fixes:
- Do an asynchronous bring up of Wifi. This will
allow WifiWatchdogServiceThread to be immediately
brought up, instead of relying on an update.

- There is no need to listen on supplicant connection
in wifiwatchdog anymore. We kill the thread when
supplicant connection is no more.

Bug: 2546756
Change-Id: I15a188e031bc79856c55aabdd271287b0df0377d
diff --git a/services/java/com/android/server/WifiService.java b/services/java/com/android/server/WifiService.java
index e4d7623..76e0d74 100644
--- a/services/java/com/android/server/WifiService.java
+++ b/services/java/com/android/server/WifiService.java
@@ -268,7 +268,7 @@
         boolean wifiEnabled = getPersistedWifiEnabled() || testAndClearWifiSavedState();
         Slog.i(TAG, "WifiService starting up with Wi-Fi " +
                 (wifiEnabled ? "enabled" : "disabled"));
-        setWifiEnabledBlocking(wifiEnabled, true, Process.myUid());
+        setWifiEnabled(wifiEnabled);
     }
 
     private void updateTetherState(ArrayList<String> available, ArrayList<String> tethered) {
@@ -1857,10 +1857,10 @@
             switch (msg.what) {
 
                 case MESSAGE_ENABLE_WIFI:
+                    setWifiEnabledBlocking(true, msg.arg1 == 1, msg.arg2);
                     if (mWifiWatchdogService == null) {
                         mWifiWatchdogService = new WifiWatchdogService(mContext, mWifiStateTracker);
                     }
-                    setWifiEnabledBlocking(true, msg.arg1 == 1, msg.arg2);
                     sWakeLock.release();
                     break;
 
@@ -1878,10 +1878,7 @@
                     // a non-zero msg.arg1 value means the "enabled" setting
                     // should be persisted
                     setWifiEnabledBlocking(false, msg.arg1 == 1, msg.arg2);
-                    if (mWifiWatchdogService != null) {
-                        mWifiWatchdogService.quit();
-                        mWifiWatchdogService = null;
-                    }
+                    mWifiWatchdogService = null;
                     sWakeLock.release();
                     break;