Merge "Allow debug-overrides to be specified in an extra resource" into nyc-dev

am: 8064b4a687

* commit '8064b4a687b41377bff5ea767dedc9c8a366cb51':
  Allow debug-overrides to be specified in an extra resource
This commit is contained in:
Chad Brubaker
2016-03-09 20:50:14 +00:00
committed by android-build-merger
6 changed files with 105 additions and 1 deletions

View File

@@ -339,7 +339,7 @@ public class XmlConfigSource implements ConfigSource {
}
if (mDebugBuild) {
debugConfigBuilder =
parseConfigEntry(parser, seenDomains, null, CONFIG_DEBUG).get(0).first;
parseConfigEntry(parser, null, null, CONFIG_DEBUG).get(0).first;
} else {
XmlUtils.skipCurrentTag(parser);
}
@@ -348,6 +348,11 @@ public class XmlConfigSource implements ConfigSource {
XmlUtils.skipCurrentTag(parser);
}
}
// If debug is true and there was no debug-overrides in the file check for an extra
// _debug resource.
if (mDebugBuild && debugConfigBuilder == null) {
debugConfigBuilder = parseDebugOverridesResource();
}
// Use the platform default as the parent of the base config for any values not provided
// there. If there is no base config use the platform default.
@@ -385,6 +390,43 @@ public class XmlConfigSource implements ConfigSource {
mDomainMap = configs;
}
private NetworkSecurityConfig.Builder parseDebugOverridesResource()
throws IOException, XmlPullParserException, ParserException {
Resources resources = mContext.getResources();
String packageName = resources.getResourcePackageName(mResourceId);
String entryName = resources.getResourceEntryName(mResourceId);
int resId = resources.getIdentifier(entryName + "_debug", "xml", packageName);
// No debug-overrides resource was found, nothing to parse.
if (resId == 0) {
return null;
}
NetworkSecurityConfig.Builder debugConfigBuilder = null;
// Parse debug-overrides out of the _debug resource.
try (XmlResourceParser parser = resources.getXml(resId)) {
XmlUtils.beginDocument(parser, "network-security-config");
int outerDepth = parser.getDepth();
boolean seenDebugOverrides = false;
while (XmlUtils.nextElementWithin(parser, outerDepth)) {
if ("debug-overrides".equals(parser.getName())) {
if (seenDebugOverrides) {
throw new ParserException(parser, "Only one debug-overrides allowed");
}
if (mDebugBuild) {
debugConfigBuilder =
parseConfigEntry(parser, null, null, CONFIG_DEBUG).get(0).first;
} else {
XmlUtils.skipCurrentTag(parser);
}
seenDebugOverrides = true;
} else {
XmlUtils.skipCurrentTag(parser);
}
}
}
return debugConfigBuilder;
}
public static class ParserException extends Exception {
public ParserException(XmlPullParser parser, String message, Throwable cause) {