Loading services/core/java/com/android/server/location/provider/LocationProviderManager.java +34 −0 Original line number Diff line number Diff line Loading @@ -1607,6 +1607,8 @@ public class LocationProviderManager extends public @Nullable Location getLastLocation(LastLocationRequest request, CallerIdentity identity, @PermissionLevel int permissionLevel) { request = calculateLastLocationRequest(request); if (!isActive(request.isBypass(), identity)) { return null; } Loading Loading @@ -1634,6 +1636,38 @@ public class LocationProviderManager extends return location; } private LastLocationRequest calculateLastLocationRequest(LastLocationRequest baseRequest) { LastLocationRequest.Builder builder = new LastLocationRequest.Builder(baseRequest); boolean locationSettingsIgnored = baseRequest.isLocationSettingsIgnored(); if (locationSettingsIgnored) { // if we are not currently allowed use location settings ignored, disable it if (!mSettingsHelper.getIgnoreSettingsAllowlist().contains( getIdentity().getPackageName(), getIdentity().getAttributionTag()) && !mLocationManagerInternal.isProvider(null, getIdentity())) { locationSettingsIgnored = false; } builder.setLocationSettingsIgnored(locationSettingsIgnored); } boolean adasGnssBypass = baseRequest.isAdasGnssBypass(); if (adasGnssBypass) { // if we are not currently allowed use adas gnss bypass, disable it if (!GPS_PROVIDER.equals(mName)) { Log.e(TAG, "adas gnss bypass request received in non-gps provider"); adasGnssBypass = false; } else if (!mLocationSettings.getUserSettings( getIdentity().getUserId()).isAdasGnssLocationEnabled()) { adasGnssBypass = false; } builder.setAdasGnssBypass(adasGnssBypass); } return builder.build(); } /** * This function does not perform any permissions or safety checks, by calling it you are * committing to performing all applicable checks yourself. This always returns a "fine" Loading services/tests/mockingservicestests/src/com/android/server/location/provider/LocationProviderManagerTest.java +12 −0 Original line number Diff line number Diff line Loading @@ -333,6 +333,10 @@ public class LocationProviderManagerTest { @Test public void testGetLastLocation_Bypass() { mInjector.getSettingsHelper().setIgnoreSettingsAllowlist( new PackageTagsList.Builder().add( IDENTITY.getPackageName()).build()); assertThat(mManager.getLastLocation(new LastLocationRequest.Builder().build(), IDENTITY, PERMISSION_FINE)).isNull(); assertThat(mManager.getLastLocation( Loading Loading @@ -381,6 +385,14 @@ public class LocationProviderManagerTest { new LastLocationRequest.Builder().setLocationSettingsIgnored(true).build(), IDENTITY, PERMISSION_FINE)).isEqualTo( loc); mInjector.getSettingsHelper().setIgnoreSettingsAllowlist( new PackageTagsList.Builder().build()); mProvider.setProviderAllowed(false); assertThat(mManager.getLastLocation( new LastLocationRequest.Builder().setLocationSettingsIgnored(true).build(), IDENTITY, PERMISSION_FINE)).isNull(); } @Test Loading Loading
services/core/java/com/android/server/location/provider/LocationProviderManager.java +34 −0 Original line number Diff line number Diff line Loading @@ -1607,6 +1607,8 @@ public class LocationProviderManager extends public @Nullable Location getLastLocation(LastLocationRequest request, CallerIdentity identity, @PermissionLevel int permissionLevel) { request = calculateLastLocationRequest(request); if (!isActive(request.isBypass(), identity)) { return null; } Loading Loading @@ -1634,6 +1636,38 @@ public class LocationProviderManager extends return location; } private LastLocationRequest calculateLastLocationRequest(LastLocationRequest baseRequest) { LastLocationRequest.Builder builder = new LastLocationRequest.Builder(baseRequest); boolean locationSettingsIgnored = baseRequest.isLocationSettingsIgnored(); if (locationSettingsIgnored) { // if we are not currently allowed use location settings ignored, disable it if (!mSettingsHelper.getIgnoreSettingsAllowlist().contains( getIdentity().getPackageName(), getIdentity().getAttributionTag()) && !mLocationManagerInternal.isProvider(null, getIdentity())) { locationSettingsIgnored = false; } builder.setLocationSettingsIgnored(locationSettingsIgnored); } boolean adasGnssBypass = baseRequest.isAdasGnssBypass(); if (adasGnssBypass) { // if we are not currently allowed use adas gnss bypass, disable it if (!GPS_PROVIDER.equals(mName)) { Log.e(TAG, "adas gnss bypass request received in non-gps provider"); adasGnssBypass = false; } else if (!mLocationSettings.getUserSettings( getIdentity().getUserId()).isAdasGnssLocationEnabled()) { adasGnssBypass = false; } builder.setAdasGnssBypass(adasGnssBypass); } return builder.build(); } /** * This function does not perform any permissions or safety checks, by calling it you are * committing to performing all applicable checks yourself. This always returns a "fine" Loading
services/tests/mockingservicestests/src/com/android/server/location/provider/LocationProviderManagerTest.java +12 −0 Original line number Diff line number Diff line Loading @@ -333,6 +333,10 @@ public class LocationProviderManagerTest { @Test public void testGetLastLocation_Bypass() { mInjector.getSettingsHelper().setIgnoreSettingsAllowlist( new PackageTagsList.Builder().add( IDENTITY.getPackageName()).build()); assertThat(mManager.getLastLocation(new LastLocationRequest.Builder().build(), IDENTITY, PERMISSION_FINE)).isNull(); assertThat(mManager.getLastLocation( Loading Loading @@ -381,6 +385,14 @@ public class LocationProviderManagerTest { new LastLocationRequest.Builder().setLocationSettingsIgnored(true).build(), IDENTITY, PERMISSION_FINE)).isEqualTo( loc); mInjector.getSettingsHelper().setIgnoreSettingsAllowlist( new PackageTagsList.Builder().build()); mProvider.setProviderAllowed(false); assertThat(mManager.getLastLocation( new LastLocationRequest.Builder().setLocationSettingsIgnored(true).build(), IDENTITY, PERMISSION_FINE)).isNull(); } @Test Loading