diff options
5 files changed, 117 insertions, 3 deletions
diff --git a/service/java/com/android/server/wifi/SupplicantStaIfaceHal.java b/service/java/com/android/server/wifi/SupplicantStaIfaceHal.java index c12f5b3fe..2f59e8a3f 100644 --- a/service/java/com/android/server/wifi/SupplicantStaIfaceHal.java +++ b/service/java/com/android/server/wifi/SupplicantStaIfaceHal.java @@ -386,6 +386,27 @@ public class SupplicantStaIfaceHal { } /** + * Set the currently configured network's bssid. + * + * @param bssidStr Bssid to set in the form of "XX:XX:XX:XX:XX:XX" + * @return true if succeeds, false otherwise. + */ + public boolean setCurrentNetworkBssid(String bssidStr) { + if (mCurrentNetwork == null) return false; + return mCurrentNetwork.setBssid(bssidStr); + } + + /** + * Get the currently configured network's WPS NFC token. + * + * @return Hex string corresponding to the WPS NFC token. + */ + public String getCurrentNetworkWpsNfcConfigurationToken() { + if (mCurrentNetwork == null) return null; + return mCurrentNetwork.getWpsNfcConfigurationToken(); + } + + /** * Gets the interface name. * * @return returns the name of Iface or null if the call fails diff --git a/service/java/com/android/server/wifi/SupplicantStaNetworkHal.java b/service/java/com/android/server/wifi/SupplicantStaNetworkHal.java index 37ee083eb..e96de5f2f 100644 --- a/service/java/com/android/server/wifi/SupplicantStaNetworkHal.java +++ b/service/java/com/android/server/wifi/SupplicantStaNetworkHal.java @@ -2207,8 +2207,21 @@ public class SupplicantStaNetworkHal { } } + /** + * Retrieve the NFC token for this network. + * + * @return Hex string corresponding to the NFC token or null for failure. + */ + public String getWpsNfcConfigurationToken() { + ArrayList<Byte> token = getWpsNfcConfigurationTokenInternal(); + if (token == null) { + return null; + } + return NativeUtil.hexStringFromByteArray(NativeUtil.byteArrayFromArrayList(token)); + } + /** See ISupplicantStaNetwork.hal for documentation */ - private ArrayList<Byte> getWpsNfcConfigurationToken() { + private ArrayList<Byte> getWpsNfcConfigurationTokenInternal() { synchronized (mLock) { final String methodStr = "getWpsNfcConfigurationToken"; if (!checkISupplicantStaNetworkAndLogFailure(methodStr)) return null; diff --git a/service/java/com/android/server/wifi/util/NativeUtil.java b/service/java/com/android/server/wifi/util/NativeUtil.java index dc515efd3..91cf23e97 100644 --- a/service/java/com/android/server/wifi/util/NativeUtil.java +++ b/service/java/com/android/server/wifi/util/NativeUtil.java @@ -208,7 +208,7 @@ public class NativeUtil { /** * Convert from an array of primitive bytes to an array list of Byte. */ - private static ArrayList<Byte> byteArrayToArrayList(byte[] bytes) { + public static ArrayList<Byte> byteArrayToArrayList(byte[] bytes) { ArrayList<Byte> byteList = new ArrayList<>(); for (Byte b : bytes) { byteList.add(b); @@ -219,7 +219,7 @@ public class NativeUtil { /** * Convert from an array list of Byte to an array of primitive bytes. */ - private static byte[] byteArrayFromArrayList(ArrayList<Byte> bytes) { + public static byte[] byteArrayFromArrayList(ArrayList<Byte> bytes) { byte[] byteArray = new byte[bytes.size()]; int i = 0; for (Byte b : bytes) { diff --git a/tests/wifitests/src/com/android/server/wifi/SupplicantStaIfaceHalTest.java b/tests/wifitests/src/com/android/server/wifi/SupplicantStaIfaceHalTest.java index a0caad09d..2dc2eaa13 100644 --- a/tests/wifitests/src/com/android/server/wifi/SupplicantStaIfaceHalTest.java +++ b/tests/wifitests/src/com/android/server/wifi/SupplicantStaIfaceHalTest.java @@ -472,6 +472,29 @@ public class SupplicantStaIfaceHalTest { } /** + * Tests removal of all configured networks from wpa_supplicant. + */ + @Test + public void testRemoveAllNetworks() throws Exception { + executeAndValidateInitializationSequence(false, false, false); + doAnswer(new MockAnswerUtil.AnswerWithArguments() { + public void answer(ISupplicantStaIface.listNetworksCallback cb) { + cb.onValues(mStatusSuccess, new ArrayList<>(NETWORK_ID_TO_SSID.keySet())); + } + }).when(mISupplicantStaIfaceMock) + .listNetworks(any(ISupplicantStaIface.listNetworksCallback.class)); + doAnswer(new MockAnswerUtil.AnswerWithArguments() { + public SupplicantStatus answer(int id) { + assertTrue(NETWORK_ID_TO_SSID.containsKey(id)); + return mStatusSuccess; + } + }).when(mISupplicantStaIfaceMock).removeNetwork(anyInt()); + + assertTrue(mDut.removeAllNetworks()); + verify(mISupplicantStaIfaceMock, times(NETWORK_ID_TO_SSID.size())).removeNetwork(anyInt()); + } + + /** * Tests roaming failure because of unable to reassociate. */ @Test @@ -494,6 +517,42 @@ public class SupplicantStaIfaceHalTest { } /** + * Tests the retrieval of WPS NFC token. + */ + @Test + public void testGetCurrentNetworkWpsNfcConfigurationToken() throws Exception { + String token = "45adbc1"; + when(mSupplicantStaNetworkMock.getWpsNfcConfigurationToken()).thenReturn(token); + + executeAndValidateInitializationSequence(false, false, false); + + // Return null when not connected to the network. + assertTrue(mDut.getCurrentNetworkWpsNfcConfigurationToken() == null); + + executeAndValidateConnectSequence(4, false, false); + + assertEquals(token, mDut.getCurrentNetworkWpsNfcConfigurationToken()); + } + + /** + * Tests the retrieval of WPS NFC token. + */ + @Test + public void testSetCurrentNetworkBssid() throws Exception { + String bssidStr = "34:34:12:12:12:90"; + when(mSupplicantStaNetworkMock.setBssid(eq(bssidStr))).thenReturn(true); + + executeAndValidateInitializationSequence(false, false, false); + + // Fail when not connected to a network. + assertFalse(mDut.setCurrentNetworkBssid(bssidStr)); + + executeAndValidateConnectSequence(4, false, false); + + assertTrue(mDut.setCurrentNetworkBssid(bssidStr)); + } + + /** * Calls.initialize(), mocking various call back answers and verifying flow, asserting for the * expected result. Verifies if ISupplicantStaIface manager is initialized or reset. * Each of the arguments will cause a different failure mode when set true. diff --git a/tests/wifitests/src/com/android/server/wifi/SupplicantStaNetworkHalTest.java b/tests/wifitests/src/com/android/server/wifi/SupplicantStaNetworkHalTest.java index 6021b1c7d..780b39cd7 100644 --- a/tests/wifitests/src/com/android/server/wifi/SupplicantStaNetworkHalTest.java +++ b/tests/wifitests/src/com/android/server/wifi/SupplicantStaNetworkHalTest.java @@ -617,6 +617,27 @@ 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. */ |