diff --git a/tests/cts/net/src/android/net/wifi/cts/WifiManagerTest.java b/tests/cts/net/src/android/net/wifi/cts/WifiManagerTest.java index 152789cafb..4478bd4c52 100644 --- a/tests/cts/net/src/android/net/wifi/cts/WifiManagerTest.java +++ b/tests/cts/net/src/android/net/wifi/cts/WifiManagerTest.java @@ -21,6 +21,8 @@ import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; +import android.content.pm.PackageManager; +import android.location.LocationManager; import android.net.NetworkInfo; import android.net.wifi.ScanResult; import android.net.wifi.WifiConfiguration; @@ -29,6 +31,7 @@ import android.net.wifi.WifiManager; import android.net.wifi.WifiManager.TxPacketCountListener; import android.net.wifi.WifiManager.WifiLock; import android.os.SystemClock; +import android.provider.Settings; import android.test.AndroidTestCase; import android.util.Log; @@ -278,6 +281,14 @@ public class WifiManagerTest extends AndroidTestCase { Log.d(TAG, "Skipping test as WiFi is not supported"); return; } + if (!hasLocationFeature()) { + Log.d(TAG, "Skipping test as location is not supported"); + return; + } + if (!isLocationEnabled()) { + fail("Please enable location for this test - since Marshmallow WiFi scan results are" + + " empty when location is disabled!"); + } if (!mWifiManager.isWifiEnabled()) { setWifiEnabled(true); } @@ -307,6 +318,18 @@ public class WifiManagerTest extends AndroidTestCase { } } + // Return true if location is enabled. + private boolean isLocationEnabled() { + return Settings.Secure.getInt(getContext().getContentResolver(), + Settings.Secure.LOCATION_MODE, Settings.Secure.LOCATION_MODE_OFF) != + Settings.Secure.LOCATION_MODE_OFF; + } + + // Returns true if the device has location feature. + private boolean hasLocationFeature() { + return getContext().getPackageManager().hasSystemFeature(PackageManager.FEATURE_LOCATION); + } + /** * test point of wifiManager NetWork: * 1.add NetWork