From 02be40f9f6e737e573b58635eba7febe7fe43d89 Mon Sep 17 00:00:00 2001 From: Brian Julian Date: Thu, 1 Feb 2024 16:23:55 +0000 Subject: Adds geoid map assets used to calculating expiration distances in AltitudeConverter. Test: FrameworksMockingServicesTests:AltitudeConverterTest Bug: 304375846 Change-Id: If358669f2bf11df52b797220d276a467ff996efc --- .../internal/location/altitude/GeoidMap.java | 33 +++++++++++++--------- 1 file changed, 20 insertions(+), 13 deletions(-) (limited to 'location/java') diff --git a/location/java/com/android/internal/location/altitude/GeoidMap.java b/location/java/com/android/internal/location/altitude/GeoidMap.java index 9bf5689c1028..df9ca97817f7 100644 --- a/location/java/com/android/internal/location/altitude/GeoidMap.java +++ b/location/java/com/android/internal/location/altitude/GeoidMap.java @@ -51,6 +51,10 @@ import java.util.Objects; */ public final class GeoidMap { + private static final String GEOID_HEIGHT_PREFIX = "geoid-height"; + + private static final String EXPIRATION_DISTANCE_PREFIX = "expiration-distance"; + private static final Object GEOID_HEIGHT_PARAMS_LOCK = new Object(); private static final Object EXPIRATION_DISTANCE_PARAMS_LOCK = new Object(); @@ -82,8 +86,7 @@ public final class GeoidMap { public static MapParamsProto getGeoidHeightParams(@NonNull Context context) throws IOException { synchronized (GEOID_HEIGHT_PARAMS_LOCK) { if (sGeoidHeightParams == null) { - // TODO: b/304375846 - Configure with disk tile prefix once resources are updated. - sGeoidHeightParams = parseParams(context); + sGeoidHeightParams = parseParams(context, GEOID_HEIGHT_PREFIX); } return sGeoidHeightParams; } @@ -99,17 +102,17 @@ public final class GeoidMap { throws IOException { synchronized (EXPIRATION_DISTANCE_PARAMS_LOCK) { if (sExpirationDistanceParams == null) { - // TODO: b/304375846 - Configure with disk tile prefix once resources are updated. - sExpirationDistanceParams = parseParams(context); + sExpirationDistanceParams = parseParams(context, EXPIRATION_DISTANCE_PREFIX); } return sExpirationDistanceParams; } } @NonNull - private static MapParamsProto parseParams(@NonNull Context context) throws IOException { + private static MapParamsProto parseParams(@NonNull Context context, @NonNull String prefix) + throws IOException { try (InputStream is = context.getApplicationContext().getAssets().open( - "geoid_height_map/map-params.pb")) { + "geoid_map/" + prefix + "-params.pb")) { return MapParamsProto.parseFrom(is.readAllBytes()); } } @@ -267,7 +270,8 @@ public final class GeoidMap { @NonNull public double[] readGeoidHeights(@NonNull MapParamsProto params, @NonNull Context context, @NonNull long[] s2CellIds) throws IOException { - return readMapValues(params, context, s2CellIds, mGeoidHeightCacheTiles); + return readMapValues(params, context, s2CellIds, mGeoidHeightCacheTiles, + GEOID_HEIGHT_PREFIX); } /** @@ -278,7 +282,8 @@ public final class GeoidMap { @NonNull public double[] readExpirationDistances(@NonNull MapParamsProto params, @NonNull Context context, @NonNull long[] s2CellIds) throws IOException { - return readMapValues(params, context, s2CellIds, mExpirationDistanceCacheTiles); + return readMapValues(params, context, s2CellIds, mExpirationDistanceCacheTiles, + EXPIRATION_DISTANCE_PREFIX); } /** @@ -288,15 +293,16 @@ public final class GeoidMap { */ @NonNull private static double[] readMapValues(@NonNull MapParamsProto params, @NonNull Context context, - @NonNull long[] s2CellIds, @NonNull LruCache cacheTiles) - throws IOException { + @NonNull long[] s2CellIds, @NonNull LruCache cacheTiles, + @NonNull String prefix) throws IOException { validate(params, s2CellIds); double[] mapValuesMeters = new double[s2CellIds.length]; if (getMapValues(params, cacheTiles::get, s2CellIds, mapValuesMeters)) { return mapValuesMeters; } - TileFunction loadedTiles = loadFromCacheAndDisk(params, context, s2CellIds, cacheTiles); + TileFunction loadedTiles = loadFromCacheAndDisk(params, context, s2CellIds, cacheTiles, + prefix); if (getMapValues(params, loadedTiles, s2CellIds, mapValuesMeters)) { return mapValuesMeters; } @@ -338,7 +344,8 @@ public final class GeoidMap { @NonNull private static TileFunction loadFromCacheAndDisk(@NonNull MapParamsProto params, @NonNull Context context, @NonNull long[] s2CellIds, - @NonNull LruCache cacheTiles) throws IOException { + @NonNull LruCache cacheTiles, @NonNull String prefix) + throws IOException { int len = s2CellIds.length; // Enable batch loading by finding all cache keys upfront. @@ -374,7 +381,7 @@ public final class GeoidMap { S2TileProto tile; try (InputStream is = context.getApplicationContext().getAssets().open( - "geoid_height_map/tile-" + diskTokens[i] + ".pb")) { + "geoid_map/" + prefix + "-disk-tile-" + diskTokens[i] + ".pb")) { tile = S2TileProto.parseFrom(is.readAllBytes()); } mergeFromDiskTile(params, tile, cacheKeys, diskTokens, i, loadedTiles, cacheTiles); -- cgit v1.2.3-59-g8ed1b