summaryrefslogtreecommitdiffstats
path: root/service/java/com/android/server/wifi/WifiServiceImpl.java
diff options
context:
space:
mode:
Diffstat (limited to 'service/java/com/android/server/wifi/WifiServiceImpl.java')
-rw-r--r--service/java/com/android/server/wifi/WifiServiceImpl.java84
1 files changed, 80 insertions, 4 deletions
diff --git a/service/java/com/android/server/wifi/WifiServiceImpl.java b/service/java/com/android/server/wifi/WifiServiceImpl.java
index 33ce852..02ba186 100644
--- a/service/java/com/android/server/wifi/WifiServiceImpl.java
+++ b/service/java/com/android/server/wifi/WifiServiceImpl.java
@@ -70,6 +70,7 @@ import android.util.Slog;
import com.android.internal.R;
import com.android.internal.app.IBatteryStats;
import com.android.internal.telephony.IccCardConstants;
+import com.android.internal.telephony.PhoneConstants;
import com.android.internal.telephony.TelephonyIntents;
import com.android.internal.util.AsyncChannel;
import com.android.server.am.BatteryStatsService;
@@ -99,6 +100,7 @@ import java.util.List;
import static com.android.server.wifi.WifiController.CMD_AIRPLANE_TOGGLED;
import static com.android.server.wifi.WifiController.CMD_BATTERY_CHANGED;
+import static com.android.server.wifi.WifiController.CMD_EMERGENCY_CALL_STATE_CHANGED;
import static com.android.server.wifi.WifiController.CMD_EMERGENCY_MODE_CHANGED;
import static com.android.server.wifi.WifiController.CMD_LOCKS_CHANGED;
import static com.android.server.wifi.WifiController.CMD_SCAN_ALWAYS_MODE_CHANGED;
@@ -153,6 +155,7 @@ public final class WifiServiceImpl extends IWifiManager.Stub {
/* Tracks the persisted states for wi-fi & airplane mode */
final WifiSettingsStore mSettingsStore;
+ private boolean mIsControllerStarted = false;
/**
* Asynchronous channel to WifiStateMachine
*/
@@ -373,6 +376,8 @@ public final class WifiServiceImpl extends IWifiManager.Stub {
public void onReceive(Context context, Intent intent) {
String state = intent.getStringExtra(IccCardConstants.INTENT_KEY_ICC_STATE);
if (state.equals(IccCardConstants.INTENT_VALUE_ICC_ABSENT)) {
+ Log.d(TAG, "resetting networks because SIM was removed");
+ mWifiStateMachine.resetSimAuthNetworks();
Log.d(TAG, "resetting country code because SIM is removed");
mWifiStateMachine.resetCountryCode();
}
@@ -389,6 +394,8 @@ public final class WifiServiceImpl extends IWifiManager.Stub {
mWifiController.start();
+ mIsControllerStarted = true;
+
// If we are already disabled (could be due to airplane mode), avoid changing persist
// state here
if (wifiEnabled) setWifiEnabled(wifiEnabled);
@@ -607,6 +614,11 @@ public final class WifiServiceImpl extends IWifiManager.Stub {
Binder.restoreCallingIdentity(ident);
}
+ if (!mIsControllerStarted) {
+ Slog.e(TAG,"WifiController is not yet started, abort setWifiEnabled");
+ return false;
+ }
+
mWifiController.sendMessage(CMD_WIFI_TOGGLED);
return true;
}
@@ -1162,6 +1174,21 @@ public final class WifiServiceImpl extends IWifiManager.Stub {
com.android.internal.R.bool.config_wifi_dual_band_support);
}
+ /**
+ * Is Ad-Hoc (IBSS) mode supported by the driver?
+ * Will only return correct results when we have reached WIFI_STATE_ENABLED
+ * @return {@code true} if IBSS mode is supported, {@code false} if not
+ */
+ public boolean isIbssSupported() {
+ enforceAccessPermission();
+ if (mWifiStateMachineChannel != null) {
+ return (mWifiStateMachine.syncIsIbssSupported(mWifiStateMachineChannel) == 1);
+ } else {
+ Slog.e(TAG, "mWifiStateMachineChannel is not initialized");
+ return false;
+ }
+ }
+
/**
* Return the DHCP-assigned addresses from the last successful DHCP request,
* if any.
@@ -1176,7 +1203,10 @@ public final class WifiServiceImpl extends IWifiManager.Stub {
if (dhcpResults.ipAddress != null &&
dhcpResults.ipAddress.getAddress() instanceof Inet4Address) {
- info.ipAddress = NetworkUtils.inetAddressToInt((Inet4Address) dhcpResults.ipAddress.getAddress());
+ info.ipAddress = NetworkUtils.inetAddressToInt(
+ (Inet4Address) dhcpResults.ipAddress.getAddress());
+ info.netmask = NetworkUtils.prefixLengthToNetmaskInt(
+ dhcpResults.ipAddress.getNetworkPrefixLength());
}
if (dhcpResults.gateway != null) {
@@ -1390,10 +1420,47 @@ public final class WifiServiceImpl extends IWifiManager.Stub {
BluetoothAdapter.STATE_DISCONNECTED);
mWifiStateMachine.sendBluetoothAdapterStateChange(state);
} else if (action.equals(TelephonyIntents.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED)) {
- boolean emergencyMode = intent.getBooleanExtra("phoneinECMState", false);
- mWifiController.sendMessage(CMD_EMERGENCY_MODE_CHANGED, emergencyMode ? 1 : 0, 0);
+ if (mContext.getResources().getBoolean(R.bool.config_wifi_ecbm_mode_change)) {
+ boolean emergencyMode = intent.getBooleanExtra("phoneinECMState", false);
+ mWifiController.sendMessage(CMD_EMERGENCY_MODE_CHANGED, emergencyMode ? 1 : 0, 0);
+ }
+ } else if (action.equals(TelephonyIntents.ACTION_EMERGENCY_CALL_STATE_CHANGED)) {
+ boolean inCall = intent.getBooleanExtra(PhoneConstants.PHONE_IN_EMERGENCY_CALL, false);
+ mWifiController.sendMessage(CMD_EMERGENCY_CALL_STATE_CHANGED, inCall ? 1 : 0, 0);
} else if (action.equals(PowerManager.ACTION_DEVICE_IDLE_MODE_CHANGED)) {
handleIdleModeChanged();
+ } else if (action.equals(WifiManager.WIFI_AP_STATE_CHANGED_ACTION)) {
+ int wifiApState = intent.getIntExtra(WifiManager.EXTRA_WIFI_AP_STATE,
+ WifiManager.WIFI_AP_STATE_FAILED);
+ Slog.d(TAG, "wifiApState=" + wifiApState);
+ /*
+ * If start SoftAp fails, WifiStateMachine would transition to InitialState,
+ * but WifiController is left stuck in ApEnabledState, which in turn
+ * fails to turn on WLAN again.
+ *
+ * Register WifiService to receive WIFI_AP_STATE_CHANGED_ACTION intent
+ * from WifiStateMachine, and if wifiApState is failed, inform WifiController
+ * to transtion to ApStaDisabledState.
+ */
+ if (wifiApState == WifiManager.WIFI_AP_STATE_FAILED) {
+ setWifiApEnabled(null, false);
+ }
+ } else if (action.equals(WifiManager.WIFI_STATE_CHANGED_ACTION)) {
+ int wifiState = intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE,
+ WifiManager.WIFI_STATE_UNKNOWN);
+ /*
+ * If Wi-Fi turn on fails, WifiStateMachine stays in InitialState,
+ * but WifiController is left stuck in StaEnabledState, which in turn
+ * fails to turn on WLAN again.
+ *
+ * Register WifiService to receive WIFI_STATE_CHANGED_ACTION intent
+ * from WifiStateMachine, and if wifiState is failed, inform WifiController
+ * to transtion to ApStaDisabledState.
+ */
+ if (wifiState == WifiManager.WIFI_STATE_FAILED) {
+ Slog.e(TAG, "Wi-Fi state is failed");
+ setWifiEnabled(false);
+ }
}
}
};
@@ -1422,9 +1489,18 @@ public final class WifiServiceImpl extends IWifiManager.Stub {
intentFilter.addAction(Intent.ACTION_SCREEN_OFF);
intentFilter.addAction(Intent.ACTION_BATTERY_CHANGED);
intentFilter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION);
+ intentFilter.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION);
+ intentFilter.addAction(WifiManager.WIFI_AP_STATE_CHANGED_ACTION);
intentFilter.addAction(BluetoothAdapter.ACTION_CONNECTION_STATE_CHANGED);
- intentFilter.addAction(TelephonyIntents.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED);
intentFilter.addAction(PowerManager.ACTION_DEVICE_IDLE_MODE_CHANGED);
+ intentFilter.addAction(TelephonyIntents.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED);
+
+ boolean trackEmergencyCallState = mContext.getResources().getBoolean(
+ com.android.internal.R.bool.config_wifi_turn_off_during_emergency_call);
+ if (trackEmergencyCallState) {
+ intentFilter.addAction(TelephonyIntents.ACTION_EMERGENCY_CALL_STATE_CHANGED);
+ }
+
mContext.registerReceiver(mReceiver, intentFilter);
}