Merge "Don\'t run Wifi scan timestamp tests when location is turned off." into marshmallow-cts-dev

am: 57031aa47e

* commit '57031aa47e16e4d493c03df886c35c5081fcaeed':
  Don't run Wifi scan timestamp tests when location is turned off.
This commit is contained in:
Daniel Xie
2015-11-17 01:12:55 +00:00
committed by android-build-merger

View File

@@ -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