diff --git a/app/src/androidTest/java/com/metova/wisefy/WiseFyTest.java b/app/src/androidTest/java/com/metova/wisefy/WiseFyTest.java index 6d909b4f..fa947bf0 100644 --- a/app/src/androidTest/java/com/metova/wisefy/WiseFyTest.java +++ b/app/src/androidTest/java/com/metova/wisefy/WiseFyTest.java @@ -13,7 +13,6 @@ 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.*; @@ -257,6 +256,37 @@ public void testIsSecureNullCapabilities() { assertEquals(false, WiseFy.getSmarts().isSecure(scanResult)); } + public void testIsWiFiEnabledFalse() { + final WifiManager wifiManager = getLiveWiFiManager(getActivity()); + wifiManager.setWifiEnabled(false); + assertTrue(getSolo().waitForCondition(new Condition() { + @Override + public boolean isSatisfied() { + return !wifiManager.isWifiEnabled(); + } + }, 3000)); + assertEquals(false, WiseFy.getSmarts().isWifiEnabled(getActivity())); + wifiManager.setWifiEnabled(true); + assertTrue(getSolo().waitForCondition(new Condition() { + @Override + public boolean isSatisfied() { + return wifiManager.isWifiEnabled(); + } + }, 3000)); + } + + public void testIsWifiEnabledTrue() { + final WifiManager wifiManager = getLiveWiFiManager(getActivity()); + wifiManager.setWifiEnabled(true); + assertTrue(getSolo().waitForCondition(new Condition() { + @Override + public boolean isSatisfied() { + return wifiManager.isWifiEnabled(); + } + }, 3000)); + assertEquals(true, WiseFy.getSmarts().isWifiEnabled(getActivity())); + } + 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 e96dccdf..411d8c50 100644 --- a/app/src/main/java/com/metova/wisefy/WiseFy.java +++ b/app/src/main/java/com/metova/wisefy/WiseFy.java @@ -483,6 +483,24 @@ public boolean isSecure(ScanResult scanResult) { return isSecure; } + + /** + * To check if Wifi is enabled on the device or not + * + * @param activity - The activity to use as context to retrieve a wifi manager via getSystemService + * @return boolean - if Wifi is enabled on device + */ + public boolean isWifiEnabled(Activity activity) { + boolean isWifiEnabled = false; + if(activity != null) { + WifiManager wifiManager = GetManagerUtil.getInstance().getWiFiManager(activity); + isWifiEnabled = wifiManager.isWifiEnabled(); + } else { + LogUtil.w(TAG, "No activity to get wifi config"); + } + return isWifiEnabled; + } + /** * Used to reconnect to a network *