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

Commit 8e3f9658 authored by atrost's avatar atrost
Browse files

Read compat config from APEX

Expose getActiveApexInfos for CompatConfig to use, then go over it
searching for configs in etc/compatconfig.

Test: Put a change in an APEX, flash device, inspect
`adb shell dumpsys platform_compat` output. It contains the change.
Bug: 142650523
Bug: 138222363

Change-Id: I9e249900271eb1ea6d34a1ca02b8ba1dd8eddb6b
parent 4a8fc13d
Loading
Loading
Loading
Loading
+9 −1
Original line number Original line Diff line number Diff line
@@ -35,6 +35,7 @@ import com.android.internal.compat.IOverrideValidator;
import com.android.internal.compat.OverrideAllowedState;
import com.android.internal.compat.OverrideAllowedState;
import com.android.server.compat.config.Change;
import com.android.server.compat.config.Change;
import com.android.server.compat.config.XmlParser;
import com.android.server.compat.config.XmlParser;
import com.android.server.pm.ApexManager;


import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlPullParserException;


@@ -45,6 +46,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.Set;


import javax.xml.datatype.DatatypeConfigurationException;
import javax.xml.datatype.DatatypeConfigurationException;
@@ -369,12 +371,18 @@ final class CompatConfig {
                Environment.getRootDirectory(), "etc", "compatconfig"));
                Environment.getRootDirectory(), "etc", "compatconfig"));
        config.initConfigFromLib(Environment.buildPath(
        config.initConfigFromLib(Environment.buildPath(
                Environment.getRootDirectory(), "system_ext", "etc", "compatconfig"));
                Environment.getRootDirectory(), "system_ext", "etc", "compatconfig"));

        List<ApexManager.ActiveApexInfo> apexes = ApexManager.getInstance().getActiveApexInfos();
        for (ApexManager.ActiveApexInfo apex : apexes) {
            config.initConfigFromLib(Environment.buildPath(
                    apex.apexDirectory, "etc", "compatconfig"));
        }
        return config;
        return config;
    }
    }


    void initConfigFromLib(File libraryDir) {
    void initConfigFromLib(File libraryDir) {
        if (!libraryDir.exists() || !libraryDir.isDirectory()) {
        if (!libraryDir.exists() || !libraryDir.isDirectory()) {
            Slog.e(TAG, "No directory " + libraryDir + ", skipping");
            Slog.d(TAG, "No directory " + libraryDir + ", skipping");
            return;
            return;
        }
        }
        for (File f : libraryDir.listFiles()) {
        for (File f : libraryDir.listFiles()) {
+9 −5
Original line number Original line Diff line number Diff line
@@ -95,15 +95,17 @@ public abstract class ApexManager {
     * Returns an instance of either {@link ApexManagerImpl} or {@link ApexManagerFlattenedApex}
     * Returns an instance of either {@link ApexManagerImpl} or {@link ApexManagerFlattenedApex}
     * depending on whether this device supports APEX, i.e. {@link ApexProperties#updatable()}
     * depending on whether this device supports APEX, i.e. {@link ApexProperties#updatable()}
     * evaluates to {@code true}.
     * evaluates to {@code true}.
     * @hide
     */
     */
    static ApexManager getInstance() {
    public static ApexManager getInstance() {
        return sApexManagerSingleton.get();
        return sApexManagerSingleton.get();
    }
    }


    /**
    /**
     * Minimal information about APEX mount points and the original APEX package they refer to.
     * Minimal information about APEX mount points and the original APEX package they refer to.
     * @hide
     */
     */
    static class ActiveApexInfo {
    public static class ActiveApexInfo {
        @Nullable public final String apexModuleName;
        @Nullable public final String apexModuleName;
        public final File apexDirectory;
        public final File apexDirectory;
        public final File preInstalledApexPath;
        public final File preInstalledApexPath;
@@ -130,8 +132,10 @@ public abstract class ApexManager {


    /**
    /**
     * Returns {@link ActiveApexInfo} records relative to all active APEX packages.
     * Returns {@link ActiveApexInfo} records relative to all active APEX packages.
     *
     * @hide
     */
     */
    abstract List<ActiveApexInfo> getActiveApexInfos();
    public abstract List<ActiveApexInfo> getActiveApexInfos();


    abstract void systemReady(Context context);
    abstract void systemReady(Context context);


@@ -347,7 +351,7 @@ public abstract class ApexManager {
        }
        }


        @Override
        @Override
        List<ActiveApexInfo> getActiveApexInfos() {
        public List<ActiveApexInfo> getActiveApexInfos() {
            synchronized (mLock) {
            synchronized (mLock) {
                if (mActiveApexInfosCache == null) {
                if (mActiveApexInfosCache == null) {
                    try {
                    try {
@@ -744,7 +748,7 @@ public abstract class ApexManager {
     */
     */
    private static final class ApexManagerFlattenedApex extends ApexManager {
    private static final class ApexManagerFlattenedApex extends ApexManager {
        @Override
        @Override
        List<ActiveApexInfo> getActiveApexInfos() {
        public List<ActiveApexInfo> getActiveApexInfos() {
            // There is no apexd running in case of flattened apex
            // There is no apexd running in case of flattened apex
            // We look up the /apex directory and identify the active APEX modules from there.
            // We look up the /apex directory and identify the active APEX modules from there.
            // As "preinstalled" path, we just report /system since in the case of flattened APEX
            // As "preinstalled" path, we just report /system since in the case of flattened APEX