diff --git a/README.md b/README.md index 66438887..3facf889 100644 --- a/README.md +++ b/README.md @@ -72,6 +72,12 @@ To get the networks whose configuration is already stored: List savedNetworks = WiseFy.getSmarts().getSavedNetworks(getActivity()); ``` +To check and see if a network is secure (WEP/PSK/EAP capabilities): + +```java +boolean secure = WiseFy.getSmarts().isSecure(scanResult; +``` + To reconnect to a network given an SSID: ```java diff --git a/app/build.gradle b/app/build.gradle index e7c8974e..c97d4f54 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -52,8 +52,8 @@ android { defaultConfig { minSdkVersion 16 targetSdkVersion 23 - versionCode 1 - versionName "1.0.0" + versionCode 2 + versionName "1.0.1" } buildTypes { diff --git a/app/src/androidTest/java/com/metova/wisefy/WiseFyTest.java b/app/src/androidTest/java/com/metova/wisefy/WiseFyTest.java index 5db55681..6d909b4f 100644 --- a/app/src/androidTest/java/com/metova/wisefy/WiseFyTest.java +++ b/app/src/androidTest/java/com/metova/wisefy/WiseFyTest.java @@ -13,6 +13,7 @@ import com.metova.wisefy.util.GetManagerUtil; import com.metova.wisefy.util.TestActivity; import com.robotium.solo.Condition; +import org.mockito.Mockito; import java.util.ArrayList; import java.util.List; import static org.mockito.Mockito.*; @@ -227,6 +228,35 @@ public void testGetSavedNetworks() { assertEquals(wifiList, WiseFy.getSmarts().getSavedNetworks(getActivity())); } + public void testIsSecureWithWEP() { + ScanResult scanResult = mock(ScanResult.class); + scanResult.capabilities = "WEP"; + assertEquals(true, WiseFy.getSmarts().isSecure(scanResult)); + } + + public void testIsSecureWithPSK() { + ScanResult scanResult = mock(ScanResult.class); + scanResult.capabilities = "PSK"; + assertEquals(true, WiseFy.getSmarts().isSecure(scanResult)); + } + + public void testIsSecureWithEAP() { + ScanResult scanResult = mock(ScanResult.class); + scanResult.capabilities = "EAP"; + assertEquals(true, WiseFy.getSmarts().isSecure(scanResult)); + } + + public void testIsSecureEmptyCapabilities() { + ScanResult scanResult = mock(ScanResult.class); + scanResult.capabilities = ""; + assertEquals(false, WiseFy.getSmarts().isSecure(scanResult)); + } + + public void testIsSecureNullCapabilities() { + ScanResult scanResult = mock(ScanResult.class); + assertEquals(false, WiseFy.getSmarts().isSecure(scanResult)); + } + public void testReconnectToNetworkSuccess() { WiseFy.getSmarts().mGetManagerUtil = mMockGetManagerUtil; List wifiList = new ArrayList<>(); diff --git a/app/src/main/java/com/metova/wisefy/WiseFy.java b/app/src/main/java/com/metova/wisefy/WiseFy.java index 0a642c77..e96dccdf 100644 --- a/app/src/main/java/com/metova/wisefy/WiseFy.java +++ b/app/src/main/java/com/metova/wisefy/WiseFy.java @@ -467,6 +467,22 @@ public List getSavedNetworks(Activity activity) { } } + /** + * To check and return if a network is secure (WEP/PSK/EAP capabilities) + * + * @param scanResult - The network to see if it is secure + * @return boolean - Whether the network is secure + */ + public boolean isSecure(ScanResult scanResult) { + boolean isSecure = false; + if(scanResult != null && scanResult.capabilities != null) { + if (scanResult.capabilities.contains("WEP") || scanResult.capabilities.contains("PSK") || scanResult.capabilities.contains("EAP")) { + isSecure = true; + } + } + return isSecure; + } + /** * Used to reconnect to a network *