Skip to content

Commit 27346bb

Browse files
committed
minor fixes for pull 2791
1 parent e9c8d28 commit 27346bb

File tree

2 files changed

+7
-10
lines changed

2 files changed

+7
-10
lines changed

brut.apktool/apktool-lib/src/main/java/brut/androlib/Androlib.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import brut.androlib.meta.UsesFramework;
2121
import brut.androlib.options.BuildOptions;
2222
import brut.androlib.res.AndrolibResources;
23+
import brut.androlib.res.data.ResConfigFlags;
2324
import brut.androlib.res.data.ResPackage;
2425
import brut.androlib.res.data.ResTable;
2526
import brut.androlib.res.data.ResUnknownFiles;
@@ -35,6 +36,7 @@
3536
import org.apache.commons.io.FileUtils;
3637
import org.apache.commons.io.FilenameUtils;
3738
import org.jf.dexlib2.iface.DexFile;
39+
import org.xml.sax.SAXException;
3840

3941
import javax.xml.parsers.ParserConfigurationException;
4042
import javax.xml.transform.TransformerException;
@@ -491,12 +493,13 @@ public boolean buildResourcesFull(File appDir, UsesFramework usesFramework)
491493
if (buildOptions.netSecConf) {
492494
MetaInfo meta = readMetaFile(new ExtFile(appDir));
493495
if (meta.sdkInfo != null && meta.sdkInfo.get("targetSdkVersion") != null) {
494-
if (Integer.parseInt(meta.sdkInfo.get("targetSdkVersion")) < 24) {
496+
if (Integer.parseInt(meta.sdkInfo.get("targetSdkVersion")) < ResConfigFlags.SDK_NOUGAT) {
495497
LOGGER.warning("Target SDK version is lower than 24! Network Security Configuration might be ignored!");
496498
}
497499
}
498500
File netSecConfOrig = new File(appDir, "res/xml/network_security_config.xml");
499501
if (netSecConfOrig.exists()) {
502+
LOGGER.info("Replacing existing network_security_config.xml!");
500503
netSecConfOrig.delete();
501504
}
502505
ResXmlPatcher.modNetworkSecurityConfig(netSecConfOrig);
@@ -539,7 +542,7 @@ public boolean buildResourcesFull(File appDir, UsesFramework usesFramework)
539542
apkFile.delete();
540543
}
541544
return true;
542-
} catch (IOException | BrutException | ParserConfigurationException | TransformerException ex) {
545+
} catch (IOException | BrutException | ParserConfigurationException | TransformerException | SAXException ex) {
543546
throw new AndrolibException(ex);
544547
}
545548
}

brut.apktool/apktool-lib/src/main/java/brut/androlib/res/xml/ResXmlPatcher.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ public static void setNetworkSecurityConfig(File file) {
130130
*
131131
* @param file network security config file
132132
*/
133-
public static void modNetworkSecurityConfig(File file) throws ParserConfigurationException, TransformerException {
133+
public static void modNetworkSecurityConfig(File file) throws ParserConfigurationException, TransformerException, IOException, SAXException {
134134
DocumentBuilderFactory documentFactory = DocumentBuilderFactory.newInstance();
135135
DocumentBuilder documentBuilder = documentFactory.newDocumentBuilder();
136136
Document document = documentBuilder.newDocument();
@@ -154,13 +154,7 @@ public static void modNetworkSecurityConfig(File file) throws ParserConfiguratio
154154
certUser.setAttributeNode(attrUser);
155155
trustAnchors.appendChild(certUser);
156156

157-
// create the xml file
158-
//transform the DOM Object to an XML File
159-
TransformerFactory transformerFactory = TransformerFactory.newInstance();
160-
Transformer transformer = transformerFactory.newTransformer();
161-
DOMSource domSource = new DOMSource(document);
162-
StreamResult streamResult = new StreamResult(file);
163-
transformer.transform(domSource, streamResult);
157+
saveDocument(file, document);
164158
}
165159

166160
/**

0 commit comments

Comments
 (0)