Merge "Return default value if fingerprint doesn't match" into main am: 093e0a8a62 am: bf19afe3b3
Original change: https://android-review.googlesource.com/c/platform/build/+/3392085
Change-Id: Ieea9fab34a5b436e6ded23c663b5e34cc71586ae
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
diff --git a/tools/aconfig/TEST_MAPPING b/tools/aconfig/TEST_MAPPING
index 043a956..a7f0a4f 100644
--- a/tools/aconfig/TEST_MAPPING
+++ b/tools/aconfig/TEST_MAPPING
@@ -102,9 +102,7 @@
{
// aconfig_storage file java integration tests
"name": "aconfig_storage_file.test.java"
- }
- ],
- "postsubmit": [
+ },
{
// aconfig_storage read functional test
"name": "aconfig_storage_read_functional"
diff --git a/tools/aconfig/aconfig/src/codegen/java.rs b/tools/aconfig/aconfig/src/codegen/java.rs
index 81cbcf4..7aff4e9 100644
--- a/tools/aconfig/aconfig/src/codegen/java.rs
+++ b/tools/aconfig/aconfig/src/codegen/java.rs
@@ -543,7 +543,6 @@
import android.compat.annotation.UnsupportedAppUsage;
import android.os.Build;
import android.os.flagging.PlatformAconfigPackageInternal;
- import android.os.flagging.AconfigStorageReadException;
import android.util.Log;
/** @hide */
public final class FeatureFlagsImpl implements FeatureFlags {
@@ -556,38 +555,16 @@
private void init() {
try {
PlatformAconfigPackageInternal reader = PlatformAconfigPackageInternal.load("system", "com.android.aconfig.test", 0x5081CE7221C77064L);
- AconfigStorageReadException error = reader.getException();
- if (error == null) {
- disabledRw = reader.getBooleanFlagValue(0);
- disabledRwExported = reader.getBooleanFlagValue(1);
- enabledRw = reader.getBooleanFlagValue(7);
- disabledRwInOtherNamespace = reader.getBooleanFlagValue(2);
- } else if (Build.VERSION.SDK_INT > 35 && error.getErrorCode() == 5 /* fingerprint doesn't match*/) {
- disabledRw = reader.getBooleanFlagValue("disabled_rw", false);
- disabledRwExported = reader.getBooleanFlagValue("disabled_rw_exported", false);
- enabledRw = reader.getBooleanFlagValue("enabled_rw", true);
- disabledRwInOtherNamespace = reader.getBooleanFlagValue("disabled_rw_in_other_namespace", false);
- } else {
- if (error.getMessage() != null) {
- Log.e(TAG, error.getMessage());
- } else {
- Log.e(TAG, "Encountered a null AconfigStorageReadException");
- }
- }
+ disabledRw = reader.getBooleanFlagValue(0);
+ disabledRwExported = reader.getBooleanFlagValue(1);
+ enabledRw = reader.getBooleanFlagValue(7);
+ disabledRwInOtherNamespace = reader.getBooleanFlagValue(2);
} catch (Exception e) {
- if (e.getMessage() != null) {
- Log.e(TAG, e.getMessage());
- } else {
- Log.e(TAG, "Encountered a null Exception");
- }
+ Log.e(TAG, e.toString());
} catch (NoClassDefFoundError e) {
// for mainline module running on older devices.
// This should be replaces to version check, after the version bump.
- if (e.getMessage() != null) {
- Log.e(TAG, e.getMessage());
- } else {
- Log.e(TAG, "Encountered a null NoClassDefFoundError");
- }
+ Log.e(TAG, e.toString());
}
isCached = true;
}
diff --git a/tools/aconfig/aconfig/templates/FeatureFlagsImpl.java.template b/tools/aconfig/aconfig/templates/FeatureFlagsImpl.java.template
index 3fc444a..b605e72 100644
--- a/tools/aconfig/aconfig/templates/FeatureFlagsImpl.java.template
+++ b/tools/aconfig/aconfig/templates/FeatureFlagsImpl.java.template
@@ -11,7 +11,6 @@
{{ -else }}
import android.os.flagging.AconfigPackageInternal;
{{ -endif }}
-import android.os.flagging.AconfigStorageReadException;
import android.util.Log;
{{ -endif }}
/** @hide */
@@ -32,44 +31,19 @@
{{ -else }}
AconfigPackageInternal reader = AconfigPackageInternal.load("{container}", "{package_name}", {package_fingerprint});
{{ -endif }}
- AconfigStorageReadException error = reader.getException();
- if (error == null) \{
- {{ for namespace_with_flags in namespace_flags }}
- {{ -for flag in namespace_with_flags.flags }}
- {{ -if flag.is_read_write }}
- {flag.method_name} = reader.getBooleanFlagValue({flag.flag_offset});
- {{ endif }}
- {{ -endfor }}
- {{ -endfor }}
- } else if (Build.VERSION.SDK_INT > 35 && error.getErrorCode() == 5 /* fingerprint doesn't match*/) \{
- {{ for namespace_with_flags in namespace_flags }}
- {{ -for flag in namespace_with_flags.flags }}
- {{ -if flag.is_read_write }}
- {flag.method_name} = reader.getBooleanFlagValue("{flag.flag_name}", {flag.default_value});
- {{ -endif }}
- {{ -endfor }}
- {{ -endfor }}
- } else \{
- if (error.getMessage() != null) \{
- Log.e(TAG, error.getMessage());
- } else \{
- Log.e(TAG, "Encountered a null AconfigStorageReadException");
- }
- }
+ {{ -for namespace_with_flags in namespace_flags }}
+ {{ -for flag in namespace_with_flags.flags }}
+ {{ -if flag.is_read_write }}
+ {flag.method_name} = reader.getBooleanFlagValue({flag.flag_offset});
+ {{ -endif }}
+ {{ -endfor }}
+ {{ -endfor }}
} catch (Exception e) \{
- if (e.getMessage() != null) \{
- Log.e(TAG, e.getMessage());
- } else \{
- Log.e(TAG, "Encountered a null Exception");
- }
+ Log.e(TAG, e.toString());
} catch (NoClassDefFoundError e) \{
// for mainline module running on older devices.
// This should be replaces to version check, after the version bump.
- if (e.getMessage() != null) \{
- Log.e(TAG, e.getMessage());
- } else \{
- Log.e(TAG, "Encountered a null NoClassDefFoundError");
- }
+ Log.e(TAG, e.toString());
}
isCached = true;
}
diff --git a/tools/aconfig/aconfig_storage_file/tests/srcs/StorageFileProviderTest.java b/tools/aconfig/aconfig_storage_file/tests/srcs/StorageFileProviderTest.java
index a820970..c2720f9 100644
--- a/tools/aconfig/aconfig_storage_file/tests/srcs/StorageFileProviderTest.java
+++ b/tools/aconfig/aconfig_storage_file/tests/srcs/StorageFileProviderTest.java
@@ -58,10 +58,6 @@
new StorageFileProvider(TestDataUtils.TESTDATA_PATH, TestDataUtils.TESTDATA_PATH);
PackageTable pt = p.getPackageTable("mock.v1");
assertNotNull(pt);
- pt =
- StorageFileProvider.getPackageTable(
- Paths.get(TestDataUtils.TESTDATA_PATH, "mock.v1.package.map"));
- assertNotNull(pt);
FlagTable f = p.getFlagTable("mock.v1");
assertNotNull(f);
FlagValueList v = p.getFlagValueList("mock.v1");
diff --git a/tools/aconfig/aconfig_storage_read_api/srcs/android/os/flagging/PlatformAconfigPackageInternal.java b/tools/aconfig/aconfig_storage_read_api/srcs/android/os/flagging/PlatformAconfigPackageInternal.java
index e6b6db4..d73d9eb 100644
--- a/tools/aconfig/aconfig_storage_read_api/srcs/android/os/flagging/PlatformAconfigPackageInternal.java
+++ b/tools/aconfig/aconfig_storage_read_api/srcs/android/os/flagging/PlatformAconfigPackageInternal.java
@@ -17,7 +17,6 @@
package android.os.flagging;
import android.aconfig.storage.AconfigStorageException;
-import android.aconfig.storage.FlagTable;
import android.aconfig.storage.FlagValueList;
import android.aconfig.storage.PackageTable;
import android.aconfig.storage.StorageFileProvider;
@@ -41,75 +40,13 @@
*/
public class PlatformAconfigPackageInternal {
- private final FlagTable mFlagTable;
private final FlagValueList mFlagValueList;
- private final int mPackageId;
private final int mPackageBooleanStartOffset;
- private final AconfigStorageReadException mException;
private PlatformAconfigPackageInternal(
- FlagValueList flagValueList,
- FlagTable flagTable,
- int packageBooleanStartOffset,
- int packageId,
- AconfigStorageReadException exception) {
+ FlagValueList flagValueList, int packageBooleanStartOffset) {
this.mFlagValueList = flagValueList;
- this.mFlagTable = flagTable;
this.mPackageBooleanStartOffset = packageBooleanStartOffset;
- this.mPackageId = packageId;
- this.mException = exception;
- }
-
- /**
- * Loads an Aconfig Package from platform Aconfig Storage.
- *
- * <p>This method is intended for internal use only and may be changed or removed without
- * notice.
- *
- * <p>This method loads the specified Aconfig Package from the given container.
- *
- * <p>AconfigStorageException will be stored if there is an error reading from Aconfig Storage.
- * The specific error code can be got using {@link #getException()}.
- *
- * @param container The name of the container.
- * @param packageName The name of the Aconfig package to load.
- * @return An instance of {@link PlatformAconfigPackageInternal}
- * @hide
- */
- @UnsupportedAppUsage
- public static PlatformAconfigPackageInternal load(String container, String packageName) {
- return load(container, packageName, StorageFileProvider.getDefaultProvider());
- }
-
- /** @hide */
- public static PlatformAconfigPackageInternal load(
- String container, String packageName, StorageFileProvider fileProvider) {
- StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads();
- try {
- PackageTable.Node pNode = fileProvider.getPackageTable(container).get(packageName);
-
- if (pNode == null) {
- return createExceptionInstance(
- AconfigStorageException.ERROR_PACKAGE_NOT_FOUND,
- "package "
- + packageName
- + " in container "
- + container
- + " cannot be found on the device");
- }
-
- return new PlatformAconfigPackageInternal(
- fileProvider.getFlagValueList(container),
- fileProvider.getFlagTable(container),
- pNode.getBooleanStartIndex(),
- pNode.getPackageId(),
- null);
-
- } catch (AconfigStorageException e) {
- return createExceptionInstance(e.getErrorCode(), e.getMessage());
- } finally {
- StrictMode.setThreadPolicy(oldPolicy);
- }
}
/**
@@ -118,9 +55,6 @@
* <p>This method is intended for internal use only and may be changed or removed without
* notice.
*
- * <p>AconfigStorageException will be stored if there is an error reading from Aconfig Storage.
- * The specific error code can be got using {@link #getException()}.
- *
* @param container The name of the container.
* @param packageName The name of the Aconfig package.
* @param packageFingerprint The expected fingerprint of the package.
@@ -145,48 +79,40 @@
long packageFingerprint,
StorageFileProvider fileProvider) {
StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads();
+ PackageTable.Node pNode = null;
+ FlagValueList vList = null;
try {
- PackageTable.Node pNode = fileProvider.getPackageTable(container).get(packageName);
-
- if (pNode == null) {
- return createExceptionInstance(
- AconfigStorageReadException.ERROR_PACKAGE_NOT_FOUND,
- "package "
- + packageName
- + " in container "
- + container
- + " cannot be found on the device");
- }
-
- if (pNode.hasPackageFingerprint()
- && packageFingerprint != pNode.getPackageFingerprint()) {
- return new PlatformAconfigPackageInternal(
- fileProvider.getFlagValueList(container),
- fileProvider.getFlagTable(container),
- pNode.getBooleanStartIndex(),
- pNode.getPackageId(),
- new AconfigStorageReadException(
- AconfigStorageException.ERROR_FILE_FINGERPRINT_MISMATCH,
- "The fingerprint provided for the Aconfig package "
- + packageName
- + " in container "
- + container
- + " does not match"
- + " the fingerprint of the package found on the device."));
- }
-
- return new PlatformAconfigPackageInternal(
- fileProvider.getFlagValueList(container),
- null,
- pNode.getBooleanStartIndex(),
- 0,
- null);
-
+ pNode = fileProvider.getPackageTable(container).get(packageName);
+ vList = fileProvider.getFlagValueList(container);
} catch (AconfigStorageException e) {
- return createExceptionInstance(e.getErrorCode(), e.getMessage());
+ throw new AconfigStorageReadException(e.getErrorCode(), e.toString());
} finally {
StrictMode.setThreadPolicy(oldPolicy);
}
+
+ if (pNode == null || vList == null) {
+ throw new AconfigStorageReadException(
+ AconfigStorageReadException.ERROR_PACKAGE_NOT_FOUND,
+ String.format(
+ "package "
+ + packageName
+ + " in container "
+ + container
+ + " cannot be found on the device"));
+ }
+
+ if (pNode.hasPackageFingerprint() && packageFingerprint != pNode.getPackageFingerprint()) {
+ throw new AconfigStorageReadException(
+ 5, // AconfigStorageReadException.ERROR_FILE_FINGERPRINT_MISMATCH,
+ String.format(
+ "package "
+ + packageName
+ + " in container "
+ + container
+ + " cannot be found on the device"));
+ }
+
+ return new PlatformAconfigPackageInternal(vList, pNode.getBooleanStartIndex());
}
/**
@@ -198,10 +124,6 @@
* <p>This method retrieves the value of a flag within the loaded Aconfig package using its
* index. The index is generated at build time and may vary between builds.
*
- * <p>To ensure you are using the correct index, verify that the package's fingerprint matches
- * the expected fingerprint before calling this method. If the fingerprints do not match, use
- * {@link #getBooleanFlagValue(String, boolean)} instead.
- *
* @param index The index of the flag within the package.
* @return The boolean value of the flag.
* @hide
@@ -210,55 +132,4 @@
public boolean getBooleanFlagValue(int index) {
return mFlagValueList.getBoolean(index + mPackageBooleanStartOffset);
}
-
- /**
- * Retrieves the value of a boolean flag using its name.
- *
- * <p>This method is intended for internal use only and may be changed or removed without
- * notice.
- *
- * <p>This method retrieves the value of a flag within the loaded Aconfig package using its
- * name.
- *
- * @param flagName The name of the flag.
- * @param defaultValue The default value to return if the flag is not found.
- * @return The boolean value of the flag.
- * @hide
- */
- @UnsupportedAppUsage
- public boolean getBooleanFlagValue(String flagName, boolean defaultValue) {
- FlagTable.Node fNode = mFlagTable.get(mPackageId, flagName);
- if (fNode == null) {
- return defaultValue;
- }
- return mFlagValueList.getBoolean(fNode.getFlagIndex() + mPackageBooleanStartOffset);
- }
-
- /**
- * Returns any exception that occurred during the loading of the Aconfig package.
- *
- * <p>This method is intended for internal use only and may be changed or removed without
- * notice.
- *
- * @return The exception that occurred, or {@code null} if no exception occurred.
- * @hide
- */
- @UnsupportedAppUsage
- public AconfigStorageReadException getException() {
- return mException;
- }
-
- /**
- * Creates a new {@link PlatformAconfigPackageInternal} instance with an {@link
- * AconfigStorageException}.
- *
- * @param errorCode The error code for the exception.
- * @param message The error message for the exception.
- * @return A new {@link PlatformAconfigPackageInternal} instance with the specified exception.
- */
- private static PlatformAconfigPackageInternal createExceptionInstance(
- int errorCode, String message) {
- return new PlatformAconfigPackageInternal(
- null, null, 0, 0, new AconfigStorageReadException(errorCode, message));
- }
}
diff --git a/tools/aconfig/aconfig_storage_read_api/tests/functional/srcs/PlatformAconfigPackageInternalTest.java b/tools/aconfig/aconfig_storage_read_api/tests/functional/srcs/PlatformAconfigPackageInternalTest.java
index c4a5560..69e224b 100644
--- a/tools/aconfig/aconfig_storage_read_api/tests/functional/srcs/PlatformAconfigPackageInternalTest.java
+++ b/tools/aconfig/aconfig_storage_read_api/tests/functional/srcs/PlatformAconfigPackageInternalTest.java
@@ -16,18 +16,17 @@
package android.aconfig.storage.test;
-import static android.aconfig.nano.Aconfig.ENABLED;
-
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertThrows;
import android.aconfig.DeviceProtos;
+import android.aconfig.nano.Aconfig;
import android.aconfig.nano.Aconfig.parsed_flag;
-import android.aconfig.storage.AconfigStorageException;
import android.aconfig.storage.FlagTable;
import android.aconfig.storage.FlagValueList;
import android.aconfig.storage.PackageTable;
import android.aconfig.storage.StorageFileProvider;
+import android.os.flagging.AconfigStorageReadException;
import android.os.flagging.PlatformAconfigPackageInternal;
import org.junit.Test;
@@ -52,41 +51,9 @@
StorageFileProvider fp = StorageFileProvider.getDefaultProvider();
for (parsed_flag flag : flags) {
-
- String container = flag.container;
- String packageName = flag.package_;
- String flagName = flag.name;
- if (!PLATFORM_CONTAINERS.contains(container)) continue;
-
- PackageTable pTable = fp.getPackageTable(container);
- PackageTable.Node pNode = pTable.get(packageName);
- FlagTable fTable = fp.getFlagTable(container);
- FlagTable.Node fNode = fTable.get(pNode.getPackageId(), flagName);
- FlagValueList fList = fp.getFlagValueList(container);
-
- int index = pNode.getBooleanStartIndex() + fNode.getFlagIndex();
- boolean rVal = fList.getBoolean(index);
-
- PlatformAconfigPackageInternal reader = readerMap.get(packageName);
- if (reader == null) {
- reader = PlatformAconfigPackageInternal.load(container, packageName);
- assertNull(reader.getException());
- readerMap.put(packageName, reader);
+ if (flag.permission == Aconfig.READ_ONLY && flag.state == Aconfig.DISABLED) {
+ continue;
}
- boolean jVal = reader.getBooleanFlagValue(flagName, !rVal);
-
- assertEquals(rVal, jVal);
- }
- }
-
- @Test
- public void testPlatformAconfigPackageInternal_load_with_fingerprint() throws IOException {
- List<parsed_flag> flags = DeviceProtos.loadAndParseFlagProtos();
- Map<String, PlatformAconfigPackageInternal> readerMap = new HashMap<>();
- StorageFileProvider fp = StorageFileProvider.getDefaultProvider();
-
- for (parsed_flag flag : flags) {
-
String container = flag.container;
String packageName = flag.package_;
String flagName = flag.name;
@@ -106,7 +73,6 @@
PlatformAconfigPackageInternal reader = readerMap.get(packageName);
if (reader == null) {
reader = PlatformAconfigPackageInternal.load(container, packageName, fingerprint);
- assertNull(reader.getException());
readerMap.put(packageName, reader);
}
boolean jVal = reader.getBooleanFlagValue(fNode.getFlagIndex());
@@ -118,17 +84,20 @@
@Test
public void testAconfigPackage_load_withError() throws IOException {
// container not found fake_container
- PlatformAconfigPackageInternal aPackage =
- PlatformAconfigPackageInternal.load("fake_container", "fake_package", 0);
- assertEquals(
- AconfigStorageException.ERROR_CANNOT_READ_STORAGE_FILE,
- aPackage.getException().getErrorCode());
+ AconfigStorageReadException e =
+ assertThrows(
+ AconfigStorageReadException.class,
+ () ->
+ PlatformAconfigPackageInternal.load(
+ "fake_container", "fake_package", 0));
+ assertEquals(AconfigStorageReadException.ERROR_CANNOT_READ_STORAGE_FILE, e.getErrorCode());
// package not found
- aPackage = PlatformAconfigPackageInternal.load("system", "fake_container", 0);
- assertEquals(
- AconfigStorageException.ERROR_PACKAGE_NOT_FOUND,
- aPackage.getException().getErrorCode());
+ e =
+ assertThrows(
+ AconfigStorageReadException.class,
+ () -> PlatformAconfigPackageInternal.load("system", "fake_container", 0));
+ assertEquals(AconfigStorageReadException.ERROR_PACKAGE_NOT_FOUND, e.getErrorCode());
// fingerprint doesn't match
List<parsed_flag> flags = DeviceProtos.loadAndParseFlagProtos();
@@ -138,18 +107,22 @@
String container = flag.container;
String packageName = flag.package_;
- boolean value = flag.state == ENABLED;
+ boolean value = flag.state == Aconfig.ENABLED;
PackageTable pTable = fp.getPackageTable(container);
PackageTable.Node pNode = pTable.get(packageName);
if (pNode.hasPackageFingerprint()) {
long fingerprint = pNode.getPackageFingerprint();
- aPackage = PlatformAconfigPackageInternal.load(container, packageName, fingerprint + 1);
+ e =
+ assertThrows(
+ AconfigStorageReadException.class,
+ () ->
+ PlatformAconfigPackageInternal.load(
+ container, packageName, fingerprint + 1));
assertEquals(
// AconfigStorageException.ERROR_FILE_FINGERPRINT_MISMATCH,
- 5, aPackage.getException().getErrorCode());
- assertEquals(aPackage.getBooleanFlagValue(flag.name, !value), value);
+ 5, e.getErrorCode());
}
}
}
diff --git a/tools/aconfig/aconfig_storage_read_api/tests/unit/srcs/PlatformAconfigPackageInternalTest.java b/tools/aconfig/aconfig_storage_read_api/tests/unit/srcs/PlatformAconfigPackageInternalTest.java
index ce3786a..961f0ea 100644
--- a/tools/aconfig/aconfig_storage_read_api/tests/unit/srcs/PlatformAconfigPackageInternalTest.java
+++ b/tools/aconfig/aconfig_storage_read_api/tests/unit/srcs/PlatformAconfigPackageInternalTest.java
@@ -18,12 +18,12 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
-import android.aconfig.storage.AconfigStorageException;
import android.aconfig.storage.PackageTable;
import android.aconfig.storage.StorageFileProvider;
+import android.os.flagging.AconfigStorageReadException;
import android.os.flagging.PlatformAconfigPackageInternal;
import org.junit.Before;
@@ -46,137 +46,101 @@
@Test
public void testLoad_container_package() throws Exception {
+ PackageTable packageTable = pr.getPackageTable("mockup");
+
+ PackageTable.Node node1 = packageTable.get("com.android.aconfig.storage.test_1");
+
+ long fingerprint = node1.getPackageFingerprint();
PlatformAconfigPackageInternal p =
PlatformAconfigPackageInternal.load(
- "mockup", "com.android.aconfig.storage.test_1", pr);
- assertNull(p.getException());
+ "mockup", "com.android.aconfig.storage.test_1", fingerprint, pr);
}
@Test
public void testLoad_container_package_error() throws Exception {
+ PackageTable packageTable = pr.getPackageTable("mockup");
+ PackageTable.Node node1 = packageTable.get("com.android.aconfig.storage.test_1");
+ long fingerprint = node1.getPackageFingerprint();
// cannot find package
- PlatformAconfigPackageInternal p =
- PlatformAconfigPackageInternal.load(
- "mockup", "com.android.aconfig.storage.test_10", pr);
-
- assertEquals(
- AconfigStorageException.ERROR_PACKAGE_NOT_FOUND,
- p.getException().getErrorCode());
+ AconfigStorageReadException e =
+ assertThrows(
+ AconfigStorageReadException.class,
+ () ->
+ PlatformAconfigPackageInternal.load(
+ "mockup",
+ "com.android.aconfig.storage.test_10",
+ fingerprint,
+ pr));
+ assertEquals(AconfigStorageReadException.ERROR_PACKAGE_NOT_FOUND, e.getErrorCode());
// cannot find container
- p = PlatformAconfigPackageInternal.load(null, "com.android.aconfig.storage.test_1", pr);
- assertEquals(
- AconfigStorageException.ERROR_CANNOT_READ_STORAGE_FILE,
- p.getException().getErrorCode());
- p = PlatformAconfigPackageInternal.load("test", "com.android.aconfig.storage.test_1", pr);
- assertEquals(
- AconfigStorageException.ERROR_CANNOT_READ_STORAGE_FILE,
- p.getException().getErrorCode());
+ e =
+ assertThrows(
+ AconfigStorageReadException.class,
+ () ->
+ PlatformAconfigPackageInternal.load(
+ null,
+ "com.android.aconfig.storage.test_1",
+ fingerprint,
+ pr));
+ assertEquals(AconfigStorageReadException.ERROR_CANNOT_READ_STORAGE_FILE, e.getErrorCode());
- // new storage doesn't exist
- pr = new StorageFileProvider("fake/path/", "fake/path/");
- p = PlatformAconfigPackageInternal.load("mockup", "com.android.aconfig.storage.test_1", pr);
- assertEquals(
- AconfigStorageException.ERROR_CANNOT_READ_STORAGE_FILE,
- p.getException().getErrorCode());
+ e =
+ assertThrows(
+ AconfigStorageReadException.class,
+ () ->
+ PlatformAconfigPackageInternal.load(
+ "test",
+ "com.android.aconfig.storage.test_1",
+ fingerprint,
+ pr));
+ assertEquals(AconfigStorageReadException.ERROR_CANNOT_READ_STORAGE_FILE, e.getErrorCode());
- // file read issue
- pr = new StorageFileProvider(TESTDATA_PATH, "fake/path/");
- p = PlatformAconfigPackageInternal.load("mockup", "com.android.aconfig.storage.test_1", pr);
- assertEquals(
- AconfigStorageException.ERROR_CANNOT_READ_STORAGE_FILE,
- p.getException().getErrorCode());
- }
-
- @Test
- public void testLoad_container_package_fingerprint() throws Exception {
- PackageTable packageTable = pr.getPackageTable("mockup");
-
- PackageTable.Node node1 = packageTable.get("com.android.aconfig.storage.test_1");
-
- long fingerprint = node1.getPackageFingerprint();
- PlatformAconfigPackageInternal p =
- PlatformAconfigPackageInternal.load(
- "mockup", "com.android.aconfig.storage.test_1", fingerprint, pr);
- assertNull(p.getException());
- }
-
- @Test
- public void testLoad_container_package_fingerprint_error() throws Exception {
-
- PackageTable packageTable = pr.getPackageTable("mockup");
-
- PackageTable.Node node1 = packageTable.get("com.android.aconfig.storage.test_1");
-
- long fingerprint = node1.getPackageFingerprint();
-
- // cannot find package
- PlatformAconfigPackageInternal p =
- PlatformAconfigPackageInternal.load(
- "mockup", "com.android.aconfig.storage.test_10", fingerprint, pr);
-
- assertEquals(
- AconfigStorageException.ERROR_PACKAGE_NOT_FOUND,
- p.getException().getErrorCode());
-
- // cannot find container
- p =
- PlatformAconfigPackageInternal.load(
- null, "com.android.aconfig.storage.test_1", fingerprint, pr);
- assertEquals(
- AconfigStorageException.ERROR_CANNOT_READ_STORAGE_FILE,
- p.getException().getErrorCode());
- p =
- PlatformAconfigPackageInternal.load(
- "test", "com.android.aconfig.storage.test_1", fingerprint, pr);
- assertEquals(
- AconfigStorageException.ERROR_CANNOT_READ_STORAGE_FILE,
- p.getException().getErrorCode());
// fingerprint doesn't match
- p =
- PlatformAconfigPackageInternal.load(
- "mockup", "com.android.aconfig.storage.test_1", fingerprint + 1, pr);
+ e =
+ assertThrows(
+ AconfigStorageReadException.class,
+ () ->
+ PlatformAconfigPackageInternal.load(
+ "mockup",
+ "com.android.aconfig.storage.test_1",
+ fingerprint + 1,
+ pr));
assertEquals(
// AconfigStorageException.ERROR_FILE_FINGERPRINT_MISMATCH,
- 5, p.getException().getErrorCode());
+ 5, e.getErrorCode());
// new storage doesn't exist
pr = new StorageFileProvider("fake/path/", "fake/path/");
- p =
- PlatformAconfigPackageInternal.load(
- "mockup", "com.android.aconfig.storage.test_1", fingerprint, pr);
- assertEquals(
- AconfigStorageException.ERROR_CANNOT_READ_STORAGE_FILE,
- p.getException().getErrorCode());
+ e =
+ assertThrows(
+ AconfigStorageReadException.class,
+ () ->
+ PlatformAconfigPackageInternal.load(
+ "mockup",
+ "com.android.aconfig.storage.test_1",
+ fingerprint,
+ pr));
+ assertEquals(AconfigStorageReadException.ERROR_CANNOT_READ_STORAGE_FILE, e.getErrorCode());
// file read issue
pr = new StorageFileProvider(TESTDATA_PATH, "fake/path/");
- p =
- PlatformAconfigPackageInternal.load(
- "mockup", "com.android.aconfig.storage.test_1", fingerprint, pr);
- assertEquals(
- AconfigStorageException.ERROR_CANNOT_READ_STORAGE_FILE,
- p.getException().getErrorCode());
- }
-
- @Test
- public void testGetBooleanFlagValue_flagName() throws Exception {
- PlatformAconfigPackageInternal p =
- PlatformAconfigPackageInternal.load(
- "mockup", "com.android.aconfig.storage.test_1", pr);
- assertFalse(p.getBooleanFlagValue("disabled_rw", true));
- assertTrue(p.getBooleanFlagValue("enabled_ro", false));
- assertTrue(p.getBooleanFlagValue("enabled_rw", false));
- assertFalse(p.getBooleanFlagValue("fake", false));
+ e =
+ assertThrows(
+ AconfigStorageReadException.class,
+ () ->
+ PlatformAconfigPackageInternal.load(
+ "mockup",
+ "com.android.aconfig.storage.test_1",
+ fingerprint,
+ pr));
+ assertEquals(AconfigStorageReadException.ERROR_CANNOT_READ_STORAGE_FILE, e.getErrorCode());
}
@Test
public void testGetBooleanFlagValue_index() throws Exception {
-
PackageTable packageTable = pr.getPackageTable("mockup");
-
PackageTable.Node node1 = packageTable.get("com.android.aconfig.storage.test_1");
-
long fingerprint = node1.getPackageFingerprint();
PlatformAconfigPackageInternal p =
PlatformAconfigPackageInternal.load(
diff --git a/tools/aconfig/fake_device_config/src/android/os/flagging/AconfigPackageInternal.java b/tools/aconfig/fake_device_config/src/android/os/flagging/AconfigPackageInternal.java
index 5f066a8..d084048 100644
--- a/tools/aconfig/fake_device_config/src/android/os/flagging/AconfigPackageInternal.java
+++ b/tools/aconfig/fake_device_config/src/android/os/flagging/AconfigPackageInternal.java
@@ -21,10 +21,6 @@
*/
public class AconfigPackageInternal {
- public static AconfigPackageInternal load(String container, String packageName) {
- throw new UnsupportedOperationException("Stub!");
- }
-
public static AconfigPackageInternal load(
String container, String packageName, long packageFingerprint) {
throw new UnsupportedOperationException("Stub!");
@@ -33,12 +29,4 @@
public boolean getBooleanFlagValue(int index) {
throw new UnsupportedOperationException("Stub!");
}
-
- public boolean getBooleanFlagValue(String flagName, boolean defaultValue) {
- throw new UnsupportedOperationException("Stub!");
- }
-
- public AconfigStorageReadException getException() {
- throw new UnsupportedOperationException("Stub!");
- }
}
diff --git a/tools/aconfig/fake_device_config/src/android/os/flagging/PlatformAconfigPackageInternal.java b/tools/aconfig/fake_device_config/src/android/os/flagging/PlatformAconfigPackageInternal.java
index c1bc19b..283b251 100644
--- a/tools/aconfig/fake_device_config/src/android/os/flagging/PlatformAconfigPackageInternal.java
+++ b/tools/aconfig/fake_device_config/src/android/os/flagging/PlatformAconfigPackageInternal.java
@@ -21,10 +21,6 @@
*/
public class PlatformAconfigPackageInternal {
- public static PlatformAconfigPackageInternal load(String container, String packageName) {
- throw new UnsupportedOperationException("Stub!");
- }
-
public static PlatformAconfigPackageInternal load(
String container, String packageName, long packageFingerprint) {
throw new UnsupportedOperationException("Stub!");
@@ -33,12 +29,4 @@
public boolean getBooleanFlagValue(int index) {
throw new UnsupportedOperationException("Stub!");
}
-
- public boolean getBooleanFlagValue(String flagName, boolean defaultValue) {
- throw new UnsupportedOperationException("Stub!");
- }
-
- public AconfigStorageReadException getException() {
- throw new UnsupportedOperationException("Stub!");
- }
}