Merge "Add location permission to netpolicy test app." into oc-mr1-dev

am: 97cbea8559

Change-Id: If98dd7fa8426281498ea30ca5310dcf8bf6a6030
This commit is contained in:
Sudheer Shanka
2017-08-16 22:22:16 +00:00
committed by android-build-merger
2 changed files with 32 additions and 0 deletions

View File

@@ -21,6 +21,8 @@
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS" />
<application>
<uses-library android:name="android.test.runner" />

View File

@@ -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);
}