Add support for getting literal values for references in android:scheme

- side affect of using public.xml to get constant resource ids
 - fixes #1097
This commit is contained in:
Connor Tumbleson 2016-08-06 08:31:58 -04:00
parent 0e0f8b0dee
commit d0baa841eb
No known key found for this signature in database
GPG Key ID: C3CC0A201EC7DA75

View File

@ -82,6 +82,7 @@ public final class ResXmlPatcher {
* @throws AndrolibException * @throws AndrolibException
*/ */
public static void fixingPublicAttrsInProviderAttributes(File file) throws AndrolibException { public static void fixingPublicAttrsInProviderAttributes(File file) throws AndrolibException {
boolean saved = false;
if (file.exists()) { if (file.exists()) {
try { try {
Document doc = loadDocument(file); Document doc = loadDocument(file);
@ -104,12 +105,42 @@ public final class ResXmlPatcher {
if (replacement != null) { if (replacement != null) {
provider.setNodeValue(replacement); provider.setNodeValue(replacement);
saveDocument(file, doc); saved = true;
} }
} }
} }
} }
// android:scheme
xPath = XPathFactory.newInstance().newXPath();
expression = xPath.compile("/manifest/application/activity/intent-filter/data");
result = expression.evaluate(doc, XPathConstants.NODESET);
nodes = (NodeList) result;
for (int i = 0; i < nodes.getLength(); i++) {
Node node = nodes.item(i);
NamedNodeMap attrs = node.getAttributes();
if (attrs != null) {
Node provider = attrs.getNamedItem("android:scheme");
if (provider != null) {
String reference = provider.getNodeValue();
String replacement = pullValueFromStrings(file.getParentFile(), reference);
if (replacement != null) {
provider.setNodeValue(replacement);
saved = true;
}
}
}
}
if (saved) {
saveDocument(file, doc);
}
} catch (SAXException | ParserConfigurationException | IOException | } catch (SAXException | ParserConfigurationException | IOException |
XPathExpressionException | TransformerException ignored) { XPathExpressionException | TransformerException ignored) {
} }