Add DynamicConfig support for CtsHiddenApiBlocklistApiTestCases
As all the hidden API tests verify the accessibility of the same set of
APIs if an API that was previously inaccessible becomes accessible then
it would likely break all the tests. Therefore, this change adds one
set of dynamic config called CtsHiddenApiBlocklistApiTestCases.dynamic
and uses it for all the CtsHiddenApiBlocklist*TestCases.
Due to limitations in the build only one of the tests that use it can
reference the file in the 'data' property. That test is
CtsHiddenApiBlocklistCurrentApiTestCases. However, as all of the tests
use it from the same location it still works. The only issue is that
changes to the file will only have an effect when the
CtsHiddenApiBlocklistCurrentApiTestCases test is built.
Although all the tests use the same data this change follows the same
pattern as the SignatureTest of having the name of the dynamic config
provided by an instrumentation-arg so that a future refactoring can
move the handling of the DynamicConfig into the AbstractApiTest class.
Bug: 204723907
Test: atest CtsHiddenApiBlocklistApi27TestCases \
CtsHiddenApiBlocklistApi28TestCases \
CtsHiddenApiBlocklistCurrentApiTestCases \
CtsHiddenApiBlocklistTestApiTestCases \
CtsHiddenApiBlocklistDebugClassTestCases
Merged-In: I058a282b6020883cc2851c6516042446ae932d59
Change-Id: I058a282b6020883cc2851c6516042446ae932d59
(cherry picked from commit b51e76ab172d975a5b30e973581541d8dfb3f3ed)
diff --git a/tests/signature/api-check/Android.bp b/tests/signature/api-check/Android.bp
index fd0315f..96f3a9a 100644
--- a/tests/signature/api-check/Android.bp
+++ b/tests/signature/api-check/Android.bp
@@ -92,7 +92,7 @@
// Defaults for hiddenapi blocklist checks.
java_defaults {
name: "hiddenapi-blocklist-check-defaults",
- defaults: ["signature-api-check-defaults"],
+ defaults: ["signature-api-check-dynamic-config-defaults"],
java_resources: [
":platform-bootclasspath{hiddenapi-flags.csv}",
":cts-api-hiddenapi-filter-csv"
@@ -101,3 +101,12 @@
"libcts_dexchecker",
],
}
+
+// The CtsHiddenApiBlocklistApiDynamicConfig file is intended to be used by
+// multiple CtsHiddenApiBlocklist...TestCases.
+filegroup {
+ name: "CtsHiddenApiBlocklistApiDynamicConfig",
+ srcs: [
+ "CtsHiddenApiBlocklistApiDynamicConfig.dynamic",
+ ],
+}
diff --git a/tests/signature/api-check/CtsHiddenApiBlocklistApiDynamicConfig.dynamic b/tests/signature/api-check/CtsHiddenApiBlocklistApiDynamicConfig.dynamic
new file mode 100644
index 0000000..6dd8025
--- /dev/null
+++ b/tests/signature/api-check/CtsHiddenApiBlocklistApiDynamicConfig.dynamic
@@ -0,0 +1,67 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2021 Google Inc.
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<dynamicConfig>
+ <entry key ="expected_failures">
+ <!--
+ ! Each value in this section identifies an expected failure and is of the
+ ! form:
+ ! <failure-type>:<signature of class/member>
+ !
+ ! These entries are loaded by AnnotationTest which uses them to construct
+ ! an ExpectedFailuresFilter which discards them.
+ !
+ ! e.g. If the test fails with the following error message:
+ ! repackaged.junit.framework.AssertionFailedError:
+ ! extra_class: android.media.MediaParceledListSlice Error: Class annotated with android.annotation.SystemApi does not exist in the documented API
+ ! extra_class: android.media.MediaFrameworkInitializer Error: Class annotated with android.annotation.SystemApi does not exist in the documented API
+ ! extra_interface: android.media.MediaCommunicationManager$SessionCallback Error: Class annotated with android.annotation.SystemApi does not exist in the documented API
+ ! extra_class: android.media.MediaTranscodingManager Error: Class annotated with android.annotation.SystemApi does not exist in the documented API
+ ! ClassLoader hierarchy
+ !
+ ! The first step is to check that the extra classes are expected (e.g.
+ ! because they have been annotated with the @SystemApi since this version
+ ! of the CTS tests were released and the tests are being run on an
+ ! Android system with a version of the mainline modules that includes
+ ! those changes.
+ !
+ ! If they are not expected then this must be caused by a partner
+ ! inadvertently adding something to the @SystemApi so the correct
+ ! response is for them to stop doing that.
+ !
+ ! If they are expected then additional entries should be added to this
+ ! section. That simply requires copying each error message into their own
+ ! <value></value> element and then removing the whitespace after the
+ ! first : and also removing the trailing " Error: ..." part (including
+ ! the leading white space).
+ !
+ ! See below for some examples.
+ !-->
+ <!-- Bug: 204723907 -->
+ <value>extra_field:int android.net.wifi.ScanResult.UNSPECIFIED</value>
+ <value>extra_method:boolean android.net.wifi.WifiInfo.isTrusted()</value>
+ <value>extra_method:long[] android.net.wifi.hotspot2.pps.HomeSp.getMatchAllOis()</value>
+ <value>extra_method:long[] android.net.wifi.hotspot2.pps.HomeSp.getMatchAnyOis()</value>
+ <value>extra_method:void android.net.wifi.hotspot2.pps.HomeSp.setMatchAllOis(long[])</value>
+ <value>extra_method:void android.net.wifi.hotspot2.pps.HomeSp.setMatchAnyOis(long[])</value>
+ <!--
+ ! Add any new entries before this.
+ !
+ ! Note: Due to limitations within the build changes to this file it is
+ ! necessary to build CtsHiddenApiBlacklistCurrentApiTestCases in order
+ ! for changes to this file to take effect.
+ !-->
+ </entry>
+</dynamicConfig>
diff --git a/tests/signature/api-check/hidden-api-blocklist-27-api/Android.bp b/tests/signature/api-check/hidden-api-blocklist-27-api/Android.bp
index 86cb1ee..e9f7d7b 100644
--- a/tests/signature/api-check/hidden-api-blocklist-27-api/Android.bp
+++ b/tests/signature/api-check/hidden-api-blocklist-27-api/Android.bp
@@ -28,4 +28,12 @@
"cts",
"general-tests",
],
+ // Ideally the following should be uncommented but unfortunately due to
+ // limitations in the build that causes build failures due to duplicate copy
+ // rules being generated. In the meantime it is necessary to build
+ // CtsHiddenApiBlacklistCurrentApiTestCases before running this test to
+ // pick up any changes to CtsHiddenApiBlocklistApiDynamicConfig.dynamic.
+ // data: [
+ // ":CtsHiddenApiBlocklistApiDynamicConfig",
+ // ],
}
diff --git a/tests/signature/api-check/hidden-api-blocklist-27-api/AndroidTest.xml b/tests/signature/api-check/hidden-api-blocklist-27-api/AndroidTest.xml
index fdf5bfa..ac0a3d8 100644
--- a/tests/signature/api-check/hidden-api-blocklist-27-api/AndroidTest.xml
+++ b/tests/signature/api-check/hidden-api-blocklist-27-api/AndroidTest.xml
@@ -16,8 +16,13 @@
<configuration description="Config for CTS Hidden API Signature test cases">
<option name="test-suite-tag" value="cts" />
<option name="config-descriptor:metadata" key="component" value="systems" />
- <option name="config-descriptor:metadata" key="parameter" value="instant_app" />
+ <option name="config-descriptor:metadata" key="parameter" value="not_instant_app" />
<option name="config-descriptor:metadata" key="parameter" value="not_multi_abi" />
+ <target_preparer class="com.android.compatibility.common.tradefed.targetprep.DynamicConfigPusher">
+ <option name="target" value="device" />
+ <option name="config-filename" value="CtsHiddenApiBlocklistApiDynamicConfig" />
+ <option name="version" value="1.0" />
+ </target_preparer>
<option name="config-descriptor:metadata" key="parameter" value="secondary_user" />
<target_preparer class="com.android.tradefed.targetprep.suite.SuiteApkInstaller">
<option name="cleanup-apks" value="true" />
@@ -27,10 +32,13 @@
<option name="package" value="android.signature.cts.api.hiddenapi_blocklist_api_27" />
<option name="runner" value="repackaged.android.test.InstrumentationTestRunner" />
<option name="class" value="android.signature.cts.api.api27.HiddenApiTest" />
+ <option name="instrumentation-arg" key="dynamic-config-name" value="CtsHiddenApiBlocklistApiDynamicConfig" />
<option name="instrumentation-arg" key="hiddenapi-files" value="hiddenapi-flags.csv" />
<option name="instrumentation-arg" key="hiddenapi-test-flags" value="blocked" />
<option name="instrumentation-arg" key="hiddenapi-filter-file" value="hiddenapi-filter.csv" />
<option name="test-api-access" value="false" />
<option name="runtime-hint" value="30s" />
+ <!-- disable isolated storage so tests can access dynamic config stored in /sdcard. -->
+ <option name="isolated-storage" value="false" />
</test>
</configuration>
diff --git a/tests/signature/api-check/hidden-api-blocklist-27-api/src/android/signature/cts/api/api27/HiddenApiTest.java b/tests/signature/api-check/hidden-api-blocklist-27-api/src/android/signature/cts/api/api27/HiddenApiTest.java
index c940aac..13ea0f1 100644
--- a/tests/signature/api-check/hidden-api-blocklist-27-api/src/android/signature/cts/api/api27/HiddenApiTest.java
+++ b/tests/signature/api-check/hidden-api-blocklist-27-api/src/android/signature/cts/api/api27/HiddenApiTest.java
@@ -16,5 +16,7 @@
package android.signature.cts.api.api27;
-public class HiddenApiTest extends android.signature.cts.api.HiddenApiTest {
+import android.signature.cts.api.dynamic.DynamicConfigHiddenApiTest;
+
+public class HiddenApiTest extends DynamicConfigHiddenApiTest {
}
diff --git a/tests/signature/api-check/hidden-api-blocklist-28-api/Android.bp b/tests/signature/api-check/hidden-api-blocklist-28-api/Android.bp
index 7c9f844..562c407 100644
--- a/tests/signature/api-check/hidden-api-blocklist-28-api/Android.bp
+++ b/tests/signature/api-check/hidden-api-blocklist-28-api/Android.bp
@@ -28,4 +28,12 @@
"cts",
"general-tests",
],
+ // Ideally the following should be uncommented but unfortunately due to
+ // limitations in the build that causes build failures due to duplicate copy
+ // rules being generated. In the meantime it is necessary to build
+ // CtsHiddenApiBlacklistCurrentApiTestCases before running this test to
+ // pick up any changes to CtsHiddenApiBlocklistApiDynamicConfig.dynamic.
+ // data: [
+ // ":CtsHiddenApiBlocklistApiDynamicConfig",
+ // ],
}
diff --git a/tests/signature/api-check/hidden-api-blocklist-28-api/AndroidTest.xml b/tests/signature/api-check/hidden-api-blocklist-28-api/AndroidTest.xml
index 30d29f0..9a8ba04 100644
--- a/tests/signature/api-check/hidden-api-blocklist-28-api/AndroidTest.xml
+++ b/tests/signature/api-check/hidden-api-blocklist-28-api/AndroidTest.xml
@@ -16,8 +16,13 @@
<configuration description="Config for CTS Hidden API Signature test cases">
<option name="test-suite-tag" value="cts" />
<option name="config-descriptor:metadata" key="component" value="systems" />
- <option name="config-descriptor:metadata" key="parameter" value="instant_app" />
+ <option name="config-descriptor:metadata" key="parameter" value="not_instant_app" />
<option name="config-descriptor:metadata" key="parameter" value="not_multi_abi" />
+ <target_preparer class="com.android.compatibility.common.tradefed.targetprep.DynamicConfigPusher">
+ <option name="target" value="device" />
+ <option name="config-filename" value="CtsHiddenApiBlocklistApiDynamicConfig" />
+ <option name="version" value="1.0" />
+ </target_preparer>
<option name="config-descriptor:metadata" key="parameter" value="secondary_user" />
<target_preparer class="com.android.tradefed.targetprep.suite.SuiteApkInstaller">
<option name="cleanup-apks" value="true" />
@@ -27,10 +32,13 @@
<option name="package" value="android.signature.cts.api.hiddenapi_blocklist_api_28" />
<option name="runner" value="repackaged.android.test.InstrumentationTestRunner" />
<option name="class" value="android.signature.cts.api.api28.HiddenApiTest" />
+ <option name="instrumentation-arg" key="dynamic-config-name" value="CtsHiddenApiBlocklistApiDynamicConfig" />
<option name="instrumentation-arg" key="hiddenapi-files" value="hiddenapi-flags.csv" />
<option name="instrumentation-arg" key="hiddenapi-test-flags" value="blocked,max-target-o" />
<option name="instrumentation-arg" key="hiddenapi-filter-file" value="hiddenapi-filter.csv" />
<option name="test-api-access" value="false" />
<option name="runtime-hint" value="30s" />
+ <!-- disable isolated storage so tests can access dynamic config stored in /sdcard. -->
+ <option name="isolated-storage" value="false" />
</test>
</configuration>
diff --git a/tests/signature/api-check/hidden-api-blocklist-28-api/src/android/signature/cts/api/api28/HiddenApiTest.java b/tests/signature/api-check/hidden-api-blocklist-28-api/src/android/signature/cts/api/api28/HiddenApiTest.java
index f85dda3..091a25f 100644
--- a/tests/signature/api-check/hidden-api-blocklist-28-api/src/android/signature/cts/api/api28/HiddenApiTest.java
+++ b/tests/signature/api-check/hidden-api-blocklist-28-api/src/android/signature/cts/api/api28/HiddenApiTest.java
@@ -16,5 +16,7 @@
package android.signature.cts.api.api28;
-public class HiddenApiTest extends android.signature.cts.api.HiddenApiTest {
+import android.signature.cts.api.dynamic.DynamicConfigHiddenApiTest;
+
+public class HiddenApiTest extends DynamicConfigHiddenApiTest {
}
diff --git a/tests/signature/api-check/hidden-api-blocklist-current-api/Android.bp b/tests/signature/api-check/hidden-api-blocklist-current-api/Android.bp
index 67e5742..6c3401b 100644
--- a/tests/signature/api-check/hidden-api-blocklist-current-api/Android.bp
+++ b/tests/signature/api-check/hidden-api-blocklist-current-api/Android.bp
@@ -27,4 +27,7 @@
"cts",
"general-tests",
],
+ data: [
+ ":CtsHiddenApiBlocklistApiDynamicConfig",
+ ],
}
diff --git a/tests/signature/api-check/hidden-api-blocklist-current-api/AndroidTest.xml b/tests/signature/api-check/hidden-api-blocklist-current-api/AndroidTest.xml
index 7063418..e503a76 100644
--- a/tests/signature/api-check/hidden-api-blocklist-current-api/AndroidTest.xml
+++ b/tests/signature/api-check/hidden-api-blocklist-current-api/AndroidTest.xml
@@ -16,8 +16,13 @@
<configuration description="Config for CTS Hidden API Signature test cases">
<option name="test-suite-tag" value="cts" />
<option name="config-descriptor:metadata" key="component" value="systems" />
- <option name="config-descriptor:metadata" key="parameter" value="instant_app" />
+ <option name="config-descriptor:metadata" key="parameter" value="not_instant_app" />
<option name="config-descriptor:metadata" key="parameter" value="not_multi_abi" />
+ <target_preparer class="com.android.compatibility.common.tradefed.targetprep.DynamicConfigPusher">
+ <option name="target" value="device" />
+ <option name="config-filename" value="CtsHiddenApiBlocklistApiDynamicConfig" />
+ <option name="version" value="1.0" />
+ </target_preparer>
<option name="config-descriptor:metadata" key="parameter" value="secondary_user" />
<target_preparer class="com.android.tradefed.targetprep.suite.SuiteApkInstaller">
<option name="cleanup-apks" value="true" />
@@ -27,10 +32,13 @@
<option name="package" value="android.signature.cts.api.hiddenapi_blocklist_current" />
<option name="runner" value="repackaged.android.test.InstrumentationTestRunner" />
<option name="class" value="android.signature.cts.api.current.HiddenApiTest" />
+ <option name="instrumentation-arg" key="dynamic-config-name" value="CtsHiddenApiBlocklistApiDynamicConfig" />
<option name="instrumentation-arg" key="hiddenapi-files" value="hiddenapi-flags.csv" />
<option name="instrumentation-arg" key="hiddenapi-test-flags" value="blocked,max-target-o,max-target-p" />
<option name="instrumentation-arg" key="hiddenapi-filter-file" value="hiddenapi-filter.csv" />
<option name="test-api-access" value="false" />
<option name="runtime-hint" value="30s" />
+ <!-- disable isolated storage so tests can access dynamic config stored in /sdcard. -->
+ <option name="isolated-storage" value="false" />
</test>
</configuration>
diff --git a/tests/signature/api-check/hidden-api-blocklist-current-api/src/android/signature/cts/api/current/HiddenApiTest.java b/tests/signature/api-check/hidden-api-blocklist-current-api/src/android/signature/cts/api/current/HiddenApiTest.java
index 34f33fe..7726489 100644
--- a/tests/signature/api-check/hidden-api-blocklist-current-api/src/android/signature/cts/api/current/HiddenApiTest.java
+++ b/tests/signature/api-check/hidden-api-blocklist-current-api/src/android/signature/cts/api/current/HiddenApiTest.java
@@ -16,5 +16,7 @@
package android.signature.cts.api.current;
-public class HiddenApiTest extends android.signature.cts.api.HiddenApiTest {
+import android.signature.cts.api.dynamic.DynamicConfigHiddenApiTest;
+
+public class HiddenApiTest extends DynamicConfigHiddenApiTest {
}
diff --git a/tests/signature/api-check/hidden-api-blocklist-debug-class/AndroidTest.xml b/tests/signature/api-check/hidden-api-blocklist-debug-class/AndroidTest.xml
index 2ab58bd..c7df2ee 100644
--- a/tests/signature/api-check/hidden-api-blocklist-debug-class/AndroidTest.xml
+++ b/tests/signature/api-check/hidden-api-blocklist-debug-class/AndroidTest.xml
@@ -16,8 +16,13 @@
<configuration description="Config for CTS Hidden API Signature test cases">
<option name="test-suite-tag" value="cts" />
<option name="config-descriptor:metadata" key="component" value="systems" />
- <option name="config-descriptor:metadata" key="parameter" value="instant_app" />
+ <option name="config-descriptor:metadata" key="parameter" value="not_instant_app" />
<option name="config-descriptor:metadata" key="parameter" value="not_multi_abi" />
+ <target_preparer class="com.android.compatibility.common.tradefed.targetprep.DynamicConfigPusher">
+ <option name="target" value="device" />
+ <option name="config-filename" value="CtsHiddenApiBlocklistApiDynamicConfig" />
+ <option name="version" value="1.0" />
+ </target_preparer>
<option name="config-descriptor:metadata" key="parameter" value="secondary_user" />
<target_preparer class="com.android.tradefed.targetprep.suite.SuiteApkInstaller">
<option name="cleanup-apks" value="true" />
@@ -26,11 +31,14 @@
<test class="com.android.tradefed.testtype.AndroidJUnitTest" >
<option name="package" value="android.signature.cts.api.hiddenapi_blocklist_debug_class" />
<option name="runner" value="repackaged.android.test.InstrumentationTestRunner" />
- <option name="class" value="android.signature.cts.api.DebugClassHiddenApiTest" />
+ <option name="class" value="android.signature.cts.api.blocklist.debug.DebugClassHiddenApiTest" />
+ <option name="instrumentation-arg" key="dynamic-config-name" value="CtsHiddenApiBlocklistApiDynamicConfig" />
<option name="instrumentation-arg" key="hiddenapi-files" value="hiddenapi-flags.csv" />
<option name="instrumentation-arg" key="hiddenapi-test-flags" value="blocked,max-target-o,max-target-p" />
<option name="instrumentation-arg" key="hiddenapi-filter-file" value="hiddenapi-filter.csv" />
<option name="test-api-access" value="false" />
<option name="runtime-hint" value="30s" />
+ <!-- disable isolated storage so tests can access dynamic config stored in /sdcard. -->
+ <option name="isolated-storage" value="false" />
</test>
</configuration>
diff --git a/tests/signature/api-check/src/java/android/signature/cts/api/DebugClassHiddenApiTest.java b/tests/signature/api-check/hidden-api-blocklist-debug-class/src/android/signature/cts/api/blocklist/debug/DebugClassHiddenApiTest.java
similarity index 83%
rename from tests/signature/api-check/src/java/android/signature/cts/api/DebugClassHiddenApiTest.java
rename to tests/signature/api-check/hidden-api-blocklist-debug-class/src/android/signature/cts/api/blocklist/debug/DebugClassHiddenApiTest.java
index 8168f08..9266976 100644
--- a/tests/signature/api-check/src/java/android/signature/cts/api/DebugClassHiddenApiTest.java
+++ b/tests/signature/api-check/hidden-api-blocklist-debug-class/src/android/signature/cts/api/blocklist/debug/DebugClassHiddenApiTest.java
@@ -14,11 +14,12 @@
* limitations under the License.
*/
-package android.signature.cts.api;
+package android.signature.cts.api.blocklist.debug;
import android.signature.cts.DexMemberChecker;
+import android.signature.cts.api.dynamic.DynamicConfigHiddenApiTest;
-public class DebugClassHiddenApiTest extends HiddenApiTest {
+public class DebugClassHiddenApiTest extends DynamicConfigHiddenApiTest {
@Override
protected void setUp() throws Exception {
super.setUp();
diff --git a/tests/signature/api-check/hidden-api-blocklist-test-api/Android.bp b/tests/signature/api-check/hidden-api-blocklist-test-api/Android.bp
index 4ee2db5..d9e8431 100644
--- a/tests/signature/api-check/hidden-api-blocklist-test-api/Android.bp
+++ b/tests/signature/api-check/hidden-api-blocklist-test-api/Android.bp
@@ -26,4 +26,12 @@
"cts",
"general-tests",
],
+ // Ideally the following should be uncommented but unfortunately due to
+ // limitations in the build that causes build failures due to duplicate copy
+ // rules being generated. In the meantime it is necessary to build
+ // CtsHiddenApiBlacklistCurrentApiTestCases before running this test to
+ // pick up any changes to CtsHiddenApiBlocklistApiDynamicConfig.dynamic.
+ // data: [
+ // ":CtsHiddenApiBlocklistApiDynamicConfig",
+ // ],
}
diff --git a/tests/signature/api-check/hidden-api-blocklist-test-api/AndroidTest.xml b/tests/signature/api-check/hidden-api-blocklist-test-api/AndroidTest.xml
index b08abec..1f916fe 100644
--- a/tests/signature/api-check/hidden-api-blocklist-test-api/AndroidTest.xml
+++ b/tests/signature/api-check/hidden-api-blocklist-test-api/AndroidTest.xml
@@ -17,8 +17,13 @@
<configuration description="Config for CTS Hidden API Signature test cases">
<option name="test-suite-tag" value="cts" />
<option name="config-descriptor:metadata" key="component" value="systems" />
- <option name="config-descriptor:metadata" key="parameter" value="instant_app" />
+ <option name="config-descriptor:metadata" key="parameter" value="not_instant_app" />
<option name="config-descriptor:metadata" key="parameter" value="not_multi_abi" />
+ <target_preparer class="com.android.compatibility.common.tradefed.targetprep.DynamicConfigPusher">
+ <option name="target" value="device" />
+ <option name="config-filename" value="CtsHiddenApiBlocklistApiDynamicConfig" />
+ <option name="version" value="1.0" />
+ </target_preparer>
<option name="config-descriptor:metadata" key="parameter" value="secondary_user" />
<target_preparer class="com.android.tradefed.targetprep.suite.SuiteApkInstaller">
<option name="cleanup-apks" value="true" />
@@ -28,8 +33,11 @@
<option name="package" value="android.signature.cts.api.hiddenapi_blocklist_test" />
<option name="runner" value="repackaged.android.test.InstrumentationTestRunner" />
<option name="class" value="android.signature.cts.api.test.HiddenApiTest" />
+ <option name="instrumentation-arg" key="dynamic-config-name" value="CtsHiddenApiBlocklistApiDynamicConfig" />
<option name="instrumentation-arg" key="hiddenapi-files" value="hiddenapi-flags.csv" />
<option name="test-api-access" value="false" />
<option name="runtime-hint" value="30s" />
+ <!-- disable isolated storage so tests can access dynamic config stored in /sdcard. -->
+ <option name="isolated-storage" value="false" />
</test>
</configuration>
diff --git a/tests/signature/api-check/hidden-api-blocklist-test-api/src/android/signature/cts/api/test/HiddenApiTest.java b/tests/signature/api-check/hidden-api-blocklist-test-api/src/android/signature/cts/api/test/HiddenApiTest.java
index ffe85fc..3fe708c 100644
--- a/tests/signature/api-check/hidden-api-blocklist-test-api/src/android/signature/cts/api/test/HiddenApiTest.java
+++ b/tests/signature/api-check/hidden-api-blocklist-test-api/src/android/signature/cts/api/test/HiddenApiTest.java
@@ -17,9 +17,10 @@
package android.signature.cts.api.test;
import android.signature.cts.DexMember;
+import android.signature.cts.api.dynamic.DynamicConfigHiddenApiTest;
import java.util.Set;
-public class HiddenApiTest extends android.signature.cts.api.HiddenApiTest {
+public class HiddenApiTest extends DynamicConfigHiddenApiTest {
/**
* Override to match only those members that specify both test-api and blocked.
diff --git a/tests/signature/api-check/hidden-api-killswitch-sdklist/Android.bp b/tests/signature/api-check/hidden-api-killswitch-sdklist/Android.bp
index 5384558..333a3aa 100644
--- a/tests/signature/api-check/hidden-api-killswitch-sdklist/Android.bp
+++ b/tests/signature/api-check/hidden-api-killswitch-sdklist/Android.bp
@@ -25,4 +25,12 @@
"cts",
"general-tests",
],
+ // Ideally the following should be uncommented but unfortunately due to
+ // limitations in the build that causes build failures due to duplicate copy
+ // rules being generated. In the meantime it is necessary to build
+ // CtsHiddenApiBlacklistCurrentApiTestCases before running this test to
+ // pick up any changes to CtsHiddenApiBlocklistApiDynamicConfig.dynamic.
+ // data: [
+ // ":CtsHiddenApiBlocklistApiDynamicConfig",
+ // ],
}
diff --git a/tests/signature/api-check/src/java/android/signature/cts/api/HiddenApiTest.java b/tests/signature/api-check/src/java/android/signature/cts/api/HiddenApiTest.java
index 3b6fec9..97ae404 100644
--- a/tests/signature/api-check/src/java/android/signature/cts/api/HiddenApiTest.java
+++ b/tests/signature/api-check/src/java/android/signature/cts/api/HiddenApiTest.java
@@ -43,7 +43,7 @@
private Set<String> hiddenapiFilterSet;
@Override
- protected void initializeFromArgs(Bundle instrumentationArgs) {
+ protected void initializeFromArgs(Bundle instrumentationArgs) throws Exception {
hiddenapiFiles = getCommaSeparatedListRequired(instrumentationArgs, "hiddenapi-files");
hiddenapiTestFlags = getCommaSeparatedListOptional(instrumentationArgs, "hiddenapi-test-flags");
hiddenapiFilterFile = instrumentationArgs.getString("hiddenapi-filter-file");
diff --git a/tests/signature/api-check/with-dynamic-config/src/java/android/signature/cts/api/dynamic/DynamicConfigHiddenApiTest.java b/tests/signature/api-check/with-dynamic-config/src/java/android/signature/cts/api/dynamic/DynamicConfigHiddenApiTest.java
new file mode 100644
index 0000000..99f6b7b
--- /dev/null
+++ b/tests/signature/api-check/with-dynamic-config/src/java/android/signature/cts/api/dynamic/DynamicConfigHiddenApiTest.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2021 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package android.signature.cts.api.dynamic;
+
+import android.os.Bundle;
+import android.signature.cts.api.HiddenApiTest;
+import android.signature.cts.api.SignatureTest;
+import androidx.test.InstrumentationRegistry;
+import com.android.compatibility.common.util.DynamicConfigDeviceSide;
+import java.util.Collection;
+
+/**
+ * A hidden API test that supports the use of dynamic config.
+ */
+public class DynamicConfigHiddenApiTest extends HiddenApiTest {
+
+ /**
+ * The name of the optional instrumentation option that contains the name of the dynamic config
+ * data set that contains the expected failures.
+ */
+ private static final String DYNAMIC_CONFIG_NAME_OPTION = "dynamic-config-name";
+
+ @Override
+ protected void initializeFromArgs(Bundle instrumentationArgs) throws Exception {
+ super.initializeFromArgs(instrumentationArgs);
+
+ String dynamicConfigName = instrumentationArgs.getString(DYNAMIC_CONFIG_NAME_OPTION);
+ if (dynamicConfigName != null) {
+ // Make sure that the Instrumentation provided to this test is registered so it can be
+ // retrieved by the DynamicConfigDeviceSide below.
+ InstrumentationRegistry.registerInstance(getInstrumentation(), new Bundle());
+
+ // Get the DynamicConfig.xml contents and extract the expected failures list.
+ DynamicConfigDeviceSide dcds = new DynamicConfigDeviceSide(dynamicConfigName);
+ Collection<String> expectedFailures = dcds.getValues("expected_failures");
+ initExpectedFailures(expectedFailures);
+ }
+ }
+}