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

Commit 13a794a8 authored by Chaitanya Cheemala (xWF)'s avatar Chaitanya Cheemala (xWF) Committed by Android (Google) Code Review
Browse files

Merge "Revert "add PlatformAconfigPackageInternal"" into main

parents dbbfe1e8 1b422968
Loading
Loading
Loading
Loading
+0 −4
Original line number Diff line number Diff line
@@ -39,8 +39,6 @@ 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;

    /**
@@ -128,8 +126,6 @@ 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 + ">";
        }
+0 −16
Original line number Diff line number Diff line
@@ -42,20 +42,4 @@ 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";
        }
    }
}
+8 −19
Original line number Diff line number Diff line
@@ -26,10 +26,7 @@ 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 {
@@ -55,20 +52,13 @@ public class StorageFileProvider {
    }

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

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

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

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

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

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

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

    @Test
    public void testlistContainers() throws Exception {
    public void testListpackageMapFiles() throws Exception {
        StorageFileProvider p =
                new StorageFileProvider(TestDataUtils.TESTDATA_PATH, TestDataUtils.TESTDATA_PATH);
        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());
        List<Path> file = p.listPackageMapFiles();
        assertEquals(2, file.size());

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

    @Test
@@ -60,7 +56,8 @@ 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);
+2 −3
Original line number Diff line number Diff line
@@ -154,13 +154,12 @@ 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",
@@ -177,8 +176,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