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

Commit b9ded17d authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge changes from topic "overlay-config-dumpsys-include-config-file"

* changes:
  Overlay config: include config file data in dumpsys
  Mark ParsedConfiguration.parsedInfo as @Nullable
parents e08eb4c5 fa61d140
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -183,7 +183,7 @@ public class OverlayConfig {
                final ParsedOverlayInfo p = partitionOverlayInfos.get(j);
                if (p.isStatic) {
                    partitionConfigs.add(new ParsedConfiguration(p.packageName,
                            true /* enabled */, false /* mutable */, partition.policy, p));
                            true /* enabled */, false /* mutable */, partition.policy, p, null));
                }
            }

+70 −8
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import android.annotation.NonNull;
import android.annotation.Nullable;
import android.content.pm.PackagePartitions;
import android.content.pm.PackagePartitions.SystemPartition;
import android.os.Build;
import android.os.FileUtils;
import android.util.ArraySet;
import android.util.Log;
@@ -56,6 +57,34 @@ import java.util.Map;
 **/
final class OverlayConfigParser {

    /** Represents a part of a parsed overlay configuration XML file. */
    public static class ParsedConfigFile {
        @NonNull public final String path;
        @NonNull public final int line;
        @Nullable public final String xml;

        ParsedConfigFile(@NonNull String path, int line, @Nullable String xml) {
            this.path = path;
            this.line = line;
            this.xml = xml;
        }

        @Override
        public String toString() {
            StringBuilder sb = new StringBuilder(getClass().getSimpleName());
            sb.append("{path=");
            sb.append(path);
            sb.append(", line=");
            sb.append(line);
            if (xml != null) {
                sb.append(", xml=");
                sb.append(xml);
            }
            sb.append("}");
            return sb.toString();
        }
    }

    // Default values for overlay configurations.
    static final boolean DEFAULT_ENABLED_STATE = false;
    static final boolean DEFAULT_MUTABILITY = true;
@@ -94,24 +123,40 @@ final class OverlayConfigParser {
        @NonNull
        public final String policy;

        /** Information extracted from the manifest of the overlay. */
        @NonNull
        /**
         * Information extracted from the manifest of the overlay.
         * Null if the information was read from a config file instead of a manifest.
         *
         * @see parsedConfigFile
         **/
        @Nullable
        public final ParsedOverlayInfo parsedInfo;

        /**
         * The config file used to configure this overlay.
         * Null if no config file was used, in which case the overlay's manifest was used instead.
         *
         * @see parsedInfo
         **/
        @Nullable
        public final ParsedConfigFile parsedConfigFile;

        ParsedConfiguration(@NonNull String packageName, boolean enabled, boolean mutable,
                @NonNull String policy, @NonNull ParsedOverlayInfo parsedInfo) {
                @NonNull String policy, @Nullable ParsedOverlayInfo parsedInfo,
                @Nullable ParsedConfigFile parsedConfigFile) {
            this.packageName = packageName;
            this.enabled = enabled;
            this.mutable = mutable;
            this.policy = policy;
            this.parsedInfo = parsedInfo;
            this.parsedConfigFile = parsedConfigFile;
        }

        @Override
        public String toString() {
            return getClass().getSimpleName() + String.format("{packageName=%s, enabled=%s"
                            + ", mutable=%s, policy=%s, parsedInfo=%s}", packageName, enabled,
                    mutable, policy, parsedInfo);
                            + ", mutable=%s, policy=%s, parsedInfo=%s, parsedConfigFile=%s}",
                    packageName, enabled, mutable, policy, parsedInfo, parsedConfigFile);
        }
    }

@@ -417,9 +462,26 @@ final class OverlayConfigParser {
            Log.w(TAG, "found default-disabled immutable overlay " + packageName);
        }

        final ParsedConfiguration Config = new ParsedConfiguration(packageName, isEnabled,
                isMutable, parsingContext.mPartition.policy, info);
        final ParsedConfigFile parsedConfigFile = new ParsedConfigFile(
                configFile.getPath().intern(), parser.getLineNumber(),
                (Build.IS_ENG || Build.IS_USERDEBUG) ? currentParserContextToString(parser) : null);
        final ParsedConfiguration config = new ParsedConfiguration(packageName, isEnabled,
                isMutable, parsingContext.mPartition.policy, info, parsedConfigFile);
        parsingContext.mConfiguredOverlays.add(packageName);
        parsingContext.mOrderedConfigurations.add(Config);
        parsingContext.mOrderedConfigurations.add(config);
    }

    private static String currentParserContextToString(@NonNull XmlPullParser parser) {
        StringBuilder sb = new StringBuilder("<");
        sb.append(parser.getName());
        sb.append(" ");
        for (int i = 0; i < parser.getAttributeCount(); i++) {
            sb.append(parser.getAttributeName(i));
            sb.append("=\"");
            sb.append(parser.getAttributeValue(i));
            sb.append("\" ");
        }
        sb.append("/>");
        return sb.toString();
    }
}