Switch test_com.android.sdkext to use java_sdk_library am: b22d2c944d

Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/modules/SdkExtensions/+/14722291

Change-Id: I4fc49d1eab62c790ed442dbb552b007131dc3e95
diff --git a/framework/Android.bp b/framework/Android.bp
index 6d23abe..3d3a500 100644
--- a/framework/Android.bp
+++ b/framework/Android.bp
@@ -28,19 +28,28 @@
     ],
 }
 
-java_sdk_library {
-    name: "framework-sdkextensions",
+filegroup {
+    name: "framework-sdkextensions-jarjar",
+    srcs: ["jarjar_rules.txt"],
+}
+
+java_defaults {
+    name: "framework-sdkextensions-defaults",
     srcs: [":framework-sdkextensions-sources"],
     defaults: ["framework-module-defaults"],
     permitted_packages: ["android.os.ext"],
     static_libs: ["modules-utils-build"],
-    jarjar_rules: "jarjar_rules.txt",
+    jarjar_rules: ":framework-sdkextensions-jarjar",
+    min_sdk_version: "30",
+}
+
+java_sdk_library {
+    name: "framework-sdkextensions",
+    defaults: ["framework-sdkextensions-defaults"],
     lint: {
         strict_updatability_linting: true,
     },
     apex_available: [
         "com.android.sdkext",
-        "test_com.android.sdkext",
     ],
-    min_sdk_version: "30",
 }
diff --git a/testing/Android.bp b/testing/Android.bp
index 41c428c..3d8fb9f 100644
--- a/testing/Android.bp
+++ b/testing/Android.bp
@@ -19,7 +19,7 @@
 apex_test {
     name: "test_com.android.sdkext",
     defaults: ["com.android.sdkext-defaults"],
-    java_libs: ["test_framework-sdkextensions"],
+    bootclasspath_fragments: ["test_com.android.sdkext-bootclasspath-fragment"],
     manifest: "test_manifest.json",
     prebuilts: [
         "sdkinfo_45",
@@ -29,6 +29,22 @@
     installable: false, // Should never be installed on the systemimage
 }
 
+// Encapsulate the contributions made by the test_com.android.sdkext to the
+// bootclasspath.
+bootclasspath_fragment {
+    name: "test_com.android.sdkext-bootclasspath-fragment",
+    contents: ["test_framework-sdkextensions"],
+    apex_available: ["test_com.android.sdkext"],
+
+    // The bootclasspath_fragments that provide APIs on which this depends.
+    fragments: [
+        {
+            apex: "com.android.art",
+            module: "art-bootclasspath-fragment",
+        },
+    ],
+}
+
 genrule {
     name: "sdkinfo_45_src",
     out: ["sdkinfo.binarypb"],
@@ -74,28 +90,31 @@
     ],
 }
 
-dex_import {
+java_sdk_library {
     name: "test_framework-sdkextensions",
-    jars: ["test_framework-sdkextensions.jar"],
+    defaults: ["framework-sdkextensions-defaults"],
+    srcs: [
+        // Additional test library specific stuff.
+        ":test_framework-sdkextensions-sources",
+    ],
+    apex_available: [
+        "test_com.android.sdkext",
+    ],
+    impl_library_visibility: [
+        "//packages/modules/SdkExtensions/tests/e2e",
+    ],
+
+    // Output the api files to a special directory that won't trigger an API
+    // review as it is a test only API.
+    api_dir: "apis_for_tests",
+
     stem: "framework-sdkextensions",
-    apex_available: ["test_com.android.sdkext"],
-}
 
-// It isn't currently possible to build this from source because of limitations
-// in the build + hiddenapi generation.
-//java_library {
-//    name: "test_framework-sdkextensions",
-//    srcs: ["impl-src/**/*.java"],
-//    static_libs: ["framework-sdkextensions.impl"],
-//    libs: ["framework-annotations-lib"],
-//    stem: "framework-sdkextensions",
-//    sdk_version: "module_current",
-//    installable: true,
-//    hostdex: true, // for hiddenapi check
-//}
+    // Although this has a different name it is intended to be a later version
+    // of the framework-extensions module so verify its API against its
+    // previously released API.
+    dist_stem: "framework-sdkextensions",
 
-java_library {
-    name: "test_framework-sdkextensions-stubs",
-    srcs: ["stub-src/**/*.java"],
-    sdk_version: "current",
+    // Testing only.
+    no_dist: true,
 }
diff --git a/testing/apis_for_tests/current.txt b/testing/apis_for_tests/current.txt
new file mode 100644
index 0000000..87395d3
--- /dev/null
+++ b/testing/apis_for_tests/current.txt
@@ -0,0 +1,11 @@
+// Signature format: 2.0
+package android.os.ext.test {
+
+  public class Test {
+    ctor public Test();
+    method public void publicMethod();
+    method public static void staticPublicMethod();
+  }
+
+}
+
diff --git a/testing/apis_for_tests/module-lib-current.txt b/testing/apis_for_tests/module-lib-current.txt
new file mode 100644
index 0000000..b5e61fa
--- /dev/null
+++ b/testing/apis_for_tests/module-lib-current.txt
@@ -0,0 +1,10 @@
+// Signature format: 2.0
+package android.os.ext.test {
+
+  public class Test {
+    method public void moduleLibsApiMethod();
+    method public static void staticModuleLibsApiMethod();
+  }
+
+}
+
diff --git a/testing/apis_for_tests/module-lib-removed.txt b/testing/apis_for_tests/module-lib-removed.txt
new file mode 100644
index 0000000..d802177
--- /dev/null
+++ b/testing/apis_for_tests/module-lib-removed.txt
@@ -0,0 +1 @@
+// Signature format: 2.0
diff --git a/testing/apis_for_tests/removed.txt b/testing/apis_for_tests/removed.txt
new file mode 100644
index 0000000..d802177
--- /dev/null
+++ b/testing/apis_for_tests/removed.txt
@@ -0,0 +1 @@
+// Signature format: 2.0
diff --git a/testing/apis_for_tests/system-current.txt b/testing/apis_for_tests/system-current.txt
new file mode 100644
index 0000000..0f9a99e
--- /dev/null
+++ b/testing/apis_for_tests/system-current.txt
@@ -0,0 +1,19 @@
+// Signature format: 2.0
+package android.os.ext {
+
+  public class SdkExtensions {
+    method @NonNull public static java.util.Map<java.lang.Integer,java.lang.Integer> getAllExtensionVersions();
+    method public static int getExtensionVersion(int);
+  }
+
+}
+
+package android.os.ext.test {
+
+  public class Test {
+    method public static void staticSystemApiMethod();
+    method public void systemApiMethod();
+  }
+
+}
+
diff --git a/testing/apis_for_tests/system-removed.txt b/testing/apis_for_tests/system-removed.txt
new file mode 100644
index 0000000..d802177
--- /dev/null
+++ b/testing/apis_for_tests/system-removed.txt
@@ -0,0 +1 @@
+// Signature format: 2.0
diff --git a/testing/stub-src/android/os/ext/test/Test.java b/testing/stub-src/android/os/ext/test/Test.java
deleted file mode 100644
index fbf8fa3..0000000
--- a/testing/stub-src/android/os/ext/test/Test.java
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * Copyright (C) 2020 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.os.ext.test;
-
-public class Test {
-
-    public Test() {
-        throw new RuntimeException("Stub!");
-    }
-
-    public void publicMethod() {
-        throw new RuntimeException("Stub!");
-    }
-
-    public void systemApiMethod() {
-        throw new RuntimeException("Stub!");
-    }
-
-    public void moduleLibsApiMethod() {
-        throw new RuntimeException("Stub!");
-    }
-
-    public void testApiMethod() {
-        throw new RuntimeException("Stub!");
-    }
-
-    public void hiddenMethod() {
-        throw new RuntimeException("Stub!");
-    }
-
-    public static void staticPublicMethod() {
-        throw new RuntimeException("Stub!");
-    }
-
-    public static void staticSystemApiMethod() {
-        throw new RuntimeException("Stub!");
-    }
-
-    public static void staticModuleLibsApiMethod() {
-        throw new RuntimeException("Stub!");
-    }
-
-    public static void staticTestApiMethod() {
-        throw new RuntimeException("Stub!");
-    }
-
-    public static void staticHiddenMethod() {
-        throw new RuntimeException("Stub!");
-    }
-
-}
diff --git a/testing/update_prebuilt.sh b/testing/update_prebuilt.sh
deleted file mode 100755
index 986258c..0000000
--- a/testing/update_prebuilt.sh
+++ /dev/null
@@ -1,36 +0,0 @@
-#!/bin/bash -ex
-
-# This script updates the prebuilt test_framework-sdkextension.jar, which is
-# required when the "new APIs" added change, or the framework jar changes
-# for other reasons.
-
-function gettop() {
-    local p=$(pwd)
-    while [[ ! -e "${p}/build/envsetup.sh" ]]; do
-        p="${p}/.."
-    done
-    echo $(readlink -f $p)
-}
-
-if [[ -z "$OUT" ]]; then
-    echo "lunch first"
-    exit 1
-fi
-
-dir=$(dirname $(readlink -f $BASH_SOURCE))
-bp="${dir}/../framework/Android.bp"
-
-if ! test -e $bp; then
-    echo $bp does not exist
-    exit 1
-elif test -e "${bp}.bak"; then
-    echo "skipping ${bp} modification because ${bp}.bak exists"
-    continue
-fi
-cp $bp "${bp}.bak"
-sed -i -e 's|":framework-sdkextensions-sources"|":framework-sdkextensions-sources",":test_framework-sdkextensions-sources"|' $bp
-
-$(gettop)/build/soong/soong_ui.bash --make-mode framework-sdkextensions
-
-mv "${bp}.bak" $bp ; touch $bp
-cp "${OUT}/apex/com.android.sdkext/javalib/framework-sdkextensions.jar" "${dir}/test_framework-sdkextensions.jar"
diff --git a/tests/e2e/Android.bp b/tests/e2e/Android.bp
index 1a0b6f8..6ae1135 100644
--- a/tests/e2e/Android.bp
+++ b/tests/e2e/Android.bp
@@ -40,8 +40,13 @@
 android_app {
     name: "sdkextensions_e2e_test_app",
     srcs: ["app-src/**/*.java"],
-    libs: ["test_framework-sdkextensions-stubs"],
+    libs: [
+        // Depend on the impl library directly so that its tests can try and
+        // invoke methods which it is not allowed to use to verify that the
+        // runtime correctly refuses access to them.
+        "test_framework-sdkextensions.impl",
+    ],
     static_libs: ["modules-utils-build_system"],
-    sdk_version: "system_current",
+    sdk_version: "module_current",
     min_sdk_version: "30",
 }