summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoshan Pius <rpius@google.com>2017-02-17 21:03:40 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2017-02-17 21:03:41 +0000
commit2e6fd575d84c12ba27e8dec50eeafd11585699fd (patch)
tree88c9403b8048ddd7537fd7a504c6864c5411b3b1
parentfc83b303a3382329c28d631b1e0fb2bb35969f85 (diff)
parentc224fb554deca894818490c9416ff35d18a79d76 (diff)
Merge changes Ie6ba8410,Ifd3374ef,I7cc92129
* changes: SupplicantStaIfaceHal: Register for callbacks SupplicantStaNetworkHal: Handle callbacks SupplicantStaIface/Network: Store the iface name
-rw-r--r--service/java/com/android/server/wifi/SupplicantStaIfaceHal.java122
-rw-r--r--service/java/com/android/server/wifi/SupplicantStaNetworkHal.java99
-rw-r--r--tests/wifitests/src/com/android/server/wifi/SupplicantStaIfaceHalTest.java99
-rw-r--r--tests/wifitests/src/com/android/server/wifi/SupplicantStaNetworkHalTest.java150
4 files changed, 359 insertions, 111 deletions
diff --git a/service/java/com/android/server/wifi/SupplicantStaIfaceHal.java b/service/java/com/android/server/wifi/SupplicantStaIfaceHal.java
index a86341b76..3ac60b452 100644
--- a/service/java/com/android/server/wifi/SupplicantStaIfaceHal.java
+++ b/service/java/com/android/server/wifi/SupplicantStaIfaceHal.java
@@ -20,6 +20,7 @@ import android.hardware.wifi.supplicant.V1_0.ISupplicant;
import android.hardware.wifi.supplicant.V1_0.ISupplicantIface;
import android.hardware.wifi.supplicant.V1_0.ISupplicantNetwork;
import android.hardware.wifi.supplicant.V1_0.ISupplicantStaIface;
+import android.hardware.wifi.supplicant.V1_0.ISupplicantStaIfaceCallback;
import android.hardware.wifi.supplicant.V1_0.ISupplicantStaNetwork;
import android.hardware.wifi.supplicant.V1_0.IfaceType;
import android.hardware.wifi.supplicant.V1_0.SupplicantStatus;
@@ -63,6 +64,7 @@ public class SupplicantStaIfaceHal {
// Supplicant HAL interface objects
private ISupplicant mISupplicant;
private ISupplicantStaIface mISupplicantStaIface;
+ private String mIfaceName;
// Currently configured network in wpa_supplicant
private SupplicantStaNetworkHal mCurrentNetwork;
// Currently configured network's framework network Id.
@@ -181,6 +183,7 @@ public class SupplicantStaIfaceHal {
return false;
}
Mutable<ISupplicantIface> supplicantIface = new Mutable<>();
+ Mutable<String> ifaceName = new Mutable<>();
for (ISupplicant.IfaceInfo ifaceInfo : supplicantIfaces) {
if (ifaceInfo.type == IfaceType.STA) {
try {
@@ -196,6 +199,7 @@ public class SupplicantStaIfaceHal {
Log.e(TAG, "ISupplicant.getInterface exception: " + e);
return false;
}
+ ifaceName.value = ifaceInfo.name;
break;
}
}
@@ -204,6 +208,10 @@ public class SupplicantStaIfaceHal {
return false;
}
mISupplicantStaIface = getStaIfaceMockable(supplicantIface.value);
+ mIfaceName = ifaceName.value;
+ if (!registerCallback(new SupplicantStaIfaceHalCallback())) {
+ return false;
+ }
return true;
}
}
@@ -419,32 +427,6 @@ public class SupplicantStaIfaceHal {
}
/**
- * Gets the interface name.
- *
- * @return returns the name of Iface or null if the call fails
- */
- private String getName() {
- synchronized (mLock) {
- final String methodStr = "getName";
- if (DBG) Log.i(TAG, methodStr);
- if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return null;
- final Mutable<String> gotName = new Mutable<>();
- try {
- mISupplicantStaIface.getName((SupplicantStatus status, String name) -> {
- if (checkStatusAndLogFailure(status, methodStr)) {
- gotName.value = name;
-
- }
- });
- } catch (RemoteException e) {
- Log.e(TAG, "ISupplicantStaIface." + methodStr + ": exception: " + e);
- supplicantServiceDiedHandler();
- }
- return gotName.value;
- }
- }
-
- /**
* Adds a new network.
*
* @return The ISupplicantNetwork object for the new network, or null if the call fails
@@ -505,7 +487,8 @@ public class SupplicantStaIfaceHal {
*/
protected SupplicantStaNetworkHal getStaNetworkMockable(
ISupplicantStaNetwork iSupplicantStaNetwork) {
- return new SupplicantStaNetworkHal(iSupplicantStaNetwork, mContext, mWifiMonitor);
+ return new SupplicantStaNetworkHal(
+ iSupplicantStaNetwork, mIfaceName, mContext, mWifiMonitor);
}
/**
@@ -538,6 +521,21 @@ public class SupplicantStaIfaceHal {
}
}
+ /** See ISupplicantStaNetwork.hal for documentation */
+ private boolean registerCallback(ISupplicantStaIfaceCallback callback) {
+ synchronized (mLock) {
+ final String methodStr = "registerCallback";
+ if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
+ try {
+ SupplicantStatus status = mISupplicantStaIface.registerCallback(callback);
+ return checkStatusAndLogFailure(status, methodStr);
+ } catch (RemoteException e) {
+ supplicantServiceDiedHandler();
+ return false;
+ }
+ }
+ }
+
/**
* @return a list of SupplicantNetworkID ints for all networks controlled by supplicant, returns
* null if the call fails
@@ -1523,6 +1521,76 @@ public class SupplicantStaIfaceHal {
}
}
+ private class SupplicantStaIfaceHalCallback extends ISupplicantStaIfaceCallback.Stub {
+ @Override
+ public void onNetworkAdded(int id) {
+ }
+
+ @Override
+ public void onNetworkRemoved(int id) {
+ }
+
+ @Override
+ public void onStateChanged(int newState, byte[/* 6 */] bssid, int id,
+ ArrayList<Byte> ssid) {
+ }
+
+ @Override
+ public void onAnqpQueryDone(byte[/* 6 */] macAddress,
+ ISupplicantStaIfaceCallback.AnqpData data,
+ ISupplicantStaIfaceCallback.Hs20AnqpData hs20Data) {
+ }
+
+ @Override
+ public void onHs20IconQueryDone(byte[/* 6 */] macAddress, String fileName,
+ ArrayList<Byte> data) {
+ }
+
+ @Override
+ public void onHs20SubscriptionRemediation(byte osuMethod, String url) {
+ }
+
+ @Override
+ public void onHs20DeauthImminentNotice(int reasonCode, int reAuthDelayInSec, String url) {
+ }
+
+ @Override
+ public void onDisconnected(byte[/* 6 */] bssid, boolean locallyGenerated, int reasonCode) {
+ }
+
+ @Override
+ public void onAssociationRejected(byte[/* 6 */] bssid, int statusCode) {
+ }
+
+ @Override
+ public void onAuthenticationTimeout(byte[/* 6 */] bssid) {
+ }
+
+ @Override
+ public void onEapFailure() {
+ }
+
+ @Override
+ public void onWpsEventSuccess() {
+ }
+
+ @Override
+ public void onWpsEventFail(byte[/* 6 */] bssid, short configError, short errorInd) {
+ }
+
+ @Override
+ public void onWpsEventPbcOverlap() {
+ }
+
+ @Override
+ public void onExtRadioWorkStart(int id) {
+ }
+
+ @Override
+ public void onExtRadioWorkTimeout(int id) {
+ }
+ }
+
private void logd(String s) {
Log.d(TAG, s);
}
diff --git a/service/java/com/android/server/wifi/SupplicantStaNetworkHal.java b/service/java/com/android/server/wifi/SupplicantStaNetworkHal.java
index 6f3aac2b2..a41f1f5f3 100644
--- a/service/java/com/android/server/wifi/SupplicantStaNetworkHal.java
+++ b/service/java/com/android/server/wifi/SupplicantStaNetworkHal.java
@@ -76,14 +76,15 @@ public class SupplicantStaNetworkHal {
Pattern.compile("^:([0-9a-fA-F]+)$");
private final Object mLock = new Object();
- private ISupplicantStaNetwork mISupplicantStaNetwork = null;
+ private final String mIfaceName;
private final WifiMonitor mWifiMonitor;
+ private ISupplicantStaNetwork mISupplicantStaNetwork;
+
// Indicates whether the system is capable of 802.11r fast BSS transition.
private boolean mSystemSupportsFastBssTransition = false;
// Network variables read from wpa_supplicant.
private int mNetworkId;
- private String mIfaceName;
private ArrayList<Byte> mSsid;
private byte[/* 6 */] mBssid;
private boolean mScanSsid;
@@ -112,9 +113,10 @@ public class SupplicantStaNetworkHal {
private String mEapEngineID;
private String mEapDomainSuffixMatch;
- SupplicantStaNetworkHal(ISupplicantStaNetwork iSupplicantStaNetwork,
+ SupplicantStaNetworkHal(ISupplicantStaNetwork iSupplicantStaNetwork, String ifaceName,
Context context, WifiMonitor monitor) {
mISupplicantStaNetwork = iSupplicantStaNetwork;
+ mIfaceName = ifaceName;
mWifiMonitor = monitor;
mSystemSupportsFastBssTransition =
context.getResources().getBoolean(R.bool.config_wifi_fast_bss_transition_enabled);
@@ -329,12 +331,19 @@ public class SupplicantStaNetworkHal {
return false;
}
// Finish here if no EAP config to set
- if (config.enterpriseConfig == null
- || config.enterpriseConfig.getEapMethod() == WifiEnterpriseConfig.Eap.NONE) {
- return true;
- } else {
- return saveWifiEnterpriseConfig(config.SSID, config.enterpriseConfig);
+ if (config.enterpriseConfig != null
+ && config.enterpriseConfig.getEapMethod() != WifiEnterpriseConfig.Eap.NONE) {
+ if (!saveWifiEnterpriseConfig(config.SSID, config.enterpriseConfig)) {
+ return false;
+ }
}
+
+ // Now that the network is configured fully, start listening for callback events.
+ if (!registerCallback(new SupplicantStaNetworkHalCallback(config.networkId, config.SSID))) {
+ Log.e(TAG, "Failed to register callback");
+ return false;
+ }
+ return true;
}
/**
@@ -904,30 +913,6 @@ public class SupplicantStaNetworkHal {
}
}
- /** See ISupplicantNetwork.hal for documentation */
- private boolean getInterfaceName() {
- synchronized (mLock) {
- final String methodStr = "getInterfaceName";
- if (!checkISupplicantStaNetworkAndLogFailure(methodStr)) return false;
- try {
- MutableBoolean statusOk = new MutableBoolean(false);
- mISupplicantStaNetwork.getInterfaceName((SupplicantStatus status,
- String nameValue) -> {
- statusOk.value = status.code == SupplicantStatusCode.SUCCESS;
- if (statusOk.value) {
- this.mIfaceName = nameValue;
- } else {
- logFailureStatus(status, methodStr);
- }
- });
- return statusOk.value;
- } catch (RemoteException e) {
- handleRemoteException(e, methodStr);
- return false;
- }
- }
- }
-
/** See ISupplicantStaNetwork.hal for documentation */
private boolean registerCallback(ISupplicantStaNetworkCallback callback) {
synchronized (mLock) {
@@ -2326,4 +2311,54 @@ public class SupplicantStaNetworkHal {
this.value = value;
}
}
+
+ private class SupplicantStaNetworkHalCallback extends ISupplicantStaNetworkCallback.Stub {
+ /**
+ * Current configured network's framework network id.
+ */
+ private final int mFramewokNetworkId;
+ /**
+ * Current configured network's ssid.
+ */
+ private final String mSsid;
+
+ SupplicantStaNetworkHalCallback(int framewokNetworkId, String ssid) {
+ mFramewokNetworkId = framewokNetworkId;
+ mSsid = ssid;
+ }
+
+ @Override
+ public void onNetworkEapSimGsmAuthRequest(
+ ISupplicantStaNetworkCallback.NetworkRequestEapSimGsmAuthParams params) {
+ synchronized (mLock) {
+ String[] data = new String[params.rands.size()];
+ int i = 0;
+ for (byte[] rand : params.rands) {
+ data[i++] = NativeUtil.hexStringFromByteArray(rand);
+ }
+ mWifiMonitor.broadcastNetworkGsmAuthRequestEvent(
+ mIfaceName, mFramewokNetworkId, mSsid, data);
+ }
+ }
+
+ @Override
+ public void onNetworkEapSimUmtsAuthRequest(
+ ISupplicantStaNetworkCallback.NetworkRequestEapSimUmtsAuthParams params) {
+ synchronized (mLock) {
+ String autnHex = NativeUtil.hexStringFromByteArray(params.autn);
+ String randHex = NativeUtil.hexStringFromByteArray(params.rand);
+ String[] data = {autnHex, randHex};
+ mWifiMonitor.broadcastNetworkUmtsAuthRequestEvent(
+ mIfaceName, mFramewokNetworkId, mSsid, data);
+ }
+ }
+
+ @Override
+ public void onNetworkEapIdentityRequest() {
+ synchronized (mLock) {
+ mWifiMonitor.broadcastNetworkIdentityRequestEvent(
+ mIfaceName, mFramewokNetworkId, mSsid);
+ }
+ }
+ }
}
diff --git a/tests/wifitests/src/com/android/server/wifi/SupplicantStaIfaceHalTest.java b/tests/wifitests/src/com/android/server/wifi/SupplicantStaIfaceHalTest.java
index fb583ca1b..a8c9d3409 100644
--- a/tests/wifitests/src/com/android/server/wifi/SupplicantStaIfaceHalTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/SupplicantStaIfaceHalTest.java
@@ -37,6 +37,7 @@ import android.content.Context;
import android.hardware.wifi.supplicant.V1_0.ISupplicant;
import android.hardware.wifi.supplicant.V1_0.ISupplicantIface;
import android.hardware.wifi.supplicant.V1_0.ISupplicantStaIface;
+import android.hardware.wifi.supplicant.V1_0.ISupplicantStaIfaceCallback;
import android.hardware.wifi.supplicant.V1_0.ISupplicantStaNetwork;
import android.hardware.wifi.supplicant.V1_0.IfaceType;
import android.hardware.wifi.supplicant.V1_0.SupplicantStatus;
@@ -87,6 +88,7 @@ public class SupplicantStaIfaceHalTest {
ISupplicant.IfaceInfo mStaIface;
ISupplicant.IfaceInfo mP2pIface;
ArrayList<ISupplicant.IfaceInfo> mIfaceInfoList;
+ ISupplicantStaIfaceCallback mISupplicantStaIfaceCallback;
private SupplicantStaIfaceHal mDut;
private ArgumentCaptor<IHwBinder.DeathRecipient> mDeathRecipientCaptor =
ArgumentCaptor.forClass(IHwBinder.DeathRecipient.class);
@@ -146,7 +148,7 @@ public class SupplicantStaIfaceHalTest {
*/
@Test
public void testInitialize_success() throws Exception {
- executeAndValidateInitializationSequence(false, false, false);
+ executeAndValidateInitializationSequence(false, false, false, false);
}
/**
@@ -155,7 +157,7 @@ public class SupplicantStaIfaceHalTest {
*/
@Test
public void testInitialize_remoteExceptionFailure() throws Exception {
- executeAndValidateInitializationSequence(true, false, false);
+ executeAndValidateInitializationSequence(true, false, false, false);
}
/**
@@ -164,7 +166,7 @@ public class SupplicantStaIfaceHalTest {
*/
@Test
public void testInitialize_zeroInterfacesFailure() throws Exception {
- executeAndValidateInitializationSequence(false, true, false);
+ executeAndValidateInitializationSequence(false, true, false, false);
}
/**
@@ -173,7 +175,16 @@ public class SupplicantStaIfaceHalTest {
*/
@Test
public void testInitialize_nullInterfaceFailure() throws Exception {
- executeAndValidateInitializationSequence(false, false, true);
+ executeAndValidateInitializationSequence(false, false, true, false);
+ }
+
+ /**
+ * Tests the initialization flow, with a callback registration failure.
+ * Ensures initialization fails.
+ */
+ @Test
+ public void testInitialize_callbackRegistrationFailure() throws Exception {
+ executeAndValidateInitializationSequence(false, false, false, true);
}
/**
@@ -182,7 +193,7 @@ public class SupplicantStaIfaceHalTest {
*/
@Test
public void testLoadNetworks() throws Exception {
- executeAndValidateInitializationSequence(false, false, false);
+ executeAndValidateInitializationSequence();
doAnswer(new MockAnswerUtil.AnswerWithArguments() {
public void answer(ISupplicantStaIface.listNetworksCallback cb) {
cb.onValues(mStatusSuccess, new ArrayList<>(NETWORK_ID_TO_SSID.keySet()));
@@ -235,7 +246,7 @@ public class SupplicantStaIfaceHalTest {
// Network ID which will have the same config key as the previous one.
final int duplicateNetworkId = 2;
final int toRemoveNetworkId = duplicateNetworkId - 1;
- executeAndValidateInitializationSequence(false, false, false);
+ executeAndValidateInitializationSequence();
doAnswer(new MockAnswerUtil.AnswerWithArguments() {
public void answer(ISupplicantStaIface.listNetworksCallback cb) {
cb.onValues(mStatusSuccess, new ArrayList<>(NETWORK_ID_TO_SSID.keySet()));
@@ -306,7 +317,7 @@ public class SupplicantStaIfaceHalTest {
*/
@Test
public void testLoadNetworksFailedDueToListNetworks() throws Exception {
- executeAndValidateInitializationSequence(false, false, false);
+ executeAndValidateInitializationSequence();
doAnswer(new MockAnswerUtil.AnswerWithArguments() {
public void answer(ISupplicantStaIface.listNetworksCallback cb) {
cb.onValues(mStatusFailure, null);
@@ -324,7 +335,7 @@ public class SupplicantStaIfaceHalTest {
*/
@Test
public void testLoadNetworksFailedDueToGetNetwork() throws Exception {
- executeAndValidateInitializationSequence(false, false, false);
+ executeAndValidateInitializationSequence();
doAnswer(new MockAnswerUtil.AnswerWithArguments() {
public void answer(ISupplicantStaIface.listNetworksCallback cb) {
cb.onValues(mStatusSuccess, new ArrayList<>(NETWORK_ID_TO_SSID.keySet()));
@@ -349,7 +360,7 @@ public class SupplicantStaIfaceHalTest {
*/
@Test
public void testLoadNetworksFailedDueToLoadWifiConfiguration() throws Exception {
- executeAndValidateInitializationSequence(false, false, false);
+ executeAndValidateInitializationSequence();
doAnswer(new MockAnswerUtil.AnswerWithArguments() {
public void answer(ISupplicantStaIface.listNetworksCallback cb) {
cb.onValues(mStatusSuccess, new ArrayList<>(NETWORK_ID_TO_SSID.keySet()));
@@ -373,7 +384,7 @@ public class SupplicantStaIfaceHalTest {
*/
@Test
public void testConnectWithNoDisconnectAndEmptyExistingNetworks() throws Exception {
- executeAndValidateInitializationSequence(false, false, false);
+ executeAndValidateInitializationSequence();
executeAndValidateConnectSequence(0, false, false);
}
@@ -382,7 +393,7 @@ public class SupplicantStaIfaceHalTest {
*/
@Test
public void testConnectWithNoDisconnectAndSingleExistingNetwork() throws Exception {
- executeAndValidateInitializationSequence(false, false, false);
+ executeAndValidateInitializationSequence();
executeAndValidateConnectSequence(0, true, false);
}
@@ -391,7 +402,7 @@ public class SupplicantStaIfaceHalTest {
*/
@Test
public void testConnectWithDisconnectAndSingleExistingNetwork() throws Exception {
- executeAndValidateInitializationSequence(false, false, false);
+ executeAndValidateInitializationSequence();
executeAndValidateConnectSequence(0, false, true);
}
@@ -400,7 +411,7 @@ public class SupplicantStaIfaceHalTest {
*/
@Test
public void testConnectFailureDueToNetworkAddFailure() throws Exception {
- executeAndValidateInitializationSequence(false, false, false);
+ executeAndValidateInitializationSequence();
setupMocksForConnectSequence(false);
doAnswer(new MockAnswerUtil.AnswerWithArguments() {
public void answer(ISupplicantStaIface.addNetworkCallback cb) throws RemoteException {
@@ -418,7 +429,7 @@ public class SupplicantStaIfaceHalTest {
*/
@Test
public void testConnectFailureDueToNetworkSaveFailure() throws Exception {
- executeAndValidateInitializationSequence(false, false, false);
+ executeAndValidateInitializationSequence();
setupMocksForConnectSequence(false);
when(mSupplicantStaNetworkMock.saveWifiConfiguration(any(WifiConfiguration.class)))
@@ -432,7 +443,7 @@ public class SupplicantStaIfaceHalTest {
*/
@Test
public void testConnectFailureDueToNetworkSelectFailure() throws Exception {
- executeAndValidateInitializationSequence(false, false, false);
+ executeAndValidateInitializationSequence();
setupMocksForConnectSequence(false);
when(mSupplicantStaNetworkMock.select()).thenReturn(false);
@@ -445,7 +456,7 @@ public class SupplicantStaIfaceHalTest {
*/
@Test
public void testRoamToSameNetwork() throws Exception {
- executeAndValidateInitializationSequence(false, false, false);
+ executeAndValidateInitializationSequence();
executeAndValidateRoamSequence(true);
}
@@ -454,7 +465,7 @@ public class SupplicantStaIfaceHalTest {
*/
@Test
public void testRoamToDifferentNetwork() throws Exception {
- executeAndValidateInitializationSequence(false, false, false);
+ executeAndValidateInitializationSequence();
executeAndValidateRoamSequence(false);
}
@@ -463,7 +474,7 @@ public class SupplicantStaIfaceHalTest {
*/
@Test
public void testRoamFailureDueToBssidSet() throws Exception {
- executeAndValidateInitializationSequence(false, false, false);
+ executeAndValidateInitializationSequence();
int connectedNetworkId = 5;
executeAndValidateConnectSequence(connectedNetworkId, false, false);
when(mSupplicantStaNetworkMock.setBssid(anyString())).thenReturn(false);
@@ -479,7 +490,7 @@ public class SupplicantStaIfaceHalTest {
*/
@Test
public void testRemoveAllNetworks() throws Exception {
- executeAndValidateInitializationSequence(false, false, false);
+ executeAndValidateInitializationSequence();
doAnswer(new MockAnswerUtil.AnswerWithArguments() {
public void answer(ISupplicantStaIface.listNetworksCallback cb) {
cb.onValues(mStatusSuccess, new ArrayList<>(NETWORK_ID_TO_SSID.keySet()));
@@ -502,7 +513,7 @@ public class SupplicantStaIfaceHalTest {
*/
@Test
public void testRoamFailureDueToReassociate() throws Exception {
- executeAndValidateInitializationSequence(false, false, false);
+ executeAndValidateInitializationSequence();
int connectedNetworkId = 5;
executeAndValidateConnectSequence(connectedNetworkId, false, false);
@@ -527,7 +538,7 @@ public class SupplicantStaIfaceHalTest {
String token = "45adbc1";
when(mSupplicantStaNetworkMock.getWpsNfcConfigurationToken()).thenReturn(token);
- executeAndValidateInitializationSequence(false, false, false);
+ executeAndValidateInitializationSequence();
// Return null when not connected to the network.
assertTrue(mDut.getCurrentNetworkWpsNfcConfigurationToken() == null);
@@ -545,7 +556,7 @@ public class SupplicantStaIfaceHalTest {
String bssidStr = "34:34:12:12:12:90";
when(mSupplicantStaNetworkMock.setBssid(eq(bssidStr))).thenReturn(true);
- executeAndValidateInitializationSequence(false, false, false);
+ executeAndValidateInitializationSequence();
// Fail when not connected to a network.
assertFalse(mDut.setCurrentNetworkBssid(bssidStr));
@@ -567,7 +578,7 @@ public class SupplicantStaIfaceHalTest {
when(mISupplicantStaIfaceMock.setWpsDeviceType(any(byte[].class)))
.thenReturn(mStatusSuccess);
- executeAndValidateInitializationSequence(false, false, false);
+ executeAndValidateInitializationSequence();
// This should work.
assertTrue(mDut.setWpsDeviceType(validDeviceTypeStr));
@@ -590,7 +601,7 @@ public class SupplicantStaIfaceHalTest {
String invalidConfigMethodsStr = "physical_display virtual_push_button test";
when(mISupplicantStaIfaceMock.setWpsConfigMethods(anyShort())).thenReturn(mStatusSuccess);
- executeAndValidateInitializationSequence(false, false, false);
+ executeAndValidateInitializationSequence();
// This should work.
assertTrue(mDut.setWpsConfigMethods(validConfigMethodsStr));
@@ -605,6 +616,10 @@ public class SupplicantStaIfaceHalTest {
assertTrue(false);
}
+ private void executeAndValidateInitializationSequence() throws Exception {
+ executeAndValidateInitializationSequence(false, false, false, false);
+ }
+
/**
* Tests the setting of log level.
*/
@@ -616,7 +631,7 @@ public class SupplicantStaIfaceHalTest {
// Fail before initialization is performed.
assertFalse(mDut.setLogLevel(SupplicantStaIfaceHal.LOG_LEVEL_DEBUG));
- executeAndValidateInitializationSequence(false, false, false);
+ executeAndValidateInitializationSequence();
// This should work.
assertTrue(mDut.setLogLevel(SupplicantStaIfaceHal.LOG_LEVEL_DEBUG));
@@ -634,7 +649,7 @@ public class SupplicantStaIfaceHalTest {
// Fail before initialization is performed.
assertFalse(mDut.setConcurrencyPriority(false));
- executeAndValidateInitializationSequence(false, false, false);
+ executeAndValidateInitializationSequence();
// This should work.
assertTrue(mDut.setConcurrencyPriority(false));
@@ -650,9 +665,12 @@ public class SupplicantStaIfaceHalTest {
*/
private void executeAndValidateInitializationSequence(boolean causeRemoteException,
boolean getZeroInterfaces,
- boolean getNullInterface)
+ boolean getNullInterface,
+ boolean causeCallbackRegFailure)
throws Exception {
- boolean shouldSucceed = !causeRemoteException && !getZeroInterfaces && !getNullInterface;
+ boolean shouldSucceed =
+ !causeRemoteException && !getZeroInterfaces && !getNullInterface
+ && !causeCallbackRegFailure;
// Setup callback mock answers
ArrayList<ISupplicant.IfaceInfo> interfaces;
if (getZeroInterfaces) {
@@ -671,8 +689,27 @@ public class SupplicantStaIfaceHalTest {
.when(mISupplicantMock).getInterface(any(ISupplicant.IfaceInfo.class),
any(ISupplicant.getInterfaceCallback.class));
}
+ /** Callback registeration */
+ if (causeCallbackRegFailure) {
+ doAnswer(new MockAnswerUtil.AnswerWithArguments() {
+ public SupplicantStatus answer(ISupplicantStaIfaceCallback cb)
+ throws RemoteException {
+ return mStatusFailure;
+ }
+ }).when(mISupplicantStaIfaceMock)
+ .registerCallback(any(ISupplicantStaIfaceCallback.class));
+ } else {
+ doAnswer(new MockAnswerUtil.AnswerWithArguments() {
+ public SupplicantStatus answer(ISupplicantStaIfaceCallback cb)
+ throws RemoteException {
+ mISupplicantStaIfaceCallback = cb;
+ return mStatusSuccess;
+ }
+ }).when(mISupplicantStaIfaceMock)
+ .registerCallback(any(ISupplicantStaIfaceCallback.class));
+ }
- mInOrder = inOrder(mServiceManagerMock, mISupplicantMock);
+ mInOrder = inOrder(mServiceManagerMock, mISupplicantMock, mISupplicantStaIfaceMock);
// Initialize SupplicantStaIfaceHal, should call serviceManager.registerForNotifications
assertTrue(mDut.initialize());
// verify: service manager initialization sequence
@@ -692,6 +729,10 @@ public class SupplicantStaIfaceHalTest {
.getInterface(any(ISupplicant.IfaceInfo.class),
any(ISupplicant.getInterfaceCallback.class));
}
+ if (!causeRemoteException && !getZeroInterfaces && !getNullInterface) {
+ mInOrder.verify(mISupplicantStaIfaceMock)
+ .registerCallback(any(ISupplicantStaIfaceCallback.class));
+ }
}
private SupplicantStatus createSupplicantStatus(int code) {
diff --git a/tests/wifitests/src/com/android/server/wifi/SupplicantStaNetworkHalTest.java b/tests/wifitests/src/com/android/server/wifi/SupplicantStaNetworkHalTest.java
index c1596f00a..48c478948 100644
--- a/tests/wifitests/src/com/android/server/wifi/SupplicantStaNetworkHalTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/SupplicantStaNetworkHalTest.java
@@ -16,14 +16,21 @@
package com.android.server.wifi;
import static org.junit.Assert.*;
+import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.doAnswer;
+import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.app.test.MockAnswerUtil.AnswerWithArguments;
import android.content.Context;
import android.hardware.wifi.supplicant.V1_0.ISupplicantNetwork;
import android.hardware.wifi.supplicant.V1_0.ISupplicantStaNetwork;
+import android.hardware.wifi.supplicant.V1_0.ISupplicantStaNetworkCallback;
+import android.hardware.wifi.supplicant.V1_0.ISupplicantStaNetworkCallback
+ .NetworkRequestEapSimGsmAuthParams;
+import android.hardware.wifi.supplicant.V1_0.ISupplicantStaNetworkCallback
+ .NetworkRequestEapSimUmtsAuthParams;
import android.hardware.wifi.supplicant.V1_0.SupplicantStatus;
import android.hardware.wifi.supplicant.V1_0.SupplicantStatusCode;
import android.net.wifi.WifiConfiguration;
@@ -42,12 +49,13 @@ import org.mockito.MockitoAnnotations;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
+import java.util.Random;
/**
* Unit tests for SupplicantStaNetworkHal
*/
public class SupplicantStaNetworkHalTest {
- private static final String TAG = "SupplicantStaNetworkHalTest";
+ private static final String IFACE_NAME = "wlan0";
private SupplicantStaNetworkHal mSupplicantNetwork;
private SupplicantStatus mStatusSuccess;
@@ -57,6 +65,7 @@ public class SupplicantStaNetworkHalTest {
@Mock private WifiMonitor mWifiMonitor;
private SupplicantNetworkVariables mSupplicantVariables;
private MockResources mResources;
+ private ISupplicantStaNetworkCallback mISupplicantStaNetworkCallback;
@Before
public void setUp() throws Exception {
@@ -600,6 +609,111 @@ public class SupplicantStaNetworkHalTest {
WifiConfigurationTestUtil.assertConfigurationEqualForSupplicant(config, loadConfig);
}
+ /**
+ * Tests the retrieval of WPS NFC token.
+ */
+ @Test
+ public void testGetWpsNfcConfigurationToken() throws Exception {
+ final ArrayList<Byte> token = new ArrayList<>();
+ token.add(Byte.valueOf((byte) 0x45));
+ token.add(Byte.valueOf((byte) 0x34));
+
+ doAnswer(new AnswerWithArguments() {
+ public void answer(ISupplicantStaNetwork.getWpsNfcConfigurationTokenCallback cb)
+ throws RemoteException {
+ cb.onValues(mStatusSuccess, token);
+ }
+ }).when(mISupplicantStaNetworkMock)
+ .getWpsNfcConfigurationToken(
+ any(ISupplicantStaNetwork.getWpsNfcConfigurationTokenCallback.class));
+
+ assertEquals("4534", mSupplicantNetwork.getWpsNfcConfigurationToken());
+ }
+
+ /**
+ * Tests that callback registration failure triggers a failure in saving network config.
+ */
+ @Test
+ public void testSaveFailureDueToCallbackReg() throws Exception {
+ when(mISupplicantStaNetworkMock.registerCallback(any(ISupplicantStaNetworkCallback.class)))
+ .thenReturn(mStatusFailure);
+ WifiConfiguration config = WifiConfigurationTestUtil.createPskNetwork();
+ assertFalse(mSupplicantNetwork.saveWifiConfiguration(config));
+ }
+
+ /**
+ * Tests the network gsm auth callback.
+ */
+ @Test
+ public void testNetworkEapGsmAuthCallback() throws Exception {
+ WifiConfiguration config = WifiConfigurationTestUtil.createPskNetwork();
+ assertTrue(mSupplicantNetwork.saveWifiConfiguration(config));
+ assertNotNull(mISupplicantStaNetworkCallback);
+
+ // Now trigger eap gsm callback and ensure that the event is broadcast via WifiMonitor.
+ NetworkRequestEapSimGsmAuthParams params = new NetworkRequestEapSimGsmAuthParams();
+ Random random = new Random();
+ byte[] rand1 = new byte[16];
+ byte[] rand2 = new byte[16];
+ byte[] rand3 = new byte[16];
+ random.nextBytes(rand1);
+ random.nextBytes(rand2);
+ random.nextBytes(rand3);
+ params.rands.add(rand1);
+ params.rands.add(rand2);
+ params.rands.add(rand3);
+
+ String[] expectedRands = {
+ NativeUtil.hexStringFromByteArray(rand1), NativeUtil.hexStringFromByteArray(rand2),
+ NativeUtil.hexStringFromByteArray(rand3)
+ };
+
+ mISupplicantStaNetworkCallback.onNetworkEapSimGsmAuthRequest(params);
+ verify(mWifiMonitor).broadcastNetworkGsmAuthRequestEvent(
+ eq(IFACE_NAME), eq(config.networkId), eq(config.SSID), eq(expectedRands));
+ }
+
+ /**
+ * Tests the network umts auth callback.
+ */
+ @Test
+ public void testNetworkEapUmtsAuthCallback() throws Exception {
+ WifiConfiguration config = WifiConfigurationTestUtil.createPskNetwork();
+ assertTrue(mSupplicantNetwork.saveWifiConfiguration(config));
+ assertNotNull(mISupplicantStaNetworkCallback);
+
+ // Now trigger eap gsm callback and ensure that the event is broadcast via WifiMonitor.
+ NetworkRequestEapSimUmtsAuthParams params = new NetworkRequestEapSimUmtsAuthParams();
+ Random random = new Random();
+ random.nextBytes(params.autn);
+ random.nextBytes(params.rand);
+
+ String[] expectedRands = {
+ NativeUtil.hexStringFromByteArray(params.autn),
+ NativeUtil.hexStringFromByteArray(params.rand)
+ };
+
+ mISupplicantStaNetworkCallback.onNetworkEapSimUmtsAuthRequest(params);
+ verify(mWifiMonitor).broadcastNetworkUmtsAuthRequestEvent(
+ eq(IFACE_NAME), eq(config.networkId), eq(config.SSID), eq(expectedRands));
+ }
+
+ /**
+ * Tests the network identity callback.
+ */
+ @Test
+ public void testNetworkIdentityCallback() throws Exception {
+ WifiConfiguration config = WifiConfigurationTestUtil.createPskNetwork();
+ assertTrue(mSupplicantNetwork.saveWifiConfiguration(config));
+ assertNotNull(mISupplicantStaNetworkCallback);
+
+ // Now trigger identity request callback and ensure that the event is broadcast via
+ // WifiMonitor.
+ mISupplicantStaNetworkCallback.onNetworkEapIdentityRequest();
+ verify(mWifiMonitor).broadcastNetworkIdentityRequestEvent(
+ eq(IFACE_NAME), eq(config.networkId), eq(config.SSID));
+ }
+
private void testWifiConfigurationSaveLoad(WifiConfiguration config) {
assertTrue(mSupplicantNetwork.saveWifiConfiguration(config));
WifiConfiguration loadConfig = new WifiConfiguration();
@@ -628,27 +742,6 @@ public class SupplicantStaNetworkHalTest {
}
/**
- * Tests the retrieval of WPS NFC token.
- */
- @Test
- public void testGetWpsNfcConfigurationToken() throws Exception {
- final ArrayList<Byte> token = new ArrayList<>();
- token.add(Byte.valueOf((byte) 0x45));
- token.add(Byte.valueOf((byte) 0x34));
-
- doAnswer(new AnswerWithArguments() {
- public void answer(ISupplicantStaNetwork.getWpsNfcConfigurationTokenCallback cb)
- throws RemoteException {
- cb.onValues(mStatusSuccess, token);
- }
- }).when(mISupplicantStaNetworkMock)
- .getWpsNfcConfigurationToken(
- any(ISupplicantStaNetwork.getWpsNfcConfigurationTokenCallback.class));
-
- assertEquals("4534", mSupplicantNetwork.getWpsNfcConfigurationToken());
- }
-
- /**
* Sets up the HIDL interface mock with all the setters/getter values.
* Note: This only sets up the mock to return success on all methods.
*/
@@ -1086,6 +1179,16 @@ public class SupplicantStaNetworkHalTest {
return mStatusSuccess;
}
}).when(mISupplicantStaNetworkMock).setProactiveKeyCaching(any(boolean.class));
+
+ /** Callback registeration */
+ doAnswer(new AnswerWithArguments() {
+ public SupplicantStatus answer(ISupplicantStaNetworkCallback cb)
+ throws RemoteException {
+ mISupplicantStaNetworkCallback = cb;
+ return mStatusSuccess;
+ }
+ }).when(mISupplicantStaNetworkMock)
+ .registerCallback(any(ISupplicantStaNetworkCallback.class));
}
private SupplicantStatus createSupplicantStatus(int code) {
@@ -1099,7 +1202,8 @@ public class SupplicantStaNetworkHalTest {
*/
private void createSupplicantStaNetwork() {
mSupplicantNetwork =
- new SupplicantStaNetworkHal(mISupplicantStaNetworkMock, mContext, mWifiMonitor);
+ new SupplicantStaNetworkHal(
+ mISupplicantStaNetworkMock, IFACE_NAME, mContext, mWifiMonitor);
}
// Private class to to store/inspect values set via the HIDL mock.