Reapply "Add ConscryptPrivateTestCases"

This reverts commit a6663cecc8144691e5cf3fb43e2382287e39cea5.

The test package name has been updated to android.conscrypt.tests.

Bug: 360775273
Test: atest ConscryptPrivateTestCases
Test: build on git_main; target aosp_cheetah-next-userdebug
Change-Id: I8a8e47d20fd22c0b71a223a8cb0802829fdffc4a
diff --git a/Android.bp b/Android.bp
index 17f093f..7505deb 100644
--- a/Android.bp
+++ b/Android.bp
@@ -683,16 +683,15 @@
     ],
     hostdex: true,
     srcs: [
-        "repackaged/platform/src/test/java/**/*.java",
-        "repackaged/common/src/test/java/**/*.java",
+        "repackaged/platform/src/test/java/com/android/org/conscrypt/TrustedCertificateStoreTest.java",
+        "repackaged/platform/src/test/java/com/android/org/conscrypt/metrics/*.java",
+        "repackaged/common/src/test/java/com/android/org/conscrypt/*.java",
+        "repackaged/common/src/test/java/com/android/org/conscrypt/metrics/*.java",
+        "repackaged/common/src/test/java/com/android/org/conscrypt/java/**/*.java",
+        "repackaged/common/src/test/java/com/android/org/conscrypt/javax/**/*.java",
         "repackaged/testing/src/main/java/**/*.java",
         "publicapi/src/test/java/**/*.java",
     ],
-    exclude_srcs: [
-        // b/360775273.
-        "repackaged/platform/src/test/java/com/android/org/conscrypt/ct/*.java",
-        "repackaged/common/src/test/java/com/android/org/conscrypt/ct/*.java",
-    ],
     java_resource_dirs: [
         // Resource directories do not need repackaging.
         "openjdk/src/test/resources",
@@ -732,6 +731,46 @@
     java_version: "1.8",
 }
 
+// Conscrypt private tests. These tests relies on private APIs. Prefer adding
+// your test to conscrypt-tests if possible, as these will be executed as part
+// of CTS (see CtsLibcoreTestCases).
+android_test {
+    name: "ConscryptPrivateTestCases",
+    srcs: [
+        "repackaged/platform/src/test/java/com/android/org/conscrypt/ct/*.java",
+        "repackaged/platform/src/test/java/com/android/org/conscrypt/CertBlocklistTest.java",
+        "repackaged/common/src/test/java/com/android/org/conscrypt/ct/*.java",
+        "repackaged/testing/src/main/java/**/*.java",
+    ],
+
+    java_resource_dirs: [
+        // Resource directories do not need repackaging.
+        "openjdk/src/test/resources",
+        "common/src/test/resources",
+    ],
+
+    platform_apis: true,
+    manifest: "AndroidManifest-private.xml",
+    test_config: "AndroidTest-private.xml",
+    libs: [
+        "conscrypt",
+        "core-test-rules",
+        "junit",
+        "mockito-target-minus-junit4",
+        "framework-statsd.stubs.module_lib",
+    ],
+
+    static_libs: [
+        "androidx.test.runner",
+        "androidx.test.rules",
+        "bouncycastle-unbundled",
+        "bouncycastle-bcpkix-unbundled",
+        "bouncycastle-ocsp-unbundled",
+    ],
+
+    java_version: "1.8",
+}
+
 // Make the conscrypt-benchmarks library.
 java_test {
     name: "conscrypt-benchmarks",
diff --git a/AndroidManifest-private.xml b/AndroidManifest-private.xml
new file mode 100644
index 0000000..377bd97
--- /dev/null
+++ b/AndroidManifest-private.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ * Copyright (C) 2024 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.
+ -->
+
+<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="android.conscrypt.tests">
+    <application>
+        <uses-library android:name="android.test.runner" />
+    </application>
+    <instrumentation android:name="androidx.test.runner.AndroidJUnitRunner"
+                     android:targetPackage="android.conscrypt.tests"
+                     android:label="Conscrypt private test cases">
+    </instrumentation>
+</manifest>
diff --git a/AndroidTest-private.xml b/AndroidTest-private.xml
new file mode 100644
index 0000000..ea31fab
--- /dev/null
+++ b/AndroidTest-private.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2024 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.
+-->
+<configuration description="Config for conscrypt private test cases">
+    <target_preparer class="com.android.tradefed.targetprep.suite.SuiteApkInstaller">
+        <option name="cleanup-apks" value="true" />
+        <!-- this has just the instrumentation which acts as the tests we want to run -->
+        <option name="test-file-name" value="ConscryptPrivateTestCases.apk" />
+    </target_preparer>
+    <test class="com.android.tradefed.testtype.AndroidJUnitTest" >
+        <option name="package" value="android.conscrypt.tests" />
+        <option name="hidden-api-checks" value="false"/>
+    </test>
+</configuration>