Overlay config: include config file data in dumpsys

Overlay packages are configured via one of two mutually exclusive
approaches: either via the overlays' manifests or via XML config files.
The overlay manager dumpsys already includes data for the manifests;
update the output to also include config file data.

The new output includes the raw XML, but to save memory, this is omitted
on user builds.

Example output; note the parsedConfigFile field, and that the parsedInfo
field is null.

  0, ParsedConfiguration{packageName=com.android.overlaytest.framework, enabled=true, mutable=true, policy=vendor, parsedInfo=null, parsedConfigFile=ParsedConfigFile{path=/vendor/overlay/config/config.xml, line=2, xml=<overlay package="com.android.overlaytest.framework" enabled="true" />}}

Bug: 224945112
Test: atest OverlayConfigTest
Test: adb exec-out cmd overlay dump
Change-Id: I1d880d2cc6cff763865b9b445fd2caa7d35c431f
This commit is contained in:
Mårten Kongstad
2022-03-16 10:54:38 +00:00
parent 3bfe1f39a0
commit fa61d140da
2 changed files with 70 additions and 8 deletions

View File

@@ -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));
}
}

View File

@@ -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. */
/**
* 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, @Nullable 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();
}
}