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

Commit 7b4c46e4 authored by Zhi Dou's avatar Zhi Dou Committed by Gerrit Code Review
Browse files

Merge "add PlatformAconfigPackageInternal" into main

parents 9712d1e4 589b6a9c
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -39,6 +39,8 @@ public class AconfigStorageException extends RuntimeException {
    /** Error code indicating that there was an error reading the Aconfig Storage file. */
    public static final int ERROR_CANNOT_READ_STORAGE_FILE = 4;

    public static final int ERROR_FILE_FINGERPRINT_MISMATCH = 5;

    private final int mErrorCode;

    /**
@@ -126,6 +128,8 @@ public class AconfigStorageException extends RuntimeException {
                return "ERROR_CONTAINER_NOT_FOUND";
            case ERROR_CANNOT_READ_STORAGE_FILE:
                return "ERROR_CANNOT_READ_STORAGE_FILE";
            case ERROR_FILE_FINGERPRINT_MISMATCH:
                return "ERROR_FILE_FINGERPRINT_MISMATCH";
            default:
                return "<Unknown error code " + mErrorCode + ">";
        }
+16 −0
Original line number Diff line number Diff line
@@ -42,4 +42,20 @@ public enum FileType {
                return null;
        }
    }

    @Override
    public String toString() {
        switch (type) {
            case 0:
                return "PACKAGE_MAP";
            case 1:
                return "FLAG_MAP";
            case 2:
                return "FLAG_VAL";
            case 3:
                return "FLAG_INFO";
            default:
                return "unrecognized type";
        }
    }
}
+19 −8
Original line number Diff line number Diff line
@@ -26,7 +26,10 @@ import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/** @hide */
public class StorageFileProvider {
@@ -52,13 +55,20 @@ public class StorageFileProvider {
    }

    /** @hide */
    public List<Path> listPackageMapFiles() {
        List<Path> result = new ArrayList<>();
    public List<String> listContainers(String[] excludes) {
        List<String> result = new ArrayList<>();
        Set<String> set = new HashSet<>(Arrays.asList(excludes));

        try {
            DirectoryStream<Path> stream =
                    Files.newDirectoryStream(Paths.get(mMapPath), "*" + PMAP_FILE_EXT);
            for (Path entry : stream) {
                result.add(entry);
                String fileName = entry.getFileName().toString();
                String container =
                        fileName.substring(0, fileName.length() - PMAP_FILE_EXT.length());
                if (!set.contains(container)) {
                    result.add(container);
                }
            }
        } catch (NoSuchFileException e) {
            return result;
@@ -77,22 +87,23 @@ public class StorageFileProvider {

    /** @hide */
    public FlagTable getFlagTable(String container) {
        return FlagTable.fromBytes(mapStorageFile(Paths.get(mMapPath, container + FMAP_FILE_EXT)));
        return FlagTable.fromBytes(
                mapStorageFile(Paths.get(mMapPath, container + FMAP_FILE_EXT), FileType.FLAG_MAP));
    }

    /** @hide */
    public FlagValueList getFlagValueList(String container) {
        return FlagValueList.fromBytes(
                mapStorageFile(Paths.get(mBootPath, container + VAL_FILE_EXT)));
                mapStorageFile(Paths.get(mBootPath, container + VAL_FILE_EXT), FileType.FLAG_VAL));
    }

    /** @hide */
    public static PackageTable getPackageTable(Path path) {
        return PackageTable.fromBytes(mapStorageFile(path));
        return PackageTable.fromBytes(mapStorageFile(path, FileType.PACKAGE_MAP));
    }

    // Map a storage file given file path
    private static MappedByteBuffer mapStorageFile(Path file) {
    private static MappedByteBuffer mapStorageFile(Path file, FileType type) {
        FileChannel channel = null;
        try {
            channel = FileChannel.open(file, StandardOpenOption.READ);
@@ -100,7 +111,7 @@ public class StorageFileProvider {
        } catch (Exception e) {
            throw new AconfigStorageException(
                    AconfigStorageException.ERROR_CANNOT_READ_STORAGE_FILE,
                    String.format("Fail to mmap storage file %s", file),
                    String.format("Fail to mmap storage %s file %s", type.toString(), file),
                    e);
        } finally {
            quietlyDispose(channel);
+11 −8
Original line number Diff line number Diff line
@@ -29,7 +29,6 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;

@@ -37,15 +36,20 @@ import java.util.List;
public class StorageFileProviderTest {

    @Test
    public void testListpackageMapFiles() throws Exception {
    public void testlistContainers() throws Exception {
        StorageFileProvider p =
                new StorageFileProvider(TestDataUtils.TESTDATA_PATH, TestDataUtils.TESTDATA_PATH);
        List<Path> file = p.listPackageMapFiles();
        assertEquals(2, file.size());
        String[] excludes = {};
        List<String> containers = p.listContainers(excludes);
        assertEquals(2, containers.size());

        excludes = new String[] {"mock.v1"};
        containers = p.listContainers(excludes);
        assertEquals(1, containers.size());

        p = new StorageFileProvider("fake/path/", "fake/path/");
        file = p.listPackageMapFiles();
        assertTrue(file.isEmpty());
        containers = p.listContainers(excludes);
        assertTrue(containers.isEmpty());
    }

    @Test
@@ -56,8 +60,7 @@ public class StorageFileProviderTest {
        assertNotNull(pt);
        pt =
                StorageFileProvider.getPackageTable(
                        Paths.get(
                                TestDataUtils.TESTDATA_PATH, "mock.v1.package.map"));
                        Paths.get(TestDataUtils.TESTDATA_PATH, "mock.v1.package.map"));
        assertNotNull(pt);
        FlagTable f = p.getFlagTable("mock.v1");
        assertNotNull(f);
+3 −2
Original line number Diff line number Diff line
@@ -154,12 +154,13 @@ java_library {
java_library {
    name: "aconfig_storage_reader_java",
    srcs: [
        "srcs/android/aconfig/storage/AconfigPackageImpl.java",
        "srcs/android/aconfig/storage/StorageInternalReader.java",
        "srcs/android/os/flagging/PlatformAconfigPackageInternal.java",
    ],
    libs: [
        "unsupportedappusage",
        "strict_mode_stub",
        "aconfig_storage_stub",
    ],
    static_libs: [
        "aconfig_storage_file_java",
@@ -176,8 +177,8 @@ java_library {
java_library {
    name: "aconfig_storage_reader_java_none",
    srcs: [
        "srcs/android/aconfig/storage/AconfigPackageImpl.java",
        "srcs/android/aconfig/storage/StorageInternalReader.java",
        "srcs/android/os/flagging/PlatformAconfigPackageInternal.java",
    ],
    libs: [
        "unsupportedappusage-sdk-none",
Loading