Merge "[Geofence] Write/read entry values to/from satellite block file" into main
diff --git a/src/com/android/phone/satellite/accesscontrol/S2RangeSatelliteOnDeviceAccessController.java b/src/com/android/phone/satellite/accesscontrol/S2RangeSatelliteOnDeviceAccessController.java
index c5ecfd9..845ff18 100644
--- a/src/com/android/phone/satellite/accesscontrol/S2RangeSatelliteOnDeviceAccessController.java
+++ b/src/com/android/phone/satellite/accesscontrol/S2RangeSatelliteOnDeviceAccessController.java
@@ -15,15 +15,11 @@
*/
package com.android.phone.satellite.accesscontrol;
-import static com.android.phone.satellite.accesscontrol.SatelliteAccessController.DEFAULT_REGIONAL_SATELLITE_CONFIG_ID;
-
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.telephony.Rlog;
import com.android.internal.telephony.flags.FeatureFlags;
-import com.android.storage.s2.S2LevelRange;
-
import com.android.telephony.sats2range.read.SatS2RangeFileReader;
import com.android.telephony.sats2range.read.SuffixTableRange;
@@ -178,18 +174,22 @@
@Override
@Nullable
- public Integer getRegionalConfigIdForLocation(LocationToken locationToken)
+ public Integer getRegionalConfigIdForLocation(@NonNull LocationToken locationToken)
throws IOException {
if (!mFeatureFlags.carrierRoamingNbIotNtn()) {
logd("getAccessControlConfigIdForLocation: carrierRoamingNbIotNtn is disabled");
return null;
}
- if (!isSatCommunicationAllowedAtLocation(locationToken)) {
- logd("getRegionalConfigIdForLocation: isSatCommunicationAllowedAtLocation is false");
- return null;
+ if (locationToken instanceof LocationTokenImpl locationTokenImpl) {
+ return getRegionalConfigIdForLocation(locationTokenImpl.getS2CellId());
+ } else {
+ throw new IllegalArgumentException("Unknown locationToken=" + locationToken);
}
+ }
- return DEFAULT_REGIONAL_SATELLITE_CONFIG_ID;
+ private Integer getRegionalConfigIdForLocation(long s2CellId) throws IOException {
+ SuffixTableRange entry = mSatS2RangeFileReader.findEntryByCellId(s2CellId);
+ return (entry == null) ? null : entry.getEntryValue();
}
}
diff --git a/tests/src/com/android/phone/satellite/accesscontrol/S2RangeSatelliteOnDeviceAccessControllerTest.java b/tests/src/com/android/phone/satellite/accesscontrol/S2RangeSatelliteOnDeviceAccessControllerTest.java
index 678d069..27f3ef7 100644
--- a/tests/src/com/android/phone/satellite/accesscontrol/S2RangeSatelliteOnDeviceAccessControllerTest.java
+++ b/tests/src/com/android/phone/satellite/accesscontrol/S2RangeSatelliteOnDeviceAccessControllerTest.java
@@ -16,20 +16,19 @@
package com.android.phone.satellite.accesscontrol;
-import static com.android.phone.satellite.accesscontrol.SatelliteAccessController.DEFAULT_REGIONAL_SATELLITE_CONFIG_ID;
-
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.mockito.Mockito.doReturn;
+import android.annotation.Nullable;
+
import androidx.test.ext.junit.runners.AndroidJUnit4;
import com.android.internal.telephony.flags.FeatureFlags;
-import com.android.storage.s2.S2LevelRange;
-
import com.android.telephony.sats2range.read.SatS2RangeFileFormat;
import com.android.telephony.sats2range.read.SuffixTableRange;
import com.android.telephony.sats2range.utils.TestUtils;
@@ -73,18 +72,42 @@
@Test
public void testSatelliteAccessControl_AllowedList() throws Exception {
- testSatelliteAccessControl(true);
+ testSatelliteAccessControl(true, null);
}
@Test
public void testSatelliteAccessControl_DisallowedList() throws Exception {
- testSatelliteAccessControl(false);
+ testSatelliteAccessControl(false, null);
}
- private void testSatelliteAccessControl(boolean isAllowedList) throws Exception {
+ @Test
+ public void testSatelliteAccessControl_AllowedList_validEntryValue() throws Exception {
+ testSatelliteAccessControl(true, 1);
+ }
+
+ @Test
+ public void testSatelliteAccessControl_DisallowedList_validEntryValue() {
+ assertThrows(IllegalArgumentException.class,
+ () -> testSatelliteAccessControl(false, 1));
+ }
+
+ private void testSatelliteAccessControl(boolean isAllowedList, @Nullable Integer entryValue)
+ throws Exception {
+ final int defaultEntryValue = -1;
+
+ if (!isAllowedList && entryValue != null) {
+ throw new IllegalArgumentException(
+ "isAllowedList must be true when entryValue is present.");
+ }
+
+ List<Integer> expectedConfigIds = List.of(1, 1, 3);
SatS2RangeFileFormat fileFormat = null;
try {
- fileFormat = createSatS2File(mFile, isAllowedList);
+ if (entryValue == null) {
+ fileFormat = createSatS2File(mFile, isAllowedList);
+ } else {
+ fileFormat = createSatS2FileWithEntryValue(mFile, isAllowedList, expectedConfigIds);
+ }
} catch (Exception ex) {
fail("Got unexpected exception in createSatS2File, ex=" + ex);
}
@@ -94,6 +117,10 @@
try {
accessController = SatelliteOnDeviceAccessController.create(mFile, mMockFeatureFlags);
int s2Level = accessController.getS2Level();
+ if (entryValue == null) {
+ expectedConfigIds = List.of(defaultEntryValue, defaultEntryValue,
+ defaultEntryValue);
+ }
// Verify an edge cell of range 1 not in the output file
S2CellId s2CellId = new S2CellId(TestUtils.createCellId(fileFormat, 1, 1000, 999));
@@ -111,12 +138,7 @@
assertTrue(isAllowed != isAllowedList);
Integer configId = accessController.getRegionalConfigIdForLocation(locationToken);
- if (isAllowedList) {
- assertNull(configId);
- } else {
- assertNotNull(configId);
- assertEquals(DEFAULT_REGIONAL_SATELLITE_CONFIG_ID, (int) configId);
- }
+ assertNull(configId);
// Verify cells in range1 present in the output file
for (int suffix = 1000; suffix < 2000; suffix++) {
@@ -130,12 +152,8 @@
assertTrue(isAllowed == isAllowedList);
configId = accessController.getRegionalConfigIdForLocation(locationToken);
- if (isAllowedList) {
- assertNotNull(configId);
- assertEquals(DEFAULT_REGIONAL_SATELLITE_CONFIG_ID, (int) configId);
- } else {
- assertNull(configId);
- }
+ assertNotNull(configId);
+ assertEquals((int) expectedConfigIds.get(0), (int) configId);
}
// Verify the middle cell not in the output file
@@ -147,12 +165,8 @@
assertTrue(isAllowed != isAllowedList);
configId = accessController.getRegionalConfigIdForLocation(locationToken);
- if (isAllowedList) {
- assertNull(configId);
- } else {
- assertNotNull(configId);
- assertEquals(DEFAULT_REGIONAL_SATELLITE_CONFIG_ID, (int) configId);
- }
+ assertNull(configId);
+
// Verify cells in range2 present in the output file
for (int suffix = 2001; suffix < 3000; suffix++) {
@@ -164,12 +178,8 @@
assertTrue(isAllowed == isAllowedList);
configId = accessController.getRegionalConfigIdForLocation(locationToken);
- if (isAllowedList) {
- assertNotNull(configId);
- assertEquals(DEFAULT_REGIONAL_SATELLITE_CONFIG_ID, (int) configId);
- } else {
- assertNull(configId);
- }
+ assertNotNull(configId);
+ assertEquals((int) expectedConfigIds.get(1), (int) configId);
}
// Verify an edge cell of range 2 not in the output file
@@ -181,12 +191,7 @@
assertTrue(isAllowed != isAllowedList);
configId = accessController.getRegionalConfigIdForLocation(locationToken);
- if (isAllowedList) {
- assertNull(configId);
- } else {
- assertNotNull(configId);
- assertEquals(DEFAULT_REGIONAL_SATELLITE_CONFIG_ID, (int) configId);
- }
+ assertNull(configId);
// Verify an edge cell of range 3 not in the output file
s2CellId = new S2CellId(TestUtils.createCellId(fileFormat, 1, 1001, 999));
@@ -197,12 +202,7 @@
assertTrue(isAllowed != isAllowedList);
configId = accessController.getRegionalConfigIdForLocation(locationToken);
- if (isAllowedList) {
- assertNull(configId);
- } else {
- assertNotNull(configId);
- assertEquals(DEFAULT_REGIONAL_SATELLITE_CONFIG_ID, (int) configId);
- }
+ assertNull(configId);
// Verify cells in range1 present in the output file
for (int suffix = 1000; suffix < 2000; suffix++) {
@@ -214,12 +214,8 @@
assertTrue(isAllowed == isAllowedList);
configId = accessController.getRegionalConfigIdForLocation(locationToken);
- if (isAllowedList) {
- assertNotNull(configId);
- assertEquals(DEFAULT_REGIONAL_SATELLITE_CONFIG_ID, (int) configId);
- } else {
- assertNull(configId);
- }
+ assertNotNull(configId);
+ assertEquals((int) expectedConfigIds.get(2), (int) configId);
}
// Verify an edge cell of range 3 not in the output file
@@ -231,12 +227,7 @@
assertTrue(isAllowed != isAllowedList);
configId = accessController.getRegionalConfigIdForLocation(locationToken);
- if (isAllowedList) {
- assertNull(configId);
- } else {
- assertNotNull(configId);
- assertEquals(DEFAULT_REGIONAL_SATELLITE_CONFIG_ID, (int) configId);
- }
+ assertNull(configId);
} catch (Exception ex) {
fail("Unexpected exception when validating the output ex=" + ex);
@@ -247,8 +238,8 @@
}
}
- private SatS2RangeFileFormat createSatS2File(
- File file, boolean isAllowedList) throws Exception {
+ private SatS2RangeFileFormat createSatS2File(File file, boolean isAllowedList)
+ throws Exception {
SatS2RangeFileFormat fileFormat;
SuffixTableRange range1, range2, range3;
try (SatS2RangeFileWriter satS2RangeFileWriter = SatS2RangeFileWriter.open(
@@ -276,4 +267,38 @@
assertTrue(file.length() > 0);
return fileFormat;
}
+
+ private SatS2RangeFileFormat createSatS2FileWithEntryValue(
+ File file, boolean isAllowedList, List<Integer> entryValues) throws Exception {
+
+ SatS2RangeFileFormat fileFormat;
+ SuffixTableRange range1, range2, range3;
+ try (SatS2RangeFileWriter satS2RangeFileWriter = SatS2RangeFileWriter.open(
+ file, TestUtils.createS2RangeFileFormat(isAllowedList, 4, 1))) {
+ fileFormat = satS2RangeFileWriter.getFileFormat();
+
+ // Two ranges that share a prefix.
+ range1 = new SuffixTableRange(
+ TestUtils.createCellId(fileFormat, 1, 1000, 1000),
+ TestUtils.createCellId(fileFormat, 1, 1000, 2000),
+ entryValues.get(0));
+ range2 = new SuffixTableRange(
+ TestUtils.createCellId(fileFormat, 1, 1000, 2001),
+ TestUtils.createCellId(fileFormat, 1, 1000, 3000),
+ entryValues.get(1));
+ // This range has a different prefix, so will be in a different suffix table.
+ range3 = new SuffixTableRange(
+ TestUtils.createCellId(fileFormat, 1, 1001, 1000),
+ TestUtils.createCellId(fileFormat, 1, 1001, 2000),
+ entryValues.get(2));
+
+ List<SuffixTableRange> ranges = new ArrayList<>();
+ ranges.add(range1);
+ ranges.add(range2);
+ ranges.add(range3);
+ satS2RangeFileWriter.createSortedSuffixBlocks(ranges.iterator());
+ }
+ assertTrue(file.length() > 0);
+ return fileFormat;
+ }
}
diff --git a/utils/satellite/s2storage/src/readonly/java/com/android/telephony/sats2range/read/PopulatedSuffixTableBlock.java b/utils/satellite/s2storage/src/readonly/java/com/android/telephony/sats2range/read/PopulatedSuffixTableBlock.java
index 2feccbf..8cb9d1d 100644
--- a/utils/satellite/s2storage/src/readonly/java/com/android/telephony/sats2range/read/PopulatedSuffixTableBlock.java
+++ b/utils/satellite/s2storage/src/readonly/java/com/android/telephony/sats2range/read/PopulatedSuffixTableBlock.java
@@ -58,7 +58,8 @@
SatS2RangeFileFormat fileFormat, IntValueTypedPackedTable packedTable) {
mFileFormat = Objects.requireNonNull(fileFormat);
mPackedTable = Objects.requireNonNull(packedTable);
- mSuffixTableSharedData = SuffixTableSharedData.fromBytes(packedTable.getSharedData());
+ mSuffixTableSharedData = SuffixTableSharedData.fromTypedData(
+ packedTable.getSharedDataAsTyped(), fileFormat);
// Obtain the prefix. All cellIds in this table will share the same prefix except for end
// range values (which are exclusive so can be for mPrefix + 1 with a suffix value of 0).
@@ -189,7 +190,8 @@
endCellIdSuffix = 0;
}
long endCellId = mFileFormat.createCellId(endCellPrefixValue, endCellIdSuffix);
- mSuffixTableRange = new SuffixTableRange(startCellId, endCellId);
+ int entryValue = getEntryValue();
+ mSuffixTableRange = new SuffixTableRange(startCellId, endCellId, entryValue);
}
return mSuffixTableRange;
}
@@ -217,5 +219,9 @@
+ "mSuffixTableEntry=" + mSuffixTableEntry
+ '}';
}
+
+ private int getEntryValue() {
+ return mSuffixTableSharedData.getEntryValue(mSuffixTableEntry.getIndex());
+ }
}
}
diff --git a/utils/satellite/s2storage/src/test/java/com/android/telephony/sats2range/SatS2RangeFileReaderTest.java b/utils/satellite/s2storage/src/test/java/com/android/telephony/sats2range/SatS2RangeFileReaderTest.java
index 2797b77..6de40e1 100644
--- a/utils/satellite/s2storage/src/test/java/com/android/telephony/sats2range/SatS2RangeFileReaderTest.java
+++ b/utils/satellite/s2storage/src/test/java/com/android/telephony/sats2range/SatS2RangeFileReaderTest.java
@@ -17,6 +17,7 @@
package com.android.telephony.sats2range;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
import com.android.telephony.sats2range.read.SatS2RangeFileFormat;
import com.android.telephony.sats2range.read.SatS2RangeFileReader;
@@ -78,4 +79,67 @@
assertEquals(expectedRange3, range3);
}
}
+
+ @Test
+ public void findEntryByCellIdWithEntryValue() throws IOException {
+ final boolean isAllowedList = true;
+ final int entryValueSizeInBytes = 4;
+ final int versionNumber = 0;
+ final int entryValue1 = 1;
+ final int entryValue2 = 2;
+ final int entryValue3 = 3;
+
+ File file = File.createTempFile("test", ".dat");
+ SatS2RangeFileFormat fileFormat;
+
+ SuffixTableRange expectedRange1, expectedRange2, expectedRange3;
+ try (SatS2RangeFileWriter satS2RangeFileWriter = SatS2RangeFileWriter.open(file,
+ TestUtils.createS2RangeFileFormat(isAllowedList, entryValueSizeInBytes,
+ versionNumber))) {
+ fileFormat = satS2RangeFileWriter.getFileFormat();
+
+ // Two ranges that share a prefix.
+ expectedRange1 = new SuffixTableRange(
+ TestUtils.createCellId(fileFormat, 1, 1000, 1000),
+ TestUtils.createCellId(fileFormat, 1, 1000, 2000),
+ entryValue1);
+ expectedRange2 = new SuffixTableRange(
+ TestUtils.createCellId(fileFormat, 1, 1000, 2000),
+ TestUtils.createCellId(fileFormat, 1, 1000, 3000),
+ entryValue2);
+ // This range has a different prefix, so will be in a different suffix table.
+ expectedRange3 = new SuffixTableRange(
+ TestUtils.createCellId(fileFormat, 1, 1001, 1000),
+ TestUtils.createCellId(fileFormat, 1, 1001, 2000),
+ entryValue3);
+
+ List<SuffixTableRange> ranges = new ArrayList<>();
+ ranges.add(expectedRange1);
+ ranges.add(expectedRange2);
+ ranges.add(expectedRange3);
+ satS2RangeFileWriter.createSortedSuffixBlocks(ranges.iterator());
+ }
+
+ try (SatS2RangeFileReader satS2RangeFileReader = SatS2RangeFileReader.open(file)) {
+ assertEquals(isAllowedList, satS2RangeFileReader.isAllowedList());
+
+ SuffixTableRange range1 = satS2RangeFileReader.findEntryByCellId(
+ TestUtils.createCellId(fileFormat, 1, 1000, 1500));
+ assertNotNull(range1);
+ assertEquals(expectedRange1, range1);
+ assertEquals(entryValue1, range1.getEntryValue());
+
+ SuffixTableRange range2 = satS2RangeFileReader.findEntryByCellId(
+ TestUtils.createCellId(fileFormat, 1, 1000, 2500));
+ assertNotNull(range2);
+ assertEquals(expectedRange2, range2);
+ assertEquals(entryValue2, range2.getEntryValue());
+
+ SuffixTableRange range3 = satS2RangeFileReader.findEntryByCellId(
+ TestUtils.createCellId(fileFormat, 1, 1001, 1500));
+ assertNotNull(range3);
+ assertEquals(expectedRange3, range3);
+ assertEquals(entryValue3, range3.getEntryValue());
+ }
+ }
}
diff --git a/utils/satellite/s2storage/src/testutils/java/com/android/telephony/sats2range/testutils/TestUtils.java b/utils/satellite/s2storage/src/testutils/java/com/android/telephony/sats2range/testutils/TestUtils.java
index 3dfc720..ca0b754 100644
--- a/utils/satellite/s2storage/src/testutils/java/com/android/telephony/sats2range/testutils/TestUtils.java
+++ b/utils/satellite/s2storage/src/testutils/java/com/android/telephony/sats2range/testutils/TestUtils.java
@@ -38,6 +38,14 @@
/** Returns a valid {@link SatS2RangeFileFormat}. */
public static SatS2RangeFileFormat createS2RangeFileFormat(boolean isAllowedList) {
+ return createS2RangeFileFormat(isAllowedList,
+ /* entryValueSizeInBytes */0,
+ /* versionNumber */0);
+ }
+
+ /** Returns a valid {@link SatS2RangeFileFormat}. */
+ public static SatS2RangeFileFormat createS2RangeFileFormat(boolean isAllowedList,
+ int entryValueSizeInBytes, int versionNumber) {
int dataS2Level = TEST_S2_LEVEL;
int faceIdBits = 3;
int bitCountPerLevel = 2;
@@ -48,7 +56,8 @@
int suffixTableEntryBitCount = 4 * Byte.SIZE;
int suffixTableBlockIdOffset = 5;
return new SatS2RangeFileFormat(dataS2Level, prefixBitCount, suffixBitCount,
- suffixTableBlockIdOffset, suffixTableEntryBitCount, isAllowedList);
+ suffixTableBlockIdOffset, suffixTableEntryBitCount, isAllowedList,
+ entryValueSizeInBytes, versionNumber);
}
/** Create an S2 cell ID */
diff --git a/utils/satellite/s2storage/src/write/java/com/android/telephony/sats2range/write/SatS2RangeFileWriter.java b/utils/satellite/s2storage/src/write/java/com/android/telephony/sats2range/write/SatS2RangeFileWriter.java
index 3018aec..375707a 100644
--- a/utils/satellite/s2storage/src/write/java/com/android/telephony/sats2range/write/SatS2RangeFileWriter.java
+++ b/utils/satellite/s2storage/src/write/java/com/android/telephony/sats2range/write/SatS2RangeFileWriter.java
@@ -168,36 +168,16 @@
// Add an empty block.
blockWriter = SuffixTableWriter.createEmptyBlockWriter();
} else {
+ List<SuffixTableRange> suffixTableRanges = convertSamePrefixRangesToSuffixTableRanges(
+ samePrefixRanges);
+ List<Integer> entryValues = getEntryValues(suffixTableRanges);
// Create a suffix table block.
- SuffixTableSharedData sharedData = new SuffixTableSharedData(currentPrefix);
+ SuffixTableSharedData sharedData = new SuffixTableSharedData(currentPrefix, entryValues,
+ mFileFormat);
SuffixTableWriter suffixTableWriter =
SuffixTableWriter.createPopulated(mFileFormat, sharedData);
- SuffixTableRange lastRange = null;
- for (SuffixTableRange currentRange : samePrefixRanges) {
- // Validate ranges don't overlap.
- if (lastRange != null) {
- if (lastRange.overlaps(currentRange)) {
- throw new IllegalStateException("lastRange=" + lastRange + " overlaps"
- + " currentRange=" + currentRange);
- }
- }
- lastRange = currentRange;
-
- // Split the range so it fits.
- final int maxRangeLength = mFileFormat.getTableEntryMaxRangeLengthValue();
- long startCellId = currentRange.getStartCellId();
- long endCellId = currentRange.getEndCellId();
- int rangeLength = mFileFormat.calculateRangeLength(startCellId, endCellId);
- while (rangeLength > maxRangeLength) {
- long newEndCellId = S2Support.offsetCellId(startCellId, maxRangeLength);
- SuffixTableRange suffixTableRange = new SuffixTableRange(startCellId,
- newEndCellId);
- suffixTableWriter.addRange(suffixTableRange);
- startCellId = newEndCellId;
- rangeLength = mFileFormat.calculateRangeLength(startCellId, endCellId);
- }
- SuffixTableRange suffixTableRange = new SuffixTableRange(startCellId, endCellId);
- suffixTableWriter.addRange(suffixTableRange);
+ for (SuffixTableRange range : suffixTableRanges) {
+ suffixTableWriter.addRange(range);
}
blockWriter = suffixTableWriter;
}
@@ -237,4 +217,48 @@
public SatS2RangeFileFormat getFileFormat() {
return mFileFormat;
}
+
+ private List<SuffixTableRange> convertSamePrefixRangesToSuffixTableRanges(
+ List<SuffixTableRange> samePrefixRanges) {
+ List<SuffixTableRange> suffixTableRanges = new ArrayList<>();
+ SuffixTableRange lastRange = null;
+ for (SuffixTableRange currentRange : samePrefixRanges) {
+ // Validate ranges don't overlap.
+ if (lastRange != null) {
+ if (lastRange.overlaps(currentRange)) {
+ throw new IllegalStateException("lastRange=" + lastRange + " overlaps"
+ + " currentRange=" + currentRange);
+ }
+ }
+ lastRange = currentRange;
+ int entryValue = currentRange.getEntryValue();
+
+ // Split the range so it fits.
+ final int maxRangeLength = mFileFormat.getTableEntryMaxRangeLengthValue();
+ long startCellId = currentRange.getStartCellId();
+ long endCellId = currentRange.getEndCellId();
+ int rangeLength = mFileFormat.calculateRangeLength(startCellId, endCellId);
+ while (rangeLength > maxRangeLength) {
+ long newEndCellId = S2Support.offsetCellId(startCellId, maxRangeLength);
+ SuffixTableRange suffixTableRange =
+ new SuffixTableRange(startCellId, newEndCellId, entryValue);
+ suffixTableRanges.add(suffixTableRange);
+ startCellId = newEndCellId;
+ rangeLength = mFileFormat.calculateRangeLength(startCellId, endCellId);
+ }
+ SuffixTableRange suffixTableRange =
+ new SuffixTableRange(startCellId, endCellId, entryValue);
+ suffixTableRanges.add(suffixTableRange);
+ }
+ return suffixTableRanges;
+ }
+
+ private List<Integer> getEntryValues(List<SuffixTableRange> suffixTableRanges) {
+ List<Integer> entryValues = new ArrayList<>();
+ for (SuffixTableRange suffixTableRange : suffixTableRanges) {
+ entryValues.add(suffixTableRange.getEntryValue());
+ }
+ return entryValues;
+ }
+
}