summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoshan Pius <rpius@google.com>2017-03-28 05:25:25 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2017-03-28 05:25:25 +0000
commit96455476082f5680fd0f66eb5a87cd6f2fde1a70 (patch)
tree6750bebbca86bb86d4e8eeee021a3a5d13bf2e2d
parent8700fa5b38ce4d9a439936df04058b557bbd4cd1 (diff)
parentcb594dc8e61189be19c56ab03626df045ed90d1a (diff)
Merge changes from topic 'unused_code'
* changes: WifiNative: Fixing some nits Add try/catch blocks for incoming HAL params WSM: Reconnect on network credential change WifiStateMachine: Handle vendor HAL death WifiStateMachine: Remove unused code
-rw-r--r--service/java/com/android/server/wifi/NetworkUpdateResult.java17
-rw-r--r--service/java/com/android/server/wifi/SupplicantStaIfaceHal.java190
-rw-r--r--service/java/com/android/server/wifi/SupplicantStaNetworkHal.java154
-rw-r--r--service/java/com/android/server/wifi/WifiConfigManager.java17
-rw-r--r--service/java/com/android/server/wifi/WifiInjector.java3
-rw-r--r--service/java/com/android/server/wifi/WifiMonitor.java7
-rw-r--r--service/java/com/android/server/wifi/WifiNative.java39
-rw-r--r--service/java/com/android/server/wifi/WifiServiceImpl.java16
-rw-r--r--service/java/com/android/server/wifi/WifiStateMachine.java206
-rw-r--r--service/java/com/android/server/wifi/WifiVendorHal.java67
-rw-r--r--service/java/com/android/server/wifi/p2p/SupplicantP2pIfaceHal.java70
-rw-r--r--tests/wifitests/src/com/android/server/wifi/SupplicantStaIfaceHalTest.java22
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java2
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java29
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiVendorHalTest.java24
15 files changed, 493 insertions, 370 deletions
diff --git a/service/java/com/android/server/wifi/NetworkUpdateResult.java b/service/java/com/android/server/wifi/NetworkUpdateResult.java
index 1db7c102e..851b13b11 100644
--- a/service/java/com/android/server/wifi/NetworkUpdateResult.java
+++ b/service/java/com/android/server/wifi/NetworkUpdateResult.java
@@ -22,18 +22,21 @@ public class NetworkUpdateResult {
int netId;
boolean ipChanged;
boolean proxyChanged;
+ boolean credentialChanged;
boolean isNewNetwork = false;
public NetworkUpdateResult(int id) {
netId = id;
ipChanged = false;
proxyChanged = false;
+ credentialChanged = false;
}
- public NetworkUpdateResult(boolean ip, boolean proxy) {
+ public NetworkUpdateResult(boolean ip, boolean proxy, boolean credential) {
netId = INVALID_NETWORK_ID;
ipChanged = ip;
proxyChanged = proxy;
+ credentialChanged = credential;
}
public void setNetworkId(int id) {
@@ -44,22 +47,18 @@ public class NetworkUpdateResult {
return netId;
}
- public void setIpChanged(boolean ip) {
- ipChanged = ip;
- }
-
public boolean hasIpChanged() {
return ipChanged;
}
- public void setProxyChanged(boolean proxy) {
- proxyChanged = proxy;
- }
-
public boolean hasProxyChanged() {
return proxyChanged;
}
+ public boolean hasCredentialChanged() {
+ return credentialChanged;
+ }
+
public boolean isNewNetwork() {
return isNewNetwork;
}
diff --git a/service/java/com/android/server/wifi/SupplicantStaIfaceHal.java b/service/java/com/android/server/wifi/SupplicantStaIfaceHal.java
index 2432db6be..681cf3a3e 100644
--- a/service/java/com/android/server/wifi/SupplicantStaIfaceHal.java
+++ b/service/java/com/android/server/wifi/SupplicantStaIfaceHal.java
@@ -354,7 +354,7 @@ public class SupplicantStaIfaceHal {
* @param config Config corresponding to the network.
* @return SupplicantStaNetwork of the added network in wpa_supplicant.
*/
- private SupplicantStaNetworkHal addNetwork(WifiConfiguration config) {
+ private SupplicantStaNetworkHal addNetworkAndSaveConfig(WifiConfiguration config) {
logi("addSupplicantStaNetwork via HIDL");
if (config == null) {
loge("Cannot add NULL network!");
@@ -365,7 +365,13 @@ public class SupplicantStaIfaceHal {
loge("Failed to add a network!");
return null;
}
- if (!network.saveWifiConfiguration(config)) {
+ boolean saveSuccess = false;
+ try {
+ saveSuccess = network.saveWifiConfiguration(config);
+ } catch (IllegalArgumentException e) {
+ Log.e(TAG, "Exception while saving config params: " + config, e);
+ }
+ if (!saveSuccess) {
loge("Failed to save variables for: " + config.configKey());
if (!removeAllNetworks()) {
loge("Failed to remove all networks on failure.");
@@ -395,7 +401,7 @@ public class SupplicantStaIfaceHal {
loge("Failed to remove existing networks");
return false;
}
- mCurrentNetwork = addNetwork(config);
+ mCurrentNetwork = addNetworkAndSaveConfig(config);
if (mCurrentNetwork == null) {
loge("Failed to add/save network configuration: " + config.configKey());
return false;
@@ -754,21 +760,26 @@ public class SupplicantStaIfaceHal {
* @return true if request is sent successfully, false otherwise.
*/
public boolean setWpsDeviceType(String typeStr) {
- Matcher match = WPS_DEVICE_TYPE_PATTERN.matcher(typeStr);
- if (!match.find() || match.groupCount() != 3) {
- Log.e(TAG, "Malformed WPS device type " + typeStr);
+ try {
+ Matcher match = WPS_DEVICE_TYPE_PATTERN.matcher(typeStr);
+ if (!match.find() || match.groupCount() != 3) {
+ Log.e(TAG, "Malformed WPS device type " + typeStr);
+ return false;
+ }
+ short categ = Short.parseShort(match.group(1));
+ byte[] oui = NativeUtil.hexStringToByteArray(match.group(2));
+ short subCateg = Short.parseShort(match.group(3));
+
+ byte[] bytes = new byte[8];
+ ByteBuffer byteBuffer = ByteBuffer.wrap(bytes).order(ByteOrder.BIG_ENDIAN);
+ byteBuffer.putShort(categ);
+ byteBuffer.put(oui);
+ byteBuffer.putShort(subCateg);
+ return setWpsDeviceType(bytes);
+ } catch (IllegalArgumentException e) {
+ Log.e(TAG, "Illegal argument " + typeStr, e);
return false;
}
- short categ = Short.parseShort(match.group(1));
- byte[] oui = NativeUtil.hexStringToByteArray(match.group(2));
- short subCateg = Short.parseShort(match.group(3));
-
- byte[] bytes = new byte[8];
- ByteBuffer byteBuffer = ByteBuffer.wrap(bytes).order(ByteOrder.BIG_ENDIAN);
- byteBuffer.putShort(categ);
- byteBuffer.put(oui);
- byteBuffer.putShort(subCateg);
- return setWpsDeviceType(bytes);
}
private boolean setWpsDeviceType(byte[/* 8 */] type) {
@@ -978,7 +989,12 @@ public class SupplicantStaIfaceHal {
* @return true if request is sent successfully, false otherwise.
*/
public boolean initiateTdlsDiscover(String macAddress) {
- return initiateTdlsDiscover(NativeUtil.macAddressToByteArray(macAddress));
+ try {
+ return initiateTdlsDiscover(NativeUtil.macAddressToByteArray(macAddress));
+ } catch (IllegalArgumentException e) {
+ Log.e(TAG, "Illegal argument " + macAddress, e);
+ return false;
+ }
}
/** See ISupplicantStaIface.hal for documentation */
private boolean initiateTdlsDiscover(byte[/* 6 */] macAddress) {
@@ -1002,7 +1018,12 @@ public class SupplicantStaIfaceHal {
* @return true if request is sent successfully, false otherwise.
*/
public boolean initiateTdlsSetup(String macAddress) {
- return initiateTdlsSetup(NativeUtil.macAddressToByteArray(macAddress));
+ try {
+ return initiateTdlsSetup(NativeUtil.macAddressToByteArray(macAddress));
+ } catch (IllegalArgumentException e) {
+ Log.e(TAG, "Illegal argument " + macAddress, e);
+ return false;
+ }
}
/** See ISupplicantStaIface.hal for documentation */
private boolean initiateTdlsSetup(byte[/* 6 */] macAddress) {
@@ -1025,7 +1046,12 @@ public class SupplicantStaIfaceHal {
* @return true if request is sent successfully, false otherwise.
*/
public boolean initiateTdlsTeardown(String macAddress) {
- return initiateTdlsTeardown(NativeUtil.macAddressToByteArray(macAddress));
+ try {
+ return initiateTdlsTeardown(NativeUtil.macAddressToByteArray(macAddress));
+ } catch (IllegalArgumentException e) {
+ Log.e(TAG, "Illegal argument " + macAddress, e);
+ return false;
+ }
}
/** See ISupplicantStaIface.hal for documentation */
@@ -1053,8 +1079,13 @@ public class SupplicantStaIfaceHal {
*/
public boolean initiateAnqpQuery(String bssid, ArrayList<Short> infoElements,
ArrayList<Integer> hs20SubTypes) {
- return initiateAnqpQuery(
- NativeUtil.macAddressToByteArray(bssid), infoElements, hs20SubTypes);
+ try {
+ return initiateAnqpQuery(
+ NativeUtil.macAddressToByteArray(bssid), infoElements, hs20SubTypes);
+ } catch (IllegalArgumentException e) {
+ Log.e(TAG, "Illegal argument " + bssid, e);
+ return false;
+ }
}
/** See ISupplicantStaIface.hal for documentation */
@@ -1082,7 +1113,12 @@ public class SupplicantStaIfaceHal {
* @return true if request is sent successfully, false otherwise.
*/
public boolean initiateHs20IconQuery(String bssid, String fileName) {
- return initiateHs20IconQuery(NativeUtil.macAddressToByteArray(bssid), fileName);
+ try {
+ return initiateHs20IconQuery(NativeUtil.macAddressToByteArray(bssid), fileName);
+ } catch (IllegalArgumentException e) {
+ Log.e(TAG, "Illegal argument " + bssid, e);
+ return false;
+ }
}
/** See ISupplicantStaIface.hal for documentation */
@@ -1163,17 +1199,29 @@ public class SupplicantStaIfaceHal {
}
}
- public static final byte RX_FILTER_TYPE_V4_MULTICAST =
- ISupplicantStaIface.RxFilterType.V6_MULTICAST;
- public static final byte RX_FILTER_TYPE_V6_MULTICAST =
- ISupplicantStaIface.RxFilterType.V6_MULTICAST;
/**
* Add an RX filter.
*
- * @param type one of {@link #RX_FILTER_TYPE_V4_MULTICAST} or
- * {@link #RX_FILTER_TYPE_V6_MULTICAST} values.
+ * @param type one of {@link WifiNative#RX_FILTER_TYPE_V4_MULTICAST}
+ * {@link WifiNative#RX_FILTER_TYPE_V6_MULTICAST} values.
* @return true if request is sent successfully, false otherwise.
*/
+ public boolean addRxFilter(int type) {
+ byte halType;
+ switch (type) {
+ case WifiNative.RX_FILTER_TYPE_V4_MULTICAST:
+ halType = ISupplicantStaIface.RxFilterType.V4_MULTICAST;
+ break;
+ case WifiNative.RX_FILTER_TYPE_V6_MULTICAST:
+ halType = ISupplicantStaIface.RxFilterType.V6_MULTICAST;
+ break;
+ default:
+ Log.e(TAG, "Invalid Rx Filter type: " + type);
+ return false;
+ }
+ return addRxFilter(halType);
+ }
+
public boolean addRxFilter(byte type) {
synchronized (mLock) {
final String methodStr = "addRxFilter";
@@ -1191,10 +1239,26 @@ public class SupplicantStaIfaceHal {
/**
* Remove an RX filter.
*
- * @param type one of {@link #RX_FILTER_TYPE_V4_MULTICAST} or
- * {@link #RX_FILTER_TYPE_V6_MULTICAST} values.
+ * @param type one of {@link WifiNative#RX_FILTER_TYPE_V4_MULTICAST}
+ * {@link WifiNative#RX_FILTER_TYPE_V6_MULTICAST} values.
* @return true if request is sent successfully, false otherwise.
*/
+ public boolean removeRxFilter(int type) {
+ byte halType;
+ switch (type) {
+ case WifiNative.RX_FILTER_TYPE_V4_MULTICAST:
+ halType = ISupplicantStaIface.RxFilterType.V4_MULTICAST;
+ break;
+ case WifiNative.RX_FILTER_TYPE_V6_MULTICAST:
+ halType = ISupplicantStaIface.RxFilterType.V6_MULTICAST;
+ break;
+ default:
+ Log.e(TAG, "Invalid Rx Filter type: " + type);
+ return false;
+ }
+ return removeRxFilter(halType);
+ }
+
public boolean removeRxFilter(byte type) {
synchronized (mLock) {
final String methodStr = "removeRxFilter";
@@ -1209,17 +1273,34 @@ public class SupplicantStaIfaceHal {
}
}
- public static final byte BT_COEX_MODE_ENABLED = ISupplicantStaIface.BtCoexistenceMode.ENABLED;
- public static final byte BT_COEX_MODE_DISABLED = ISupplicantStaIface.BtCoexistenceMode.DISABLED;
- public static final byte BT_COEX_MODE_SENSE = ISupplicantStaIface.BtCoexistenceMode.SENSE;
/**
* Set Bt co existense mode.
*
- * @param mode one of the above {@link #BT_COEX_MODE_ENABLED}, {@link #BT_COEX_MODE_DISABLED}
- * or {@link #BT_COEX_MODE_SENSE} values.
+ * @param mode one of the above {@link WifiNative#BLUETOOTH_COEXISTENCE_MODE_DISABLED},
+ * {@link WifiNative#BLUETOOTH_COEXISTENCE_MODE_ENABLED} or
+ * {@link WifiNative#BLUETOOTH_COEXISTENCE_MODE_SENSE}.
* @return true if request is sent successfully, false otherwise.
*/
- public boolean setBtCoexistenceMode(byte mode) {
+ public boolean setBtCoexistenceMode(int mode) {
+ byte halMode;
+ switch (mode) {
+ case WifiNative.BLUETOOTH_COEXISTENCE_MODE_ENABLED:
+ halMode = ISupplicantStaIface.BtCoexistenceMode.ENABLED;
+ break;
+ case WifiNative.BLUETOOTH_COEXISTENCE_MODE_DISABLED:
+ halMode = ISupplicantStaIface.BtCoexistenceMode.DISABLED;
+ break;
+ case WifiNative.BLUETOOTH_COEXISTENCE_MODE_SENSE:
+ halMode = ISupplicantStaIface.BtCoexistenceMode.SENSE;
+ break;
+ default:
+ Log.e(TAG, "Invalid Bt Coex mode: " + mode);
+ return false;
+ }
+ return setBtCoexistenceMode(halMode);
+ }
+
+ private boolean setBtCoexistenceMode(byte mode) {
synchronized (mLock) {
final String methodStr = "setBtCoexistenceMode";
if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
@@ -1308,7 +1389,12 @@ public class SupplicantStaIfaceHal {
*/
public boolean startWpsRegistrar(String bssidStr, String pin) {
if (TextUtils.isEmpty(bssidStr) || TextUtils.isEmpty(pin)) return false;
- return startWpsRegistrar(NativeUtil.macAddressToByteArray(bssidStr), pin);
+ try {
+ return startWpsRegistrar(NativeUtil.macAddressToByteArray(bssidStr), pin);
+ } catch (IllegalArgumentException e) {
+ Log.e(TAG, "Illegal argument " + bssidStr, e);
+ return false;
+ }
}
/** See ISupplicantStaIface.hal for documentation */
@@ -1333,7 +1419,12 @@ public class SupplicantStaIfaceHal {
* @return true if request is sent successfully, false otherwise.
*/
public boolean startWpsPbc(String bssidStr) {
- return startWpsPbc(NativeUtil.macAddressToByteArray(bssidStr));
+ try {
+ return startWpsPbc(NativeUtil.macAddressToByteArray(bssidStr));
+ } catch (IllegalArgumentException e) {
+ Log.e(TAG, "Illegal argument " + bssidStr, e);
+ return false;
+ }
}
/** See ISupplicantStaIface.hal for documentation */
@@ -1379,7 +1470,12 @@ public class SupplicantStaIfaceHal {
* @return new pin generated on success, null otherwise.
*/
public String startWpsPinDisplay(String bssidStr) {
- return startWpsPinDisplay(NativeUtil.macAddressToByteArray(bssidStr));
+ try {
+ return startWpsPinDisplay(NativeUtil.macAddressToByteArray(bssidStr));
+ } catch (IllegalArgumentException e) {
+ Log.e(TAG, "Illegal argument " + bssidStr, e);
+ return null;
+ }
}
/** See ISupplicantStaIface.hal for documentation */
@@ -1456,19 +1552,17 @@ public class SupplicantStaIfaceHal {
}
}
- public static final int LOG_LEVEL_EXCESSIVE = ISupplicant.DebugLevel.EXCESSIVE;
- public static final int LOG_LEVEL_MSGDUMP = ISupplicant.DebugLevel.MSGDUMP;
- public static final int LOG_LEVEL_DEBUG = ISupplicant.DebugLevel.DEBUG;
- public static final int LOG_LEVEL_INFO = ISupplicant.DebugLevel.INFO;
- public static final int LOG_LEVEL_WARNING = ISupplicant.DebugLevel.WARNING;
- public static final int LOG_LEVEL_ERROR = ISupplicant.DebugLevel.ERROR;
/**
* Set the debug log level for wpa_supplicant
- * @param level One of the above {@link #LOG_LEVEL_EXCESSIVE} - {@link #LOG_LEVEL_ERROR} value.
+ *
+ * @param turnOnVerbose Whether to turn on verbose logging or not.
* @return true if request is sent successfully, false otherwise.
*/
- public boolean setLogLevel(int level) {
- return setDebugParams(level, false, false);
+ public boolean setLogLevel(boolean turnOnVerbose) {
+ int logLevel = turnOnVerbose
+ ? ISupplicant.DebugLevel.DEBUG
+ : ISupplicant.DebugLevel.INFO;
+ return setDebugParams(logLevel, false, false);
}
/** See ISupplicant.hal for documentation */
diff --git a/service/java/com/android/server/wifi/SupplicantStaNetworkHal.java b/service/java/com/android/server/wifi/SupplicantStaNetworkHal.java
index 46f8c41b9..262725cc4 100644
--- a/service/java/com/android/server/wifi/SupplicantStaNetworkHal.java
+++ b/service/java/com/android/server/wifi/SupplicantStaNetworkHal.java
@@ -146,6 +146,7 @@ public class SupplicantStaNetworkHal {
* @param config WifiConfiguration object to be populated.
* @param networkExtras Map of network extras parsed from wpa_supplicant.
* @return true if succeeds, false otherwise.
+ * @throws IllegalArgumentException on malformed configuration params.
*/
public boolean loadWifiConfiguration(WifiConfiguration config,
Map<String, String> networkExtras) {
@@ -240,6 +241,7 @@ public class SupplicantStaNetworkHal {
*
* @param config WifiConfiguration object to be saved.
* @return true if succeeds, false otherwise.
+ * @throws IllegalArgumentException on malformed configuration params.
*/
public boolean saveWifiConfiguration(WifiConfiguration config) {
if (config == null) return false;
@@ -979,7 +981,12 @@ public class SupplicantStaNetworkHal {
* @return true if it succeeds, false otherwise.
*/
public boolean setBssid(String bssidStr) {
- return setBssid(NativeUtil.macAddressToByteArray(bssidStr));
+ try {
+ return setBssid(NativeUtil.macAddressToByteArray(bssidStr));
+ } catch (IllegalArgumentException e) {
+ Log.e(TAG, "Illegal argument " + bssidStr, e);
+ return false;
+ }
}
/** See ISupplicantStaNetwork.hal for documentation */
@@ -2082,36 +2089,41 @@ public class SupplicantStaNetworkHal {
* @return true if succeeds, false otherwise.
*/
public boolean sendNetworkEapSimGsmAuthResponse(String paramsStr) {
- Matcher match = GSM_AUTH_RESPONSE_PARAMS_PATTERN.matcher(paramsStr);
- ArrayList<ISupplicantStaNetwork.NetworkResponseEapSimGsmAuthParams> params =
- new ArrayList<>();
- while (match.find()) {
- if (match.groupCount() != 2) {
- Log.e(TAG, "Malformed gsm auth response params: " + paramsStr);
- return false;
- }
- ISupplicantStaNetwork.NetworkResponseEapSimGsmAuthParams param =
- new ISupplicantStaNetwork.NetworkResponseEapSimGsmAuthParams();
- byte[] kc = NativeUtil.hexStringToByteArray(match.group(1));
- if (kc == null || kc.length != param.kc.length) {
- Log.e(TAG, "Invalid kc value: " + match.group(1));
- return false;
+ try {
+ Matcher match = GSM_AUTH_RESPONSE_PARAMS_PATTERN.matcher(paramsStr);
+ ArrayList<ISupplicantStaNetwork.NetworkResponseEapSimGsmAuthParams> params =
+ new ArrayList<>();
+ while (match.find()) {
+ if (match.groupCount() != 2) {
+ Log.e(TAG, "Malformed gsm auth response params: " + paramsStr);
+ return false;
+ }
+ ISupplicantStaNetwork.NetworkResponseEapSimGsmAuthParams param =
+ new ISupplicantStaNetwork.NetworkResponseEapSimGsmAuthParams();
+ byte[] kc = NativeUtil.hexStringToByteArray(match.group(1));
+ if (kc == null || kc.length != param.kc.length) {
+ Log.e(TAG, "Invalid kc value: " + match.group(1));
+ return false;
+ }
+ byte[] sres = NativeUtil.hexStringToByteArray(match.group(2));
+ if (sres == null || sres.length != param.sres.length) {
+ Log.e(TAG, "Invalid sres value: " + match.group(2));
+ return false;
+ }
+ System.arraycopy(kc, 0, param.kc, 0, param.kc.length);
+ System.arraycopy(sres, 0, param.sres, 0, param.sres.length);
+ params.add(param);
}
- byte[] sres = NativeUtil.hexStringToByteArray(match.group(2));
- if (sres == null || sres.length != param.sres.length) {
- Log.e(TAG, "Invalid sres value: " + match.group(2));
+ // The number of kc/sres pairs can either be 2 or 3 depending on the request.
+ if (params.size() > 3 || params.size() < 2) {
+ Log.e(TAG, "Malformed gsm auth response params: " + paramsStr);
return false;
}
- System.arraycopy(kc, 0, param.kc, 0, param.kc.length);
- System.arraycopy(sres, 0, param.sres, 0, param.sres.length);
- params.add(param);
- }
- // The number of kc/sres pairs can either be 2 or 3 depending on the request.
- if (params.size() > 3 || params.size() < 2) {
- Log.e(TAG, "Malformed gsm auth response params: " + paramsStr);
+ return sendNetworkEapSimGsmAuthResponse(params);
+ } catch (IllegalArgumentException e) {
+ Log.e(TAG, "Illegal argument " + paramsStr, e);
return false;
}
- return sendNetworkEapSimGsmAuthResponse(params);
}
/** See ISupplicantStaNetwork.hal for documentation */
@@ -2151,35 +2163,41 @@ public class SupplicantStaNetworkHal {
* @return true if succeeds, false otherwise.
*/
public boolean sendNetworkEapSimUmtsAuthResponse(String paramsStr) {
- Matcher match = UMTS_AUTH_RESPONSE_PARAMS_PATTERN.matcher(paramsStr);
- if (!match.find() || match.groupCount() != 3) {
- Log.e(TAG, "Malformed umts auth response params: " + paramsStr);
- return false;
- }
- ISupplicantStaNetwork.NetworkResponseEapSimUmtsAuthParams params =
- new ISupplicantStaNetwork.NetworkResponseEapSimUmtsAuthParams();
- byte[] ik = NativeUtil.hexStringToByteArray(match.group(1));
- if (ik == null || ik.length != params.ik.length) {
- Log.e(TAG, "Invalid ik value: " + match.group(1));
- return false;
- }
- byte[] ck = NativeUtil.hexStringToByteArray(match.group(2));
- if (ck == null || ck.length != params.ck.length) {
- Log.e(TAG, "Invalid ck value: " + match.group(2));
- return false;
- }
- byte[] res = NativeUtil.hexStringToByteArray(match.group(3));
- if (res == null || res.length == 0) {
- Log.e(TAG, "Invalid res value: " + match.group(3));
+ try {
+ Matcher match = UMTS_AUTH_RESPONSE_PARAMS_PATTERN.matcher(paramsStr);
+ if (!match.find() || match.groupCount() != 3) {
+ Log.e(TAG, "Malformed umts auth response params: " + paramsStr);
+ return false;
+ }
+ ISupplicantStaNetwork.NetworkResponseEapSimUmtsAuthParams params =
+ new ISupplicantStaNetwork.NetworkResponseEapSimUmtsAuthParams();
+ byte[] ik = NativeUtil.hexStringToByteArray(match.group(1));
+ if (ik == null || ik.length != params.ik.length) {
+ Log.e(TAG, "Invalid ik value: " + match.group(1));
+ return false;
+ }
+ byte[] ck = NativeUtil.hexStringToByteArray(match.group(2));
+ if (ck == null || ck.length != params.ck.length) {
+ Log.e(TAG, "Invalid ck value: " + match.group(2));
+ return false;
+ }
+ byte[] res = NativeUtil.hexStringToByteArray(match.group(3));
+ if (res == null || res.length == 0) {
+ Log.e(TAG, "Invalid res value: " + match.group(3));
+ return false;
+ }
+ System.arraycopy(ik, 0, params.ik, 0, params.ik.length);
+ System.arraycopy(ck, 0, params.ck, 0, params.ck.length);
+ for (byte b : res) {
+ params.res.add(b);
+ }
+ return sendNetworkEapSimUmtsAuthResponse(params);
+ } catch (IllegalArgumentException e) {
+ Log.e(TAG, "Illegal argument " + paramsStr, e);
return false;
}
- System.arraycopy(ik, 0, params.ik, 0, params.ik.length);
- System.arraycopy(ck, 0, params.ck, 0, params.ck.length);
- for (byte b : res) {
- params.res.add(b);
- }
- return sendNetworkEapSimUmtsAuthResponse(params);
}
+
/** See ISupplicantStaNetwork.hal for documentation */
private boolean sendNetworkEapSimUmtsAuthResponse(
ISupplicantStaNetwork.NetworkResponseEapSimUmtsAuthParams params) {
@@ -2203,17 +2221,22 @@ public class SupplicantStaNetworkHal {
* @return true if succeeds, false otherwise.
*/
public boolean sendNetworkEapSimUmtsAutsResponse(String paramsStr) {
- Matcher match = UMTS_AUTS_RESPONSE_PARAMS_PATTERN.matcher(paramsStr);
- if (!match.find() || match.groupCount() != 1) {
- Log.e(TAG, "Malformed umts auts response params: " + paramsStr);
- return false;
- }
- byte[] auts = NativeUtil.hexStringToByteArray(match.group(1));
- if (auts == null || auts.length != 14) {
- Log.e(TAG, "Invalid auts value: " + match.group(1));
+ try {
+ Matcher match = UMTS_AUTS_RESPONSE_PARAMS_PATTERN.matcher(paramsStr);
+ if (!match.find() || match.groupCount() != 1) {
+ Log.e(TAG, "Malformed umts auts response params: " + paramsStr);
+ return false;
+ }
+ byte[] auts = NativeUtil.hexStringToByteArray(match.group(1));
+ if (auts == null || auts.length != 14) {
+ Log.e(TAG, "Invalid auts value: " + match.group(1));
+ return false;
+ }
+ return sendNetworkEapSimUmtsAutsResponse(auts);
+ } catch (IllegalArgumentException e) {
+ Log.e(TAG, "Illegal argument " + paramsStr, e);
return false;
}
- return sendNetworkEapSimUmtsAutsResponse(auts);
}
/** See ISupplicantStaNetwork.hal for documentation */
private boolean sendNetworkEapSimUmtsAutsResponse(byte[/* 14 */] auts) {
@@ -2251,8 +2274,13 @@ public class SupplicantStaNetworkHal {
* @return true if succeeds, false otherwise.
*/
public boolean sendNetworkEapIdentityResponse(String identityStr) {
- ArrayList<Byte> identity = NativeUtil.stringToByteArrayList(identityStr);
- return sendNetworkEapIdentityResponse(identity);
+ try {
+ ArrayList<Byte> identity = NativeUtil.stringToByteArrayList(identityStr);
+ return sendNetworkEapIdentityResponse(identity);
+ } catch (IllegalArgumentException e) {
+ Log.e(TAG, "Illegal argument " + identityStr, e);
+ return false;
+ }
}
/** See ISupplicantStaNetwork.hal for documentation */
private boolean sendNetworkEapIdentityResponse(ArrayList<Byte> identity) {
diff --git a/service/java/com/android/server/wifi/WifiConfigManager.java b/service/java/com/android/server/wifi/WifiConfigManager.java
index ba3c8d305..63168e995 100644
--- a/service/java/com/android/server/wifi/WifiConfigManager.java
+++ b/service/java/com/android/server/wifi/WifiConfigManager.java
@@ -939,6 +939,13 @@ public class WifiConfigManager {
}
boolean newNetwork = (existingInternalConfig == null);
+ // This is needed to inform IpManager about any IP configuration changes.
+ boolean hasIpChanged =
+ newNetwork || WifiConfigurationUtil.hasIpChanged(
+ existingInternalConfig, newInternalConfig);
+ boolean hasProxyChanged =
+ newNetwork || WifiConfigurationUtil.hasProxyChanged(
+ existingInternalConfig, newInternalConfig);
// Reset the |hasEverConnected| flag if the credential parameters changed in this update.
boolean hasCredentialChanged =
newNetwork || WifiConfigurationUtil.hasCredentialChanged(
@@ -960,14 +967,8 @@ public class WifiConfigManager {
// Stage the backup of the SettingsProvider package which backs this up.
mBackupManagerProxy.notifyDataChanged();
- // This is needed to inform IpManager about any IP configuration changes.
- boolean hasIpChanged =
- newNetwork || WifiConfigurationUtil.hasIpChanged(
- existingInternalConfig, newInternalConfig);
- boolean hasProxyChanged =
- newNetwork || WifiConfigurationUtil.hasProxyChanged(
- existingInternalConfig, newInternalConfig);
- NetworkUpdateResult result = new NetworkUpdateResult(hasIpChanged, hasProxyChanged);
+ NetworkUpdateResult result =
+ new NetworkUpdateResult(hasIpChanged, hasProxyChanged, hasCredentialChanged);
result.setIsNewNetwork(newNetwork);
result.setNetworkId(newInternalConfig.networkId);
diff --git a/service/java/com/android/server/wifi/WifiInjector.java b/service/java/com/android/server/wifi/WifiInjector.java
index 6fee22c1a..1ecf88260 100644
--- a/service/java/com/android/server/wifi/WifiInjector.java
+++ b/service/java/com/android/server/wifi/WifiInjector.java
@@ -152,7 +152,8 @@ public class WifiInjector {
// Modules interacting with Native.
mWifiMonitor = new WifiMonitor(this);
mHalDeviceManager = new HalDeviceManager();
- mWifiVendorHal = new WifiVendorHal(mHalDeviceManager, mWifiStateMachineHandlerThread);
+ mWifiVendorHal =
+ new WifiVendorHal(mHalDeviceManager, mWifiStateMachineHandlerThread.getLooper());
mSupplicantStaIfaceHal = new SupplicantStaIfaceHal(mContext, mWifiMonitor);
mWificondControl = new WificondControl(this, mWifiMonitor);
mWifiNative = new WifiNative(SystemProperties.get("wifi.interface", "wlan0"),
diff --git a/service/java/com/android/server/wifi/WifiMonitor.java b/service/java/com/android/server/wifi/WifiMonitor.java
index c4f0bdedb..6c8ac813f 100644
--- a/service/java/com/android/server/wifi/WifiMonitor.java
+++ b/service/java/com/android/server/wifi/WifiMonitor.java
@@ -72,13 +72,6 @@ public class WifiMonitor {
public static final int WPS_OVERLAP_EVENT = BASE + 10;
/* WPS timeout detected */
public static final int WPS_TIMEOUT_EVENT = BASE + 11;
- /* Driver was hung */
- public static final int DRIVER_HUNG_EVENT = BASE + 12;
- /* SSID was disabled due to auth failure or excessive
- * connection failures */
- public static final int SSID_TEMP_DISABLED = BASE + 13;
- /* SSID reenabled by supplicant */
- public static final int SSID_REENABLED = BASE + 14;
/* Request Identity */
public static final int SUP_REQUEST_IDENTITY = BASE + 15;
diff --git a/service/java/com/android/server/wifi/WifiNative.java b/service/java/com/android/server/wifi/WifiNative.java
index cae705aff..f6a7e7c39 100644
--- a/service/java/com/android/server/wifi/WifiNative.java
+++ b/service/java/com/android/server/wifi/WifiNative.java
@@ -272,10 +272,7 @@ public class WifiNative {
* @param turnOnVerbose Whether to turn on verbose logging or not.
*/
public void setSupplicantLogLevel(boolean turnOnVerbose) {
- int logLevel = turnOnVerbose
- ? SupplicantStaIfaceHal.LOG_LEVEL_DEBUG
- : SupplicantStaIfaceHal.LOG_LEVEL_INFO;
- mSupplicantStaIfaceHal.setLogLevel(logLevel);
+ mSupplicantStaIfaceHal.setLogLevel(turnOnVerbose);
}
/**
@@ -314,6 +311,8 @@ public class WifiNative {
return mSupplicantStaIfaceHal.getMacAddress();
}
+ public static final int RX_FILTER_TYPE_V4_MULTICAST = 0;
+ public static final int RX_FILTER_TYPE_V6_MULTICAST = 1;
/**
* Start filtering out Multicast V4 packets
* @return {@code true} if the operation succeeded, {@code false} otherwise
@@ -341,7 +340,7 @@ public class WifiNative {
public boolean startFilteringMulticastV4Packets() {
return mSupplicantStaIfaceHal.stopRxFilter()
&& mSupplicantStaIfaceHal.removeRxFilter(
- SupplicantStaIfaceHal.RX_FILTER_TYPE_V4_MULTICAST)
+ RX_FILTER_TYPE_V4_MULTICAST)
&& mSupplicantStaIfaceHal.startRxFilter();
}
@@ -352,7 +351,7 @@ public class WifiNative {
public boolean stopFilteringMulticastV4Packets() {
return mSupplicantStaIfaceHal.stopRxFilter()
&& mSupplicantStaIfaceHal.addRxFilter(
- SupplicantStaIfaceHal.RX_FILTER_TYPE_V4_MULTICAST)
+ RX_FILTER_TYPE_V4_MULTICAST)
&& mSupplicantStaIfaceHal.startRxFilter();
}
@@ -363,7 +362,7 @@ public class WifiNative {
public boolean startFilteringMulticastV6Packets() {
return mSupplicantStaIfaceHal.stopRxFilter()
&& mSupplicantStaIfaceHal.removeRxFilter(
- SupplicantStaIfaceHal.RX_FILTER_TYPE_V6_MULTICAST)
+ RX_FILTER_TYPE_V6_MULTICAST)
&& mSupplicantStaIfaceHal.startRxFilter();
}
@@ -374,16 +373,13 @@ public class WifiNative {
public boolean stopFilteringMulticastV6Packets() {
return mSupplicantStaIfaceHal.stopRxFilter()
&& mSupplicantStaIfaceHal.addRxFilter(
- SupplicantStaIfaceHal.RX_FILTER_TYPE_V6_MULTICAST)
+ RX_FILTER_TYPE_V6_MULTICAST)
&& mSupplicantStaIfaceHal.startRxFilter();
}
- public static final int BLUETOOTH_COEXISTENCE_MODE_ENABLED =
- SupplicantStaIfaceHal.BT_COEX_MODE_ENABLED;
- public static final int BLUETOOTH_COEXISTENCE_MODE_DISABLED =
- SupplicantStaIfaceHal.BT_COEX_MODE_DISABLED;
- public static final int BLUETOOTH_COEXISTENCE_MODE_SENSE =
- SupplicantStaIfaceHal.BT_COEX_MODE_SENSE;
+ public static final int BLUETOOTH_COEXISTENCE_MODE_ENABLED = 0;
+ public static final int BLUETOOTH_COEXISTENCE_MODE_DISABLED = 1;
+ public static final int BLUETOOTH_COEXISTENCE_MODE_SENSE = 2;
/**
* Sets the bluetooth coexistence mode.
*
@@ -393,7 +389,7 @@ public class WifiNative {
* @return Whether the mode was successfully set.
*/
public boolean setBluetoothCoexistenceMode(int mode) {
- return mSupplicantStaIfaceHal.setBtCoexistenceMode((byte) mode);
+ return mSupplicantStaIfaceHal.setBtCoexistenceMode(mode);
}
/**
@@ -779,12 +775,21 @@ public class WifiNative {
/********************************************************
* Vendor HAL operations
********************************************************/
+ /**
+ * Callback to notify vendor HAL death.
+ */
+ public interface VendorHalDeathEventHandler {
+ /**
+ * Invoked when the vendor HAL dies.
+ */
+ void onDeath();
+ }
/**
* Initializes the vendor HAL. This is just used to initialize the {@link HalDeviceManager}.
*/
- public boolean initializeVendorHal() {
- return mWifiVendorHal.initialize();
+ public boolean initializeVendorHal(VendorHalDeathEventHandler handler) {
+ return mWifiVendorHal.initialize(handler);
}
/**
diff --git a/service/java/com/android/server/wifi/WifiServiceImpl.java b/service/java/com/android/server/wifi/WifiServiceImpl.java
index a95ddabc8..757be2dac 100644
--- a/service/java/com/android/server/wifi/WifiServiceImpl.java
+++ b/service/java/com/android/server/wifi/WifiServiceImpl.java
@@ -441,22 +441,6 @@ public class WifiServiceImpl extends IWifiManager.Stub {
}
/**
- * see {@link android.net.wifi.WifiManager#pingSupplicant()}
- * @return {@code true} if the operation succeeds, {@code false} otherwise
- */
- @Override
- public boolean pingSupplicant() {
- enforceAccessPermission();
- mLog.trace("pingSupplicant uid=%").c(Binder.getCallingUid()).flush();
- if (mWifiStateMachineChannel != null) {
- return mWifiStateMachine.syncPingSupplicant(mWifiStateMachineChannel);
- } else {
- Slog.e(TAG, "mWifiStateMachineChannel is not initialized");
- return false;
- }
- }
-
- /**
* see {@link android.net.wifi.WifiManager#startScan}
* and {@link android.net.wifi.WifiManager#startCustomizedScan}
*
diff --git a/service/java/com/android/server/wifi/WifiStateMachine.java b/service/java/com/android/server/wifi/WifiStateMachine.java
index 50c8f4ef8..d8971ae8b 100644
--- a/service/java/com/android/server/wifi/WifiStateMachine.java
+++ b/service/java/com/android/server/wifi/WifiStateMachine.java
@@ -241,6 +241,9 @@ public class WifiStateMachine extends StateMachine implements WifiNative.WifiRss
private boolean mIsLinkDebouncing = false;
private final StateMachineDeathRecipient mDeathRecipient =
new StateMachineDeathRecipient(this, CMD_CLIENT_INTERFACE_BINDER_DEATH);
+ private final WifiNative.VendorHalDeathEventHandler mVendorHalDeathRecipient = () -> {
+ sendMessage(CMD_VENDOR_HAL_HWBINDER_DEATH);
+ };
private boolean mIpReachabilityDisconnectEnabled = true;
@Override
@@ -483,8 +486,6 @@ public class WifiStateMachine extends StateMachine implements WifiNative.WifiRss
static final int CMD_BLUETOOTH_ADAPTER_STATE_CHANGE = BASE + 31;
/* Supplicant commands */
- /* Is supplicant alive ? */
- static final int CMD_PING_SUPPLICANT = BASE + 51;
/* Add/update a network configuration */
static final int CMD_ADD_OR_UPDATE_NETWORK = BASE + 52;
/* Delete a network */
@@ -700,8 +701,11 @@ public class WifiStateMachine extends StateMachine implements WifiNative.WifiRss
/* Signals that IClientInterface instance underpinning our state is dead. */
private static final int CMD_CLIENT_INTERFACE_BINDER_DEATH = BASE + 250;
+ /* Signals that the Vendor HAL instance underpinning our state is dead. */
+ private static final int CMD_VENDOR_HAL_HWBINDER_DEATH = BASE + 251;
+
/* Indicates that diagnostics should time out a connection start event. */
- private static final int CMD_DIAGS_CONNECT_TIMEOUT = BASE + 251;
+ private static final int CMD_DIAGS_CONNECT_TIMEOUT = BASE + 252;
// For message logging.
private static final Class[] sMessageClasses = {
@@ -1041,7 +1045,6 @@ public class WifiStateMachine extends StateMachine implements WifiNative.WifiRss
getHandler());
mWifiMonitor.registerHandler(mInterfaceName, WifiMonitor.AUTHENTICATION_FAILURE_EVENT,
getHandler());
- mWifiMonitor.registerHandler(mInterfaceName, WifiMonitor.DRIVER_HUNG_EVENT, getHandler());
mWifiMonitor.registerHandler(mInterfaceName, WifiMonitor.GAS_QUERY_DONE_EVENT, getHandler());
mWifiMonitor.registerHandler(mInterfaceName, WifiMonitor.GAS_QUERY_START_EVENT,
getHandler());
@@ -1055,8 +1058,6 @@ public class WifiStateMachine extends StateMachine implements WifiNative.WifiRss
getHandler());
mWifiMonitor.registerHandler(mInterfaceName, WifiMonitor.SCAN_FAILED_EVENT, getHandler());
mWifiMonitor.registerHandler(mInterfaceName, WifiMonitor.SCAN_RESULTS_EVENT, getHandler());
- mWifiMonitor.registerHandler(mInterfaceName, WifiMonitor.SSID_REENABLED, getHandler());
- mWifiMonitor.registerHandler(mInterfaceName, WifiMonitor.SSID_TEMP_DISABLED, getHandler());
mWifiMonitor.registerHandler(mInterfaceName, WifiMonitor.SUP_CONNECTION_EVENT, getHandler());
mWifiMonitor.registerHandler(mInterfaceName, WifiMonitor.SUP_DISCONNECTION_EVENT,
getHandler());
@@ -1258,8 +1259,15 @@ public class WifiStateMachine extends StateMachine implements WifiNative.WifiRss
/**
* Initiates connection to a network specified by the user/app. This method checks if the
* requesting app holds the WIFI_CONFIG_OVERRIDE permission.
+ *
+ * @param netId Id network to initiate connection.
+ * @param uid UID of the app requesting the connection.
+ * @param forceReconnect Whether to force a connection even if we're connected to the same
+ * network currently.
*/
- private boolean connectToUserSelectNetwork(int netId, int uid) {
+ private boolean connectToUserSelectNetwork(int netId, int uid, boolean forceReconnect) {
+ logd("connectToUserSelectNetwork netId " + netId + ", uid " + uid
+ + ", forceReconnect = " + forceReconnect);
if (mWifiConfigManager.getConfiguredNetwork(netId) == null) {
loge("connectToUserSelectNetwork Invalid network Id=" + netId);
return false;
@@ -1273,9 +1281,9 @@ public class WifiStateMachine extends StateMachine implements WifiNative.WifiRss
// selection.
mWifiConnectivityManager.setUserConnectChoice(netId);
}
- if (mWifiInfo.getNetworkId() == netId) {
+ if (!forceReconnect && mWifiInfo.getNetworkId() == netId) {
// We're already connected to the user specified network, don't trigger a
- // reconnection.
+ // reconnection unless it was forced.
logi("connectToUserSelectNetwork already connecting/connected=" + netId);
} else {
startConnectToNetwork(netId, SUPPLICANT_BSSID_ANY);
@@ -1294,16 +1302,6 @@ public class WifiStateMachine extends StateMachine implements WifiNative.WifiRss
}
/**
- * TODO: doc
- */
- public boolean syncPingSupplicant(AsyncChannel channel) {
- Message resultMsg = channel.sendMessageSynchronously(CMD_PING_SUPPLICANT);
- boolean result = (resultMsg.arg1 != FAILURE);
- resultMsg.recycle();
- return result;
- }
-
- /**
* Initiate a wifi scan. If workSource is not null, blame is given to it, otherwise blame is
* given to callingUid.
*
@@ -2394,40 +2392,6 @@ public class WifiStateMachine extends StateMachine implements WifiNative.WifiRss
sb.append(" debounce");
}
break;
- case WifiMonitor.SSID_TEMP_DISABLED:
- case WifiMonitor.SSID_REENABLED:
- sb.append(" nid=").append(msg.arg1);
- if (msg.obj != null) {
- sb.append(" ").append((String) msg.obj);
- }
- config = getCurrentWifiConfiguration();
- if (config != null) {
- WifiConfiguration.NetworkSelectionStatus netWorkSelectionStatus =
- config.getNetworkSelectionStatus();
- sb.append(" cur=").append(config.configKey());
- sb.append(" ajst=").append(netWorkSelectionStatus.getNetworkStatusString());
- if (config.selfAdded) {
- sb.append(" selfAdded");
- }
- if (config.status != 0) {
- sb.append(" st=").append(config.status);
- sb.append(" rs=").append(
- netWorkSelectionStatus.getNetworkDisableReasonString());
- }
- if (config.lastConnected != 0) {
- now = mClock.getWallClockMillis();
- sb.append(" lastconn=").append(now - config.lastConnected).append("(ms)");
- }
- if (mLastBssid != null) {
- sb.append(" lastbssid=").append(mLastBssid);
- }
- if (mWifiInfo.getFrequency() != -1) {
- sb.append(" freq=").append(mWifiInfo.getFrequency());
- sb.append(" rssi=").append(mWifiInfo.getRssi());
- sb.append(" bssid=").append(mWifiInfo.getBSSID());
- }
- }
- break;
case CMD_RSSI_POLL:
case CMD_UNWANTED_NETWORK:
case WifiManager.RSSI_PKTCNT_FETCH:
@@ -3701,8 +3665,6 @@ public class WifiStateMachine extends StateMachine implements WifiNative.WifiRss
mBluetoothConnectionActive = (message.arg1 !=
BluetoothAdapter.STATE_DISCONNECTED);
break;
- /* Synchronous call returns */
- case CMD_PING_SUPPLICANT:
case CMD_ENABLE_NETWORK:
case CMD_ADD_OR_UPDATE_NETWORK:
case CMD_SAVE_CONFIG:
@@ -3729,7 +3691,7 @@ public class WifiStateMachine extends StateMachine implements WifiNative.WifiRss
}
break;
case CMD_INITIALIZE:
- boolean ok = mWifiNative.initializeVendorHal();
+ boolean ok = mWifiNative.initializeVendorHal(mVendorHalDeathRecipient);
replyToMessage(message, message.what, ok ? SUCCESS : FAILURE);
break;
case CMD_BOOT_COMPLETED:
@@ -3799,10 +3761,6 @@ public class WifiStateMachine extends StateMachine implements WifiNative.WifiRss
setSuspendOptimizations(SUSPEND_DUE_TO_SCREEN, false);
}
break;
- case WifiMonitor.DRIVER_HUNG_EVENT:
- setSupplicantRunning(false);
- setSupplicantRunning(true);
- break;
case WifiManager.CONNECT_NETWORK:
replyToMessage(message, WifiManager.CONNECT_NETWORK_FAILED,
WifiManager.BUSY);
@@ -3943,9 +3901,13 @@ public class WifiStateMachine extends StateMachine implements WifiNative.WifiRss
}
break;
case CMD_CLIENT_INTERFACE_BINDER_DEATH:
- // We have lost contact with a client interface, which means that we cannot
- // trust that the driver is up or that the interface is ready. We are fit
- // for no WiFi related work.
+ Log.wtf(TAG, "wificond died unexpectedly");
+ // TODO(b/36586897): Automatically recover from this.
+ transitionTo(mInitialState);
+ break;
+ case CMD_VENDOR_HAL_HWBINDER_DEATH:
+ Log.wtf(TAG, "Vendor HAL died unexpectedly");
+ // TODO(b/36586897): Automatically recover from this.
transitionTo(mInitialState);
break;
case CMD_DIAGS_CONNECT_TIMEOUT:
@@ -4254,10 +4216,6 @@ public class WifiStateMachine extends StateMachine implements WifiNative.WifiRss
if (mBufferedScanMsg.size() > 0)
sendMessage(mBufferedScanMsg.remove());
break;
- case CMD_PING_SUPPLICANT:
- // TODO (b/35620640): Remove this command since the API is deprecated.
- replyToMessage(message, message.what, FAILURE);
- break;
case CMD_START_AP:
/* Cannot start soft AP while in client mode */
loge("Failed to start soft AP with a running supplicant");
@@ -4492,9 +4450,6 @@ public class WifiStateMachine extends StateMachine implements WifiNative.WifiRss
return s;
}
switch (what) {
- case WifiMonitor.DRIVER_HUNG_EVENT:
- s = "DRIVER_HUNG_EVENT";
- break;
case AsyncChannel.CMD_CHANNEL_HALF_CONNECTED:
s = "AsyncChannel.CMD_CHANNEL_HALF_CONNECTED";
break;
@@ -4534,12 +4489,6 @@ public class WifiStateMachine extends StateMachine implements WifiNative.WifiRss
case WifiMonitor.AUTHENTICATION_FAILURE_EVENT:
s = "AUTHENTICATION_FAILURE_EVENT";
break;
- case WifiMonitor.SSID_TEMP_DISABLED:
- s = "SSID_TEMP_DISABLED";
- break;
- case WifiMonitor.SSID_REENABLED:
- s = "SSID_REENABLED";
- break;
case WifiMonitor.WPS_SUCCESS_EVENT:
s = "WPS_SUCCESS_EVENT";
break;
@@ -4771,14 +4720,9 @@ public class WifiStateMachine extends StateMachine implements WifiNative.WifiRss
mWifiDiagnostics.captureBugReportData(
WifiDiagnostics.REPORT_REASON_AUTH_FAILURE);
mSupplicantStateTracker.sendMessage(WifiMonitor.AUTHENTICATION_FAILURE_EVENT);
- // In case of wrong password, rely on SSID_TEMP_DISABLE event to update
- // the WifiConfigManager
- if ((message.arg2 != WifiMonitor.AUTHENTICATION_FAILURE_REASON_WRONG_PSWD)
- && (mTargetNetworkId != WifiConfiguration.INVALID_NETWORK_ID)) {
- mWifiConfigManager.updateNetworkSelectionStatus(mTargetNetworkId,
- WifiConfiguration.NetworkSelectionStatus
- .DISABLED_AUTHENTICATION_FAILURE);
- }
+ mWifiConfigManager.updateNetworkSelectionStatus(mTargetNetworkId,
+ WifiConfiguration.NetworkSelectionStatus
+ .DISABLED_AUTHENTICATION_FAILURE);
//If failure occurred while Metrics is tracking a ConnnectionEvent, end it.
reportConnectionAttemptEnd(
WifiMetrics.ConnectionEvent.FAILURE_AUTHENTICATION_FAILURE,
@@ -4788,29 +4732,6 @@ public class WifiStateMachine extends StateMachine implements WifiNative.WifiRss
getTargetSsid(), mTargetRoamBSSID,
WifiLastResortWatchdog.FAILURE_CODE_AUTHENTICATION);
break;
- case WifiMonitor.SSID_TEMP_DISABLED:
- netId = lookupFrameworkNetworkId(message.arg1);
- Log.e(TAG, "Supplicant SSID temporary disabled:"
- + mWifiConfigManager.getConfiguredNetwork(netId));
- mWifiConfigManager.updateNetworkSelectionStatus(
- netId,
- WifiConfiguration.NetworkSelectionStatus
- .DISABLED_AUTHENTICATION_FAILURE);
- reportConnectionAttemptEnd(
- WifiMetrics.ConnectionEvent.FAILURE_SSID_TEMP_DISABLED,
- WifiMetricsProto.ConnectionEvent.HLF_NONE);
- mWifiInjector.getWifiLastResortWatchdog()
- .noteConnectionFailureAndTriggerIfNeeded(
- getTargetSsid(), mTargetRoamBSSID,
- WifiLastResortWatchdog.FAILURE_CODE_AUTHENTICATION);
- break;
- case WifiMonitor.SSID_REENABLED:
- netId = lookupFrameworkNetworkId(message.arg1);
- Log.d(TAG, "Supplicant SSID reenable:"
- + mWifiConfigManager.getConfiguredNetwork(netId));
- // Do not re-enable it in Quality Network Selection since framework has its own
- // Algorithm of disable/enable
- break;
case WifiMonitor.SUPPLICANT_STATE_CHANGE_EVENT:
SupplicantState state = handleSupplicantStateChange(message);
// A driver/firmware hang can now put the interface in a down state.
@@ -4884,7 +4805,7 @@ public class WifiStateMachine extends StateMachine implements WifiNative.WifiRss
if (disableOthers) {
// If the app has all the necessary permissions, this will trigger a connect
// attempt.
- ok = connectToUserSelectNetwork(netId, message.sendingUid);
+ ok = connectToUserSelectNetwork(netId, message.sendingUid, false);
} else {
ok = mWifiConfigManager.enableNetwork(netId, false, message.sendingUid);
}
@@ -5058,6 +4979,7 @@ public class WifiStateMachine extends StateMachine implements WifiNative.WifiRss
netId = message.arg1;
config = (WifiConfiguration) message.obj;
mWifiConnectionStatistics.numWifiManagerJoinAttempt++;
+ boolean hasCredentialChanged = false;
// New network addition.
if (config != null) {
result = mWifiConfigManager.addOrUpdateNetwork(config, message.sendingUid);
@@ -5069,8 +4991,10 @@ public class WifiStateMachine extends StateMachine implements WifiNative.WifiRss
break;
}
netId = result.getNetworkId();
+ hasCredentialChanged = result.hasCredentialChanged();
}
- if (!connectToUserSelectNetwork(netId, message.sendingUid)) {
+ if (!connectToUserSelectNetwork(
+ netId, message.sendingUid, hasCredentialChanged)) {
messageHandlingStatus = MESSAGE_HANDLING_STATUS_FAIL;
replyToMessage(message, WifiManager.CONNECT_NETWORK_FAILED,
WifiManager.NOT_AUTHORIZED);
@@ -5099,30 +5023,39 @@ public class WifiStateMachine extends StateMachine implements WifiNative.WifiRss
WifiManager.ERROR);
break;
}
- netId = result.getNetworkId();
- if (mWifiInfo.getNetworkId() == netId) {
- if (result.hasIpChanged()) {
- // The currently connection configuration was changed
- // We switched from DHCP to static or from static to DHCP, or the
- // static IP address has changed.
- log("Reconfiguring IP on connection");
- // TODO: clear addresses and disable IPv6
- // to simplify obtainingIpState.
- transitionTo(mObtainingIpState);
- }
- if (result.hasProxyChanged()) {
- log("Reconfiguring proxy on connection");
- mIpManager.setHttpProxy(
- getCurrentWifiConfiguration().getHttpProxy());
- }
- } else if (!mWifiConfigManager.enableNetwork(result.getNetworkId(),
- false, message.sendingUid)) {
- loge("ENABLE_NETWORK config=" + config + " failed");
+ if (!mWifiConfigManager.enableNetwork(
+ result.getNetworkId(), false, message.sendingUid)) {
+ loge("SAVE_NETWORK enabling config=" + config + " failed");
messageHandlingStatus = MESSAGE_HANDLING_STATUS_FAIL;
replyToMessage(message, WifiManager.SAVE_NETWORK_FAILED,
WifiManager.ERROR);
break;
}
+ netId = result.getNetworkId();
+ if (mWifiInfo.getNetworkId() == netId) {
+ if (result.hasCredentialChanged()) {
+ // The network credentials changed and we're connected to this network,
+ // start a new connection with the updated credentials.
+ logi("SAVE_NETWORK credential changed for config=" + config.configKey()
+ + ", Reconnecting.");
+ startConnectToNetwork(netId, SUPPLICANT_BSSID_ANY);
+ } else {
+ if (result.hasProxyChanged()) {
+ log("Reconfiguring proxy on connection");
+ mIpManager.setHttpProxy(
+ getCurrentWifiConfiguration().getHttpProxy());
+ }
+ if (result.hasIpChanged()) {
+ // The current connection configuration was changed
+ // We switched from DHCP to static or from static to DHCP, or the
+ // static IP address has changed.
+ log("Reconfiguring IP on connection");
+ // TODO(b/36576642): clear addresses and disable IPv6
+ // to simplify obtainingIpState.
+ transitionTo(mObtainingIpState);
+ }
+ }
+ }
broadcastWifiCredentialChanged(WifiManager.WIFI_CREDENTIAL_SAVED, config);
replyToMessage(message, WifiManager.SAVE_NETWORK_SUCCEEDED);
break;
@@ -6019,23 +5952,6 @@ public class WifiStateMachine extends StateMachine implements WifiNative.WifiRss
transitionTo(mDisconnectedState);
}
break;
- case WifiMonitor.SSID_TEMP_DISABLED:
- // Auth error while roaming
- int netId = lookupFrameworkNetworkId(message.arg1);
- logd("SSID_TEMP_DISABLED nid=" + Integer.toString(mLastNetworkId)
- + " id=" + netId
- + " isRoaming=" + isRoaming()
- + " roam=" + mAutoRoaming);
- if (netId == mLastNetworkId) {
- config = getCurrentWifiConfiguration();
- if (config != null) {
- mWifiDiagnostics.captureBugReportData(
- WifiDiagnostics.REPORT_REASON_AUTOROAM_FAILURE);
- }
- handleNetworkDisconnect();
- transitionTo(mDisconnectingState);
- }
- return NOT_HANDLED;
case CMD_START_SCAN:
deferMessage(message);
break;
diff --git a/service/java/com/android/server/wifi/WifiVendorHal.java b/service/java/com/android/server/wifi/WifiVendorHal.java
index 36e1f3aec..8646b613b 100644
--- a/service/java/com/android/server/wifi/WifiVendorHal.java
+++ b/service/java/com/android/server/wifi/WifiVendorHal.java
@@ -65,6 +65,7 @@ import android.net.wifi.WifiScanner;
import android.net.wifi.WifiSsid;
import android.net.wifi.WifiWakeReasonAndCounts;
import android.os.HandlerThread;
+import android.os.Looper;
import android.os.RemoteException;
import android.util.MutableBoolean;
import android.util.MutableInt;
@@ -204,14 +205,14 @@ public class WifiVendorHal {
private IWifiRttController mIWifiRttController;
private final HalDeviceManager mHalDeviceManager;
private final HalDeviceManagerStatusListener mHalDeviceManagerStatusCallbacks;
- private final HandlerThread mWifiStateMachineHandlerThread;
+ private final Looper mLooper;
private final IWifiStaIfaceEventCallback mIWifiStaIfaceEventCallback;
private final IWifiChipEventCallback mIWifiChipEventCallback;
public WifiVendorHal(HalDeviceManager halDeviceManager,
- HandlerThread wifiStateMachineHandlerThread) {
+ Looper looper) {
mHalDeviceManager = halDeviceManager;
- mWifiStateMachineHandlerThread = wifiStateMachineHandlerThread;
+ mLooper = looper;
mHalDeviceManagerStatusCallbacks = new HalDeviceManagerStatusListener();
mIWifiStaIfaceEventCallback = new StaIfaceEventCallback();
mIWifiChipEventCallback = new ChipEventCallback();
@@ -226,16 +227,21 @@ public class WifiVendorHal {
clearState();
}
+ private WifiNative.VendorHalDeathEventHandler mDeathEventHandler;
+
/**
* Initialize the Hal device manager and register for status callbacks.
*
- * @return
+ * @param handler Handler to notify if the vendor HAL dies.
+ * @return true on success, false otherwise.
*/
- public boolean initialize() {
- mHalDeviceManager.initialize();
- mHalDeviceManager.registerStatusListener(
- mHalDeviceManagerStatusCallbacks, mWifiStateMachineHandlerThread.getLooper());
- return true;
+ public boolean initialize(WifiNative.VendorHalDeathEventHandler handler) {
+ synchronized (sLock) {
+ mHalDeviceManager.initialize();
+ mHalDeviceManager.registerStatusListener(mHalDeviceManagerStatusCallbacks, mLooper);
+ mDeathEventHandler = handler;
+ return true;
+ }
}
/**
@@ -1183,11 +1189,14 @@ public class WifiVendorHal {
static ArrayList<RttConfig> halRttConfigArrayFromFrameworkRttParamsArray(
RttManager.RttParams[] params) {
final int length = params.length;
- ArrayList<RttConfig> config = new ArrayList<RttConfig>(length);
+ ArrayList<RttConfig> configs = new ArrayList<RttConfig>(length);
for (int i = 0; i < length; i++) {
- config.add(halRttConfigFromFrameworkRttParams(params[i]));
+ RttConfig config = halRttConfigFromFrameworkRttParams(params[i]);
+ if (config != null) {
+ configs.add(config);
+ }
}
- return config;
+ return configs;
}
/**
@@ -1198,7 +1207,13 @@ public class WifiVendorHal {
* @return success indication
*/
public boolean requestRtt(RttManager.RttParams[] params, WifiNative.RttEventHandler handler) {
- ArrayList<RttConfig> rttConfigs = halRttConfigArrayFromFrameworkRttParamsArray(params);
+ ArrayList<RttConfig> rttConfigs;
+ try {
+ rttConfigs = halRttConfigArrayFromFrameworkRttParamsArray(params);
+ } catch (IllegalArgumentException e) {
+ mLog.err("Illegal argument for RTT request").c(e.toString()).flush();
+ return false;
+ }
synchronized (sLock) {
if (mIWifiRttController == null) return boolResult(false);
if (mRttCmdId != 0) return boolResult(false);
@@ -1533,7 +1548,7 @@ public class WifiVendorHal {
}
}
- private WifiNative.WifiLoggerEventHandler mVerboseLogEventHandler = null;
+ private WifiNative.WifiLoggerEventHandler mLogEventHandler = null;
/**
* Registers the logger callback and enables alerts.
@@ -1543,11 +1558,11 @@ public class WifiVendorHal {
if (handler == null) return boolResult(false);
synchronized (sLock) {
if (mIWifiChip == null) return boolResult(false);
- if (mVerboseLogEventHandler != null) return boolResult(false);
+ if (mLogEventHandler != null) return boolResult(false);
try {
WifiStatus status = mIWifiChip.enableDebugErrorAlerts(true);
if (!ok(status)) return false;
- mVerboseLogEventHandler = handler;
+ mLogEventHandler = handler;
return true;
} catch (RemoteException e) {
handleRemoteException(e);
@@ -1563,13 +1578,13 @@ public class WifiVendorHal {
public boolean resetLogHandler() {
synchronized (sLock) {
if (mIWifiChip == null) return boolResult(false);
- if (mVerboseLogEventHandler == null) return boolResult(false);
+ if (mLogEventHandler == null) return boolResult(false);
try {
WifiStatus status = mIWifiChip.enableDebugErrorAlerts(false);
if (!ok(status)) return false;
status = mIWifiChip.stopLoggingToDebugRingBuffer();
if (!ok(status)) return false;
- mVerboseLogEventHandler = null;
+ mLogEventHandler = null;
return true;
} catch (RemoteException e) {
handleRemoteException(e);
@@ -2280,6 +2295,9 @@ public class WifiVendorHal {
} catch (RemoteException e) {
handleRemoteException(e);
return false;
+ } catch (IllegalArgumentException e) {
+ mLog.err("Illegal argument for roaming configuration").c(e.toString()).flush();
+ return false;
}
return true;
}
@@ -2432,8 +2450,8 @@ public class WifiVendorHal {
// mVerboseLog.d("onDebugRingBufferDataAvailable " + status);
WifiNative.WifiLoggerEventHandler eventHandler;
synchronized (sLock) {
- if (mVerboseLogEventHandler == null || status == null || data == null) return;
- eventHandler = mVerboseLogEventHandler;
+ if (mLogEventHandler == null || status == null || data == null) return;
+ eventHandler = mLogEventHandler;
}
eventHandler.onRingBufferData(
ringBufferStatus(status), NativeUtil.byteArrayFromArrayList(data));
@@ -2444,8 +2462,8 @@ public class WifiVendorHal {
mVerboseLog.d("onDebugErrorAlert " + errorCode);
WifiNative.WifiLoggerEventHandler eventHandler;
synchronized (sLock) {
- if (mVerboseLogEventHandler == null || debugData == null) return;
- eventHandler = mVerboseLogEventHandler;
+ if (mLogEventHandler == null || debugData == null) return;
+ eventHandler = mLogEventHandler;
}
eventHandler.onWifiAlert(
errorCode, NativeUtil.byteArrayFromArrayList(debugData));
@@ -2465,8 +2483,13 @@ public class WifiVendorHal {
+ ", isStarted(): " + isStarted);
if (!isReady) {
// Probably something unpleasant, e.g. the server died
+ WifiNative.VendorHalDeathEventHandler handler;
synchronized (sLock) {
clearState();
+ handler = mDeathEventHandler;
+ }
+ if (handler != null) {
+ handler.onDeath();
}
}
}
diff --git a/service/java/com/android/server/wifi/p2p/SupplicantP2pIfaceHal.java b/service/java/com/android/server/wifi/p2p/SupplicantP2pIfaceHal.java
index 117dff6c0..fc63894b8 100644
--- a/service/java/com/android/server/wifi/p2p/SupplicantP2pIfaceHal.java
+++ b/service/java/com/android/server/wifi/p2p/SupplicantP2pIfaceHal.java
@@ -601,7 +601,7 @@ public class SupplicantP2pIfaceHal {
} catch (RemoteException e) {
Log.e(TAG, "ISupplicantP2pIface exception: " + e);
supplicantServiceDiedHandler();
- } catch (Exception e) {
+ } catch (IllegalArgumentException e) {
Log.e(TAG, "Could not decode SSID.", e);
return false;
}
@@ -1868,31 +1868,36 @@ public class SupplicantP2pIfaceHal {
* @return true if request is sent successfully, false otherwise.
*/
public boolean setWpsDeviceType(String typeStr) {
- Matcher match = WPS_DEVICE_TYPE_PATTERN.matcher(typeStr);
- if (!match.find() || match.groupCount() != 3) {
- Log.e(TAG, "Malformed WPS device type " + typeStr);
- return false;
- }
- short categ = Short.parseShort(match.group(1));
- byte[] oui = NativeUtil.hexStringToByteArray(match.group(2));
- short subCateg = Short.parseShort(match.group(3));
+ try {
+ Matcher match = WPS_DEVICE_TYPE_PATTERN.matcher(typeStr);
+ if (!match.find() || match.groupCount() != 3) {
+ Log.e(TAG, "Malformed WPS device type " + typeStr);
+ return false;
+ }
+ short categ = Short.parseShort(match.group(1));
+ byte[] oui = NativeUtil.hexStringToByteArray(match.group(2));
+ short subCateg = Short.parseShort(match.group(3));
- byte[] bytes = new byte[8];
- ByteBuffer byteBuffer = ByteBuffer.wrap(bytes).order(ByteOrder.BIG_ENDIAN);
- byteBuffer.putShort(categ);
- byteBuffer.put(oui);
- byteBuffer.putShort(subCateg);
- synchronized (mLock) {
- if (!checkSupplicantP2pIfaceAndLogFailure("setWpsDeviceType")) return false;
- SupplicantResult<Void> result = new SupplicantResult(
- "setWpsDeviceType(" + typeStr + ")");
- try {
- result.setResult(mISupplicantP2pIface.setWpsDeviceType(bytes));
- } catch (RemoteException e) {
- Log.e(TAG, "ISupplicantP2pIface exception: " + e);
- supplicantServiceDiedHandler();
+ byte[] bytes = new byte[8];
+ ByteBuffer byteBuffer = ByteBuffer.wrap(bytes).order(ByteOrder.BIG_ENDIAN);
+ byteBuffer.putShort(categ);
+ byteBuffer.put(oui);
+ byteBuffer.putShort(subCateg);
+ synchronized (mLock) {
+ if (!checkSupplicantP2pIfaceAndLogFailure("setWpsDeviceType")) return false;
+ SupplicantResult<Void> result = new SupplicantResult(
+ "setWpsDeviceType(" + typeStr + ")");
+ try {
+ result.setResult(mISupplicantP2pIface.setWpsDeviceType(bytes));
+ } catch (RemoteException e) {
+ Log.e(TAG, "ISupplicantP2pIface exception: " + e);
+ supplicantServiceDiedHandler();
+ }
+ return result.isSuccess();
}
- return result.isSuccess();
+ } catch (IllegalArgumentException e) {
+ Log.e(TAG, "Illegal argument " + typeStr, e);
+ return false;
}
}
@@ -1996,6 +2001,9 @@ public class SupplicantP2pIfaceHal {
} catch (RemoteException e) {
Log.e(TAG, "ISupplicantP2pIface exception: " + e);
supplicantServiceDiedHandler();
+ } catch (IllegalArgumentException e) {
+ Log.e(TAG, "Illegal argument " + selectMessage, e);
+ return false;
}
return result.isSuccess();
}
@@ -2019,6 +2027,9 @@ public class SupplicantP2pIfaceHal {
} catch (RemoteException e) {
Log.e(TAG, "ISupplicantP2pIface exception: " + e);
supplicantServiceDiedHandler();
+ } catch (IllegalArgumentException e) {
+ Log.e(TAG, "Illegal argument " + requestMessage, e);
+ return false;
}
return result.isSuccess();
}
@@ -2045,15 +2056,18 @@ public class SupplicantP2pIfaceHal {
}
SupplicantResult<Void> result = new SupplicantResult(
"setClientList(" + networkId + ", " + clientListStr + ")");
- ArrayList<byte[]> clients = new ArrayList<>();
- for (String clientStr : Arrays.asList(clientListStr.split("\\s+"))) {
- clients.add(NativeUtil.macAddressToByteArray(clientStr));
- }
try {
+ ArrayList<byte[]> clients = new ArrayList<>();
+ for (String clientStr : Arrays.asList(clientListStr.split("\\s+"))) {
+ clients.add(NativeUtil.macAddressToByteArray(clientStr));
+ }
result.setResult(network.setClientList(clients));
} catch (RemoteException e) {
Log.e(TAG, "ISupplicantP2pIface exception: " + e);
supplicantServiceDiedHandler();
+ } catch (IllegalArgumentException e) {
+ Log.e(TAG, "Illegal argument " + clientListStr, e);
+ return false;
}
return result.isSuccess();
}
diff --git a/tests/wifitests/src/com/android/server/wifi/SupplicantStaIfaceHalTest.java b/tests/wifitests/src/com/android/server/wifi/SupplicantStaIfaceHalTest.java
index abf533d1f..f2cb90e63 100644
--- a/tests/wifitests/src/com/android/server/wifi/SupplicantStaIfaceHalTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/SupplicantStaIfaceHalTest.java
@@ -501,6 +501,24 @@ public class SupplicantStaIfaceHalTest {
}
/**
+ * Tests connection to a specified network failure due to exception in network save.
+ */
+ @Test
+ public void testConnectFailureDueToNetworkSaveException() throws Exception {
+ executeAndValidateInitializationSequence();
+ setupMocksForConnectSequence(true);
+
+ doThrow(new IllegalArgumentException("Some error!!!"))
+ .when(mSupplicantStaNetworkMock).saveWifiConfiguration(
+ any(WifiConfiguration.class));
+
+ assertFalse(mDut.connectToNetwork(new WifiConfiguration(), false));
+ // We should have removed the existing network once before connection and once more
+ // on failure to save network configuration.
+ verify(mISupplicantStaIfaceMock, times(2)).removeNetwork(anyInt());
+ }
+
+ /**
* Tests connection to a specified network failure due to network select.
*/
@Test
@@ -1148,12 +1166,12 @@ public class SupplicantStaIfaceHalTest {
.thenReturn(mStatusSuccess);
// Fail before initialization is performed.
- assertFalse(mDut.setLogLevel(SupplicantStaIfaceHal.LOG_LEVEL_DEBUG));
+ assertFalse(mDut.setLogLevel(true));
executeAndValidateInitializationSequence();
// This should work.
- assertTrue(mDut.setLogLevel(SupplicantStaIfaceHal.LOG_LEVEL_DEBUG));
+ assertTrue(mDut.setLogLevel(true));
verify(mISupplicantMock)
.setDebugParams(eq(ISupplicant.DebugLevel.DEBUG), eq(false), eq(false));
}
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java b/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java
index 615f61190..951f8e114 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java
@@ -1325,6 +1325,7 @@ public class WifiConfigManagerTest {
mWifiConfigManager.getConfiguredNetwork(result.getNetworkId());
assertTrue("Updating network non-credentials config should not clear hasEverConnected.",
retrievedNetwork.getNetworkSelectionStatus().getHasEverConnected());
+ assertFalse(result.hasCredentialChanged());
}
/**
@@ -3790,6 +3791,7 @@ public class WifiConfigManagerTest {
mWifiConfigManager.getConfiguredNetwork(result.getNetworkId());
assertFalse("Updating network credentials config should clear hasEverConnected.",
retrievedNetwork.getNetworkSelectionStatus().getHasEverConnected());
+ assertTrue(result.hasCredentialChanged());
}
/**
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java b/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java
index cc8535318..ad441f54d 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java
@@ -1383,6 +1383,35 @@ public class WifiStateMachineTest {
assertFalse("WpsRunningState".equals(getCurrentState().getName()));
}
+ @Test
+ public void handleVendorHalDeath() throws Exception {
+ ArgumentCaptor<WifiNative.VendorHalDeathEventHandler> deathHandlerCapturer =
+ ArgumentCaptor.forClass(WifiNative.VendorHalDeathEventHandler.class);
+ when(mWifiNative.initializeVendorHal(deathHandlerCapturer.capture())).thenReturn(true);
+
+ // Trigger initialize to capture the death handler registration.
+ mLooper.startAutoDispatch();
+ assertTrue(mWsm.syncInitialize(mWsmAsyncChannel));
+ mLooper.stopAutoDispatch();
+
+ verify(mWifiNative).initializeVendorHal(any(WifiNative.VendorHalDeathEventHandler.class));
+ WifiNative.VendorHalDeathEventHandler deathHandler = deathHandlerCapturer.getValue();
+
+ mWsm.setOperationalMode(WifiStateMachine.CONNECT_MODE);
+ mLooper.dispatchAll();
+
+ // We should not be in initial state now.
+ assertFalse("InitialState".equals(getCurrentState().getName()));
+
+ // Now trigger the death notification.
+ mLooper.startAutoDispatch();
+ deathHandler.onDeath();
+ mLooper.stopAutoDispatch();
+
+ // We should back to initial state after vendor HAL death.
+ assertTrue("InitialState".equals(getCurrentState().getName()));
+ }
+
private void setupMocksForWpsNetworkMigration() {
int newNetworkId = 5;
// Now trigger the network connection event for adding the WPS network.
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiVendorHalTest.java b/tests/wifitests/src/com/android/server/wifi/WifiVendorHalTest.java
index 36fe7d2df..4e5594bcc 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiVendorHalTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiVendorHalTest.java
@@ -55,7 +55,7 @@ import android.net.wifi.WifiManager;
import android.net.wifi.WifiScanner;
import android.net.wifi.WifiSsid;
import android.net.wifi.WifiWakeReasonAndCounts;
-import android.os.HandlerThread;
+import android.os.test.TestLooper;
import android.os.RemoteException;
import android.util.Pair;
@@ -90,7 +90,7 @@ public class WifiVendorHalTest {
@Mock
private HalDeviceManager mHalDeviceManager;
@Mock
- private HandlerThread mWifiStateMachineHandlerThread;
+ private TestLooper mLooper;
@Mock
private WifiVendorHal.HalDeviceManagerStatusListener mHalDeviceManagerStatusCallbacks;
@Mock
@@ -103,6 +103,8 @@ public class WifiVendorHalTest {
private IWifiRttController mIWifiRttController;
private IWifiStaIfaceEventCallback mIWifiStaIfaceEventCallback;
private IWifiChipEventCallback mIWifiChipEventCallback;
+ @Mock
+ private WifiNative.VendorHalDeathEventHandler mVendorHalDeathHandler;
/**
* Identity function to supply a type to its argument, which is a lambda
@@ -118,6 +120,7 @@ public class WifiVendorHalTest {
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
mWifiLog = new FakeWifiLog();
+ mLooper = new TestLooper();
mWifiStatusSuccess = new WifiStatus();
mWifiStatusSuccess.code = WifiStatusCode.SUCCESS;
mWifiStatusFailure = new WifiStatus();
@@ -169,10 +172,10 @@ public class WifiVendorHalTest {
}));
// Create the vendor HAL object under test.
- mWifiVendorHal = new WifiVendorHal(mHalDeviceManager, mWifiStateMachineHandlerThread);
+ mWifiVendorHal = new WifiVendorHal(mHalDeviceManager, mLooper.getLooper());
// Initialize the vendor HAL to capture the registered callback.
- mWifiVendorHal.initialize();
+ mWifiVendorHal.initialize(mVendorHalDeathHandler);
ArgumentCaptor<WifiVendorHal.HalDeviceManagerStatusListener> hdmCallbackCaptor =
ArgumentCaptor.forClass(WifiVendorHal.HalDeviceManagerStatusListener.class);
verify(mHalDeviceManager).registerStatusListener(hdmCallbackCaptor.capture(), any());
@@ -1729,6 +1732,19 @@ public class WifiVendorHalTest {
new WifiDebugRingBufferStatus(), NativeUtil.byteArrayToArrayList(errorData));
}
+ /**
+ * Test the handling of Vendor HAL death.
+ */
+ @Test
+ public void testVendorHalDeath() {
+ // Invoke the HAL device manager status callback with ready set to false to indicate the
+ // death of the HAL.
+ when(mHalDeviceManager.isReady()).thenReturn(false);
+ mHalDeviceManagerStatusCallbacks.onStatusChanged();
+
+ verify(mVendorHalDeathHandler).onDeath();
+ }
+
private void startBgScan(WifiNative.ScanEventHandler eventHandler) throws Exception {
when(mIWifiStaIface.startBackgroundScan(
anyInt(), any(StaBackgroundScanParameters.class))).thenReturn(mWifiStatusSuccess);