diff --git a/tests/cts/hostside/app/AndroidManifest.xml b/tests/cts/hostside/app/AndroidManifest.xml
index 0598a3b02a..7466cb88dd 100644
--- a/tests/cts/hostside/app/AndroidManifest.xml
+++ b/tests/cts/hostside/app/AndroidManifest.xml
@@ -21,6 +21,8 @@
+
+
diff --git a/tests/cts/hostside/app/src/com/android/cts/net/hostside/AbstractRestrictBackgroundNetworkTestCase.java b/tests/cts/hostside/app/src/com/android/cts/net/hostside/AbstractRestrictBackgroundNetworkTestCase.java
index f3d5d2c4b2..35e84c5f19 100644
--- a/tests/cts/hostside/app/src/com/android/cts/net/hostside/AbstractRestrictBackgroundNetworkTestCase.java
+++ b/tests/cts/hostside/app/src/com/android/cts/net/hostside/AbstractRestrictBackgroundNetworkTestCase.java
@@ -42,6 +42,7 @@ import android.os.BatteryManager;
import android.os.Binder;
import android.os.Bundle;
import android.os.SystemClock;
+import android.provider.Settings;
import android.service.notification.NotificationListenerService;
import android.test.InstrumentationTestCase;
import android.text.TextUtils;
@@ -116,6 +117,7 @@ abstract class AbstractRestrictBackgroundNetworkTestCase extends Instrumentation
private MyServiceClient mServiceClient;
private String mDeviceIdleConstantsSetting;
private boolean mSupported;
+ private boolean mIsLocationOn;
@Override
protected void setUp() throws Exception {
@@ -130,6 +132,10 @@ abstract class AbstractRestrictBackgroundNetworkTestCase extends Instrumentation
mServiceClient = new MyServiceClient(mContext);
mServiceClient.bind();
mDeviceIdleConstantsSetting = "device_idle_constants";
+ mIsLocationOn = isLocationOn();
+ if (!mIsLocationOn) {
+ enableLocation();
+ }
mSupported = setUpActiveNetworkMeteringState();
Log.i(TAG, "Apps status on " + getName() + ":\n"
@@ -139,11 +145,35 @@ abstract class AbstractRestrictBackgroundNetworkTestCase extends Instrumentation
@Override
protected void tearDown() throws Exception {
+ if (!mIsLocationOn) {
+ disableLocation();
+ }
mServiceClient.unbind();
super.tearDown();
}
+ private void enableLocation() throws Exception {
+ Settings.Secure.putInt(mContext.getContentResolver(), Settings.Secure.LOCATION_MODE,
+ Settings.Secure.LOCATION_MODE_SENSORS_ONLY);
+ assertEquals(Settings.Secure.LOCATION_MODE_SENSORS_ONLY,
+ Settings.Secure.getInt(mContext.getContentResolver(),
+ Settings.Secure.LOCATION_MODE));
+ }
+
+ private void disableLocation() throws Exception {
+ Settings.Secure.putInt(mContext.getContentResolver(), Settings.Secure.LOCATION_MODE,
+ Settings.Secure.LOCATION_MODE_OFF);
+ assertEquals(Settings.Secure.LOCATION_MODE_OFF,
+ Settings.Secure.getInt(mContext.getContentResolver(),
+ Settings.Secure.LOCATION_MODE));
+ }
+
+ private boolean isLocationOn() throws Exception {
+ return Settings.Secure.getInt(mContext.getContentResolver(),
+ Settings.Secure.LOCATION_MODE) != Settings.Secure.LOCATION_MODE_OFF;
+ }
+
protected int getUid(String packageName) throws Exception {
return mContext.getPackageManager().getPackageUid(packageName, 0);
}