Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 64909f38 authored by zhidou's avatar zhidou Committed by Zhi Dou
Browse files

Throw AconfigStorageException instead of AconfigStorageReadException

Test: atest aconfig_storage_read_functional aconfig_storage_read_unit
Change-Id: I12eaf880d3031e8ab7dd9ba6e15e608de3463bed
parent da18f1b6
Loading
Loading
Loading
Loading
+4 −6
Original line number Diff line number Diff line
@@ -84,15 +84,13 @@ public class PlatformAconfigPackageInternal {
        try {
            pNode = fileProvider.getPackageTable(container).get(packageName);
            vList = fileProvider.getFlagValueList(container);
        } catch (AconfigStorageException e) {
            throw new AconfigStorageReadException(e.getErrorCode(), e.toString());
        } finally {
            StrictMode.setThreadPolicy(oldPolicy);
        }

        if (pNode == null || vList == null) {
            throw new AconfigStorageReadException(
                    AconfigStorageReadException.ERROR_PACKAGE_NOT_FOUND,
            throw new AconfigStorageException(
                    AconfigStorageException.ERROR_PACKAGE_NOT_FOUND,
                    String.format(
                            "package "
                                    + packageName
@@ -102,8 +100,8 @@ public class PlatformAconfigPackageInternal {
        }

        if (pNode.hasPackageFingerprint() && packageFingerprint != pNode.getPackageFingerprint()) {
            throw new AconfigStorageReadException(
                    5, // AconfigStorageReadException.ERROR_FILE_FINGERPRINT_MISMATCH,
            throw new AconfigStorageException(
                    AconfigStorageException.ERROR_FILE_FINGERPRINT_MISMATCH,
                    String.format(
                            "package "
                                    + packageName
+8 −10
Original line number Diff line number Diff line
@@ -26,7 +26,7 @@ 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.internal.aconfig.storage.AconfigStorageException;
import android.os.flagging.PlatformAconfigPackageInternal;

import org.junit.Test;
@@ -84,20 +84,20 @@ public class PlatformAconfigPackageInternalTest {
    @Test
    public void testAconfigPackage_load_withError() throws IOException {
        // container not found fake_container
        AconfigStorageReadException e =
        AconfigStorageException e =
                assertThrows(
                        AconfigStorageReadException.class,
                        AconfigStorageException.class,
                        () ->
                                PlatformAconfigPackageInternal.load(
                                        "fake_container", "fake_package", 0));
        assertEquals(AconfigStorageReadException.ERROR_CANNOT_READ_STORAGE_FILE, e.getErrorCode());
        assertEquals(AconfigStorageException.ERROR_CANNOT_READ_STORAGE_FILE, e.getErrorCode());

        // package not found
        e =
                assertThrows(
                        AconfigStorageReadException.class,
                        AconfigStorageException.class,
                        () -> PlatformAconfigPackageInternal.load("system", "fake_container", 0));
        assertEquals(AconfigStorageReadException.ERROR_PACKAGE_NOT_FOUND, e.getErrorCode());
        assertEquals(AconfigStorageException.ERROR_PACKAGE_NOT_FOUND, e.getErrorCode());

        // fingerprint doesn't match
        List<parsed_flag> flags = DeviceProtos.loadAndParseFlagProtos();
@@ -116,13 +116,11 @@ public class PlatformAconfigPackageInternalTest {
            long fingerprint = pNode.getPackageFingerprint();
            e =
                    assertThrows(
                            AconfigStorageReadException.class,
                            AconfigStorageException.class,
                            () ->
                                    PlatformAconfigPackageInternal.load(
                                            container, packageName, fingerprint + 1));
            assertEquals(
                    // AconfigStorageException.ERROR_FILE_FINGERPRINT_MISMATCH,
                    5, e.getErrorCode());
            assertEquals(AconfigStorageException.ERROR_FILE_FINGERPRINT_MISMATCH, e.getErrorCode());
        }
    }
}
+13 −13
Original line number Diff line number Diff line
@@ -21,9 +21,9 @@ import static org.junit.Assert.assertFalse;
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;
@@ -62,44 +62,44 @@ public class PlatformAconfigPackageInternalTest {
        PackageTable.Node node1 = packageTable.get("com.android.aconfig.storage.test_1");
        long fingerprint = node1.getPackageFingerprint();
        // cannot find package
        AconfigStorageReadException e =
        AconfigStorageException e =
                assertThrows(
                        AconfigStorageReadException.class,
                        AconfigStorageException.class,
                        () ->
                                PlatformAconfigPackageInternal.load(
                                        "mockup",
                                        "com.android.aconfig.storage.test_10",
                                        fingerprint,
                                        pr));
        assertEquals(AconfigStorageReadException.ERROR_PACKAGE_NOT_FOUND, e.getErrorCode());
        assertEquals(AconfigStorageException.ERROR_PACKAGE_NOT_FOUND, e.getErrorCode());

        // cannot find container
        e =
                assertThrows(
                        AconfigStorageReadException.class,
                        AconfigStorageException.class,
                        () ->
                                PlatformAconfigPackageInternal.load(
                                        null,
                                        "com.android.aconfig.storage.test_1",
                                        fingerprint,
                                        pr));
        assertEquals(AconfigStorageReadException.ERROR_CANNOT_READ_STORAGE_FILE, e.getErrorCode());
        assertEquals(AconfigStorageException.ERROR_CANNOT_READ_STORAGE_FILE, e.getErrorCode());

        e =
                assertThrows(
                        AconfigStorageReadException.class,
                        AconfigStorageException.class,
                        () ->
                                PlatformAconfigPackageInternal.load(
                                        "test",
                                        "com.android.aconfig.storage.test_1",
                                        fingerprint,
                                        pr));
        assertEquals(AconfigStorageReadException.ERROR_CANNOT_READ_STORAGE_FILE, e.getErrorCode());
        assertEquals(AconfigStorageException.ERROR_CANNOT_READ_STORAGE_FILE, e.getErrorCode());

        // fingerprint doesn't match
        e =
                assertThrows(
                        AconfigStorageReadException.class,
                        AconfigStorageException.class,
                        () ->
                                PlatformAconfigPackageInternal.load(
                                        "mockup",
@@ -114,27 +114,27 @@ public class PlatformAconfigPackageInternalTest {
        pr = new StorageFileProvider("fake/path/", "fake/path/");
        e =
                assertThrows(
                        AconfigStorageReadException.class,
                        AconfigStorageException.class,
                        () ->
                                PlatformAconfigPackageInternal.load(
                                        "mockup",
                                        "com.android.aconfig.storage.test_1",
                                        fingerprint,
                                        pr));
        assertEquals(AconfigStorageReadException.ERROR_CANNOT_READ_STORAGE_FILE, e.getErrorCode());
        assertEquals(AconfigStorageException.ERROR_CANNOT_READ_STORAGE_FILE, e.getErrorCode());

        // file read issue
        pr = new StorageFileProvider(TESTDATA_PATH, "fake/path/");
        e =
                assertThrows(
                        AconfigStorageReadException.class,
                        AconfigStorageException.class,
                        () ->
                                PlatformAconfigPackageInternal.load(
                                        "mockup",
                                        "com.android.aconfig.storage.test_1",
                                        fingerprint,
                                        pr));
        assertEquals(AconfigStorageReadException.ERROR_CANNOT_READ_STORAGE_FILE, e.getErrorCode());
        assertEquals(AconfigStorageException.ERROR_CANNOT_READ_STORAGE_FILE, e.getErrorCode());
    }

    @Test