Add location permission to netpolicy test app.
As part of the test, wifi ssid needs to be extracted which
is guarded by ACCESS_COARSE_LOCATION permission.
Bug: 64274313
Test: cts-tradefed run singleCommand cts-dev --module CtsHostsideNetworkTests -t \
com.android.cts.net.HostsideRestrictBackgroundNetworkTests
Change-Id: I5c23b11dc1bf26a672bc1454ff1e2594935d43d8
This commit is contained in:
@@ -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" />
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user