Loading services/core/java/com/android/server/location/fudger/LocationFudger.java +2 −2 Original line number Diff line number Diff line Loading @@ -188,8 +188,8 @@ public class LocationFudger { // TODO(b/381204398): To ensure a safe rollout, two algorithms co-exist. The first is the // new density-based algorithm, while the second is the traditional coarsening algorithm. // Once rollout is done, clean up the unused algorithm. if (Flags.densityBasedCoarseLocations() && cacheCopy != null && cacheCopy.hasDefaultValue()) { if (Flags.populationDensityProvider() && Flags.densityBasedCoarseLocations() && cacheCopy != null && cacheCopy.hasDefaultValue()) { int level = cacheCopy.getCoarseningLevel(latitude, longitude); double[] center = snapToCenterOfS2Cell(latitude, longitude, level); latitude = center[S2CellIdUtils.LAT_INDEX]; Loading services/tests/mockingservicestests/src/com/android/server/location/fudger/LocationFudgerTest.java +24 −1 Original line number Diff line number Diff line Loading @@ -176,8 +176,28 @@ public class LocationFudgerTest { } @Test public void testDensityBasedCoarsening_ifFeatureIsDisabled_cacheIsNotUsed() { public void testDensityBasedCoarsening_ifAnyFlagIsOff1_cacheIsNotUsed() { // This feature requires two flags: one for the population density provider (which could // be used by various client), and a second one for actually enabling the new coarsening // algorithm. mSetFlagsRule.disableFlags(Flags.FLAG_DENSITY_BASED_COARSE_LOCATIONS); mSetFlagsRule.enableFlags(Flags.FLAG_POPULATION_DENSITY_PROVIDER); LocationFudgerCache cache = mock(LocationFudgerCache.class); mFudger.setLocationFudgerCache(cache); mFudger.createCoarse(createLocation("test", mRandom)); verify(cache, never()).getCoarseningLevel(anyDouble(), anyDouble()); } @Test public void testDensityBasedCoarsening_ifAnyFlagIsOff2_cacheIsNotUsed() { // This feature requires two flags: one for the population density provider (which could // be used by various client), and a second one for actually enabling the new coarsening // algorithm. mSetFlagsRule.enableFlags(Flags.FLAG_DENSITY_BASED_COARSE_LOCATIONS); mSetFlagsRule.disableFlags(Flags.FLAG_POPULATION_DENSITY_PROVIDER); LocationFudgerCache cache = mock(LocationFudgerCache.class); mFudger.setLocationFudgerCache(cache); Loading @@ -190,6 +210,7 @@ public class LocationFudgerTest { @Test public void testDensityBasedCoarsening_ifFeatureIsEnabledButNoDefaultValue_cacheIsNotUsed() { mSetFlagsRule.enableFlags(Flags.FLAG_DENSITY_BASED_COARSE_LOCATIONS); mSetFlagsRule.enableFlags(Flags.FLAG_POPULATION_DENSITY_PROVIDER); LocationFudgerCache cache = mock(LocationFudgerCache.class); doReturn(false).when(cache).hasDefaultValue(); Loading @@ -203,6 +224,7 @@ public class LocationFudgerTest { @Test public void testDensityBasedCoarsening_ifFeatureIsEnabledAndDefaultIsSet_cacheIsUsed() { mSetFlagsRule.enableFlags(Flags.FLAG_DENSITY_BASED_COARSE_LOCATIONS); mSetFlagsRule.enableFlags(Flags.FLAG_POPULATION_DENSITY_PROVIDER); LocationFudgerCache cache = mock(LocationFudgerCache.class); doReturn(true).when(cache).hasDefaultValue(); Loading @@ -223,6 +245,7 @@ public class LocationFudgerTest { // location/geometry/S2CellIdUtilsTest.java mSetFlagsRule.enableFlags(Flags.FLAG_DENSITY_BASED_COARSE_LOCATIONS); mSetFlagsRule.enableFlags(Flags.FLAG_POPULATION_DENSITY_PROVIDER); // Arbitrary location in Times Square, NYC double[] latLng = new double[] {40.758896, -73.985130}; int s2Level = 1; Loading Loading
services/core/java/com/android/server/location/fudger/LocationFudger.java +2 −2 Original line number Diff line number Diff line Loading @@ -188,8 +188,8 @@ public class LocationFudger { // TODO(b/381204398): To ensure a safe rollout, two algorithms co-exist. The first is the // new density-based algorithm, while the second is the traditional coarsening algorithm. // Once rollout is done, clean up the unused algorithm. if (Flags.densityBasedCoarseLocations() && cacheCopy != null && cacheCopy.hasDefaultValue()) { if (Flags.populationDensityProvider() && Flags.densityBasedCoarseLocations() && cacheCopy != null && cacheCopy.hasDefaultValue()) { int level = cacheCopy.getCoarseningLevel(latitude, longitude); double[] center = snapToCenterOfS2Cell(latitude, longitude, level); latitude = center[S2CellIdUtils.LAT_INDEX]; Loading
services/tests/mockingservicestests/src/com/android/server/location/fudger/LocationFudgerTest.java +24 −1 Original line number Diff line number Diff line Loading @@ -176,8 +176,28 @@ public class LocationFudgerTest { } @Test public void testDensityBasedCoarsening_ifFeatureIsDisabled_cacheIsNotUsed() { public void testDensityBasedCoarsening_ifAnyFlagIsOff1_cacheIsNotUsed() { // This feature requires two flags: one for the population density provider (which could // be used by various client), and a second one for actually enabling the new coarsening // algorithm. mSetFlagsRule.disableFlags(Flags.FLAG_DENSITY_BASED_COARSE_LOCATIONS); mSetFlagsRule.enableFlags(Flags.FLAG_POPULATION_DENSITY_PROVIDER); LocationFudgerCache cache = mock(LocationFudgerCache.class); mFudger.setLocationFudgerCache(cache); mFudger.createCoarse(createLocation("test", mRandom)); verify(cache, never()).getCoarseningLevel(anyDouble(), anyDouble()); } @Test public void testDensityBasedCoarsening_ifAnyFlagIsOff2_cacheIsNotUsed() { // This feature requires two flags: one for the population density provider (which could // be used by various client), and a second one for actually enabling the new coarsening // algorithm. mSetFlagsRule.enableFlags(Flags.FLAG_DENSITY_BASED_COARSE_LOCATIONS); mSetFlagsRule.disableFlags(Flags.FLAG_POPULATION_DENSITY_PROVIDER); LocationFudgerCache cache = mock(LocationFudgerCache.class); mFudger.setLocationFudgerCache(cache); Loading @@ -190,6 +210,7 @@ public class LocationFudgerTest { @Test public void testDensityBasedCoarsening_ifFeatureIsEnabledButNoDefaultValue_cacheIsNotUsed() { mSetFlagsRule.enableFlags(Flags.FLAG_DENSITY_BASED_COARSE_LOCATIONS); mSetFlagsRule.enableFlags(Flags.FLAG_POPULATION_DENSITY_PROVIDER); LocationFudgerCache cache = mock(LocationFudgerCache.class); doReturn(false).when(cache).hasDefaultValue(); Loading @@ -203,6 +224,7 @@ public class LocationFudgerTest { @Test public void testDensityBasedCoarsening_ifFeatureIsEnabledAndDefaultIsSet_cacheIsUsed() { mSetFlagsRule.enableFlags(Flags.FLAG_DENSITY_BASED_COARSE_LOCATIONS); mSetFlagsRule.enableFlags(Flags.FLAG_POPULATION_DENSITY_PROVIDER); LocationFudgerCache cache = mock(LocationFudgerCache.class); doReturn(true).when(cache).hasDefaultValue(); Loading @@ -223,6 +245,7 @@ public class LocationFudgerTest { // location/geometry/S2CellIdUtilsTest.java mSetFlagsRule.enableFlags(Flags.FLAG_DENSITY_BASED_COARSE_LOCATIONS); mSetFlagsRule.enableFlags(Flags.FLAG_POPULATION_DENSITY_PROVIDER); // Arbitrary location in Times Square, NYC double[] latLng = new double[] {40.758896, -73.985130}; int s2Level = 1; Loading