added option to include generic/permissive network security config file durin… (#2791)

* added option to include permissive network security config file during build

* added tests for app with existing network config and for app without

* minor fixes for pull 2791

* refactor: slim down test app for network config

* style: remove extra newlines

* refactor: moved network tests to aapt2

* refactor: remove unused exceptions

* test (aapt2): ensure aapt2 is used for net-sec-conf

* fix (cli): block use of net-sec-conf on aapt1

* fix conflict

Co-authored-by: Connor Tumbleson <connor@sourcetoad.com>
Co-authored-by: Connor Tumbleson <connor.tumbleson@gmail.com>
This commit is contained in:
erev0s
2022-05-07 13:52:07 +03:00
committed by GitHub
parent d38eceedae
commit 8fab4bfb3d
17 changed files with 414 additions and 5 deletions

View File

@ -216,6 +216,9 @@ public class Main {
if (cli.hasOption("d") || cli.hasOption("debug")) {
buildOptions.debugMode = true;
}
if (cli.hasOption("n") || cli.hasOption("net-sec-conf")) {
buildOptions.netSecConf = true;
}
if (cli.hasOption("v") || cli.hasOption("verbose")) {
buildOptions.verbose = true;
}
@ -247,6 +250,11 @@ public class Main {
outFile = null;
}
if (buildOptions.netSecConf && !buildOptions.useAapt2) {
System.err.println("-n / --net-sec-conf is only supported with --use-aapt2.");
System.exit(1);
}
// try and build apk
try {
if (cli.hasOption("a") || cli.hasOption("aapt")) {
@ -366,6 +374,11 @@ public class Main {
.desc("Sets android:debuggable to \"true\" in the APK's compiled manifest")
.build();
Option netSecConfOption = Option.builder("n")
.longOpt("net-sec-conf")
.desc("Adds a generic Network Security Configuration file in the output APK")
.build();
Option noDbgOption = Option.builder("b")
.longOpt("no-debug-info")
.desc("don't write out debug info (.local, .param, .line, etc.)")
@ -473,6 +486,7 @@ public class Main {
buildOptions.addOption(apiLevelOption);
buildOptions.addOption(debugBuiOption);
buildOptions.addOption(netSecConfOption);
buildOptions.addOption(aaptOption);
buildOptions.addOption(originalOption);
buildOptions.addOption(aapt2Option);
@ -528,6 +542,7 @@ public class Main {
allOptions.addOption(noAssetOption);
allOptions.addOption(keepResOption);
allOptions.addOption(debugBuiOption);
allOptions.addOption(netSecConfOption);
allOptions.addOption(aaptOption);
allOptions.addOption(originalOption);
allOptions.addOption(verboseOption);