From abe587984adc0fbc1e7487b69b5b45de929c7d9d Mon Sep 17 00:00:00 2001 From: Wei Wang Date: Thu, 29 Oct 2015 10:28:12 -0700 Subject: [PATCH] Don't run Wifi scan timestamp tests when location is turned off. Bug:24957400 Change-Id: I891040ffc0808d62a8f5f1bb20fd633b9f7f482c --- .../android/net/wifi/cts/WifiManagerTest.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) 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