cherry-pick 288b4ac945 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
This commit is contained in:
@@ -268,7 +268,7 @@ public class WifiService extends IWifiManager.Stub {
|
|||||||
boolean wifiEnabled = getPersistedWifiEnabled() || testAndClearWifiSavedState();
|
boolean wifiEnabled = getPersistedWifiEnabled() || testAndClearWifiSavedState();
|
||||||
Slog.i(TAG, "WifiService starting up with Wi-Fi " +
|
Slog.i(TAG, "WifiService starting up with Wi-Fi " +
|
||||||
(wifiEnabled ? "enabled" : "disabled"));
|
(wifiEnabled ? "enabled" : "disabled"));
|
||||||
setWifiEnabledBlocking(wifiEnabled, true, Process.myUid());
|
setWifiEnabled(wifiEnabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateTetherState(ArrayList<String> available, ArrayList<String> tethered) {
|
private void updateTetherState(ArrayList<String> available, ArrayList<String> tethered) {
|
||||||
@@ -1857,10 +1857,10 @@ public class WifiService extends IWifiManager.Stub {
|
|||||||
switch (msg.what) {
|
switch (msg.what) {
|
||||||
|
|
||||||
case MESSAGE_ENABLE_WIFI:
|
case MESSAGE_ENABLE_WIFI:
|
||||||
|
setWifiEnabledBlocking(true, msg.arg1 == 1, msg.arg2);
|
||||||
if (mWifiWatchdogService == null) {
|
if (mWifiWatchdogService == null) {
|
||||||
mWifiWatchdogService = new WifiWatchdogService(mContext, mWifiStateTracker);
|
mWifiWatchdogService = new WifiWatchdogService(mContext, mWifiStateTracker);
|
||||||
}
|
}
|
||||||
setWifiEnabledBlocking(true, msg.arg1 == 1, msg.arg2);
|
|
||||||
sWakeLock.release();
|
sWakeLock.release();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -1878,10 +1878,7 @@ public class WifiService extends IWifiManager.Stub {
|
|||||||
// a non-zero msg.arg1 value means the "enabled" setting
|
// a non-zero msg.arg1 value means the "enabled" setting
|
||||||
// should be persisted
|
// should be persisted
|
||||||
setWifiEnabledBlocking(false, msg.arg1 == 1, msg.arg2);
|
setWifiEnabledBlocking(false, msg.arg1 == 1, msg.arg2);
|
||||||
if (mWifiWatchdogService != null) {
|
mWifiWatchdogService = null;
|
||||||
mWifiWatchdogService.quit();
|
|
||||||
mWifiWatchdogService = null;
|
|
||||||
}
|
|
||||||
sWakeLock.release();
|
sWakeLock.release();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|||||||
@@ -251,7 +251,6 @@ public class WifiWatchdogService {
|
|||||||
private void registerForWifiBroadcasts() {
|
private void registerForWifiBroadcasts() {
|
||||||
IntentFilter intentFilter = new IntentFilter();
|
IntentFilter intentFilter = new IntentFilter();
|
||||||
intentFilter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION);
|
intentFilter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION);
|
||||||
intentFilter.addAction(WifiManager.SUPPLICANT_CONNECTION_CHANGE_ACTION);
|
|
||||||
intentFilter.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION);
|
intentFilter.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION);
|
||||||
mContext.registerReceiver(mReceiver, intentFilter);
|
mContext.registerReceiver(mReceiver, intentFilter);
|
||||||
}
|
}
|
||||||
@@ -276,7 +275,7 @@ public class WifiWatchdogService {
|
|||||||
/**
|
/**
|
||||||
* Unregister broadcasts and quit the watchdog thread
|
* Unregister broadcasts and quit the watchdog thread
|
||||||
*/
|
*/
|
||||||
public void quit() {
|
private void quit() {
|
||||||
unregisterForWifiBroadcasts();
|
unregisterForWifiBroadcasts();
|
||||||
mContext.getContentResolver().unregisterContentObserver(mContentObserver);
|
mContext.getContentResolver().unregisterContentObserver(mContentObserver);
|
||||||
mHandler.removeAllActions();
|
mHandler.removeAllActions();
|
||||||
@@ -1117,9 +1116,6 @@ public class WifiWatchdogService {
|
|||||||
if (action.equals(WifiManager.NETWORK_STATE_CHANGED_ACTION)) {
|
if (action.equals(WifiManager.NETWORK_STATE_CHANGED_ACTION)) {
|
||||||
handleNetworkStateChanged(
|
handleNetworkStateChanged(
|
||||||
(NetworkInfo) intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO));
|
(NetworkInfo) intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO));
|
||||||
} else if (action.equals(WifiManager.SUPPLICANT_CONNECTION_CHANGE_ACTION)) {
|
|
||||||
handleSupplicantConnectionChanged(
|
|
||||||
intent.getBooleanExtra(WifiManager.EXTRA_SUPPLICANT_CONNECTED, false));
|
|
||||||
} else if (action.equals(WifiManager.WIFI_STATE_CHANGED_ACTION)) {
|
} else if (action.equals(WifiManager.WIFI_STATE_CHANGED_ACTION)) {
|
||||||
handleWifiStateChanged(intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE,
|
handleWifiStateChanged(intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE,
|
||||||
WifiManager.WIFI_STATE_UNKNOWN));
|
WifiManager.WIFI_STATE_UNKNOWN));
|
||||||
@@ -1153,15 +1149,9 @@ public class WifiWatchdogService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleSupplicantConnectionChanged(boolean connected) {
|
|
||||||
if (!connected) {
|
|
||||||
onDisconnected();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void handleWifiStateChanged(int wifiState) {
|
private void handleWifiStateChanged(int wifiState) {
|
||||||
if (wifiState == WifiManager.WIFI_STATE_DISABLED) {
|
if (wifiState == WifiManager.WIFI_STATE_DISABLED) {
|
||||||
onDisconnected();
|
quit();
|
||||||
} else if (wifiState == WifiManager.WIFI_STATE_ENABLED) {
|
} else if (wifiState == WifiManager.WIFI_STATE_ENABLED) {
|
||||||
onEnabled();
|
onEnabled();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user