diff options
author | android-build-team Robot <android-build-team-robot@google.com> | 2019-10-28 23:21:59 +0000 |
---|---|---|
committer | android-build-team Robot <android-build-team-robot@google.com> | 2019-10-28 23:21:59 +0000 |
commit | ecffbf0ad26ec1a10519f112c2effd9521846c4f (patch) | |
tree | d7bfb60b04b72f621d6239a1bf50cf38c3912cd8 /tests | |
parent | 4d9dac1e142d4716f0d7bdb7a9f17bc2fd282f18 (diff) | |
parent | b59b5f33daf5a020c7f44e7fc9526db86e0d2922 (diff) | |
download | platform_cts-ecffbf0ad26ec1a10519f112c2effd9521846c4f.tar.gz platform_cts-ecffbf0ad26ec1a10519f112c2effd9521846c4f.tar.bz2 platform_cts-ecffbf0ad26ec1a10519f112c2effd9521846c4f.zip |
Merge cherrypicks of [9630981] into sparse-5967489-L31900000382779443android-10.0.0_r17
Change-Id: Icf9c2992552c21ee19b634a3b13d993855094a97
Diffstat (limited to 'tests')
-rw-r--r-- | tests/tests/permission/src/android/permission/cts/LocationAccessCheckTest.java | 59 |
1 files changed, 57 insertions, 2 deletions
diff --git a/tests/tests/permission/src/android/permission/cts/LocationAccessCheckTest.java b/tests/tests/permission/src/android/permission/cts/LocationAccessCheckTest.java index 232cd1f50bc..895c6134da0 100644 --- a/tests/tests/permission/src/android/permission/cts/LocationAccessCheckTest.java +++ b/tests/tests/permission/src/android/permission/cts/LocationAccessCheckTest.java @@ -38,6 +38,8 @@ import static org.junit.Assume.assumeTrue; import static java.util.concurrent.TimeUnit.MILLISECONDS; +import android.app.ActivityManager; +import android.app.AppOpsManager; import android.app.UiAutomation; import android.content.ComponentName; import android.content.ContentResolver; @@ -50,6 +52,7 @@ import android.location.Location; import android.location.LocationListener; import android.location.LocationManager; import android.os.Bundle; +import android.os.Debug; import android.os.IBinder; import android.os.Looper; import android.os.ParcelFileDescriptor; @@ -379,6 +382,15 @@ public class LocationAccessCheckTest { } /** + * Disable location access check + */ + private void disableLocationAccessCheck() { + runWithShellPermissionIdentity(() -> DeviceConfig.setProperty( + DeviceConfig.NAMESPACE_PRIVACY, + PROPERTY_LOCATION_ACCESS_CHECK_ENABLED, "false", false)); + } + + /** * Make sure fine location can be accessed at all. */ @Before @@ -507,7 +519,7 @@ public class LocationAccessCheckTest { accessLocation(); getNotification(true); - assertNull(getNotification(false)); + assertNull(getNotification(true)); } @Test @@ -525,7 +537,7 @@ public class LocationAccessCheckTest { grantPermissionToTestApp(ACCESS_BACKGROUND_LOCATION); accessLocation(); - assertNotNull(getNotification(false)); + assertNotNull(getNotification(true)); } @Test @@ -557,6 +569,7 @@ public class LocationAccessCheckTest { eventually(() -> assertNull(getNotification(false)), UNEXPECTED_TIMEOUT_MILLIS); } finally { installBackgroundAccessApp(); + getNotification(true); } } @@ -583,4 +596,46 @@ public class LocationAccessCheckTest { installBackgroundAccessApp(); } } + + @Test + public void noNotificationIfFeatureDisabled() throws Throwable { + disableLocationAccessCheck(); + accessLocation(); + assertNull(getNotification(true)); + } + + @Test + public void notificationOnlyForAccessesSinceFeatureWasEnabled() throws Throwable { + // Disable the feature and access location in disabled state + disableLocationAccessCheck(); + accessLocation(); + assertNull(getNotification(true)); + + // No notification expected for accesses before enabling the feature + enableLocationAccessCheck(); + assertNull(getNotification(true)); + + // Notification expected for access after enabling the feature + accessLocation(); + assertNotNull(getNotification(true)); + } + + @Test + public void noNotificationIfBlamerNotSystemOrLocationProvider() throws Throwable { + // Blame the app for access from an untrusted for notification purposes package. + runWithShellPermissionIdentity(() -> { + AppOpsManager appOpsManager = sContext.getSystemService(AppOpsManager.class); + appOpsManager.noteProxyOpNoThrow(AppOpsManager.OPSTR_FINE_LOCATION, TEST_APP_PKG, + sContext.getPackageManager().getPackageUid(TEST_APP_PKG, 0)); + }); + assertNull(getNotification(true)); + } + + @Test + public void testOpeningLocationSettingsDoesNotTriggerAccess() throws Throwable { + Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS); + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + sContext.startActivity(intent); + assertNull(getNotification(true)); + } } |