diff options
Diffstat (limited to 'wifi/java/android')
| -rw-r--r-- | wifi/java/android/net/wifi/WifiConfigStore.java | 63 | ||||
| -rw-r--r-- | wifi/java/android/net/wifi/WifiConfiguration.java | 35 | ||||
| -rw-r--r-- | wifi/java/android/net/wifi/WifiNative.java | 4 | ||||
| -rw-r--r-- | wifi/java/android/net/wifi/WifiStateMachine.java | 100 |
4 files changed, 168 insertions, 34 deletions
diff --git a/wifi/java/android/net/wifi/WifiConfigStore.java b/wifi/java/android/net/wifi/WifiConfigStore.java index 5dec269..a9dbd10 100644 --- a/wifi/java/android/net/wifi/WifiConfigStore.java +++ b/wifi/java/android/net/wifi/WifiConfigStore.java @@ -25,6 +25,7 @@ import android.net.NetworkUtils; import android.net.NetworkInfo.DetailedState; import android.net.ProxyProperties; import android.net.RouteInfo; +import android.net.wifi.WifiConfiguration.EnterpriseField; import android.net.wifi.WifiConfiguration.IpAssignment; import android.net.wifi.WifiConfiguration.KeyMgmt; import android.net.wifi.WifiConfiguration.ProxySettings; @@ -1140,7 +1141,7 @@ class WifiConfigStore { String varName = field.varName(); String value = field.value(); if (value != null) { - if (field != config.eap) { + if (field != config.eap && field != config.engine) { value = (value.length() == 0) ? "NULL" : convertToQuotedString(value); } if (!mWifiNative.setNetworkVariable( @@ -1449,10 +1450,68 @@ class WifiConfigStore { value = mWifiNative.getNetworkVariable(netId, field.varName()); if (!TextUtils.isEmpty(value)) { - if (field != config.eap) value = removeDoubleQuotes(value); + if (field != config.eap && field != config.engine) { + value = removeDoubleQuotes(value); + } field.setValue(value); } } + + migrateOldEapTlsIfNecessary(config, netId); + } + + /** + * Migration code for old EAP-TLS configurations. This should only be used + * when restoring an old wpa_supplicant.conf or upgrading from a previous + * platform version. + * + * @param config the configuration to be migrated + * @param netId the wpa_supplicant's net ID + * @param value the old private_key value + */ + private void migrateOldEapTlsIfNecessary(WifiConfiguration config, int netId) { + String value = mWifiNative.getNetworkVariable(netId, + WifiConfiguration.OLD_PRIVATE_KEY_NAME); + /* + * If the old configuration value is not present, then there is nothing + * to do. + */ + if (TextUtils.isEmpty(value)) { + return; + } else { + // Also ignore it if it's empty quotes. + value = removeDoubleQuotes(value); + if (TextUtils.isEmpty(value)) { + return; + } + } + + config.engine.setValue(WifiConfiguration.ENGINE_ENABLE); + config.engine_id.setValue(convertToQuotedString(WifiConfiguration.KEYSTORE_ENGINE_ID)); + + /* + * The old key started with the keystore:// URI prefix, but we don't + * need that anymore. Trim it off if it exists. + */ + final String keyName; + if (value.startsWith(WifiConfiguration.KEYSTORE_URI)) { + keyName = new String(value.substring(WifiConfiguration.KEYSTORE_URI.length())); + } else { + keyName = value; + } + config.key_id.setValue(convertToQuotedString(keyName)); + + // Now tell the wpa_supplicant the new configuration values. + final EnterpriseField needsUpdate[] = { config.engine, config.engine_id, config.key_id }; + for (EnterpriseField field : needsUpdate) { + mWifiNative.setNetworkVariable(netId, field.varName(), field.value()); + } + + // Remove old private_key string so we don't run this again. + mWifiNative.setNetworkVariable(netId, WifiConfiguration.OLD_PRIVATE_KEY_NAME, + convertToQuotedString("")); + + saveConfig(); } private String removeDoubleQuotes(String string) { diff --git a/wifi/java/android/net/wifi/WifiConfiguration.java b/wifi/java/android/net/wifi/WifiConfiguration.java index 85a6f27..dfc1b18 100644 --- a/wifi/java/android/net/wifi/WifiConfiguration.java +++ b/wifi/java/android/net/wifi/WifiConfiguration.java @@ -29,6 +29,33 @@ import java.util.BitSet; */ public class WifiConfiguration implements Parcelable { + /** + * In old configurations, the "private_key" field was used. However, newer + * configurations use the key_id field with the engine_id set to "keystore". + * If this field is found in the configuration, the migration code is + * triggered. + * @hide + */ + public static final String OLD_PRIVATE_KEY_NAME = "private_key"; + + /** + * String representing the keystore OpenSSL ENGINE's ID. + * @hide + */ + public static final String KEYSTORE_ENGINE_ID = "keystore"; + + /** + * String representing the keystore URI used for wpa_supplicant. + * @hide + */ + public static final String KEYSTORE_URI = "keystore://"; + + /** + * String to set the engine value to when it should be enabled. + * @hide + */ + public static final String ENGINE_ENABLE = "1"; + /** {@hide} */ public static final String ssidVarName = "ssid"; /** {@hide} */ @@ -82,14 +109,18 @@ public class WifiConfiguration implements Parcelable { /** {@hide} */ public EnterpriseField client_cert = new EnterpriseField("client_cert"); /** {@hide} */ - public EnterpriseField private_key = new EnterpriseField("private_key"); + public EnterpriseField engine = new EnterpriseField("engine"); + /** {@hide} */ + public EnterpriseField engine_id = new EnterpriseField("engine_id"); + /** {@hide} */ + public EnterpriseField key_id = new EnterpriseField("key_id"); /** {@hide} */ public EnterpriseField ca_cert = new EnterpriseField("ca_cert"); /** {@hide} */ public EnterpriseField[] enterpriseFields = { eap, phase2, identity, anonymous_identity, password, client_cert, - private_key, ca_cert }; + engine, engine_id, key_id, ca_cert }; /** * Recognized key management schemes. diff --git a/wifi/java/android/net/wifi/WifiNative.java b/wifi/java/android/net/wifi/WifiNative.java index ecd4073..91f2379 100644 --- a/wifi/java/android/net/wifi/WifiNative.java +++ b/wifi/java/android/net/wifi/WifiNative.java @@ -354,9 +354,9 @@ public class WifiNative { public boolean setSuspendOptimizations(boolean enabled) { if (enabled) { - return doBooleanCommand("DRIVER SETSUSPENDOPT 0"); + return doBooleanCommand("DRIVER SETSUSPENDMODE 1"); } else { - return doBooleanCommand("DRIVER SETSUSPENDOPT 1"); + return doBooleanCommand("DRIVER SETSUSPENDMODE 0"); } } diff --git a/wifi/java/android/net/wifi/WifiStateMachine.java b/wifi/java/android/net/wifi/WifiStateMachine.java index cbf7bf8..cc0df52 100644 --- a/wifi/java/android/net/wifi/WifiStateMachine.java +++ b/wifi/java/android/net/wifi/WifiStateMachine.java @@ -127,6 +127,9 @@ public class WifiStateMachine extends StateMachine { private static final int SCAN_RESULT_CACHE_SIZE = 80; private final LruCache<String, ScanResult> mScanResultCache; + /* Chipset supports background scan */ + private final boolean mBackgroundScanSupported; + private String mInterfaceName; /* Tethering interface could be seperate from wlan interface */ private String mTetherInterfaceName; @@ -142,9 +145,15 @@ public class WifiStateMachine extends StateMachine { private boolean mScanResultIsPending = false; /* Tracks if the current scan settings are active */ private boolean mSetScanActive = false; + /* High perf mode is true if an app has held a high perf Wifi Lock */ + private boolean mHighPerfMode = false; private boolean mBluetoothConnectionActive = false; + private BroadcastReceiver mScreenReceiver; + private IntentFilter mScreenFilter; + private PowerManager.WakeLock mSuspendWakeLock; + /** * Interval in milliseconds between polling for RSSI * and linkspeed information @@ -320,6 +329,10 @@ public class WifiStateMachine extends StateMachine { static final int CMD_START_PACKET_FILTERING = BASE + 84; /* Clear packet filter */ static final int CMD_STOP_PACKET_FILTERING = BASE + 85; + /* Set suspend mode optimizations in the driver */ + static final int CMD_SET_SUSPEND_OPTIMIZATIONS = BASE + 86; + /* Clear suspend mode optimizations in the driver */ + static final int CMD_CLEAR_SUSPEND_OPTIMIZATIONS = BASE + 87; /* arg1 values to CMD_STOP_PACKET_FILTERING and CMD_START_PACKET_FILTERING */ static final int MULTICAST_V6 = 1; @@ -566,6 +579,9 @@ public class WifiStateMachine extends StateMachine { mDriverStopDelayMs = mContext.getResources().getInteger( com.android.internal.R.integer.config_wifi_driver_stop_delay); + mBackgroundScanSupported = mContext.getResources().getBoolean( + com.android.internal.R.bool.config_wifi_background_scan_support); + mContext.registerReceiver( new BroadcastReceiver() { @Override @@ -587,11 +603,41 @@ public class WifiStateMachine extends StateMachine { }, new IntentFilter(ACTION_START_SCAN)); + mScreenFilter = new IntentFilter(); + mScreenFilter.addAction(Intent.ACTION_SCREEN_ON); + mScreenFilter.addAction(Intent.ACTION_SCREEN_OFF); + mScreenReceiver = new BroadcastReceiver() { + @Override + public void onReceive(Context context, Intent intent) { + String action = intent.getAction(); + + if (action.equals(Intent.ACTION_SCREEN_ON)) { + enableRssiPolling(true); + if (mBackgroundScanSupported) { + enableBackgroundScanCommand(false); + } + enableAllNetworks(); + sendMessage(CMD_CLEAR_SUSPEND_OPTIMIZATIONS); + } else if (action.equals(Intent.ACTION_SCREEN_OFF)) { + enableRssiPolling(false); + if (mBackgroundScanSupported) { + enableBackgroundScanCommand(true); + } + //Allow 2s for suspend optimizations to be set + mSuspendWakeLock.acquire(2000); + sendMessage(CMD_SET_SUSPEND_OPTIMIZATIONS); + } + } + }; + mScanResultCache = new LruCache<String, ScanResult>(SCAN_RESULT_CACHE_SIZE); PowerManager powerManager = (PowerManager)mContext.getSystemService(Context.POWER_SERVICE); mWakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG); + mSuspendWakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "WifiSuspend"); + mSuspendWakeLock.setReferenceCounted(false); + addState(mDefaultState); addState(mInitialState, mDefaultState); addState(mDriverUnloadingState, mDefaultState); @@ -1436,21 +1482,6 @@ public class WifiStateMachine extends StateMachine { } } - private void setHighPerfModeEnabledNative(boolean enable) { - if(!mWifiNative.setSuspendOptimizations(!enable)) { - loge("set suspend optimizations failed!"); - } - if (enable) { - if (!mWifiNative.setPowerMode(POWER_MODE_ACTIVE)) { - loge("set power mode active failed!"); - } - } else { - if (!mWifiNative.setPowerMode(POWER_MODE_AUTO)) { - loge("set power mode auto failed!"); - } - } - } - private void configureLinkProperties() { if (mWifiConfigStore.isUsingStaticIp(mLastNetworkId)) { mLinkProperties = mWifiConfigStore.getLinkProperties(mLastNetworkId); @@ -1781,6 +1812,9 @@ public class WifiStateMachine extends StateMachine { case CMD_ENABLE_BACKGROUND_SCAN: mEnableBackgroundScan = (message.arg1 == 1); break; + case CMD_SET_HIGH_PERF_MODE: + mHighPerfMode = (message.arg1 == 1); + break; /* Discard */ case CMD_LOAD_DRIVER: case CMD_UNLOAD_DRIVER: @@ -1812,7 +1846,6 @@ public class WifiStateMachine extends StateMachine { case CMD_CLEAR_BLACKLIST: case CMD_SET_SCAN_MODE: case CMD_SET_SCAN_TYPE: - case CMD_SET_HIGH_PERF_MODE: case CMD_SET_COUNTRY_CODE: case CMD_SET_FREQUENCY_BAND: case CMD_RSSI_POLL: @@ -1826,6 +1859,10 @@ public class WifiStateMachine extends StateMachine { case CMD_RESPONSE_AP_CONFIG: case WifiWatchdogStateMachine.POOR_LINK_DETECTED: case WifiWatchdogStateMachine.GOOD_LINK_DETECTED: + case CMD_CLEAR_SUSPEND_OPTIMIZATIONS: + break; + case CMD_SET_SUSPEND_OPTIMIZATIONS: + mSuspendWakeLock.release(); break; case WifiMonitor.DRIVER_HUNG_EVENT: setWifiEnabled(false); @@ -1969,7 +2006,6 @@ public class WifiStateMachine extends StateMachine { case CMD_STOP_DRIVER: case CMD_SET_SCAN_MODE: case CMD_SET_SCAN_TYPE: - case CMD_SET_HIGH_PERF_MODE: case CMD_SET_COUNTRY_CODE: case CMD_SET_FREQUENCY_BAND: case CMD_START_PACKET_FILTERING: @@ -2103,7 +2139,6 @@ public class WifiStateMachine extends StateMachine { case CMD_STOP_DRIVER: case CMD_SET_SCAN_MODE: case CMD_SET_SCAN_TYPE: - case CMD_SET_HIGH_PERF_MODE: case CMD_SET_COUNTRY_CODE: case CMD_SET_FREQUENCY_BAND: case CMD_START_PACKET_FILTERING: @@ -2206,7 +2241,6 @@ public class WifiStateMachine extends StateMachine { case CMD_STOP_DRIVER: case CMD_SET_SCAN_MODE: case CMD_SET_SCAN_TYPE: - case CMD_SET_HIGH_PERF_MODE: case CMD_SET_COUNTRY_CODE: case CMD_SET_FREQUENCY_BAND: case CMD_START_PACKET_FILTERING: @@ -2416,7 +2450,6 @@ public class WifiStateMachine extends StateMachine { case CMD_STOP_DRIVER: case CMD_SET_SCAN_MODE: case CMD_SET_SCAN_TYPE: - case CMD_SET_HIGH_PERF_MODE: case CMD_SET_COUNTRY_CODE: case CMD_SET_FREQUENCY_BAND: case CMD_START_PACKET_FILTERING: @@ -2459,7 +2492,6 @@ public class WifiStateMachine extends StateMachine { case WifiMonitor.AUTHENTICATION_FAILURE_EVENT: case WifiMonitor.WPS_OVERLAP_EVENT: case CMD_SET_SCAN_TYPE: - case CMD_SET_HIGH_PERF_MODE: case CMD_SET_COUNTRY_CODE: case CMD_SET_FREQUENCY_BAND: case CMD_START_PACKET_FILTERING: @@ -2526,6 +2558,8 @@ public class WifiStateMachine extends StateMachine { } if (mP2pSupported) mWifiP2pChannel.sendMessage(WifiStateMachine.CMD_ENABLE_P2P); + + mContext.registerReceiver(mScreenReceiver, mScreenFilter); } @Override public boolean processMessage(Message message) { @@ -2548,9 +2582,6 @@ public class WifiStateMachine extends StateMachine { } mScanResultIsPending = true; break; - case CMD_SET_HIGH_PERF_MODE: - setHighPerfModeEnabledNative(message.arg1 == 1); - break; case CMD_SET_COUNTRY_CODE: String country = (String) message.obj; if (DBG) log("set country code " + country); @@ -2631,6 +2662,22 @@ public class WifiStateMachine extends StateMachine { loge("Illegal arugments to CMD_STOP_PACKET_FILTERING"); } break; + case CMD_SET_SUSPEND_OPTIMIZATIONS: + if (!mHighPerfMode) { + mWifiNative.setSuspendOptimizations(true); + } + mSuspendWakeLock.release(); + break; + case CMD_CLEAR_SUSPEND_OPTIMIZATIONS: + mWifiNative.setSuspendOptimizations(false); + break; + case CMD_SET_HIGH_PERF_MODE: + mHighPerfMode = (message.arg1 == 1); + if (mHighPerfMode) { + //Disable any suspend optimizations + mWifiNative.setSuspendOptimizations(false); + } + break; default: return NOT_HANDLED; } @@ -2647,6 +2694,7 @@ public class WifiStateMachine extends StateMachine { mScanResults = null; if (mP2pSupported) mWifiP2pChannel.sendMessage(WifiStateMachine.CMD_DISABLE_P2P); + mContext.unregisterReceiver(mScreenReceiver); } } @@ -2670,7 +2718,6 @@ public class WifiStateMachine extends StateMachine { case CMD_START_DRIVER: case CMD_STOP_DRIVER: case CMD_SET_SCAN_TYPE: - case CMD_SET_HIGH_PERF_MODE: case CMD_SET_COUNTRY_CODE: case CMD_SET_FREQUENCY_BAND: case CMD_START_PACKET_FILTERING: @@ -3430,7 +3477,6 @@ public class WifiStateMachine extends StateMachine { case CMD_STOP_DRIVER: case CMD_SET_SCAN_MODE: case CMD_SET_SCAN_TYPE: - case CMD_SET_HIGH_PERF_MODE: case CMD_SET_COUNTRY_CODE: case CMD_SET_FREQUENCY_BAND: case CMD_START_PACKET_FILTERING: @@ -3543,7 +3589,6 @@ public class WifiStateMachine extends StateMachine { case CMD_STOP_DRIVER: case CMD_SET_SCAN_MODE: case CMD_SET_SCAN_TYPE: - case CMD_SET_HIGH_PERF_MODE: case CMD_SET_COUNTRY_CODE: case CMD_SET_FREQUENCY_BAND: case CMD_START_PACKET_FILTERING: @@ -3638,7 +3683,6 @@ public class WifiStateMachine extends StateMachine { case CMD_STOP_DRIVER: case CMD_SET_SCAN_MODE: case CMD_SET_SCAN_TYPE: - case CMD_SET_HIGH_PERF_MODE: case CMD_SET_COUNTRY_CODE: case CMD_SET_FREQUENCY_BAND: case CMD_START_PACKET_FILTERING: |
