Merge "Reduce/Fix system logging"

This commit is contained in:
Irfan Sheriff
2011-10-04 12:13:27 -07:00
committed by Android (Google) Code Review
5 changed files with 263 additions and 237 deletions

View File

@@ -336,17 +336,17 @@ public class DhcpStateMachine extends StateMachine {
DhcpInfoInternal dhcpInfoInternal = new DhcpInfoInternal(); DhcpInfoInternal dhcpInfoInternal = new DhcpInfoInternal();
if (dhcpAction == DhcpAction.START) { if (dhcpAction == DhcpAction.START) {
Log.d(TAG, "DHCP request on " + mInterfaceName); if (DBG) Log.d(TAG, "DHCP request on " + mInterfaceName);
success = NetworkUtils.runDhcp(mInterfaceName, dhcpInfoInternal); success = NetworkUtils.runDhcp(mInterfaceName, dhcpInfoInternal);
mDhcpInfo = dhcpInfoInternal; mDhcpInfo = dhcpInfoInternal;
} else if (dhcpAction == DhcpAction.RENEW) { } else if (dhcpAction == DhcpAction.RENEW) {
Log.d(TAG, "DHCP renewal on " + mInterfaceName); if (DBG) Log.d(TAG, "DHCP renewal on " + mInterfaceName);
success = NetworkUtils.runDhcpRenew(mInterfaceName, dhcpInfoInternal); success = NetworkUtils.runDhcpRenew(mInterfaceName, dhcpInfoInternal);
dhcpInfoInternal.updateFromDhcpRequest(mDhcpInfo); dhcpInfoInternal.updateFromDhcpRequest(mDhcpInfo);
} }
if (success) { if (success) {
Log.d(TAG, "DHCP succeeded on " + mInterfaceName); if (DBG) Log.d(TAG, "DHCP succeeded on " + mInterfaceName);
long leaseDuration = dhcpInfoInternal.leaseDuration; //int to long conversion long leaseDuration = dhcpInfoInternal.leaseDuration; //int to long conversion
//Sanity check for renewal //Sanity check for renewal
@@ -366,7 +366,7 @@ public class DhcpStateMachine extends StateMachine {
mController.obtainMessage(CMD_POST_DHCP_ACTION, DHCP_SUCCESS, 0, dhcpInfoInternal) mController.obtainMessage(CMD_POST_DHCP_ACTION, DHCP_SUCCESS, 0, dhcpInfoInternal)
.sendToTarget(); .sendToTarget();
} else { } else {
Log.d(TAG, "DHCP failed on " + mInterfaceName + ": " + Log.e(TAG, "DHCP failed on " + mInterfaceName + ": " +
NetworkUtils.getDhcpError()); NetworkUtils.getDhcpError());
NetworkUtils.stopDhcp(mInterfaceName); NetworkUtils.stopDhcp(mInterfaceName);
mController.obtainMessage(CMD_POST_DHCP_ACTION, DHCP_FAILURE, 0) mController.obtainMessage(CMD_POST_DHCP_ACTION, DHCP_FAILURE, 0)

View File

@@ -22,7 +22,7 @@ import android.os.Looper;
import android.os.Message; import android.os.Message;
import android.os.SystemClock; import android.os.SystemClock;
import android.provider.Settings; import android.provider.Settings;
import android.util.Slog; import android.util.Log;
import com.android.internal.util.Protocol; import com.android.internal.util.Protocol;
@@ -51,7 +51,7 @@ import java.util.concurrent.atomic.AtomicInteger;
* @hide * @hide
*/ */
public final class DnsPinger extends Handler { public final class DnsPinger extends Handler {
private static final boolean V = true; private static final boolean DBG = false;
private static final int RECEIVE_POLL_INTERVAL_MS = 200; private static final int RECEIVE_POLL_INTERVAL_MS = 200;
private static final int DNS_PORT = 53; private static final int DNS_PORT = 53;
@@ -154,7 +154,7 @@ public final class DnsPinger extends Handler {
newActivePing.socket.setNetworkInterface(NetworkInterface.getByName( newActivePing.socket.setNetworkInterface(NetworkInterface.getByName(
getCurrentLinkProperties().getInterfaceName())); getCurrentLinkProperties().getInterfaceName()));
} catch (Exception e) { } catch (Exception e) {
Slog.w(TAG,"sendDnsPing::Error binding to socket", e); loge("sendDnsPing::Error binding to socket " + e);
} }
newActivePing.packetId = (short) sRandom.nextInt(); newActivePing.packetId = (short) sRandom.nextInt();
@@ -165,8 +165,8 @@ public final class DnsPinger extends Handler {
// Send the DNS query // Send the DNS query
DatagramPacket packet = new DatagramPacket(buf, DatagramPacket packet = new DatagramPacket(buf,
buf.length, dnsAddress, DNS_PORT); buf.length, dnsAddress, DNS_PORT);
if (V) { if (DBG) {
Slog.v(TAG, "Sending a ping " + newActivePing.internalId + log("Sending a ping " + newActivePing.internalId +
" to " + dnsAddress.getHostAddress() " to " + dnsAddress.getHostAddress()
+ " with packetId " + newActivePing.packetId + "."); + " with packetId " + newActivePing.packetId + ".");
} }
@@ -196,15 +196,15 @@ public final class DnsPinger extends Handler {
curPing.result = curPing.result =
(int) (SystemClock.elapsedRealtime() - curPing.start); (int) (SystemClock.elapsedRealtime() - curPing.start);
} else { } else {
if (V) { if (DBG) {
Slog.v(TAG, "response ID didn't match, ignoring packet"); log("response ID didn't match, ignoring packet");
} }
} }
} catch (SocketTimeoutException e) { } catch (SocketTimeoutException e) {
// A timeout here doesn't mean anything - squelsh this exception // A timeout here doesn't mean anything - squelsh this exception
} catch (Exception e) { } catch (Exception e) {
if (V) { if (DBG) {
Slog.v(TAG, "DnsPinger.pingDns got socket exception: ", e); log("DnsPinger.pingDns got socket exception: " + e);
} }
curPing.result = SOCKET_EXCEPTION; curPing.result = SOCKET_EXCEPTION;
} }
@@ -244,13 +244,13 @@ public final class DnsPinger extends Handler {
public List<InetAddress> getDnsList() { public List<InetAddress> getDnsList() {
LinkProperties curLinkProps = getCurrentLinkProperties(); LinkProperties curLinkProps = getCurrentLinkProperties();
if (curLinkProps == null) { if (curLinkProps == null) {
Slog.e(TAG, "getCurLinkProperties:: LP for type" + mConnectionType + " is null!"); loge("getCurLinkProperties:: LP for type" + mConnectionType + " is null!");
return mDefaultDns; return mDefaultDns;
} }
Collection<InetAddress> dnses = curLinkProps.getDnses(); Collection<InetAddress> dnses = curLinkProps.getDnses();
if (dnses == null || dnses.size() == 0) { if (dnses == null || dnses.size() == 0) {
Slog.v(TAG, "getDns::LinkProps has null dns - returning default"); loge("getDns::LinkProps has null dns - returning default");
return mDefaultDns; return mDefaultDns;
} }
@@ -277,8 +277,8 @@ public final class DnsPinger extends Handler {
} }
private void sendResponse(int internalId, int externalId, int responseVal) { private void sendResponse(int internalId, int externalId, int responseVal) {
if(V) { if(DBG) {
Slog.d(TAG, "Responding to packet " + internalId + log("Responding to packet " + internalId +
" externalId " + externalId + " externalId " + externalId +
" and val " + responseVal); " and val " + responseVal);
} }
@@ -304,7 +304,7 @@ public final class DnsPinger extends Handler {
try { try {
return NetworkUtils.numericToInetAddress(dns); return NetworkUtils.numericToInetAddress(dns);
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
Slog.w(TAG, "getDefaultDns::malformed default dns address"); loge("getDefaultDns::malformed default dns address");
return null; return null;
} }
} }
@@ -323,4 +323,12 @@ public final class DnsPinger extends Handler {
0, 1, // QTYPE, set to 1 = A (host address) 0, 1, // QTYPE, set to 1 = A (host address)
0, 1 // QCLASS, set to 1 = IN (internet) 0, 1 // QCLASS, set to 1 = IN (internet)
}; };
private void log(String s) {
Log.d(TAG, s);
}
private void loge(String s) {
Log.e(TAG, s);
}
} }

View File

@@ -100,6 +100,7 @@ class WifiConfigStore {
private static Context sContext; private static Context sContext;
private static final String TAG = "WifiConfigStore"; private static final String TAG = "WifiConfigStore";
private static final boolean DBG = false;
/* configured networks with network id as the key */ /* configured networks with network id as the key */
private static HashMap<Integer, WifiConfiguration> sConfiguredNetworks = private static HashMap<Integer, WifiConfiguration> sConfiguredNetworks =
@@ -140,7 +141,7 @@ class WifiConfigStore {
* and enable all stored networks in supplicant. * and enable all stored networks in supplicant.
*/ */
static void initialize(Context context) { static void initialize(Context context) {
Log.d(TAG, "Loading config and enabling all networks"); if (DBG) log("Loading config and enabling all networks");
sContext = context; sContext = context;
loadConfiguredNetworks(); loadConfiguredNetworks();
enableAllNetworks(); enableAllNetworks();
@@ -173,7 +174,7 @@ class WifiConfigStore {
networkEnabledStateChanged = true; networkEnabledStateChanged = true;
config.status = Status.ENABLED; config.status = Status.ENABLED;
} else { } else {
Log.e(TAG, "Enable network failed on " + config.networkId); loge("Enable network failed on " + config.networkId);
} }
} }
} }
@@ -204,7 +205,7 @@ class WifiConfigStore {
if (netId != INVALID_NETWORK_ID) { if (netId != INVALID_NETWORK_ID) {
selectNetwork(netId); selectNetwork(netId);
} else { } else {
Log.e(TAG, "Failed to update network " + config); loge("Failed to update network " + config);
} }
return netId; return netId;
} }
@@ -290,7 +291,7 @@ class WifiConfigStore {
writeIpAndProxyConfigurations(); writeIpAndProxyConfigurations();
sendConfiguredNetworksChangedBroadcast(); sendConfiguredNetworksChangedBroadcast();
} else { } else {
Log.e(TAG, "Failed to remove network " + netId); loge("Failed to remove network " + netId);
} }
} }
@@ -404,7 +405,7 @@ class WifiConfigStore {
markAllNetworksDisabled(); markAllNetworksDisabled();
result.status = WpsResult.Status.SUCCESS; result.status = WpsResult.Status.SUCCESS;
} else { } else {
Log.e(TAG, "Failed to start WPS pin method configuration"); loge("Failed to start WPS pin method configuration");
result.status = WpsResult.Status.FAILURE; result.status = WpsResult.Status.FAILURE;
} }
return result; return result;
@@ -423,7 +424,7 @@ class WifiConfigStore {
markAllNetworksDisabled(); markAllNetworksDisabled();
result.status = WpsResult.Status.SUCCESS; result.status = WpsResult.Status.SUCCESS;
} else { } else {
Log.e(TAG, "Failed to start WPS pin method configuration"); loge("Failed to start WPS pin method configuration");
result.status = WpsResult.Status.FAILURE; result.status = WpsResult.Status.FAILURE;
} }
return result; return result;
@@ -439,7 +440,7 @@ class WifiConfigStore {
markAllNetworksDisabled(); markAllNetworksDisabled();
result.status = WpsResult.Status.SUCCESS; result.status = WpsResult.Status.SUCCESS;
} else { } else {
Log.e(TAG, "Failed to start WPS push button configuration"); loge("Failed to start WPS push button configuration");
result.status = WpsResult.Status.FAILURE; result.status = WpsResult.Status.FAILURE;
} }
return result; return result;
@@ -680,7 +681,7 @@ class WifiConfigStore {
/* Ignore */ /* Ignore */
break; break;
default: default:
Log.e(TAG, "Ignore invalid ip assignment while writing"); loge("Ignore invalid ip assignment while writing");
break; break;
} }
@@ -707,7 +708,7 @@ class WifiConfigStore {
/* Ignore */ /* Ignore */
break; break;
default: default:
Log.e(TAG, "Ignore invalid proxy settings while writing"); loge("Ignore invalid proxy settings while writing");
break; break;
} }
if (writeToFile) { if (writeToFile) {
@@ -715,14 +716,14 @@ class WifiConfigStore {
out.writeInt(configKey(config)); out.writeInt(configKey(config));
} }
} catch (NullPointerException e) { } catch (NullPointerException e) {
Log.e(TAG, "Failure in writing " + config.linkProperties + e); loge("Failure in writing " + config.linkProperties + e);
} }
out.writeUTF(EOS); out.writeUTF(EOS);
} }
} }
} catch (IOException e) { } catch (IOException e) {
Log.e(TAG, "Error writing data file"); loge("Error writing data file");
} finally { } finally {
if (out != null) { if (out != null) {
try { try {
@@ -741,7 +742,7 @@ class WifiConfigStore {
int version = in.readInt(); int version = in.readInt();
if (version != 2 && version != 1) { if (version != 2 && version != 1) {
Log.e(TAG, "Bad version on IP configuration file, ignore read"); loge("Bad version on IP configuration file, ignore read");
return; return;
} }
@@ -797,10 +798,10 @@ class WifiConfigStore {
} else if (key.equals(EOS)) { } else if (key.equals(EOS)) {
break; break;
} else { } else {
Log.e(TAG, "Ignore unknown key " + key + "while reading"); loge("Ignore unknown key " + key + "while reading");
} }
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
Log.e(TAG, "Ignore invalid address while reading" + e); loge("Ignore invalid address while reading" + e);
} }
} while (true); } while (true);
@@ -810,7 +811,7 @@ class WifiConfigStore {
sNetworkIds.get(id)); sNetworkIds.get(id));
if (config == null) { if (config == null) {
Log.e(TAG, "configuration found for missing network, ignored"); loge("configuration found for missing network, ignored");
} else { } else {
config.linkProperties = linkProperties; config.linkProperties = linkProperties;
switch (ipAssignment) { switch (ipAssignment) {
@@ -822,7 +823,7 @@ class WifiConfigStore {
//Ignore //Ignore
break; break;
default: default:
Log.e(TAG, "Ignore invalid ip assignment while reading"); loge("Ignore invalid ip assignment while reading");
break; break;
} }
@@ -840,18 +841,18 @@ class WifiConfigStore {
//Ignore //Ignore
break; break;
default: default:
Log.e(TAG, "Ignore invalid proxy settings while reading"); loge("Ignore invalid proxy settings while reading");
break; break;
} }
} }
} }
} else { } else {
Log.e(TAG, "Missing id while parsing configuration"); loge("Missing id while parsing configuration");
} }
} }
} catch (EOFException ignore) { } catch (EOFException ignore) {
} catch (IOException e) { } catch (IOException e) {
Log.e(TAG, "Error parsing configuration" + e); loge("Error parsing configuration" + e);
} finally { } finally {
if (in != null) { if (in != null) {
try { try {
@@ -878,7 +879,7 @@ class WifiConfigStore {
newNetwork = true; newNetwork = true;
netId = WifiNative.addNetworkCommand(); netId = WifiNative.addNetworkCommand();
if (netId < 0) { if (netId < 0) {
Log.e(TAG, "Failed to add a network!"); loge("Failed to add a network!");
return new NetworkUpdateResult(INVALID_NETWORK_ID); return new NetworkUpdateResult(INVALID_NETWORK_ID);
} }
} }
@@ -893,7 +894,7 @@ class WifiConfigStore {
netId, netId,
WifiConfiguration.ssidVarName, WifiConfiguration.ssidVarName,
config.SSID)) { config.SSID)) {
Log.d(TAG, "failed to set SSID: "+config.SSID); loge("failed to set SSID: "+config.SSID);
break setVariables; break setVariables;
} }
@@ -902,7 +903,7 @@ class WifiConfigStore {
netId, netId,
WifiConfiguration.bssidVarName, WifiConfiguration.bssidVarName,
config.BSSID)) { config.BSSID)) {
Log.d(TAG, "failed to set BSSID: "+config.BSSID); loge("failed to set BSSID: "+config.BSSID);
break setVariables; break setVariables;
} }
@@ -913,7 +914,7 @@ class WifiConfigStore {
netId, netId,
WifiConfiguration.KeyMgmt.varName, WifiConfiguration.KeyMgmt.varName,
allowedKeyManagementString)) { allowedKeyManagementString)) {
Log.d(TAG, "failed to set key_mgmt: "+ loge("failed to set key_mgmt: "+
allowedKeyManagementString); allowedKeyManagementString);
break setVariables; break setVariables;
} }
@@ -925,7 +926,7 @@ class WifiConfigStore {
netId, netId,
WifiConfiguration.Protocol.varName, WifiConfiguration.Protocol.varName,
allowedProtocolsString)) { allowedProtocolsString)) {
Log.d(TAG, "failed to set proto: "+ loge("failed to set proto: "+
allowedProtocolsString); allowedProtocolsString);
break setVariables; break setVariables;
} }
@@ -937,7 +938,7 @@ class WifiConfigStore {
netId, netId,
WifiConfiguration.AuthAlgorithm.varName, WifiConfiguration.AuthAlgorithm.varName,
allowedAuthAlgorithmsString)) { allowedAuthAlgorithmsString)) {
Log.d(TAG, "failed to set auth_alg: "+ loge("failed to set auth_alg: "+
allowedAuthAlgorithmsString); allowedAuthAlgorithmsString);
break setVariables; break setVariables;
} }
@@ -950,7 +951,7 @@ class WifiConfigStore {
netId, netId,
WifiConfiguration.PairwiseCipher.varName, WifiConfiguration.PairwiseCipher.varName,
allowedPairwiseCiphersString)) { allowedPairwiseCiphersString)) {
Log.d(TAG, "failed to set pairwise: "+ loge("failed to set pairwise: "+
allowedPairwiseCiphersString); allowedPairwiseCiphersString);
break setVariables; break setVariables;
} }
@@ -962,7 +963,7 @@ class WifiConfigStore {
netId, netId,
WifiConfiguration.GroupCipher.varName, WifiConfiguration.GroupCipher.varName,
allowedGroupCiphersString)) { allowedGroupCiphersString)) {
Log.d(TAG, "failed to set group: "+ loge("failed to set group: "+
allowedGroupCiphersString); allowedGroupCiphersString);
break setVariables; break setVariables;
} }
@@ -974,7 +975,7 @@ class WifiConfigStore {
netId, netId,
WifiConfiguration.pskVarName, WifiConfiguration.pskVarName,
config.preSharedKey)) { config.preSharedKey)) {
Log.d(TAG, "failed to set psk"); loge("failed to set psk");
break setVariables; break setVariables;
} }
@@ -988,9 +989,7 @@ class WifiConfigStore {
netId, netId,
WifiConfiguration.wepKeyVarNames[i], WifiConfiguration.wepKeyVarNames[i],
config.wepKeys[i])) { config.wepKeys[i])) {
Log.d(TAG, loge("failed to set wep_key" + i + ": " + config.wepKeys[i]);
"failed to set wep_key"+i+": " +
config.wepKeys[i]);
break setVariables; break setVariables;
} }
hasSetKey = true; hasSetKey = true;
@@ -1003,9 +1002,7 @@ class WifiConfigStore {
netId, netId,
WifiConfiguration.wepTxKeyIdxVarName, WifiConfiguration.wepTxKeyIdxVarName,
Integer.toString(config.wepTxKeyIndex))) { Integer.toString(config.wepTxKeyIndex))) {
Log.d(TAG, loge("failed to set wep_tx_keyidx: " + config.wepTxKeyIndex);
"failed to set wep_tx_keyidx: "+
config.wepTxKeyIndex);
break setVariables; break setVariables;
} }
} }
@@ -1014,7 +1011,7 @@ class WifiConfigStore {
netId, netId,
WifiConfiguration.priorityVarName, WifiConfiguration.priorityVarName,
Integer.toString(config.priority))) { Integer.toString(config.priority))) {
Log.d(TAG, config.SSID + ": failed to set priority: " loge(config.SSID + ": failed to set priority: "
+config.priority); +config.priority);
break setVariables; break setVariables;
} }
@@ -1023,7 +1020,7 @@ class WifiConfigStore {
netId, netId,
WifiConfiguration.hiddenSSIDVarName, WifiConfiguration.hiddenSSIDVarName,
Integer.toString(config.hiddenSSID ? 1 : 0))) { Integer.toString(config.hiddenSSID ? 1 : 0))) {
Log.d(TAG, config.SSID + ": failed to set hiddenSSID: "+ loge(config.SSID + ": failed to set hiddenSSID: "+
config.hiddenSSID); config.hiddenSSID);
break setVariables; break setVariables;
} }
@@ -1040,7 +1037,7 @@ class WifiConfigStore {
netId, netId,
varName, varName,
value)) { value)) {
Log.d(TAG, config.SSID + ": failed to set " + varName + loge(config.SSID + ": failed to set " + varName +
": " + value); ": " + value);
break setVariables; break setVariables;
} }
@@ -1052,9 +1049,7 @@ class WifiConfigStore {
if (updateFailed) { if (updateFailed) {
if (newNetwork) { if (newNetwork) {
WifiNative.removeNetworkCommand(netId); WifiNative.removeNetworkCommand(netId);
Log.d(TAG, loge("Failed to set a network variable, removed network: " + netId);
"Failed to set a network variable, removed network: "
+ netId);
} }
return new NetworkUpdateResult(INVALID_NETWORK_ID); return new NetworkUpdateResult(INVALID_NETWORK_ID);
} }
@@ -1130,7 +1125,7 @@ class WifiConfigStore {
/* Ignore */ /* Ignore */
break; break;
default: default:
Log.e(TAG, "Ignore invalid ip assignment during write"); loge("Ignore invalid ip assignment during write");
break; break;
} }
@@ -1154,7 +1149,7 @@ class WifiConfigStore {
/* Ignore */ /* Ignore */
break; break;
default: default:
Log.e(TAG, "Ignore invalid proxy configuration during write"); loge("Ignore invalid proxy configuration during write");
break; break;
} }
@@ -1163,7 +1158,7 @@ class WifiConfigStore {
} else { } else {
currentConfig.ipAssignment = newConfig.ipAssignment; currentConfig.ipAssignment = newConfig.ipAssignment;
addIpSettingsFromConfig(linkProperties, newConfig); addIpSettingsFromConfig(linkProperties, newConfig);
Log.d(TAG, "IP config changed SSID = " + currentConfig.SSID + " linkProperties: " + log("IP config changed SSID = " + currentConfig.SSID + " linkProperties: " +
linkProperties.toString()); linkProperties.toString());
} }
@@ -1173,9 +1168,9 @@ class WifiConfigStore {
} else { } else {
currentConfig.proxySettings = newConfig.proxySettings; currentConfig.proxySettings = newConfig.proxySettings;
linkProperties.setHttpProxy(newConfig.linkProperties.getHttpProxy()); linkProperties.setHttpProxy(newConfig.linkProperties.getHttpProxy());
Log.d(TAG, "proxy changed SSID = " + currentConfig.SSID); log("proxy changed SSID = " + currentConfig.SSID);
if (linkProperties.getHttpProxy() != null) { if (linkProperties.getHttpProxy() != null) {
Log.d(TAG, " proxyProperties: " + linkProperties.getHttpProxy().toString()); log(" proxyProperties: " + linkProperties.getHttpProxy().toString());
} }
} }
@@ -1394,7 +1389,7 @@ class WifiConfigStore {
// if we ever get here, we should probably add the // if we ever get here, we should probably add the
// value to WifiConfiguration to reflect that it's // value to WifiConfiguration to reflect that it's
// supported by the WPA supplicant // supported by the WPA supplicant
Log.w(TAG, "Failed to look-up a string: " + string); loge("Failed to look-up a string: " + string);
return -1; return -1;
} }
@@ -1431,4 +1426,12 @@ class WifiConfigStore {
public static String getConfigFile() { public static String getConfigFile() {
return ipConfigFile; return ipConfigFile;
} }
private static void loge(String s) {
Log.e(TAG, s);
}
private static void log(String s) {
Log.d(TAG, s);
}
} }

View File

@@ -75,7 +75,6 @@ import android.provider.Settings;
import android.util.EventLog; import android.util.EventLog;
import android.util.Log; import android.util.Log;
import android.util.LruCache; import android.util.LruCache;
import android.util.Slog;
import com.android.internal.app.IBatteryStats; import com.android.internal.app.IBatteryStats;
import com.android.internal.util.AsyncChannel; import com.android.internal.util.AsyncChannel;
@@ -1104,12 +1103,12 @@ public class WifiStateMachine extends StateMachine {
mNwService.setInterfaceConfig(intf, ifcg); mNwService.setInterfaceConfig(intf, ifcg);
} }
} catch (Exception e) { } catch (Exception e) {
Log.e(TAG, "Error configuring interface " + intf + ", :" + e); loge("Error configuring interface " + intf + ", :" + e);
return false; return false;
} }
if(mCm.tether(intf) != ConnectivityManager.TETHER_ERROR_NO_ERROR) { if(mCm.tether(intf) != ConnectivityManager.TETHER_ERROR_NO_ERROR) {
Log.e(TAG, "Error tethering on " + intf); loge("Error tethering on " + intf);
return false; return false;
} }
return true; return true;
@@ -1135,11 +1134,11 @@ public class WifiStateMachine extends StateMachine {
mNwService.setInterfaceConfig(mInterfaceName, ifcg); mNwService.setInterfaceConfig(mInterfaceName, ifcg);
} }
} catch (Exception e) { } catch (Exception e) {
Log.e(TAG, "Error resetting interface " + mInterfaceName + ", :" + e); loge("Error resetting interface " + mInterfaceName + ", :" + e);
} }
if (mCm.untether(mInterfaceName) != ConnectivityManager.TETHER_ERROR_NO_ERROR) { if (mCm.untether(mInterfaceName) != ConnectivityManager.TETHER_ERROR_NO_ERROR) {
Log.e(TAG, "Untether initiate failed!"); loge("Untether initiate failed!");
} }
} }
@@ -1175,12 +1174,12 @@ public class WifiStateMachine extends StateMachine {
mBatteryStats.noteWifiOff(); mBatteryStats.noteWifiOff();
} }
} catch (RemoteException e) { } catch (RemoteException e) {
Log.e(TAG, "Failed to note battery stats in wifi"); loge("Failed to note battery stats in wifi");
} }
mWifiState.set(wifiState); mWifiState.set(wifiState);
if (DBG) Log.d(TAG, "setWifiState: " + syncGetWifiStateByName()); if (DBG) log("setWifiState: " + syncGetWifiStateByName());
final Intent intent = new Intent(WifiManager.WIFI_STATE_CHANGED_ACTION); final Intent intent = new Intent(WifiManager.WIFI_STATE_CHANGED_ACTION);
intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT); intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
@@ -1199,13 +1198,13 @@ public class WifiStateMachine extends StateMachine {
mBatteryStats.noteWifiOff(); mBatteryStats.noteWifiOff();
} }
} catch (RemoteException e) { } catch (RemoteException e) {
Log.d(TAG, "Failed to note battery stats in wifi"); loge("Failed to note battery stats in wifi");
} }
// Update state // Update state
mWifiApState.set(wifiApState); mWifiApState.set(wifiApState);
if (DBG) Log.d(TAG, "setWifiApState: " + syncGetWifiApStateByName()); if (DBG) log("setWifiApState: " + syncGetWifiApStateByName());
final Intent intent = new Intent(WifiManager.WIFI_AP_STATE_CHANGED_ACTION); final Intent intent = new Intent(WifiManager.WIFI_AP_STATE_CHANGED_ACTION);
intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT); intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
@@ -1291,7 +1290,7 @@ public class WifiStateMachine extends StateMachine {
} }
} }
} else { } else {
Log.w(TAG, "Misformatted scan result text with " + loge("Misformatted scan result text with " +
result.length + " fields: " + line); result.length + " fields: " + line);
} }
} }
@@ -1419,15 +1418,15 @@ public class WifiStateMachine extends StateMachine {
private void setHighPerfModeEnabledNative(boolean enable) { private void setHighPerfModeEnabledNative(boolean enable) {
if(!WifiNative.setSuspendOptimizationsCommand(!enable)) { if(!WifiNative.setSuspendOptimizationsCommand(!enable)) {
Log.e(TAG, "set suspend optimizations failed!"); loge("set suspend optimizations failed!");
} }
if (enable) { if (enable) {
if (!WifiNative.setPowerModeCommand(POWER_MODE_ACTIVE)) { if (!WifiNative.setPowerModeCommand(POWER_MODE_ACTIVE)) {
Log.e(TAG, "set power mode active failed!"); loge("set power mode active failed!");
} }
} else { } else {
if (!WifiNative.setPowerModeCommand(POWER_MODE_AUTO)) { if (!WifiNative.setPowerModeCommand(POWER_MODE_AUTO)) {
Log.e(TAG, "set power mode auto failed!"); loge("set power mode auto failed!");
} }
} }
} }
@@ -1442,7 +1441,10 @@ public class WifiStateMachine extends StateMachine {
mLinkProperties.setHttpProxy(WifiConfigStore.getProxyProperties(mLastNetworkId)); mLinkProperties.setHttpProxy(WifiConfigStore.getProxyProperties(mLastNetworkId));
} }
mLinkProperties.setInterfaceName(mInterfaceName); mLinkProperties.setInterfaceName(mInterfaceName);
Log.d(TAG, "netId=" + mLastNetworkId + " Link configured: " + mLinkProperties.toString()); if (DBG) {
log("netId=" + mLastNetworkId + " Link configured: " +
mLinkProperties.toString());
}
} }
private int getMaxDhcpRetries() { private int getMaxDhcpRetries() {
@@ -1503,8 +1505,11 @@ public class WifiStateMachine extends StateMachine {
* @param state the new @{code DetailedState} * @param state the new @{code DetailedState}
*/ */
private void setNetworkDetailedState(NetworkInfo.DetailedState state) { private void setNetworkDetailedState(NetworkInfo.DetailedState state) {
Log.d(TAG, "setDetailed state, old =" if (DBG) {
+ mNetworkInfo.getDetailedState() + " and new state=" + state); log("setDetailed state, old ="
+ mNetworkInfo.getDetailedState() + " and new state=" + state);
}
if (state != mNetworkInfo.getDetailedState()) { if (state != mNetworkInfo.getDetailedState()) {
mNetworkInfo.setDetailedState(state, null, null); mNetworkInfo.setDetailedState(state, null, null);
} }
@@ -1547,7 +1552,7 @@ public class WifiStateMachine extends StateMachine {
* using the interface, stopping DHCP & disabling interface * using the interface, stopping DHCP & disabling interface
*/ */
private void handleNetworkDisconnect() { private void handleNetworkDisconnect() {
Log.d(TAG, "Stopping DHCP and clearing IP"); if (DBG) log("Stopping DHCP and clearing IP");
/* /*
* stop DHCP * stop DHCP
@@ -1562,7 +1567,7 @@ public class WifiStateMachine extends StateMachine {
mNwService.clearInterfaceAddresses(mInterfaceName); mNwService.clearInterfaceAddresses(mInterfaceName);
mNwService.disableIpv6(mInterfaceName); mNwService.disableIpv6(mInterfaceName);
} catch (Exception e) { } catch (Exception e) {
Log.e(TAG, "Failed to clear addresses or disable ipv6" + e); loge("Failed to clear addresses or disable ipv6" + e);
} }
/* Reset data structures */ /* Reset data structures */
@@ -1647,8 +1652,10 @@ public class WifiStateMachine extends StateMachine {
linkProperties.setHttpProxy(WifiConfigStore.getProxyProperties(mLastNetworkId)); linkProperties.setHttpProxy(WifiConfigStore.getProxyProperties(mLastNetworkId));
linkProperties.setInterfaceName(mInterfaceName); linkProperties.setInterfaceName(mInterfaceName);
if (!linkProperties.equals(mLinkProperties)) { if (!linkProperties.equals(mLinkProperties)) {
Log.d(TAG, "Link configuration changed for netId: " + mLastNetworkId if (DBG) {
+ " old: " + mLinkProperties + "new: " + linkProperties); log("Link configuration changed for netId: " + mLastNetworkId
+ " old: " + mLinkProperties + "new: " + linkProperties);
}
mLinkProperties = linkProperties; mLinkProperties = linkProperties;
sendLinkConfigurationChangedBroadcast(); sendLinkConfigurationChangedBroadcast();
} }
@@ -1660,7 +1667,7 @@ public class WifiStateMachine extends StateMachine {
} }
private void handleFailedIpConfiguration() { private void handleFailedIpConfiguration() {
Log.e(TAG, "IP configuration failed"); loge("IP configuration failed");
mWifiInfo.setInetAddress(null); mWifiInfo.setInetAddress(null);
/** /**
@@ -1668,7 +1675,7 @@ public class WifiStateMachine extends StateMachine {
* to a given network, disable the network * to a given network, disable the network
*/ */
if (++mReconnectCount > getMaxDhcpRetries()) { if (++mReconnectCount > getMaxDhcpRetries()) {
Log.e(TAG, "Failed " + loge("Failed " +
mReconnectCount + " times, Disabling " + mLastNetworkId); mReconnectCount + " times, Disabling " + mLastNetworkId);
WifiConfigStore.disableNetwork(mLastNetworkId, WifiConfigStore.disableNetwork(mLastNetworkId,
WifiConfiguration.DISABLED_DHCP_FAILURE); WifiConfiguration.DISABLED_DHCP_FAILURE);
@@ -1697,12 +1704,12 @@ public class WifiStateMachine extends StateMachine {
try { try {
mNwService.startAccessPoint(config, mInterfaceName, SOFTAP_IFACE); mNwService.startAccessPoint(config, mInterfaceName, SOFTAP_IFACE);
} catch (Exception e) { } catch (Exception e) {
Log.e(TAG, "Exception in softap start " + e); loge("Exception in softap start " + e);
try { try {
mNwService.stopAccessPoint(mInterfaceName); mNwService.stopAccessPoint(mInterfaceName);
mNwService.startAccessPoint(config, mInterfaceName, SOFTAP_IFACE); mNwService.startAccessPoint(config, mInterfaceName, SOFTAP_IFACE);
} catch (Exception e1) { } catch (Exception e1) {
Log.e(TAG, "Exception in softap re-start " + e1); loge("Exception in softap re-start " + e1);
return false; return false;
} }
} }
@@ -1716,17 +1723,17 @@ public class WifiStateMachine extends StateMachine {
class DefaultState extends State { class DefaultState extends State {
@Override @Override
public boolean processMessage(Message message) { public boolean processMessage(Message message) {
if (DBG) Log.d(TAG, getName() + message.toString() + "\n"); if (DBG) log(getName() + message.toString() + "\n");
switch (message.what) { switch (message.what) {
case AsyncChannel.CMD_CHANNEL_HALF_CONNECTED: case AsyncChannel.CMD_CHANNEL_HALF_CONNECTED:
if (message.arg1 == AsyncChannel.STATUS_SUCCESSFUL) { if (message.arg1 == AsyncChannel.STATUS_SUCCESSFUL) {
mWifiP2pChannel.sendMessage(AsyncChannel.CMD_CHANNEL_FULL_CONNECTION); mWifiP2pChannel.sendMessage(AsyncChannel.CMD_CHANNEL_FULL_CONNECTION);
} else { } else {
Log.e(TAG, "WifiP2pService connection failure, error=" + message.arg1); loge("WifiP2pService connection failure, error=" + message.arg1);
} }
break; break;
case AsyncChannel.CMD_CHANNEL_DISCONNECTED: case AsyncChannel.CMD_CHANNEL_DISCONNECTED:
Log.e(TAG, "WifiP2pService channel lost, message.arg1 =" + message.arg1); loge("WifiP2pService channel lost, message.arg1 =" + message.arg1);
//TODO: Re-establish connection to state machine after a delay //TODO: Re-establish connection to state machine after a delay
//mWifiP2pChannel.connect(mContext, getHandler(), mWifiP2pManager.getMessenger()); //mWifiP2pChannel.connect(mContext, getHandler(), mWifiP2pManager.getMessenger());
break; break;
@@ -1812,7 +1819,7 @@ public class WifiStateMachine extends StateMachine {
deferMessage(message); deferMessage(message);
break; break;
default: default:
Log.e(TAG, "Error! unhandled message" + message); loge("Error! unhandled message" + message);
break; break;
} }
return HANDLED; return HANDLED;
@@ -1823,7 +1830,7 @@ public class WifiStateMachine extends StateMachine {
@Override @Override
//TODO: could move logging into a common class //TODO: could move logging into a common class
public void enter() { public void enter() {
if (DBG) Log.d(TAG, getName() + "\n"); if (DBG) log(getName() + "\n");
// [31-8] Reserved for future use // [31-8] Reserved for future use
// [7 - 0] HSM state change // [7 - 0] HSM state change
// 50021 wifi_state_changed (custom|1|5) // 50021 wifi_state_changed (custom|1|5)
@@ -1853,9 +1860,9 @@ public class WifiStateMachine extends StateMachine {
try { try {
mNwService.disableIpv6(mInterfaceName); mNwService.disableIpv6(mInterfaceName);
} catch (RemoteException re) { } catch (RemoteException re) {
Log.e(TAG, "Failed to disable IPv6: " + re); loge("Failed to disable IPv6: " + re);
} catch (IllegalStateException e) { } catch (IllegalStateException e) {
Log.e(TAG, "Failed to disable IPv6: " + e); loge("Failed to disable IPv6: " + e);
} }
} }
} }
@@ -1863,7 +1870,7 @@ public class WifiStateMachine extends StateMachine {
class DriverLoadingState extends State { class DriverLoadingState extends State {
@Override @Override
public void enter() { public void enter() {
if (DBG) Log.d(TAG, getName() + "\n"); if (DBG) log(getName() + "\n");
EventLog.writeEvent(EVENTLOG_WIFI_STATE_CHANGED, getName()); EventLog.writeEvent(EVENTLOG_WIFI_STATE_CHANGED, getName());
final Message message = new Message(); final Message message = new Message();
@@ -1885,10 +1892,10 @@ public class WifiStateMachine extends StateMachine {
} }
if(WifiNative.loadDriver()) { if(WifiNative.loadDriver()) {
Log.d(TAG, "Driver load successful"); if (DBG) log("Driver load successful");
sendMessage(CMD_LOAD_DRIVER_SUCCESS); sendMessage(CMD_LOAD_DRIVER_SUCCESS);
} else { } else {
Log.e(TAG, "Failed to load driver!"); loge("Failed to load driver!");
switch(message.arg1) { switch(message.arg1) {
case WIFI_STATE_ENABLING: case WIFI_STATE_ENABLING:
setWifiState(WIFI_STATE_UNKNOWN); setWifiState(WIFI_STATE_UNKNOWN);
@@ -1906,7 +1913,7 @@ public class WifiStateMachine extends StateMachine {
@Override @Override
public boolean processMessage(Message message) { public boolean processMessage(Message message) {
if (DBG) Log.d(TAG, getName() + message.toString() + "\n"); if (DBG) log(getName() + message.toString() + "\n");
switch (message.what) { switch (message.what) {
case CMD_LOAD_DRIVER_SUCCESS: case CMD_LOAD_DRIVER_SUCCESS:
transitionTo(mDriverLoadedState); transitionTo(mDriverLoadedState);
@@ -1942,12 +1949,12 @@ public class WifiStateMachine extends StateMachine {
class DriverLoadedState extends State { class DriverLoadedState extends State {
@Override @Override
public void enter() { public void enter() {
if (DBG) Log.d(TAG, getName() + "\n"); if (DBG) log(getName() + "\n");
EventLog.writeEvent(EVENTLOG_WIFI_STATE_CHANGED, getName()); EventLog.writeEvent(EVENTLOG_WIFI_STATE_CHANGED, getName());
} }
@Override @Override
public boolean processMessage(Message message) { public boolean processMessage(Message message) {
if (DBG) Log.d(TAG, getName() + message.toString() + "\n"); if (DBG) log(getName() + message.toString() + "\n");
switch(message.what) { switch(message.what) {
case CMD_UNLOAD_DRIVER: case CMD_UNLOAD_DRIVER:
transitionTo(mDriverUnloadingState); transitionTo(mDriverUnloadingState);
@@ -1956,7 +1963,7 @@ public class WifiStateMachine extends StateMachine {
try { try {
mNwService.wifiFirmwareReload(mInterfaceName, "STA"); mNwService.wifiFirmwareReload(mInterfaceName, "STA");
} catch (Exception e) { } catch (Exception e) {
Log.e(TAG, "Failed to reload STA firmware " + e); loge("Failed to reload STA firmware " + e);
// continue // continue
} }
try { try {
@@ -1967,17 +1974,17 @@ public class WifiStateMachine extends StateMachine {
//Set privacy extensions //Set privacy extensions
mNwService.setInterfaceIpv6PrivacyExtensions(mInterfaceName, true); mNwService.setInterfaceIpv6PrivacyExtensions(mInterfaceName, true);
} catch (RemoteException re) { } catch (RemoteException re) {
if (DBG) Log.w(TAG, "Unable to change interface settings: " + re); loge("Unable to change interface settings: " + re);
} catch (IllegalStateException ie) { } catch (IllegalStateException ie) {
if (DBG) Log.w(TAG, "Unable to change interface settings: " + ie); loge("Unable to change interface settings: " + ie);
} }
if(WifiNative.startSupplicant()) { if(WifiNative.startSupplicant()) {
Log.d(TAG, "Supplicant start successful"); if (DBG) log("Supplicant start successful");
mWifiMonitor.startMonitoring(); mWifiMonitor.startMonitoring();
transitionTo(mSupplicantStartingState); transitionTo(mSupplicantStartingState);
} else { } else {
Log.e(TAG, "Failed to start supplicant!"); loge("Failed to start supplicant!");
sendMessage(obtainMessage(CMD_UNLOAD_DRIVER, WIFI_STATE_UNKNOWN, 0)); sendMessage(obtainMessage(CMD_UNLOAD_DRIVER, WIFI_STATE_UNKNOWN, 0));
} }
break; break;
@@ -1995,17 +2002,17 @@ public class WifiStateMachine extends StateMachine {
class DriverUnloadingState extends State { class DriverUnloadingState extends State {
@Override @Override
public void enter() { public void enter() {
if (DBG) Log.d(TAG, getName() + "\n"); if (DBG) log(getName() + "\n");
EventLog.writeEvent(EVENTLOG_WIFI_STATE_CHANGED, getName()); EventLog.writeEvent(EVENTLOG_WIFI_STATE_CHANGED, getName());
final Message message = new Message(); final Message message = new Message();
message.copyFrom(getCurrentMessage()); message.copyFrom(getCurrentMessage());
new Thread(new Runnable() { new Thread(new Runnable() {
public void run() { public void run() {
if (DBG) Log.d(TAG, getName() + message.toString() + "\n"); if (DBG) log(getName() + message.toString() + "\n");
mWakeLock.acquire(); mWakeLock.acquire();
if(WifiNative.unloadDriver()) { if(WifiNative.unloadDriver()) {
Log.d(TAG, "Driver unload successful"); if (DBG) log("Driver unload successful");
sendMessage(CMD_UNLOAD_DRIVER_SUCCESS); sendMessage(CMD_UNLOAD_DRIVER_SUCCESS);
switch(message.arg1) { switch(message.arg1) {
@@ -2019,7 +2026,7 @@ public class WifiStateMachine extends StateMachine {
break; break;
} }
} else { } else {
Log.e(TAG, "Failed to unload driver!"); loge("Failed to unload driver!");
sendMessage(CMD_UNLOAD_DRIVER_FAILURE); sendMessage(CMD_UNLOAD_DRIVER_FAILURE);
switch(message.arg1) { switch(message.arg1) {
@@ -2040,7 +2047,7 @@ public class WifiStateMachine extends StateMachine {
@Override @Override
public boolean processMessage(Message message) { public boolean processMessage(Message message) {
if (DBG) Log.d(TAG, getName() + message.toString() + "\n"); if (DBG) log(getName() + message.toString() + "\n");
switch (message.what) { switch (message.what) {
case CMD_UNLOAD_DRIVER_SUCCESS: case CMD_UNLOAD_DRIVER_SUCCESS:
transitionTo(mDriverUnloadedState); transitionTo(mDriverUnloadedState);
@@ -2076,12 +2083,12 @@ public class WifiStateMachine extends StateMachine {
class DriverUnloadedState extends State { class DriverUnloadedState extends State {
@Override @Override
public void enter() { public void enter() {
if (DBG) Log.d(TAG, getName() + "\n"); if (DBG) log(getName() + "\n");
EventLog.writeEvent(EVENTLOG_WIFI_STATE_CHANGED, getName()); EventLog.writeEvent(EVENTLOG_WIFI_STATE_CHANGED, getName());
} }
@Override @Override
public boolean processMessage(Message message) { public boolean processMessage(Message message) {
if (DBG) Log.d(TAG, getName() + message.toString() + "\n"); if (DBG) log(getName() + message.toString() + "\n");
switch (message.what) { switch (message.what) {
case CMD_LOAD_DRIVER: case CMD_LOAD_DRIVER:
mWifiP2pChannel.sendMessage(WIFI_ENABLE_PENDING); mWifiP2pChannel.sendMessage(WIFI_ENABLE_PENDING);
@@ -2101,12 +2108,12 @@ public class WifiStateMachine extends StateMachine {
class DriverFailedState extends State { class DriverFailedState extends State {
@Override @Override
public void enter() { public void enter() {
Log.e(TAG, getName() + "\n"); loge(getName() + "\n");
EventLog.writeEvent(EVENTLOG_WIFI_STATE_CHANGED, getName()); EventLog.writeEvent(EVENTLOG_WIFI_STATE_CHANGED, getName());
} }
@Override @Override
public boolean processMessage(Message message) { public boolean processMessage(Message message) {
if (DBG) Log.d(TAG, getName() + message.toString() + "\n"); if (DBG) log(getName() + message.toString() + "\n");
return NOT_HANDLED; return NOT_HANDLED;
} }
} }
@@ -2115,15 +2122,15 @@ public class WifiStateMachine extends StateMachine {
class SupplicantStartingState extends State { class SupplicantStartingState extends State {
@Override @Override
public void enter() { public void enter() {
if (DBG) Log.d(TAG, getName() + "\n"); if (DBG) log(getName() + "\n");
EventLog.writeEvent(EVENTLOG_WIFI_STATE_CHANGED, getName()); EventLog.writeEvent(EVENTLOG_WIFI_STATE_CHANGED, getName());
} }
@Override @Override
public boolean processMessage(Message message) { public boolean processMessage(Message message) {
if (DBG) Log.d(TAG, getName() + message.toString() + "\n"); if (DBG) log(getName() + message.toString() + "\n");
switch(message.what) { switch(message.what) {
case WifiMonitor.SUP_CONNECTION_EVENT: case WifiMonitor.SUP_CONNECTION_EVENT:
Log.d(TAG, "Supplicant connection established"); if (DBG) log("Supplicant connection established");
setWifiState(WIFI_STATE_ENABLED); setWifiState(WIFI_STATE_ENABLED);
mSupplicantRestartCount = 0; mSupplicantRestartCount = 0;
/* Reset the supplicant state to indicate the supplicant /* Reset the supplicant state to indicate the supplicant
@@ -2144,12 +2151,12 @@ public class WifiStateMachine extends StateMachine {
break; break;
case WifiMonitor.SUP_DISCONNECTION_EVENT: case WifiMonitor.SUP_DISCONNECTION_EVENT:
if (++mSupplicantRestartCount <= SUPPLICANT_RESTART_TRIES) { if (++mSupplicantRestartCount <= SUPPLICANT_RESTART_TRIES) {
Log.e(TAG, "Failed to setup control channel, restart supplicant"); loge("Failed to setup control channel, restart supplicant");
WifiNative.killSupplicant(); WifiNative.killSupplicant();
transitionTo(mDriverLoadedState); transitionTo(mDriverLoadedState);
sendMessageDelayed(CMD_START_SUPPLICANT, SUPPLICANT_RESTART_INTERVAL_MSECS); sendMessageDelayed(CMD_START_SUPPLICANT, SUPPLICANT_RESTART_INTERVAL_MSECS);
} else { } else {
Log.e(TAG, "Failed " + mSupplicantRestartCount + loge("Failed " + mSupplicantRestartCount +
" times to start supplicant, unload driver"); " times to start supplicant, unload driver");
mSupplicantRestartCount = 0; mSupplicantRestartCount = 0;
transitionTo(mDriverLoadedState); transitionTo(mDriverLoadedState);
@@ -2184,7 +2191,7 @@ public class WifiStateMachine extends StateMachine {
class SupplicantStartedState extends State { class SupplicantStartedState extends State {
@Override @Override
public void enter() { public void enter() {
if (DBG) Log.d(TAG, getName() + "\n"); if (DBG) log(getName() + "\n");
EventLog.writeEvent(EVENTLOG_WIFI_STATE_CHANGED, getName()); EventLog.writeEvent(EVENTLOG_WIFI_STATE_CHANGED, getName());
/* Initialize for connect mode operation at start */ /* Initialize for connect mode operation at start */
mIsScanMode = false; mIsScanMode = false;
@@ -2198,7 +2205,7 @@ public class WifiStateMachine extends StateMachine {
} }
@Override @Override
public boolean processMessage(Message message) { public boolean processMessage(Message message) {
if (DBG) Log.d(TAG, getName() + message.toString() + "\n"); if (DBG) log(getName() + message.toString() + "\n");
WifiConfiguration config; WifiConfiguration config;
boolean eventLoggingEnabled = true; boolean eventLoggingEnabled = true;
switch(message.what) { switch(message.what) {
@@ -2206,7 +2213,7 @@ public class WifiStateMachine extends StateMachine {
transitionTo(mSupplicantStoppingState); transitionTo(mSupplicantStoppingState);
break; break;
case WifiMonitor.SUP_DISCONNECTION_EVENT: /* Supplicant connection lost */ case WifiMonitor.SUP_DISCONNECTION_EVENT: /* Supplicant connection lost */
Log.e(TAG, "Connection lost, restart supplicant"); loge("Connection lost, restart supplicant");
WifiNative.killSupplicant(); WifiNative.killSupplicant();
WifiNative.closeSupplicantConnection(); WifiNative.closeSupplicantConnection();
mNetworkInfo.setIsAvailable(false); mNetworkInfo.setIsAvailable(false);
@@ -2270,7 +2277,7 @@ public class WifiStateMachine extends StateMachine {
break; break;
/* Cannot start soft AP while in client mode */ /* Cannot start soft AP while in client mode */
case CMD_START_AP: case CMD_START_AP:
Log.d(TAG, "Failed to start soft AP with a running supplicant"); loge("Failed to start soft AP with a running supplicant");
setWifiApState(WIFI_AP_STATE_FAILED); setWifiApState(WIFI_AP_STATE_FAILED);
break; break;
case CMD_SET_SCAN_MODE: case CMD_SET_SCAN_MODE:
@@ -2301,11 +2308,11 @@ public class WifiStateMachine extends StateMachine {
class SupplicantStoppingState extends State { class SupplicantStoppingState extends State {
@Override @Override
public void enter() { public void enter() {
if (DBG) Log.d(TAG, getName() + "\n"); if (DBG) log(getName() + "\n");
EventLog.writeEvent(EVENTLOG_WIFI_STATE_CHANGED, getName()); EventLog.writeEvent(EVENTLOG_WIFI_STATE_CHANGED, getName());
Log.d(TAG, "stopping supplicant"); if (DBG) log("stopping supplicant");
if (!WifiNative.stopSupplicant()) { if (!WifiNative.stopSupplicant()) {
Log.e(TAG, "Failed to stop supplicant"); loge("Failed to stop supplicant");
} }
/* Send ourselves a delayed message to indicate failure after a wait time */ /* Send ourselves a delayed message to indicate failure after a wait time */
@@ -2321,13 +2328,13 @@ public class WifiStateMachine extends StateMachine {
} }
@Override @Override
public boolean processMessage(Message message) { public boolean processMessage(Message message) {
if (DBG) Log.d(TAG, getName() + message.toString() + "\n"); if (DBG) log(getName() + message.toString() + "\n");
switch(message.what) { switch(message.what) {
case WifiMonitor.SUP_CONNECTION_EVENT: case WifiMonitor.SUP_CONNECTION_EVENT:
Log.e(TAG, "Supplicant connection received while stopping"); loge("Supplicant connection received while stopping");
break; break;
case WifiMonitor.SUP_DISCONNECTION_EVENT: case WifiMonitor.SUP_DISCONNECTION_EVENT:
Log.d(TAG, "Supplicant connection lost"); if (DBG) log("Supplicant connection lost");
/* Socket connection can be lost when we do a graceful shutdown /* Socket connection can be lost when we do a graceful shutdown
* or when the driver is hung. Ensure supplicant is stopped here. * or when the driver is hung. Ensure supplicant is stopped here.
*/ */
@@ -2337,7 +2344,7 @@ public class WifiStateMachine extends StateMachine {
break; break;
case CMD_STOP_SUPPLICANT_FAILED: case CMD_STOP_SUPPLICANT_FAILED:
if (message.arg1 == mSupplicantStopFailureToken) { if (message.arg1 == mSupplicantStopFailureToken) {
Log.e(TAG, "Timed out on a supplicant stop, kill and proceed"); loge("Timed out on a supplicant stop, kill and proceed");
WifiNative.killSupplicant(); WifiNative.killSupplicant();
WifiNative.closeSupplicantConnection(); WifiNative.closeSupplicantConnection();
transitionTo(mDriverLoadedState); transitionTo(mDriverLoadedState);
@@ -2371,12 +2378,12 @@ public class WifiStateMachine extends StateMachine {
class DriverStartingState extends State { class DriverStartingState extends State {
@Override @Override
public void enter() { public void enter() {
if (DBG) Log.d(TAG, getName() + "\n"); if (DBG) log(getName() + "\n");
EventLog.writeEvent(EVENTLOG_WIFI_STATE_CHANGED, getName()); EventLog.writeEvent(EVENTLOG_WIFI_STATE_CHANGED, getName());
} }
@Override @Override
public boolean processMessage(Message message) { public boolean processMessage(Message message) {
if (DBG) Log.d(TAG, getName() + message.toString() + "\n"); if (DBG) log(getName() + message.toString() + "\n");
switch(message.what) { switch(message.what) {
case WifiMonitor.SUPPLICANT_STATE_CHANGE_EVENT: case WifiMonitor.SUPPLICANT_STATE_CHANGE_EVENT:
SupplicantState state = handleSupplicantStateChange(message); SupplicantState state = handleSupplicantStateChange(message);
@@ -2418,7 +2425,7 @@ public class WifiStateMachine extends StateMachine {
class DriverStartedState extends State { class DriverStartedState extends State {
@Override @Override
public void enter() { public void enter() {
if (DBG) Log.d(TAG, getName() + "\n"); if (DBG) log(getName() + "\n");
EventLog.writeEvent(EVENTLOG_WIFI_STATE_CHANGED, getName()); EventLog.writeEvent(EVENTLOG_WIFI_STATE_CHANGED, getName());
mIsRunning = true; mIsRunning = true;
@@ -2459,7 +2466,7 @@ public class WifiStateMachine extends StateMachine {
} }
@Override @Override
public boolean processMessage(Message message) { public boolean processMessage(Message message) {
if (DBG) Log.d(TAG, getName() + message.toString() + "\n"); if (DBG) log(getName() + message.toString() + "\n");
boolean eventLoggingEnabled = true; boolean eventLoggingEnabled = true;
switch(message.what) { switch(message.what) {
case CMD_SET_SCAN_TYPE: case CMD_SET_SCAN_TYPE:
@@ -2479,20 +2486,20 @@ public class WifiStateMachine extends StateMachine {
break; break;
case CMD_SET_COUNTRY_CODE: case CMD_SET_COUNTRY_CODE:
String country = (String) message.obj; String country = (String) message.obj;
Log.d(TAG, "set country code " + country); if (DBG) log("set country code " + country);
if (!WifiNative.setCountryCodeCommand(country.toUpperCase())) { if (!WifiNative.setCountryCodeCommand(country.toUpperCase())) {
Log.e(TAG, "Failed to set country code " + country); loge("Failed to set country code " + country);
} }
break; break;
case CMD_SET_FREQUENCY_BAND: case CMD_SET_FREQUENCY_BAND:
int band = message.arg1; int band = message.arg1;
Log.d(TAG, "set frequency band " + band); if (DBG) log("set frequency band " + band);
if (WifiNative.setBandCommand(band)) { if (WifiNative.setBandCommand(band)) {
mFrequencyBand.set(band); mFrequencyBand.set(band);
//Fetch the latest scan results when frequency band is set //Fetch the latest scan results when frequency band is set
startScan(true); startScan(true);
} else { } else {
Log.e(TAG, "Failed to set frequency band " + band); loge("Failed to set frequency band " + band);
} }
break; break;
case CMD_BLUETOOTH_ADAPTER_STATE_CHANGE: case CMD_BLUETOOTH_ADAPTER_STATE_CHANGE:
@@ -2512,7 +2519,7 @@ public class WifiStateMachine extends StateMachine {
} else if (message.arg1 == MULTICAST_V4) { } else if (message.arg1 == MULTICAST_V4) {
WifiNative.startFilteringMulticastV4Packets(); WifiNative.startFilteringMulticastV4Packets();
} else { } else {
Log.e(TAG, "Illegal arugments to CMD_START_PACKET_FILTERING"); loge("Illegal arugments to CMD_START_PACKET_FILTERING");
} }
break; break;
case CMD_STOP_PACKET_FILTERING: case CMD_STOP_PACKET_FILTERING:
@@ -2521,7 +2528,7 @@ public class WifiStateMachine extends StateMachine {
} else if (message.arg1 == MULTICAST_V4) { } else if (message.arg1 == MULTICAST_V4) {
WifiNative.stopFilteringMulticastV4Packets(); WifiNative.stopFilteringMulticastV4Packets();
} else { } else {
Log.e(TAG, "Illegal arugments to CMD_STOP_PACKET_FILTERING"); loge("Illegal arugments to CMD_STOP_PACKET_FILTERING");
} }
break; break;
default: default:
@@ -2534,7 +2541,7 @@ public class WifiStateMachine extends StateMachine {
} }
@Override @Override
public void exit() { public void exit() {
if (DBG) Log.d(TAG, getName() + "\n"); if (DBG) log(getName() + "\n");
mIsRunning = false; mIsRunning = false;
updateBatteryWorkSource(null); updateBatteryWorkSource(null);
mScanResults = null; mScanResults = null;
@@ -2544,12 +2551,12 @@ public class WifiStateMachine extends StateMachine {
class DriverStoppingState extends State { class DriverStoppingState extends State {
@Override @Override
public void enter() { public void enter() {
if (DBG) Log.d(TAG, getName() + "\n"); if (DBG) log(getName() + "\n");
EventLog.writeEvent(EVENTLOG_WIFI_STATE_CHANGED, getName()); EventLog.writeEvent(EVENTLOG_WIFI_STATE_CHANGED, getName());
} }
@Override @Override
public boolean processMessage(Message message) { public boolean processMessage(Message message) {
if (DBG) Log.d(TAG, getName() + message.toString() + "\n"); if (DBG) log(getName() + message.toString() + "\n");
switch(message.what) { switch(message.what) {
case WifiMonitor.SUPPLICANT_STATE_CHANGE_EVENT: case WifiMonitor.SUPPLICANT_STATE_CHANGE_EVENT:
SupplicantState state = handleSupplicantStateChange(message); SupplicantState state = handleSupplicantStateChange(message);
@@ -2583,12 +2590,12 @@ public class WifiStateMachine extends StateMachine {
class DriverStoppedState extends State { class DriverStoppedState extends State {
@Override @Override
public void enter() { public void enter() {
if (DBG) Log.d(TAG, getName() + "\n"); if (DBG) log(getName() + "\n");
EventLog.writeEvent(EVENTLOG_WIFI_STATE_CHANGED, getName()); EventLog.writeEvent(EVENTLOG_WIFI_STATE_CHANGED, getName());
} }
@Override @Override
public boolean processMessage(Message message) { public boolean processMessage(Message message) {
if (DBG) Log.d(TAG, getName() + message.toString() + "\n"); if (DBG) log(getName() + message.toString() + "\n");
switch (message.what) { switch (message.what) {
case CMD_START_DRIVER: case CMD_START_DRIVER:
mWakeLock.acquire(); mWakeLock.acquire();
@@ -2607,12 +2614,12 @@ public class WifiStateMachine extends StateMachine {
class ScanModeState extends State { class ScanModeState extends State {
@Override @Override
public void enter() { public void enter() {
if (DBG) Log.d(TAG, getName() + "\n"); if (DBG) log(getName() + "\n");
EventLog.writeEvent(EVENTLOG_WIFI_STATE_CHANGED, getName()); EventLog.writeEvent(EVENTLOG_WIFI_STATE_CHANGED, getName());
} }
@Override @Override
public boolean processMessage(Message message) { public boolean processMessage(Message message) {
if (DBG) Log.d(TAG, getName() + message.toString() + "\n"); if (DBG) log(getName() + message.toString() + "\n");
switch(message.what) { switch(message.what) {
case CMD_SET_SCAN_MODE: case CMD_SET_SCAN_MODE:
if (message.arg1 == SCAN_ONLY_MODE) { if (message.arg1 == SCAN_ONLY_MODE) {
@@ -2644,12 +2651,12 @@ public class WifiStateMachine extends StateMachine {
class ConnectModeState extends State { class ConnectModeState extends State {
@Override @Override
public void enter() { public void enter() {
if (DBG) Log.d(TAG, getName() + "\n"); if (DBG) log(getName() + "\n");
EventLog.writeEvent(EVENTLOG_WIFI_STATE_CHANGED, getName()); EventLog.writeEvent(EVENTLOG_WIFI_STATE_CHANGED, getName());
} }
@Override @Override
public boolean processMessage(Message message) { public boolean processMessage(Message message) {
if (DBG) Log.d(TAG, getName() + message.toString() + "\n"); if (DBG) log(getName() + message.toString() + "\n");
StateChangeResult stateChangeResult; StateChangeResult stateChangeResult;
switch(message.what) { switch(message.what) {
case WifiMonitor.AUTHENTICATION_FAILURE_EVENT: case WifiMonitor.AUTHENTICATION_FAILURE_EVENT:
@@ -2696,7 +2703,7 @@ public class WifiStateMachine extends StateMachine {
mLastExplicitNetworkId = netId; mLastExplicitNetworkId = netId;
mLastNetworkChoiceTime = SystemClock.elapsedRealtime(); mLastNetworkChoiceTime = SystemClock.elapsedRealtime();
mNextWifiActionExplicit = true; mNextWifiActionExplicit = true;
Slog.d(TAG, "Setting wifi connect explicit for netid " + netId); if (DBG) log("Setting wifi connect explicit for netid " + netId);
/* Expect a disconnection from the old connection */ /* Expect a disconnection from the old connection */
transitionTo(mDisconnectingState); transitionTo(mDisconnectingState);
break; break;
@@ -2710,7 +2717,7 @@ public class WifiStateMachine extends StateMachine {
/* Handle scan results */ /* Handle scan results */
return NOT_HANDLED; return NOT_HANDLED;
case WifiMonitor.NETWORK_CONNECTION_EVENT: case WifiMonitor.NETWORK_CONNECTION_EVENT:
Log.d(TAG,"Network connection established"); if (DBG) log("Network connection established");
mLastNetworkId = message.arg1; mLastNetworkId = message.arg1;
mLastBssid = (String) message.obj; mLastBssid = (String) message.obj;
@@ -2731,7 +2738,7 @@ public class WifiStateMachine extends StateMachine {
transitionTo(mConnectingState); transitionTo(mConnectingState);
break; break;
case WifiMonitor.NETWORK_DISCONNECTION_EVENT: case WifiMonitor.NETWORK_DISCONNECTION_EVENT:
Log.d(TAG,"Network connection lost"); if (DBG) log("Network connection lost");
handleNetworkDisconnect(); handleNetworkDisconnect();
transitionTo(mDisconnectedState); transitionTo(mDisconnectedState);
break; break;
@@ -2747,15 +2754,15 @@ public class WifiStateMachine extends StateMachine {
@Override @Override
public void enter() { public void enter() {
if (DBG) Log.d(TAG, getName() + "\n"); if (DBG) log(getName() + "\n");
EventLog.writeEvent(EVENTLOG_WIFI_STATE_CHANGED, getName()); EventLog.writeEvent(EVENTLOG_WIFI_STATE_CHANGED, getName());
try { try {
mNwService.enableIpv6(mInterfaceName); mNwService.enableIpv6(mInterfaceName);
} catch (RemoteException re) { } catch (RemoteException re) {
Log.e(TAG, "Failed to enable IPv6: " + re); loge("Failed to enable IPv6: " + re);
} catch (IllegalStateException e) { } catch (IllegalStateException e) {
Log.e(TAG, "Failed to enable IPv6: " + e); loge("Failed to enable IPv6: " + e);
} }
if (!WifiConfigStore.isUsingStaticIp(mLastNetworkId)) { if (!WifiConfigStore.isUsingStaticIp(mLastNetworkId)) {
@@ -2772,20 +2779,20 @@ public class WifiStateMachine extends StateMachine {
ifcg.interfaceFlags = "[up]"; ifcg.interfaceFlags = "[up]";
try { try {
mNwService.setInterfaceConfig(mInterfaceName, ifcg); mNwService.setInterfaceConfig(mInterfaceName, ifcg);
Log.v(TAG, "Static IP configuration succeeded"); if (DBG) log("Static IP configuration succeeded");
sendMessage(CMD_STATIC_IP_SUCCESS, dhcpInfoInternal); sendMessage(CMD_STATIC_IP_SUCCESS, dhcpInfoInternal);
} catch (RemoteException re) { } catch (RemoteException re) {
Log.v(TAG, "Static IP configuration failed: " + re); loge("Static IP configuration failed: " + re);
sendMessage(CMD_STATIC_IP_FAILURE); sendMessage(CMD_STATIC_IP_FAILURE);
} catch (IllegalStateException e) { } catch (IllegalStateException e) {
Log.v(TAG, "Static IP configuration failed: " + e); loge("Static IP configuration failed: " + e);
sendMessage(CMD_STATIC_IP_FAILURE); sendMessage(CMD_STATIC_IP_FAILURE);
} }
} }
} }
@Override @Override
public boolean processMessage(Message message) { public boolean processMessage(Message message) {
if (DBG) Log.d(TAG, getName() + message.toString() + "\n"); if (DBG) log(getName() + message.toString() + "\n");
switch(message.what) { switch(message.what) {
case DhcpStateMachine.CMD_PRE_DHCP_ACTION: case DhcpStateMachine.CMD_PRE_DHCP_ACTION:
@@ -2856,7 +2863,7 @@ public class WifiStateMachine extends StateMachine {
class ConnectedState extends State { class ConnectedState extends State {
@Override @Override
public void enter() { public void enter() {
if (DBG) Log.d(TAG, getName() + "\n"); if (DBG) log(getName() + "\n");
EventLog.writeEvent(EVENTLOG_WIFI_STATE_CHANGED, getName()); EventLog.writeEvent(EVENTLOG_WIFI_STATE_CHANGED, getName());
mRssiPollToken++; mRssiPollToken++;
if (mEnableRssiPolling) { if (mEnableRssiPolling) {
@@ -2865,7 +2872,7 @@ public class WifiStateMachine extends StateMachine {
} }
@Override @Override
public boolean processMessage(Message message) { public boolean processMessage(Message message) {
if (DBG) Log.d(TAG, getName() + message.toString() + "\n"); if (DBG) log(getName() + message.toString() + "\n");
boolean eventLoggingEnabled = true; boolean eventLoggingEnabled = true;
switch (message.what) { switch (message.what) {
case DhcpStateMachine.CMD_PRE_DHCP_ACTION: case DhcpStateMachine.CMD_PRE_DHCP_ACTION:
@@ -2921,11 +2928,11 @@ public class WifiStateMachine extends StateMachine {
NetworkUpdateResult result = WifiConfigStore.saveNetwork(config); NetworkUpdateResult result = WifiConfigStore.saveNetwork(config);
if (mWifiInfo.getNetworkId() == result.getNetworkId()) { if (mWifiInfo.getNetworkId() == result.getNetworkId()) {
if (result.hasIpChanged()) { if (result.hasIpChanged()) {
Log.d(TAG,"Reconfiguring IP on connection"); log("Reconfiguring IP on connection");
transitionTo(mConnectingState); transitionTo(mConnectingState);
} }
if (result.hasProxyChanged()) { if (result.hasProxyChanged()) {
Log.d(TAG,"Reconfiguring proxy on connection"); log("Reconfiguring proxy on connection");
configureLinkProperties(); configureLinkProperties();
sendLinkConfigurationChangedBroadcast(); sendLinkConfigurationChangedBroadcast();
} }
@@ -2977,12 +2984,12 @@ public class WifiStateMachine extends StateMachine {
class DisconnectingState extends State { class DisconnectingState extends State {
@Override @Override
public void enter() { public void enter() {
if (DBG) Log.d(TAG, getName() + "\n"); if (DBG) log(getName() + "\n");
EventLog.writeEvent(EVENTLOG_WIFI_STATE_CHANGED, getName()); EventLog.writeEvent(EVENTLOG_WIFI_STATE_CHANGED, getName());
} }
@Override @Override
public boolean processMessage(Message message) { public boolean processMessage(Message message) {
if (DBG) Log.d(TAG, getName() + message.toString() + "\n"); if (DBG) log(getName() + message.toString() + "\n");
switch (message.what) { switch (message.what) {
case CMD_STOP_DRIVER: /* Stop driver only after disconnect handled */ case CMD_STOP_DRIVER: /* Stop driver only after disconnect handled */
deferMessage(message); deferMessage(message);
@@ -3029,7 +3036,7 @@ public class WifiStateMachine extends StateMachine {
@Override @Override
public void enter() { public void enter() {
if (DBG) Log.d(TAG, getName() + "\n"); if (DBG) log(getName() + "\n");
EventLog.writeEvent(EVENTLOG_WIFI_STATE_CHANGED, getName()); EventLog.writeEvent(EVENTLOG_WIFI_STATE_CHANGED, getName());
mFrameworkScanIntervalMs = Settings.Secure.getLong(mContext.getContentResolver(), mFrameworkScanIntervalMs = Settings.Secure.getLong(mContext.getContentResolver(),
@@ -3056,7 +3063,7 @@ public class WifiStateMachine extends StateMachine {
} }
@Override @Override
public boolean processMessage(Message message) { public boolean processMessage(Message message) {
if (DBG) Log.d(TAG, getName() + message.toString() + "\n"); if (DBG) log(getName() + message.toString() + "\n");
switch (message.what) { switch (message.what) {
case CMD_SET_SCAN_MODE: case CMD_SET_SCAN_MODE:
if (message.arg1 == SCAN_ONLY_MODE) { if (message.arg1 == SCAN_ONLY_MODE) {
@@ -3119,12 +3126,12 @@ public class WifiStateMachine extends StateMachine {
class WaitForWpsCompletionState extends State { class WaitForWpsCompletionState extends State {
@Override @Override
public void enter() { public void enter() {
if (DBG) Log.d(TAG, getName() + "\n"); if (DBG) log(getName() + "\n");
EventLog.writeEvent(EVENTLOG_WIFI_STATE_CHANGED, getName()); EventLog.writeEvent(EVENTLOG_WIFI_STATE_CHANGED, getName());
} }
@Override @Override
public boolean processMessage(Message message) { public boolean processMessage(Message message) {
if (DBG) Log.d(TAG, getName() + message.toString() + "\n"); if (DBG) log(getName() + message.toString() + "\n");
switch (message.what) { switch (message.what) {
/* Defer all commands that can cause connections to a different network /* Defer all commands that can cause connections to a different network
* or put the state machine out of connect mode * or put the state machine out of connect mode
@@ -3139,7 +3146,7 @@ public class WifiStateMachine extends StateMachine {
deferMessage(message); deferMessage(message);
break; break;
case WifiMonitor.NETWORK_DISCONNECTION_EVENT: case WifiMonitor.NETWORK_DISCONNECTION_EVENT:
Log.d(TAG,"Network connection lost"); if (DBG) log("Network connection lost");
handleNetworkDisconnect(); handleNetworkDisconnect();
break; break;
case WPS_COMPLETED_EVENT: case WPS_COMPLETED_EVENT:
@@ -3158,7 +3165,7 @@ public class WifiStateMachine extends StateMachine {
class SoftApStartingState extends State { class SoftApStartingState extends State {
@Override @Override
public void enter() { public void enter() {
if (DBG) Log.d(TAG, getName() + "\n"); if (DBG) log(getName() + "\n");
EventLog.writeEvent(EVENTLOG_WIFI_STATE_CHANGED, getName()); EventLog.writeEvent(EVENTLOG_WIFI_STATE_CHANGED, getName());
final Message message = Message.obtain(getCurrentMessage()); final Message message = Message.obtain(getCurrentMessage());
@@ -3168,10 +3175,10 @@ public class WifiStateMachine extends StateMachine {
new Thread(new Runnable() { new Thread(new Runnable() {
public void run() { public void run() {
if (startSoftApWithConfig(config)) { if (startSoftApWithConfig(config)) {
Log.d(TAG, "Soft AP start successful"); if (DBG) log("Soft AP start successful");
sendMessage(CMD_START_AP_SUCCESS); sendMessage(CMD_START_AP_SUCCESS);
} else { } else {
Log.d(TAG, "Soft AP start failed"); loge("Soft AP start failed");
sendMessage(CMD_START_AP_FAILURE); sendMessage(CMD_START_AP_FAILURE);
} }
} }
@@ -3179,7 +3186,7 @@ public class WifiStateMachine extends StateMachine {
} }
@Override @Override
public boolean processMessage(Message message) { public boolean processMessage(Message message) {
if (DBG) Log.d(TAG, getName() + message.toString() + "\n"); if (DBG) log(getName() + message.toString() + "\n");
switch(message.what) { switch(message.what) {
case CMD_LOAD_DRIVER: case CMD_LOAD_DRIVER:
case CMD_UNLOAD_DRIVER: case CMD_UNLOAD_DRIVER:
@@ -3219,21 +3226,21 @@ public class WifiStateMachine extends StateMachine {
class SoftApStartedState extends State { class SoftApStartedState extends State {
@Override @Override
public void enter() { public void enter() {
if (DBG) Log.d(TAG, getName() + "\n"); if (DBG) log(getName() + "\n");
EventLog.writeEvent(EVENTLOG_WIFI_STATE_CHANGED, getName()); EventLog.writeEvent(EVENTLOG_WIFI_STATE_CHANGED, getName());
} }
@Override @Override
public boolean processMessage(Message message) { public boolean processMessage(Message message) {
if (DBG) Log.d(TAG, getName() + message.toString() + "\n"); if (DBG) log(getName() + message.toString() + "\n");
switch(message.what) { switch(message.what) {
case CMD_STOP_AP: case CMD_STOP_AP:
Log.d(TAG,"Stopping Soft AP"); if (DBG) log("Stopping Soft AP");
setWifiApState(WIFI_AP_STATE_DISABLING); setWifiApState(WIFI_AP_STATE_DISABLING);
stopTethering(); stopTethering();
try { try {
mNwService.stopAccessPoint(mInterfaceName); mNwService.stopAccessPoint(mInterfaceName);
} catch(Exception e) { } catch(Exception e) {
Log.e(TAG, "Exception in stopAccessPoint()"); loge("Exception in stopAccessPoint()");
} }
transitionTo(mDriverLoadedState); transitionTo(mDriverLoadedState);
break; break;
@@ -3242,7 +3249,7 @@ public class WifiStateMachine extends StateMachine {
break; break;
/* Fail client mode operation when soft AP is enabled */ /* Fail client mode operation when soft AP is enabled */
case CMD_START_SUPPLICANT: case CMD_START_SUPPLICANT:
Log.e(TAG,"Cannot start supplicant with a running soft AP"); loge("Cannot start supplicant with a running soft AP");
setWifiState(WIFI_STATE_UNKNOWN); setWifiState(WIFI_STATE_UNKNOWN);
break; break;
case CMD_TETHER_INTERFACE: case CMD_TETHER_INTERFACE:
@@ -3268,7 +3275,7 @@ public class WifiStateMachine extends StateMachine {
private int mSavedArg; private int mSavedArg;
@Override @Override
public void enter() { public void enter() {
if (DBG) Log.d(TAG, getName() + "\n"); if (DBG) log(getName() + "\n");
EventLog.writeEvent(EVENTLOG_WIFI_STATE_CHANGED, getName()); EventLog.writeEvent(EVENTLOG_WIFI_STATE_CHANGED, getName());
//Preserve the argument arg1 that has information used in DriverLoadingState //Preserve the argument arg1 that has information used in DriverLoadingState
@@ -3276,7 +3283,7 @@ public class WifiStateMachine extends StateMachine {
} }
@Override @Override
public boolean processMessage(Message message) { public boolean processMessage(Message message) {
if (DBG) Log.d(TAG, getName() + message.toString() + "\n"); if (DBG) log(getName() + message.toString() + "\n");
switch(message.what) { switch(message.what) {
case WifiP2pService.WIFI_ENABLE_PROCEED: case WifiP2pService.WIFI_ENABLE_PROCEED:
//restore argument from original message (CMD_LOAD_DRIVER) //restore argument from original message (CMD_LOAD_DRIVER)
@@ -3311,12 +3318,12 @@ public class WifiStateMachine extends StateMachine {
class TetheredState extends State { class TetheredState extends State {
@Override @Override
public void enter() { public void enter() {
if (DBG) Log.d(TAG, getName() + "\n"); if (DBG) log(getName() + "\n");
EventLog.writeEvent(EVENTLOG_WIFI_STATE_CHANGED, getName()); EventLog.writeEvent(EVENTLOG_WIFI_STATE_CHANGED, getName());
} }
@Override @Override
public boolean processMessage(Message message) { public boolean processMessage(Message message) {
if (DBG) Log.d(TAG, getName() + message.toString() + "\n"); if (DBG) log(getName() + message.toString() + "\n");
switch(message.what) { switch(message.what) {
case CMD_TETHER_INTERFACE: case CMD_TETHER_INTERFACE:
// Ignore any duplicate interface available notifications // Ignore any duplicate interface available notifications
@@ -3327,4 +3334,12 @@ public class WifiStateMachine extends StateMachine {
} }
} }
} }
private void log(String s) {
Log.d(TAG, s);
}
private void loge(String s) {
Log.e(TAG, s);
}
} }

View File

@@ -35,7 +35,6 @@ import android.os.SystemClock;
import android.os.SystemProperties; import android.os.SystemProperties;
import android.provider.Settings; import android.provider.Settings;
import android.provider.Settings.Secure; import android.provider.Settings.Secure;
import android.util.Slog;
import android.util.Log; import android.util.Log;
import com.android.internal.util.Protocol; import com.android.internal.util.Protocol;
@@ -67,10 +66,8 @@ import java.util.List;
*/ */
public class WifiWatchdogStateMachine extends StateMachine { public class WifiWatchdogStateMachine extends StateMachine {
private static final boolean DBG = false;
private static final boolean VDBG = false; private static final String TAG = "WifiWatchdogStateMachine";
private static final boolean DBG = true;
private static final String WWSM_TAG = "WifiWatchdogStateMachine";
private static final String WATCHDOG_NOTIFICATION_ID = "Android.System.WifiWatchdog"; private static final String WATCHDOG_NOTIFICATION_ID = "Android.System.WifiWatchdog";
private static final int WIFI_SIGNAL_LEVELS = 4; private static final int WIFI_SIGNAL_LEVELS = 4;
@@ -192,7 +189,7 @@ public class WifiWatchdogStateMachine extends StateMachine {
* (all other states) * (all other states)
*/ */
private WifiWatchdogStateMachine(Context context) { private WifiWatchdogStateMachine(Context context) {
super(WWSM_TAG); super(TAG);
mContext = context; mContext = context;
mContentResolver = context.getContentResolver(); mContentResolver = context.getContentResolver();
mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
@@ -351,7 +348,7 @@ public class WifiWatchdogStateMachine extends StateMachine {
return urlConnection.getResponseCode() != 204; return urlConnection.getResponseCode() != 204;
} catch (IOException e) { } catch (IOException e) {
if (DBG) { if (DBG) {
Slog.d(WWSM_TAG, "Walled garden check - probably not a portal: exception ", e); log("Walled garden check - probably not a portal: exception " + e);
} }
return false; return false;
} finally { } finally {
@@ -443,7 +440,7 @@ public class WifiWatchdogStateMachine extends StateMachine {
if (results == null) { if (results == null) {
if (DBG) { if (DBG) {
Slog.d(WWSM_TAG, "updateBssids: Got null scan results!"); log("updateBssids: Got null scan results!");
} }
return; return;
} }
@@ -451,7 +448,7 @@ public class WifiWatchdogStateMachine extends StateMachine {
for (ScanResult result : results) { for (ScanResult result : results) {
if (result == null || result.SSID == null) { if (result == null || result.SSID == null) {
if (DBG) { if (DBG) {
Slog.d(WWSM_TAG, "Received invalid scan result: " + result); log("Received invalid scan result: " + result);
} }
continue; continue;
} }
@@ -461,8 +458,8 @@ public class WifiWatchdogStateMachine extends StateMachine {
} }
private void resetWatchdogState() { private void resetWatchdogState() {
if (VDBG) { if (DBG) {
Slog.v(WWSM_TAG, "Resetting watchdog state..."); log("Resetting watchdog state...");
} }
mConnectionInfo = null; mConnectionInfo = null;
mDisableAPNextFailure = false; mDisableAPNextFailure = false;
@@ -522,13 +519,13 @@ public class WifiWatchdogStateMachine extends StateMachine {
switch (msg.what) { switch (msg.what) {
case EVENT_WATCHDOG_SETTINGS_CHANGE: case EVENT_WATCHDOG_SETTINGS_CHANGE:
updateSettings(); updateSettings();
if (VDBG) { if (DBG) {
Slog.d(WWSM_TAG, "Updating wifi-watchdog secure settings"); log("Updating wifi-watchdog secure settings");
} }
return HANDLED; return HANDLED;
} }
if (VDBG) { if (DBG) {
Slog.v(WWSM_TAG, "Caught message " + msg.what + " in state " + log("Caught message " + msg.what + " in state " +
getCurrentState().getName()); getCurrentState().getName());
} }
return HANDLED; return HANDLED;
@@ -553,7 +550,7 @@ public class WifiWatchdogStateMachine extends StateMachine {
public void enter() { public void enter() {
resetWatchdogState(); resetWatchdogState();
mContext.registerReceiver(mBroadcastReceiver, mIntentFilter); mContext.registerReceiver(mBroadcastReceiver, mIntentFilter);
Slog.i(WWSM_TAG, "WifiWatchdogService enabled"); if (DBG) log("WifiWatchdogService enabled");
} }
@Override @Override
@@ -574,12 +571,12 @@ public class WifiWatchdogStateMachine extends StateMachine {
WifiInfo wifiInfo = (WifiInfo) WifiInfo wifiInfo = (WifiInfo)
stateChangeIntent.getParcelableExtra(WifiManager.EXTRA_WIFI_INFO); stateChangeIntent.getParcelableExtra(WifiManager.EXTRA_WIFI_INFO);
if (wifiInfo == null) { if (wifiInfo == null) {
Slog.e(WWSM_TAG, "Connected --> WifiInfo object null!"); loge("Connected --> WifiInfo object null!");
return HANDLED; return HANDLED;
} }
if (wifiInfo.getSSID() == null || wifiInfo.getBSSID() == null) { if (wifiInfo.getSSID() == null || wifiInfo.getBSSID() == null) {
Slog.e(WWSM_TAG, "Received wifiInfo object with null elts: " loge("Received wifiInfo object with null elts: "
+ wifiInfoToStr(wifiInfo)); + wifiInfoToStr(wifiInfo));
return HANDLED; return HANDLED;
} }
@@ -598,7 +595,7 @@ public class WifiWatchdogStateMachine extends StateMachine {
return HANDLED; return HANDLED;
case EVENT_WIFI_RADIO_STATE_CHANGE: case EVENT_WIFI_RADIO_STATE_CHANGE:
if ((Integer) msg.obj == WifiManager.WIFI_STATE_DISABLING) { if ((Integer) msg.obj == WifiManager.WIFI_STATE_DISABLING) {
Slog.i(WWSM_TAG, "WifiStateDisabling -- Resetting WatchdogState"); if (DBG) log("WifiStateDisabling -- Resetting WatchdogState");
resetWatchdogState(); resetWatchdogState();
mNetEventCounter++; mNetEventCounter++;
transitionTo(mNotConnectedState); transitionTo(mNotConnectedState);
@@ -613,8 +610,8 @@ public class WifiWatchdogStateMachine extends StateMachine {
* @param wifiInfo Info object with non-null ssid and bssid * @param wifiInfo Info object with non-null ssid and bssid
*/ */
private void initConnection(WifiInfo wifiInfo) { private void initConnection(WifiInfo wifiInfo) {
if (VDBG) { if (DBG) {
Slog.v(WWSM_TAG, "Connected:: old " + wifiInfoToStr(mConnectionInfo) + log("Connected:: old " + wifiInfoToStr(mConnectionInfo) +
" ==> new " + wifiInfoToStr(wifiInfo)); " ==> new " + wifiInfoToStr(wifiInfo));
} }
@@ -628,7 +625,7 @@ public class WifiWatchdogStateMachine extends StateMachine {
@Override @Override
public void exit() { public void exit() {
mContext.unregisterReceiver(mBroadcastReceiver); mContext.unregisterReceiver(mBroadcastReceiver);
Slog.i(WWSM_TAG, "WifiWatchdogService disabled"); if (DBG) log("WifiWatchdogService disabled");
} }
} }
@@ -671,7 +668,7 @@ public class WifiWatchdogStateMachine extends StateMachine {
if (DBG) { if (DBG) {
dnsCheckLogStr = String.format("Pinging %s on ssid [%s]: ", dnsCheckLogStr = String.format("Pinging %s on ssid [%s]: ",
mDnsList, mConnectionInfo.getSSID()); mDnsList, mConnectionInfo.getSSID());
Slog.d(WWSM_TAG, dnsCheckLogStr); log(dnsCheckLogStr);
} }
idDnsMap.clear(); idDnsMap.clear();
@@ -694,7 +691,7 @@ public class WifiWatchdogStateMachine extends StateMachine {
Integer dnsServerId = idDnsMap.get(pingID); Integer dnsServerId = idDnsMap.get(pingID);
if (dnsServerId == null) { if (dnsServerId == null) {
Slog.w(WWSM_TAG, "Received a Dns response with unknown ID!"); loge("Received a Dns response with unknown ID!");
return HANDLED; return HANDLED;
} }
@@ -722,7 +719,7 @@ public class WifiWatchdogStateMachine extends StateMachine {
if (dnsCheckSuccesses[dnsServerId] >= mMinDnsResponses) { if (dnsCheckSuccesses[dnsServerId] >= mMinDnsResponses) {
// DNS CHECKS OK, NOW WALLED GARDEN // DNS CHECKS OK, NOW WALLED GARDEN
if (DBG) { if (DBG) {
Slog.d(WWSM_TAG, makeLogString() + " SUCCESS"); log(makeLogString() + " SUCCESS");
} }
if (!shouldCheckWalledGarden()) { if (!shouldCheckWalledGarden()) {
@@ -732,13 +729,10 @@ public class WifiWatchdogStateMachine extends StateMachine {
mLastWalledGardenCheckTime = SystemClock.elapsedRealtime(); mLastWalledGardenCheckTime = SystemClock.elapsedRealtime();
if (isWalledGardenConnection()) { if (isWalledGardenConnection()) {
if (DBG) if (DBG) log("Walled garden test complete - walled garden detected");
Slog.d(WWSM_TAG,
"Walled garden test complete - walled garden detected");
transitionTo(mWalledGardenState); transitionTo(mWalledGardenState);
} else { } else {
if (DBG) if (DBG) log("Walled garden test complete - online");
Slog.d(WWSM_TAG, "Walled garden test complete - online");
transitionTo(mOnlineWatchState); transitionTo(mOnlineWatchState);
} }
return HANDLED; return HANDLED;
@@ -746,7 +740,7 @@ public class WifiWatchdogStateMachine extends StateMachine {
if (idDnsMap.isEmpty()) { if (idDnsMap.isEmpty()) {
if (DBG) { if (DBG) {
Slog.d(WWSM_TAG, makeLogString() + " FAILURE"); log(makeLogString() + " FAILURE");
} }
transitionTo(mDnsCheckFailureState); transitionTo(mDnsCheckFailureState);
return HANDLED; return HANDLED;
@@ -769,15 +763,15 @@ public class WifiWatchdogStateMachine extends StateMachine {
private boolean shouldCheckWalledGarden() { private boolean shouldCheckWalledGarden() {
if (!mWalledGardenTestEnabled) { if (!mWalledGardenTestEnabled) {
if (VDBG) if (DBG)
Slog.v(WWSM_TAG, "Skipping walled garden check - disabled"); log("Skipping walled garden check - disabled");
return false; return false;
} }
long waitTime = waitTime(mWalledGardenIntervalMs, long waitTime = waitTime(mWalledGardenIntervalMs,
mLastWalledGardenCheckTime); mLastWalledGardenCheckTime);
if (waitTime > 0) { if (waitTime > 0) {
if (DBG) { if (DBG) {
Slog.d(WWSM_TAG, "Skipping walled garden check - wait " + log("Skipping walled garden check - wait " +
waitTime + " ms."); waitTime + " ms.");
} }
return false; return false;
@@ -825,28 +819,28 @@ public class WifiWatchdogStateMachine extends StateMachine {
case EVENT_RSSI_CHANGE: case EVENT_RSSI_CHANGE:
if (msg.arg1 != mNetEventCounter) { if (msg.arg1 != mNetEventCounter) {
if (DBG) { if (DBG) {
Slog.d(WWSM_TAG, "Rssi change message out of sync, ignoring"); log("Rssi change message out of sync, ignoring");
} }
return HANDLED; return HANDLED;
} }
int newRssi = msg.arg2; int newRssi = msg.arg2;
signalUnstable = !rssiStrengthAboveCutoff(newRssi); signalUnstable = !rssiStrengthAboveCutoff(newRssi);
if (VDBG) { if (DBG) {
Slog.v(WWSM_TAG, "OnlineWatchState:: new rssi " + newRssi + " --> level " + log("OnlineWatchState:: new rssi " + newRssi + " --> level " +
WifiManager.calculateSignalLevel(newRssi, WIFI_SIGNAL_LEVELS)); WifiManager.calculateSignalLevel(newRssi, WIFI_SIGNAL_LEVELS));
} }
if (signalUnstable && !unstableSignalChecks) { if (signalUnstable && !unstableSignalChecks) {
if (VDBG) { if (DBG) {
Slog.v(WWSM_TAG, "Sending triggered check msg"); log("Sending triggered check msg");
} }
triggerSingleDnsCheck(); triggerSingleDnsCheck();
} }
return HANDLED; return HANDLED;
case MESSAGE_SINGLE_DNS_CHECK: case MESSAGE_SINGLE_DNS_CHECK:
if (msg.arg1 != checkGuard) { if (msg.arg1 != checkGuard) {
if (VDBG) { if (DBG) {
Slog.v(WWSM_TAG, "Single check msg out of sync, ignoring."); log("Single check msg out of sync, ignoring.");
} }
return HANDLED; return HANDLED;
} }
@@ -865,8 +859,8 @@ public class WifiWatchdogStateMachine extends StateMachine {
pingInfoMap.remove(msg.arg1); pingInfoMap.remove(msg.arg1);
int responseTime = msg.arg2; int responseTime = msg.arg2;
if (responseTime >= 0) { if (responseTime >= 0) {
if (VDBG) { if (DBG) {
Slog.v(WWSM_TAG, "Single DNS ping OK. Response time: " log("Single DNS ping OK. Response time: "
+ responseTime + " from DNS " + curDnsServer); + responseTime + " from DNS " + curDnsServer);
} }
pingInfoMap.clear(); pingInfoMap.clear();
@@ -877,7 +871,7 @@ public class WifiWatchdogStateMachine extends StateMachine {
} else { } else {
if (pingInfoMap.isEmpty()) { if (pingInfoMap.isEmpty()) {
if (DBG) { if (DBG) {
Slog.d(WWSM_TAG, "Single dns ping failure. All dns servers failed, " log("Single dns ping failure. All dns servers failed, "
+ "starting full checks."); + "starting full checks.");
} }
transitionTo(mDnsCheckingState); transitionTo(mDnsCheckingState);
@@ -924,8 +918,8 @@ public class WifiWatchdogStateMachine extends StateMachine {
} }
if (msg.arg1 != mNetEventCounter) { if (msg.arg1 != mNetEventCounter) {
if (VDBG) { if (DBG) {
Slog.v(WWSM_TAG, "Msg out of sync, ignoring..."); log("Msg out of sync, ignoring...");
} }
return HANDLED; return HANDLED;
} }
@@ -933,7 +927,7 @@ public class WifiWatchdogStateMachine extends StateMachine {
if (mDisableAPNextFailure || mNumCheckFailures >= mBssids.size() if (mDisableAPNextFailure || mNumCheckFailures >= mBssids.size()
|| mNumCheckFailures >= mMaxSsidBlacklists) { || mNumCheckFailures >= mMaxSsidBlacklists) {
if (sWifiOnly) { if (sWifiOnly) {
Slog.w(WWSM_TAG, "Would disable bad network, but device has no mobile data!" + log("Would disable bad network, but device has no mobile data!" +
" Going idle..."); " Going idle...");
// This state should be called idle -- will be changing flow. // This state should be called idle -- will be changing flow.
transitionTo(mNotConnectedState); transitionTo(mNotConnectedState);
@@ -941,7 +935,7 @@ public class WifiWatchdogStateMachine extends StateMachine {
} }
// TODO : Unban networks if they had low signal ? // TODO : Unban networks if they had low signal ?
Slog.i(WWSM_TAG, "Disabling current SSID " + wifiInfoToStr(mConnectionInfo) log("Disabling current SSID " + wifiInfoToStr(mConnectionInfo)
+ ". " + "numCheckFailures " + mNumCheckFailures + ". " + "numCheckFailures " + mNumCheckFailures
+ ", numAPs " + mBssids.size()); + ", numAPs " + mBssids.size());
int networkId = mConnectionInfo.getNetworkId(); int networkId = mConnectionInfo.getNetworkId();
@@ -955,7 +949,7 @@ public class WifiWatchdogStateMachine extends StateMachine {
} }
transitionTo(mNotConnectedState); transitionTo(mNotConnectedState);
} else { } else {
Slog.i(WWSM_TAG, "Blacklisting current BSSID. " + wifiInfoToStr(mConnectionInfo) log("Blacklisting current BSSID. " + wifiInfoToStr(mConnectionInfo)
+ "numCheckFailures " + mNumCheckFailures + ", numAPs " + mBssids.size()); + "numCheckFailures " + mNumCheckFailures + ", numAPs " + mBssids.size());
mWifiManager.addToBlacklist(mConnectionInfo.getBSSID()); mWifiManager.addToBlacklist(mConnectionInfo.getBSSID());
@@ -979,8 +973,8 @@ public class WifiWatchdogStateMachine extends StateMachine {
} }
if (msg.arg1 != mNetEventCounter) { if (msg.arg1 != mNetEventCounter) {
if (VDBG) { if (DBG) {
Slog.v(WWSM_TAG, "WalledGardenState::Msg out of sync, ignoring..."); log("WalledGardenState::Msg out of sync, ignoring...");
} }
return HANDLED; return HANDLED;
} }
@@ -1005,8 +999,8 @@ public class WifiWatchdogStateMachine extends StateMachine {
} }
if (msg.arg1 != mNetEventCounter) { if (msg.arg1 != mNetEventCounter) {
if (VDBG) { if (DBG) {
Slog.v(WWSM_TAG, "BlacklistedApState::Msg out of sync, ignoring..."); log("BlacklistedApState::Msg out of sync, ignoring...");
} }
return HANDLED; return HANDLED;
} }
@@ -1067,5 +1061,11 @@ public class WifiWatchdogStateMachine extends StateMachine {
return Settings.Secure.putInt(cr, name, value ? 1 : 0); return Settings.Secure.putInt(cr, name, value ? 1 : 0);
} }
private void log(String s) {
Log.d(TAG, s);
}
private void loge(String s) {
Log.e(TAG, s);
}
} }