Set up a test for hidden API enforcement
Submitting the test first for easier review. The expected outcome
is that all currently class members are discoverable and accessible.
Future CLs will implement the enforcement and change the expected
outcome.
The test itself has two JARs - parent declares classes and child
tries to access them using reflection, JNI and static linking.
The test driver ("Main" class) loads these JARs as follows:
(a) both with class loaders
(b) parent in boot class path, child with class loader
(c) both in boot class path
In (a), there should be no enforcement as the JAR does not have
hidden API access flags (would not load otherwise). In situation(b),
child should only be allowed to access parent's public, non-hidden
members. And in (c), parent contains hidden API access flags but
child is exempt from access checks.
Bug: 64382372
Test: art/test.py -b -r -t 674-hiddenapi
Change-Id: I19f5f7c30c0c7913703209817d36006b161c6778
diff --git a/test/etc/default-build b/test/etc/default-build
index 5c8257f..4dc2393 100755
--- a/test/etc/default-build
+++ b/test/etc/default-build
@@ -81,6 +81,17 @@
HAS_SRC_DEX2OAT_UNRESOLVED=false
fi
+if [ -f api-light-greylist.txt -o -f api-dark-greylist.txt -o -f api-blacklist.txt ]; then
+ HAS_HIDDENAPI_SPEC=true
+else
+ HAS_HIDDENAPI_SPEC=false
+fi
+
+# USE_HIDDENAPI=false run-test... will disable hiddenapi.
+if [ -z "${USE_HIDDENAPI}" ]; then
+ USE_HIDDENAPI=true
+fi
+
# DESUGAR=false run-test... will disable desugar.
if [[ "$DESUGAR" == false ]]; then
USE_DESUGAR=false
@@ -321,6 +332,24 @@
${DXMERGER} "$dst_file" "${dex_files_to_merge[@]}"
}
+function make_hiddenapi() {
+ local args=()
+ while [[ $# -gt 0 ]]; do
+ args+=("--dex=$1")
+ shift
+ done
+ if [ -f api-light-greylist.txt ]; then
+ args+=("--light-greylist=api-light-greylist.txt")
+ fi
+ if [ -f api-dark-greylist.txt ]; then
+ args+=("--dark-greylist=api-dark-greylist.txt")
+ fi
+ if [ -f api-blacklist.txt ]; then
+ args+=("--blacklist=api-blacklist.txt")
+ fi
+ ${HIDDENAPI} "${args[@]}"
+}
+
# Print the directory name only if it exists.
function maybe_dir() {
local dirname="$1"
@@ -334,6 +363,13 @@
exit 0
fi
+# Helper function for a common test. Evaluate with $(has_mutlidex).
+function has_multidex() {
+ echo [ ${HAS_SRC_MULTIDEX} = "true" \
+ -o ${HAS_JASMIN_MULTIDEX} = "true" \
+ -o ${HAS_SMALI_MULTIDEX} = "true" ]
+}
+
if [ ${HAS_SRC_DEX2OAT_UNRESOLVED} = "true" ]; then
mkdir classes
mkdir classes-ex
@@ -501,9 +537,18 @@
fi
fi
+# Apply hiddenapi on the dex files if the test has API list file(s).
+if [ ${NEED_DEX} = "true" -a ${USE_HIDDENAPI} = "true" -a ${HAS_HIDDENAPI_SPEC} = "true" ]; then
+ if $(has_multidex); then
+ make_hiddenapi classes.dex classes2.dex
+ else
+ make_hiddenapi classes.dex
+ fi
+fi
+
# Create a single dex jar with two dex files for multidex.
if [ ${NEED_DEX} = "true" ]; then
- if [ ${HAS_SRC_MULTIDEX} = "true" ] || [ ${HAS_JASMIN_MULTIDEX} = "true" ] || [ ${HAS_SMALI_MULTIDEX} = "true" ]; then
+ if $(has_multidex); then
zip $TEST_NAME.jar classes.dex classes2.dex
else
zip $TEST_NAME.jar classes.dex